diff --git a/libsrc/csg/python_csg.cpp b/libsrc/csg/python_csg.cpp index bb646d08..58f6034e 100644 --- a/libsrc/csg/python_csg.cpp +++ b/libsrc/csg/python_csg.cpp @@ -21,6 +21,7 @@ class SPSolid shared_ptr s1, s2; Solid * solid; int bc = -1; + string bcname = ""; double maxh = -1; string material; bool owner; @@ -98,6 +99,25 @@ public: } } + void SetBCName(string name) + { + if (bcname == "") + { + bcname = name; + if (s1) s1 -> SetBCName(name); + if (s2) s2 -> SetBCName(name); + if (op == TERM) + { + Primitive * prim = solid -> GetPrimitive(); + for (int i = 0; i < prim->GetNSurfaces(); i++) + prim->GetSurface(i).SetBCName (name); + // cout << "set " << prim->GetNSurfaces() << " surfaces to bc " << bc << endl; + } + } + } + + + void SetMaxH(double amaxh) { if (maxh == -1) @@ -201,6 +221,8 @@ DLL_HEADER void ExportCSG() .def ("bc", FunctionPointer([](shared_ptr & self, int nr) -> shared_ptr { self->SetBC(nr); return self; })) + .def ("bc", FunctionPointer([](shared_ptr & self, string name) -> shared_ptr + { self->SetBCName(name); return self; })) .def ("maxh", FunctionPointer([](shared_ptr & self, double maxh) -> shared_ptr { self->SetMaxH(maxh); return self; })) .def ("mat", FunctionPointer([](shared_ptr & self, string mat) -> shared_ptr @@ -252,7 +274,7 @@ DLL_HEADER void ExportCSG() })); - bp::class_ ("CSGeometry") + bp::class_, boost::noncopyable> ("CSGeometry") .def("__init__", bp::make_constructor (FunctionPointer ([](const string & filename) { @@ -352,13 +374,13 @@ DLL_HEADER void ExportCSG() ; bp::def("GenerateMesh", FunctionPointer - ([](CSGeometry & geo, MeshingParameters & param) + ([](shared_ptr geo, MeshingParameters & param) { - // testout = new ofstream ("test.out"); - shared_ptr dummy; - geo.FindIdenticSurfaces(1e-8 * geo.MaxSize()); - geo.GenerateMesh (dummy, param, 0, 6); - ng_geometry.reset (&geo, NOOP_Deleter); + auto dummy = make_shared(); + dummy->SetGeometry(geo); + ng_geometry = geo; + geo->FindIdenticSurfaces(1e-8 * geo->MaxSize()); + geo->GenerateMesh (dummy, param, 0, 6); return dummy; })) ; diff --git a/libsrc/geom2d/python_geom2d.cpp b/libsrc/geom2d/python_geom2d.cpp index a3fdc2ad..700268e9 100644 --- a/libsrc/geom2d/python_geom2d.cpp +++ b/libsrc/geom2d/python_geom2d.cpp @@ -221,6 +221,7 @@ DLL_HEADER void ExportGeom2d() .def("GenerateMesh", FunctionPointer([](shared_ptr self, MeshingParameters & mparam) { shared_ptr mesh = make_shared (); + mesh->SetGeometry(self); ng_geometry = self; self->GenerateMesh(mesh, mparam, 0, 0); return mesh; diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index 0a9481b0..ad8e3d96 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -158,10 +158,7 @@ void Ng_LoadMeshFromStream ( istream & input ) { mesh.reset (new Mesh()); mesh -> Load(input); - /* - vssolution.SetMesh(mesh); - vsmesh.SetMesh(mesh); - */ + SetGlobalMesh (mesh); for (int i = 0; i < geometryregister.Size(); i++) { @@ -172,6 +169,8 @@ void Ng_LoadMeshFromStream ( istream & input ) break; } } + + mesh->SetGeometry (ng_geometry); } @@ -1017,7 +1016,7 @@ void Ng_Refine (NG_REFINEMENT_TYPE reftype) if (reftype == NG_REFINE_HP) biopt.refine_hp = 1; - const Refinement & ref = ng_geometry->GetRefinement(); + const Refinement & ref = mesh->GetGeometry()->GetRefinement(); // Refinement * ref; MeshOptimize2d * opt = NULL; @@ -1063,7 +1062,7 @@ void Ng_Refine (NG_REFINEMENT_TYPE reftype) void Ng_SecondOrder () { - const_cast (ng_geometry->GetRefinement()).MakeSecondOrder(*mesh); + const_cast (mesh->GetGeometry()->GetRefinement()).MakeSecondOrder(*mesh); /* if (stlgeometry) { @@ -1130,7 +1129,7 @@ void Ng_HPRefinement (int levels, double parameter, bool setorders, bool ref_level) { NgLock meshlock (mesh->MajorMutex(), true); - Refinement & ref = const_cast (ng_geometry -> GetRefinement()); + Refinement & ref = const_cast (mesh->GetGeometry()->GetRefinement()); HPRefinement (*mesh, &ref, levels, parameter, setorders, ref_level); /* Refinement * ref; @@ -1156,7 +1155,7 @@ void Ng_HighOrder (int order, bool rational) order, rational); */ mesh->BuildCurvedElements - (&const_cast (ng_geometry -> GetRefinement()), + (&const_cast (mesh->GetGeometry()->GetRefinement()), order, rational); mesh -> SetNextMajorTimeStamp(); @@ -2105,7 +2104,7 @@ int Ng_Bisect_WithInfo ( const char * refinementfile, double ** qualityloss, int biopt.femcode = "fepp"; biopt.refinementfilename = refinementfile; - Refinement * ref = const_cast (&ng_geometry -> GetRefinement()); + Refinement * ref = const_cast (&mesh->GetGeometry()->GetRefinement()); MeshOptimize2d * opt = NULL; /* if (stlgeometry) diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index ee23004b..5cd07e85 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -794,6 +794,12 @@ namespace netgen void Mesh :: Load (istream & infile) { + if (! (infile.good()) ) + { + cout << "cannot load mesh" << endl; + throw NgException ("mesh file not found"); + } + char str[100]; int i, n; diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index cf32a736..a0745a4f 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -139,6 +139,8 @@ namespace netgen #endif + + shared_ptr geometry; private: void BuildBoundaryEdges(void); @@ -722,6 +724,15 @@ namespace netgen NgMutex & MajorMutex () { return majormutex; } + shared_ptr GetGeometry() const + { + return geometry; + } + void SetGeometry (shared_ptr geom) + { + geometry = geom; + } + /// void SetUserData(const char * id, Array & data); /// diff --git a/ng/ngpkg.cpp b/ng/ngpkg.cpp index 002ce67c..3a1101a6 100644 --- a/ng/ngpkg.cpp +++ b/ng/ngpkg.cpp @@ -859,12 +859,13 @@ namespace netgen else #endif { - ng_geometry -> GetRefinement().Refine(*mesh); + // ng_geometry -> GetRefinement().Refine(*mesh); + mesh->GetGeometry()->GetRefinement().Refine(*mesh); } //redo second order refinement if desired if (mparam.secondorder) - const_cast (ng_geometry->GetRefinement()).MakeSecondOrder(*mesh); + const_cast (mesh->GetGeometry()->GetRefinement()).MakeSecondOrder(*mesh); return TCL_OK; } @@ -884,7 +885,7 @@ namespace netgen return TCL_ERROR; } - const_cast (ng_geometry -> GetRefinement()).MakeSecondOrder (*mesh); + const_cast (mesh->GetGeometry()->GetRefinement()).MakeSecondOrder (*mesh); return TCL_OK; } @@ -895,7 +896,7 @@ namespace netgen // mparam.elementorder = atoi (Tcl_GetVar (interp, "options.elementorder", 0)); const char * savetask = multithread.task; - Refinement & ref = const_cast (ng_geometry -> GetRefinement()); + Refinement & ref = const_cast (mesh->GetGeometry()->GetRefinement()); mesh -> GetCurvedElements().BuildCurvedElements (&ref, mparam.elementorder); multithread.task = savetask; @@ -936,7 +937,7 @@ namespace netgen void * ValidateDummy (void *) { - Refinement & ref = const_cast (ng_geometry -> GetRefinement()); + Refinement & ref = const_cast (mesh->GetGeometry()->GetRefinement()); ref.ValidateSecondOrder (*mesh); multithread.running = 0; @@ -1010,7 +1011,7 @@ namespace netgen int levels = atoi (argv[1]); - Refinement & ref = const_cast (ng_geometry -> GetRefinement()); + Refinement & ref = const_cast (mesh->GetGeometry()->GetRefinement()); HPRefinement (*mesh, &ref, levels); return TCL_OK; } @@ -1334,6 +1335,7 @@ namespace netgen mesh = make_shared (); // vsmesh.SetMesh (mesh); SetGlobalMesh (mesh); + mesh -> SetGeometry(ng_geometry); int res = ng_geometry -> GenerateMesh (mesh, mparam, perfstepsstart, perfstepsend); // int res = ng_geometry -> GenerateMesh (mesh.Ptr(), mparam, perfstepsstart, perfstepsend); @@ -1355,13 +1357,13 @@ namespace netgen if (mparam.secondorder) { - const_cast (ng_geometry -> GetRefinement()).MakeSecondOrder (*mesh); + const_cast (mesh->GetGeometry()->GetRefinement()).MakeSecondOrder (*mesh); mesh -> SetNextMajorTimeStamp(); } if (mparam.elementorder > 1) { - mesh -> GetCurvedElements().BuildCurvedElements (&const_cast (ng_geometry -> GetRefinement()), + mesh -> GetCurvedElements().BuildCurvedElements (&const_cast (mesh->GetGeometry()->GetRefinement()), mparam.elementorder); mesh -> SetNextMajorTimeStamp(); @@ -1709,7 +1711,7 @@ namespace netgen void * BisectDummy (void *) { - const Refinement & ref = ng_geometry->GetRefinement(); + const Refinement & ref = mesh->GetGeometry()->GetRefinement(); MeshOptimize2d * opt = NULL; /* diff --git a/python/geom2d.py b/python/geom2d.py index bb6537a1..d8f76b86 100644 --- a/python/geom2d.py +++ b/python/geom2d.py @@ -14,17 +14,26 @@ if __platform.startswith('win'): +tmp_generate_mesh = SplineGeometry.GenerateMesh + +def geom2d_meshing_func (geom, **args): + if "mp" in args: + return tmp_generate_mesh (geom, args["mp"]) + else: + return tmp_generate_mesh (geom, MeshingParameters (**args)) + + +SplineGeometry.GenerateMesh = geom2d_meshing_func + + + unit_square = SplineGeometry() -pi1 = unit_square.AppendPoint(0,0) -pi2 = unit_square.AppendPoint(1,0) -pi3 = unit_square.AppendPoint(1,1) -pi4 = unit_square.AppendPoint(0,1) -unit_square.Append(["line",pi1,pi2], bc=1) -unit_square.Append(["line",pi2,pi3], bc=2) -unit_square.Append(["line",pi3,pi4], bc=3) -unit_square.Append(["line",pi4,pi1], bc=4) - +pnts = [ (0,0), (1,0), (1,1), (0,1) ] +lines = [ (0,1,1), (1,2,2), (2,3,3), (3,0,4) ] +pnums = [unit_square.AppendPoint(*p) for p in pnts] +for l1,l2,bc in lines: + unit_square.Append( ["line", pnums[l1], pnums[l2]], bc=bc) all = ['SplineGeometry', 'unit_square']