mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-26 05:50:32 +05:00
py::init constructors
This commit is contained in:
parent
cf0d3f6682
commit
5de403ffd8
@ -204,39 +204,41 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
|||||||
;
|
;
|
||||||
|
|
||||||
py::class_<Element>(m, "Element3D")
|
py::class_<Element>(m, "Element3D")
|
||||||
.def("__init__", [](Element *instance, int index, py::list vertices)
|
.def(py::init([](int index, py::list vertices)
|
||||||
{
|
{
|
||||||
if (py::len(vertices) == 4)
|
Element * newel = nullptr;
|
||||||
{
|
if (py::len(vertices) == 4)
|
||||||
new (instance) Element(TET);
|
{
|
||||||
for (int i = 0; i < 4; i++)
|
newel = new Element(TET);
|
||||||
(*instance)[i] = py::extract<PointIndex>(vertices[i])();
|
for (int i = 0; i < 4; i++)
|
||||||
instance->SetIndex(index);
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||||
}
|
newel->SetIndex(index);
|
||||||
else if (py::len(vertices) == 5)
|
}
|
||||||
{
|
else if (py::len(vertices) == 5)
|
||||||
new (instance) Element(PYRAMID);
|
{
|
||||||
for (int i = 0; i < 5; i++)
|
newel = new Element(PYRAMID);
|
||||||
(*instance)[i] = py::extract<PointIndex>(vertices[i])();
|
for (int i = 0; i < 5; i++)
|
||||||
instance->SetIndex(index);
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||||
}
|
newel->SetIndex(index);
|
||||||
else if (py::len(vertices) == 6)
|
}
|
||||||
{
|
else if (py::len(vertices) == 6)
|
||||||
new (instance) Element(PRISM);
|
{
|
||||||
for (int i = 0; i < 6; i++)
|
newel = new Element(PRISM);
|
||||||
(*instance)[i] = py::extract<PointIndex>(vertices[i])();
|
for (int i = 0; i < 6; i++)
|
||||||
instance->SetIndex(index);
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||||
}
|
newel->SetIndex(index);
|
||||||
else if (py::len(vertices) == 8)
|
}
|
||||||
{
|
else if (py::len(vertices) == 8)
|
||||||
new (instance) Element(HEX);
|
{
|
||||||
for (int i = 0; i < 8; i++)
|
newel = new Element(HEX);
|
||||||
(*instance)[i] = py::extract<PointIndex>(vertices[i])();
|
for (int i = 0; i < 8; i++)
|
||||||
instance->SetIndex(index);
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||||
}
|
newel->SetIndex(index);
|
||||||
else
|
}
|
||||||
throw NgException ("cannot create element");
|
else
|
||||||
},
|
throw NgException ("cannot create element");
|
||||||
|
return newel;
|
||||||
|
}),
|
||||||
py::arg("index")=1,py::arg("vertices"),
|
py::arg("index")=1,py::arg("vertices"),
|
||||||
"create volume element"
|
"create volume element"
|
||||||
)
|
)
|
||||||
@ -261,36 +263,35 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
|||||||
;
|
;
|
||||||
|
|
||||||
py::class_<Element2d>(m, "Element2D")
|
py::class_<Element2d>(m, "Element2D")
|
||||||
.def("__init__",
|
.def(py::init ([](int index, py::list vertices)
|
||||||
[](Element2d *instance, int index, py::list vertices)
|
{
|
||||||
{
|
Element2d * newel = nullptr;
|
||||||
if (py::len(vertices) == 3)
|
if (py::len(vertices) == 3)
|
||||||
{
|
{
|
||||||
new (instance) Element2d(TRIG);
|
newel = new Element2d(TRIG);
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
(*instance)[i] = py::extract<PointIndex>(vertices[i])();
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||||
instance->SetIndex(index);
|
newel->SetIndex(index);
|
||||||
return;
|
}
|
||||||
}
|
else if (py::len(vertices) == 4)
|
||||||
if (py::len(vertices) == 4)
|
{
|
||||||
{
|
newel = new Element2d(QUAD);
|
||||||
new (instance) Element2d(QUAD);
|
for (int i = 0; i < 4; i++)
|
||||||
for (int i = 0; i < 4; i++)
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||||
(*instance)[i] = py::extract<PointIndex>(vertices[i])();
|
newel->SetIndex(index);
|
||||||
instance->SetIndex(index);
|
}
|
||||||
return;
|
else if (py::len(vertices) == 6)
|
||||||
}
|
{
|
||||||
if (py::len(vertices) == 6)
|
newel = new Element2d(TRIG6);
|
||||||
{
|
for(int i = 0; i<6; i++)
|
||||||
new (instance) Element2d(TRIG6);
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||||
for(int i = 0; i<6; i++)
|
newel->SetIndex(index);
|
||||||
(*instance)[i] = py::extract<PointIndex>(vertices[i])();
|
}
|
||||||
instance->SetIndex(index);
|
else
|
||||||
return;
|
throw NgException("Inconsistent number of vertices in Element2D");
|
||||||
}
|
return newel;
|
||||||
throw NgException("Inconsistent number of vertices in Element2D");
|
}),
|
||||||
},
|
py::arg("index")=1,py::arg("vertices"),
|
||||||
py::arg("index")=1,py::arg("vertices"),
|
|
||||||
"create surface element"
|
"create surface element"
|
||||||
)
|
)
|
||||||
.def_property("index", &Element2d::GetIndex, &Element2d::SetIndex)
|
.def_property("index", &Element2d::GetIndex, &Element2d::SetIndex)
|
||||||
@ -313,21 +314,21 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
|||||||
;
|
;
|
||||||
|
|
||||||
py::class_<Segment>(m, "Element1D")
|
py::class_<Segment>(m, "Element1D")
|
||||||
.def("__init__",
|
.def(py::init([](py::list vertices, py::list surfaces, int index)
|
||||||
[](Segment *instance, py::list vertices, py::list surfaces, int index)
|
{
|
||||||
{
|
Segment * newel = new Segment();
|
||||||
new (instance) Segment();
|
for (int i = 0; i < 2; i++)
|
||||||
for (int i = 0; i < 2; i++)
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||||
(*instance)[i] = py::extract<PointIndex>(vertices[i])();
|
newel -> si = index;
|
||||||
instance -> si = index;
|
// needed for codim2 in 3d
|
||||||
// needed for codim2 in 3d
|
newel -> edgenr = index;
|
||||||
instance -> edgenr = index;
|
if (len(surfaces))
|
||||||
if (len(surfaces))
|
{
|
||||||
{
|
newel->surfnr1 = py::extract<int>(surfaces[0])();
|
||||||
instance->surfnr1 = py::extract<int>(surfaces[0])();
|
newel->surfnr2 = py::extract<int>(surfaces[1])();
|
||||||
instance->surfnr2 = py::extract<int>(surfaces[1])();
|
}
|
||||||
}
|
return newel;
|
||||||
},
|
}),
|
||||||
py::arg("vertices"),
|
py::arg("vertices"),
|
||||||
py::arg("surfaces")=py::list(),
|
py::arg("surfaces")=py::list(),
|
||||||
py::arg("index")=1,
|
py::arg("index")=1,
|
||||||
@ -370,13 +371,13 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
|||||||
|
|
||||||
|
|
||||||
py::class_<Element0d>(m, "Element0D")
|
py::class_<Element0d>(m, "Element0D")
|
||||||
.def("__init__",
|
.def(py::init([](PointIndex vertex, int index)
|
||||||
[](Element0d *instance, PointIndex vertex, int index)
|
{
|
||||||
{
|
Element0d * instance = new Element0d;
|
||||||
new (instance) Element0d;
|
instance->pnum = vertex;
|
||||||
instance->pnum = vertex;
|
instance->index = index;
|
||||||
instance->index = index;
|
return instance;
|
||||||
},
|
}),
|
||||||
py::arg("vertex"),
|
py::arg("vertex"),
|
||||||
py::arg("index")=1,
|
py::arg("index")=1,
|
||||||
"create point element"
|
"create point element"
|
||||||
@ -397,19 +398,19 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
|||||||
|
|
||||||
py::class_<FaceDescriptor>(m, "FaceDescriptor")
|
py::class_<FaceDescriptor>(m, "FaceDescriptor")
|
||||||
.def(py::init<const FaceDescriptor&>())
|
.def(py::init<const FaceDescriptor&>())
|
||||||
.def("__init__",
|
.def(py::init([](int surfnr, int domin, int domout, int bc)
|
||||||
[](FaceDescriptor *instance, int surfnr, int domin, int domout, int bc)
|
{
|
||||||
{
|
FaceDescriptor * instance = new FaceDescriptor();
|
||||||
new (instance) FaceDescriptor();
|
instance->SetSurfNr(surfnr);
|
||||||
instance->SetSurfNr(surfnr);
|
instance->SetDomainIn(domin);
|
||||||
instance->SetDomainIn(domin);
|
instance->SetDomainOut(domout);
|
||||||
instance->SetDomainOut(domout);
|
instance->SetBCProperty(bc);
|
||||||
instance->SetBCProperty(bc);
|
return instance;
|
||||||
},
|
}),
|
||||||
py::arg("surfnr")=1,
|
py::arg("surfnr")=1,
|
||||||
py::arg("domin")=1,
|
py::arg("domin")=1,
|
||||||
py::arg("domout")=py::int_(0),
|
py::arg("domout")=py::int_(0),
|
||||||
py::arg("bc")=py::int_(0),
|
py::arg("bc")=py::int_(0),
|
||||||
"create facedescriptor")
|
"create facedescriptor")
|
||||||
.def("__str__", &ToString<FaceDescriptor>)
|
.def("__str__", &ToString<FaceDescriptor>)
|
||||||
.def("__repr__", &ToString<FaceDescriptor>)
|
.def("__repr__", &ToString<FaceDescriptor>)
|
||||||
@ -792,40 +793,40 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
|||||||
.value("MESHSURFACE",MESHCONST_OPTSURFACE)
|
.value("MESHSURFACE",MESHCONST_OPTSURFACE)
|
||||||
.value("MESHVOLUME",MESHCONST_OPTVOLUME)
|
.value("MESHVOLUME",MESHCONST_OPTVOLUME)
|
||||||
;
|
;
|
||||||
|
|
||||||
typedef MeshingParameters MP;
|
typedef MeshingParameters MP;
|
||||||
py::class_<MP> (m, "MeshingParameters")
|
py::class_<MP> (m, "MeshingParameters")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def("__init__",
|
.def(py::init([](double maxh, bool quad_dominated, int optsteps2d, int optsteps3d,
|
||||||
[](MP *instance, double maxh, bool quad_dominated, int optsteps2d, int optsteps3d,
|
MESHING_STEP perfstepsend, int only3D_domain, const string & meshsizefilename,
|
||||||
MESHING_STEP perfstepsend, int only3D_domain, const string & meshsizefilename,
|
double grading, double curvaturesafety, double segmentsperedge)
|
||||||
double grading, double curvaturesafety, double segmentsperedge)
|
{
|
||||||
{
|
MP * instance = new MeshingParameters;
|
||||||
new (instance) MeshingParameters;
|
instance->maxh = maxh;
|
||||||
instance->maxh = maxh;
|
instance->quad = int(quad_dominated);
|
||||||
instance->quad = int(quad_dominated);
|
instance->optsteps2d = optsteps2d;
|
||||||
instance->optsteps2d = optsteps2d;
|
instance->optsteps3d = optsteps3d;
|
||||||
instance->optsteps3d = optsteps3d;
|
instance->only3D_domain_nr = only3D_domain;
|
||||||
instance->only3D_domain_nr = only3D_domain;
|
instance->perfstepsend = perfstepsend;
|
||||||
instance->perfstepsend = perfstepsend;
|
instance->meshsizefilename = meshsizefilename;
|
||||||
instance->meshsizefilename = meshsizefilename;
|
|
||||||
|
instance->grading = grading;
|
||||||
instance->grading = grading;
|
instance->curvaturesafety = curvaturesafety;
|
||||||
instance->curvaturesafety = curvaturesafety;
|
instance->segmentsperedge = segmentsperedge;
|
||||||
instance->segmentsperedge = segmentsperedge;
|
return instance;
|
||||||
},
|
}),
|
||||||
py::arg("maxh")=1000,
|
py::arg("maxh")=1000,
|
||||||
py::arg("quad_dominated")=false,
|
py::arg("quad_dominated")=false,
|
||||||
py::arg("optsteps2d") = 3,
|
py::arg("optsteps2d") = 3,
|
||||||
py::arg("optsteps3d") = 3,
|
py::arg("optsteps3d") = 3,
|
||||||
py::arg("perfstepsend") = MESHCONST_OPTVOLUME,
|
py::arg("perfstepsend") = MESHCONST_OPTVOLUME,
|
||||||
py::arg("only3D_domain") = 0,
|
py::arg("only3D_domain") = 0,
|
||||||
py::arg("meshsizefilename") = "",
|
py::arg("meshsizefilename") = "",
|
||||||
py::arg("grading")=0.3,
|
py::arg("grading")=0.3,
|
||||||
py::arg("curvaturesafety")=2,
|
py::arg("curvaturesafety")=2,
|
||||||
py::arg("segmentsperedge")=1,
|
py::arg("segmentsperedge")=1,
|
||||||
"create meshing parameters"
|
"create meshing parameters"
|
||||||
)
|
)
|
||||||
.def("__str__", &ToString<MP>)
|
.def("__str__", &ToString<MP>)
|
||||||
.def_property("maxh",
|
.def_property("maxh",
|
||||||
FunctionPointer ([](const MP & mp ) { return mp.maxh; }),
|
FunctionPointer ([](const MP & mp ) { return mp.maxh; }),
|
||||||
|
Loading…
Reference in New Issue
Block a user