176 Handle(XSControl_WorkSession) WS;
177 Handle(Interface_InterfaceModel) Model;
178 Handle(XSControl_TransferReader) TR;
179 Handle(Transfer_TransientProcess) TP;
180 Handle(XCAFDoc_ShapeTool) STool;
182 bool fromStep =
false;
188 if (fs::path(
m_name).extension() ==
".geo")
201 Interface_Static::SetCVal(
"xstep.cascade.unit",
"MM");
203 STEPCAFControl_Reader readerCAF;
204 readerCAF.SetNameMode(
true);
205 readerCAF.SetLayerMode(
true);
206 readerCAF.SetColorMode(
true);
208 Handle(TDocStd_Document) document =
209 new TDocStd_Document(Storage::Version());
210 readerCAF.ReadFile(
m_name.c_str());
211 readerCAF.Transfer(document);
213 STEPControl_Reader reader = readerCAF.Reader();
217 TR = WS->TransferReader();
218 TP = TR->TransientProcess();
219 XCAFDoc_DocumentTool::ShapeTool(document->Main());
221 reader.NbRootsForTransfer();
222 reader.TransferRoots();
236 TopExp_Explorer explr;
238 TopTools_DataMapOfShapeShape modShape;
263 std::max(1e-5 * diagonal, Precision::Confusion());
268 BRepBuilderAPI_Sewing sew(sewTolerance);
270 for (explr.Init(
m_shape, TopAbs_FACE); explr.More(); explr.Next())
272 sew.Add(explr.Current());
277 for (explr.Init(
m_shape, TopAbs_FACE); explr.More(); explr.Next())
279 if (sew.IsModified(explr.Current()))
281 modShape.Bind(explr.Current(), sew.Modified(explr.Current()));
289 for (explr.Init(
m_shape, TopAbs_VERTEX); explr.More(); explr.Next())
291 TopoDS_Shape v = explr.Current();
303 for (explr.Init(
m_shape, TopAbs_EDGE); explr.More(); explr.Next())
305 TopoDS_Shape e = explr.Current().Oriented(TopAbs_FORWARD);
311 if (!BRep_Tool::Degenerated(TopoDS::Edge(e)))
318 for (explr.Init(
m_shape, TopAbs_FACE); explr.More(); explr.Next())
320 TopoDS_Shape f = explr.Current();
323 m_log(
FATAL) <<
"the CAD model lists the same face twice, which "
324 "leaves the surface mesher no way to tell which "
325 "of the two a mesh element belongs to."
336 int nb = Model->NbEntities();
337 for (
int i = 1; i <= nb; i++)
339 if (!Model->Value(i)->DynamicType()->SubType(
340 "StepRepr_RepresentationItem"))
345 Handle(StepRepr_RepresentationItem) enti =
346 Handle(StepRepr_RepresentationItem)::DownCast(Model->Value(i));
347 Handle(TCollection_HAsciiString) name = enti->Name();
354 Handle(Transfer_Binder) binder = TP->Find(Model->Value(i));
355 if (binder.IsNull() || !binder->HasResult())
360 TopoDS_Shape S = TransferBRep::ShapeResult(TP, binder);
367 if (S.ShapeType() == TopAbs_FACE)
369 string s(name->ToCString());
396 TopoDS_Shape face =
m_mapOfFaces.FindKey(i).Oriented(TopAbs_FORWARD);
398 TopTools_IndexedMapOfShape localEdges;
399 TopExp::MapShapes(face, TopAbs_EDGE, localEdges);
401 for (
int j = 1; j <= localEdges.Extent(); j++)
403 TopoDS_Shape edge = localEdges.FindKey(j);
404 if (BRep_Tool::Degenerated(TopoDS::Edge(edge)))
408 BRep_Tool::UVPoints(TopoDS::Edge(edge), TopoDS::Face(face), p1,
412 TopoDS::Edge(edge), Standard_True))]
413 ->SetDegen(i,
m_surfs[i], (p1.X() + p2.X()) / 2.0,
414 (p1.Y() + p2.Y()) / 2.0);
564 if (naca.length() != 4)
566 m_log(
FATAL) <<
"a NACA profile is named by four digits; '" << naca
567 <<
"' has " << naca.length() <<
"." << endl;
569 vector<NekDouble> data;
571 if (data.size() != 5)
573 m_log(
FATAL) <<
"UseNACA needs five numbers -- the domain's xmin, "
574 "ymin, xmax and ymax, then the angle of attack in "
575 "degrees -- and was given "
576 << data.size() <<
"." << endl;
579 int n = std::stoi(naca);
590 for (
int i = 0; i < np; i++)
592 xc[i] = (1.0 - cos(i * dtheta)) / 2.0;
596 for (
int i = 0; i < np; i++)
600 yc[i] = M /
P /
P * (2.0 *
P * xc[i] - xc[i] * xc[i]);
601 dyc[i] = 2.0 * M /
P /
P * (
P - xc[i]);
605 yc[i] = M / (1.0 -
P) / (1.0 -
P) *
606 (1.0 - 2.0 *
P + 2.0 *
P * xc[i] - xc[i] * xc[i]);
607 dyc[i] = 2.0 * M / (1.0 -
P) / (1.0 -
P) * (
P - xc[i]);
612 for (
int i = 0; i < np; i++)
615 (0.2969 *
sqrt(xc[i]) - 0.1260 * xc[i] -
616 0.3516 * xc[i] * xc[i] + 0.2843 * xc[i] * xc[i] * xc[i] -
617 0.1015 * xc[i] * xc[i] * xc[i] * xc[i]);
622 for (
int i = np - 1; i >= 0; i--, l++)
626 x[l] = xc[i] - yt[i] * sin(theta);
627 y[l] = yc[i] + yt[i] * cos(theta);
629 for (
int i = 1; i < np; i++)
633 x[i + np - 1] = xc[i] + yt[i] * sin(theta);
634 y[i + np - 1] = yc[i] - yt[i] * cos(theta);
637 TColgp_Array1OfPnt pointArray(0, 2 * np - 2);
639 for (
int i = 0; i < 2 * np - 1; i++)
644 GeomAPI_PointsToBSpline spline(pointArray);
645 Handle(Geom_BSplineCurve) curve = spline.Curve();
647 BRepBuilderAPI_MakeEdge areoEdgeBuilder(curve);
648 TopoDS_Edge aeroEdge = areoEdgeBuilder.Edge();
649 BRepBuilderAPI_MakeEdge aeroTEBuilder(
652 TopoDS_Edge TeEdge = aeroTEBuilder.Edge();
654 BRepBuilderAPI_MakeWire aeroWireBuilder(aeroEdge, TeEdge);
655 TopoDS_Wire aeroWire = aeroWireBuilder.Wire();
659 gp_Dir(gp_Vec(0.0, 0.0, -1.0)));
660 transform.SetRotation(rotAx, data[4] / 180.0 * M_PI);
661 TopLoc_Location mv(transform);
664 BRepBuilderAPI_MakeEdge domInlBuilder(
667 TopoDS_Edge inlEdge = domInlBuilder.Edge();
669 BRepBuilderAPI_MakeEdge domTopBuilder(
672 TopoDS_Edge topEdge = domTopBuilder.Edge();
674 BRepBuilderAPI_MakeEdge domOutBuilder(
677 TopoDS_Edge outEdge = domOutBuilder.Edge();
679 BRepBuilderAPI_MakeEdge domBotBuilder(
682 TopoDS_Edge botEdge = domBotBuilder.Edge();
684 BRepBuilderAPI_MakeWire domWireBuilder(inlEdge, topEdge, outEdge, botEdge);
685 TopoDS_Wire domWire = domWireBuilder.Wire();
687 BRepBuilderAPI_MakeFace face(domWire,
true);
690 ShapeFix_Face sf(face.Face());
756 ifstream f(geo.c_str());
757 const std::string str((std::istreambuf_iterator<char>(f)),
758 std::istreambuf_iterator<char>());
768 std::string::const_iterator iter = str.begin();
769 std::string::const_iterator end = str.end();
770 bool r = qi::phrase_parse(iter, end, geoParser, skip, geoFile);
775 std::string::const_iterator some = iter + 30;
776 std::string context(iter, (some > end) ? end : some);
778 m_log(
FATAL) <<
"Parsing of geo file failed, "
779 <<
"stopped at: \": " << context <<
"...\"" << endl;
783 map<unsigned int, gp_Pnt> cPoints;
784 for (
auto &point : geoFile.
points)
793 map<unsigned int, TopoDS_Edge> cEdges;
794 map<unsigned int, std::string> cEdgeTypes;
795 map<unsigned int, Geom> edgeMap;
798 for (
auto &line : geoFile.
lines)
800 if (line.ids.size() != 2)
803 "Line " + std::to_string(line.id) +
804 " contains more than two points, ignoring.");
809 if (!
ContainsIDs(
"Line", line.id,
"point", line.ids, cPoints))
814 BRepBuilderAPI_MakeEdge em(cPoints[line.ids[0]], cPoints[line.ids[1]]);
815 cEdges[line.id] = em.Edge();
816 edgeMap[line.id] = line;
817 cEdgeTypes[line.id] =
"line";
821 for (
auto &spline : geoFile.
splines)
823 if (spline.ids.size() < 2)
826 "Spline " + std::to_string(spline.id) +
827 " does not contain enough points, ignoring.");
832 if (!
ContainsIDs(
"Spline", spline.id,
"point", spline.ids, cPoints))
837 TColgp_Array1OfPnt pointArray(0, spline.ids.size() - 1);
839 for (
int i = 0; i < spline.ids.size(); i++)
841 pointArray.SetValue(i, cPoints[spline.ids[i]]);
843 GeomAPI_PointsToBSpline oceSpline(pointArray);
844 Handle(Geom_BSplineCurve) curve = oceSpline.Curve();
846 BRepBuilderAPI_MakeEdge em(curve);
847 cEdges[spline.id] = em.Edge();
848 edgeMap[spline.id] = spline;
849 cEdgeTypes[spline.id] =
"spline";
853 for (
auto &bspline : geoFile.
bsplines)
855 if (bspline.ids.size() < 2)
858 "BSpline " + std::to_string(bspline.id) +
860 "contain enough points, ignoring.");
865 if (!
ContainsIDs(
"BSpline", bspline.id,
"point", bspline.ids, cPoints))
870 TColgp_Array1OfPnt pointArray(0, bspline.ids.size() - 1);
872 for (
int i = 0; i < bspline.ids.size(); i++)
874 pointArray.SetValue(i, cPoints[bspline.ids[i]]);
876 Handle(Geom_BezierCurve) curve =
new Geom_BezierCurve(pointArray);
878 BRepBuilderAPI_MakeEdge em(curve);
879 cEdges[bspline.id] = em.Edge();
880 edgeMap[bspline.id] = bspline;
881 cEdgeTypes[bspline.id] =
"bspline";
885 for (
auto &circle : geoFile.
circles)
887 if (circle.ids.size() != 3)
890 "Circle " + std::to_string(circle.id) +
891 " should contain only three points.");
896 if (!
ContainsIDs(
"Circle", circle.id,
"point", circle.ids, cPoints))
901 gp_Pnt start = cPoints[circle.ids[0]];
902 gp_Pnt centre = cPoints[circle.ids[1]];
903 gp_Pnt end = cPoints[circle.ids[2]];
905 Standard_Real radius = start.Distance(centre);
906 gce_MakeCirc mkArc(centre, gce_MakePln(start, centre, end).Value(),
909 const gp_Circ &circ = mkArc.Value();
910 Handle(Geom_Circle) c =
new Geom_Circle(circ);
912 Standard_Real alpha1 = ElCLib::Parameter(circ, start);
913 Standard_Real alpha2 = ElCLib::Parameter(circ, end);
914 if ((alpha1 > alpha2) ^ (fabs(alpha2 - alpha1) > M_PI))
916 std::swap(alpha1, alpha2);
919 Handle(Geom_TrimmedCurve) tc =
920 new Geom_TrimmedCurve(c, alpha1, alpha2,
false);
922 BRepBuilderAPI_MakeEdge em(tc);
924 cEdges[circle.id] = em.Edge();
925 edgeMap[circle.id] = circle;
926 cEdgeTypes[circle.id] =
"circle";
930 for (
auto &ellipse : geoFile.
ellipses)
932 if (ellipse.ids.size() != 4)
935 std::to_string(ellipse.id) +
937 " only four points.");
942 if (!
ContainsIDs(
"Ellipse", ellipse.id,
"point", ellipse.ids, cPoints))
947 gp_Pnt start = cPoints[ellipse.ids[0]];
948 gp_Pnt centre = cPoints[ellipse.ids[1]];
950 gp_Pnt end = cPoints[ellipse.ids[3]];
952 NekDouble major = start.Distance(centre);
954 gp_Vec v1(centre, start);
955 gp_Vec v2(centre, end);
957 gp_Vec vx(1.0, 0.0, 0.0);
966 v2.Rotate(gp_Ax1(), angle);
968 fabs(v2.Y() /
sqrt(1.0 - v2.X() * v2.X() / (major * major)));
971 e.SetLocation(centre);
972 e.SetMajorRadius(major);
973 e.SetMinorRadius(minor);
974 e.Rotate(e.Axis(), angle);
975 Handle(Geom_Ellipse) ge =
new Geom_Ellipse(e);
977 ShapeAnalysis_Curve sac;
979 sac.Project(ge, start, 1e-8, start, p1);
980 sac.Project(ge, end, 1e-8, end, p2);
983 if (fabs(p2 - p1) > M_PI)
988 Handle(Geom_TrimmedCurve) tc =
new Geom_TrimmedCurve(ge, p1, p2,
true);
990 BRepBuilderAPI_MakeEdge em(tc);
992 cEdges[ellipse.id] = em.Edge();
993 edgeMap[ellipse.id] = ellipse;
994 cEdgeTypes[ellipse.id] =
"ellipse";
1000 map<unsigned int, TopoDS_Wire> cWires;
1001 map<unsigned int, Geom> loopMap;
1006 for (
auto &
id : loop.ids)
1012 if (!
ContainsIDs(
"Line Loop", loop.id,
"edge", loop.ids, cEdges))
1017 BRepBuilderAPI_MakeWire wm;
1018 for (
auto &edgeId : loop.ids)
1020 wm.Add(cEdges[edgeId]);
1022 cWires[loop.id] = wm.Wire();
1023 loopMap[loop.id] = loop;
1029 map<unsigned int, TopoDS_Face> cFaces;
1030 map<unsigned int, Geom> faceMap;
1035 BRepBuilderAPI_MakeFace face(cWires[planeSurf.ids[0]],
true);
1036 for (
int i = 1; i < planeSurf.ids.size(); i++)
1038 face.Add(cWires[planeSurf.ids[i]]);
1041 ASSERTL0(face.Error() == BRepBuilderAPI_FaceDone,
"build geo failed");
1043 ShapeFix_Face sf(face.Face());
1044 sf.FixOrientation();
1046 cFaces[planeSurf.id] = sf.Face();
1047 faceMap[planeSurf.id] = planeSurf;
1055 "2D simulations should define at most one plane surface in "
1058 return cFaces.begin()->second;
1079 if (!
ContainsIDs(
"Ruled Surface", surf.id,
"line loop", surf.ids,
1084 if (surf.ids.size() != 1)
1087 "Surface " + std::to_string(surf.id) +
1089 "contain a single line loop, ignoring.");
1093 Geom &loop = loopMap[surf.ids[0]];
1096 const int nEdges = loop.ids.size();
1101 bool isSphere =
true;
1102 if (nEdges == 3 || nEdges == 4)
1104 for (
int i = 0; i < nEdges; ++i)
1106 if (cEdgeTypes[loop.ids[i]] !=
"circle")
1116 int originId = edgeMap[loop.ids[0]].ids[1];
1117 for (
int i = 1; i < nEdges; ++i)
1119 if (originId != edgeMap[loop.ids[i]].ids[1])
1131 gp_Pnt origin = cPoints[edgeMap[loop.ids[0]].ids[1]];
1133 sph.SetLocation(origin);
1135 origin.Distance(cPoints[edgeMap[loop.ids[0]].ids[0]]));
1136 BRepBuilderAPI_MakeFace makeFace(sph, cWires[surf.ids[0]]);
1138 ShapeFix_Face sf(makeFace.Face());
1139 sf.FixOrientation();
1140 cFaces[surf.id] = sf.Face();
1146 bool builtIn =
true;
1147 if (nEdges == 4 && builtIn)
1160 std::vector<Handle(Geom_Curve)> edges(nEdges);
1161 std::vector<pair<double, double>> clims(nEdges);
1162 std::vector<int> vertIds(nEdges);
1163 std::vector<bool> fwd(nEdges);
1164 std::vector<gp_Pnt> verts(nEdges);
1166 for (
int i = 0; i < nEdges; ++i)
1168 auto edge = edgeMap[loop.ids[i]];
1169 auto nextEdge = edgeMap[loop.ids[(i + 1) % nEdges]];
1171 std::pair<double, double> clim;
1172 edges[i] = BRep_Tool::Curve(cEdges[loop.ids[i]], clim.first,
1178 if ((edge.ids[0] == nextEdge.ids[0]) ||
1179 (edge.ids[0] == nextEdge.ids.back()))
1183 else if ((edge.ids.back() != nextEdge.ids[0]) &&
1184 (edge.ids.back() != nextEdge.ids.back()))
1186 ASSERTL0(
false,
"connectivity issue");
1190 fwd[i] ? cPoints[edge.ids[0]] : cPoints[edge.ids.back()];
1197 BRepBuilderAPI_MakeFace mkFace(tf, cWires[surf.ids[0]]);
1198 TopoDS_Face face = mkFace.Face();
1206 if (nEdges == 4 &&
false)
1210 BRep_Tool::Surface(face,
L);
1211 Handle(Geom2d_Line) e0, e1, e2, e3;
1212 e0 =
new Geom2d_Line(gp_Pnt2d(0, 0), gp_Dir2d(1, 0));
1213 e1 =
new Geom2d_Line(gp_Pnt2d(1, 0), gp_Dir2d(0, 1));
1214 e2 =
new Geom2d_Line(gp_Pnt2d(0, 1), gp_Dir2d(1, 0));
1215 e3 =
new Geom2d_Line(gp_Pnt2d(0, 0), gp_Dir2d(0, 1));
1217 B.UpdateEdge(cEdges[loop.ids[0]], e0, tf,
L, 0.);
1218 B.UpdateEdge(cEdges[loop.ids[1]], e1, tf,
L, 0.);
1219 B.UpdateEdge(cEdges[loop.ids[2]], e2, tf,
L, 0.);
1220 B.UpdateEdge(cEdges[loop.ids[3]], e3, tf,
L, 0.);
1221 B.Range(cEdges[loop.ids[0]], face, 0, 1);
1222 B.Range(cEdges[loop.ids[1]], face, 0, 1);
1223 B.Range(cEdges[loop.ids[2]], face, 0, 1);
1224 B.Range(cEdges[loop.ids[3]], face, 0, 1);
1227 cFaces[surf.id] = face;
1233 BRepOffsetAPI_MakeFilling fill;
1237 for (ex.Init(cWires[surf.ids[0]], TopAbs_EDGE); ex.More(); ex.Next())
1239 const TopoDS_Edge &shape = TopoDS::Edge(ex.Current());
1240 fill.Add(shape, GeomAbs_C0);
1244 cFaces[surf.id] = TopoDS::Face(fill.Shape());
1250 map<unsigned int, TopoDS_Shell> cShells;
1254 if (!
ContainsIDs(
"Surface Loop", sloop.id,
"surface", sloop.ids,
1260 BRep_Builder builder;
1261 BRepPrim_Builder b(builder);
1264 for (
auto &
id : sloop.ids)
1266 b.AddShellFace(shell, cFaces[
id]);
1268 cShells[sloop.id] = shell;
1271 map<unsigned int, TopoDS_Shape> cVolumes;
1272 for (
auto &vol : geoFile.
volumes)
1274 for (
auto &
id : vol.ids)
1280 if (!
ContainsIDs(
"Volume", vol.id,
"surface loop", vol.ids, cShells))
1285 BRepBuilderAPI_MakeSolid solidMaker;
1287 for (
int i = 0; i < vol.ids.size(); ++i)
1289 solidMaker.Add(cShells[vol.ids[i]]);
1292 cVolumes[vol.id] = solidMaker.Solid();
1296 "3D .geo file should define exactly one volume.");
1298 return cVolumes.begin()->second;