mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-26 21:00:34 +05:00
python meshing (merge meshes)
This commit is contained in:
parent
5c5e84b4bc
commit
507b370a6f
@ -196,9 +196,25 @@ DLL_HEADER void ExportNetgenMeshing()
|
||||
|
||||
bp::class_<FaceDescriptor>("FaceDescriptor")
|
||||
.def(bp::init<const FaceDescriptor&>())
|
||||
.def("__init__", bp::make_constructor
|
||||
(FunctionPointer ([](int surfnr, int domin, int domout)
|
||||
{
|
||||
auto fd = new FaceDescriptor();
|
||||
fd->SetSurfNr(surfnr);
|
||||
fd->SetDomainIn(domin);
|
||||
fd->SetDomainOut(domout);
|
||||
return fd;
|
||||
}),
|
||||
bp::default_call_policies(), // need it to use arguments
|
||||
(bp::arg("surfnr")=1,
|
||||
bp::arg("domin")=1,
|
||||
bp::arg("domout")=0)),
|
||||
"create facedescriptor")
|
||||
.def("__str__", &ToString<FaceDescriptor>)
|
||||
.def("__repr__", &ToString<FaceDescriptor>)
|
||||
.add_property("surfnr", &FaceDescriptor::SurfNr, &FaceDescriptor::SetSurfNr)
|
||||
.add_property("domin", &FaceDescriptor::DomainIn, &FaceDescriptor::SetDomainIn)
|
||||
.add_property("domout", &FaceDescriptor::DomainOut, &FaceDescriptor::SetDomainOut)
|
||||
;
|
||||
|
||||
|
||||
@ -282,17 +298,20 @@ DLL_HEADER void ExportNetgenMeshing()
|
||||
return self.AddFaceDescriptor (fd);
|
||||
}))
|
||||
|
||||
/*
|
||||
.def("__init__", bp::make_constructor
|
||||
(FunctionPointer ([]()
|
||||
{
|
||||
cout << "create new mesh" << endl;
|
||||
auto tmp = make_shared<Mesh>();
|
||||
return tmp;
|
||||
})),
|
||||
"create empty mesh"
|
||||
)
|
||||
*/
|
||||
.def ("GenerateVolumeMesh", FunctionPointer
|
||||
([](Mesh & self)
|
||||
{
|
||||
cout << "generate vol mesh" << endl;
|
||||
MeshingParameters mp;
|
||||
MeshVolume (mp, self);
|
||||
}))
|
||||
|
||||
.def ("Refine", FunctionPointer
|
||||
([](Mesh & self)
|
||||
{
|
||||
self.GetGeometry()->GetRefinement().Refine(self);
|
||||
}))
|
||||
|
||||
.def ("BoundaryLayer", FunctionPointer
|
||||
([](Mesh & self, int bc, double thickness, int volnr, string material)
|
||||
{
|
||||
|
58
py_tutorials/merge.py
Normal file
58
py_tutorials/merge.py
Normal file
@ -0,0 +1,58 @@
|
||||
from netgen.meshing import *
|
||||
from netgen.csg import *
|
||||
|
||||
from ngsolve import ngsglobals
|
||||
ngsglobals.msg_level = 2
|
||||
|
||||
geo1 = CSGeometry()
|
||||
geo1.Add (OrthoBrick( Pnt(0,0,0), Pnt(1,1,1) ))
|
||||
m1 = geo1.GenerateMesh (maxh=0.1)
|
||||
m1.Refine()
|
||||
m1.Refine()
|
||||
|
||||
|
||||
geo2 = CSGeometry()
|
||||
geo2.Add (Sphere (Pnt(0.5,0.5,0.5), 0.1))
|
||||
m2 = geo2.GenerateMesh (maxh=0.05)
|
||||
m2.Refine()
|
||||
m2.Refine()
|
||||
|
||||
print ("********************")
|
||||
print ("** start merging **")
|
||||
print ("********************")
|
||||
|
||||
mesh = Mesh()
|
||||
fd_outside = mesh.Add (FaceDescriptor(surfnr=1,domin=1))
|
||||
fd_inside = mesh.Add (FaceDescriptor(surfnr=2,domin=2,domout=1))
|
||||
|
||||
|
||||
pmap1 = { }
|
||||
for e in m1.Elements2D():
|
||||
for v in e.vertices:
|
||||
if (v not in pmap1):
|
||||
pmap1[v] = mesh.Add (m1[v])
|
||||
|
||||
for e in m1.Elements2D():
|
||||
mesh.Add (Element2D (fd_outside, [pmap1[v] for v in e.vertices]))
|
||||
|
||||
|
||||
|
||||
pmap2 = { }
|
||||
for e in m2.Elements2D():
|
||||
for v in e.vertices:
|
||||
if (v not in pmap2):
|
||||
pmap2[v] = mesh.Add (m2[v])
|
||||
|
||||
for e in m2.Elements2D():
|
||||
mesh.Add (Element2D (fd_inside, [pmap2[v] for v in e.vertices]))
|
||||
|
||||
|
||||
print ("******************")
|
||||
print ("** merging done **")
|
||||
print ("******************")
|
||||
|
||||
|
||||
mesh.GenerateVolumeMesh()
|
||||
mesh.Save ("newmesh.vol")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user