Running coupled DEM-FEM simulations
Descriptions:
This article describes how to couple Aspherix® with Elmer FEM, which comes bundled with your Aspherix® installation. For this we will take an open box that will be filled with particles. The box is fixed on the top boundaries and the rest is allowed to deform.
Setting up the FEM simulation
In order to run a Finite Element Method (FEM) simulation, an ElmerSolver Input File (SIF) is required. This is a plain text file with all Elmer settings. Although this file can be created via any text editor, it is advised to use the ElmerGUI (which is available on the elmerfem website) to generate the initial version. This file can be placed anywhere, as Elmer will use the plain text file named ELMERSOLVER_STARTINFO to locate the file. This file must be located in the main folder where the simulation is run, and should contain something like:
data/elmer_script.sif
With this setting, Elmer will look for an input file named elmer_script.sif, placed in the data folder within the simulation folder.
Elmer and ElmerGrid
The Elmer solver used in the coupled simulation is installed together with Aspherix.
However, in the preprocessing steps you will need ElmerGrid (https://www.nic.funet.fi/index/elmer/doc/ElmerGridManual.pdf),
which is a mesh generation and manipulation utility built into Elmer.
To install Elmergrid you need a standalone Elmer installation. On Ubuntu/Debian you can use
sudo apt-add-repository ppa:elmer-csc-ubuntu/elmer-csc-ppa
sudo apt-get update
sudo apt-get install elmerfem-csc
Further information and instructions on how to install the Elmer package can be found here: https://www.csc.fi/web/elmer/binaries.
Elmer input file
Following is a brief explanation of the sections in the Elmer input file. For more information, please refer to the Elmer documentation: http://www.elmerfem.org/blog/documentation/
Header section
The Header section must contain the following:
Header
CHECK KEYWORDS Warn
Mesh DB "meshes" "."
Include Path ""
Results Directory "post"
End
The Mesh DB setting contains the preceding path and folder name of the mesh database. In the example above, meshes is the name of the folder where the mesh files in the ElmerSolver format (.mesh.*) are found. If the mesh file is available in another file format, the ElmerGrid program (part of the Elmer installation) can be used to convert these into the ElmerSolver format. For example, if a mesh file is available in the *.unv format, it can be converted using:
ElmerGrid 8 2 my_mesh.unv -autoclean
Here the integers reflect the specific in- and output mesh file formats (see the ElmerGrid help for more information), and the -autoclean flag ensures the resulting ElmerSolver format mesh files will not contain any unnecessary information that might break the Elmer simulation. The default output folder can be adjusted by changing the Results Directory name.
Simulation section
In the Simulation section the following parameters must be modified: Timestep Intervals, Timestep Size and Exit Condition. These must be coupled to Aspherix® by setting them as Procedure with the library name being Aspherix_FEM_coupling and the correct function as shown below.
Simulation
Timestep Intervals = Procedure "Aspherix_FEM_coupling" "fem_timeintervals"
Timestep Size = Procedure "Aspherix_FEM_coupling" "fem_timestep"
Exit Condition = Procedure "Aspherix_FEM_coupling" "fem_exit_condition"
Simulation Type = Transient
Timestepping Method = BDF
BDF Order = 1
Partition Mesh = True
Partitioning Method = Zoltan
Output File Final Only = True
Output File = "fem_restart.txt"
Binary Output = True
Note that we currently only support Transient simulations. In the example above
the first order BDF time stepping method is used. The partitioning settings can be
used to minimize communication in case of a parallel simulation. Elmer will perform
an automatic partitioning of the mesh when Partition Mesh = True. In general, this
is the best approach, but if one of the automatic partitions becomes empty the
simulation might terminate shortly after starting. To circumvent this, one might
try manual partitioning. This can be achieved by setting Partition Mesh = False in the input file,
and when generating the mesh with ElmerGrid:
ElmerGrid 8 2 my_mesh.unv -autoclean -partition PX PY PZ
where PX, PY, and PZ denote the number of processors in each Cartesian direction.
Their product should match the number of processors PT to be used during the simulation.
This command will create a folder called my_mesh/partitioning.PT, where my_mesh and PT
depend on the mesh name and total number of processors, respectively. The partitioning.PT
folder should be moved to the same location where otherwise the .mesh.* files are.
The last three lines will ensure a binary restart file is written at the and of a simulation, which can be used to continue a simulation.
Boundary Condition sections
For each boundary condition where forces from DEM should be exchanged to the FEM side, the Force must be set to be a Procedure
with the Aspherix_FEM_coupling library and the correct function as shown below.
Boundary Condition 2
Target Boundaries(10) = 1 2 4 5 6 7 8 9 10 11
Name = "elastic box"
Force 1 = Variable Coordinate
Procedure "Aspherix_FEM_coupling" "mesh_force_x"
Force 2 = Variable Coordinate
Procedure "Aspherix_FEM_coupling" "mesh_force_y"
Force 3 = Variable Coordinate
Procedure "Aspherix_FEM_coupling" "mesh_force_z"
End
Note also the Name of the boundary condition as it is relevant for the setup of the DEM boundaries.
Solver section
The Solver on the FEM side should always be ElasticSolve as this is the only supported solver within Aspherix, so this section should contain (besides the (non)linear solver settings, which can be set via the ElmerGUI) the following:
Solver 1
Equation = Nonlinear elasticity
Procedure = "ElasticSolve" "ElasticSolver"
Variable = -dofs 3 Displacement
Setting up the DEM simulation
The setup on the DEM side requires at its core the enable_fem_coupling command. In its most basic version it is similar to the following:
enable_fem_coupling id fem coupling_timestep 1e-3
In order to properly couple DEM to FEM, the DEM stresses must be averaged over time. This can be achieved with the mesh_module stress_average:
mesh_module stress_average id avg exponential_averaging yes exponential_averaging_time 1e-2
The DEM mesh needs to be imported from the boundary mesh data on the FEM side with the mesh command and the from_command keyword, where the id of the enable_fem_coupling command is used as value. The boundary_condition_name is the same that was used in the Elmer input script (here elastic box). The mesh_module is applied to the mesh in this step.
mesh id moving_part from_command fem boundary_condition_name "elastic box" material m1 solid yes mesh_modules {avg}
Note you can also use this for FEM boundary conditions that do not deform based on forces. So for the rigid top boundary we can use
mesh id rigid_top from_command fem boundary_condition_name "rigid top" material m1 solid yes
Postprocessing in Paraview
The node deformations as determined by Elmer are synchronized with Aspherix® automatically, and these values can be written to the Paraview output files by adding the following commands to the DEM input file:
simulate time_steps 0
output_settings meshes { rigid_top, moving_part } mesh_properties { stress, area, f, deformation }
Here the first command will ensure the deformation mesh property is available when initializing the output_settings command.
Next, the relevant meshes and mesh_properties can be added to this output_settings command. Note that if no meshes are
specified, no mesh data will be written. If no mesh_properties are defined, all mesh properties (of type double) will be written
(which would also include the deformation).
Restarting a coupled simulation
To be able to restart a coupled simulation, both Aspherix® and Elmer must write restart files. For Aspherix® this can be done via the regular command for that:
write_restart dem_restart.basx
To allow Elmer to find the restart file, the following line should be added to the Simulation section of the Elmer input file:
Simulation
Restart File = "data/fem_restart.txt"
Here it should be ensured that the correct path for the restart file is used.
After all restart data is available, the coupled simulation can be restarted by adding the following line at the beginning of the Aspherix® input file:
read_restart dem_restart.basx
NB: depending on the commands used in the initial input file, it might be necessary to comment out some more commands (like a one-time-only particle insertion).
Some additional remarks
This feature should be considered experimental. It relies on coupling with an externally developed simulation package, which might sometimes lead to unexpected errors. For example, an Aspherix® error (due to an incorrect input file) might cause Elmer to crash with a segmentation fault. If something like this happens, please take a closer look at the log_aspherix.txt and warnings_aspherix.txt files as these might contain useful information on the cause of the error in the first place.
FAQ
None yet.