diff --git a/libsrc/csg/genmesh.cpp b/libsrc/csg/genmesh.cpp index 07fa41d2..ad67151f 100644 --- a/libsrc/csg/genmesh.cpp +++ b/libsrc/csg/genmesh.cpp @@ -692,6 +692,8 @@ namespace netgen mparam.grading); mesh -> LoadLocalMeshSize (mparam.meshsizefilename); + for (auto mspnt : mparam.meshsize_points) + mesh -> RestrictLocalH (mspnt.pnt, mspnt.h); } spoints.SetSize(0); diff --git a/libsrc/csg/revolution.cpp b/libsrc/csg/revolution.cpp index a8a01a07..85b49bd8 100644 --- a/libsrc/csg/revolution.cpp +++ b/libsrc/csg/revolution.cpp @@ -156,25 +156,42 @@ namespace netgen { if(spline_coefficient.Size() == 0) spline->GetCoeff(spline_coefficient); + if(spline_coefficient_shifted.Size() == 0) + spline->GetCoeff(spline_coefficient_shifted, spline->StartPI()); Point<2> p; CalcProj(point,p); - return spline_coefficient(0)*p(0)*p(0) + spline_coefficient(1)*p(1)*p(1) + double val = spline_coefficient(0)*p(0)*p(0) + spline_coefficient(1)*p(1)*p(1) + spline_coefficient(2)*p(0)*p(1) + spline_coefficient(3)*p(0) + spline_coefficient(4)*p(1) + spline_coefficient(5); + + Vec<2> pr = p-spline->StartPI(); + + + // cout << "spline_coefficinet = " << spline_coefficient << endl; + // cout << "shifted = " << spline_coefficient_shifted << endl; + + double val2 = spline_coefficient_shifted(0)*pr(0)*pr(0) + spline_coefficient_shifted(1)*pr(1)*pr(1) + + spline_coefficient_shifted(2)*pr(0)*pr(1) + spline_coefficient_shifted(3)*pr(0) + + spline_coefficient_shifted(4)*pr(1) + spline_coefficient_shifted(5); + + // cout << "val = " << val << " =?= " << val2 << endl; + return val2; } void RevolutionFace :: CalcGradient (const Point<3> & point, Vec<3> & grad) const { if(spline_coefficient.Size() == 0) spline->GetCoeff(spline_coefficient); + if(spline_coefficient_shifted.Size() == 0) + spline->GetCoeff(spline_coefficient_shifted, spline->StartPI()); Vec<3> point_minus_p0 = point-p0; Point<2> p; CalcProj0(point_minus_p0,p); - + /* const double dFdxbar = 2.*spline_coefficient(0)*p(0) + spline_coefficient(2)*p(1) + spline_coefficient(3); if(fabs(p(1)) > 1e-10) @@ -193,6 +210,27 @@ namespace netgen grad(2) = dFdxbar*v_axis(2); //(*testout) << "grad2("< pr = p-spline->StartPI(); + const double dFdxbar = 2.*spline_coefficient_shifted(0)*pr(0) + spline_coefficient_shifted(2)*pr(1) + spline_coefficient_shifted(3); + + if(fabs(p(1)) > 1e-10) + { + const double dFdybar = 2.*spline_coefficient_shifted(1)*pr(1) + spline_coefficient_shifted(2)*pr(0) + spline_coefficient_shifted(4); + + grad(0) = dFdxbar*v_axis(0) + dFdybar * ( point_minus_p0(0)-v_axis(0)*p(0) )/p(1); + grad(1) = dFdxbar*v_axis(1) + dFdybar * ( point_minus_p0(1)-v_axis(1)*p(0) )/p(1); + grad(2) = dFdxbar*v_axis(2) + dFdybar * ( point_minus_p0(2)-v_axis(2)*p(0) )/p(1); + //(*testout) << "grad1("< & EndPI () const { return p3; } /// virtual void GetCoeff (Vector & coeffs) const; - + virtual void GetCoeff (Vector & coeffs, Point p0) const; + virtual string GetType(void) const {return "spline3";} const GeomPoint & TangentPoint (void) const { return p2; } @@ -394,6 +397,19 @@ namespace netgen coeffs[5] = -dx * p1(1) + dy * p1(0); } + template + void LineSeg :: GetCoeff (Vector & coeffs, Point p) const + { + coeffs.SetSize(6); + + double dx = p2(0) - p1(0); + double dy = p2(1) - p1(1); + + coeffs[0] = coeffs[1] = coeffs[2] = 0; + coeffs[3] = -dy; + coeffs[4] = dx; + coeffs[5] = -dx * (p1(1)-p(1)) + dy * (p1(0)-p(0)); + } template diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index e6918e7e..ca272439 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -70,6 +70,10 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (int nr) const ret.index = el.si; else ret.index = el.edgenr; + if (mesh->GetDimension() == 2) + ret.mat = mesh->GetBCNamePtr(el.si-1); + else + ret.mat = nullptr; ret.points.num = el.GetNP(); ret.points.ptr = (int*)&(el[0]); diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 80be7fa1..44d2a6d0 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -1134,12 +1134,26 @@ namespace netgen MeshingParameters (); /// MeshingParameters (const MeshingParameters & mp2) = default; + MeshingParameters (MeshingParameters && mp2) = default; /// void Print (ostream & ost) const; /// // void CopyFrom(const MeshingParameters & other); - + class MeshSizePoint + { + public: + Point<3> pnt; + double h; + MeshSizePoint (Point<3> _pnt, double _h) : pnt(_pnt), h(_h) { ; } + MeshSizePoint () = default; + MeshSizePoint (const MeshSizePoint &) = default; + MeshSizePoint (MeshSizePoint &&) = default; + MeshSizePoint & operator= (const MeshSizePoint &) = default; + MeshSizePoint & operator= (MeshSizePoint &&) = default; + }; + Array meshsize_points; + void (*render_function)(bool) = NULL; void Render(bool blocking = false) { diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index fd6a8c37..41faf084 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -609,7 +609,13 @@ DLL_HEADER void ExportNetgenMeshing() .add_property("maxh", FunctionPointer ([](const MP & mp ) { return mp.maxh; }), FunctionPointer ([](MP & mp, double maxh) { return mp.maxh = maxh; })) - + .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)); + }), + (bp::arg("x"), bp::arg("y"), bp::arg("z"), bp::arg("h")) + ) ; bp::def("SetTestoutFile", FunctionPointer ([] (const string & filename) diff --git a/python/csg.py b/python/csg.py index 725a09a9..cde89fc9 100644 --- a/python/csg.py +++ b/python/csg.py @@ -14,7 +14,11 @@ def VS (obj): def csg_meshing_func (geom, **args): - return GenerateMesh (geom, MeshingParameters (**args)) + if "mp" in args: + return GenerateMesh (geom, args["mp"]) + else: + return GenerateMesh (geom, MeshingParameters (**args)) +# return GenerateMesh (geom, MeshingParameters (**args)) CSGeometry.GenerateMesh = csg_meshing_func