Elmer integration as a solver

There is some development of integrating Elmer into Salome going on which for sure we can benefit from.
It looks like that Rainer Jacob already wrote some code to nicely supply/extract all possible solver input setting out of the .edf (xml -files) files which are usually used by ElmerGUI.

The corresponding discussion can be found here…
http://elmerfem.org/forum/viewtopic.php?f=15&t=3636&start=0&sid=d10230fd798db4f6b8c37ba9f1756e5b

while the project can be found here
https://github.com/physici/ElmerSalomeModule/tree/master/ElmerSalome

BR,
HoWil

A bit offtopic. Is there an Elmer package for Debian Jessie available?

I personally use the the official Ubuntu ppa *) thats why I had to search with this results:

There is a relatively old version 7.0 in the experimental branch please see…
https://packages.debian.org/experimental/elmer
For just testing the solver it should be OK but you still have to compile the ElmerGUI if you want to use it too.

For sure there is also the possibility to compile all parts of Elmer see… http://www.elmerfem.org/elmerwiki/index.php?title=Compilation_and_Installation

*)
In the official ppa repo is the several days old, the latest version is 8.2-201611251631
https://launchpad.net/~elmer-csc-ubuntu/+archive/ubuntu/elmer-csc-ppa

@HoWil:
I’m gone try to compile ElmerFEM. I do not know anything about the Elmer languarge to define everything. Would it be possible to make an Elmerfile of the FreeCAD 3D FEM Cantilver Example and post it here. It is easier to test a new FEM with an well know example.

Bernd

Hi Bernd,

Attached you find a .zip file with the complete data regarding a Calculix-Elmer comparison which is discussed subsequently.
If you have a running Elmer and want to recompute the Elmer-project just open it with ‘File->Load Project’, navigate into the folder called ‘mesh_with_BC_from_FC-FEM’ and press ‘Open’.

A short step by step instruction how to rebuild the attached model in FreeCAD, Elmer and Paraview (using 0.17 from ppa and elmer from the official ppa) is given here:

##########################################################################
In FreeCAD:

* Open the standard 3D-FEM example on the start page under 'Example projects' called 'Load an FEM 3D example analysis.
* Select the mesh object called 'Box_Mesh' and delete it. The original Mesh was created with the integrated Netgen-Mesher (and has be recomputed with GMSH).
* Selet the object called 'Cube' and use 'FEM->FEM mesh from shape with GMSH' to generate a new mesh object.
* Select the new mesh object called 'Box_Mesh' and export it via 'File->Export' as 'mesh_with_BC_from_FC-FEM.unv'.
* Execute ElmerGrid in the folder where the exported .unv file is located with 'ElmerGrid 8 2 mesh_with_BC_from_FC-FEM.unv -autoclean'. This transvers the mesh including the boundary conditions stored in the .unv file into several Elmer-mesh files in an identically named folder.


##########################################################################
In ElmerGUI:

* Open the transfered mesh with 'File->Load mesh' by simply navigating into the prior generated folder called as the .unv file. The Mesh is now visible. 
* In 'Model->Setup->Simulation->Free_text' insert 'Coordinate scaling = 1'.
* 'Model->Equation->Add' and select in the column 'Linear elasticity' 'Acitve->on' and 'Apply to body-> Body1'. Select 'Edit Solver Settings' for in the current tab and there insert in the 'Solver specific options' in the 'Free text input' the string:'Element=p:2'. Than press 'Apply'.
Select in the 'Result Output' column the 'Active' field. 
Select 'Edit Solver Settings' for in the current tab and there insert in the 'Solver specific options' in the select in the 'General' tab under 'Execute solver' the point 'After simulation'.
Press 'Apply' and 'OK'.

* 'Model->Material-Add' and select 'Apply to body-> Body1' and select the 'Material library' -> Select 'Steel (alloy -generic)'. Adopt 'Youngs modulus' to '210.0e9' and 'Poisson ratio' to '0.3'.
 
* Under 'Model->Boundary condition->Add' in column 'Linear elasticity' set 'Displacement 1' and 'Displacement 2' and 'Displacement 3' to 0. Set 'Name:' to 'BoundaryConditionFixed'. Press 'OK'

