Plot variables
-
- Site Admin
- Posts: 4832
- Joined: 22 Aug 2009, 11:57
- Antispam: Yes
- Location: Espoo, Finland
- Contact:
Re: Plot variables
Hi
I dont really know how this would be made totally generic. You can save the results as a table only if there is one variable. If the function has multiple variables then what should one do?
-Peter
I dont really know how this would be made totally generic. You can save the results as a table only if there is one variable. If the function has multiple variables then what should one do?
-Peter
Re: Plot variables
Hi,
functions of several variables would be the next step.
What I mean is if I have a material section like
and in myconductivity.f90, I have something like
I get a segmentation fault at the GetMaterial call. I suspect that this is because CurrentElement is undefined for a ListGetFun call of myconductivity. So I somehow need to supply a valid CurrentElement where I can set the temperature to the value(s) I would like to test.
I have begun to think about something like taking a node number, save its current state and then sweep the material assignment to this node through all available materials (or in fact, through all available bodies since as far as I understand the material assigment is derived from the body ID). Before tha actual simulation starts, I would restore the previously saved state.
Does that sound reasonable, or is there a more elegant way?
Matthias
functions of several variables would be the next step.
What I mean is if I have a material section like
Code: Select all
Material 1
My Parameter = Real 0.5
Thermal Conductivity = Variable Temperature; Real Procedure "Myconductivity.dll" "myconductivity"
(...)
End
Code: Select all
FUNCTION myconductivity( Model, n, Temp ) RESULT(s)
(...)
TYPE(ValueList_t), POINTER :: VList
VList => GetMaterial(CurrentModel % CurrentElement)
myParameter = GetConstReal( VList, 'My Parameter')
s = Temp * myParameter ** 2
END FUNCTION myconductivity
I have begun to think about something like taking a node number, save its current state and then sweep the material assignment to this node through all available materials (or in fact, through all available bodies since as far as I understand the material assigment is derived from the body ID). Before tha actual simulation starts, I would restore the previously saved state.
Does that sound reasonable, or is there a more elegant way?
Matthias
-
- Posts: 86
- Joined: 18 Nov 2014, 18:18
- Antispam: Yes
Re: Plot variables
Hi,
On the same topic, it is possible to cheik a variable dependancy? For example electrical conductivity function of temperature ?
I try in ResultOutputSolver, the simple:
Variable i = Electric Conductivity
but in the log -> WARNING:: WriteVtuXMLFile: Nonexistent variable: electric conductivity
What is the trick to plot material properties in vtu format?
Regards
Julien
On the same topic, it is possible to cheik a variable dependancy? For example electrical conductivity function of temperature ?
I try in ResultOutputSolver, the simple:
Variable i = Electric Conductivity
but in the log -> WARNING:: WriteVtuXMLFile: Nonexistent variable: electric conductivity
What is the trick to plot material properties in vtu format?
Regards
Julien
Re: Plot variables
Hi,
you have to use SaveMaterials/SaveScalars to do that. I think I did a similar thing some time ago, but don't have the time right now to look up the details. There are threads in this forum dealing with the subject, and the Models manual contains some info also.
HTH,
Matthias
you have to use SaveMaterials/SaveScalars to do that. I think I did a similar thing some time ago, but don't have the time right now to look up the details. There are threads in this forum dealing with the subject, and the Models manual contains some info also.
HTH,
Matthias
-
- Posts: 86
- Joined: 18 Nov 2014, 18:18
- Antispam: Yes
Re: Plot variables
Thank you Matthias
I found in documentation informations about SaveMaterials solver.
log file give:
SaveMaterials: Creating selected material parameters as fields
SaveMaterials: Parameter > electric conductivity < defined with 2403 dofs
Now how to make a plot of this parameters field in ResultOutputSolver...?
Try different things but no results
Julien
I found in documentation informations about SaveMaterials solver.
Code: Select all
Solver i
Procedure = File "SaveData" "SaveMaterials"
Exec Solver = after simulation
Parameter 1 = Electric Conductivity
End
SaveMaterials: Creating selected material parameters as fields
SaveMaterials: Parameter > electric conductivity < defined with 2403 dofs
Now how to make a plot of this parameters field in ResultOutputSolver...?
Try different things but no results
Julien
Re: Plot variables
Hi,
check out the SaveDependence solver which is in SaveData.src (see Peter's post earlier in this thread), it might already do what you need. You can call it right away since it is in the distribution already.
I went on and improved it in the meantime, but it is not yet ready to share. I am very busy with a totally different project right now and cannot go into details for at least the next one or two weeks, sorry.
HTH,
Matthias
check out the SaveDependence solver which is in SaveData.src (see Peter's post earlier in this thread), it might already do what you need. You can call it right away since it is in the distribution already.
I went on and improved it in the meantime, but it is not yet ready to share. I am very busy with a totally different project right now and cannot go into details for at least the next one or two weeks, sorry.
HTH,
Matthias
-
- Posts: 86
- Joined: 18 Nov 2014, 18:18
- Antispam: Yes
Re: Plot variables
Hi,
It is possible to plot material properties after simulation in using Exported variable using body force section and exported variable, like this:
You can plot for example thermal dependent properties and what you want.
Julien
It is possible to plot material properties after simulation in using Exported variable using body force section and exported variable, like this:
Code: Select all
Body 1
Target Bodies(1) = 1
Name = "Body 1"
Equation = 1
Material = 1
Body Force = 1
Initial condition = 1
End
Body Force 1
condTherm = Variable Temperature
Real MATC "tx(0)"
End
....
Solver 1
Equation = Heat Equation
Procedure = "HeatSolve" "HeatSolver"
Calculate Loads = True
Variable = Temperature
Exec Solver = Always
Stabilize = True
Bubbles = False
Lumped Mass Matrix = False
Optimize Bandwidth = True
Exported Variable 1 = condTherm
!Nonlinear Update Exported Variables = Logical True
Update Exported Variables = Logical True
....
End
...
Julien
Re: Plot variables
Hi everyone,
Although this topic may be a bit older, I hope you don't mind me revisiting it. Like many before me, I would like to verify my User-Defined Function (UDF) before utilizing it in elmer within a particular temperature range.
To achieve this, I compiled a Fortran program that incorporates the UDF. During the compilation process, it is important to handle the type definitions correctly, which can be achieved by having the "defutils.mod" file present in the same directory as the program. For a win installation this file is found in "C:\Program Files\Elmer 9.0-Release\share\elmersolver\include".
The codes and compilation instructions:
The UDF definition file "own-materials.f90":
The Fortran program "TestProperty.f90":
Compilation as shared dll object for use in elmer as usual (cmd in the path of the *.f90 files):
Compilation of the testprogram using the elmer-provided fortran compiler (cmd in the path of the *.f90 files):
Run the test program (cmd in the path of the compiled *.exe file):
Program output (values here are as expected):
It may be worth noting, that I had compiling issues with following common lines in the "own-materials.f90", as the compiler does not know where GetMaterial() and Fatal() are defined. Hence, these lines were removed in "own-materials.f90".
I also tried to use the *.dll file from python, but I think there are issues with the iso_c_bindings using the elmerf90 compiler.
I hope this information proves helpful to someone in the future.
Danny
Although this topic may be a bit older, I hope you don't mind me revisiting it. Like many before me, I would like to verify my User-Defined Function (UDF) before utilizing it in elmer within a particular temperature range.
To achieve this, I compiled a Fortran program that incorporates the UDF. During the compilation process, it is important to handle the type definitions correctly, which can be achieved by having the "defutils.mod" file present in the same directory as the program. For a win installation this file is found in "C:\Program Files\Elmer 9.0-Release\share\elmersolver\include".
The codes and compilation instructions:
The UDF definition file "own-materials.f90":
Code: Select all
!-----------------------------------------------------
! material property user defined function for ELMER:
! electrical conductivity as a function of temperature
! Written By: Anil Kunwar (2015-03-13)
! Modified by D.Kojda (2023-06-28)
!-----------------------------------------------------
FUNCTION getThermalConductivity_steel304( model, n, temp ) RESULT(condt)
! using "https://trc.nist.gov/cryogenics/materials/304Stainless/304Stainless_rev.htm"
! unit in W/(m*K)
! modules needed
USE DefUtils
IMPLICIT None
! variables in function header
TYPE(Model_t) :: model
INTEGER :: n
REAL :: temp, condt
! variables in function
REAL :: logTerm
! very important declaration, uncomment for debug printing in ElmerGUI
! CHARACTER(LEN=30) :: FMT
! Calculate the logarithmic term
logTerm = log(temp)/log(10.0)
!Calculate the NIST Polynom
condt = 10**(-1.4087 + 1.3982 * logTerm + 0.2543 * logTerm**2 &
- 0.6260 * logTerm**3 + 0.2334 * logTerm**4 &
+ 0.4256 * logTerm**5 - 0.4658 * logTerm**6 &
+ 0.1650 * logTerm**7 - 0.0199 * logTerm**8)
!For Debug in ElmerGUI
!write(*,FMT="(A, 1pE11.3E3)") " Temperature = ", tx
!write(*,FMT="(A, 1pE11.3E3)") " Logterm = ", logTerm
!write(*,FMT="(A, 1pE11.3E3)") " Thermal Conductivity = ", condt
END FUNCTION getThermalConductivity_steel304
The Fortran program "TestProperty.f90":
Code: Select all
PROGRAM TestProperty
USE DefUtils
IMPLICIT NONE
INTEGER :: i, numPoints
REAL :: temp, conductivity
REAL :: minTemp, maxTemp
REAL :: getThermalConductivity_steel304
TYPE(Model_t) :: model
INTEGER :: n
! Define the number of points
numPoints = 1000
minTemp = 4.2
maxTemp = 300
DO i = 1, numPoints
temp = minTemp + (maxTemp - minTemp) / REAL(numPoints - 1) * REAL(i - 1)
conductivity = getThermalConductivity_steel304(model, n, temp)
WRITE(*,*) temp, conductivity
END DO
END PROGRAM TestProperty
Code: Select all
elmerf90 -o own-materials.dll own-materials.f90
Code: Select all
"C:\Program Files\Elmer 9.0-Release\stripped_gfortran\bin\x86_64-w64-mingw32-gfortran.exe" -o TestProperty.exe TestProperty.f90 own-materials.f90
Code: Select all
TestProperty.exe
Code: Select all
4.19999981 0.290716350
4.49609566 0.318263769
4.79219198 0.346298039
...
299.407806 15.2935171
299.703918 15.3009739
300.000000 15.3089056
Code: Select all
! get pointer on list for material
material => GetMaterial()
IF (.NOT. ASSOCIATED(material)) THEN
CALL Fatal('getConductivity', 'No material found')
END IF
I hope this information proves helpful to someone in the future.
Danny