Phase change / switch variable

Numerical methods and mathematical models of Elmer
XisZero
Posts: 14
Joined: 11 Sep 2014, 12:10
Antispam: Yes

Phase change / switch variable

Post by XisZero »

Hi everyone,

First of all, thanks for the softtware, and all the information given in the forum. It really helped me a lot, starting with Elmer.

Now on to my "problems" :

I am trying to simulate the transient heating of a material with a phase change. I was able to setup a model and a simulation which comes close to the practical tests i have done this far.
Now i want to implement the phase change. I already read a lot of topics dealing with several things about phase change and writing UDF.
Some things are still unclear to me:
1) what exactly does "Phase change interval (2,1) = T1 T2" mean? perhaps this could already solve my issues.
2) is it possible to write a UDF with a variable that switches on a specified temperature of the model (i want to create a UDF/model that implements subcooling, for example: the PCM melts at 300K and freezes back again at 270 K ). If there already is a model, i would be happy to know ;)

I can attach my current files, if someone could take a look.
Thanks in advance!

Greetingss,
X=0
Attachments
PCMUDF.f90
(1.1 KiB) Downloaded 315 times
case.sif
(3.14 KiB) Downloaded 341 times
mzenker
Posts: 1998
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: Phase change / switch variable

Post by mzenker »

Hi,

short answers for the moment:

1) Since that one is not documented in the Models Manual, the best you can do is look into the code yourself. I did this while ago when I made a simulation with phase change, but did not use the phase change interval feature. I don't have the time to delve into the code right now. I might do it in the next days. It is in HeatSolve.src.

2) Yes, I think so. If you never wrote an udf I advise the Solver Manual and the programmer's tutorial to get started.


HTH,

Matthias
XisZero
Posts: 14
Joined: 11 Sep 2014, 12:10
Antispam: Yes

Re: Phase change / switch variable

Post by XisZero »

Thanks for your answers.
I will have a look at the Heatsolve.src.
i already looked at Solvermanual and the programmers tutorial, that was were i started. unfortunately it didn´t work properly. Think, i have to re-program or change a few things.

Greetings,
X=0
mzenker
Posts: 1998
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: Phase change / switch variable

Post by mzenker »

Hi,

from a quick glance at your udf, I think you must associate a phase to every node of the mesh, and save it between successive calls to your udf. I dont' know right away how to do that, however.

HTH,

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

Re: Phase change / switch variable

Post by raback »

Hi

The 'phase change intervals' is not really used except for the following

Code: Select all

!     If modelling phase change (and if requested by the user), check if any
!     node has jumped over the phase change interval, and if so, reduce
!     timestep and or relaxation and recompute.
The idea is just to ensure that there are integration points in the interval where the phase change occurs.

So you can as well forget about it and tune the accuracy by hand by changing the h/dt resolution.

What comes to your sif it seems you're trying to combine a Eulerian and a Lagrangian approach. The Eulerian one must use smeared down latent heat i.e. enthalpy. So you need to replace the latent heat with delta functions that result to the same integral over a finite temperature interval. In Lagrangian approach you need a different solver that works on the boundary only and can directly take latent heat. The merits of Eulerian vs. Lagrangian approaches have been discussed before and you should find info on that also in the forum.

-Peter
XisZero
Posts: 14
Joined: 11 Sep 2014, 12:10
Antispam: Yes

Re: Phase change / switch variable

Post by XisZero »

@ Matthias:
I will try that, hope it works, and hope i can do this. i will report back if there is a success.

@ Peter:
There are some left-overs from previous versions. haven´t checked the sif before uploading... I didn´t know about those two approaches. Thanks for the advice. I will study the posts and topics concerning these approaches.

Greetings
X=0
XisZero
Posts: 14
Joined: 11 Sep 2014, 12:10
Antispam: Yes

Re: Phase change / switch variable

Post by XisZero »

Hello Again,

So, after some time, i finally was able to restart my project. So this is what i have so far, and it works (almost).

The enthalpy values are calculated correctly at the given temperatures. Also the subcooling is working properly, so if the material melts (above 350K) there is the crystallization at 348K.

Now i came across other problems. So a short question: is it possible to read in a second variable, e.g. " = variabe temperature, time" in the UDF? and how do i use the second variable in the udf? (e.g. " Function phase (model,n,temp,time)" ? )



The UDF:

Code: Select all

FUNCTION phase(Model, n,  temp) RESULT(ent)
USE DefUtils
IMPLICIT None
TYPE(Model_t) :: Model
Integer :: n, ph
REAL(KIND=dp) :: temp, ent

Logical :: ph0 = .true.,ph1 = .False. , ph2 = .False. , ph3 = .False. , ph4 = .False. , ph5 = .False.


	if (temp >= 350 .AND. temp <= 353 ) then
		if (ph0) then				
		ph = 1	
		ph1 = .True.					
		end if
	else if (temp > 353 .AND. temp <= 356) then
		if (ph1) then						
		ph = 2
		ph0 = .False.
		ph2 = .true.			
		end if					
	else if (temp > 356) then
		if (ph2) then		
		ph = 3
		ph1 = .false.		
		ph3 = .true.
		end if

	else if (temp <= 348 .And. temp > 345) then	
		if (ph1 .or. ph2 .or. ph3) then	
		ph = 4	
		ph2 = .false. 		
		end if	
	
	else if (temp <= 345 .AND. temp > 342) then
		if (ph1 .or. ph2 .or. ph3 .or. ph4) then
		ph = 5
		ph3 = .false.				
		end if
	end if	