* Under 'Model->Boundary condition->Add' in column 'Linear elasticity' set 'Force 2' to 9000000. Set 'Name:' to 'BoundaryConditionForce'. Press 'OK'

* Set 'Model->Set boundary properties' and select left boundary with a double-click. Choose 'BoundaryConditionFixed' from pull down-menu. Click 'Add'.

* Set 'Model->Set boundary properties' and select left boundary with a double-click. Choose 'BoundaryConditionForce' from pull down-menu. Click 'Add'.

* 'File->Save'
* 'File->Save Project'
* 'Sif->Generate'
* 'Run->Start solver'
* After the computation has finished: 'Run->Start paraview'.

##########################################################################
In Paraview:

Select the 'Properties' window press 'Apply' and select in the subgroup for 'Coloring' 'displacement' instead of 'Solid Color'.



The needed Elmer-Solver input file case.sif where all necessary definitions are listed looks like:

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 = Steady state
  Steady State Max Iterations = 1
  Output Intervals = 1
  Timestepping Method = BDF
  BDF Order = 1
  Solver Input File = case.sif
  Post File = case.vtu
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) = 1
  Name = "Body Property 1"
  Equation = 1
  Material = 1
End

Solver 2
  Equation = Linear elasticity
Element=p:2
  Variable = -dofs 3 Displacement
  Procedure = "StressSolve" "StressSolver"
  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
  BiCGstabl polynomial degree = 2
  Linear System Preconditioning = Diagonal
  Linear System ILUT Tolerance = 1.0e-3
  Linear System Abort Not Converged = False
  Linear System Residual Output = 1
  Linear System Precondition Recompute = 1
End

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

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

Material 1
  Name = "Steel (alloy - generic)"
  Heat expansion Coefficient = 12.0e-6
  Electric Conductivity = 1.367e6
  Heat Conductivity = 37.2
  Sound speed = 5100.0
  Heat Capacity = 976.0
  Mesh Poisson ratio = 0.285
  Density = 7850.0
  Poisson ratio = 0.3
  Youngs modulus = 210.0e9
End

Boundary Condition 1
  Target Boundaries(1) = 1 
  Name = "BoundaryConditionFixed"
  Displacement 3 = 0
  Displacement 2 = 0
  Displacement 1 = 0
End

Boundary Condition 2
  Target Boundaries(1) = 2 
  Name = "BoundaryConditionForce"
  Force 2 = 9000000
End

Note that boundary conditions can also be targeted by names from the .unv when simply accessing them by script and not using ElmerGUI.
Screenshot from 2016-11-29 20-50-52_FC_resized.png
Screenshot from 2016-11-29 20-51-11_Paraview_resized.png
Comparison Calculix_Elmer.zip (191 KB)

There is also a short presentation about the structure of .sif files… http://www.nic.funet.fi/pub/sci/physics/elmer/slides/TUT2014April/ElmerSolverInput_2014April.pdf

In the case that one wants now to reuse the given mechanical simulation model but wants to switch the boundaries, you would have to do the following steps:

  • generate a new mesh as .unv with the new faces grouped
  • translate it with ElmerGrid and copy the Elmer-Mesh-files into the project folder
  • Check if the defined ‘Target Boundaries’ do still match, see e.g. the prior boundary condition for boundary nr. 2:
  Target Boundaries(1) = 2

compiled the elmer solver and tried to run your example at the command line. Seams I’m missing something essential …

http://www.elmerfem.org/forum/viewtopic.php?f=2&t=4408&start=0&sid=e0b80af51fc3cbf835aca28dc710fcd6

How about just running ElmerSolver instead of its mpi counterpart?

I do not have a binary without mpi. Compiling without mpi fails. But this seams not to be the culprit.

the elemer solver says the example file has no mesh ?!? see http://www.elmerfem.org/forum/viewtopic.php?f=2&t=4408&p=15920&sid=87915662126e05a342d60087027a7124#p15920

Attached the results of CalculiX cantilever analyzed with ElmerFEM. Output format is vtu which is supported by FreeCAD FEM. But FreeCAD only reads the mesh data. A result object is not made.

The result files open fine in Paraview and the displacements could be visualized.

