Elmer in FreeCAD - Tutorial Challenge - Tutorial 4

About the development of the FEM module/workbench.

Moderator: bernd

RatonLaveur
Posts: 991
Joined: Wed Mar 27, 2019 10:45 am

Elmer in FreeCAD - Tutorial Challenge - Tutorial 4

Post by RatonLaveur »

Hello gents,

Following up on Tutorial 1 (https://forum.freecadweb.org/viewtopic.php?f=18&t=56590), I explored how to use FreeCAD to solve tutorials sequentially through the Elmer non-GUI tutorials found specifically here: http://www.nic.funet.fi/pub/sci/physics ... GUI.tar.gz
(https://www.csc.fi/web/elmer/documentation)

Looking at tutorials 2 and 3, I determined that there is not enough information in the tutorial document to simply recreate the cases. Specifically, no dimensions are given for the problem, which defeats the purpose of using FreeCAD for drawing and setting up the case, for example.
Also the Elmer implementation in FreeCAD is not yet sufficient to run all types of cases (given the capabilities of Elmer, it is EVIDENT, that the wonderful guys who implemented what already exists in FC did a great job, but the road is long :) )
Faced with these difficulties I browsed all the way to Tutorial 4, which seemed already closer to something I could tackle mostly through FreeCAD.

What and adventure!

The objectives of this thread:
1. To have some fun
2. To relentlessly test the capabilities of the Elmer implementation in FreeCAD
3. To find bugs and possible issues
4. To guide the people interested in developing the Elmer implementation further by showing where work may be needed
5. To popularize and showcase the great synergies of FreeCAD and the Elmer solver.

We are moving to
Tutorial 4: Induction heating of a graphite crucible

Let's go.

My observations through this tutorial actually dispelled some of my issues that made me skip tuto2 and tuto3. The tutorial-nongui document is not sufficient in itself. One needs to download the tutorial files, and observe them through the ElmerGUI, to see exactly how the case is defined geometrically. The attached sif file is also capital in understanding how the case is set up.

In this post, due to my lack of knowledge I ended up solving the following problems:

1. How to design 2D cases with multi-materials in FreeCAD.
2. How to make sure a multi-area mesh works.
3. How to translate an Elmer defined sif file (provided by the Elmer team) and apply it to the case made in FreeCAD.

In the following posts I will try further to create more of the case directly in FreeCAD (I think MagneticFlux + Heat equations can achieve it, but have not tried yet).

Challenge: re-creating the geometry in FreeCAD and understanding what is what
2021-03-20 18_18_19.png
2021-03-20 18_18_19.png (191.14 KiB) Viewed 4088 times
2021-03-20 18_17_53.png
2021-03-20 18_17_53.png (38.78 KiB) Viewed 4088 times
It is easy to simply create sketches and use the Part: MakeFacefromWires

Followed by a boolean operation, warning, all boolean operations are not equal when considering an FEM case that has to be meshed!

Challenge: meshing in a coherent and controlled manner
2021-03-20 18_18_36.png
2021-03-20 18_18_36.png (162.58 KiB) Viewed 4088 times
2021-03-13 19_10_13.png
2021-03-13 19_10_13.png (70.54 KiB) Viewed 4088 times
Challenge: setting up the case
Here the challenge was as much with the driver (me) than the car (Elmer in FreeCAD).

Driver: I have fought to understand how to setup the case, and I had not even realized it needs to be multi-physical (Flux & Heat)! I had forgotten to set the surrounding domain with Air.

Car: Material cards are simply not right, the user needs to add electrical conductivity as a user defined property for example. Not sure yet if the currently implemented equations in FreeCAD allow the setting up of the case (subject of further posting from me in this thread).
Searching text in the "writer.py" file for Elmer, "Body Force" is not written, so I'm pretty sure not everything can be setup just yet.
The automated sif writing in FreeCAD through "writer.py" is quite messy at the moment, many things are out of order or grouped in a way that is very different than what the Elmer team typically writes. It makes reviewing and modifying the case quite difficult.

Here below the sif file provided by the Elmer team:

Code: Select all

! Historical tutorial case
! Updated 3.8.2020 P.R.

Check Keywords Warn

Header
  Mesh DB "." "crucible"
  Include Path ""
  Results Directory ""
End

Simulation
  Coordinate System = "Axi Symmetric"
  Simulation Type = Steady State
  Steady State Max Iterations = 1
  Max Output Level = 7
  Output File = "crucible.result"
  Post File = "crucible.vtu"
End

Constants
  Permittivity Of Vacuum = 8.8542e-12
End

Body Force 1
  Current Density = 2.5e5
End

Body Force 2
  Joule Heat = Logical True
End



Body 1
  Name = "Air"
  Equation = 1
  Material = 1
End

Body 2
  Name = "Coil"
  Equation = 1
  Material = 1
  Body Force = 1
End

Body 3
  Name = "Insulation"
  Equation = 1
  Material = 2
  Body Force = 2
End

Body 4
  Name = "Graphite"
  Equation = 1
  Material = 3
  Body Force = 2
End

Body 5
  Name = "Powder"
  Equation = 1
  Material = 4
  Body Force = 2
End

Equation 1
  Name = "Vector Potential Equation"
  Active Solvers(2) = 1 2
End

Solver 1
  Equation = Potential Solver
  Variable = Potential
  Variable DOFs = 2

  Angular Frequency = Real 50.0e3
  Calculate Joule Heating = Logical True
!  Calculate Magnetic Flux = Logical True
  Desired Heating = Real 3.0e3

  Procedure = "StatMagSolve" "StatMagSolver"
  Linear System Solver = Iterative
  Linear System Iterative Method = BiCGStab
  Linear System Max Iterations = 300
  Linear System Convergence Tolerance = 1.0e-10
  Linear System Preconditioning = ILU1
  Linear System ILUT Tolerance = 1.0e-03
  Linear System Residual Output = 10
  Nonlinear System Max Iterations = 1
  Nonlinear System Convergence Tolerance = 1.0e-6
  Nonlinear System Relaxation Factor = 1
  Steady State Convergence Tolerance = 1.0e-6
End


Solver 2
  Equation = Heat Equation
  Procedure = "HeatSolve" "HeatSolver"
  Variable = Temperature
  Stabilize = True
  Steady State Convergence Tolerance = 1.0e-5
  Nonlinear System Convergence Tolerance = 1.0e-5
  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-8
  Linear System Preconditioning = ILU0
  Linear System ILUT Tolerance = 1.0e-3
  Linear System Abort Not Converged = False
  Linear System Residual Output = 10
  Linear System Precondition Recompute = 1
End


Material 1
  Name = "Air"
  Electric Conductivity = 0.0
  Heat Conductivity = 1.0
  Density = 1.0
End

Material 2
  Name = "Insulation"
  Electric Conductivity = 2.0E3
  Heat Conductivity = 1.0
  Density = 1.0
End

Material 3
  Name = "Graphite"
  Electric Conductivity = 2.0E4
  Heat Conductivity = 1.0
  Density = 1.0
End

Material 4
  Name = "Powder"
  Electric Conductivity = 1.0E4
  Heat Conductivity = 1.0
  Density = 1.0
End

Boundary Condition 1
  Target Boundaries = 1
  Potential 1 = Real 0.0
  Potential 2 = Real 0.0
  Temperature = 293
End

Solver 1 :: Reference Norm = 9.22429576E-06
Solver 2 :: Reference Norm = 2.93337866E+02


!End Of File

Here the case as setup by me:

Code: Select all

Check Keywords Warn

Header
  Mesh DB "."
End

Solver 1
	Equation = Potential Solver
	Variable = Potential
	Variable DOFs = 2
	Angular Frequency = Real 50.0e3
	Calculate Joule Heating = Logical True
	Calculate Magnetic Flux = Logical True
	Desired Heating = Real 3.0e3
	Procedure = "StatMagSolve" "StatMagSolver"
	Linear System Solver = Iterative
	Linear System Iterative Method = BiCGStab
	Linear System Max Iterations = 300
	Linear System Convergence Tolerance = 1.0e-10
	Linear System Preconditioning = ILU1
	Linear System ILUT Tolerance = 1.0e-03
	Linear System Residual Output = 1
	Nonlinear System Max Iterations = 1
	Nonlinear System Convergence Tolerance = 1.0e-6
	Nonlinear System Relaxation Factor = 1
	Steady State Convergence Tolerance = 1.0e-6
End

Solver 2
  Equation = Heat Equation
  Procedure = "HeatSolve" "HeatSolver"
  Variable = Temperature
  Stabilize = True
  Steady State Convergence Tolerance = 1.0e-5
  Nonlinear System Convergence Tolerance = 1.0e-5
  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-8
  Linear System Preconditioning = ILU0
  Linear System ILUT Tolerance = 1.0e-3
  Linear System Abort Not Converged = False
  Linear System Residual Output = 10
  Linear System Precondition Recompute = 1
End

Simulation 
  BDF Order = Integer 1
  Coordinate Mapping(3) = Integer 1 2 3
  Coordinate Scaling = Real 0.001
  Coordinate System = String "Axi Symmetric"
  Output Intervals = Integer 1
  Simulation Type = String "Steady state"
  Steady State Max Iterations = Integer 1
  Steady State Min Iterations = Integer 0
  Timestepping Method = String "BDF"
  Use Mesh Names = Logical True
End

Constants
  Permittivity Of Vacuum = 8.8542e-12
End

Body Force 1
  Current Density = 2.5e5
End

Body Force 2
  Joule Heat = Logical True
End

Body 1
  Equation = Integer 1
  Material = Integer 1
  Name = String "Face1"
  Body Force = 2
End

Material 1
  Name = "Graphite"
  Electric Conductivity = 2.0E4
  Heat Conductivity = 1.0
  Density = 1.0
End

Equation 1
  Active Solvers(2) = Integer 1 2
End

Solver 2
  Coordinate Scaling Revert = Logical True
  Equation = String "ResultOutput"
  Exec Solver = String "After simulation"
  Output File Name = File "case"
  Procedure = File "ResultOutputSolve" "ResultOutputSolver"
  Vtu Format = Logical True
End

Body 2
  Equation = Integer 2
  Material = Integer 2
  Name = String "Face2"
  Body Force = 2
End

Material 2
  Name = "Insulation"
  Electric Conductivity = 2.0E3
  Heat Conductivity = 1.0
  Density = 1.0
End

Equation 2
  Active Solvers(2) = Integer 1 2
End

Body 3
  Equation = Integer 3
  Name = String "Face3"
  Body Force = 1
  Material = 5
End

Equation 3
  Active Solvers(2) = Integer 1 2
End

Body 4
  Equation = Integer 4
  Material = Integer 3
  Name = String "Face4"
  Body Force = 2
End

Material 3
  Name = "Powder"
  Electric Conductivity = 1.0E4
  Heat Conductivity = 1.0
  Density = 1.0
End

Equation 4
  Active Solvers(2) = Integer 1 2
End

Body 5
  Equation = Integer 5
  Name = String "Face5"
  Material = 5
End

Material 5
	Name = "Air"
  Electric Conductivity = 0.0
  Heat Conductivity = 1.0
  Density = 1.0
End

Equation 5
  Active Solvers(2) = Integer 1 2
End

Body 6
  Equation = Integer 6
  Name = String "Face6"
  Material = 5
End

Equation 6
  Active Solvers(2) = Integer 1 2
End


Boundary Condition 1
  Name = String "Edge21"
  Potential 1 = Real 0.0
	Potential 2 = Real 0.0
	Temperature = 293
End

Boundary Condition 2
  Name = String "Edge22"
  Potential 1 = Real 0.0
	Potential 2 = Real 0.0
	Temperature = 293
End

Boundary Condition 3
  Name = String "Edge23"
  Potential 1 = Real 0.0
	Potential 2 = Real 0.0
	Temperature = 293
End

Here is the crux of the exercise I accomplished and document here: I designed the case in FreeCAD completely, I only copied everything from the Elmer team provided sif file in the end, so the challenge was how to make sure that the features in the original sif (domains, boundaries...etc) are properly translated to FreeCAD. To help I created a "Fake case" that wrote boundary conditions and materials in FreeCAD so that the placeholders would be there to help me translate (if that makes sense).

The result:
2021-03-20 18_19_14.png
2021-03-20 18_19_14.png (130.88 KiB) Viewed 4088 times
Anyway I need to spend more time on this particular case, to understand it better and see how far I can go in FreeCAD entirely.

If anything it proves that this workflow could work: use a case entirely setup by the Elmer team, create a similar case in FreeCAD (or modified) and translate the sif files for compatibility.

To me the biggest difficulty this time was: understanding what the Elmer team had in mind with this case. Untangling the wildly diverging sif file organization between typical Elmer sif files and FreeCAD automated sif file.

Hope you find it interesting!
thschrader
Veteran
Posts: 3155
Joined: Sat May 20, 2017 12:06 pm
Location: Germany

Re: Elmer in FreeCAD - Tutorial Challenge - Tutorial 4

Post by thschrader »

RatonLaveur wrote: Sat Mar 20, 2021 5:38 pm ...
The objectives of this thread:
1. To have some fun
2. To relentlessly test the capabilities of the Elmer implementation in FreeCAD
3. To find bugs and possible issues
4. To guide the people interested in developing the Elmer implementation further by showing where work may be needed
5. To popularize and showcase the great synergies of FreeCAD and the Elmer solver.
...
Hope you find it interesting!
Yes, very interesting. Amazing job man!
Nobody expects a PHd thesis.

I use ccx-solver on daily engineering work.
Lets put elmer to the same status.

My laptop still kills elmer solver. Aaaahh...

Regards Thomas

Keep up the spirit
theTruth.JPG
theTruth.JPG (21.43 KiB) Viewed 4070 times
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Elmer in FreeCAD - Tutorial Challenge - Tutorial 4

Post by uwestoehr »

I would like to join the party to help bringing Elmer fully alive with FC.

I can contribute my CAD file I have so far:
Crucible-heating.FCStd
CAD file
(622.19 KiB) Downloaded 78 times
(I see that you made the coil 12 units high as the insulation, but the coil is only 8 units high as the graphite.)

I am stuck with the material editor. I created a material card for graphite:
Graphite.txt
rename this to Graphite.FCMat
(598 Bytes) Downloaded 130 times

I encounter several issues:
1. the file content is not Unicode, thus the umlaut in my name is mangled
2. In the material dialog I cannot load the file. I can also not open the file in the material editor because when I do, it shows me an empty card.

The bug is point 1. When I remove the Umlaut, I can at least load the card in the material editor, but still not in the material dialog.
But OK, I loaded the file but when I open the material again I see this:
FreeCAD_fvSo9yHYmR.png
FreeCAD_fvSo9yHYmR.png (8.08 KiB) Viewed 4038 times
3. So the material is shown there as "_document_material".

4. But OK, I open the material editor via the button "use FreeCAD material editor".
result: I get an empty card. Argh!

5. So I try to load the card again, but then the file explorer opens in my installation folder and not in the folder of the material card. So obviously the material card setting is lost.

6. And the issue continues:
- open the material dialog
- click on "use FreeCAD material editor"
- close the material editor with Cancel
- close the material dialog with OK

result: FreeCAD is now in a state in which it thinks there is still a task dialog open. So you cannot reopen the material dialog.

I fiddled now around for one hour to find a workaround but have to give up :(

Inviting Bernd to the material party.
bernd wrote: .
------------

@Besides the material troubles, I see that you made the
RatonLaveur
Posts: 991
Joined: Wed Mar 27, 2019 10:45 am

Re: Elmer in FreeCAD - Tutorial Challenge - Tutorial 4

Post by RatonLaveur »

@tschrader, really liked the little poem, thank you

@uwestoehr, after setting up and selecting the material, the drop-down menu seems to reset, properties however are maintained.

The coil is 8 in the .pdf document but it is 12 in the .grd file provided by the Elmer team (see my screenshot for case definition).

I also made a mistake in my case, I manually added Solver 2 for the Heat Equation, but did not modify Solver 2 for the generation of .vtu file (a "fake" solver added by HoWil to create the correct final data for FreeCAD). Therefore the sim may have done something unexpected, need to double check.

If anyone modifies the Solvers accordingly don't forget for all Equations to add solver 3 to the list of active solvers.

In the Elmer team sif, they call Equation only once (it is therefore active for all bodies). In the FreeCAD sif Equation is called for each body.

I also have no clue where Elmer defines the location of the axisymmetry. Peter Raback explained that a 2D case had to be in XY in Elmer, so perhaps if I extrapolate based on this case, axisymmetry must be around the Y axis.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Elmer in FreeCAD - Tutorial Challenge - Tutorial 4

Post by uwestoehr »

uwestoehr wrote: Sun Mar 21, 2021 4:37 am IInviting Bernd to the material party.
To to hijack this thread, I started a new one for the material card issues: https://forum.freecadweb.org/viewtopic.php?f=18&t=56912
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Elmer in FreeCAD - Tutorial Challenge - Tutorial 4

Post by bernd »

uwestoehr wrote: Sun Mar 21, 2021 4:37 am 6. And the issue continues:
- open the material dialog
- click on "use FreeCAD material editor"
- close the material editor with Cancel
- close the material dialog with OK

result: FreeCAD is now in a state in which it thinks there is still a task dialog open. So you cannot reopen the material dialog.
confirmed
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Elmer in FreeCAD - Tutorial Challenge - Tutorial 4

Post by bernd »

bernd wrote: Sun Mar 21, 2021 9:58 pm
uwestoehr wrote: Sun Mar 21, 2021 4:37 am 6. And the issue continues:
- open the material dialog
- click on "use FreeCAD material editor"
- close the material editor with Cancel
- close the material dialog with OK

result: FreeCAD is now in a state in which it thinks there is still a task dialog open. So you cannot reopen the material dialog.
confirmed
git commit 011cef1e7bab
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Elmer in FreeCAD - Tutorial Challenge - Tutorial 4

Post by bernd »

uwestoehr wrote: Sun Mar 21, 2021 4:37 am ...
4. But OK, I open the material editor via the button "use FreeCAD material editor".
result: I get an empty card. Argh!
...

- load your file
- open material
- edit with material editor
- it is not empty for me

am I missing something?
raback
Posts: 75
Joined: Fri May 08, 2020 4:02 pm
Location: Finland
Contact:

Re: Elmer in FreeCAD - Tutorial Challenge - Tutorial 4

Post by raback »

Hi

You have done a great work with the tutorial!

You were wondering what the Elmer team had in mind with this. Well, I made my thesis long ago about sublimation growth of silicon carbide crystals (like in the blue led of PS4). This was basically a simple furnace. When I later moved from my own code to Elmer I tested that I could get similar results. Induction heating of cylindrically symmetric crucibles is used a lot to achieve easily high temperatures.

There are some variations among the style how people prefer to write Elmer solver input files (=sif). I use two spaces for tabulation and empty line between sections as in the example. There are also other styles. The order of sections is not strict. The whole sif file is read in before being analyzed and run (actually you can run the input so far by writing "RUN" to the sif file, but that's hardly ever used.). Still it makes sense to have more fundamental things first (Header, Simulation, Constants) and spare the most variable stuff to the end (Boundary Conditions).

The tutorials are since some time open, see
https://github.com/ElmerCSC/elmerfem-manuals

We would be happy to co-write some cases. Our cases often lack geometric complexity needed in real-world cases. Demonstrating some real world cases from geometry to solution could be generally of interest.

We have currently a weekly free webinar on Elmer, see
https://ssl.eventilla.com/event/ng1zO

We will have still one meeting for by Elmer team and then go to contributed cases. Perhaps FreeCAD plugin developers would like to take a slot on the webinar in May? It would certainly be of interest to many.

BR, Peter
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Elmer in FreeCAD - Tutorial Challenge - Tutorial 4

Post by uwestoehr »

This tutorial challenge is ideal to improve FEM since there are many things missing to perform a multiphysics simulation.

In this tutorial we need to specify the electrical conductivity and since FreeCAD did neither know this parameter and can also not handle typical values of MS/m, I implemented electrical conductivity and the units kS and MS: https://github.com/FreeCAD/FreeCAD/pull/4647

@Bernd, please review and put it in if it is OK. I tested by creating a material card for Graphite that defines the electrical conductivity:
Graphite.txt
(585 Bytes) Downloaded 68 times
Post Reply