Difference between revisions of "Contrib gmsh2ToFoam"

From OpenFOAMWiki
Line 3: Line 3:
 
==Short Description==
 
==Short Description==
  
A modified <tt>gmshToFoam</tt> with .msh file format version 2.0 (ASCII type only) support which became the standard in Gmsh 2. <tt>Gmsh2ToFoam</tt> can also handle the conventional version 1.0 format.
+
A modified <tt>gmshToFoam</tt> with .msh file format version 2.0 (ASCII type only) support which became the standard in Gmsh 2.0. <tt>Gmsh2ToFoam</tt> can also handle the conventional version 1.0 format.
  
 
==Usage==
 
==Usage==
Identical to the original <tt>gmshToFoam</tt>. <tt>Gmsh2ToFoam</tt> automatically detects and handles the format version.
+
Identical to the original <tt>gmshToFoam</tt>. <tt>Gmsh2ToFoam</tt> automatically detects and handles the format versions.
  
 
==Features==
 
==Features==
<tt>Gmsh2ToFoam</tt> has several features over the original <tt>gmshToFoam</tt> that comes with OF 1.3 other than the .msh version 2.0 format file handling:
+
Other than the .msh version 2.0 format handling, <tt>gmsh2ToFoam</tt> has several features especially focused on practical usage over the original <tt>gmshToFoam</tt> that comes with OF 1.3:
  
* <tt>Gmsh2ToFoam</tt> assigns physical entity names (such as "inlet," "outlet," ...) 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.
+
====Patch/cellZone/faceZone labeling====
* In <tt>gmsh2ToFoam</tt> suffix numbers of automatically generated patch/cellZone/faceZone names ("patch1," ...) are determined based on original region numbers given in a .geo file, instead of the order of their appearence in a .msh file. This contributes easy correspondence between the .geo file and the final converted mesh.
+
* Assignment of physical region names ("inlet," "outlet," ...) defined in a .geo file insted of automatically generated names ("patch0," "patch1," ...) for patches/cellZones/faceZones if a <tt>$PhysicalNames</tt> section is present in a .msh version 2.0 file.
* <tt>Gmsh2ToFoam</tt> removes the <tt>defaultFaces</tt> patch if its size is determined to be zero. You don't have to write a dummy <tt>defaultFaces</tt> entry in boundary description.
+
* Assignment of suffix numbers of automatically generated patch/cellZone/faceZone names ("patch1," ...) based on the region numbers defined in a .geo file, instead of the order of their appearance in a .msh file, if the physical regions are labeled by numbers.
* <tt>Gmsh2ToFoam</tt> removes unreferred points (points which do not belong to any of faces nor cells e. g. spline control points or the center of a circular arc). <tt>CheckMesh</tt> test of the converted mesh does not fail anymore due to "Unused points."
+
 
* <tt>Gmsh2ToFoam</tt> has compatibility with .msh files generated by Windows versions of Gmsh.
+
The above two should contribute easy correspondence between the .geo file and the final converted mesh. To understand their meanings, see the example below.
* <tt>Gmsh2ToFoam</tt> produces a fatal error if the mesh contains second-order elements, instead of silently ignoring them.
+
 
 +
====Removal of unused patches/points====
 +
* Removal of the <tt>defaultFaces</tt> patch if its size is determined to be zero. You don't have to write a dummy <tt>defaultFaces</tt> entry in boundary description.
 +
* Removal of unreferred points (points which do not belong to any of faces nor cells; e. g. spline control points or the center of a circular arc). <tt>CheckMesh</tt> test of the converted mesh does not fail anymore due to "Unused points."
 +
 
 +
====Others====
 +
* Compatibility with .msh files generated by Windows versions of Gmsh.
 +
* Producing a fatal error if a mesh contains second-order elements, instead of silently ignoring them.
  
 
==Technical==
 
