Difference between revisions of "Contrib gmsh2ToFoam"

From OpenFOAMWiki
m (Example)
m (Example)
Line 48: Line 48:
 
Physical Volume("internalDomain") = {34};
 
Physical Volume("internalDomain") = {34};
 
</pre>
 
</pre>
Next generate a 3D mesh by executing the following command under <tt>cubeTetra/constant</tt> directory.
+
Next generate a 3D mesh <b>with Gmsh >= 2.0</b> by executing the following command under <tt>cubeTetra/constant</tt> directory.
 
<pre>
 
<pre>
 
> gmsh -3 -optimize cube.geo
 
> gmsh -3 -optimize cube.geo

Revision as of 07:30, 19 February 2007

Valid versions: OF version 13.png

1 Short Description

A modified gmshToFoam with support to .msh file format version 2.0 (ASCII type only) which became the standard in gmsh-2.0.0.

2 Usage

Identical to the original gmshToFoam. Gmsh2ToFoam can also handle the conventional (version 1.0) .msh file format and automatically detects the format version.

gmsh2ToFoam assigns physical entity names insted of automatically generated names (such as "patch0", "patch1", ...) for patches / cellZones / faceZones if a $PhysicalNames section is present in a .msh format version 2.0 file. To understand what this means, see the example below.

3 Example

First write a .geo file called cube.geo as follows and put it under cubeTetra/constant directory.

// A cube of side lengths 1

// Create edges
lc = 0.025;
Point(1) = {-0.5, -0.5, -0.5, lc}; Point(2) = { 0.5, -0.5, -0.5, lc};
Point(3) = { 0.5,  0.5, -0.5, lc}; Point(4) = {-0.5,  0.5, -0.5, lc};
Point(5) = {-0.5, -0.5,  0.5, lc}; Point(6) = { 0.5, -0.5,  0.5, lc};
Point(7) = { 0.5,  0.5,  0.5, lc}; Point(8) = {-0.5,  0.5,  0.5, lc};
Line(9) = {1,2}; Line(10) = {2,3}; Line(11) = {3,4}; Line(12) = {4,1};
Line(13) = {5,6}; Line(14) = {6,7}; Line(15) = {7,8}; Line(16) = {8,5};
Line(17) = {1,5}; Line(18) = {2,6}; Line(19) = {3,7}; Line(20) = {4,8};

// Create surface patches
Line Loop(21) = {9,10,11,12}; Line Loop(22) = {17,13,-18,-9};
Line Loop(23) = {18,14,-19,-10}; Line Loop(24) = {19,15,-20,-11};
Line Loop(25) = {20,16,-17,-12}; Line Loop(26) = {-16,-15,-14,-13};
Plane Surface(27)={21}; Plane Surface(28)={22};
Plane Surface(29)={23}; Plane Surface(30)={24};
Plane Surface(31)={25}; Plane Surface(32)={26};

// Create a volume
Surface Loop(33) = {27,28,29,30,31,32};
Volume(34) = {33};

// Naming physical entities (instead of numbering) is a new key feature in Gmsh 2.0.
// Name the patches
Physical Surface("inlet") = {31};
Physical Surface("outlet") = {29};
Physical Surface("lateral") = {28,30};
Physical Surface("bottomTop") = {27,32};

// Name the volume
// (Don't forget! Read Section 4.1 of Gmsh 2.0 Reference Manual carefully.)
Physical Volume("internalDomain") = {34};

Next generate a 3D mesh with Gmsh >= 2.0 by executing the following command under cubeTetra/constant directory.

> gmsh -3 -optimize cube.geo

And finally convert to OpenFOAM polyMesh by

> gmsh2ToFoam ../.. cubeTetra cube.msh

After that you can access the patches "inlet", "outlet", "lateral" and "bottomTop" by their names instead of automatically generated "patch0", "patch1", ... names. For example you can write the boundaryField of cubeTetra/0/U as follows.

boundaryField
{
    inlet
    {
        type            fixedValue;
        value           uniform (1.0 0.0 0.0);
    }
    outlet
    {
        type            convectiveOutlet;
        convectiveVelocity uniform 1.0;
    }
    lateral
    {
        type            fixedValue;
        value           uniform (0.0 0.0 0.0);
    }
    bottomTop
    {
        type            fixedValue;
        value           uniform (0.0 0.0 0.0);
    }
    defaultFaces
    {
        type            fixedValue;
        value           uniform (0.0 0.0 0.0);
    }
}

4 Technical

The only known incompatibility with the original gmshToFoam is that gmsh2ToFoam produces a fatal error if the mesh contains second-order elements, instead of silently ignoring them. This is simply due to saving my programming time of some 10 minutes so I could change the behavior upon request.

For feedback and discussion go to this thread on the Message Board.

5 Download

gmsh2ToFoam-20070219.tar.gz

6 History

7islands 08:10, 19 Feb 2007 (CET):

  • Assign physical entity names instead of automatically generating them (such as "patch0") for patches / cellZones / faceZones if a $PhysicalNames section is present in a version 2.0 .msh file.

7islands 03:32, 18 Feb 2007 (CET):

  • Incorporated primitivePatch::meshPointMap() call optimization from Bernhard's gmshToFoamMod.
  • Fixed correspondence between OpenFOAM cellZone/patch numbering and Gmsh physical/elementary entity tagging. The meaning of physical entity tag seems to be different between .msh file format versions.

7islands 03:30, 17 Feb 2007 (CET): Improved compatibility with .msh files generated by Windows versions of Gmsh.

7islands 13:28, 16 Feb 2007 (CET): First upload.