From 3a1c950a5f3d23d85798f6209981b5fc924c4547 Mon Sep 17 00:00:00 2001 From: Christoph Lehrenfeld <christoph.lehrenfeld@gmail.com> Date: Tue, 26 Feb 2019 15:23:06 +0100 Subject: [PATCH 1/3] import mymesh from python --- python/CMakeLists.txt | 2 +- python/mymesh.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 python/mymesh.py diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 96a9cdc7..c6ce69d3 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -7,7 +7,7 @@ configure_file(__init__.py ${CMAKE_CURRENT_BINARY_DIR}/__init__.py @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/__init__.py - meshing.py csg.py geom2d.py stl.py gui.py NgOCC.py read_gmsh.py + meshing.py csg.py geom2d.py stl.py gui.py NgOCC.py read_gmsh.py mymesh.py DESTINATION ${NG_INSTALL_DIR_PYTHON}/${NG_INSTALL_SUFFIX} COMPONENT netgen ) diff --git a/python/mymesh.py b/python/mymesh.py new file mode 100644 index 00000000..b36add28 --- /dev/null +++ b/python/mymesh.py @@ -0,0 +1 @@ +from netgen.libngpy._mymesh import * -- GitLab From e8ef35fcb14d2707e9685e3449ebb173a58ca59e Mon Sep 17 00:00:00 2001 From: Christoph Lehrenfeld <christoph.lehrenfeld@gmail.com> Date: Tue, 26 Feb 2019 17:09:22 +0100 Subject: [PATCH 2/3] ngx_mymesh to python (as ngs_mesh) --- libsrc/include/nginterface_v2.hpp | 7 ++++++- libsrc/mymesh/mymesh_python.cpp | 16 ++++++++++++++-- libsrc/mymesh/mymeshclass.hpp | 6 ++---- libsrc/mymesh/mymeshclasstest.cpp | 10 ++++++++-- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/libsrc/include/nginterface_v2.hpp b/libsrc/include/nginterface_v2.hpp index 54b5c061..3c2e209b 100644 --- a/libsrc/include/nginterface_v2.hpp +++ b/libsrc/include/nginterface_v2.hpp @@ -641,6 +641,12 @@ namespace netgen Ng_Buffer<int[2]> GetPeriodicVertices(int idnr) const override; inline int GetTimeStamp() const override; + + + virtual shared_ptr<Mesh> GetMesh () const override { return nullptr; } + virtual shared_ptr<Mesh> SelectMesh () const override{ return nullptr; } + bool Valid () override { return true; } + }; class DLL_HEADER Ngx_netgen_Mesh : public Ngx_Mesh @@ -845,7 +851,6 @@ DLL_HEADER Ngx_netgen_Mesh * LoadMesh (const string & filename); - #ifdef HAVE_NETGEN_SOURCES #include <meshing.hpp> diff --git a/libsrc/mymesh/mymesh_python.cpp b/libsrc/mymesh/mymesh_python.cpp index fe097621..677e464f 100644 --- a/libsrc/mymesh/mymesh_python.cpp +++ b/libsrc/mymesh/mymesh_python.cpp @@ -3,6 +3,12 @@ #include "../general/ngpython.hpp" #include "mymeshclass.hpp" +#include <meshing.hpp> +// #include "nginterface.h" +#include "nginterface.h" +#include "../include/nginterface_v2.hpp" +// #include <meshing.hpp> + #ifdef WIN32 #define DLL_HEADER __declspec(dllimport) #else @@ -13,9 +19,15 @@ using namespace netgen; DLL_HEADER void ExportMyMesh(py::module &m) { - py::class_<MyMesh> (m, "MyMesh") + py::class_<Ngx_Mesh,shared_ptr<Ngx_Mesh>> (m, "Ngx_Mesh"); + //.def(py::init<std::size_t, std::size_t, std::size_t>()); + + py::class_<MyMesh,shared_ptr<MyMesh>> (m, "MyMesh") .def(py::init<std::size_t, std::size_t, std::size_t>()); + py::class_<Ngx_MyMesh,shared_ptr<Ngx_MyMesh>,Ngx_Mesh> (m, "Ngx_MyMesh") + .def(py::init<shared_ptr<MyMesh>>()); + py::class_<MyMesh::Node> (m, "Node") .def("__str__", &MyMesh::Node::print); @@ -33,4 +45,4 @@ PYBIND11_MODULE(libmesh, m) { ExportMyMesh(m); } -#endif \ No newline at end of file +#endif diff --git a/libsrc/mymesh/mymeshclass.hpp b/libsrc/mymesh/mymeshclass.hpp index 537a54db..ef5abf21 100644 --- a/libsrc/mymesh/mymeshclass.hpp +++ b/libsrc/mymesh/mymeshclass.hpp @@ -1,6 +1,4 @@ -#ifndef MYMESHCLASS -#define MYMESHCLASS -#endif +#pragma once #include <cstdlib> #include <memory> @@ -220,4 +218,4 @@ std::ostream &operator<<(std::ostream &os, const MyMesh::Edge &edge); std::ostream &operator<<(std::ostream &os, const MyMesh::Face &face); std::ostream &operator<<(std::ostream &os, const MyMesh::Volume &volume); -} \ No newline at end of file +} diff --git a/libsrc/mymesh/mymeshclasstest.cpp b/libsrc/mymesh/mymeshclasstest.cpp index 16b43f2c..2efb312d 100644 --- a/libsrc/mymesh/mymeshclasstest.cpp +++ b/libsrc/mymesh/mymeshclasstest.cpp @@ -1,9 +1,13 @@ #include "mymeshclass.hpp" #include <iostream> +#include <meshing.hpp> +#include <nginterface.h> +#include <nginterface_v2.hpp> int main() { - netgen::MyMesh m = netgen::MyMesh(3, 3, 3); + auto spm = make_shared<netgen::MyMesh>(3, 3, 3); + netgen::MyMesh & m(*spm); std::cout << "Number of Nodes:" << m.getNumNodes() << "\n"; for (auto i : m.getNodes()) { @@ -50,4 +54,6 @@ int main() std::cout << j << " "; std::cout << "\n\n"; } -} \ No newline at end of file + + netgen::Ngx_MyMesh ngsmym(spm); +} -- GitLab From 7b1b2a844e8b8630a5ab4ffb3869f177507026dc Mon Sep 17 00:00:00 2001 From: Christoph Lehrenfeld <christoph.lehrenfeld@gmail.com> Date: Tue, 26 Feb 2019 17:10:56 +0100 Subject: [PATCH 3/3] minimal python test --- libsrc/mymesh/mytest.py | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 libsrc/mymesh/mytest.py diff --git a/libsrc/mymesh/mytest.py b/libsrc/mymesh/mytest.py new file mode 100644 index 00000000..4954d211 --- /dev/null +++ b/libsrc/mymesh/mytest.py @@ -0,0 +1,46 @@ +#import netgen.gui +#from ngsolve import * +#from netgen.csg import unit_cube +#from ngsolve.meshes import * + +#mesh = MakeQuadMesh(nx=5,ny=5) +#asdf + +# for v in mesh.vertices: +# print (v, v.point) + +# input("step 1 done") + +# for e in mesh.edges: +# print (e, e.elements) + +# input("step 2 done") + +# for el in mesh.Elements(VOL): +# print (el, el.vertices, el.edges) + +# input("step 3 done") + +# for el in mesh.Elements(BND): +# print (el, el.vertices, el.edges) + +# input("step 4 done") + + +# V=H1(mesh,order=1) +# gfu = GridFunction(V) +# gfu.Set(sin(10*x)) +# integral = Integrate(gfu,mesh) + +# Draw(gfu,mesh,"u") +# print(integral, " =!= ", 0.183129283601153) + + +from netgen.mymesh import * + +mesh = MyMesh(2,2,2) +ngxmymesh = Ngx_MyMesh(mesh) + +from ngsolve import * +ngsmesh = Mesh(ngxmymesh) + -- GitLab