mesh has geometry-ptr

This commit is contained in:
Joachim Schoeberl 2015-08-08 19:10:48 +02:00
parent 714385724c
commit 8c6cf8ded4
7 changed files with 84 additions and 34 deletions

View File

@ -21,6 +21,7 @@ class SPSolid
shared_ptr<SPSolid> s1, s2; shared_ptr<SPSolid> s1, s2;
Solid * solid; Solid * solid;
int bc = -1; int bc = -1;
string bcname = "";
double maxh = -1; double maxh = -1;
string material; string material;
bool owner; 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) void SetMaxH(double amaxh)
{ {
if (maxh == -1) if (maxh == -1)
@ -201,6 +221,8 @@ DLL_HEADER void ExportCSG()
.def ("bc", FunctionPointer([](shared_ptr<SPSolid> & self, int nr) -> shared_ptr<SPSolid> .def ("bc", FunctionPointer([](shared_ptr<SPSolid> & self, int nr) -> shared_ptr<SPSolid>
{ self->SetBC(nr); return self; })) { self->SetBC(nr); return self; }))
.def ("bc", FunctionPointer([](shared_ptr<SPSolid> & self, string name) -> shared_ptr<SPSolid>
{ self->SetBCName(name); return self; }))
.def ("maxh", FunctionPointer([](shared_ptr<SPSolid> & self, double maxh) -> shared_ptr<SPSolid> .def ("maxh", FunctionPointer([](shared_ptr<SPSolid> & self, double maxh) -> shared_ptr<SPSolid>
{ self->SetMaxH(maxh); return self; })) { self->SetMaxH(maxh); return self; }))
.def ("mat", FunctionPointer([](shared_ptr<SPSolid> & self, string mat) -> shared_ptr<SPSolid> .def ("mat", FunctionPointer([](shared_ptr<SPSolid> & self, string mat) -> shared_ptr<SPSolid>
@ -252,7 +274,7 @@ DLL_HEADER void ExportCSG()
})); }));
bp::class_<CSGeometry, boost::noncopyable> ("CSGeometry") bp::class_<CSGeometry,shared_ptr<CSGeometry>, boost::noncopyable> ("CSGeometry")
.def("__init__", bp::make_constructor (FunctionPointer .def("__init__", bp::make_constructor (FunctionPointer
([](const string & filename) ([](const string & filename)
{ {
@ -352,13 +374,13 @@ DLL_HEADER void ExportCSG()
; ;
bp::def("GenerateMesh", FunctionPointer bp::def("GenerateMesh", FunctionPointer
([](CSGeometry & geo, MeshingParameters & param) ([](shared_ptr<CSGeometry> geo, MeshingParameters & param)
{ {
// testout = new ofstream ("test.out"); auto dummy = make_shared<Mesh>();
shared_ptr<Mesh> dummy; dummy->SetGeometry(geo);
geo.FindIdenticSurfaces(1e-8 * geo.MaxSize()); ng_geometry = geo;
geo.GenerateMesh (dummy, param, 0, 6); geo->FindIdenticSurfaces(1e-8 * geo->MaxSize());
ng_geometry.reset (&geo, NOOP_Deleter); geo->GenerateMesh (dummy, param, 0, 6);
return dummy; return dummy;
})) }))
; ;

View File

@ -221,6 +221,7 @@ DLL_HEADER void ExportGeom2d()
.def("GenerateMesh", FunctionPointer([](shared_ptr<SplineGeometry2d> self, MeshingParameters & mparam) .def("GenerateMesh", FunctionPointer([](shared_ptr<SplineGeometry2d> self, MeshingParameters & mparam)
{ {
shared_ptr<Mesh> mesh = make_shared<Mesh> (); shared_ptr<Mesh> mesh = make_shared<Mesh> ();
mesh->SetGeometry(self);
ng_geometry = self; ng_geometry = self;
self->GenerateMesh(mesh, mparam, 0, 0); self->GenerateMesh(mesh, mparam, 0, 0);
return mesh; return mesh;

View File

@ -158,10 +158,7 @@ void Ng_LoadMeshFromStream ( istream & input )
{ {
mesh.reset (new Mesh()); mesh.reset (new Mesh());
mesh -> Load(input); mesh -> Load(input);
/*
vssolution.SetMesh(mesh);
vsmesh.SetMesh(mesh);
*/
SetGlobalMesh (mesh); SetGlobalMesh (mesh);
for (int i = 0; i < geometryregister.Size(); i++) for (int i = 0; i < geometryregister.Size(); i++)
{ {
@ -172,6 +169,8 @@ void Ng_LoadMeshFromStream ( istream & input )
break; break;
} }
} }
mesh->SetGeometry (ng_geometry);
} }
@ -1017,7 +1016,7 @@ void Ng_Refine (NG_REFINEMENT_TYPE reftype)
if (reftype == NG_REFINE_HP) if (reftype == NG_REFINE_HP)
biopt.refine_hp = 1; biopt.refine_hp = 1;
const Refinement & ref = ng_geometry->GetRefinement(); const Refinement & ref = mesh->GetGeometry()->GetRefinement();
// Refinement * ref; // Refinement * ref;
MeshOptimize2d * opt = NULL; MeshOptimize2d * opt = NULL;
@ -1063,7 +1062,7 @@ void Ng_Refine (NG_REFINEMENT_TYPE reftype)
void Ng_SecondOrder () void Ng_SecondOrder ()
{ {
const_cast<Refinement&> (ng_geometry->GetRefinement()).MakeSecondOrder(*mesh); const_cast<Refinement&> (mesh->GetGeometry()->GetRefinement()).MakeSecondOrder(*mesh);
/* /*
if (stlgeometry) if (stlgeometry)
{ {
@ -1130,7 +1129,7 @@ void Ng_HPRefinement (int levels, double parameter, bool setorders,
bool ref_level) bool ref_level)
{ {
NgLock meshlock (mesh->MajorMutex(), true); NgLock meshlock (mesh->MajorMutex(), true);
Refinement & ref = const_cast<Refinement&> (ng_geometry -> GetRefinement()); Refinement & ref = const_cast<Refinement&> (mesh->GetGeometry()->GetRefinement());
HPRefinement (*mesh, &ref, levels, parameter, setorders, ref_level); HPRefinement (*mesh, &ref, levels, parameter, setorders, ref_level);
/* /*
Refinement * ref; Refinement * ref;
@ -1156,7 +1155,7 @@ void Ng_HighOrder (int order, bool rational)
order, rational); order, rational);
*/ */
mesh->BuildCurvedElements mesh->BuildCurvedElements
(&const_cast<Refinement&> (ng_geometry -> GetRefinement()), (&const_cast<Refinement&> (mesh->GetGeometry()->GetRefinement()),
order, rational); order, rational);
mesh -> SetNextMajorTimeStamp(); mesh -> SetNextMajorTimeStamp();
@ -2105,7 +2104,7 @@ int Ng_Bisect_WithInfo ( const char * refinementfile, double ** qualityloss, int
biopt.femcode = "fepp"; biopt.femcode = "fepp";
biopt.refinementfilename = refinementfile; biopt.refinementfilename = refinementfile;
Refinement * ref = const_cast<Refinement*> (&ng_geometry -> GetRefinement()); Refinement * ref = const_cast<Refinement*> (&mesh->GetGeometry()->GetRefinement());
MeshOptimize2d * opt = NULL; MeshOptimize2d * opt = NULL;
/* /*
if (stlgeometry) if (stlgeometry)

View File

@ -794,6 +794,12 @@ namespace netgen
void Mesh :: Load (istream & infile) void Mesh :: Load (istream & infile)
{ {
if (! (infile.good()) )
{
cout << "cannot load mesh" << endl;
throw NgException ("mesh file not found");
}
char str[100]; char str[100];
int i, n; int i, n;

View File

@ -140,6 +140,8 @@ namespace netgen
#endif #endif
shared_ptr<NetgenGeometry> geometry;
private: private:
void BuildBoundaryEdges(void); void BuildBoundaryEdges(void);
@ -722,6 +724,15 @@ namespace netgen
NgMutex & MajorMutex () { return majormutex; } NgMutex & MajorMutex () { return majormutex; }
shared_ptr<NetgenGeometry> GetGeometry() const
{
return geometry;
}
void SetGeometry (shared_ptr<NetgenGeometry> geom)
{
geometry = geom;
}
/// ///
void SetUserData(const char * id, Array<int> & data); void SetUserData(const char * id, Array<int> & data);
/// ///

View File

@ -859,12 +859,13 @@ namespace netgen
else else
#endif #endif
{ {
ng_geometry -> GetRefinement().Refine(*mesh); // ng_geometry -> GetRefinement().Refine(*mesh);
mesh->GetGeometry()->GetRefinement().Refine(*mesh);
} }
//redo second order refinement if desired //redo second order refinement if desired
if (mparam.secondorder) if (mparam.secondorder)
const_cast<Refinement&> (ng_geometry->GetRefinement()).MakeSecondOrder(*mesh); const_cast<Refinement&> (mesh->GetGeometry()->GetRefinement()).MakeSecondOrder(*mesh);
return TCL_OK; return TCL_OK;
} }
@ -884,7 +885,7 @@ namespace netgen
return TCL_ERROR; return TCL_ERROR;
} }
const_cast<Refinement&> (ng_geometry -> GetRefinement()).MakeSecondOrder (*mesh); const_cast<Refinement&> (mesh->GetGeometry()->GetRefinement()).MakeSecondOrder (*mesh);
return TCL_OK; return TCL_OK;
} }
@ -895,7 +896,7 @@ namespace netgen
// mparam.elementorder = atoi (Tcl_GetVar (interp, "options.elementorder", 0)); // mparam.elementorder = atoi (Tcl_GetVar (interp, "options.elementorder", 0));
const char * savetask = multithread.task; const char * savetask = multithread.task;
Refinement & ref = const_cast<Refinement&> (ng_geometry -> GetRefinement()); Refinement & ref = const_cast<Refinement&> (mesh->GetGeometry()->GetRefinement());
mesh -> GetCurvedElements().BuildCurvedElements (&ref, mparam.elementorder); mesh -> GetCurvedElements().BuildCurvedElements (&ref, mparam.elementorder);
multithread.task = savetask; multithread.task = savetask;
@ -936,7 +937,7 @@ namespace netgen
void * ValidateDummy (void *) void * ValidateDummy (void *)
{ {
Refinement & ref = const_cast<Refinement&> (ng_geometry -> GetRefinement()); Refinement & ref = const_cast<Refinement&> (mesh->GetGeometry()->GetRefinement());
ref.ValidateSecondOrder (*mesh); ref.ValidateSecondOrder (*mesh);
multithread.running = 0; multithread.running = 0;
@ -1010,7 +1011,7 @@ namespace netgen
int levels = atoi (argv[1]); int levels = atoi (argv[1]);
Refinement & ref = const_cast<Refinement&> (ng_geometry -> GetRefinement()); Refinement & ref = const_cast<Refinement&> (mesh->GetGeometry()->GetRefinement());
HPRefinement (*mesh, &ref, levels); HPRefinement (*mesh, &ref, levels);
return TCL_OK; return TCL_OK;
} }
@ -1334,6 +1335,7 @@ namespace netgen
mesh = make_shared<Mesh> (); mesh = make_shared<Mesh> ();
// vsmesh.SetMesh (mesh); // vsmesh.SetMesh (mesh);
SetGlobalMesh (mesh); SetGlobalMesh (mesh);
mesh -> SetGeometry(ng_geometry);
int res = ng_geometry -> GenerateMesh (mesh, mparam, perfstepsstart, perfstepsend); int res = ng_geometry -> GenerateMesh (mesh, mparam, perfstepsstart, perfstepsend);
// int res = ng_geometry -> GenerateMesh (mesh.Ptr(), mparam, perfstepsstart, perfstepsend); // int res = ng_geometry -> GenerateMesh (mesh.Ptr(), mparam, perfstepsstart, perfstepsend);
@ -1355,13 +1357,13 @@ namespace netgen
if (mparam.secondorder) if (mparam.secondorder)
{ {
const_cast<Refinement&> (ng_geometry -> GetRefinement()).MakeSecondOrder (*mesh); const_cast<Refinement&> (mesh->GetGeometry()->GetRefinement()).MakeSecondOrder (*mesh);
mesh -> SetNextMajorTimeStamp(); mesh -> SetNextMajorTimeStamp();
} }
if (mparam.elementorder > 1) if (mparam.elementorder > 1)
{ {
mesh -> GetCurvedElements().BuildCurvedElements (&const_cast<Refinement&> (ng_geometry -> GetRefinement()), mesh -> GetCurvedElements().BuildCurvedElements (&const_cast<Refinement&> (mesh->GetGeometry()->GetRefinement()),
mparam.elementorder); mparam.elementorder);
mesh -> SetNextMajorTimeStamp(); mesh -> SetNextMajorTimeStamp();
@ -1709,7 +1711,7 @@ namespace netgen
void * BisectDummy (void *) void * BisectDummy (void *)
{ {
const Refinement & ref = ng_geometry->GetRefinement(); const Refinement & ref = mesh->GetGeometry()->GetRefinement();
MeshOptimize2d * opt = NULL; MeshOptimize2d * opt = NULL;
/* /*

View File

@ -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() unit_square = SplineGeometry()
pi1 = unit_square.AppendPoint(0,0) pnts = [ (0,0), (1,0), (1,1), (0,1) ]
pi2 = unit_square.AppendPoint(1,0) lines = [ (0,1,1), (1,2,2), (2,3,3), (3,0,4) ]
pi3 = unit_square.AppendPoint(1,1) pnums = [unit_square.AppendPoint(*p) for p in pnts]
pi4 = unit_square.AppendPoint(0,1) for l1,l2,bc in lines:
unit_square.Append(["line",pi1,pi2], bc=1) unit_square.Append( ["line", pnums[l1], pnums[l2]], bc=bc)
unit_square.Append(["line",pi2,pi3], bc=2)
unit_square.Append(["line",pi3,pi4], bc=3)
unit_square.Append(["line",pi4,pi1], bc=4)
all = ['SplineGeometry', 'unit_square'] all = ['SplineGeometry', 'unit_square']