Fix Medit im-/export

This commit is contained in:
Matthias Hochsteger 2023-11-06 17:33:36 +01:00
parent fd3a5bbd34
commit c4bece8dc8
2 changed files with 20 additions and 13 deletions

View File

@ -3,7 +3,7 @@
namespace netgen namespace netgen
{ {
void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<int, tuple<int,int>> & index_map) void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<tuple<int,int>, int> & index_map)
{ {
static Timer tall("ReadMeditMesh"); RegionTimer rtall(tall); static Timer tall("ReadMeditMesh"); RegionTimer rtall(tall);
auto fin = ifstream(filename); auto fin = ifstream(filename);
@ -13,16 +13,16 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<int, t
int index_cnt[4] = {0,0,0,0}; int index_cnt[4] = {0,0,0,0};
auto getIndex = [&](int eldim, int index) { auto getIndex = [&](int eldim, int index) {
if(index_map.count(index)==0) { if(index_map.count({eldim,index})==0) {
auto n = ++index_cnt[eldim]; auto n = ++index_cnt[eldim];
index_map[index] = {eldim, n}; index_map[{eldim, index}] = n;
if(eldim==2) { if(eldim==2) {
auto fd = FaceDescriptor(n-1,1,0,0); auto fd = FaceDescriptor(n-1,1,0,0);
fd.SetBCProperty(n); fd.SetBCProperty(n);
mesh.AddFaceDescriptor (fd); mesh.AddFaceDescriptor (fd);
} }
} }
return get<1>(index_map[index]); return index_map[{eldim, index}];
}; };
while(true) { while(true) {
@ -31,14 +31,14 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<int, t
if(token == "End") if(token == "End")
break; break;
if(token == "MeshVersionFormatted") { else if(token == "MeshVersionFormatted") {
fin >> version; fin >> version;
} }
if(token == "Dimension") { else if(token == "Dimension") {
fin >> dim; fin >> dim;
mesh.SetDimension(dim); mesh.SetDimension(dim);
} }
if(token == "Vertices") { else if(token == "Vertices") {
int nvert; int nvert;
fin >> nvert; fin >> nvert;
Point<3> p{0.,0.,0.}; Point<3> p{0.,0.,0.};
@ -49,7 +49,7 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<int, t
mesh.AddPoint(p); mesh.AddPoint(p);
} }
} }
if(token == "Edges") { else if(token == "Edges") {
int nedge; int nedge;
fin >> nedge; fin >> nedge;
Segment seg; Segment seg;
@ -62,7 +62,7 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<int, t
mesh.AddSegment(seg); mesh.AddSegment(seg);
} }
} }
if(token == "Triangles") { else if(token == "Triangles") {
int ntrig, index; int ntrig, index;
fin >> ntrig; fin >> ntrig;
Element2d sel; Element2d sel;
@ -74,7 +74,7 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<int, t
mesh.AddSurfaceElement(sel); mesh.AddSurfaceElement(sel);
} }
} }
if(token == "Tetrahedra") { else if(token == "Tetrahedra") {
int ntet; int ntet;
fin >> ntet; fin >> ntet;
Element el(4); Element el(4);
@ -87,12 +87,19 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<int, t
mesh.AddVolumeElement(el); mesh.AddVolumeElement(el);
} }
} }
else {
int nitems;
fin >> nitems;
string s;
for(auto i : Range(nitems))
fin >> s; // read one line
}
} }
} }
void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename) void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename)
{ {
map<int, tuple<int,int>> index_map; map<tuple<int, int>, int> index_map;
ReadMeditFormat(mesh, filename, index_map); ReadMeditFormat(mesh, filename, index_map);
} }
@ -141,7 +148,7 @@ void WriteMeditFormat (const Mesh & mesh, const filesystem::path & filename, map
void WriteMeditFormat (const Mesh & mesh, const filesystem::path & filename) void WriteMeditFormat (const Mesh & mesh, const filesystem::path & filename)
{ {
map<tuple<int,int>,int> index_map; map<tuple<int,int>, int> index_map;
WriteMeditFormat(mesh, filename, index_map); WriteMeditFormat(mesh, filename, index_map);
} }

View File

@ -3,7 +3,7 @@
namespace netgen namespace netgen
{ {
DLL_HEADER void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<int, tuple<int,int>> & index_map); DLL_HEADER void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<tuple<int, int>, int> & index_map);
DLL_HEADER void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename); DLL_HEADER void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename);
DLL_HEADER void WriteMeditFormat (const Mesh & mesh, const filesystem::path & filename, map<tuple<int,int>, int> & index_map); DLL_HEADER void WriteMeditFormat (const Mesh & mesh, const filesystem::path & filename, map<tuple<int,int>, int> & index_map);