mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-26 13:50:33 +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)
|
||||||
{
|
{
|
||||||
|
Element * newel = nullptr;
|
||||||
if (py::len(vertices) == 4)
|
if (py::len(vertices) == 4)
|
||||||
{
|
{
|
||||||
new (instance) Element(TET);
|
newel = new Element(TET);
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
(*instance)[i] = py::extract<PointIndex>(vertices[i])();
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||||
instance->SetIndex(index);
|
newel->SetIndex(index);
|
||||||
}
|
}
|
||||||
else if (py::len(vertices) == 5)
|
else if (py::len(vertices) == 5)
|
||||||
{
|
{
|
||||||
new (instance) Element(PYRAMID);
|
newel = new Element(PYRAMID);
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
(*instance)[i] = py::extract<PointIndex>(vertices[i])();
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||||
instance->SetIndex(index);
|
newel->SetIndex(index);
|
||||||
}
|
}
|
||||||
else if (py::len(vertices) == 6)
|
else if (py::len(vertices) == 6)
|
||||||
{
|
{
|
||||||
new (instance) Element(PRISM);
|
newel = new Element(PRISM);
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
(*instance)[i] = py::extract<PointIndex>(vertices[i])();
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||||
instance->SetIndex(index);
|
newel->SetIndex(index);
|
||||||
}
|
}
|
||||||
else if (py::len(vertices) == 8)
|
else if (py::len(vertices) == 8)
|
||||||
{
|
{
|
||||||
new (instance) Element(HEX);
|
newel = new Element(HEX);
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++)
|
||||||
(*instance)[i] = py::extract<PointIndex>(vertices[i])();
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||||
instance->SetIndex(index);
|
newel->SetIndex(index);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw NgException ("cannot create element");
|
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,35 +263,34 @@ 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;
|
|
||||||
}
|
}
|
||||||
if (py::len(vertices) == 4)
|
else if (py::len(vertices) == 4)
|
||||||
{
|
{
|
||||||
new (instance) Element2d(QUAD);
|
newel = new Element2d(QUAD);
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
(*instance)[i] = py::extract<PointIndex>(vertices[i])();
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||||
instance->SetIndex(index);
|
newel->SetIndex(index);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (py::len(vertices) == 6)
|
else if (py::len(vertices) == 6)
|
||||||
{
|
{
|
||||||
new (instance) Element2d(TRIG6);
|
newel = new Element2d(TRIG6);
|
||||||
for(int i = 0; i<6; i++)
|
for(int i = 0; i<6; i++)
|
||||||
(*instance)[i] = py::extract<PointIndex>(vertices[i])();
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||||
instance->SetIndex(index);
|
newel->SetIndex(index);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
throw NgException("Inconsistent number of vertices in Element2D");
|
throw NgException("Inconsistent number of vertices in Element2D");
|
||||||
},
|
return newel;
|
||||||
|
}),
|
||||||
py::arg("index")=1,py::arg("vertices"),
|
py::arg("index")=1,py::arg("vertices"),
|
||||||
"create surface element"
|
"create surface element"
|
||||||
)
|
)
|
||||||
@ -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)
|
|
||||||
{
|
{
|
||||||
new (instance) Segment();
|
Segment * newel = new Segment();
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
(*instance)[i] = py::extract<PointIndex>(vertices[i])();
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||||
instance -> si = index;
|
newel -> si = index;
|
||||||
// needed for codim2 in 3d
|
// needed for codim2 in 3d
|
||||||
instance -> edgenr = index;
|
newel -> edgenr = index;
|
||||||
if (len(surfaces))
|
if (len(surfaces))
|
||||||
{
|
{
|
||||||
instance->surfnr1 = py::extract<int>(surfaces[0])();
|
newel->surfnr1 = py::extract<int>(surfaces[0])();
|
||||||
instance->surfnr2 = py::extract<int>(surfaces[1])();
|
newel->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)
|
|
||||||
{
|
{
|
||||||
new (instance) Element0d;
|
Element0d * instance = new 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,15 +398,15 @@ 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)
|
|
||||||
{
|
{
|
||||||
new (instance) FaceDescriptor();
|
FaceDescriptor * instance = new 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),
|
||||||
@ -796,12 +797,11 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
|||||||
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)
|
||||||
{
|
{
|
||||||
new (instance) MeshingParameters;
|
MP * instance = new MeshingParameters;
|
||||||
instance->maxh = maxh;
|
instance->maxh = maxh;
|
||||||
instance->quad = int(quad_dominated);
|
instance->quad = int(quad_dominated);
|
||||||
instance->optsteps2d = optsteps2d;
|
instance->optsteps2d = optsteps2d;
|
||||||
@ -813,7 +813,8 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
|||||||
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,
|
||||||
|
Loading…
Reference in New Issue
Block a user