mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +05:00
mesh has geometry-ptr
This commit is contained in:
parent
714385724c
commit
8c6cf8ded4
@ -21,6 +21,7 @@ class SPSolid
|
||||
shared_ptr<SPSolid> 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<SPSolid> & self, int nr) -> shared_ptr<SPSolid>
|
||||
{ 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>
|
||||
{ self->SetMaxH(maxh); return self; }))
|
||||
.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
|
||||
([](const string & filename)
|
||||
{
|
||||
@ -352,13 +374,13 @@ DLL_HEADER void ExportCSG()
|
||||
;
|
||||
|
||||
bp::def("GenerateMesh", FunctionPointer
|
||||
([](CSGeometry & geo, MeshingParameters & param)
|
||||
([](shared_ptr<CSGeometry> geo, MeshingParameters & param)
|
||||
{
|
||||
// testout = new ofstream ("test.out");
|
||||
shared_ptr<Mesh> dummy;
|
||||
geo.FindIdenticSurfaces(1e-8 * geo.MaxSize());
|
||||
geo.GenerateMesh (dummy, param, 0, 6);
|
||||
ng_geometry.reset (&geo, NOOP_Deleter);
|
||||
auto dummy = make_shared<Mesh>();
|
||||
dummy->SetGeometry(geo);
|
||||
ng_geometry = geo;
|
||||
geo->FindIdenticSurfaces(1e-8 * geo->MaxSize());
|
||||
geo->GenerateMesh (dummy, param, 0, 6);
|
||||
return dummy;
|
||||
}))
|
||||
;
|
||||
|
@ -221,6 +221,7 @@ DLL_HEADER void ExportGeom2d()
|
||||
.def("GenerateMesh", FunctionPointer([](shared_ptr<SplineGeometry2d> self, MeshingParameters & mparam)
|
||||
{
|
||||
shared_ptr<Mesh> mesh = make_shared<Mesh> ();
|
||||
mesh->SetGeometry(self);
|
||||
ng_geometry = self;
|
||||
self->GenerateMesh(mesh, mparam, 0, 0);
|
||||
return mesh;
|
||||
|
@ -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<Refinement&> (ng_geometry->GetRefinement()).MakeSecondOrder(*mesh);
|
||||
const_cast<Refinement&> (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<Refinement&> (ng_geometry -> GetRefinement());
|
||||
Refinement & ref = const_cast<Refinement&> (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<Refinement&> (ng_geometry -> GetRefinement()),
|
||||
(&const_cast<Refinement&> (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<Refinement*> (&ng_geometry -> GetRefinement());
|
||||
Refinement * ref = const_cast<Refinement*> (&mesh->GetGeometry()->GetRefinement());
|
||||
MeshOptimize2d * opt = NULL;
|
||||
/*
|
||||
if (stlgeometry)
|
||||
|
@ -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;
|
||||
|
||||
|
@ -140,6 +140,8 @@ namespace netgen
|
||||
#endif
|
||||
|
||||
|
||||
shared_ptr<NetgenGeometry> geometry;
|
||||
|
||||
private:
|
||||
void BuildBoundaryEdges(void);
|
||||
|
||||
@ -722,6 +724,15 @@ namespace netgen
|
||||
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);
|
||||
///
|
||||
|
20
ng/ngpkg.cpp
20
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<Refinement&> (ng_geometry->GetRefinement()).MakeSecondOrder(*mesh);
|
||||
const_cast<Refinement&> (mesh->GetGeometry()->GetRefinement()).MakeSecondOrder(*mesh);
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
@ -884,7 +885,7 @@ namespace netgen
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
const_cast<Refinement&> (ng_geometry -> GetRefinement()).MakeSecondOrder (*mesh);
|
||||
const_cast<Refinement&> (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<Refinement&> (ng_geometry -> GetRefinement());
|
||||
Refinement & ref = const_cast<Refinement&> (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<Refinement&> (ng_geometry -> GetRefinement());
|
||||
Refinement & ref = const_cast<Refinement&> (mesh->GetGeometry()->GetRefinement());
|
||||
ref.ValidateSecondOrder (*mesh);
|
||||
|
||||
multithread.running = 0;
|
||||
@ -1010,7 +1011,7 @@ namespace netgen
|
||||
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);
|
||||
return TCL_OK;
|
||||
}
|
||||
@ -1334,6 +1335,7 @@ namespace netgen
|
||||
mesh = make_shared<Mesh> ();
|
||||
// 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<Refinement&> (ng_geometry -> GetRefinement()).MakeSecondOrder (*mesh);
|
||||
const_cast<Refinement&> (mesh->GetGeometry()->GetRefinement()).MakeSecondOrder (*mesh);
|
||||
mesh -> SetNextMajorTimeStamp();
|
||||
}
|
||||
|
||||
if (mparam.elementorder > 1)
|
||||
{
|
||||
mesh -> GetCurvedElements().BuildCurvedElements (&const_cast<Refinement&> (ng_geometry -> GetRefinement()),
|
||||
mesh -> GetCurvedElements().BuildCurvedElements (&const_cast<Refinement&> (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;
|
||||
|
||||
/*
|
||||
|
@ -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']
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user