select case (ph)
case (0)
ent = 0

case (1)
ent = 30e6 * (temp - 350)

case (2)
ent = 30e6 * (temp -353) + 90e6

case (3)
ent = 0

case (4)
ent = 30e6 * (temp - 345) - 90e6

case (5)
ent = -30e6 * (temp - 342)

end select
END FUNCTION phase
The SIF:

Code: Select all

Header
  CHECK KEYWORDS Warn
  Mesh DB "." "."
  Include Path ""
  Results Directory ""
End

Simulation
  Max Output Level = 5
  Coordinate System = Cartesian
  Coordinate Mapping(3) = 1 2 3
  Simulation Type = Transient
  Steady State Max Iterations = 1
  Output Intervals = 1
  Timestepping Method = BDF
  BDF Order = 1
  Timestep intervals = 1000
  Timestep Sizes = 0.2
  Solver Input File = case.sif
  Post File = case.ep
coordinate scaling = 0.001
End

Constants
  Gravity(4) = 0 -1 0 9.82
  Stefan Boltzmann = 5.67e-08
  Permittivity of Vacuum = 8.8542e-12
  Boltzmann Constant = 1.3807e-23
  Unit Charge = 1.602e-19
End

Body 1
  Target Bodies(1) = 14
  Name = "Body 1"
  Equation = 2
  Material = 1
  Initial condition = 1
End

Body 2
  Target Bodies(1) = 15
  Name = "Body 2"
  Equation = 1
  Material = 2
  Body Force = 1
  Initial condition = 1
End

Solver 1
  Equation = Result Output
  Procedure = "ResultOutputSolve" "ResultOutputSolver"
  Output File Name = case
  Output Format = Vtu
  Exec Solver = Always
End

Solver 2
  Equation = Heat Equation
  Procedure = "HeatSolve" "HeatSolver"
  Variable = -dofs 1 Temperature
  Exec Solver = Always
  Stabilize = True
  Bubbles = False
  Lumped Mass Matrix = False
  Optimize Bandwidth = True
  Steady State Convergence Tolerance = 1.0e-5
  Nonlinear System Convergence Tolerance = 1.0e-7
  Nonlinear System Max Iterations = 20
  Nonlinear System Newton After Iterations = 3
  Nonlinear System Newton After Tolerance = 1.0e-3
  Nonlinear System Relaxation Factor = 1
  Linear System Solver = Iterative
  Linear System Iterative Method = BiCGStab
  Linear System Max Iterations = 500
  Linear System Convergence Tolerance = 1.0e-10
  Linear System Preconditioning = ILU0
  Linear System ILUT Tolerance = 1.0e-3
  Linear System Abort Not Converged = False
  Linear System Residual Output = 1
  Linear System Precondition Recompute = 1
End

Equation 1
  Name = "Widerstaende"
  Active Solvers(2) = 1 2
End

Equation 2
  Name = "Probe"
  Phase Change Model = Spatial 2
check latent heat release = true
  Active Solvers(2) = 1 2
End

Material 1
  Name = "Aluminium (generic)"
  Enthalpy = variable temperature; Real procedure "PCMUDF" "phase"
  Heat expansion Coefficient = 23.1e-6
  Heat Conductivity = 100
  Sound speed = 5000.0
  Heat Capacity = 1300
  Mesh Poisson ratio = 0.35
  Density = 1000
  Poisson ratio = 0.35
  Youngs modulus = 70.0e9
End

Material 2
  Name = "Copper (generic)"
  Reference Temperature = 293
  Heat expansion Coefficient = 16.5e-6
  Heat Conductivity = 401.0
  Sound speed = 3810.0
  Heat Capacity = 385.0
  Mesh Poisson ratio = 0.34
  Density = 8960.0
  Poisson ratio = 0.34
  Youngs modulus = 115.0e9
End

Body Force 1
  Name = "BodyForce 1"
  Heat Source = variable time;real;0.0 500;40.0 500;40.1 0;80.0 0;end
End

Initial Condition 1
  Name = "InitialCondition 1"
  Temperature = 340
End
Thanks in advance!
Greetings,
X=0
mzenker
Posts: 1998
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: Phase change / switch variable

Post by mzenker »

Hi,

short answer: yes it is, see here.

HTH,

Matthias
XisZero
Posts: 14
Joined: 11 Sep 2014, 12:10
Antispam: Yes

Re: Phase change / switch variable

Post by XisZero »

Thanks a lot! haven´t found that ...
annier
Posts: 1142
Joined: 27 Aug 2013, 13:51
Antispam: Yes

Re: Phase change / switch variable

Post by annier »

Hi X=0,
1. So, you are making 2 solver input files each for phase changes during temperature rise and recrystallization. Very useful and lucid codes. Also, did you complete inserting the time dependence of enthalpy in your UDF?
2. For the UDF of subcool or recrystallization, is it the requirement of Heat Solver to associate UDF with GetMaterial() and GetConstReal() or you did it just for alert of error?

Yours
Anil Kunwar
Anil Kunwar
Department of Materials Engineering, KU Leuven, Belgium
Post Reply