From ef545c5d86f1162e79256e4ed5e687a9520455f5 Mon Sep 17 00:00:00 2001 From: Julius Zimmermann Date: Mon, 15 Jul 2019 16:07:32 +0200 Subject: [PATCH 1/5] unv interface for 2D case --- libsrc/interface/readuser.cpp | 118 +++++++++++++++++++++++++++++----- 1 file changed, 102 insertions(+), 16 deletions(-) diff --git a/libsrc/interface/readuser.cpp b/libsrc/interface/readuser.cpp index 8321a962..37e3c15c 100644 --- a/libsrc/interface/readuser.cpp +++ b/libsrc/interface/readuser.cpp @@ -98,6 +98,8 @@ namespace netgen mesh.GetFaceDescriptor(1).SetBCProperty (1); // map from unv element nr to our element number + an index if it is vol (0), bnd(1), ... std::map> element_map; + int dim = 3; + int bccounter = 0; // for 2D case NgArray tmp_segments; while (in.good()) @@ -125,6 +127,15 @@ namespace netgen mesh.AddPoint (p); } cout << "read " << mesh.GetNP() << " points" << endl; + Point3d pmin, pmax; + mesh.GetBox (pmin, pmax); + if(fabs(pmin.Z() - pmax.Z()) < 1e-10) //hard-coded for now + { + cout << "Set Dimension to 2." << endl; + mesh.SetDimension(2); + dim = 2 ; + } + } else if (strcmp (reco, "2412") == 0) @@ -150,6 +161,26 @@ namespace netgen switch (fe_id) { + case 11: // (Rod) SEGM + { + Segment el; + el[0] = nodes[0]; + el[1] = nodes[1]; + el[2] = -1; + + if(dim == 3){ + auto nr = tmp_segments.Size(); + tmp_segments.Append(el); + element_map[label] = std::make_tuple(nr+1, 2); + } + else if(dim == 2){ + el.si = -1; // add label to segment, will be changed later when BC's are assigned + auto nr = mesh.AddSegment(el); + element_map[label] = std::make_tuple(nr+1, 2); + } + break; + } + case 22: // (Tapered beam) SEGM { Segment el; @@ -165,10 +196,10 @@ namespace netgen case 41: // TRIG { Element2d el (TRIG); - el.SetIndex (1); + el.SetIndex(1); for (int j = 0; j < nnodes; j++) el[j] = nodes[j]; - auto nr = mesh.AddSurfaceElement (el); + auto nr = mesh.AddSurfaceElement(el); element_map[label] = std::make_tuple(nr+1, 1); break; } @@ -244,24 +275,48 @@ namespace netgen } case 1: { - int bcpr = mesh.GetNFD()+1; - fdnr = mesh.AddFaceDescriptor(FaceDescriptor(bcpr, 0,0,0)); - mesh.GetFaceDescriptor(fdnr).SetBCProperty(bcpr+1); - mesh.SetBCName(bcpr, name); - mesh.SurfaceElement(get<0>(element_map[index])).SetIndex(fdnr); + if(dim == 3) + { + int bcpr = mesh.GetNFD()+1; + fdnr = mesh.AddFaceDescriptor(FaceDescriptor(bcpr, 0,0,0)); + mesh.GetFaceDescriptor(fdnr).SetBCProperty(bcpr+1); + mesh.SetBCName(bcpr, name); + mesh.SurfaceElement(get<0>(element_map[index])).SetIndex(fdnr); + } + else if(dim == 2) + { + mesh.SetMaterial(matnr, name); + fdnr = mesh.AddFaceDescriptor(FaceDescriptor(matnr, 0,0,0)); + mesh.SurfaceElement(get<0>(element_map[index])).SetIndex(matnr); + mesh.GetFaceDescriptor(fdnr).SetBCProperty(matnr); + matnr++; + } break; + } case 2: { - int bcpr = mesh.GetNCD2Names()+1; - auto ed = EdgeDescriptor(); - ed.SetSurfNr(0,bcpr);//? - ednr = mesh.AddEdgeDescriptor(ed); - mesh.SetCD2Name(bcpr, name); - auto nr = mesh.AddSegment(tmp_segments[get<0>(element_map[index])-1]); - mesh[nr].SetBCName(mesh.GetCD2NamePtr(mesh.GetNCD2Names())); - mesh[nr].edgenr = ednr+1; + if(dim == 3) + { + int bcpr = mesh.GetNCD2Names()+1; + auto ed = EdgeDescriptor(); + ed.SetSurfNr(0,bcpr);//? + ednr = mesh.AddEdgeDescriptor(ed); + mesh.SetCD2Name(bcpr, name); + auto nr = mesh.AddSegment(tmp_segments[get<0>(element_map[index])-1]); + mesh[nr].SetBCName(mesh.GetCD2NamePtr(mesh.GetNCD2Names())); + mesh[nr].edgenr = ednr+1; + } + else if(dim == 2) + { + Segment & seg = mesh.LineSegment(get<0>(element_map[index])); + seg.si = bccounter + 1; + mesh.SetBCName(bccounter, name); + seg.SetBCName(mesh.GetBCNamePtr(bccounter)); + bccounter++; + } break; + } default: { @@ -278,14 +333,25 @@ namespace netgen mesh.VolumeElement(get<0>(element_map[index])).SetIndex(matnr); break; case 1: - mesh.SurfaceElement(get<0>(element_map[index])).SetIndex(fdnr); + if(dim == 3) mesh.SurfaceElement(get<0>(element_map[index])).SetIndex(fdnr); + else if (dim == 2){ + mesh.SurfaceElement(get<0>(element_map[index])).SetIndex(matnr-1); + mesh.GetFaceDescriptor(fdnr).SetBCProperty(matnr); + } break; case 2: + if(dim == 3) { auto nr = mesh.AddSegment(tmp_segments[get<0>(element_map[index])-1]); mesh[nr].edgenr = ednr+1; mesh[nr].SetBCName(mesh.GetCD2NamePtr(mesh.GetNCD2Names())); } + else if(dim == 2) + { + Segment & seg = mesh.LineSegment(get<0>(element_map[index])); + seg.si = bccounter; + seg.SetBCName(mesh.GetBCNamePtr(bccounter-1)); + } break; default: break; @@ -304,6 +370,21 @@ namespace netgen } } } + + if(dim == 2){ + // loop through segments to assign default BC to unmarked edges + int bccounter_tmp = bccounter; + for(int index=0; index < mesh.GetNSeg(); index++){ + Segment & seg = mesh.LineSegment(get<0>(element_map[index])); + if(seg.si == -1){ + seg.si = bccounter; + mesh.SetBCName(bccounter, "default"); // could be more efficient + seg.SetBCName(mesh.GetBCNamePtr(bccounter)); + bccounter_tmp++; + } + } + if(bccounter_tmp > bccounter) bccounter++; + } Point3d pmin, pmax; @@ -312,6 +393,11 @@ namespace netgen mesh.GetBox (pmin, pmax); mesh.UpdateTopology(); cout << "bounding-box = " << pmin << "-" << pmax << endl; + cout << "Created " << bccounter << " boundaries." << endl; + for(int i=0; i Date: Mon, 15 Jul 2019 16:42:13 +0200 Subject: [PATCH 2/5] fixed bug --- libsrc/interface/readuser.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libsrc/interface/readuser.cpp b/libsrc/interface/readuser.cpp index 37e3c15c..c76829a5 100644 --- a/libsrc/interface/readuser.cpp +++ b/libsrc/interface/readuser.cpp @@ -4,8 +4,6 @@ #include - - #include #include #include @@ -242,6 +240,7 @@ namespace netgen } cout << mesh.GetNE() << " elements found" << endl; cout << mesh.GetNSE() << " surface elements found" << endl; + } else if(strcmp (reco, "2467") == 0) { @@ -374,11 +373,11 @@ namespace netgen if(dim == 2){ // loop through segments to assign default BC to unmarked edges int bccounter_tmp = bccounter; - for(int index=0; index < mesh.GetNSeg(); index++){ + for(int index=1; index <= mesh.GetNSeg(); index++){ Segment & seg = mesh.LineSegment(get<0>(element_map[index])); if(seg.si == -1){ - seg.si = bccounter; - mesh.SetBCName(bccounter, "default"); // could be more efficient + seg.si = bccounter + 1; + if(bccounter_tmp == bccounter) mesh.SetBCName(bccounter, "default"); // could be more efficient seg.SetBCName(mesh.GetBCNamePtr(bccounter)); bccounter_tmp++; } @@ -397,7 +396,6 @@ namespace netgen for(int i=0; i Date: Tue, 16 Jul 2019 10:42:27 +0200 Subject: [PATCH 3/5] curved elements work, too --- libsrc/interface/readuser.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/libsrc/interface/readuser.cpp b/libsrc/interface/readuser.cpp index c76829a5..1e0d85f8 100644 --- a/libsrc/interface/readuser.cpp +++ b/libsrc/interface/readuser.cpp @@ -127,7 +127,7 @@ namespace netgen cout << "read " << mesh.GetNP() << " points" << endl; Point3d pmin, pmax; mesh.GetBox (pmin, pmax); - if(fabs(pmin.Z() - pmax.Z()) < 1e-10) //hard-coded for now + if(fabs(pmin.Z() - pmax.Z()) < 1e-10 * Dist(pmin, pmax)) { cout << "Set Dimension to 2." << endl; mesh.SetDimension(2); @@ -167,14 +167,14 @@ namespace netgen el[2] = -1; if(dim == 3){ - auto nr = tmp_segments.Size(); - tmp_segments.Append(el); - element_map[label] = std::make_tuple(nr+1, 2); + auto nr = tmp_segments.Size(); + tmp_segments.Append(el); + element_map[label] = std::make_tuple(nr+1, 2); } else if(dim == 2){ - el.si = -1; // add label to segment, will be changed later when BC's are assigned - auto nr = mesh.AddSegment(el); - element_map[label] = std::make_tuple(nr+1, 2); + el.si = -1; // add label to segment, will be changed later when BC's are assigned + auto nr = mesh.AddSegment(el); + element_map[label] = std::make_tuple(nr+1, 2); } break; } @@ -186,18 +186,26 @@ namespace netgen el[1] = nodes[2]; el[2] = nodes[1]; - auto nr = tmp_segments.Size(); - tmp_segments.Append(el); - element_map[label] = std::make_tuple(nr+1, 2); + if(dim == 3){ + auto nr = tmp_segments.Size(); + tmp_segments.Append(el); + element_map[label] = std::make_tuple(nr+1, 2); + } + else if(dim == 2){ + el.si = -1; // add label to segment, will be changed later when BC's are assigned + auto nr = mesh.AddSegment(el); + element_map[label] = std::make_tuple(nr+1, 2); + } + break; } case 41: // TRIG { Element2d el (TRIG); - el.SetIndex(1); + el.SetIndex (1); for (int j = 0; j < nnodes; j++) el[j] = nodes[j]; - auto nr = mesh.AddSurfaceElement(el); + auto nr = mesh.AddSurfaceElement (el); element_map[label] = std::make_tuple(nr+1, 1); break; } From 57215cc707fccab316b9dc40d4d4f96f7b84243e Mon Sep 17 00:00:00 2001 From: Julius Zimmermann Date: Tue, 23 Jul 2019 23:23:10 +0200 Subject: [PATCH 4/5] fixed another bug --- libsrc/interface/readuser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/interface/readuser.cpp b/libsrc/interface/readuser.cpp index 1e0d85f8..cd52a5ac 100644 --- a/libsrc/interface/readuser.cpp +++ b/libsrc/interface/readuser.cpp @@ -382,7 +382,7 @@ namespace netgen // loop through segments to assign default BC to unmarked edges int bccounter_tmp = bccounter; for(int index=1; index <= mesh.GetNSeg(); index++){ - Segment & seg = mesh.LineSegment(get<0>(element_map[index])); + Segment & seg = mesh.LineSegment(index); if(seg.si == -1){ seg.si = bccounter + 1; if(bccounter_tmp == bccounter) mesh.SetBCName(bccounter, "default"); // could be more efficient From 490b6800d581e8643f9de32b4de906a602aadfa3 Mon Sep 17 00:00:00 2001 From: Julius Zimmermann Date: Wed, 31 Jul 2019 22:55:43 +0200 Subject: [PATCH 5/5] there will not be 2 default groups in the 3D case --- libsrc/interface/readuser.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libsrc/interface/readuser.cpp b/libsrc/interface/readuser.cpp index cd52a5ac..f53b9b40 100644 --- a/libsrc/interface/readuser.cpp +++ b/libsrc/interface/readuser.cpp @@ -97,7 +97,7 @@ namespace netgen // map from unv element nr to our element number + an index if it is vol (0), bnd(1), ... std::map> element_map; int dim = 3; - int bccounter = 0; // for 2D case + int bccounter = 0; NgArray tmp_segments; while (in.good()) @@ -284,11 +284,12 @@ namespace netgen { if(dim == 3) { - int bcpr = mesh.GetNFD()+1; + int bcpr = mesh.GetNFD(); fdnr = mesh.AddFaceDescriptor(FaceDescriptor(bcpr, 0,0,0)); mesh.GetFaceDescriptor(fdnr).SetBCProperty(bcpr+1); mesh.SetBCName(bcpr, name); mesh.SurfaceElement(get<0>(element_map[index])).SetIndex(fdnr); + bccounter++; } else if(dim == 2) { @@ -399,6 +400,7 @@ namespace netgen mesh.RebuildSurfaceElementLists(); mesh.GetBox (pmin, pmax); mesh.UpdateTopology(); + if(dim == 3) bccounter++; cout << "bounding-box = " << pmin << "-" << pmax << endl; cout << "Created " << bccounter << " boundaries." << endl; for(int i=0; i