Bernd
ccx_canti–elmer_results.vtu.zip (44.3 KB)

This means at least that the toolchain FC-Elmer-Paraview does work!?

Did you generate the complete .sif or did you ‘just’ change adopt/recreate the mesh.

Did you use the boundary names from FC stored in the .unv file? They can be used with ‘Use Mesh Names = True’ as described here … http://www.elmerfem.org/forum/viewtopic.php?f=7&t=4220#p14925 ?

Is there a problem regarding the result inread? Do you need a special format? Elmer does support many different output formats. Please see also ‘6.3 Strategies for postprocessing’ on page 9 in ftp://lukusali.nic.funet.fi/ftp/index/Science/physics/elmer/doc/ElmerOverview.pdf

Hi bernd,

I started to have a look to the issue tonight, there are some new features that I didn’t know yet from the test I made earlier. First why is there an option while importing the results which is asking you through a popup, if we are importing a mesh or results ? Are we sure that selecting result is realling importing results as as you saied this is a mesh, and the import work fine. If it was focused on results it shouldnt import the mesh no ?

vejmarie

No not at all. See dvbranch https://github.com/berndhahnebach/FreeCAD_bhb/commits/femsolverelmer I just added the solver object and the modules needed. At the moment in any case the calculix cantilver is writen as elmer input. The elmer process handling is not implemented. My idea was to start with the result reading because elmer uses output format supported by FreeCAD FEM. I tried *.vtu but may be I should have tried *.vtk

@HoWil:
since you know elmer you could may be give it a try and import some *.vtu or *.vtk in FreeCAD and give some Feedback.

The new features Have been added by xing feng. I have not been used them. See https://github.com/FreeCAD/FreeCAD/commits?author=qingfengxia

With CalculiX it works the following way.

  • If a frd output file is imported in an empty an analysis, a FEMmesh and a result object is created.
  • If a frd is read from an analysis run just the result object is created in the active analysis. The mesh from the analysis should fit to the result object.


    IMHO it should work the same way with the vtk, vtu etc files, but I have never been imported one before.

Bernd

I tested my example from over here … http://forum.freecadweb.org/viewtopic.php?f=18&t=16630&start=20#p146553
as well as some other elmer results which all work fine in Paraview 5.0.1. All were imported into FC as .vtu and the example above also as .vtk but I always get only the mesh, no matter if I select results or mesh import!

Is my version of FC sufficiently up-to-date?

OS: Ubuntu 16.04.1 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.9177 (Git)
Build type: Unknown
Branch: femmeshregion
Hash: bba68d007c461ff80b4f72fe82e53b20a8600458
Python version: 2.7.12
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.0.0

actually it should work, and my implementation supported all kind of result data in the vtk files. Most likely this is a bug or something that got lost during the latest changes. I will try to have a look at this over the next days.

It might make sense if you would use my current FEM development branch to be sure my branch one does not make problems again. See https://github.com/berndhahnebach/FreeCAD_bhb/commits/femmeshregion

Hallo ickby,
Did you have time to look into this issue?
This is growing interest since almost all new external solver (Elmer, FeniCS, Openfoam) will output some kind of .vtk file or similar.
Thank you in advance,
HoWil

To solve CFD problem, you may reuse some of the code in CfdWorkbench, which is a split from FemWorkbench
https://github.com/qingfengxia/Cfd
This workbench is designed to fit in more solvers.

CfdSolverElmer.py derived from CfdSolver which defined most of setting for CFD, include elmer specific settings, example are CfdSolverFoam.py
CfdCaseWriterElmer.py expose only a write_case() method. write_mesh (which should be similar as Bernd has done)and write boundary condition
CfdRunnableElmer.py , then call the calculation and retrieve the result and display, CfdSolverControl can be reused with tiny modification

then add _CommandCfdSolverElmer.py _ViewProviderCfdSolverElmer.py, can be adapted from *Foam.py
add into CfdWorkbench via InitGui.py

CfdResultVTKElmer.py is needed to load result. curently this piece of code (CfdResult and taskpanel) is under review, there is no need to

FluidMaterial.py has several implementation, currently needs a unification.
FemConstraintFluidBoundary.cpp can be reused for common CFD boundary types