From: Alexander Grayver Date: Fri, 29 Nov 2019 10:34:05 +0000 (+0100) Subject: Add hyper_shell generator X-Git-Tag: v9.2.0-rc1~811^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=adf4bf614540ea4bfadb79fc5808a84a83710fd0;p=dealii.git Add hyper_shell generator --- diff --git a/contrib/python-bindings/include/manifold_wrapper.h b/contrib/python-bindings/include/manifold_wrapper.h index e72018c338..54b848d34c 100644 --- a/contrib/python-bindings/include/manifold_wrapper.h +++ b/contrib/python-bindings/include/manifold_wrapper.h @@ -60,7 +60,7 @@ namespace python * Create CylindricalManifold */ void - create_cylindrical(const int axis, const double tolerance); + create_cylindrical(const int axis = 0, const double tolerance = 1e-10); /** * Return pointer to an underlying manifold object diff --git a/contrib/python-bindings/include/triangulation_wrapper.h b/contrib/python-bindings/include/triangulation_wrapper.h index bbab008dee..a599e62ed5 100644 --- a/contrib/python-bindings/include/triangulation_wrapper.h +++ b/contrib/python-bindings/include/triangulation_wrapper.h @@ -267,6 +267,19 @@ namespace python void generate_half_hyper_ball(PointWrapper ¢er, const double radius = 1.); + /** + * Produce a hyper-shell, the region between two spheres around center, + * with given inner_radius and outer_radius. The number n_cells indicates + * the number of cells of the resulting triangulation, i.e., how many + * cells form the ring (in 2d) or the shell (in 3d). + * The appropriate manifold class is SphericalManifold. + */ + void + generate_hyper_shell(PointWrapper & center, + const double inner_radius, + const double outer_radius, + const unsigned n_cells = 0); + /** * Shift each vertex of the Triangulation by the given @p shift_list. */ @@ -334,6 +347,13 @@ namespace python void write(const std::string &filename, const std::string format) const; + /** + * Read mesh from the file @filename using the given data + * format. + */ + void + read(const std::string &filename, const std::string format) const; + /** * Write the Triangulation in file. */ diff --git a/contrib/python-bindings/source/export_manifold.cc b/contrib/python-bindings/source/export_manifold.cc index e752153655..d9225359b3 100644 --- a/contrib/python-bindings/source/export_manifold.cc +++ b/contrib/python-bindings/source/export_manifold.cc @@ -21,6 +21,12 @@ DEAL_II_NAMESPACE_OPEN namespace python { + BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(create_cylindrical_overloads, + create_cylindrical, + 0, + 2) + + const char create_spherical_docstring[] = " Create spherical manifold with a given center point \n"; @@ -39,7 +45,7 @@ namespace python export_manifold() { boost::python::class_( - "ManifoldWrapper", + "Manifold", boost::python::init( boost::python::args("dim", "spacedim"))) .def("create_spherical", @@ -52,8 +58,9 @@ namespace python boost::python::args("self", "center")) .def("create_cylindrical", &ManifoldWrapper::create_cylindrical, - create_cylindrical_docstring, - boost::python::args("self", "axis", "tolerance")); + create_cylindrical_overloads( + boost::python::args("self", "axis", "tolerance"), + create_cylindrical_docstring)); } } // namespace python diff --git a/contrib/python-bindings/source/export_triangulation.cc b/contrib/python-bindings/source/export_triangulation.cc index f1bab25860..8992688d91 100644 --- a/contrib/python-bindings/source/export_triangulation.cc +++ b/contrib/python-bindings/source/export_triangulation.cc @@ -94,7 +94,10 @@ namespace python 1, 2) - + BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_hyper_shell_overloads, + generate_hyper_shell, + 3, + 4) const char n_active_cells_docstring[] = "Return the number of active cells \n"; @@ -252,6 +255,15 @@ namespace python + const char generate_hyper_shell_docstring[] = + "Produce a hyper-shell, the region between two spheres around center, \n" + "with given inner_radius and outer_radius. The number n_cells indicates \n" + "the number of cells of the resulting triangulation, i.e., how many \n" + "cells form the ring (in 2d) or the shell (in 3d). \n" + "The appropriate manifold class is SphericalManifold. \n"; + + + const char generate_half_hyper_ball_docstring[] = "Generate a half hyper-ball around center, which contains four \n" "elements in 2d and 6 in 3d. The cut plane is perpendicular to the \n" @@ -323,6 +335,14 @@ namespace python + const char read_docstring[] = + "Read a mesh from the file according to the given data format. \n" + "The possible formats are: \n" + " - msh \n" + " - vtk \n"; + + + const char save_docstring[] = "Write the Triangulation to a file \n"; @@ -442,6 +462,14 @@ namespace python generate_half_hyper_ball_overloads( boost::python::args("self", "center", "radius"), generate_half_hyper_ball_docstring)) + .def("generate_hyper_shell", + &TriangulationWrapper::generate_hyper_shell, + generate_hyper_shell_overloads(boost::python::args("self", + "center", + "inner_radius", + "outer_radius", + "n_cells"), + generate_hyper_shell_docstring)) .def("shift", &TriangulationWrapper::shift, shift_docstring, @@ -470,6 +498,10 @@ namespace python &TriangulationWrapper::write, write_docstring, boost::python::args("self", "filename", "format")) + .def("read", + &TriangulationWrapper::read, + read_docstring, + boost::python::args("self", "filename", "format")) .def("save", &TriangulationWrapper::save, save_docstring, diff --git a/contrib/python-bindings/source/manifold_wrapper.cc b/contrib/python-bindings/source/manifold_wrapper.cc index 9c78c60cda..239ba9dfec 100644 --- a/contrib/python-bindings/source/manifold_wrapper.cc +++ b/contrib/python-bindings/source/manifold_wrapper.cc @@ -26,7 +26,7 @@ namespace python { template Manifold * - create_spherical_manifold(PointWrapper center) + create_spherical_manifold(const PointWrapper ¢er) { const Point *point = static_cast *>(center.get_point()); @@ -37,7 +37,7 @@ namespace python template Manifold * - create_polar_manifold(PointWrapper center) + create_polar_manifold(const PointWrapper ¢er) { const Point *point = static_cast *>(center.get_point()); @@ -72,6 +72,12 @@ namespace python { return new PolarManifold(*d); } + else if (const CylindricalManifold *d = + dynamic_cast *>( + manifold)) + { + return new CylindricalManifold(*d); + } else ExcMessage("Unsupported manifold type in clone."); diff --git a/contrib/python-bindings/source/triangulation_wrapper.cc b/contrib/python-bindings/source/triangulation_wrapper.cc index 45b1024ea8..5457d2f00e 100644 --- a/contrib/python-bindings/source/triangulation_wrapper.cc +++ b/contrib/python-bindings/source/triangulation_wrapper.cc @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -373,6 +374,25 @@ namespace python } + template + void + generate_hyper_shell(PointWrapper & center, + const double inner_radius, + const double outer_radius, + const unsigned n_cells, + void * triangulation) + { + // Cast the PointWrapper object to Point + Point center_point = + *(static_cast *>(center.get_point())); + + Triangulation *tria = + static_cast *>(triangulation); + tria->clear(); + GridGenerator::hyper_shell( + *tria, center_point, inner_radius, outer_radius, n_cells); + } + template void @@ -519,6 +539,34 @@ namespace python mesh_writer.write(*tria, ofs, output_format); ofs.close(); } + + + + template + void + read(const std::string &filename, + const std::string &format, + void * triangulation) + { + Triangulation *tria = + static_cast *>(triangulation); + + tria->clear(); + + typename GridIn::Format input_format; + if (format.compare("msh") == 0) + input_format = GridIn::Format::msh; + else if (format.compare("vtk") == 0) + input_format = GridIn::Format::vtk; + else + ExcMessage("Cannot read triangulation of the given format."); + + GridIn mesh_reader; + mesh_reader.attach_triangulation(*tria); + std::ifstream ifs(filename); + mesh_reader.read(ifs, input_format); + ifs.close(); + } } // namespace internal @@ -1004,6 +1052,27 @@ namespace python } + + void + TriangulationWrapper::generate_hyper_shell(PointWrapper & center, + const double inner_radius, + const double outer_radius, + const unsigned n_cells) + { + AssertThrow( + dim == spacedim, + ExcMessage( + "This function is only implemented for dim equal to spacedim.")); + if (dim == 2) + internal::generate_hyper_shell<2>( + center, inner_radius, outer_radius, n_cells, triangulation); + else + internal::generate_hyper_shell<3>( + center, inner_radius, outer_radius, n_cells, triangulation); + } + + + void TriangulationWrapper::generate_hyper_sphere(PointWrapper ¢er, const double radius) @@ -1190,6 +1259,20 @@ namespace python + void + TriangulationWrapper::read(const std::string &filename, + const std::string format) const + { + if ((dim == 2) && (spacedim == 2)) + internal::read<2, 2>(filename, format, triangulation); + else if ((dim == 2) && (spacedim == 3)) + internal::read<2, 3>(filename, format, triangulation); + else + internal::read<3, 3>(filename, format, triangulation); + } + + + void TriangulationWrapper::save(const std::string &filename) const {