mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +05:00
double conversion on C++ side
This commit is contained in:
parent
ff8708d76b
commit
6b28275b88
@ -914,16 +914,23 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
|||||||
return self.AddFaceDescriptor (fd);
|
return self.AddFaceDescriptor (fd);
|
||||||
})
|
})
|
||||||
|
|
||||||
.def ("AddPoints", [](Mesh & self, py::buffer b)
|
.def ("AddPoints", [](Mesh & self, py::buffer b1)
|
||||||
{
|
{
|
||||||
static Timer timer("Mesh::AddPoints");
|
static Timer timer("Mesh::AddPoints");
|
||||||
|
static Timer timercast("Mesh::AddPoints - casting");
|
||||||
RegionTimer reg(timer);
|
RegionTimer reg(timer);
|
||||||
|
|
||||||
|
timercast.Start();
|
||||||
|
// casting from here: https://github.com/pybind/pybind11/issues/1908
|
||||||
|
auto b = b1.cast<py::array_t<double_t, py::array::c_style | py::array::forcecast>>();
|
||||||
|
timercast.Stop();
|
||||||
|
|
||||||
py::buffer_info info = b.request();
|
py::buffer_info info = b.request();
|
||||||
|
// cout << "data format = " << info.format << endl;
|
||||||
if (info.ndim != 2)
|
if (info.ndim != 2)
|
||||||
throw std::runtime_error("AddPoints needs buffer of dimension 2");
|
throw std::runtime_error("AddPoints needs buffer of dimension 2");
|
||||||
if (info.format != py::format_descriptor<double>::format())
|
// if (info.format != py::format_descriptor<double>::format())
|
||||||
throw std::runtime_error("AddPoints needs buffer of type double");
|
// throw std::runtime_error("AddPoints needs buffer of type double");
|
||||||
if (info.strides[0] != sizeof(double)*info.shape[1])
|
if (info.strides[0] != sizeof(double)*info.shape[1])
|
||||||
throw std::runtime_error("AddPoints needs packed array");
|
throw std::runtime_error("AddPoints needs packed array");
|
||||||
double * ptr = static_cast<double*> (info.ptr);
|
double * ptr = static_cast<double*> (info.ptr);
|
||||||
@ -942,16 +949,21 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
|||||||
ptr += 3;
|
ptr += 3;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.def ("AddElements", [](Mesh & self, int dim, int index, py::buffer b, int base)
|
.def ("AddElements", [](Mesh & self, int dim, int index, py::buffer b1, int base)
|
||||||
{
|
{
|
||||||
static Timer timer("Mesh::AddElements");
|
static Timer timer("Mesh::AddElements");
|
||||||
|
static Timer timercast("Mesh::AddElements casting");
|
||||||
RegionTimer reg(timer);
|
RegionTimer reg(timer);
|
||||||
|
|
||||||
|
timercast.Start();
|
||||||
|
auto b = b1.cast<py::array_t<int, py::array::c_style | py::array::forcecast>>();
|
||||||
|
timercast.Stop();
|
||||||
|
|
||||||
py::buffer_info info = b.request();
|
py::buffer_info info = b.request();
|
||||||
if (info.ndim != 2)
|
if (info.ndim != 2)
|
||||||
throw std::runtime_error("AddElements needs buffer of dimension 2");
|
throw std::runtime_error("AddElements needs buffer of dimension 2");
|
||||||
if (info.format != py::format_descriptor<int>::format())
|
// if (info.format != py::format_descriptor<int>::format())
|
||||||
throw std::runtime_error("AddPoints needs buffer of type int");
|
// throw std::runtime_error("AddPoints needs buffer of type int");
|
||||||
|
|
||||||
int * ptr = static_cast<int*> (info.ptr);
|
int * ptr = static_cast<int*> (info.ptr);
|
||||||
if (dim == 2)
|
if (dim == 2)
|
||||||
|
@ -10,11 +10,13 @@ def ReadViaMeshIO(filename):
|
|||||||
pts = m.points
|
pts = m.points
|
||||||
|
|
||||||
mesh = Mesh(dim=pts.shape[1])
|
mesh = Mesh(dim=pts.shape[1])
|
||||||
mesh.AddPoints ( np.asarray(pts, dtype=np.float64) ) # needed for correct little/big endian
|
# mesh.AddPoints ( np.asarray(pts, dtype=np.float64) ) # needed for correct little/big endian
|
||||||
|
mesh.AddPoints ( pts )
|
||||||
|
|
||||||
fd = mesh.Add (FaceDescriptor(bc=1))
|
fd = mesh.Add (FaceDescriptor(bc=1))
|
||||||
for cb in m.cells:
|
for cb in m.cells:
|
||||||
mesh.AddElements(dim=cb.dim, index=1, data=np.asarray(cb.data, dtype=np.int32), base=0)
|
# mesh.AddElements(dim=cb.dim, index=1, data=np.asarray(cb.data, dtype=np.int32), base=0)
|
||||||
|
mesh.AddElements(dim=cb.dim, index=1, data=cb.data, base=0)
|
||||||
|
|
||||||
return mesh
|
return mesh
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user