==Technical==
* Some features of <tt>gmsh2ToFoam</tt> described above are considered as intentional incompatibilities with <tt>gmshToFoam</tt>.
+
* <b>Be sure to label at least one physical region by a number other than 0 (zero) if all the physical regions are to be labeled by numbers.</b> This restriction comes from <tt>gmsh2ToFoam</tt> following one of the Gmsh authors' suggestion. See [http://www.geuz.org/pipermail/gmsh/2007/002395.html Gmsh mailing list archive] for details.
* Be sure to label at least one physical region by a number other than 0 if all the physical regions are to be labeled by numbers. This restriction comes from <tt>gmsh2ToFoam</tt> following one of the Gmsh authors' suggestion. See [http://www.geuz.org/pipermail/gmsh/2007/002395.html Gmsh mailing list archive] for details.
+
* Beware that if physical regions are defined in a .geo file, Gmsh writes .msh file only with those elements that belong to the physical regions. Read Section 4.1 of Gmsh 2.0 Reference Manual carefully before using the labeling features of <tt>gmsh2ToFoam</tt>.
 +
* <b><tt>Gmsh2ToFoam</tt> still has not been well tested</b>.
  
 
For feedback and discussion go to [http://openfoam.cfd-online.com/forum/messages/1/3841.html this thread] on the Message Board.
 
For feedback and discussion go to [http://openfoam.cfd-online.com/forum/messages/1/3841.html this thread] on the Message Board.
  
 
==Example==
 
==Example==
First write a .geo file called <tt>cube.geo</tt> as follows and put it under <tt>cubeTetra/constant</tt> directory. Especially note that surface patches and a volume are given their names (not numbers) of "inlet", "outlet", "lateral", "bottomTop" and "internalField" at the last part.
+
First write a .geo file called <tt>cube.geo</tt> as follows and put it under <tt>cubeTetra/constant</tt> directory. Especially note that at the last part surface patches and a volume are given their names (not numbers) of "inlet", "outlet", "bottomTop," "internalField" except the lateral patches given a common number of 10.
 
<pre>
 
<pre>
 
// A cube of side lengths 1
 
// A cube of side lengths 1
Line 55: Line 63:
 
Physical Surface("inlet") = {31};
 
Physical Surface("inlet") = {31};
 
Physical Surface("outlet") = {29};
 
Physical Surface("outlet") = {29};
Physical Surface("lateral") = {28,30};
+
Physical Surface(10) = {28,30}; // lateral patches
 
Physical Surface("bottomTop") = {27,32};
 
Physical Surface("bottomTop") = {27,32};
  
Line 70: Line 78:
 
> gmsh2ToFoam ../.. cubeTetra cube.msh
 
> gmsh2ToFoam ../.. cubeTetra cube.msh
 
</pre>
 
</pre>
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 <tt>cubeTetra/0/U</tt> as follows.
+
After that you can access the patches named "inlet," "outlet" and "bottomTop" by their names instead of automatically generated "patch0," "patch1," ... names. Besides, the patches labeled by the number of 10 is named "patch10," which means the number is retained in the suffix of automatically generated name. For example you can write the boundaryField of <tt>cubeTetra/0/U</tt> as follows.
 
<pre>
 
<pre>
 
boundaryField
 
boundaryField
Line 84: Line 92:
 
         convectiveVelocity uniform 1.0;
 
         convectiveVelocity uniform 1.0;
 
     }
 
     }
     lateral
+
     patch10
 
     {
 
     {
 
         type            fixedValue;
 
         type            fixedValue;
Line 96: Line 104:
 
}
 
}
 
</pre>
 
</pre>
Similarly the "internalField" is accessible with its name as a cellZone instead of automatically generated name of "cellZone_0".
+
Similarly the "internalField" is accessible with its name as a cellZone instead of automatically generated name of "cellZone_0."
 
+
If <tt>gmsh2ToFoam</tt> found an unnamed (and given an ID number) physical entity it will be given an automatically generated name of such as "patch0." Further, beware that if physical entities are defined, the output mesh only contains those elements that belong to physical entities. Read Section 4.1 of Gmsh 2.0 Reference Manual carefully before using this feature.
+
  
 
==Download==
 
