-
Notifications
You must be signed in to change notification settings - Fork 247
Converting Gmsh mesh format to MDPA
It is possible to convert Gmsh native mesh format (.msh) to MDPA, Kratos' native mesh format) using meshio's mdpa module.
Besides the geometry, MDPA format also includes data which is not available in the Gmsh mesh, particularly:
- MDPA distinguishes two types of cells: elements and conditions
meshio
's mdpa module will categorize cells into elements or conditions (the cells on which the boundary conditions are applied)
based on their dimension, i.e., 3D cells are considered elements and any other cell is considered a condition.
- Each element or condition in the MDPA file does not only represent the geometry of the cell, but also its physics.
After conversion, meshio
will return cell types based only on their geometry.
The user may need to edit the MDPA file and rename the elements and conditions accordingly to the name required by its application.
This step can added to the conversion script.
List of possible cell names returned by meshio
:
- Line3D2
- Triangle3D3
- Quadrilateral3D4
- Tetrahedra3D4
- Hexahedra3D8
- Prism3D6
- Line3D3
- Triangle3D6
- Quadrilateral3D9
- Tetrahedra3D10
- Hexahedra3D27
- Point3D
- Quadrilateral3D8
- Hexahedra3D20
- Create your .geo gmsh geometry, defining physical volumes and surfaces
- Generate its .msh mesh
- Use
meshio
to convert .msh to .mdpa - Rename elements and conditions
A small working example of the steps above, going from the initial definition of the geometry file until the final .mdpa file.
This step depends on your system.
The official repository of meshio
does not have the last version of the MDPA module yet.
For now, you can clone our forked repository.
We'll update these instructions when/if the module makes it into the official repository.
Clone the repository, and make sure that the PYTHONPATH
environment variable is properly set:
cd /path/to/
git clone git@github.com:marandra/meshio.git
export PYTHONPATH=/path/to/meshio/src:$PYTHONPATH
Create a file cylinder.geo
:
// geometry:
// Lx
// ____________
// | |
// cy - O | Ly
// |___,________|
// cx
Ly = 1;
Lx = 5;
Lz = 0.1;
cr = 0.1;
cy = 0.0;
cx = 1.25;
pCC = newp; Point(pCC) = { cx, cy, -Lz/2};
p00 = newp; Point(p00) = { 0, -Ly/2, -Lz/2, 0.4};
p01 = newp; Point(p01) = { Lx, -Ly/2, -Lz/2, 0.4};
p03 = newp; Point(p03) = { cx+cr, 0, -Lz/2, 0.4};
p04 = newp; Point(p04) = { cx, -cr, -Lz/2, 0.4};
p05 = newp; Point(p05) = { cx-cr, 0, -Lz/2, 0.4};
p07 = newp; Point(p07) = { 0, Ly/2, -Lz/2, 0.4};
p08 = newp; Point(p08) = { Lx, Ly/2, -Lz/2, 0.4};
p09 = newp; Point(p09) = { cx, cr, -Lz/2, 0.4};
l00 = newl; Line(l00) = {p00, p01};
l01 = newl; Line(l01) = {p01, p08};
l03 = newl; Circle(l03) = {p03, pCC, p04};
l04 = newl; Circle(l04) = {p04, pCC, p05};
l07 = newl; Circle(l07) = {p05, pCC, p09};
l08 = newl; Circle(l08) = {p09, pCC, p03};
l10 = newl; Line(l10) = {p08, p07};
l11 = newl; Line(l11) = {p07, p00};
Transfinite Line{l03} = 4;
Transfinite Line{l04} = 4;
Transfinite Line{l07} = 4;
Transfinite Line{l08} = 4;
ll0 = newll; Curve Loop(ll0) = {l00, l01, l10, l11};
ll1 = newll; Curve Loop(ll1) = {l03, l04, l07, l08};
wall = news; Plane Surface(wall) = {ll0, ll1};
BoundingBox;
box[] = Extrude{0, 0, Lz}{Surface{wall}; Layers{1};};
Physical Volume("Fluid") = {box[1]};
Physical Surface("Symm") = {wall, box[0]};
Physical Surface("Outlet") = {box[3]};
Physical Surface("Walls") = {box[2], box[4]};
Physical Surface("Inlet") = {box[5]};
Physical Surface("Cylinder") = {box[6], box[7], box[8], box[9]};
Note the block with the definitions of the physical parts, that define the regions of interest of the mesh, where boundary and initial conditions will be applied.
gmsh -3 -o cylinder.msh cylinder.geo
That generates the following mesh:
Create a simple python script msh2mdpa.py
, for calling meshio
:
import sys
import meshio
fni = sys.argv[1]
fno = fni.rsplit('.', 1)[0] + ".mdpa"
m = meshio.read(fni)
meshio.write(fno, m, "mdpa")
and execute it:
python msh2mdpa.py cylinder.msh
The output will be a cylinder.mdpa
file, as shown below (edited):
...
Begin Nodes
1 0.0000000000000000e+00 -5.0000000000000000e-01 -5.0000000000000003e-02
...
204 1.1232090300445310e+00 -9.9985260714015506e-02 5.0000000000000003e-02
End Nodes
Begin Conditions Triangle3D3 // GUI group identifier: Symm
1000001 0 5 35 135
...
1000160 0 125 128 139
End Conditions
Begin Conditions Triangle3D3 // GUI group identifier: Walls
2000001 0 9 1 17
...
2000026 0 64 2 10
End Conditions
Begin Conditions Triangle3D3 // GUI group identifier: Outlet
3000001 0 10 2 29
...
3000006 0 66 7 11
End Conditions
...
Begin Elements Tetrahedra3D4 // GUI group identifier: Fluid
11000001 0 5 35 135 193
...
11000480 0 128 125 186 197
End Elements
...
The name of elements and conditions describe only their geometry. It is necessary to change their names to the actual elements and conditions required in the project. An example of the MDPA file after renaming:
...
Begin Nodes
1 0.0000000000000000e+00 -5.0000000000000000e-01 -5.0000000000000003e-02
...
204 1.1232090300445310e+00 -9.9985260714015506e-02 5.0000000000000003e-02
End Nodes
Begin Conditions Slip3D // GUI group identifier: Symm
1000001 0 5 35 135
...
1000160 0 125 128 139
End Conditions
Begin Conditions MonolithicWallCondition3D3N // GUI group identifier: Walls
2000001 0 9 1 17
...
2000026 0 64 2 10
End Conditions
Begin Conditions AutomaticInlet3D_Inlet // GUI group identifier: Inlet
3000001 0 10 2 29
...
3000006 0 66 7 11
End Conditions
...
Begin Elements Element3D4N // GUI group identifier: Fluid
11000001 0 5 35 135 193
...
11000480 0 128 125 186 197
End Elements
...
Finally, add the mesh to ProjectParameters.json:
"solver_settings" : {
...
"model_import_settings" : {
"input_type" : "mdpa",
"input_filename" : "cylinder"
},
},
...
- Getting Kratos (Last compiled Release)
- Compiling Kratos
- Running an example from GiD
- Kratos input files and I/O
- Data management
- Solving strategies
- Manipulating solution values
- Multiphysics
- Video tutorials
- Style Guide
- Authorship of Kratos files
- Configure .gitignore
- How to configure clang-format
- How to use smart pointer in Kratos
- How to define adjoint elements and response functions
- Visibility and Exposure
- Namespaces and Static Classes
Kratos structure
Conventions
Solvers
Debugging, profiling and testing
- Compiling Kratos in debug mode
- Debugging Kratos using GDB
- Cross-debugging Kratos under Windows
- Debugging Kratos C++ under Windows
- Checking memory usage with Valgind
- Profiling Kratos with MAQAO
- Creating unitary tests
- Using ThreadSanitizer to detect OMP data race bugs
- Debugging Memory with ASAN
HOW TOs
- How to create applications
- Python Tutorials
- Kratos For Dummies (I)
- List of classes and variables accessible via python
- How to use Logger
- How to Create a New Application using cmake
- How to write a JSON configuration file
- How to Access DataBase
- How to use quaternions in Kratos
- How to do Mapping between nonmatching meshes
- How to use Clang-Tidy to automatically correct code
- How to use the Constitutive Law class
- How to use Serialization
- How to use GlobalPointerCommunicator
- How to use PointerMapCommunicator
- How to use the Geometry
- How to use processes for BCs
- How to use Parallel Utilities in futureproofing the code
- Porting to Pybind11 (LEGACY CODE)
- Porting to AMatrix
- How to use Cotire
- Applications: Python-modules
- How to run multiple cases using PyCOMPSs
- How to apply a function to a list of variables
- How to use Kratos Native sparse linear algebra
Utilities
Kratos API
Kratos Structural Mechanics API