Code to get node data…
// Get all nodes
var nodes = new Dictionary<int, double[]>;
IntPtr[] nodeTagsIntPtr;
double[] coords;
Gmsh.Mesh.GetNodes(out nodeTagsIntPtr, out coords, 3, -1, true, false);
for (int i = 0; i < nodeTagsIntPtr.Length; ++i)
{
var nodeTag = (int)nodeTagsIntPtr[i];
var nodeCoord = new double[] { coords[i * 3], coords[i * 3 + 1], coords[i * 3 + 2] };
nodes[nodeTag] = nodeCoord;
}
… and element data…
var elements = new Dictionary<int, int[]>();
var elementTypes = new Dictionary<int, int>();
int dimension = 3;
int[] elementTypesTemp;
IntPtr[][] elementTagsIntPtr;
IntPtr[][] elementNodeTags;
Gmsh.Mesh.GetElements(out elementTypesTemp, out elementTagsIntPtr, out elementNodeTags, dimension , -1);
// This reshuffling is required due to the way Gmsh
// organizes the returned element data
for (int i = 0; i < elementTypesTemp.Length; ++i)
{
var elementType = elementTypesTemp[i];
int dim, order, numNodes, numPrimaryNodes;
string elementName;
double[] localNodeCoords;
elementName = GmshCommon.Gmsh.Mesh.GetElementProperties(elementType, out dim, out order, out numNodes, out localNodeCoords, out numPrimaryNodes);
for (int j = 0; j < elementTagsIntPtr[i].Length; ++j)
{
var elementTag = (int)elementTagsIntPtr[i][j];
elementTypes[elementTag] = elementType;
var elementNodes = new int[numNodes];
for (int k = 0; k < numNodes; ++k)
{
elementNodes[k] = (int)elementNodeTags[i][j * numNodes + k];
}
elements[elementTag] = elementNodes;
}
}
Then, to make nodes in PrePoMax…
foreach (var entry in nodes)
{
model.Mesh.Nodes.Add(entry .Key, new FeNode(entry .Key, entry .Value));
}
…and elements…
var partId = 1;
foreach (var entry in elements)
{
// Element types from http://gmsh.info/doc/texinfo/gmsh.html#MSH-file-format
switch (elementTypes[entry.Key])
{
case (4): // 4-node tetrahedron.
model.Mesh.Elements.Add(entry.Key, new LinearTetraElement(entry.Key, partId , entry.Value));
break;
case (11): // 10-node second order tetrahedron
model.Mesh.Elements.Add(entry.Key, new ParabolicTetraElement(entry.Key, partId , entry.Value));
break;
case (...): // other element types...
model.Mesh.Elements.Add(entry.Key, new ...);
break;
default:
break;
}
}