Plot variables

General discussion about Elmer
mzenker
Posts: 1999
Joined: 07 Dec 2009, 11:49
Location: Germany

Plot variables

Post by mzenker »

Hi,

when defining Variables, for example, material properties depending on temperature, as in

Code: Select all

Electric Conductivity = Variable Temperature; Real MATC "0.5 * (1 + 0.0025 * (tx - 20))"
one sometimes would like to plot the result of what has been entered in Elmer, be it a table, a MATC function or a user defined function, for debugging purposes. Is there a possibility to do that from within Elmer?

Thanks,

Matthias
Chris_DE
Posts: 10
Joined: 20 Nov 2011, 19:45
Antispam: Yes
Location: Deutschland

Re: Plot variables

Post by Chris_DE »

Hi Matthias,

I ask me for a week the same question. I found a solution that works to display the value in the solver log window.

Concerning the User variables that are defined in the sif or Elmer variables:

I wrote some printf commands in a free text input (e.g. in Result Ouptut Solver)

the two last lines is the code I wrote in the free text input:

Code: Select all

(...)
Solver 2
  Equation = Result Output
  Output Format = Vtu
  Procedure = "ResultOutputSolve" "ResultOutputSolver"
  Output File Name = case
  Exec Solver = After Simulation
End

Equation 2
  Name = "VTK Output"
$fprintf( stderr, "Electric Conductivity: ");
$fprintf( stderr, "%.2f\n", Electric Conductivity);
  Active Solvers(1) = 2
End
(...)
I haven't test it for Array, it works for variable that contains floating numbers.

Concerning Variables only defined in User Defined Functions (UDF), I wrote the following Command in the function (.f90) to display the value during processing.

Code: Select all

! Very important declaration
CHARACTER(LEN=30) :: FMT
!
!(....)
!
! Floating Number
write(*,FMT="(A, F7.2)"),"Valeur de ma Variable local 1 = ", MaVariablelocal1
! Scientific notation with exponent
write(*,FMT="(A, 1pE11.3E3)")," Valeur de ma Variable local 2 = ", MaVariablelocal2
You seems to be fit with UDF, I learn a lot reading your precedent topics.
I hope that I could help you this time ;)

Cheers
Chris
Takala
Posts: 186
Joined: 23 Aug 2009, 23:59

Re: Plot variables

Post by Takala »

Hi,

check out model 49 from http://www.nic.funet.fi/pub/sci/physics ... Manual.pdf

Is that what you need?

Cheers,

Eelis
mzenker
Posts: 1999
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: Plot variables

Post by mzenker »

Hi,

thank you Chris and Eelis for your suggestions. That way, I could monitor a temperature-dependent material property during simulation, but only for the temperatures which are actually present.
I was more looking for a possibility to get a plot or a table of a property for a given range of the variable it depends on. For example, if the electric conductivity depends on temperature, I would like to output the conductivity for temperatures between 25 and 100 °C so that I can check if my MATC expression or UDF works correctly.
Of course I could build a test case where the temperature range is swept through, and use either SaveData/SaveMaterials or printf statements. But I would imagine a more elegant solutionwithin the actual simulation case, e.g. a solver called before simulation where the properties and temperature (or time) range can be specified, and which spits a table. One could even dream of an ElmerGUI feature allowing to plot the property directly upon mouse click... ;)
Such a feature doesn't seem to exist right now - how would one implement it (without GUI, to start with)? This would require changing variables such as temperature or time from within a solver without affecting the simulation course. I don't know if and how this is possible, or if there is another trick.
Any suggestions?

Matthias
raback
Site Admin
Posts: 4812
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Plot variables

Post by raback »

Hi

Here is a quick hack that might do what you need

Code: Select all

!------------------------------------------------------------------------------
!> This subroutine saves 1D dependence of a given property.
!------------------------------------------------------------------------------
SUBROUTINE SaveDependence( Model,Solver,dt,TransientSimulation )
  
  USE Types
  USE Lists
  USE DefUtils

  IMPLICIT NONE
!------------------------------------------------------------------------------
  TYPE(Solver_t) :: Solver
  TYPE(Model_t) :: Model
  REAL(KIND=dp) :: dt
  LOGICAL :: TransientSimulation