==Download==

Revision as of 02:16, 6 March 2007

Valid versions: OF version 13.png

1 Short Description

A modified gmshToFoam with .msh file format version 2.0 (ASCII type only) support which became the standard in Gmsh 2.0. Gmsh2ToFoam can also handle the conventional version 1.0 format.

2 Usage

Identical to the original gmshToFoam. Gmsh2ToFoam automatically detects and handles the format versions.

3 Features

Other than the .msh version 2.0 format handling, gmsh2ToFoam has several features especially focused on practical usage over the original gmshToFoam that comes with OF 1.3:

3.1 Patch/cellZone/faceZone labeling

  • Assignment of physical region names ("inlet," "outlet," ...) defined in a .geo file insted of automatically generated names ("patch0," "patch1," ...) for patches/cellZones/faceZones if a $PhysicalNames section is present in a .msh version 2.0 file.
  • Assignment of suffix numbers of automatically generated patch/cellZone/faceZone names ("patch1," ...) based on the region numbers defined in a .geo file, instead of the order of their appearance in a .msh file, if the physical regions are labeled by numbers.

The above two should contribute easy correspondence between the .geo file and the final converted mesh. To understand their meanings, see the example below.

3.2 Removal of unused patches/points

  • Removal of the defaultFaces patch if its size is determined to be zero. You don't have to write a dummy defaultFaces entry in boundary description.
  • Removal of unreferred points (points which do not belong to any of faces nor cells; e. g. spline control points or the center of a circular arc). CheckMesh test of the converted mesh does not fail anymore due to "Unused points."

3.3 Others

  • Compatibility with .msh files generated by Windows versions of Gmsh.
  • Producing a fatal error if a mesh contains second-order elements, instead of silently ignoring them.

4 Technical

  • Be sure to label at least one physical region by a number other than 0 (zero) if all the physical regions are to be labeled by numbers. This restriction comes from gmsh2ToFoam following one of the Gmsh authors' suggestion. See Gmsh mailing list archive for details.
  • Beware that if physical regions are defined in a .geo file, Gmsh writes .msh file only with those elements that belong to the physical regions. Read Section 4.1 of Gmsh 2.0 Reference Manual carefully before using the labeling features of gmsh2ToFoam.
  • Gmsh2ToFoam still has not been well tested.

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

5 Example

First write a .geo file called cube.geo as follows and put it under cubeTetra/constant directory. Especially note that at the last part surface patches and a volume are given their names (not numbers) of "inlet", "outlet", "bottomTop," "internalField" except the lateral patches given a common number of 10.

// 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(10) = {28,30}; // lateral patches
Physical Surface("bottomTop") = {27,32};

// Name the volume
// (Don't forget! Read Section 4.1 of Gmsh 2.0 Reference Manual carefully.)
Physical Volume("internalField") = {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 named "inlet," "outlet" and "bottomTop" by their names instead of automatically generated "patch0," "patch1," ... names. Besides, the patches labeled by the number of 10 is named "patch10," which means the number is retained in the suffix of automatically generated name. 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;
    }
    patch10
    {
        type            fixedValue;
        value           uniform (0.0 0.0 0.0);
    }
    bottomTop
    {
        type            fixedValue;
        value           uniform (0.0 0.0 0.0);
    }
}

Similarly the "internalField" is accessible with its name as a cellZone instead of automatically generated name of "cellZone_0."

6 Download

Current version:


Past versions:

7 History

7islands 15:19, 5 Mar 2007 (CET):

  • Following one of the Gmsh authors' suggestion, another modification is made to physical/elementary region (entity) number handling. See Gmsh mailing list archive for details.
  • Automatically generated patche/cellZone/faceZone names ("patch1," ...) are now labeled by numbers based on original region numbers given in a .geo file, instead of the order of their appearence in a .msh file.
  • Deletes the defaultFaces patch if its size is determined to be zero.
  • Removes unreferred points.

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.