2014-08-31 19:05:24 +06:00
|
|
|
#ifdef NG_PYTHON
|
|
|
|
|
2014-10-08 21:48:48 +06:00
|
|
|
#include <../general/ngpython.hpp>
|
2019-07-11 19:23:22 +05:00
|
|
|
#include <core/python_ngcore.hpp>
|
2019-07-26 02:25:58 +05:00
|
|
|
#include "python_mesh.hpp"
|
2014-08-30 06:15:59 +06:00
|
|
|
|
|
|
|
#include <mystdlib.h>
|
|
|
|
#include "meshing.hpp"
|
2017-01-05 09:08:24 +05:00
|
|
|
// #include <csg.hpp>
|
|
|
|
// #include <geometry2d.hpp>
|
2016-07-10 21:07:36 +05:00
|
|
|
#include <../interface/writeuser.hpp>
|
2014-08-30 06:15:59 +06:00
|
|
|
|
|
|
|
|
|
|
|
using namespace netgen;
|
|
|
|
|
2017-05-30 00:19:34 +05:00
|
|
|
extern const char *ngscript[];
|
|
|
|
|
2014-12-19 19:03:36 +05:00
|
|
|
namespace netgen
|
|
|
|
{
|
2017-05-15 21:56:47 +05:00
|
|
|
extern bool netgen_executable_started;
|
2014-12-19 19:03:36 +05:00
|
|
|
extern shared_ptr<NetgenGeometry> ng_geometry;
|
2019-04-10 17:13:12 +05:00
|
|
|
extern void Optimize2d (Mesh & mesh, MeshingParameters & mp);
|
|
|
|
|
2019-01-31 00:55:45 +05:00
|
|
|
#ifdef PARALLEL
|
|
|
|
/** we need allreduce in python-wrapped communicators **/
|
|
|
|
template <typename T>
|
2019-02-13 02:11:55 +05:00
|
|
|
inline T MyMPI_AllReduceNG (T d, const MPI_Op & op /* = MPI_SUM */, MPI_Comm comm)
|
2019-01-31 00:55:45 +05:00
|
|
|
{
|
|
|
|
T global_d;
|
|
|
|
MPI_Allreduce ( &d, &global_d, 1, MyGetMPIType<T>(), op, comm);
|
|
|
|
return global_d;
|
|
|
|
}
|
|
|
|
#else
|
2019-02-13 02:27:58 +05:00
|
|
|
// enum { MPI_SUM = 0, MPI_MIN = 1, MPI_MAX = 2 };
|
|
|
|
// typedef int MPI_Op;
|
2019-01-31 00:55:45 +05:00
|
|
|
template <typename T>
|
2019-02-13 02:11:55 +05:00
|
|
|
inline T MyMPI_AllReduceNG (T d, const MPI_Op & op /* = MPI_SUM */, MPI_Comm comm)
|
2019-01-31 00:55:45 +05:00
|
|
|
{ return d; }
|
|
|
|
#endif
|
2014-12-19 19:03:36 +05:00
|
|
|
}
|
|
|
|
|
2014-08-30 06:15:59 +06:00
|
|
|
|
2015-10-22 20:26:43 +05:00
|
|
|
void TranslateException (const NgException & ex)
|
|
|
|
{
|
|
|
|
string err = string("Netgen exception: ")+ex.What();
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, err.c_str());
|
|
|
|
}
|
2014-08-30 06:15:59 +06:00
|
|
|
|
2017-01-05 09:08:24 +05:00
|
|
|
static Transformation<3> global_trafo(Vec<3> (0,0,0));
|
2014-08-30 06:15:59 +06:00
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
2014-08-30 06:15:59 +06:00
|
|
|
{
|
2017-08-24 16:59:16 +05:00
|
|
|
py::register_exception<NgException>(m, "NgException");
|
2017-05-15 21:56:47 +05:00
|
|
|
m.attr("_netgen_executable_started") = py::cast(netgen::netgen_executable_started);
|
2017-05-30 00:19:34 +05:00
|
|
|
string script;
|
|
|
|
const char ** hcp = ngscript;
|
|
|
|
while (*hcp)
|
|
|
|
script += *hcp++;
|
|
|
|
|
|
|
|
m.attr("_ngscript") = py::cast(script);
|
2017-05-15 21:56:47 +05:00
|
|
|
|
2018-11-06 15:41:04 +05:00
|
|
|
m.def("_GetStatus", []()
|
|
|
|
{
|
|
|
|
MyStr s; double percent;
|
|
|
|
GetStatus(s, percent);
|
|
|
|
return py::make_tuple(s.c_str(), percent);
|
|
|
|
});
|
|
|
|
m.def("_PushStatus", [](string s) { PushStatus(MyStr(s)); });
|
|
|
|
m.def("_SetThreadPercentage", [](double percent) { SetThreadPercent(percent); });
|
|
|
|
|
2019-02-12 03:59:32 +05:00
|
|
|
py::class_<NgMPI_Comm> (m, "MPI_Comm")
|
|
|
|
.def_property_readonly ("rank", &NgMPI_Comm::Rank)
|
|
|
|
.def_property_readonly ("size", &NgMPI_Comm::Size)
|
2019-02-13 02:11:55 +05:00
|
|
|
.def("Barrier", &NgMPI_Comm::Barrier)
|
|
|
|
|
2019-02-12 03:59:32 +05:00
|
|
|
#ifdef PARALLEL
|
|
|
|
.def("WTime", [](NgMPI_Comm & c) { return MPI_Wtime(); })
|
|
|
|
#else
|
|
|
|
.def("WTime", [](NgMPI_Comm & c) { return -1.0; })
|
|
|
|
#endif
|
|
|
|
.def("Sum", [](NgMPI_Comm & c, double x) { return MyMPI_AllReduceNG(x, MPI_SUM, c); })
|
|
|
|
.def("Min", [](NgMPI_Comm & c, double x) { return MyMPI_AllReduceNG(x, MPI_MIN, c); })
|
|
|
|
.def("Max", [](NgMPI_Comm & c, double x) { return MyMPI_AllReduceNG(x, MPI_MAX, c); })
|
|
|
|
.def("Sum", [](NgMPI_Comm & c, int x) { return MyMPI_AllReduceNG(x, MPI_SUM, c); })
|
|
|
|
.def("Min", [](NgMPI_Comm & c, int x) { return MyMPI_AllReduceNG(x, MPI_MIN, c); })
|
|
|
|
.def("Max", [](NgMPI_Comm & c, int x) { return MyMPI_AllReduceNG(x, MPI_MAX, c); })
|
|
|
|
.def("Sum", [](NgMPI_Comm & c, size_t x) { return MyMPI_AllReduceNG(x, MPI_SUM, c); })
|
|
|
|
.def("Min", [](NgMPI_Comm & c, size_t x) { return MyMPI_AllReduceNG(x, MPI_MIN, c); })
|
|
|
|
.def("Max", [](NgMPI_Comm & c, size_t x) { return MyMPI_AllReduceNG(x, MPI_MAX, c); })
|
|
|
|
.def("SubComm", [](NgMPI_Comm & c, std::vector<int> proc_list) {
|
2019-08-26 16:13:53 +05:00
|
|
|
Array<int> procs(proc_list.size());
|
2019-02-12 03:59:32 +05:00
|
|
|
for (int i = 0; i < procs.Size(); i++)
|
2019-08-26 16:13:53 +05:00
|
|
|
{ procs[i] = proc_list[i]; }
|
2019-02-12 03:59:32 +05:00
|
|
|
if (!procs.Contains(c.Rank()))
|
2019-08-26 16:13:53 +05:00
|
|
|
{ throw Exception("rank "+ToString(c.Rank())+" not in subcomm"); }
|
|
|
|
return c.SubCommunicator(procs);
|
2019-02-12 03:59:32 +05:00
|
|
|
}, py::arg("procs"));
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-01-05 09:08:24 +05:00
|
|
|
py::class_<NGDummyArgument>(m, "NGDummyArgument")
|
|
|
|
.def("__bool__", []( NGDummyArgument &self ) { return false; } )
|
|
|
|
;
|
2014-08-30 06:15:59 +06:00
|
|
|
|
2017-01-05 09:08:24 +05:00
|
|
|
py::class_<Point<2>> (m, "Point2d")
|
|
|
|
.def(py::init<double,double>())
|
|
|
|
.def ("__str__", &ToString<Point<2>>)
|
|
|
|
.def(py::self-py::self)
|
|
|
|
.def(py::self+Vec<2>())
|
|
|
|
.def(py::self-Vec<2>())
|
2019-01-23 14:35:20 +05:00
|
|
|
.def("__getitem__", [](Point<2>& self, int index) { return self[index]; })
|
2017-01-05 09:08:24 +05:00
|
|
|
;
|
|
|
|
|
|
|
|
py::class_<Point<3>> (m, "Point3d")
|
|
|
|
.def(py::init<double,double,double>())
|
|
|
|
.def ("__str__", &ToString<Point<3>>)
|
|
|
|
.def(py::self-py::self)
|
|
|
|
.def(py::self+Vec<3>())
|
|
|
|
.def(py::self-Vec<3>())
|
2019-01-23 14:35:20 +05:00
|
|
|
.def("__getitem__", [](Point<2>& self, int index) { return self[index]; })
|
2017-01-05 09:08:24 +05:00
|
|
|
;
|
|
|
|
|
|
|
|
m.def ("Pnt", FunctionPointer
|
|
|
|
([](double x, double y, double z) { return global_trafo(Point<3>(x,y,z)); }));
|
|
|
|
m.def ("Pnt", FunctionPointer
|
|
|
|
([](double x, double y) { return Point<2>(x,y); }));
|
|
|
|
|
2018-03-09 19:29:50 +05:00
|
|
|
/*
|
|
|
|
// duplicated functions ????
|
2017-01-05 09:08:24 +05:00
|
|
|
m.def ("Pnt", FunctionPointer
|
|
|
|
([](double x, double y, double z) { return Point<3>(x,y,z); }));
|
|
|
|
m.def ("Pnt", FunctionPointer
|
|
|
|
([](double x, double y) { return Point<2>(x,y); }));
|
2018-03-09 19:29:50 +05:00
|
|
|
*/
|
2017-01-05 09:08:24 +05:00
|
|
|
|
|
|
|
py::class_<Vec<2>> (m, "Vec2d")
|
|
|
|
.def(py::init<double,double>())
|
|
|
|
.def ("__str__", &ToString<Vec<3>>)
|
|
|
|
.def(py::self+py::self)
|
|
|
|
.def(py::self-py::self)
|
|
|
|
.def(-py::self)
|
|
|
|
.def(double()*py::self)
|
|
|
|
.def("Norm", &Vec<2>::Length)
|
2019-01-24 20:13:22 +05:00
|
|
|
.def("__getitem__", [](Vec<2>& vec, int index) { return vec[index]; })
|
|
|
|
.def("__len__", [](Vec<2>& /*unused*/) { return 2; })
|
2017-01-05 09:08:24 +05:00
|
|
|
;
|
|
|
|
|
|
|
|
py::class_<Vec<3>> (m, "Vec3d")
|
|
|
|
.def(py::init<double,double,double>())
|
|
|
|
.def ("__str__", &ToString<Vec<3>>)
|
|
|
|
.def(py::self+py::self)
|
|
|
|
.def(py::self-py::self)
|
|
|
|
.def(-py::self)
|
|
|
|
.def(double()*py::self)
|
|
|
|
.def("Norm", &Vec<3>::Length)
|
2019-01-24 20:13:22 +05:00
|
|
|
.def("__getitem__", [](Vec<3>& vec, int index) { return vec[index]; })
|
|
|
|
.def("__len__", [](Vec<3>& /*unused*/) { return 3; })
|
2017-01-05 09:08:24 +05:00
|
|
|
;
|
|
|
|
|
|
|
|
m.def ("Vec", FunctionPointer
|
|
|
|
([] (double x, double y, double z) { return global_trafo(Vec<3>(x,y,z)); }));
|
|
|
|
m.def ("Vec", FunctionPointer
|
|
|
|
([] (double x, double y) { return Vec<2>(x,y); }));
|
|
|
|
|
2018-03-09 19:29:50 +05:00
|
|
|
py::class_<Transformation<3>> (m, "Trafo")
|
2019-03-25 16:33:16 +05:00
|
|
|
.def(py::init<Vec<3>>(), "a translation")
|
|
|
|
.def(py::init<Point<3>,Vec<3>,double>(), "a rotation given by point on axes, direction of axes, angle")
|
|
|
|
.def("__mul__", [](Transformation<3> a, Transformation<3> b)->Transformation<3>
|
|
|
|
{ Transformation<3> res; res.Combine(a,b); return res; })
|
2018-03-09 19:29:50 +05:00
|
|
|
.def("__call__", [] (Transformation<3> trafo, Point<3> p) { return trafo(p); })
|
|
|
|
;
|
2017-01-05 09:08:24 +05:00
|
|
|
|
2018-06-25 22:42:42 +05:00
|
|
|
m.def ("GetTransformation", [] () { return global_trafo; });
|
|
|
|
m.def ("SetTransformation", [] (Transformation<3> trafo) { global_trafo = trafo; });
|
2018-06-25 22:25:17 +05:00
|
|
|
m.def ("SetTransformation",
|
|
|
|
[](int dir, double angle)
|
|
|
|
{
|
|
|
|
if (dir > 0)
|
|
|
|
global_trafo.SetAxisRotation (dir, angle*M_PI/180);
|
|
|
|
else
|
|
|
|
global_trafo = Transformation<3> (Vec<3>(0,0,0));
|
|
|
|
},
|
2017-01-05 09:08:24 +05:00
|
|
|
py::arg("dir")=int(0), py::arg("angle")=int(0));
|
2018-06-25 22:25:17 +05:00
|
|
|
m.def ("SetTransformation",
|
|
|
|
[](Point<3> p0, Vec<3> ex, Vec<3> ey, Vec<3> ez)
|
|
|
|
{
|
|
|
|
Point<3> pnts[4];
|
|
|
|
pnts[0] = p0;
|
|
|
|
pnts[1] = p0 + ex;
|
|
|
|
pnts[2] = p0 + ey;
|
|
|
|
pnts[3] = p0 + ez;
|
|
|
|
global_trafo = Transformation<3> (pnts);
|
|
|
|
},
|
|
|
|
py::arg("p0"), py::arg("ex"), py::arg("ey"), py::arg("ez"));
|
2017-01-05 09:08:24 +05:00
|
|
|
|
|
|
|
|
2015-10-22 20:26:43 +05:00
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
py::class_<PointIndex>(m, "PointId")
|
|
|
|
.def(py::init<int>())
|
2014-08-30 06:15:59 +06:00
|
|
|
.def("__repr__", &ToString<PointIndex>)
|
|
|
|
.def("__str__", &ToString<PointIndex>)
|
2016-11-04 16:14:52 +05:00
|
|
|
.def_property_readonly("nr", &PointIndex::operator int)
|
2015-05-20 13:39:55 +05:00
|
|
|
.def("__eq__" , FunctionPointer( [](PointIndex &self, PointIndex &other)
|
|
|
|
{ return static_cast<int>(self)==static_cast<int>(other); }) )
|
|
|
|
.def("__hash__" , FunctionPointer( [](PointIndex &self ) { return static_cast<int>(self); }) )
|
2014-08-30 06:15:59 +06:00
|
|
|
;
|
2014-09-26 02:23:31 +06:00
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
py::class_<ElementIndex>(m, "ElementId3D")
|
|
|
|
.def(py::init<int>())
|
2015-05-18 19:19:38 +05:00
|
|
|
.def("__repr__", &ToString<ElementIndex>)
|
|
|
|
.def("__str__", &ToString<ElementIndex>)
|
2016-11-04 16:14:52 +05:00
|
|
|
.def_property_readonly("nr", &ElementIndex::operator int)
|
2015-05-20 13:39:55 +05:00
|
|
|
.def("__eq__" , FunctionPointer( [](ElementIndex &self, ElementIndex &other)
|
|
|
|
{ return static_cast<int>(self)==static_cast<int>(other); }) )
|
|
|
|
.def("__hash__" , FunctionPointer( [](ElementIndex &self ) { return static_cast<int>(self); }) )
|
2015-05-18 19:19:38 +05:00
|
|
|
;
|
|
|
|
|
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
py::class_<SurfaceElementIndex>(m, "ElementId2D")
|
|
|
|
.def(py::init<int>())
|
2015-05-18 19:19:38 +05:00
|
|
|
.def("__repr__", &ToString<SurfaceElementIndex>)
|
|
|
|
.def("__str__", &ToString<SurfaceElementIndex>)
|
2016-11-04 16:14:52 +05:00
|
|
|
.def_property_readonly("nr", &SurfaceElementIndex::operator int)
|
2015-05-20 13:39:55 +05:00
|
|
|
.def("__eq__" , FunctionPointer( [](SurfaceElementIndex &self, SurfaceElementIndex &other)
|
|
|
|
{ return static_cast<int>(self)==static_cast<int>(other); }) )
|
|
|
|
.def("__hash__" , FunctionPointer( [](SurfaceElementIndex &self ) { return static_cast<int>(self); }) )
|
2015-05-18 19:19:38 +05:00
|
|
|
;
|
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
py::class_<SegmentIndex>(m, "ElementId1D")
|
|
|
|
.def(py::init<int>())
|
2015-05-18 19:19:38 +05:00
|
|
|
.def("__repr__", &ToString<SegmentIndex>)
|
|
|
|
.def("__str__", &ToString<SegmentIndex>)
|
2016-11-04 16:14:52 +05:00
|
|
|
.def_property_readonly("nr", &SegmentIndex::operator int)
|
2015-05-20 13:39:55 +05:00
|
|
|
.def("__eq__" , FunctionPointer( [](SegmentIndex &self, SegmentIndex &other)
|
|
|
|
{ return static_cast<int>(self)==static_cast<int>(other); }) )
|
|
|
|
.def("__hash__" , FunctionPointer( [](SegmentIndex &self ) { return static_cast<int>(self); }) )
|
2015-05-18 19:19:38 +05:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-26 02:23:31 +06:00
|
|
|
/*
|
2016-11-04 16:14:52 +05:00
|
|
|
py::class_<Point<3>> ("Point")
|
|
|
|
.def(py::init<double,double,double>())
|
2014-08-31 15:14:18 +06:00
|
|
|
;
|
2014-09-26 02:23:31 +06:00
|
|
|
*/
|
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
py::class_<MeshPoint /* ,py::bases<Point<3>> */ >(m, "MeshPoint")
|
|
|
|
.def(py::init<Point<3>>())
|
2015-05-18 19:19:38 +05:00
|
|
|
.def("__str__", &ToString<MeshPoint>)
|
|
|
|
.def("__repr__", &ToString<MeshPoint>)
|
2019-09-04 18:24:37 +05:00
|
|
|
.def_property_readonly("p", [](const MeshPoint & self)
|
|
|
|
{
|
|
|
|
py::list l;
|
|
|
|
l.append ( py::cast(self[0]) );
|
|
|
|
l.append ( py::cast(self[1]) );
|
|
|
|
l.append ( py::cast(self[2]) );
|
|
|
|
return py::tuple(l);
|
|
|
|
})
|
|
|
|
.def("__getitem__", [](const MeshPoint & self, int index) {
|
2016-08-06 15:55:59 +05:00
|
|
|
if(index<0 || index>2)
|
2016-11-04 16:14:52 +05:00
|
|
|
throw py::index_error();
|
2016-08-06 15:55:59 +05:00
|
|
|
return self[index];
|
2019-09-04 18:24:37 +05:00
|
|
|
})
|
|
|
|
.def("__setitem__", [](MeshPoint & self, int index, double val) {
|
2017-06-27 02:26:09 +05:00
|
|
|
if(index<0 || index>2)
|
|
|
|
throw py::index_error();
|
|
|
|
self(index) = val;
|
2019-09-04 18:24:37 +05:00
|
|
|
})
|
2014-08-31 15:14:18 +06:00
|
|
|
;
|
2019-02-15 18:32:57 +05:00
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
py::class_<Element>(m, "Element3D")
|
2019-02-15 18:32:57 +05:00
|
|
|
.def(py::init([](int index, std::vector<PointIndex> vertices)
|
2018-03-09 02:19:11 +05:00
|
|
|
{
|
2019-02-15 18:32:57 +05:00
|
|
|
int np = vertices.size();
|
|
|
|
ELEMENT_TYPE et;
|
|
|
|
switch (np)
|
|
|
|
{
|
|
|
|
case 4: et = TET; break;
|
|
|
|
case 5: et = PYRAMID; break;
|
|
|
|
case 6: et = PRISM; break;
|
|
|
|
case 8: et = HEX; break;
|
|
|
|
case 10: et = TET10; break;
|
|
|
|
case 13: et = PYRAMID13; break;
|
|
|
|
case 15: et = PRISM15; break;
|
|
|
|
case 20: et = HEX20; break;
|
|
|
|
default:
|
|
|
|
throw Exception ("no Element3D with " + ToString(np) +
|
|
|
|
" points");
|
|
|
|
}
|
|
|
|
|
|
|
|
auto newel = new Element(et);
|
2019-02-06 23:13:51 +05:00
|
|
|
for(int i=0; i<np; i++)
|
2019-02-15 18:32:57 +05:00
|
|
|
(*newel)[i] = vertices[i];
|
2019-02-06 23:13:51 +05:00
|
|
|
newel->SetIndex(index);
|
2018-03-09 02:19:11 +05:00
|
|
|
return newel;
|
|
|
|
}),
|
2016-11-04 16:14:52 +05:00
|
|
|
py::arg("index")=1,py::arg("vertices"),
|
2015-05-18 19:19:38 +05:00
|
|
|
"create volume element"
|
|
|
|
)
|
|
|
|
.def("__repr__", &ToString<Element>)
|
2016-11-04 16:14:52 +05:00
|
|
|
.def_property("index", &Element::GetIndex, &Element::SetIndex)
|
2018-11-20 13:36:27 +05:00
|
|
|
.def_property("curved", &Element::IsCurved, &Element::SetCurved)
|
2016-11-04 16:14:52 +05:00
|
|
|
.def_property_readonly("vertices",
|
|
|
|
FunctionPointer ([](const Element & self) -> py::list
|
2014-08-30 06:15:59 +06:00
|
|
|
{
|
2016-11-04 16:14:52 +05:00
|
|
|
py::list li;
|
2014-08-30 06:15:59 +06:00
|
|
|
for (int i = 0; i < self.GetNV(); i++)
|
2016-11-04 16:14:52 +05:00
|
|
|
li.append (py::cast(self[i]));
|
2014-08-30 06:15:59 +06:00
|
|
|
return li;
|
|
|
|
}))
|
2017-06-01 02:44:50 +05:00
|
|
|
.def_property_readonly("points",
|
|
|
|
FunctionPointer ([](const Element & self) -> py::list
|
|
|
|
{
|
|
|
|
py::list li;
|
|
|
|
for (int i = 0; i < self.GetNP(); i++)
|
|
|
|
li.append (py::cast(self[i]));
|
|
|
|
return li;
|
|
|
|
}))
|
2014-08-30 06:15:59 +06:00
|
|
|
;
|
2014-10-01 19:16:34 +06:00
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
py::class_<Element2d>(m, "Element2D")
|
2018-03-09 02:19:11 +05:00
|
|
|
.def(py::init ([](int index, py::list vertices)
|
|
|
|
{
|
|
|
|
Element2d * newel = nullptr;
|
|
|
|
if (py::len(vertices) == 3)
|
|
|
|
{
|
|
|
|
newel = new Element2d(TRIG);
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
|
|
|
newel->SetIndex(index);
|
|
|
|
}
|
|
|
|
else if (py::len(vertices) == 4)
|
|
|
|
{
|
|
|
|
newel = new Element2d(QUAD);
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
|
|
|
newel->SetIndex(index);
|
|
|
|
}
|
|
|
|
else if (py::len(vertices) == 6)
|
|
|
|
{
|
|
|
|
newel = new Element2d(TRIG6);
|
|
|
|
for(int i = 0; i<6; i++)
|
|
|
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
|
|
|
newel->SetIndex(index);
|
|
|
|
}
|
2019-01-18 02:08:35 +05:00
|
|
|
else if (py::len(vertices) == 8)
|
|
|
|
{
|
|
|
|
newel = new Element2d(QUAD8);
|
|
|
|
for(int i = 0; i<8; i++)
|
|
|
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
|
|
|
newel->SetIndex(index);
|
|
|
|
}
|
2018-03-09 02:19:11 +05:00
|
|
|
else
|
|
|
|
throw NgException("Inconsistent number of vertices in Element2D");
|
|
|
|
return newel;
|
|
|
|
}),
|
|
|
|
py::arg("index")=1,py::arg("vertices"),
|
2015-05-18 19:19:38 +05:00
|
|
|
"create surface element"
|
|
|
|
)
|
2016-11-04 16:14:52 +05:00
|
|
|
.def_property("index", &Element2d::GetIndex, &Element2d::SetIndex)
|
2018-11-18 00:57:53 +05:00
|
|
|
.def_property("curved", &Element2d::IsCurved, &Element2d::SetCurved)
|
2016-11-04 16:14:52 +05:00
|
|
|
.def_property_readonly("vertices",
|
|
|
|
FunctionPointer([](const Element2d & self) -> py::list
|
2015-01-20 22:41:16 +05:00
|
|
|
{
|
2016-11-04 16:14:52 +05:00
|
|
|
py::list li;
|
2015-01-20 22:41:16 +05:00
|
|
|
for (int i = 0; i < self.GetNV(); i++)
|
2016-11-04 16:14:52 +05:00
|
|
|
li.append(py::cast(self[i]));
|
2015-01-20 22:41:16 +05:00
|
|
|
return li;
|
|
|
|
}))
|
2017-06-28 10:23:28 +05:00
|
|
|
.def_property_readonly("points",
|
|
|
|
FunctionPointer ([](const Element2d & self) -> py::list
|
|
|
|
{
|
|
|
|
py::list li;
|
|
|
|
for (int i = 0; i < self.GetNP(); i++)
|
|
|
|
li.append (py::cast(self[i]));
|
|
|
|
return li;
|
|
|
|
}))
|
2015-01-20 22:41:16 +05:00
|
|
|
;
|
2015-05-18 19:19:38 +05:00
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
py::class_<Segment>(m, "Element1D")
|
2018-04-18 12:34:41 +05:00
|
|
|
.def(py::init([](py::list vertices, py::list surfaces, int index, int edgenr)
|
2018-03-09 02:19:11 +05:00
|
|
|
{
|
|
|
|
Segment * newel = new Segment();
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
|
|
|
newel -> si = index;
|
2018-04-18 12:34:41 +05:00
|
|
|
newel -> edgenr = edgenr;
|
|
|
|
newel -> epgeominfo[0].edgenr = edgenr;
|
|
|
|
newel -> epgeominfo[1].edgenr = edgenr;
|
2018-03-09 02:19:11 +05:00
|
|
|
// needed for codim2 in 3d
|
|
|
|
newel -> edgenr = index;
|
|
|
|
if (len(surfaces))
|
|
|
|
{
|
|
|
|
newel->surfnr1 = py::extract<int>(surfaces[0])();
|
|
|
|
newel->surfnr2 = py::extract<int>(surfaces[1])();
|
|
|
|
}
|
|
|
|
return newel;
|
|
|
|
}),
|
2016-11-04 16:14:52 +05:00
|
|
|
py::arg("vertices"),
|
|
|
|
py::arg("surfaces")=py::list(),
|
|
|
|
py::arg("index")=1,
|
2018-04-18 12:34:41 +05:00
|
|
|
py::arg("edgenr")=1,
|
2015-05-18 19:19:38 +05:00
|
|
|
"create segment element"
|
|
|
|
)
|
2015-11-11 22:46:18 +05:00
|
|
|
.def("__repr__", &ToString<Segment>)
|
2016-11-04 16:14:52 +05:00
|
|
|
.def_property_readonly("vertices",
|
|
|
|
FunctionPointer ([](const Segment & self) -> py::list
|
2015-05-18 19:19:38 +05:00
|
|
|
{
|
2016-11-04 16:14:52 +05:00
|
|
|
py::list li;
|
2015-05-18 19:19:38 +05:00
|
|
|
for (int i = 0; i < 2; i++)
|
2016-11-04 16:14:52 +05:00
|
|
|
li.append (py::cast(self[i]));
|
2015-05-18 19:19:38 +05:00
|
|
|
return li;
|
|
|
|
}))
|
2017-06-28 10:23:28 +05:00
|
|
|
.def_property_readonly("points",
|
|
|
|
FunctionPointer ([](const Segment & self) -> py::list
|
|
|
|
{
|
|
|
|
py::list li;
|
|
|
|
for (int i = 0; i < self.GetNP(); i++)
|
|
|
|
li.append (py::cast(self[i]));
|
|
|
|
return li;
|
|
|
|
}))
|
2016-11-04 16:14:52 +05:00
|
|
|
.def_property_readonly("surfaces",
|
|
|
|
FunctionPointer ([](const Segment & self) -> py::list
|
2015-05-18 19:19:38 +05:00
|
|
|
{
|
2016-11-04 16:14:52 +05:00
|
|
|
py::list li;
|
|
|
|
li.append (py::cast(self.surfnr1));
|
|
|
|
li.append (py::cast(self.surfnr2));
|
2015-05-18 19:19:38 +05:00
|
|
|
return li;
|
|
|
|
}))
|
2016-11-05 21:15:16 +05:00
|
|
|
.def_property_readonly("index", FunctionPointer([](const Segment &self) -> size_t
|
2016-10-28 19:49:50 +05:00
|
|
|
{
|
2016-11-21 18:54:11 +05:00
|
|
|
return self.si;
|
2016-10-28 19:49:50 +05:00
|
|
|
}))
|
2016-11-21 18:54:11 +05:00
|
|
|
.def_property_readonly("edgenr", FunctionPointer([](const Segment & self) -> size_t
|
|
|
|
{
|
|
|
|
return self.edgenr;
|
|
|
|
}))
|
2015-05-18 19:19:38 +05:00
|
|
|
;
|
|
|
|
|
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
py::class_<Element0d>(m, "Element0D")
|
2018-03-09 02:19:11 +05:00
|
|
|
.def(py::init([](PointIndex vertex, int index)
|
|
|
|
{
|
|
|
|
Element0d * instance = new Element0d;
|
|
|
|
instance->pnum = vertex;
|
|
|
|
instance->index = index;
|
|
|
|
return instance;
|
|
|
|
}),
|
2016-11-04 16:14:52 +05:00
|
|
|
py::arg("vertex"),
|
|
|
|
py::arg("index")=1,
|
2015-11-11 22:46:18 +05:00
|
|
|
"create point element"
|
|
|
|
)
|
|
|
|
.def("__repr__", &ToString<Element0d>)
|
2016-11-04 16:14:52 +05:00
|
|
|
.def_property_readonly("vertices",
|
|
|
|
FunctionPointer ([](const Element0d & self) -> py::list
|
2015-11-11 22:46:18 +05:00
|
|
|
{
|
2016-11-04 16:14:52 +05:00
|
|
|
py::list li;
|
|
|
|
li.append (py::cast(self.pnum));
|
2015-11-11 22:46:18 +05:00
|
|
|
return li;
|
|
|
|
}))
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-18 19:19:38 +05:00
|
|
|
|
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
py::class_<FaceDescriptor>(m, "FaceDescriptor")
|
|
|
|
.def(py::init<const FaceDescriptor&>())
|
2018-03-09 02:19:11 +05:00
|
|
|
.def(py::init([](int surfnr, int domin, int domout, int bc)
|
|
|
|
{
|
|
|
|
FaceDescriptor * instance = new FaceDescriptor();
|
|
|
|
instance->SetSurfNr(surfnr);
|
|
|
|
instance->SetDomainIn(domin);
|
|
|
|
instance->SetDomainOut(domout);
|
|
|
|
instance->SetBCProperty(bc);
|
|
|
|
return instance;
|
|
|
|
}),
|
|
|
|
py::arg("surfnr")=1,
|
|
|
|
py::arg("domin")=1,
|
|
|
|
py::arg("domout")=py::int_(0),
|
|
|
|
py::arg("bc")=py::int_(0),
|
2015-08-29 16:54:00 +05:00
|
|
|
"create facedescriptor")
|
2015-05-18 19:19:38 +05:00
|
|
|
.def("__str__", &ToString<FaceDescriptor>)
|
|
|
|
.def("__repr__", &ToString<FaceDescriptor>)
|
2016-11-04 16:14:52 +05:00
|
|
|
.def_property("surfnr", &FaceDescriptor::SurfNr, &FaceDescriptor::SetSurfNr)
|
|
|
|
.def_property("domin", &FaceDescriptor::DomainIn, &FaceDescriptor::SetDomainIn)
|
|
|
|
.def_property("domout", &FaceDescriptor::DomainOut, &FaceDescriptor::SetDomainOut)
|
|
|
|
.def_property("bc", &FaceDescriptor::BCProperty, &FaceDescriptor::SetBCProperty)
|
2017-02-09 14:06:34 +05:00
|
|
|
.def_property("bcname",
|
|
|
|
[](FaceDescriptor & self) -> string { return self.GetBCName(); },
|
|
|
|
[](FaceDescriptor & self, string name) { self.SetBCName(new string(name)); } // memleak
|
|
|
|
)
|
2016-11-04 16:14:52 +05:00
|
|
|
.def("SetSurfaceColor", [](FaceDescriptor & self, py::list color )
|
2016-08-25 20:18:16 +05:00
|
|
|
{
|
|
|
|
Vec3d c;
|
2016-11-04 16:14:52 +05:00
|
|
|
c.X() = py::extract<double>(color[0])();
|
|
|
|
c.Y() = py::extract<double>(color[1])();
|
|
|
|
c.Z() = py::extract<double>(color[2])();
|
2016-08-25 20:18:16 +05:00
|
|
|
self.SetSurfColour(c);
|
2016-11-04 16:14:52 +05:00
|
|
|
})
|
2015-05-18 19:19:38 +05:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-08-12 17:20:30 +05:00
|
|
|
ExportArray<Element,size_t>(m);
|
2019-08-18 16:25:04 +05:00
|
|
|
ExportArray<Element2d,SurfaceElementIndex>(m);
|
2019-08-12 17:20:30 +05:00
|
|
|
ExportArray<Segment,size_t>(m);
|
2016-11-04 16:14:52 +05:00
|
|
|
ExportArray<Element0d>(m);
|
2019-08-12 17:20:30 +05:00
|
|
|
ExportArray<MeshPoint,PointIndex>(m);
|
2016-11-04 16:14:52 +05:00
|
|
|
ExportArray<FaceDescriptor>(m);
|
|
|
|
|
|
|
|
py::implicitly_convertible< int, PointIndex>();
|
2017-01-05 09:08:24 +05:00
|
|
|
|
2018-04-17 22:37:29 +05:00
|
|
|
py::class_<NetgenGeometry, shared_ptr<NetgenGeometry>> (m, "NetgenGeometry", py::dynamic_attr())
|
2017-01-05 09:08:24 +05:00
|
|
|
;
|
2014-08-30 06:15:59 +06:00
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
py::class_<Mesh,shared_ptr<Mesh>>(m, "Mesh")
|
|
|
|
// .def(py::init<>("create empty mesh"))
|
2015-10-22 19:32:58 +05:00
|
|
|
|
2019-02-12 01:37:00 +05:00
|
|
|
.def(py::init( [] (int dim, NgMPI_Comm comm)
|
2017-09-06 21:08:39 +05:00
|
|
|
{
|
|
|
|
auto mesh = make_shared<Mesh>();
|
2019-02-12 01:37:00 +05:00
|
|
|
mesh->SetCommunicator(comm);
|
2017-09-06 21:08:39 +05:00
|
|
|
mesh -> SetDimension(dim);
|
|
|
|
SetGlobalMesh(mesh); // for visualization
|
2018-12-14 16:01:58 +05:00
|
|
|
mesh -> SetGeometry (nullptr);
|
2017-09-06 21:08:39 +05:00
|
|
|
return mesh;
|
|
|
|
} ),
|
2019-02-12 20:30:18 +05:00
|
|
|
py::arg("dim")=3, py::arg("comm")=NgMPI_Comm{}
|
2017-09-06 21:08:39 +05:00
|
|
|
)
|
2018-12-20 21:01:27 +05:00
|
|
|
.def(NGSPickle<Mesh>())
|
2019-02-12 01:37:00 +05:00
|
|
|
.def_property_readonly("comm", [](const Mesh & amesh) -> NgMPI_Comm
|
|
|
|
{ return amesh.GetCommunicator(); },
|
2019-01-31 00:55:45 +05:00
|
|
|
"MPI-communicator the Mesh lives in")
|
2017-09-06 21:08:39 +05:00
|
|
|
/*
|
2016-11-04 16:14:52 +05:00
|
|
|
.def("__init__",
|
|
|
|
[](Mesh *instance, int dim)
|
2015-10-22 19:32:58 +05:00
|
|
|
{
|
2016-11-04 16:14:52 +05:00
|
|
|
new (instance) Mesh();
|
|
|
|
instance->SetDimension(dim);
|
|
|
|
},
|
|
|
|
py::arg("dim")=3
|
|
|
|
)
|
2017-09-06 21:08:39 +05:00
|
|
|
*/
|
2015-10-22 19:32:58 +05:00
|
|
|
|
2018-05-14 14:01:27 +05:00
|
|
|
.def_property_readonly("_timestamp", &Mesh::GetTimeStamp)
|
2019-08-08 13:12:33 +05:00
|
|
|
.def_property_readonly("ne", [](Mesh& m) { return m.GetNE(); })
|
2019-02-12 01:37:00 +05:00
|
|
|
.def("Distribute", [](shared_ptr<Mesh> self, NgMPI_Comm comm) {
|
2019-02-08 18:14:19 +05:00
|
|
|
self->SetCommunicator(comm);
|
2019-02-13 02:11:55 +05:00
|
|
|
if(comm.Size()==1) return self;
|
2019-02-09 02:12:00 +05:00
|
|
|
// if(MyMPI_GetNTasks(comm)==2) throw NgException("Sorry, cannot handle communicators with NP=2!");
|
|
|
|
// cout << " rank " << MyMPI_GetId(comm) << " of " << MyMPI_GetNTasks(comm) << " called Distribute " << endl;
|
2019-02-13 02:11:55 +05:00
|
|
|
if(comm.Rank()==0) self->Distribute();
|
2019-02-08 18:14:19 +05:00
|
|
|
else self->SendRecvMesh();
|
2019-02-25 20:22:44 +05:00
|
|
|
return self;
|
2019-02-13 02:11:55 +05:00
|
|
|
}, py::arg("comm"))
|
2019-04-17 15:22:38 +05:00
|
|
|
.def_static("Receive", [](NgMPI_Comm comm) -> shared_ptr<Mesh> {
|
2019-02-08 18:14:19 +05:00
|
|
|
auto mesh = make_shared<Mesh>();
|
2019-02-12 01:37:00 +05:00
|
|
|
mesh->SetCommunicator(comm);
|
2019-02-08 18:14:19 +05:00
|
|
|
mesh->SendRecvMesh();
|
|
|
|
return mesh;
|
2019-04-17 15:22:38 +05:00
|
|
|
}, py::arg("comm"))
|
2014-12-19 19:03:36 +05:00
|
|
|
.def("Load", FunctionPointer
|
2019-02-25 20:22:44 +05:00
|
|
|
([](shared_ptr<Mesh> self, const string & filename)
|
2014-12-19 19:03:36 +05:00
|
|
|
{
|
2017-06-09 23:21:55 +05:00
|
|
|
|
2019-02-25 20:22:44 +05:00
|
|
|
auto comm = self->GetCommunicator();
|
|
|
|
int id = comm.Rank();
|
|
|
|
int ntasks = comm.Size();
|
|
|
|
auto & mesh = self;
|
2019-01-31 00:55:45 +05:00
|
|
|
|
2019-02-25 20:22:44 +05:00
|
|
|
{
|
|
|
|
ifstream infile(filename.c_str());
|
|
|
|
if(!infile.good())
|
|
|
|
throw NgException(string("Error opening file ") + filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( filename.find(".vol") == string::npos )
|
|
|
|
{
|
|
|
|
if(ntasks>1)
|
|
|
|
throw NgException("Not sure what to do with this?? Does this work with MPI??");
|
|
|
|
mesh->SetCommunicator(comm);
|
|
|
|
ReadFile(*mesh,filename.c_str());
|
|
|
|
//mesh->SetGlobalH (mparam.maxh);
|
|
|
|
//mesh->CalcLocalH();
|
|
|
|
return;
|
2016-02-27 00:35:09 +05:00
|
|
|
}
|
2019-02-25 20:22:44 +05:00
|
|
|
|
|
|
|
istream * infile;
|
2019-07-09 13:39:16 +05:00
|
|
|
NgArray<char> buf; // for distributing geometry!
|
2019-02-25 20:22:44 +05:00
|
|
|
int strs;
|
|
|
|
|
|
|
|
if( id == 0) {
|
|
|
|
|
|
|
|
if (filename.substr (filename.length()-3, 3) == ".gz")
|
|
|
|
infile = new igzstream (filename.c_str());
|
|
|
|
else
|
|
|
|
infile = new ifstream (filename.c_str());
|
|
|
|
mesh -> Load(*infile);
|
|
|
|
|
|
|
|
// make string from rest of file (for geometry info!)
|
|
|
|
// (this might be empty, in which case we take the global ng_geometry)
|
|
|
|
stringstream geom_part;
|
|
|
|
geom_part << infile->rdbuf();
|
|
|
|
string geom_part_string = geom_part.str();
|
|
|
|
strs = geom_part_string.size();
|
|
|
|
// buf = new char[strs];
|
|
|
|
buf.SetSize(strs);
|
|
|
|
memcpy(&buf[0], geom_part_string.c_str(), strs*sizeof(char));
|
|
|
|
|
|
|
|
delete infile;
|
|
|
|
|
|
|
|
if (ntasks > 1)
|
|
|
|
{
|
|
|
|
|
|
|
|
char * weightsfilename = new char [filename.size()+1];
|
|
|
|
strcpy (weightsfilename, filename.c_str());
|
|
|
|
weightsfilename[strlen (weightsfilename)-3] = 'w';
|
|
|
|
weightsfilename[strlen (weightsfilename)-2] = 'e';
|
|
|
|
weightsfilename[strlen (weightsfilename)-1] = 'i';
|
|
|
|
|
|
|
|
ifstream weightsfile(weightsfilename);
|
|
|
|
delete [] weightsfilename;
|
|
|
|
|
|
|
|
if (!(weightsfile.good()))
|
|
|
|
{
|
|
|
|
// cout << "regular distribute" << endl;
|
|
|
|
mesh -> Distribute();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char str[20];
|
|
|
|
bool endfile = false;
|
|
|
|
int n, dummy;
|
|
|
|
|
2019-07-09 13:39:16 +05:00
|
|
|
NgArray<int> segment_weights;
|
|
|
|
NgArray<int> surface_weights;
|
|
|
|
NgArray<int> volume_weights;
|
2019-02-25 20:22:44 +05:00
|
|
|
|
|
|
|
while (weightsfile.good() && !endfile)
|
|
|
|
{
|
|
|
|
weightsfile >> str;
|
|
|
|
|
|
|
|
if (strcmp (str, "edgeweights") == 0)
|
|
|
|
{
|
|
|
|
weightsfile >> n;
|
|
|
|
segment_weights.SetSize(n);
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
weightsfile >> dummy >> segment_weights[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp (str, "surfaceweights") == 0)
|
|
|
|
{
|
|
|
|
weightsfile >> n;
|
|
|
|
surface_weights.SetSize(n);
|
|
|
|
for (int i=0; i<n; i++)
|
|
|
|
weightsfile >> dummy >> surface_weights[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp (str, "volumeweights") == 0)
|
|
|
|
{
|
|
|
|
weightsfile >> n;
|
|
|
|
volume_weights.SetSize(n);
|
|
|
|
for (int i=0; i<n; i++)
|
|
|
|
weightsfile >> dummy >> volume_weights[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp (str, "endfile") == 0)
|
|
|
|
endfile = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mesh -> Distribute(volume_weights, surface_weights, segment_weights);
|
|
|
|
}
|
|
|
|
} // ntasks>1 end
|
|
|
|
} // id==0 end
|
2017-06-09 23:21:55 +05:00
|
|
|
else {
|
2019-02-25 20:22:44 +05:00
|
|
|
mesh->SendRecvMesh();
|
2017-06-09 23:21:55 +05:00
|
|
|
}
|
|
|
|
|
2019-02-25 20:22:44 +05:00
|
|
|
if(ntasks>1) {
|
|
|
|
#ifdef PARALLEL
|
|
|
|
/** Scatter the geometry-string (no dummy-implementation in mpi_interface) **/
|
|
|
|
int strs = buf.Size();
|
|
|
|
MyMPI_Bcast(strs, comm);
|
|
|
|
if(strs>0)
|
|
|
|
MyMPI_Bcast(buf, comm);
|
2016-02-27 00:35:09 +05:00
|
|
|
#endif
|
2019-02-25 20:22:44 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
shared_ptr<NetgenGeometry> geo;
|
|
|
|
if(buf.Size()) { // if we had geom-info in the file, take it
|
|
|
|
istringstream geom_infile(string((const char*)&buf[0], buf.Size()));
|
|
|
|
geo = geometryregister.LoadFromMeshFile(geom_infile);
|
|
|
|
}
|
|
|
|
if(geo!=nullptr) mesh->SetGeometry(geo);
|
|
|
|
else if(ng_geometry!=nullptr) mesh->SetGeometry(ng_geometry);
|
2018-03-13 02:38:21 +05:00
|
|
|
}),py::call_guard<py::gil_scoped_release>())
|
2014-12-19 19:03:36 +05:00
|
|
|
// static_cast<void(Mesh::*)(const string & name)>(&Mesh::Load))
|
2018-03-13 02:38:21 +05:00
|
|
|
.def("Save", static_cast<void(Mesh::*)(const string & name)const>(&Mesh::Save),py::call_guard<py::gil_scoped_release>())
|
2016-11-04 16:14:52 +05:00
|
|
|
.def("Export",
|
|
|
|
[] (Mesh & self, string filename, string format)
|
2016-07-10 21:07:36 +05:00
|
|
|
{
|
2017-07-25 01:26:18 +05:00
|
|
|
if (WriteUserFormat (format, self, /* *self.GetGeometry(), */ filename))
|
2016-07-10 21:07:36 +05:00
|
|
|
{
|
|
|
|
string err = string ("nothing known about format")+format;
|
2019-07-09 13:39:16 +05:00
|
|
|
NgArray<const char*> names, extensions;
|
2016-07-10 21:07:36 +05:00
|
|
|
RegisterUserFormats (names, extensions);
|
|
|
|
err += "\navailable formats are:\n";
|
|
|
|
for (auto name : names)
|
|
|
|
err += string("'") + name + "'\n";
|
|
|
|
throw NgException (err);
|
|
|
|
}
|
2016-11-04 16:14:52 +05:00
|
|
|
},
|
2018-03-13 02:38:21 +05:00
|
|
|
py::arg("filename"), py::arg("format"),py::call_guard<py::gil_scoped_release>())
|
2016-07-10 21:07:36 +05:00
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
.def_property("dim", &Mesh::GetDimension, &Mesh::SetDimension)
|
2015-08-31 20:41:26 +05:00
|
|
|
|
2014-08-30 06:15:59 +06:00
|
|
|
.def("Elements3D",
|
2019-08-09 03:23:12 +05:00
|
|
|
static_cast<Array<Element>&(Mesh::*)()> (&Mesh::VolumeElements),
|
2016-11-04 16:14:52 +05:00
|
|
|
py::return_value_policy::reference)
|
2014-08-31 15:14:18 +06:00
|
|
|
|
|
|
|
.def("Elements2D",
|
2019-08-18 16:10:58 +05:00
|
|
|
static_cast<Array<Element2d,SurfaceElementIndex>&(Mesh::*)()> (&Mesh::SurfaceElements),
|
2016-11-04 16:14:52 +05:00
|
|
|
py::return_value_policy::reference)
|
2014-08-31 15:14:18 +06:00
|
|
|
|
2015-05-18 19:19:38 +05:00
|
|
|
.def("Elements1D",
|
2019-08-09 03:23:12 +05:00
|
|
|
static_cast<Array<Segment>&(Mesh::*)()> (&Mesh::LineSegments),
|
2016-11-04 16:14:52 +05:00
|
|
|
py::return_value_policy::reference)
|
2015-05-18 19:19:38 +05:00
|
|
|
|
2019-08-09 03:23:12 +05:00
|
|
|
.def("Elements0D", FunctionPointer([] (Mesh & self) -> Array<Element0d>&
|
2015-11-11 22:46:18 +05:00
|
|
|
{
|
|
|
|
return self.pointelements;
|
|
|
|
} ),
|
2016-11-04 16:14:52 +05:00
|
|
|
py::return_value_policy::reference)
|
2015-05-18 19:19:38 +05:00
|
|
|
|
2014-08-31 15:14:18 +06:00
|
|
|
.def("Points",
|
2014-09-03 15:07:10 +06:00
|
|
|
static_cast<Mesh::T_POINTS&(Mesh::*)()> (&Mesh::Points),
|
2016-11-04 16:14:52 +05:00
|
|
|
py::return_value_policy::reference)
|
2014-08-30 06:15:59 +06:00
|
|
|
|
2015-05-18 19:19:38 +05:00
|
|
|
.def("FaceDescriptor", static_cast<FaceDescriptor&(Mesh::*)(int)> (&Mesh::GetFaceDescriptor),
|
2016-11-04 16:14:52 +05:00
|
|
|
py::return_value_policy::reference)
|
2015-12-11 18:31:28 +05:00
|
|
|
.def("GetNFaceDescriptors", &Mesh::GetNFD)
|
2016-11-18 20:57:42 +05:00
|
|
|
|
2019-05-22 03:25:18 +05:00
|
|
|
.def("GetVolumeNeighboursOfSurfaceElement", [](Mesh & self, size_t sel)
|
|
|
|
{
|
|
|
|
int elnr1, elnr2;
|
|
|
|
self.GetTopology().GetSurface2VolumeElement(sel+1, elnr1, elnr2);
|
|
|
|
return py::make_tuple(elnr1, elnr2);
|
|
|
|
}, "Returns element nrs of volume element connected to surface element, -1 if no volume element")
|
|
|
|
|
2016-11-18 20:57:42 +05:00
|
|
|
.def("GetNCD2Names", &Mesh::GetNCD2Names)
|
2015-12-11 18:31:28 +05:00
|
|
|
|
2014-08-30 06:15:59 +06:00
|
|
|
|
2019-09-04 18:24:37 +05:00
|
|
|
.def("__getitem__", [](const Mesh & self, PointIndex id) { return self[id]; })
|
|
|
|
.def("__getitem__", [](const Mesh & self, ElementIndex id) { return self[id]; })
|
|
|
|
.def("__getitem__", [](const Mesh & self, SurfaceElementIndex id) { return self[id]; })
|
|
|
|
.def("__getitem__", [](const Mesh & self, SegmentIndex id) { return self[id]; })
|
2015-05-18 19:19:38 +05:00
|
|
|
|
2019-09-04 18:24:37 +05:00
|
|
|
.def("__setitem__", [](Mesh & self, PointIndex id, const MeshPoint & mp) { return self[id] = mp; })
|
2015-11-11 22:46:18 +05:00
|
|
|
|
2019-09-04 18:24:37 +05:00
|
|
|
.def ("Add", [](Mesh & self, MeshPoint p)
|
|
|
|
{
|
|
|
|
return self.AddPoint (Point3d(p));
|
|
|
|
})
|
|
|
|
|
|
|
|
.def ("Add", [](Mesh & self, const Element & el)
|
|
|
|
{
|
|
|
|
return self.AddVolumeElement (el);
|
|
|
|
})
|
|
|
|
|
|
|
|
.def ("Add", [](Mesh & self, const Element2d & el)
|
|
|
|
{
|
|
|
|
return self.AddSurfaceElement (el);
|
|
|
|
})
|
2015-05-18 19:19:38 +05:00
|
|
|
|
2019-09-04 18:24:37 +05:00
|
|
|
.def ("Add", [](Mesh & self, const Segment & el)
|
|
|
|
{
|
|
|
|
return self.AddSegment (el);
|
|
|
|
})
|
|
|
|
|
|
|
|
.def ("Add", [](Mesh & self, const Element0d & el)
|
|
|
|
{
|
|
|
|
return self.pointelements.Append (el);
|
|
|
|
})
|
|
|
|
|
|
|
|
.def ("Add", [](Mesh & self, const FaceDescriptor & fd)
|
|
|
|
{
|
|
|
|
return self.AddFaceDescriptor (fd);
|
|
|
|
})
|
2016-12-15 17:05:34 +05:00
|
|
|
|
|
|
|
.def ("DeleteSurfaceElement",
|
2019-09-04 18:24:37 +05:00
|
|
|
[](Mesh & self, SurfaceElementIndex i)
|
|
|
|
{
|
|
|
|
return self.Delete(i);
|
|
|
|
})
|
|
|
|
|
|
|
|
.def ("Compress", [](Mesh & self)
|
|
|
|
{
|
|
|
|
return self.Compress ();
|
|
|
|
} ,py::call_guard<py::gil_scoped_release>())
|
|
|
|
|
2016-12-15 17:05:34 +05:00
|
|
|
|
2015-09-01 13:50:15 +05:00
|
|
|
.def ("SetBCName", &Mesh::SetBCName)
|
2015-09-01 22:21:52 +05:00
|
|
|
.def ("GetBCName", FunctionPointer([](Mesh & self, int bc)->string
|
|
|
|
{ return self.GetBCName(bc); }))
|
|
|
|
.def ("SetMaterial", &Mesh::SetMaterial)
|
|
|
|
.def ("GetMaterial", FunctionPointer([](Mesh & self, int domnr)
|
|
|
|
{ return string(self.GetMaterial(domnr)); }))
|
2016-10-20 16:19:24 +05:00
|
|
|
|
2016-11-18 20:57:42 +05:00
|
|
|
.def ("GetCD2Name", &Mesh::GetCD2Name)
|
2018-08-06 20:09:03 +05:00
|
|
|
.def ("SetCD2Name", &Mesh::SetCD2Name)
|
|
|
|
|
|
|
|
.def ("GetCD3Name", &Mesh::GetCD3Name)
|
|
|
|
.def ("SetCD3Name", &Mesh::SetCD3Name)
|
2016-11-18 20:57:42 +05:00
|
|
|
|
2016-11-16 20:13:17 +05:00
|
|
|
.def ("AddPointIdentification", [](Mesh & self, py::object pindex1, py::object pindex2, int identnr, int type)
|
2016-10-21 19:01:46 +05:00
|
|
|
{
|
2016-11-16 20:13:17 +05:00
|
|
|
if(py::extract<PointIndex>(pindex1).check() && py::extract<PointIndex>(pindex2).check())
|
2016-10-21 19:01:46 +05:00
|
|
|
{
|
2016-11-16 20:13:17 +05:00
|
|
|
self.GetIdentifications().Add (py::extract<PointIndex>(pindex1)(), py::extract<PointIndex>(pindex2)(), identnr);
|
2016-10-21 19:01:46 +05:00
|
|
|
self.GetIdentifications().SetType(identnr, Identifications::ID_TYPE(type)); // type = 2 ... periodic
|
|
|
|
}
|
2016-11-16 20:13:17 +05:00
|
|
|
},
|
|
|
|
//py::default_call_policies(),
|
|
|
|
py::arg("pid1"),
|
|
|
|
py::arg("pid2"),
|
|
|
|
py::arg("identnr"),
|
|
|
|
py::arg("type"))
|
2017-10-12 15:55:07 +05:00
|
|
|
.def ("CalcLocalH", &Mesh::CalcLocalH)
|
|
|
|
.def ("SetMaxHDomain", [] (Mesh& self, py::list maxhlist)
|
|
|
|
{
|
2019-07-09 13:39:16 +05:00
|
|
|
NgArray<double> maxh;
|
2017-10-12 15:55:07 +05:00
|
|
|
for(auto el : maxhlist)
|
|
|
|
maxh.Append(py::cast<double>(el));
|
|
|
|
self.SetMaxHDomain(maxh);
|
|
|
|
})
|
2016-11-16 20:13:17 +05:00
|
|
|
.def ("GenerateVolumeMesh",
|
2019-07-29 10:11:57 +05:00
|
|
|
[](Mesh & self, MeshingParameters* pars,
|
|
|
|
py::kwargs kwargs)
|
2015-08-29 16:54:00 +05:00
|
|
|
{
|
|
|
|
MeshingParameters mp;
|
2019-07-29 10:11:57 +05:00
|
|
|
if(pars) mp = *pars;
|
2018-03-13 02:38:21 +05:00
|
|
|
{
|
|
|
|
py::gil_scoped_acquire acquire;
|
2019-07-29 10:11:57 +05:00
|
|
|
CreateMPfromKwargs(mp, kwargs);
|
2018-03-13 02:38:21 +05:00
|
|
|
}
|
2015-08-29 16:54:00 +05:00
|
|
|
MeshVolume (mp, self);
|
2015-09-02 22:01:49 +05:00
|
|
|
OptimizeVolume (mp, self);
|
2019-07-29 10:54:38 +05:00
|
|
|
}, py::arg("mp")=nullptr,
|
|
|
|
meshingparameter_description.c_str(),
|
2019-07-26 20:07:30 +05:00
|
|
|
py::call_guard<py::gil_scoped_release>())
|
2015-08-29 16:54:00 +05:00
|
|
|
|
2019-04-10 17:13:12 +05:00
|
|
|
.def ("OptimizeVolumeMesh", [](Mesh & self)
|
2015-12-11 18:31:28 +05:00
|
|
|
{
|
|
|
|
MeshingParameters mp;
|
|
|
|
mp.optsteps3d = 5;
|
|
|
|
OptimizeVolume (mp, self);
|
2019-04-10 17:13:12 +05:00
|
|
|
},py::call_guard<py::gil_scoped_release>())
|
2015-12-11 18:31:28 +05:00
|
|
|
|
2019-04-10 17:13:12 +05:00
|
|
|
.def ("OptimizeMesh2d", [](Mesh & self)
|
|
|
|
{
|
|
|
|
self.CalcLocalH(0.5);
|
|
|
|
MeshingParameters mp;
|
|
|
|
mp.optsteps2d = 5;
|
|
|
|
Optimize2d (self, mp);
|
|
|
|
},py::call_guard<py::gil_scoped_release>())
|
|
|
|
|
2015-08-29 16:54:00 +05:00
|
|
|
.def ("Refine", FunctionPointer
|
|
|
|
([](Mesh & self)
|
|
|
|
{
|
2019-07-30 15:40:22 +05:00
|
|
|
self.GetGeometry()->GetRefinement().Refine(self);
|
2018-05-19 00:13:09 +05:00
|
|
|
self.UpdateTopology();
|
2018-03-13 02:38:21 +05:00
|
|
|
}),py::call_guard<py::gil_scoped_release>())
|
2015-08-29 16:54:00 +05:00
|
|
|
|
2017-06-01 02:44:50 +05:00
|
|
|
.def ("SecondOrder", FunctionPointer
|
|
|
|
([](Mesh & self)
|
|
|
|
{
|
2019-07-30 15:40:22 +05:00
|
|
|
self.GetGeometry()->GetRefinement().MakeSecondOrder(self);
|
2017-06-01 02:44:50 +05:00
|
|
|
}))
|
|
|
|
|
2017-12-06 18:16:52 +05:00
|
|
|
.def ("GetGeometry", [] (Mesh& self) { return self.GetGeometry(); })
|
|
|
|
.def ("SetGeometry", [](Mesh & self, shared_ptr<NetgenGeometry> geo)
|
2016-05-09 12:48:33 +05:00
|
|
|
{
|
|
|
|
self.SetGeometry(geo);
|
2017-12-06 18:16:52 +05:00
|
|
|
})
|
2016-05-09 12:48:33 +05:00
|
|
|
|
2017-01-05 09:08:24 +05:00
|
|
|
/*
|
|
|
|
.def ("SetGeometry", FunctionPointer
|
|
|
|
([](Mesh & self, shared_ptr<CSGeometry> geo)
|
|
|
|
{
|
|
|
|
self.SetGeometry(geo);
|
|
|
|
}))
|
|
|
|
*/
|
|
|
|
|
2018-03-13 02:38:21 +05:00
|
|
|
.def ("BuildSearchTree", &Mesh::BuildElementSearchTree,py::call_guard<py::gil_scoped_release>())
|
2016-05-06 00:26:33 +05:00
|
|
|
|
2014-12-18 19:00:58 +05:00
|
|
|
.def ("BoundaryLayer", FunctionPointer
|
2016-11-04 16:14:52 +05:00
|
|
|
([](Mesh & self, int bc, py::list thicknesses, int volnr, py::list materials)
|
2015-09-01 19:35:03 +05:00
|
|
|
{
|
2016-11-04 16:14:52 +05:00
|
|
|
int n = py::len(thicknesses);
|
2015-09-01 19:35:03 +05:00
|
|
|
BoundaryLayerParameters blp;
|
|
|
|
|
|
|
|
for (int i = 1; i <= self.GetNFD(); i++)
|
|
|
|
if (self.GetFaceDescriptor(i).BCProperty() == bc)
|
|
|
|
blp.surfid.Append (i);
|
|
|
|
|
|
|
|
cout << "add layer at surfaces: " << blp.surfid << endl;
|
|
|
|
|
|
|
|
blp.prismlayers = n;
|
|
|
|
blp.growthfactor = 1.0;
|
|
|
|
|
|
|
|
// find max domain nr
|
|
|
|
int maxind = 0;
|
|
|
|
for (ElementIndex ei = 0; ei < self.GetNE(); ei++)
|
|
|
|
maxind = max (maxind, self[ei].GetIndex());
|
|
|
|
cout << "maxind = " << maxind << endl;
|
|
|
|
for ( int i=0; i<n; i++ )
|
|
|
|
{
|
2016-11-04 16:14:52 +05:00
|
|
|
blp.heights.Append( py::extract<double>(thicknesses[i])()) ;
|
2015-09-01 19:35:03 +05:00
|
|
|
blp.new_matnrs.Append( maxind+1+i );
|
2016-11-04 16:14:52 +05:00
|
|
|
self.SetMaterial (maxind+1+i, py::extract<string>(materials[i])().c_str());
|
2015-09-01 19:35:03 +05:00
|
|
|
}
|
|
|
|
blp.bulk_matnr = volnr;
|
|
|
|
GenerateBoundaryLayer (self, blp);
|
|
|
|
}
|
|
|
|
))
|
|
|
|
|
|
|
|
.def ("BoundaryLayer", FunctionPointer
|
2015-01-09 02:18:33 +05:00
|
|
|
([](Mesh & self, int bc, double thickness, int volnr, string material)
|
2014-12-18 19:00:58 +05:00
|
|
|
{
|
|
|
|
BoundaryLayerParameters blp;
|
2014-12-18 21:46:54 +05:00
|
|
|
|
|
|
|
for (int i = 1; i <= self.GetNFD(); i++)
|
|
|
|
if (self.GetFaceDescriptor(i).BCProperty() == bc)
|
|
|
|
blp.surfid.Append (i);
|
|
|
|
|
|
|
|
cout << "add layer at surfaces: " << blp.surfid << endl;
|
|
|
|
|
2014-12-18 19:00:58 +05:00
|
|
|
blp.prismlayers = 1;
|
|
|
|
blp.hfirst = thickness;
|
|
|
|
blp.growthfactor = 1.0;
|
2014-12-18 21:46:54 +05:00
|
|
|
|
|
|
|
// find max domain nr
|
|
|
|
int maxind = 0;
|
|
|
|
for (ElementIndex ei = 0; ei < self.GetNE(); ei++)
|
|
|
|
maxind = max (maxind, self[ei].GetIndex());
|
|
|
|
cout << "maxind = " << maxind << endl;
|
|
|
|
self.SetMaterial (maxind+1, material.c_str());
|
2015-01-09 02:18:33 +05:00
|
|
|
blp.new_matnr = maxind+1;
|
|
|
|
blp.bulk_matnr = volnr;
|
2014-12-18 19:00:58 +05:00
|
|
|
GenerateBoundaryLayer (self, blp);
|
|
|
|
}
|
|
|
|
))
|
2016-10-28 19:49:50 +05:00
|
|
|
|
2018-03-11 20:28:43 +05:00
|
|
|
.def ("EnableTable", [] (Mesh & self, string name, bool set)
|
|
|
|
{
|
|
|
|
if (name == "edges")
|
|
|
|
const_cast<MeshTopology&>(self.GetTopology()).SetBuildEdges(set);
|
|
|
|
if (name == "faces")
|
|
|
|
const_cast<MeshTopology&>(self.GetTopology()).SetBuildFaces(set);
|
|
|
|
},
|
|
|
|
py::arg("name"), py::arg("set")=true)
|
|
|
|
|
2019-04-10 17:13:12 +05:00
|
|
|
.def ("Scale", [](Mesh & self, double factor)
|
|
|
|
{
|
|
|
|
for(auto i = 0; i<self.GetNP();i++)
|
|
|
|
self.Point(i).Scale(factor);
|
|
|
|
})
|
|
|
|
.def ("Copy", [](Mesh & self)
|
|
|
|
{
|
|
|
|
auto m2 = make_shared<Mesh> ();
|
|
|
|
*m2 = self;
|
|
|
|
return m2;
|
|
|
|
})
|
2019-09-16 15:11:49 +05:00
|
|
|
.def ("CalcMinMaxAngle", [](Mesh & self, double badel_limit)
|
|
|
|
{
|
|
|
|
double values[4];
|
|
|
|
self.CalcMinMaxAngle (badel_limit, values);
|
|
|
|
py::dict res;
|
|
|
|
res["trig"] = py::make_tuple( values[0], values[1] );
|
|
|
|
res["tet"] = py::make_tuple( values[2], values[3] );
|
|
|
|
return res;
|
|
|
|
}, py::arg("badelement_limit")=175.0)
|
2014-08-31 15:14:18 +06:00
|
|
|
;
|
2014-08-30 06:15:59 +06:00
|
|
|
|
2019-02-14 02:39:31 +05:00
|
|
|
m.def("ImportMesh", [](const string& filename)
|
|
|
|
{
|
|
|
|
auto mesh = make_shared<Mesh>();
|
|
|
|
ReadFile(*mesh, filename);
|
|
|
|
return mesh;
|
|
|
|
}, py::arg("filename"),
|
|
|
|
R"delimiter(Import mesh from other file format, supported file formats are:
|
|
|
|
Neutral format (*.mesh, *.emt)
|
|
|
|
Surface file (*.surf)
|
|
|
|
Universal format (*.unv)
|
|
|
|
Olaf format (*.emt)
|
|
|
|
Tet format (*.tet)
|
|
|
|
Pro/ENGINEER format (*.fnf)
|
|
|
|
)delimiter");
|
2016-12-05 18:39:09 +05:00
|
|
|
py::enum_<MESHING_STEP>(m,"MeshingStep")
|
|
|
|
.value("MESHEDGES",MESHCONST_MESHEDGES)
|
|
|
|
.value("MESHSURFACE",MESHCONST_OPTSURFACE)
|
|
|
|
.value("MESHVOLUME",MESHCONST_OPTVOLUME)
|
|
|
|
;
|
2018-03-09 02:19:11 +05:00
|
|
|
|
2014-08-31 15:14:18 +06:00
|
|
|
typedef MeshingParameters MP;
|
2019-07-26 02:25:58 +05:00
|
|
|
auto mp = py::class_<MP> (m, "MeshingParameters")
|
2016-11-04 16:14:52 +05:00
|
|
|
.def(py::init<>())
|
2019-08-02 19:22:53 +05:00
|
|
|
.def(py::init([](MeshingParameters* other, py::kwargs kwargs)
|
2018-03-09 02:19:11 +05:00
|
|
|
{
|
2019-07-29 10:11:57 +05:00
|
|
|
MeshingParameters mp;
|
2019-08-02 19:22:53 +05:00
|
|
|
if(other) mp = *other;
|
2019-08-06 13:42:53 +05:00
|
|
|
CreateMPfromKwargs(mp, kwargs, false);
|
2019-07-29 10:11:57 +05:00
|
|
|
return mp;
|
2019-08-02 19:22:53 +05:00
|
|
|
}), py::arg("mp")=nullptr, meshingparameter_description.c_str())
|
2014-08-31 15:14:18 +06:00
|
|
|
.def("__str__", &ToString<MP>)
|
2016-09-29 19:44:16 +05:00
|
|
|
.def("RestrictH", FunctionPointer
|
|
|
|
([](MP & mp, double x, double y, double z, double h)
|
|
|
|
{
|
|
|
|
mp.meshsize_points.Append ( MeshingParameters::MeshSizePoint (Point<3> (x,y,z), h));
|
|
|
|
}),
|
2016-11-04 16:14:52 +05:00
|
|
|
py::arg("x"), py::arg("y"), py::arg("z"), py::arg("h")
|
2016-09-29 19:44:16 +05:00
|
|
|
)
|
2014-08-30 06:15:59 +06:00
|
|
|
;
|
2014-12-05 21:00:01 +05:00
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
m.def("SetTestoutFile", FunctionPointer ([] (const string & filename)
|
2014-12-05 21:00:01 +05:00
|
|
|
{
|
|
|
|
delete testout;
|
|
|
|
testout = new ofstream (filename);
|
|
|
|
}));
|
2014-12-09 19:58:26 +05:00
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
m.def("SetMessageImportance", FunctionPointer ([] (int importance)
|
2014-12-09 19:58:26 +05:00
|
|
|
{
|
|
|
|
int old = printmessage_importance;
|
|
|
|
printmessage_importance = importance;
|
|
|
|
return old;
|
|
|
|
}));
|
2019-01-31 00:55:45 +05:00
|
|
|
|
|
|
|
|
2014-08-30 06:15:59 +06:00
|
|
|
}
|
|
|
|
|
2017-09-01 12:33:57 +05:00
|
|
|
PYBIND11_MODULE(libmesh, m) {
|
2016-11-04 16:14:52 +05:00
|
|
|
ExportNetgenMeshing(m);
|
2014-08-30 06:15:59 +06:00
|
|
|
}
|
2014-08-31 19:05:24 +06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-08-30 06:15:59 +06:00
|
|
|
|
|
|
|
|