!------------------------------------------------------------------------------
! Local variables
!------------------------------------------------------------------------------
  CHARACTER(LEN=MAX_NAME_LEN) :: FileName, ParName
  REAL(KIND=dp) :: x1, x0, x, w, f
  INTEGER :: i,j,n,NoPar
  TYPE(ValueList_t), POINTER :: Params
  LOGICAL :: Found

  CALL Info('SaveDependence','Saving dependencies in a table')

  Params => Solver % Values

  FileName = ListGetString( Params,'Filename',Found)
  IF(.NOT. Found ) FileName = 'dep.dat'

  n = ListGetInteger( Params,'Number of points',minv=2)
  x0 = ListGetCReal( Params,'Lower limit')
  x1 = ListGetCReal( Params,'Upper Limit')

  NoPar = 0
  DO j=1,100
    WRITE (ParName,'(A,I0)') 'Expression ',j
    IF( ListCheckPresent( Params, ParName ) ) THEN
      NoPar = j
    ELSE
      EXIT
    END IF
  END DO

  IF( NoPar == 0 ) THEN
    CALL Warn('SaveDependence','No parameter given!')
    RETURN
  END IF

  OPEN( 10, FILE=FileName )

  DO i=1,n
    w = (1.0_dp*(i-1))/(n-1)
    x = x0 + w*(x1-x0)

    WRITE (10,'(I6,ES15.6)',ADVANCE='NO') i,x
    
    DO j=1,NoPar
      WRITE (ParName,'(A,I0)') 'Expression ',j
      f = ListGetFun( Params,ParName,x )
      WRITE (10,'(ES15.6)',ADVANCE='NO') f     
    END DO

    WRITE (10,'(A)') ' '     
  END DO
  
  CLOSE( 10 ) 
 
END SUBROUTINE SaveDependence
and to call, e.g.

Code: Select all

Solver 2
  Equation = "SaveDep"
  Procedure = "SaveDependence" "SaveDependence"
  Filename = File f.dat

  Number Of Points = Integer 21
  Lower Limit = Real 1.0
  Upper Limit = Real 2.0 

  Expression 1 = Variable dummy
    Real MATC "1+tx"
  Expression 2 = Variable dummy
    Real MATC "1+sin(tx)"
  Expression 3 = Variable dummy
    Real 
      0.0 0.0
      1.0 5.0 
      2.0 5.0
    End  
End
-Peter
mzenker
Posts: 1999
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: Plot variables

Post by mzenker »

Thank you Peter!

I will try it out and report back...

Matthias
mzenker
Posts: 1999
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: Plot variables

Post by mzenker »

Hi Peter,

I get a compilation error for this line

Code: Select all

f = ListGetFun( Params,ParName,x )
And indeed I don't find ListGetFun or GetFun or any variant I could think of anywhere in the sources...

What's the name of the function?

Thanks,

Matthias
raback
Site Admin
Posts: 4812
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Plot variables

Post by raback »

Hi

I added ListGetFun yesterday so you need to make "svn update".

-Peter
mzenker
Posts: 1999
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: Plot variables

Post by mzenker »

Hi Peter,

coming back to this subject after quite some time...

I have tried your "SaveDependence" solver (btw I have seen that it is in SaveData now). It works well for simple cases, i.e. tables, MATC expressions and simple user functions. What does not work is a user function that reads other parameters from the material, e.g. to calculate a material property depending on temperature and, say, density so that I need to get the material pointer. Invocation of GetMaterial() in a udf called by ListGetFun gives a segmentation fault in ElmerSolver. I have tried to delve into the code to find out what is going on, and as far as I understand, ListGetFun does the call without valid element, i.e. node number is zero and CurrentModel % CurrentElement is not defined. So in order to make those udfs work, I need to supply the underlying model structure somehow. Basically I want to scan the materials definitions and look for properties which are variable dependant, and then plot those. This works already, except for that kind of udf - but I need that plotting functionality specifically to debug those more complicated udfs.
Can you think of an elegant way to do that?

Hope you will find the time to answer... :)

Thanks,

Matthias
mzenker
Posts: 1999
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: Plot variables

Post by mzenker »

Hi,

an idea how to do it, someone...?
Post Reply