From 67d9f772f531ddc66f7e4bfb50e3e6ef61603c3e Mon Sep 17 00:00:00 2001 From: Alexander Grayver Date: Fri, 8 Nov 2019 22:39:02 +0100 Subject: [PATCH] Make indent script work for python bindings --- contrib/.clang-format | 6 - .../include/cell_accessor_wrapper.h | 108 +- .../python-bindings/include/point_wrapper.h | 94 +- .../include/tria_accessor_wrapper.h | 39 +- .../include/triangulation_wrapper.h | 181 +-- .../source/cell_accessor_wrapper.cc | 479 +++---- .../source/export_cell_accessor.cc | 151 +-- .../python-bindings/source/export_point.cc | 106 +- .../source/export_tria_accessor.cc | 97 +- .../source/export_triangulation.cc | 508 ++++---- .../python-bindings/source/point_wrapper.cc | 341 ++--- .../source/tria_accessor_wrapper.cc | 246 ++-- .../source/triangulation_wrapper.cc | 1112 ++++++++++------- contrib/python-bindings/source/wrappers.cc | 18 +- contrib/utilities/indent | 6 +- contrib/utilities/indent-all | 6 +- doc/news/changes/minor/20191115Grayver | 3 + 17 files changed, 1947 insertions(+), 1554 deletions(-) delete mode 100644 contrib/.clang-format create mode 100644 doc/news/changes/minor/20191115Grayver diff --git a/contrib/.clang-format b/contrib/.clang-format deleted file mode 100644 index 184bb9fa58..0000000000 --- a/contrib/.clang-format +++ /dev/null @@ -1,6 +0,0 @@ -# -# The clang-format (Clang 6) style file used by deal.II. -# This directory shall not be formatted. -# - -DisableFormat: true diff --git a/contrib/python-bindings/include/cell_accessor_wrapper.h b/contrib/python-bindings/include/cell_accessor_wrapper.h index 4fb18eb2a6..159349691a 100644 --- a/contrib/python-bindings/include/cell_accessor_wrapper.h +++ b/contrib/python-bindings/include/cell_accessor_wrapper.h @@ -16,12 +16,12 @@ #ifndef dealii_cell_accessor_wrapper_h #define dealii_cell_accessor_wrapper_h -#include - #include #include +#include + DEAL_II_NAMESPACE_OPEN namespace python @@ -61,101 +61,120 @@ namespace python * - in 3D: isotropic, no_refinement, cut_x, cut_y, cut_z, cut_xy, cut_xz, * cut_yz, and cut_xyz. */ - void set_refine_flag(const std::string &refinement_case); + void + set_refine_flag(const std::string &refinement_case); /** * Get the refine flag. */ - std::string get_refine_flag() const; + std::string + get_refine_flag() const; /** * Set the coarsen flag to true or false. */ - void set_coarsen_flag(const bool coarsen_flag); + void + set_coarsen_flag(const bool coarsen_flag); /** * Get the coarsen flag. */ - bool get_coarsen_flag() const; + bool + get_coarsen_flag() const; /** * Get the barycenter of the cell. */ - PointWrapper get_barycenter() const; + PointWrapper + get_barycenter() const; /** * Set the material id. */ - void set_material_id(const int material_id); + void + set_material_id(const int material_id); /** * Get the material id. */ - int get_material_id() const; + int + get_material_id() const; /** * Set the ith vertex of the cell to @p point_wrapper. */ - void set_vertex(const int i, PointWrapper &point_wrapper); + void + set_vertex(const int i, PointWrapper &point_wrapper); /** * Return the ith vertex of the cell. */ - PointWrapper get_vertex(const int i) const; + PointWrapper + get_vertex(const int i) const; /** * Set the manifold id. */ - void set_manifold_id(const int manifold_id); + void + set_manifold_id(const int manifold_id); /** * Get the manifold id. */ - int get_manifold_id() const; + int + get_manifold_id() const; /** - * Return the ith neighbor of a cell. If the neighbor does not exist, - * i.e., if the ith face of the current object is at the boundary, + * Return the ith neighbor of a cell. If the neighbor does not exist, + * i.e., if the ith face of the current object is at the boundary, * then an exception is thrown. */ - CellAccessorWrapper neighbor(const int i) const; + CellAccessorWrapper + neighbor(const int i) const; /** * Return whether the cell is at the boundary. */ - bool at_boundary() const; + bool + at_boundary() const; /** - * This is a slight variation to the at_boundary function: - * for 2 dimensions it is equivalent, for three - * dimensions it returns whether at least one of the 12 + * This is a slight variation to the at_boundary function: + * for 2 dimensions it is equivalent, for three + * dimensions it returns whether at least one of the 12 * lines of the hexahedron is at a boundary. */ - bool has_boundary_lines() const; + bool + has_boundary_lines() const; /** * Get faces of the underlying cell. - */ - boost::python::list faces() const; + */ + boost::python::list + faces() const; /** * Exception. */ DeclException2(ExcVertexDoesNotExist, - int, int, + int, + int, << "Requested vertex number " << arg1 << " does not exist. The largest vertex number " - << "acceptable is "<< arg2-1); + << "acceptable is " << arg2 - 1); DeclException2(ExcNeighborDoesNotExist, - int, int, + int, + int, << "Requested neighbor number " << arg1 << " does not exist. The largest neighbor number " - << "acceptable is "<< arg2-1); + << "acceptable is " << arg2 - 1); + private: - template - const CellAccessorWrapper construct_neighbor_wrapper(const int i) const; + template + const CellAccessorWrapper + construct_neighbor_wrapper(const int i) const; /** * Dimension of the underlying CellAccessor object. @@ -171,25 +190,28 @@ namespace python * Pointer that can be casted to the underlying CellAccessor object. */ void *cell_accessor; - }; - template - const CellAccessorWrapper CellAccessorWrapper::construct_neighbor_wrapper(const int i) const + template + const CellAccessorWrapper + CellAccessorWrapper::construct_neighbor_wrapper(const int i) const { - CellAccessor *cell = - static_cast*>(cell_accessor); - - auto neighbor = cell->neighbor(i); - - CellAccessorWrapper neighbor_wrapper; - neighbor_wrapper.dim = dim; - neighbor_wrapper.spacedim = spacedim; - neighbor_wrapper.cell_accessor = new CellAccessor(&neighbor->get_triangulation(), neighbor->level(), neighbor->index()); - return neighbor_wrapper; + CellAccessor *cell = + static_cast *>(cell_accessor); + + auto neighbor = cell->neighbor(i); + + CellAccessorWrapper neighbor_wrapper; + neighbor_wrapper.dim = dim; + neighbor_wrapper.spacedim = spacedim; + neighbor_wrapper.cell_accessor = + new CellAccessor(&neighbor->get_triangulation(), + neighbor->level(), + neighbor->index()); + return neighbor_wrapper; } -} +} // namespace python DEAL_II_NAMESPACE_CLOSE diff --git a/contrib/python-bindings/include/point_wrapper.h b/contrib/python-bindings/include/point_wrapper.h index b780eec208..57d24db69a 100644 --- a/contrib/python-bindings/include/point_wrapper.h +++ b/contrib/python-bindings/include/point_wrapper.h @@ -17,6 +17,7 @@ #define dealii_point_wrapper_h #include + #include #include @@ -60,140 +61,165 @@ namespace python * l2_norm of the difference between the vectors representing the two * points. */ - double distance(const PointWrapper &p) const; + double + distance(const PointWrapper &p) const; /** * Return the l2_norm of the vector connecting the origin to the point. */ - double norm() const; + double + norm() const; /** * Return the sum of the absolute squares of all entries. */ - double norm_square() const; + double + norm_square() const; /** * Assignment operator. The dimension of the point is changed if it is * different than the one of @p other. */ - PointWrapper &operator= (const PointWrapper &other); + PointWrapper & + operator=(const PointWrapper &other); /** * Test for inequality of two points. */ - bool operator!= (const PointWrapper &p) const; + bool + operator!=(const PointWrapper &p) const; /** * Test for equality of two tensors. */ - bool operator== (const PointWrapper &p) const; + bool + operator==(const PointWrapper &p) const; /** * Return the scalar product of the vectors representing two points. */ - double operator* (const PointWrapper &p) const; + double operator*(const PointWrapper &p) const; /** * Add an offset to a point. */ - PointWrapper operator+(const PointWrapper &) const; + PointWrapper + operator+(const PointWrapper &) const; /** * Subtract two points. */ - PointWrapper operator-(const PointWrapper &) const; + PointWrapper + operator-(const PointWrapper &) const; /** * The opposite point. */ - PointWrapper operator-() const; + PointWrapper + operator-() const; /** * Divide the coordinates of the point by a factor. */ - PointWrapper operator/(const double factor) const; + PointWrapper + operator/(const double factor) const; /** * Multiply the coordinates of the point by a factor. */ - PointWrapper operator* (const double factor) const; + PointWrapper operator*(const double factor) const; /** * Add another point. */ - PointWrapper& operator+= (const PointWrapper &p); + PointWrapper & + operator+=(const PointWrapper &p); /** * Subtract another point. */ - PointWrapper& operator-= (const PointWrapper &p); + PointWrapper & + operator-=(const PointWrapper &p); /** * Scale the coordinates of the point by factor. */ - PointWrapper& operator*= (const double factor); + PointWrapper & + operator*=(const double factor); /** * Scale the coordinates of the point by 1/factor. */ - PointWrapper& operator/= (const double factor); + PointWrapper & + operator/=(const double factor); /** * Return the first component of the Point. */ - double get_x() const; + double + get_x() const; /** * Set the first component of the Point. */ - void set_x(double x); + void + set_x(double x); /** * Return the second component of the Point. */ - double get_y() const; + double + get_y() const; /** * Set the second component of the Point. */ - void set_y(double y); + void + set_y(double y); /** * Return the third component of the Point. */ - double get_z() const; + double + get_z() const; /** * Set the third component of the Point. */ - void set_z(double z); + void + set_z(double z); /** * Return the dimension of the underlying Point. */ - int get_dim() const; + int + get_dim() const; /** * Return a pointer that can be casted to the underlying Point. */ - void *get_point(); + void * + get_point(); /** * Return a constant pointer that can be casted to the underlying Point. */ - const void *get_point() const; + const void * + get_point() const; private: /** * Delete the underlying Point and free the memory. */ - void clear(); + void + clear(); /** * Copy @p other PointWrapper. */ - void copy(const PointWrapper &other); + void + copy(const PointWrapper &other); /** * Dimension of the Point. @@ -211,28 +237,28 @@ namespace python - inline - int PointWrapper::get_dim() const + inline int + PointWrapper::get_dim() const { return dim; } - inline - void *PointWrapper::get_point() + inline void * + PointWrapper::get_point() { return point; } - inline - const void *PointWrapper::get_point() const + inline const void * + PointWrapper::get_point() const { return point; } -} +} // namespace python DEAL_II_NAMESPACE_CLOSE diff --git a/contrib/python-bindings/include/tria_accessor_wrapper.h b/contrib/python-bindings/include/tria_accessor_wrapper.h index 76e62161ff..b34d711087 100644 --- a/contrib/python-bindings/include/tria_accessor_wrapper.h +++ b/contrib/python-bindings/include/tria_accessor_wrapper.h @@ -38,7 +38,10 @@ namespace python /** * Constructor. */ - TriaAccessorWrapper(void* tria_accessor, const int structdim, const int dim, const int spacedim); + TriaAccessorWrapper(void * tria_accessor, + const int structdim, + const int dim, + const int spacedim); /** * Destructor. @@ -48,56 +51,66 @@ namespace python /** * Get the barycenter of the cell. */ - PointWrapper get_barycenter() const; + PointWrapper + get_barycenter() const; /** * Set the ith vertex of the cell to @p point_wrapper. */ - void set_vertex(const int i, PointWrapper &point_wrapper); + void + set_vertex(const int i, PointWrapper &point_wrapper); /** * Return the ith vertex of the cell. */ - PointWrapper get_vertex(const int i) const; + PointWrapper + get_vertex(const int i) const; /** * Set the manifold id. */ - void set_manifold_id(const int manifold_id); + void + set_manifold_id(const int manifold_id); /** * Get the manifold id. */ - int get_manifold_id() const; + int + get_manifold_id() const; /** * Set the boundary id. */ - void set_boundary_id(const int boundary_id); + void + set_boundary_id(const int boundary_id); /** * Get the boundary id. */ - int get_boundary_id() const; + int + get_boundary_id() const; /** * Set the boundary id for all objects. */ - void set_all_boundary_ids(const int boundary_id); + void + set_all_boundary_ids(const int boundary_id); /** * Return whether the cell is at the boundary. */ - bool at_boundary() const; + bool + at_boundary() const; /** * Exception. */ DeclException2(ExcVertexDoesNotExist, - int, int, + int, + int, << "Requested vertex number " << arg1 << " does not exist. The largest vertex number " - << "acceptable is "<< arg2-1); + << "acceptable is " << arg2 - 1); private: /** @@ -121,7 +134,7 @@ namespace python */ void *tria_accessor; }; -} +} // namespace python DEAL_II_NAMESPACE_CLOSE diff --git a/contrib/python-bindings/include/triangulation_wrapper.h b/contrib/python-bindings/include/triangulation_wrapper.h index bccc28dea0..5e3f679be9 100644 --- a/contrib/python-bindings/include/triangulation_wrapper.h +++ b/contrib/python-bindings/include/triangulation_wrapper.h @@ -18,8 +18,10 @@ #include -#include #include + +#include + #include #include @@ -56,46 +58,52 @@ namespace python /** * Return the number of active cells. */ - unsigned int n_active_cells() const; + unsigned int + n_active_cells() const; /** * Generate a hyper cube (square in 2D and cube in 3D) with exactly one * cell. */ - void generate_hyper_cube(const double left = 0., - const double right = 1., - const bool colorize = false); + void + generate_hyper_cube(const double left = 0., + const double right = 1., + const bool colorize = false); /** * Generate a simplex with (dim+1) vertices and mesh cells. */ - void generate_simplex(boost::python::list &vertices); + void + generate_simplex(boost::python::list &vertices); /** * Same as hyper_cube but not only one cell is created but each coordinate * direction is subdivided in @p repetitions cells. */ - void generate_subdivided_hyper_cube(const unsigned int repetitions, - const double left = 0., - const double right = 1.); + void + generate_subdivided_hyper_cube(const unsigned int repetitions, + const double left = 0., + const double right = 1.); /** * Generate a coordinate-parallel brick from the two diagonally opposite * corners points @p p1 and @p p2. */ - void generate_hyper_rectangle(PointWrapper &p1, - PointWrapper &p2, - const bool colorize = false); + void + generate_hyper_rectangle(PointWrapper &p1, + PointWrapper &p2, + const bool colorize = false); /** * Generate a coordinate-parallel brick from the two diagonally opposite * corners points @p p1 and @p p2. In direction i, repetitions[i] cells are * created. */ - void generate_subdivided_hyper_rectangle(boost::python::list &repetitions, - PointWrapper &p1, - PointWrapper &p2, - const bool colorize = false); + void + generate_subdivided_hyper_rectangle(boost::python::list &repetitions, + PointWrapper & p1, + PointWrapper & p2, + const bool colorize = false); /** * Like the previous function. However, here the first argument does not @@ -105,10 +113,11 @@ namespace python * concentrated in certains areas, rather than a uniformly subdidived mesh * as the previous function generates. */ - void generate_subdivided_steps_hyper_rectangle(boost::python::list &step_sizes, - PointWrapper &p1, - PointWrapper &p2, - const bool colorize = false); + void + generate_subdivided_steps_hyper_rectangle(boost::python::list &step_sizes, + PointWrapper & p1, + PointWrapper & p2, + const bool colorize = false); /** * Like the previous function, but with the following twist: the @p @@ -118,10 +127,12 @@ namespace python * cell is deleted from the triangulation, i.e. the domain will have a void * there. */ - void generate_subdivided_material_hyper_rectangle(boost::python::list &spacing, - PointWrapper &p, - boost::python::list &material_id, - const bool colorize = false); + void + generate_subdivided_material_hyper_rectangle( + boost::python::list &spacing, + PointWrapper & p, + boost::python::list &material_id, + const bool colorize = false); /** * Rectangular domain with rectangular pattern of holes. The domain itself @@ -131,7 +142,8 @@ namespace python * total number of mesh cells in that direction is then this number plus * one. The number of holes in one direction must be at least one. */ - void generate_cheese(boost::python::list &holes); + void + generate_cheese(boost::python::list &holes); /** * A general quadrilateral in 2d or a general hexahedron in 3d. It is the @@ -143,8 +155,9 @@ namespace python * 2d and 3d. If it is true, the boundary is colorized as in * hyper_rectangle(). In 1d, the indicators are always colorized. */ - void generate_general_cell(boost::python::list &vertices, - const bool colorize = false); + void + generate_general_cell(boost::python::list &vertices, + const bool colorize = false); /** * A parallelogram. The first corner point is the origin. The @tparam dim @@ -153,8 +166,9 @@ namespace python * same way as in hyper_rectangle(). * @note This function is implemented in 2d only. */ - void generate_parallelogram(boost::python::list &corners, - const bool colorize = false); + void + generate_parallelogram(boost::python::list &corners, + const bool colorize = false); /** * A parallelepiped. The first corner point is the origin. The @tparam dim @@ -167,8 +181,9 @@ namespace python * in the array of @p corners will no longer refer to the same * triangulation. */ - void generate_parallelepiped(boost::python::list &corners, - const bool colorize = false); + void + generate_parallelepiped(boost::python::list &corners, + const bool colorize = false); /** * A subdivided parallelepiped. The first corner point is the origin. The @@ -178,18 +193,21 @@ namespace python * of subdivisions in each of the @tparam dim directions. Colorizing is odne * according to hyper_rectangle(). */ - void generate_fixed_subdivided_parallelepiped(const unsigned int n_subdivisions, - boost::python::list &corners, - const bool colorize = false); + void + generate_fixed_subdivided_parallelepiped(const unsigned int n_subdivisions, + boost::python::list &corners, + const bool colorize = false); /** * A subdivided parallelepided, i.e., the same as above, but where the * number of subdivisions in each of the @tparam dim directions may vary. * Colorizing is done according to hyper_rectangle(). */ - void generate_varying_subdivided_parallelepiped(boost::python::list &n_subdivisions, - boost::python::list &corners, - const bool colorize = false); + void + generate_varying_subdivided_parallelepiped( + boost::python::list &n_subdivisions, + boost::python::list &corners, + const bool colorize = false); /** * Hypercube with a layer of hypercubes around it. The first two parameters @@ -200,10 +218,11 @@ namespace python * In y-direction 4/8, in z-direction 16/32. The cells at corners and edges * (3d) get these values bitwise or'd. */ - void generate_enclosed_hyper_cube(const double left = 0., - const double right = 1., - const double thickness = 1., - const bool colorize = false); + void + generate_enclosed_hyper_cube(const double left = 0., + const double right = 1., + const double thickness = 1., + const bool colorize = false); /** * Generate a hyperball, i.e. a circle or a ball around @p center with @@ -214,8 +233,8 @@ namespace python * SphericalManifold to the cells and faces for correct placement of * vertices upon refinement and to be able to use higher order mappings. */ - void generate_hyper_ball(PointWrapper ¢er, - const double radius = 1.); + void + generate_hyper_ball(PointWrapper ¢er, const double radius = 1.); /** * Generate a hyper sphere, i.e., a surface of a ball in @tparam spacedim @@ -224,8 +243,8 @@ namespace python * for correct placement of vertices upon refinement and to be able to use * higher order mappings. */ - void generate_hyper_sphere(PointWrapper ¢er, - const double radius = 1.); + void + generate_hyper_sphere(PointWrapper ¢er, const double radius = 1.); /** * Generate a hyper-ball intersected with the positive orthant relate to @p @@ -234,8 +253,8 @@ namespace python * and 1 for the cut plane. The appropriate manifold class is * SphericalManifold. */ - void generate_quarter_hyper_ball(PointWrapper ¢er, - const double radius = 1.); + void + generate_quarter_hyper_ball(PointWrapper ¢er, const double radius = 1.); /** * Generate a half hyper-ball around @p center, which contains four elements @@ -244,21 +263,23 @@ namespace python * boundary and 1 for the cut plane. The appropriate manifold class is * SphericalManifold. */ - void generate_half_hyper_ball(PointWrapper ¢er, - const double radius = 1.); + void + generate_half_hyper_ball(PointWrapper ¢er, const double radius = 1.); /** * Shift each vertex of the Triangulation by the given @p shift_list. */ - void shift(boost::python::list &shift_list); + void + shift(boost::python::list &shift_list); /** * Given two triangulations, create the triangulation that contains the * cells of both triangulations. */ - void merge_triangulations(TriangulationWrapper &triangulation_1, - TriangulationWrapper &triangulation_2); - + void + merge_triangulations(TriangulationWrapper &triangulation_1, + TriangulationWrapper &triangulation_2); + /** * Create a new flat triangulation @param out_tria which contains a single * level with all active cells of the input triangulation. If the spacedim @@ -276,61 +297,73 @@ namespace python * manifold ids on interior faces, they have to be specified manually after * the triangulation is created. This function will fail the input * Triangulation contains hanging nodes. - */ - void flatten_triangulation(TriangulationWrapper &tria_out); + */ + void + flatten_triangulation(TriangulationWrapper &tria_out); /** * Refine all the cells @p n times. */ - void refine_global(const unsigned int n); + void + refine_global(const unsigned int n); /** * Execute both refinement and coarsening of the Triangulation. */ - void execute_coarsening_and_refinement(); + void + execute_coarsening_and_refinement(); /** * Return the list of active cell accessors associated to the underlying * Triangulation. */ - boost::python::list active_cells(); + boost::python::list + active_cells(); /** - * Write mesh to the output file @filename according to the given data format. + * Write mesh to the output file @filename according to the given data + * format. */ - void write(const std::string &filename, const std::string format) const; + void + write(const std::string &filename, const std::string format) const; /** * Write the Triangulation in file. */ - void save(const std::string &filename) const; + void + save(const std::string &filename) const; /** * Load the Triangulation from a file. */ - void load(const std::string &filename); + void + load(const std::string &filename); /** * Return the dimension of the underlying Triangulation object. */ - int get_dim() const; + int + get_dim() const; /** * Return the space dimension of the underlying Triangulation object. */ - int get_spacedim() const; + int + get_spacedim() const; /** * Return a pointer that can be casted to the underlying Triangulation * object. */ - void *get_triangulation(); + void * + get_triangulation(); private: /** * Helper function for the constructors. */ - void setup(const std::string &dimension, const std::string &spacedimension); + void + setup(const std::string &dimension, const std::string &spacedimension); /** * Dimension of the underlying Triangulation object. @@ -349,32 +382,32 @@ namespace python }; -//-------------------- inline functions -----------------------// + //-------------------- inline functions -----------------------// - inline - int TriangulationWrapper::get_dim() const + inline int + TriangulationWrapper::get_dim() const { return dim; } - inline - int TriangulationWrapper::get_spacedim() const + inline int + TriangulationWrapper::get_spacedim() const { return spacedim; } - inline - void *TriangulationWrapper::get_triangulation() + inline void * + TriangulationWrapper::get_triangulation() { return triangulation; } -} +} // namespace python DEAL_II_NAMESPACE_CLOSE diff --git a/contrib/python-bindings/source/cell_accessor_wrapper.cc b/contrib/python-bindings/source/cell_accessor_wrapper.cc index 2eae086538..3a5ab80b50 100644 --- a/contrib/python-bindings/source/cell_accessor_wrapper.cc +++ b/contrib/python-bindings/source/cell_accessor_wrapper.cc @@ -13,12 +13,12 @@ // // --------------------------------------------------------------------- -#include - #include + +#include #include -#include #include +#include DEAL_II_NAMESPACE_OPEN @@ -27,45 +27,44 @@ namespace python namespace internal { template - void set_refine_flag(const std::string &refinement_case, - void *cell_accessor) + void + set_refine_flag(const std::string &refinement_case, void *cell_accessor) { - CellAccessor *cell = - static_cast*>(cell_accessor); + CellAccessor *cell = + static_cast *>(cell_accessor); std::unique_ptr> ref_case; if (refinement_case.compare("isotropic") == 0) ref_case.reset(new RefinementCase( - RefinementPossibilities::Possibilities::isotropic_refinement)); + RefinementPossibilities::Possibilities::isotropic_refinement)); else if (refinement_case.compare("no_refinement") == 0) ref_case.reset(new RefinementCase( - RefinementPossibilities::Possibilities::no_refinement)); + RefinementPossibilities::Possibilities::no_refinement)); else if (refinement_case.compare("cut_x") == 0) ref_case.reset(new RefinementCase( - RefinementPossibilities::Possibilities::cut_x)); + RefinementPossibilities::Possibilities::cut_x)); else if (refinement_case.compare("cut_y") == 0) ref_case.reset(new RefinementCase( - RefinementPossibilities::Possibilities::cut_y)); + RefinementPossibilities::Possibilities::cut_y)); else if (refinement_case.compare("cut_xy") == 0) ref_case.reset(new RefinementCase( - RefinementPossibilities::Possibilities::cut_xy)); -#if dim==3 + RefinementPossibilities::Possibilities::cut_xy)); +#if dim == 3 else if (refinement_case.compare("cut_z") == 0) ref_case.reset(new RefinementCase<3>( - RefinementPossibilities<3>::Possibilities::cut_z)); + RefinementPossibilities<3>::Possibilities::cut_z)); else if (refinement_case.compare("cut_xz") == 0) ref_case.reset(new RefinementCase<3>( - RefinementPossibilities<3>::Possibilities::cut_xz)); + RefinementPossibilities<3>::Possibilities::cut_xz)); else if (refinement_case.compare("cut_yz") == 0) ref_case.reset(new RefinementCase<3>( - RefinementPossibilities<3>::Possibilities::cut_yz)); + RefinementPossibilities<3>::Possibilities::cut_yz)); else if (refinement_case.compare("cut_xyz") == 0) ref_case.reset(new RefinementCase<3>( - RefinementPossibilities<3>::Possibilities::cut_xyz)); + RefinementPossibilities<3>::Possibilities::cut_xyz)); #endif else - AssertThrow(false, - ExcMessage("Unknown refinement possibility.")); + AssertThrow(false, ExcMessage("Unknown refinement possibility.")); cell->set_refine_flag(*ref_case); } @@ -73,59 +72,60 @@ namespace python template - std::string get_refine_flag(const void *cell_accessor) + std::string + get_refine_flag(const void *cell_accessor) { - const CellAccessor *cell = - static_cast*>(cell_accessor); + const CellAccessor *cell = + static_cast *>(cell_accessor); - std::string refine_flag; + std::string refine_flag; RefinementCase ref_case = cell->refine_flag_set(); switch (static_cast(ref_case)) { - case (0) : - { - refine_flag = "no_refinement"; - break; - } - case (1) : - { - refine_flag = "cut_x"; - break; - } - case (2) : - { - refine_flag = "cut_y"; - break; - } - case (3) : - { - refine_flag = "cut_xy"; - break; - } - case (4) : - { - refine_flag = "cut_z"; - break; - } - case (5) : - { - refine_flag = "cut_xz"; - break; - } - case (6) : - { - refine_flag = "cut_yz"; - break; - } - case (7) : - { - refine_flag = "cut_xyz"; - break; - } - default : - { - AssertThrow(false, ExcMessage("Internal error.")); - } + case (0): + { + refine_flag = "no_refinement"; + break; + } + case (1): + { + refine_flag = "cut_x"; + break; + } + case (2): + { + refine_flag = "cut_y"; + break; + } + case (3): + { + refine_flag = "cut_xy"; + break; + } + case (4): + { + refine_flag = "cut_z"; + break; + } + case (5): + { + refine_flag = "cut_xz"; + break; + } + case (6): + { + refine_flag = "cut_yz"; + break; + } + case (7): + { + refine_flag = "cut_xyz"; + break; + } + default: + { + AssertThrow(false, ExcMessage("Internal error.")); + } } return refine_flag; @@ -134,10 +134,11 @@ namespace python template - void set_coarsen_flag(const bool coarsen_flag, void *cell_accessor) + void + set_coarsen_flag(const bool coarsen_flag, void *cell_accessor) { - CellAccessor *cell = - static_cast*>(cell_accessor); + CellAccessor *cell = + static_cast *>(cell_accessor); if (coarsen_flag == true) cell->set_coarsen_flag(); else @@ -147,10 +148,11 @@ namespace python template - bool get_coarsen_flag(const void *cell_accessor) + bool + get_coarsen_flag(const void *cell_accessor) { - const CellAccessor *cell = - static_cast*>(cell_accessor); + const CellAccessor *cell = + static_cast *>(cell_accessor); return cell->coarsen_flag_set(); } @@ -158,13 +160,14 @@ namespace python template - PointWrapper get_barycenter(const void *cell_accessor) + PointWrapper + get_barycenter(const void *cell_accessor) { - const CellAccessor *cell = - static_cast*>(cell_accessor); - Point barycenter = cell->barycenter(); + const CellAccessor *cell = + static_cast *>(cell_accessor); + Point barycenter = cell->barycenter(); boost::python::list barycenter_list; - for (int i=0; i - void set_material_id(const int material_id, void *cell_accessor) + void + set_material_id(const int material_id, void *cell_accessor) { - CellAccessor *cell = - static_cast*>(cell_accessor); + CellAccessor *cell = + static_cast *>(cell_accessor); cell->set_material_id(material_id); } template - int get_material_id(const void *cell_accessor) + int + get_material_id(const void *cell_accessor) { - const CellAccessor *cell = - static_cast*>(cell_accessor); + const CellAccessor *cell = + static_cast *>(cell_accessor); return cell->material_id(); } @@ -194,14 +199,13 @@ namespace python template - void set_vertex(const int i, - PointWrapper &point_wrapper, - void *cell_accessor) + void + set_vertex(const int i, PointWrapper &point_wrapper, void *cell_accessor) { - CellAccessor *cell = - static_cast*>(cell_accessor); + CellAccessor *cell = + static_cast *>(cell_accessor); Point *point = - static_cast*>(point_wrapper.get_point()); + static_cast *>(point_wrapper.get_point()); cell->vertex(i) = *point; } @@ -209,14 +213,15 @@ namespace python template - PointWrapper get_vertex(const int i, const void *cell_accessor) + PointWrapper + get_vertex(const int i, const void *cell_accessor) { - const CellAccessor *cell = - static_cast*>(cell_accessor); + const CellAccessor *cell = + static_cast *>(cell_accessor); Point vertex = cell->vertex(i); boost::python::list coordinates; - for (int i=0; i - void set_manifold_id(const int manifold_id, void *cell_accessor) + void + set_manifold_id(const int manifold_id, void *cell_accessor) { - CellAccessor *cell = - static_cast*>(cell_accessor); + CellAccessor *cell = + static_cast *>(cell_accessor); cell->set_manifold_id(manifold_id); } template - int get_manifold_id(const void *cell_accessor) + int + get_manifold_id(const void *cell_accessor) { - const CellAccessor *cell = - static_cast*>(cell_accessor); + const CellAccessor *cell = + static_cast *>(cell_accessor); return cell->manifold_id(); } template - bool at_boundary(const void *cell_accessor) + bool + at_boundary(const void *cell_accessor) { - const CellAccessor *cell = - static_cast*>(cell_accessor); + const CellAccessor *cell = + static_cast *>(cell_accessor); return cell->at_boundary(); } template - bool has_boundary_lines(const void *cell_accessor) + bool + has_boundary_lines(const void *cell_accessor) { - const CellAccessor *cell = - static_cast*>(cell_accessor); + const CellAccessor *cell = + static_cast *>(cell_accessor); return cell->has_boundary_lines(); } template - const CellAccessor* neighbor(const int i, const void *cell_accessor) + const CellAccessor * + neighbor(const int i, const void *cell_accessor) { - const CellAccessor *cell = - static_cast*>(cell_accessor); + const CellAccessor *cell = + static_cast *>(cell_accessor); return cell->neighbor(i); } template - boost::python::list faces(const void *cell_accessor) + boost::python::list + faces(const void *cell_accessor) { - const CellAccessor *cell = - static_cast*>(cell_accessor); + const CellAccessor *cell = + static_cast *>(cell_accessor); boost::python::list faces_list; auto face_iterators = cell->face_iterators(); - for(auto &it : face_iterators) - { - TriaAccessor *face_accessor = new TriaAccessor(*it); - faces_list.append(TriaAccessorWrapper(face_accessor, dim - 1, dim, spacedim)); - } + for (auto &it : face_iterators) + { + TriaAccessor *face_accessor = + new TriaAccessor(*it); + faces_list.append( + TriaAccessorWrapper(face_accessor, dim - 1, dim, spacedim)); + } return faces_list; } - } + } // namespace internal CellAccessorWrapper::CellAccessorWrapper(const CellAccessorWrapper &other) - : - dim(other.dim), - spacedim(other.spacedim) + : dim(other.dim) + , spacedim(other.spacedim) { if ((dim == 2) && (spacedim == 2)) { - CellAccessor<2,2> *other_cell = - static_cast*>(other.cell_accessor); - cell_accessor = new CellAccessor<2,2>(*other_cell); + CellAccessor<2, 2> *other_cell = + static_cast *>(other.cell_accessor); + cell_accessor = new CellAccessor<2, 2>(*other_cell); } else if ((dim == 2) && (spacedim == 3)) { - CellAccessor<2,3> *other_cell = - static_cast*>(other.cell_accessor); - cell_accessor = new CellAccessor<2,3>(*other_cell); + CellAccessor<2, 3> *other_cell = + static_cast *>(other.cell_accessor); + cell_accessor = new CellAccessor<2, 3>(*other_cell); } else if ((dim == 3) && (spacedim == 3)) { - CellAccessor<3,3> *other_cell = - static_cast*>(other.cell_accessor); - cell_accessor = new CellAccessor<3,3>(*other_cell); + CellAccessor<3, 3> *other_cell = + static_cast *>(other.cell_accessor); + cell_accessor = new CellAccessor<3, 3>(*other_cell); } else AssertThrow(false, ExcMessage("Wrong dim-spacedim combination.")); @@ -325,38 +337,37 @@ namespace python CellAccessorWrapper::CellAccessorWrapper() - : - dim(0), - spacedim(0), - cell_accessor(nullptr) - { - } + : dim(0) + , spacedim(0) + , cell_accessor(nullptr) + {} - CellAccessorWrapper::CellAccessorWrapper(TriangulationWrapper &triangulation_wrapper, - const int level, - const int index) + CellAccessorWrapper::CellAccessorWrapper( + TriangulationWrapper &triangulation_wrapper, + const int level, + const int index) { - dim = triangulation_wrapper.get_dim(); + dim = triangulation_wrapper.get_dim(); spacedim = triangulation_wrapper.get_spacedim(); if ((dim == 2) && (spacedim == 2)) { - Triangulation<2,2> *tmp = static_cast*> ( - triangulation_wrapper.get_triangulation()); - cell_accessor = new CellAccessor<2,2>(tmp ,level, index); + Triangulation<2, 2> *tmp = static_cast *>( + triangulation_wrapper.get_triangulation()); + cell_accessor = new CellAccessor<2, 2>(tmp, level, index); } else if ((dim == 2) && (spacedim == 3)) { - Triangulation<2,3> *tmp = static_cast*> ( - triangulation_wrapper.get_triangulation()); - cell_accessor = new CellAccessor<2,3>(tmp, level, index); + Triangulation<2, 3> *tmp = static_cast *>( + triangulation_wrapper.get_triangulation()); + cell_accessor = new CellAccessor<2, 3>(tmp, level, index); } else if ((dim == 3) && (spacedim == 3)) { - Triangulation<3,3> *tmp = static_cast*> ( - triangulation_wrapper.get_triangulation()); - cell_accessor = new CellAccessor<3,3>(tmp, level, index); + Triangulation<3, 3> *tmp = static_cast *>( + triangulation_wrapper.get_triangulation()); + cell_accessor = new CellAccessor<3, 3>(tmp, level, index); } else AssertThrow(false, ExcMessage("Wrong dim-spacedim combination.")); @@ -370,204 +381,217 @@ namespace python { if ((dim == 2) && (spacedim == 2)) { - // We cannot call delete on a void pointer so cast the void pointer back - // first. - CellAccessor<2,2> *tmp = - static_cast*>(cell_accessor); + // We cannot call delete on a void pointer so cast the void pointer + // back first. + CellAccessor<2, 2> *tmp = + static_cast *>(cell_accessor); delete tmp; } else if ((dim == 2) && (spacedim == 3)) { - CellAccessor<2,3> *tmp = - static_cast*>(cell_accessor); + CellAccessor<2, 3> *tmp = + static_cast *>(cell_accessor); delete tmp; } else { - CellAccessor<3,3> *tmp = - static_cast*>(cell_accessor); + CellAccessor<3, 3> *tmp = + static_cast *>(cell_accessor); delete tmp; } - dim = -1; - spacedim = -1; + dim = -1; + spacedim = -1; cell_accessor = nullptr; } } - void CellAccessorWrapper::set_refine_flag(const std::string &refinement_case) + void + CellAccessorWrapper::set_refine_flag(const std::string &refinement_case) { if ((dim == 2) && (spacedim == 2)) - internal::set_refine_flag<2,2>(refinement_case, cell_accessor); + internal::set_refine_flag<2, 2>(refinement_case, cell_accessor); else if ((dim == 2) && (spacedim == 3)) - internal::set_refine_flag<2,3>(refinement_case, cell_accessor); + internal::set_refine_flag<2, 3>(refinement_case, cell_accessor); else - internal::set_refine_flag<3,3>(refinement_case, cell_accessor); + internal::set_refine_flag<3, 3>(refinement_case, cell_accessor); } - std::string CellAccessorWrapper::get_refine_flag() const + std::string + CellAccessorWrapper::get_refine_flag() const { if ((dim == 2) && (spacedim == 2)) - return internal::get_refine_flag<2,2>(cell_accessor); + return internal::get_refine_flag<2, 2>(cell_accessor); else if ((dim == 2) && (spacedim == 3)) - return internal::get_refine_flag<2,3>(cell_accessor); + return internal::get_refine_flag<2, 3>(cell_accessor); else - return internal::get_refine_flag<3,3>(cell_accessor); + return internal::get_refine_flag<3, 3>(cell_accessor); } - void CellAccessorWrapper::set_coarsen_flag(const bool coarsen_flag) + void + CellAccessorWrapper::set_coarsen_flag(const bool coarsen_flag) { if ((dim == 2) && (spacedim == 2)) - internal::set_coarsen_flag<2,2>(coarsen_flag, cell_accessor); + internal::set_coarsen_flag<2, 2>(coarsen_flag, cell_accessor); else if ((dim == 2) && (spacedim == 3)) - internal::set_coarsen_flag<2,3>(coarsen_flag, cell_accessor); + internal::set_coarsen_flag<2, 3>(coarsen_flag, cell_accessor); else - internal::set_coarsen_flag<3,3>(coarsen_flag, cell_accessor); + internal::set_coarsen_flag<3, 3>(coarsen_flag, cell_accessor); } - bool CellAccessorWrapper::get_coarsen_flag() const + bool + CellAccessorWrapper::get_coarsen_flag() const { if ((dim == 2) && (spacedim == 2)) - return internal::get_coarsen_flag<2,2>(cell_accessor); + return internal::get_coarsen_flag<2, 2>(cell_accessor); else if ((dim == 2) && (spacedim == 3)) - return internal::get_coarsen_flag<2,3>(cell_accessor); + return internal::get_coarsen_flag<2, 3>(cell_accessor); else - return internal::get_coarsen_flag<3,3>(cell_accessor); + return internal::get_coarsen_flag<3, 3>(cell_accessor); } - PointWrapper CellAccessorWrapper::get_barycenter() const + PointWrapper + CellAccessorWrapper::get_barycenter() const { if ((dim == 2) && (spacedim == 2)) - return internal::get_barycenter<2,2>(cell_accessor); + return internal::get_barycenter<2, 2>(cell_accessor); else if ((dim == 2) && (spacedim == 3)) - return internal::get_barycenter<2,3>(cell_accessor); + return internal::get_barycenter<2, 3>(cell_accessor); else - return internal::get_barycenter<3,3>(cell_accessor); + return internal::get_barycenter<3, 3>(cell_accessor); } - void CellAccessorWrapper::set_material_id(const int material_id) + void + CellAccessorWrapper::set_material_id(const int material_id) { - AssertThrow(static_cast(material_id) < numbers::invalid_material_id, + AssertThrow(static_cast(material_id) < + numbers::invalid_material_id, ExcMessage("material_id is too large.")); if ((dim == 2) && (spacedim == 2)) - return internal::set_material_id<2,2>(material_id, cell_accessor); + return internal::set_material_id<2, 2>(material_id, cell_accessor); else if ((dim == 2) && (spacedim == 3)) - return internal::set_material_id<2,3>(material_id, cell_accessor); + return internal::set_material_id<2, 3>(material_id, cell_accessor); else - return internal::set_material_id<3,3>(material_id, cell_accessor); + return internal::set_material_id<3, 3>(material_id, cell_accessor); } - int CellAccessorWrapper::get_material_id() const + int + CellAccessorWrapper::get_material_id() const { if ((dim == 2) && (spacedim == 2)) - return internal::get_material_id<2,2>(cell_accessor); + return internal::get_material_id<2, 2>(cell_accessor); else if ((dim == 2) && (spacedim == 3)) - return internal::get_material_id<2,3>(cell_accessor); + return internal::get_material_id<2, 3>(cell_accessor); else - return internal::get_material_id<3,3>(cell_accessor); + return internal::get_material_id<3, 3>(cell_accessor); } - void CellAccessorWrapper::set_vertex(const int i, - PointWrapper &point_wrapper) + void + CellAccessorWrapper::set_vertex(const int i, PointWrapper &point_wrapper) { - AssertThrow(i(i, point_wrapper, cell_accessor); + internal::set_vertex<2, 2>(i, point_wrapper, cell_accessor); else if ((dim == 2) && (spacedim == 3)) - internal::set_vertex<2,3>(i, point_wrapper, cell_accessor); + internal::set_vertex<2, 3>(i, point_wrapper, cell_accessor); else - internal::set_vertex<3,3>(i, point_wrapper, cell_accessor); + internal::set_vertex<3, 3>(i, point_wrapper, cell_accessor); } - PointWrapper CellAccessorWrapper::get_vertex(const int i) const + PointWrapper + CellAccessorWrapper::get_vertex(const int i) const { - AssertThrow(i(i, cell_accessor); + return internal::get_vertex<2, 2>(i, cell_accessor); else if ((dim == 2) && (spacedim == 3)) - return internal::get_vertex<2,3>(i, cell_accessor); + return internal::get_vertex<2, 3>(i, cell_accessor); else - return internal::get_vertex<3,3>(i, cell_accessor); + return internal::get_vertex<3, 3>(i, cell_accessor); } - void CellAccessorWrapper::set_manifold_id(const int manifold_id) + void + CellAccessorWrapper::set_manifold_id(const int manifold_id) { if ((dim == 2) && (spacedim == 2)) - internal::set_manifold_id<2,2>(manifold_id, cell_accessor); + internal::set_manifold_id<2, 2>(manifold_id, cell_accessor); else if ((dim == 2) && (spacedim == 3)) - internal::set_manifold_id<2,3>(manifold_id, cell_accessor); + internal::set_manifold_id<2, 3>(manifold_id, cell_accessor); else - internal::set_manifold_id<3,3>(manifold_id, cell_accessor); + internal::set_manifold_id<3, 3>(manifold_id, cell_accessor); } - int CellAccessorWrapper::get_manifold_id() const + int + CellAccessorWrapper::get_manifold_id() const { if ((dim == 2) && (spacedim == 2)) - return internal::get_manifold_id<2,2>(cell_accessor); - else if ((dim== 2) && (spacedim == 3)) - return internal::get_manifold_id<2,3>(cell_accessor); + return internal::get_manifold_id<2, 2>(cell_accessor); + else if ((dim == 2) && (spacedim == 3)) + return internal::get_manifold_id<2, 3>(cell_accessor); else - return internal::get_manifold_id<3,3>(cell_accessor); + return internal::get_manifold_id<3, 3>(cell_accessor); } - bool CellAccessorWrapper::at_boundary() const + bool + CellAccessorWrapper::at_boundary() const { if ((dim == 2) && (spacedim == 2)) - return internal::at_boundary<2,2>(cell_accessor); - else if ((dim== 2) && (spacedim == 3)) - return internal::at_boundary<2,3>(cell_accessor); + return internal::at_boundary<2, 2>(cell_accessor); + else if ((dim == 2) && (spacedim == 3)) + return internal::at_boundary<2, 3>(cell_accessor); else - return internal::at_boundary<3,3>(cell_accessor); + return internal::at_boundary<3, 3>(cell_accessor); } - bool CellAccessorWrapper::has_boundary_lines() const + bool + CellAccessorWrapper::has_boundary_lines() const { if ((dim == 2) && (spacedim == 2)) - return internal::has_boundary_lines<2,2>(cell_accessor); - else if ((dim== 2) && (spacedim == 3)) - return internal::has_boundary_lines<2,3>(cell_accessor); + return internal::has_boundary_lines<2, 2>(cell_accessor); + else if ((dim == 2) && (spacedim == 3)) + return internal::has_boundary_lines<2, 3>(cell_accessor); else - return internal::has_boundary_lines<3,3>(cell_accessor); + return internal::has_boundary_lines<3, 3>(cell_accessor); } - CellAccessorWrapper CellAccessorWrapper::neighbor(const int i) const + CellAccessorWrapper + CellAccessorWrapper::neighbor(const int i) const { - AssertThrow(i<(2*dim), - ExcNeighborDoesNotExist(i, 2*dim)); + AssertThrow(i < (2 * dim), ExcNeighborDoesNotExist(i, 2 * dim)); if ((dim == 2) && (spacedim == 2)) return construct_neighbor_wrapper<2, 2>(i); - else if ((dim== 2) && (spacedim == 3)) + else if ((dim == 2) && (spacedim == 3)) return construct_neighbor_wrapper<2, 3>(i); else return construct_neighbor_wrapper<3, 3>(i); @@ -575,16 +599,17 @@ namespace python - boost::python::list CellAccessorWrapper::faces() const + boost::python::list + CellAccessorWrapper::faces() const { if ((dim == 2) && (spacedim == 2)) return internal::faces<2, 2>(cell_accessor); - else if ((dim== 2) && (spacedim == 3)) + else if ((dim == 2) && (spacedim == 3)) return internal::faces<2, 3>(cell_accessor); else return internal::faces<3, 3>(cell_accessor); } -} +} // namespace python DEAL_II_NAMESPACE_CLOSE diff --git a/contrib/python-bindings/source/export_cell_accessor.cc b/contrib/python-bindings/source/export_cell_accessor.cc index 809ea64c5e..9235bdcbdd 100644 --- a/contrib/python-bindings/source/export_cell_accessor.cc +++ b/contrib/python-bindings/source/export_cell_accessor.cc @@ -13,15 +13,16 @@ // // --------------------------------------------------------------------- +#include + #include #include -#include DEAL_II_NAMESPACE_OPEN namespace python { - const char refine_flag_docstring [] = + const char refine_flag_docstring[] = "Get/Set the refine_flag of the cell. In 2D, the possibilities are: \n" " - isotropic \n" " - no_refinement \n" @@ -37,114 +38,116 @@ namespace python " - cut_xy \n" " - cut_xz \n" " - cut_yz \n" - " - cut_xyz \n" - ; + " - cut_xyz \n"; - const char coarsen_flag_docstring [] = - "Get/Set the coarsen_flag of the cell \n" - ; + const char coarsen_flag_docstring[] = + "Get/Set the coarsen_flag of the cell \n"; - const char material_id_docstring [] = - "Get/Set the material_id of the cell \n" - ; + const char material_id_docstring[] = + "Get/Set the material_id of the cell \n"; - const char manifold_id_docstring [] = - "Get/Set the manifold_id of the cell \n" - ; + const char manifold_id_docstring[] = + "Get/Set the manifold_id of the cell \n"; - const char barycenter_docstring [] = - "Return the barycenter of the current cell \n" - ; + const char barycenter_docstring[] = + "Return the barycenter of the current cell \n"; - const char set_vertex_docstring [] = - " Set the ith vertex of the cell to point_wrapper \n" - ; + const char set_vertex_docstring[] = + " Set the ith vertex of the cell to point_wrapper \n"; - const char get_vertex_docstring [] = - " Get the ith vertex of the cell \n" - ; + const char get_vertex_docstring[] = + " Get the ith vertex of the cell \n"; - const char at_boundary_docstring [] = - " Return whether the cell is at the boundary \n" - ; + const char at_boundary_docstring[] = + " Return whether the cell is at the boundary \n"; - const char has_boundary_lines_docstring [] = + const char has_boundary_lines_docstring[] = " This is a slight variation to the at_boundary function: \n" " for two dimensions, it is equivalent, for three \n" - " dimensions it returns whether at least one of the 12 \n" - " lines of the hexahedron is at a boundary. \n" - ; + " dimensions it returns whether at least one of the 12 \n" + " lines of the hexahedron is at a boundary. \n"; - const char neighbor_docstring [] = - " Return the ith neighbor of a cell. If the neighbor does not exist,\n" - " i.e., if the ith face of the current object is at the boundary, \n" - " then an exception is thrown. \n" - ; + const char neighbor_docstring[] = + " Return the ith neighbor of a cell. If the neighbor does not exist,\n" + " i.e., if the ith face of the current object is at the boundary, \n" + " then an exception is thrown. \n"; - const char faces_docstring [] = - " Return list of cell's faces. \n" - ; + const char faces_docstring[] = + " Return list of cell's faces. \n"; - void export_cell_accessor() + void + export_cell_accessor() { - boost::python::class_("CellAccessor", - boost::python::init ()) - .add_property("refine_flag", &CellAccessorWrapper::get_refine_flag, - &CellAccessorWrapper::set_refine_flag, - refine_flag_docstring) - .add_property("coarsen_flag", &CellAccessorWrapper::get_coarsen_flag, - &CellAccessorWrapper::set_coarsen_flag, - coarsen_flag_docstring) - .add_property("material_id", &CellAccessorWrapper::get_material_id, - &CellAccessorWrapper::set_material_id, - material_id_docstring) - .add_property("manifold_id", &CellAccessorWrapper::get_manifold_id, - &CellAccessorWrapper::set_manifold_id, - manifold_id_docstring) - .def("barycenter", &CellAccessorWrapper::get_barycenter, - barycenter_docstring, - boost::python::args("self")) - .def("set_vertex", &CellAccessorWrapper::set_vertex, - set_vertex_docstring, - boost::python::args("self", "i", "point_wrapper")) - .def("get_vertex", &CellAccessorWrapper::get_vertex, - get_vertex_docstring, - boost::python::args("self", "i")) - .def("at_boundary", &CellAccessorWrapper::at_boundary, - at_boundary_docstring, - boost::python::args("self")) - .def("has_boundary_lines", &CellAccessorWrapper::has_boundary_lines, - has_boundary_lines_docstring, - boost::python::args("self")) - .def("neighbor", &CellAccessorWrapper::neighbor, - neighbor_docstring, - boost::python::args("self", "i")) - .def("faces", &CellAccessorWrapper::faces, - faces_docstring, - boost::python::args("self")); + boost::python::class_( + "CellAccessor", + boost::python::init()) + .add_property("refine_flag", + &CellAccessorWrapper::get_refine_flag, + &CellAccessorWrapper::set_refine_flag, + refine_flag_docstring) + .add_property("coarsen_flag", + &CellAccessorWrapper::get_coarsen_flag, + &CellAccessorWrapper::set_coarsen_flag, + coarsen_flag_docstring) + .add_property("material_id", + &CellAccessorWrapper::get_material_id, + &CellAccessorWrapper::set_material_id, + material_id_docstring) + .add_property("manifold_id", + &CellAccessorWrapper::get_manifold_id, + &CellAccessorWrapper::set_manifold_id, + manifold_id_docstring) + .def("barycenter", + &CellAccessorWrapper::get_barycenter, + barycenter_docstring, + boost::python::args("self")) + .def("set_vertex", + &CellAccessorWrapper::set_vertex, + set_vertex_docstring, + boost::python::args("self", "i", "point_wrapper")) + .def("get_vertex", + &CellAccessorWrapper::get_vertex, + get_vertex_docstring, + boost::python::args("self", "i")) + .def("at_boundary", + &CellAccessorWrapper::at_boundary, + at_boundary_docstring, + boost::python::args("self")) + .def("has_boundary_lines", + &CellAccessorWrapper::has_boundary_lines, + has_boundary_lines_docstring, + boost::python::args("self")) + .def("neighbor", + &CellAccessorWrapper::neighbor, + neighbor_docstring, + boost::python::args("self", "i")) + .def("faces", + &CellAccessorWrapper::faces, + faces_docstring, + boost::python::args("self")); } -} +} // namespace python DEAL_II_NAMESPACE_CLOSE diff --git a/contrib/python-bindings/source/export_point.cc b/contrib/python-bindings/source/export_point.cc index 6a005b94a6..a790c03d96 100644 --- a/contrib/python-bindings/source/export_point.cc +++ b/contrib/python-bindings/source/export_point.cc @@ -13,81 +13,89 @@ // // --------------------------------------------------------------------- -#include - -#include #include +#include + #include +#include + DEAL_II_NAMESPACE_OPEN namespace python { - const char distance_docstring [] = - "Return the Euclidean distance of this point to the point p \n" - ; + const char distance_docstring[] = + "Return the Euclidean distance of this point to the point p \n"; - const char norm_docstring [] = - "Return the L2 norm of the vector connecting the origin to the point \n" - ; + const char norm_docstring[] = + "Return the L2 norm of the vector connecting the origin to the point \n"; - const char norm_square_docstring [] = - "Return the sum of the absolute squares of all entries \n" - ; + const char norm_square_docstring[] = + "Return the sum of the absolute squares of all entries \n"; - const char get_x_docstring [] = - "Get the x component of the point \n" - ; + const char get_x_docstring[] = + "Get the x component of the point \n"; - const char get_y_docstring [] = - "Get the y component of the point \n" - ; + const char get_y_docstring[] = + "Get the y component of the point \n"; - const char get_z_docstring [] = - "Get the z component of the point \n" - ; + const char get_z_docstring[] = + "Get the z component of the point \n"; - void export_point() + void + export_point() { - boost::python::class_ ("Point", - boost::python::init()) - .def("distance", &PointWrapper::distance, distance_docstring, - boost::python::args("self", "p")) - .def("norm", &PointWrapper::norm, norm_docstring, - boost::python::args("self")) - .def("norm_square", &PointWrapper::norm_square, norm_square_docstring, - boost::python::args("self")) - .def(boost::python::self != boost::python::self) - .def(boost::python::self == boost::python::self) - .def(boost::python::self * boost::python::self) - .def(boost::python::self + boost::python::self) - .def(boost::python::self - boost::python::self) - .def(- boost::python::self) - .def(boost::python::self / float()) - .def(boost::python::self * float()) - .def(boost::python::self += boost::python::self) - .def(boost::python::self -= boost::python::self) - .def(boost::python::self *= float()) - .def(boost::python::self /= float()) - .add_property("x", &PointWrapper::get_x, &PointWrapper::set_x, - get_x_docstring) - .add_property("y", &PointWrapper::get_y, &PointWrapper::set_y, - get_y_docstring) - .add_property("z", &PointWrapper::get_z, &PointWrapper::set_z, - get_z_docstring); + boost::python::class_( + "Point", boost::python::init()) + .def("distance", + &PointWrapper::distance, + distance_docstring, + boost::python::args("self", "p")) + .def("norm", + &PointWrapper::norm, + norm_docstring, + boost::python::args("self")) + .def("norm_square", + &PointWrapper::norm_square, + norm_square_docstring, + boost::python::args("self")) + .def(boost::python::self != boost::python::self) + .def(boost::python::self == boost::python::self) + .def(boost::python::self * boost::python::self) + .def(boost::python::self + boost::python::self) + .def(boost::python::self - boost::python::self) + .def(-boost::python::self) + .def(boost::python::self / float()) + .def(boost::python::self * float()) + .def(boost::python::self += boost::python::self) + .def(boost::python::self -= boost::python::self) + .def(boost::python::self *= float()) + .def(boost::python::self /= float()) + .add_property("x", + &PointWrapper::get_x, + &PointWrapper::set_x, + get_x_docstring) + .add_property("y", + &PointWrapper::get_y, + &PointWrapper::set_y, + get_y_docstring) + .add_property("z", + &PointWrapper::get_z, + &PointWrapper::set_z, + get_z_docstring); } -} +} // namespace python DEAL_II_NAMESPACE_CLOSE diff --git a/contrib/python-bindings/source/export_tria_accessor.cc b/contrib/python-bindings/source/export_tria_accessor.cc index fcb7c680bb..237aa481c2 100644 --- a/contrib/python-bindings/source/export_tria_accessor.cc +++ b/contrib/python-bindings/source/export_tria_accessor.cc @@ -13,69 +13,72 @@ // // --------------------------------------------------------------------- +#include + #include #include -#include DEAL_II_NAMESPACE_OPEN namespace python { - const char manifold_id_docstring [] = - "Get/Set the manifold_id of the face \n" - ; + const char manifold_id_docstring[] = + "Get/Set the manifold_id of the face \n"; - const char boundary_id_docstring [] = - "Get/Set the boundary_id of the face \n" - ; + const char boundary_id_docstring[] = + "Get/Set the boundary_id of the face \n"; - const char set_all_boundary_ids_docstring [] = + const char set_all_boundary_ids_docstring[] = "Do as set_boundary_id() but also set the boundary indicators \n" - "of the objects that bound the current object. \n" - ; + "of the objects that bound the current object. \n"; - const char barycenter_docstring [] = - "Return the barycenter of the current face \n" - ; + const char barycenter_docstring[] = + "Return the barycenter of the current face \n"; - const char set_vertex_docstring [] = - " Set the ith vertex of the face to point_wrapper \n" - ; + const char set_vertex_docstring[] = + " Set the ith vertex of the face to point_wrapper \n"; - const char get_vertex_docstring [] = - " Get the ith vertex of the face \n" - ; + const char get_vertex_docstring[] = + " Get the ith vertex of the face \n"; - const char at_boundary_docstring [] = - " Return whether the face is at the boundary \n" - ; + const char at_boundary_docstring[] = + " Return whether the face is at the boundary \n"; - void export_tria_accessor() + void + export_tria_accessor() { - boost::python::class_("TriaAccessor", - boost::python::init ()) - .add_property("boundary_id", &TriaAccessorWrapper::get_boundary_id, - &TriaAccessorWrapper::set_boundary_id, - boundary_id_docstring) - .add_property("manifold_id", &TriaAccessorWrapper::get_manifold_id, - &TriaAccessorWrapper::set_manifold_id, - manifold_id_docstring) - .def("barycenter", &TriaAccessorWrapper::get_barycenter, - barycenter_docstring, - boost::python::args("self")) - .def("set_vertex", &TriaAccessorWrapper::set_vertex, - set_vertex_docstring, - boost::python::args("self", "i", "point_wrapper")) - .def("get_vertex", &TriaAccessorWrapper::get_vertex, - get_vertex_docstring, - boost::python::args("self", "i")) - .def("at_boundary", &TriaAccessorWrapper::at_boundary, - at_boundary_docstring, - boost::python::args("self")) - .def("set_all_boundary_ids", &TriaAccessorWrapper::set_all_boundary_ids, - set_all_boundary_ids_docstring, - boost::python::args("self", "boundary_id")); + boost::python::class_( + "TriaAccessor", + boost::python::init()) + .add_property("boundary_id", + &TriaAccessorWrapper::get_boundary_id, + &TriaAccessorWrapper::set_boundary_id, + boundary_id_docstring) + .add_property("manifold_id", + &TriaAccessorWrapper::get_manifold_id, + &TriaAccessorWrapper::set_manifold_id, + manifold_id_docstring) + .def("barycenter", + &TriaAccessorWrapper::get_barycenter, + barycenter_docstring, + boost::python::args("self")) + .def("set_vertex", + &TriaAccessorWrapper::set_vertex, + set_vertex_docstring, + boost::python::args("self", "i", "point_wrapper")) + .def("get_vertex", + &TriaAccessorWrapper::get_vertex, + get_vertex_docstring, + boost::python::args("self", "i")) + .def("at_boundary", + &TriaAccessorWrapper::at_boundary, + at_boundary_docstring, + boost::python::args("self")) + .def("set_all_boundary_ids", + &TriaAccessorWrapper::set_all_boundary_ids, + set_all_boundary_ids_docstring, + boost::python::args("self", "boundary_id")); } -} +} // namespace python DEAL_II_NAMESPACE_CLOSE diff --git a/contrib/python-bindings/source/export_triangulation.cc b/contrib/python-bindings/source/export_triangulation.cc index 04beed6599..ed38b6f58f 100644 --- a/contrib/python-bindings/source/export_triangulation.cc +++ b/contrib/python-bindings/source/export_triangulation.cc @@ -13,126 +13,155 @@ // // --------------------------------------------------------------------- -#include -#include #include +#include +#include + DEAL_II_NAMESPACE_OPEN namespace python { - -// Macro to enable default arguments + // Macro to enable default arguments BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_hyper_cube_overloads, - generate_hyper_cube, 0, 3) - BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_subdivided_hyper_cube_overloads, - generate_subdivided_hyper_cube, 1, 3) + generate_hyper_cube, + 0, + 3) + BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( + generate_subdivided_hyper_cube_overloads, + generate_subdivided_hyper_cube, + 1, + 3) BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_hyper_rectangle_overloads, - generate_hyper_rectangle, 2, 3) - BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_subdivided_hyper_rectangle_overloads, - generate_subdivided_hyper_rectangle, 3, 4) - BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_subdivided_steps_hyper_rectangle_overloads, - generate_subdivided_steps_hyper_rectangle, 3, 4) - BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_subdivided_material_hyper_rectangle_overloads, - generate_subdivided_material_hyper_rectangle, 3, 4) + generate_hyper_rectangle, + 2, + 3) + BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( + generate_subdivided_hyper_rectangle_overloads, + generate_subdivided_hyper_rectangle, + 3, + 4) + BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( + generate_subdivided_steps_hyper_rectangle_overloads, + generate_subdivided_steps_hyper_rectangle, + 3, + 4) + BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( + generate_subdivided_material_hyper_rectangle_overloads, + generate_subdivided_material_hyper_rectangle, + 3, + 4) BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_general_cell_overloads, - generate_general_cell, 1, 2) + generate_general_cell, + 1, + 2) BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_parallelogram_overloads, - generate_parallelogram, 1, 2) + generate_parallelogram, + 1, + 2) BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_parallelepiped_overloads, - generate_parallelepiped, 1, 2) - BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_fixed_subdivided_parallelepiped_overloads, - generate_fixed_subdivided_parallelepiped, 2, 3) - BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_varying_subdivided_parallelepiped_overloads, - generate_varying_subdivided_parallelepiped, 2, 3) + generate_parallelepiped, + 1, + 2) + BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( + generate_fixed_subdivided_parallelepiped_overloads, + generate_fixed_subdivided_parallelepiped, + 2, + 3) + BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( + generate_varying_subdivided_parallelepiped_overloads, + generate_varying_subdivided_parallelepiped, + 2, + 3) BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_enclosed_hyper_cube_overloads, - generate_enclosed_hyper_cube, 0, 4) + generate_enclosed_hyper_cube, + 0, + 4) BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_hyper_ball_overloads, - generate_hyper_ball, 1, 2) + generate_hyper_ball, + 1, + 2) BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_hyper_sphere_overloads, - generate_hyper_sphere, 1, 2) + generate_hyper_sphere, + 1, + 2) BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_quarter_hyper_ball_overloads, - generate_quarter_hyper_ball, 1, 2) + generate_quarter_hyper_ball, + 1, + 2) BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_half_hyper_ball_overloads, - generate_half_hyper_ball, 1, 2) + generate_half_hyper_ball, + 1, + 2) - const char n_active_cells_docstring [] = - "Return the number of active cells \n" - ; + const char n_active_cells_docstring[] = + "Return the number of active cells \n"; - const char generate_hyper_cube_docstring [] = + const char generate_hyper_cube_docstring[] = "Generate a hyper_cube (square in 2D and cube in 3D) \n" - "with exactly one cell \n" - ; + "with exactly one cell \n"; - const char generate_simplex_docstring [] = - "Generate a simplex with (dim+1) vertices and mesh cells \n" - ; + const char generate_simplex_docstring[] = + "Generate a simplex with (dim+1) vertices and mesh cells \n"; - const char generate_subdivided_hyper_cube_docstring [] = + const char generate_subdivided_hyper_cube_docstring[] = "Same as hyper_cube but not only one cell is created but each \n" - "coordinate direction is subdivided in repetitions cells \n" - ; + "coordinate direction is subdivided in repetitions cells \n"; - const char generate_hyper_rectangle_docstring [] = + const char generate_hyper_rectangle_docstring[] = "Generate a coordinate-parallel brick from the two diagonally opposite \n" - "corners points p1 and p2 \n" - ; + "corners points p1 and p2 \n"; - const char generate_subdivided_hyper_rectangle_docstring [] = + const char generate_subdivided_hyper_rectangle_docstring[] = "Generate a coordinate-parallel brick from the two diagonally opposite \n" "corners point p1 and p2. In direction i, repetitions[i] cells are \n" - "created \n" - ; + "created \n"; - const char generate_subdivided_steps_hyper_rectangle_docstring [] = + const char generate_subdivided_steps_hyper_rectangle_docstring[] = "Like the previous function. However, here the first argument does not \n" "denote the number of subdivisions in each coordinate direction, but a \n" "sequence of step sizes for each coordinate direction. This function is \n" "therefore the right one to generate graded meshes where cells are \n" "concentrated in certains areas, rather than a uniformly subdidived mesh\n" - "as the previous function generates. \n" - ; + "as the previous function generates. \n"; - const char generate_subdivided_material_hyper_rectangle_docstring [] = + const char generate_subdivided_material_hyper_rectangle_docstring[] = "Like the previous function, but with the following twist: the \n" "material_id argument is a dim-dimensional array that, for each cell, \n" "indicates which material_id should be set. In addition, and this is the\n" "major new functionality, if the material_id of a cell is (-1), then \n" "that cell is deleted from the triangulation, i.e. the domain will have \n" - "a void there. \n" - ; + "a void there. \n"; - const char generate_cheese_docstring [] = + const char generate_cheese_docstring[] = "Rectangular domain with rectangular pattern of holes. The domain itself\n" "is rectangular, very much as if it had been generated by \n" "subdivided_hyper_rectangle(). The argument holes specifies how many \n" "square holes the domain should have in each coordinate direction. The \n" "total number of mesh cells in that direction is then this number plus \n" - "one. The number of holes in one direction must be at least one. \n" - ; + "one. The number of holes in one direction must be at least one. \n"; - const char generate_general_cell_docstring [] = + const char generate_general_cell_docstring[] = "A general quadrilateral in 2d or a general hexahedron in 3d. It is the \n" "responsibility of the user to provide the vertices in the right order \n" "(see the documentation of the GeometryInfo class) because the vertices \n" @@ -140,22 +169,20 @@ namespace python "make that the volume of the cell is positive. If the argument \n" "colorize is false, all boundary indicators are set to zero (not \n" "colorized) for 2d and 3d. If it is true, the boundary is colorized as \n" - "in hyper_rectangle(). In 1d, the indicators are always colorized. \n" - ; + "in hyper_rectangle(). In 1d, the indicators are always colorized. \n"; - const char generate_parallelogram_docstring [] = + const char generate_parallelogram_docstring[] = "A parallelogram. The first corner point is the origin. The dim \n" "adjacent points are the ones given in the second argument and the \n" "fourth point will be the sum of these two vectors. Colorizing is done \n" "in the same way as in hyper_rectangle(). \n" - "Note: This function is implemented in 2d only. \n" - ; + "Note: This function is implemented in 2d only. \n"; - const char generate_parallelepiped_docstring [] = + const char generate_parallelepiped_docstring[] = "A parallelepiped. The first corner point is the origin. The dim \n" "adjacent points are vectors describing the edges of the parallelepiped \n" "with respect to the origin. Additional points are sums of these dim \n" @@ -164,98 +191,88 @@ namespace python "lexicographic ordering (see GridReordering::reoder_grid()). In other \n" "words, if reordering of the vertices does occur, the ordering of \n" "vertices in the array of corners will no longer refer to the same \n" - "triangulation. \n" - ; + "triangulation. \n"; - const char generate_fixed_subdivided_parallelepiped_docstring [] = + const char generate_fixed_subdivided_parallelepiped_docstring[] = "A subdivided parallelepiped. The first corner point is the origin. The \n" "dim adjacent points are vectors describing the edges of the \n" "parallelepiped with respect to the origin. Additional points are sums \n" "of these dim vectors. The variable n_subdivisions designates the number\n" "of subdivisions in each of the dim directions. Colorizing is odne \n" - "according to hyper_rectangle(). \n" - ; + "according to hyper_rectangle(). \n"; - const char generate_varying_subdivided_parallelepiped_docstring [] = + const char generate_varying_subdivided_parallelepiped_docstring[] = "A subdivided parallelepided, i.e., the same as above, but where the \n" "number of subdivisions in each of the dim directions may vary. \n" - "Colorizing is done according to hyper_rectangle(). \n" - ; + "Colorizing is done according to hyper_rectangle(). \n"; - const char generate_enclosed_hyper_cube_docstring [] = + const char generate_enclosed_hyper_cube_docstring[] = "Hypercube with a layer of hypercubes around it. The first two \n" "parameters give the lower and upper bound of the inner hypercube in all\n" "coordinate directions. thickness marks the size of the layer cells. If \n" "the flag colorize is set, the outer cells get material id's according \n" "to the following scheme: extending over the inner cube (+/-) \n" "x-direction: 1/2. In y-direction 4/8, in z-direction 16/32. The cells i\n" - "at corners and edges (3d) get these values bitwise or'd. \n" - ; + "at corners and edges (3d) get these values bitwise or'd. \n"; - const char generate_hyper_ball_docstring [] = + const char generate_hyper_ball_docstring[] = "Generate a hyperball, i.e. a circle or a ball around center with \n" "given radius. In order to avoid degenerate cells at the boundaries, \n" "the circle is triangulated by five cells, the ball by seven cells. The \n" "diameter of the center cell is chosen so that the aspect ratio of the \n" "boundary cells after one refinement is optimized. You should attach a \n" "SphericalManifold to the cells and faces for correct placement of \n" - "vertices upon refinement and to be able to use higher order mappings. \n" - ; + "vertices upon refinement and to be able to use higher order mappings. \n"; - const char generate_hyper_sphere_docstring [] = + const char generate_hyper_sphere_docstring[] = "Generate a hyper sphere, i.e., a surface of a ball in spacedim \n" "dimensions. This function only exists for dim+1=spacedim in 2 and 3 \n" "space dimensions. You should attach a SphericalManifold to the cells \n" "and faces for correct placement of vertices upon refinement and to be \n" - "able to use higher order mappings. \n" - ; + "able to use higher order mappings. \n"; - const char generate_quarter_hyper_ball_docstring [] = + const char generate_quarter_hyper_ball_docstring[] = "Generate a hyper-ball intersected with the positive orthant relate to \n" "center, which contains three elements in 2d and four in 3d. The \n" "boundary indicators for the final triangulations are 0 for the curved \n" "boundary and 1 for the cut plane. The appropriate Manifold class is \n" - "SphericalManifold. \n" - ; + "SphericalManifold. \n"; - const char generate_half_hyper_ball_docstring [] = + 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" "x-axis. The boundary indicators for the final triangulation are 0 for \n" "the curved boundary and 1 for the cut plane. The appropriate manifold \n" - "class is SphericalManifold. \n" - ; + "class is SphericalManifold. \n"; - const char shift_docstring [] = - "Shift every vertex of the Triangulation by the given shift vector \n" - ; + const char shift_docstring[] = + "Shift every vertex of the Triangulation by the given shift vector \n"; - const char merge_docstring [] = + const char merge_docstring[] = "Given two triangulations, create the triangulation that contains \n" - "the cells of both triangulations \n" - ; + "the cells of both triangulations \n"; - const char flatten_triangulation_docstring [] = + const char flatten_triangulation_docstring[] = "Create a new flat triangulation out_tria which contains a single \n" "level with all active cells of the input triangulation. If the spacedim\n" "are different, only the smalled spacedim components of the vertices are\n" @@ -271,29 +288,25 @@ namespace python "faces of the triangulation to the faces of out_tria. If you need to \n" "specify manifold ids on interior faces, they have to be specified \n" "manually after the triangulation is created. This function will fail \n" - "if the input Triangulation contains hanging nodes. \n" - ; + "if the input Triangulation contains hanging nodes. \n"; - const char refine_global_docstring [] = - "Refine all the cells times time \n" - ; + const char refine_global_docstring[] = + "Refine all the cells times time \n"; - const char execute_coarsening_and_refinement_docstring [] = - "Execute both refinement and coarsening of the Triangulation \n" - ; + const char execute_coarsening_and_refinement_docstring[] = + "Execute both refinement and coarsening of the Triangulation \n"; - const char active_cells_docstring [] = - "Return the list of active cell accessors of the Triangulation \n" - ; + const char active_cells_docstring[] = + "Return the list of active cell accessors of the Triangulation \n"; - const char write_docstring [] = + const char write_docstring[] = "Write the mesh to the output file according to the given data format. \n" "The possible formats are: \n" " - none \n" @@ -306,164 +319,159 @@ namespace python " - svg \n" " - mathgl \n" " - vtk \n" - " - vtu \n" - ; - + " - vtu \n"; - const char save_docstring [] = - "Write the Triangulation to a file \n" - ; + const char save_docstring[] = + "Write the Triangulation to a file \n"; - const char load_docstring [] = - "Load the Triangulation from a file \n" - ; + const char load_docstring[] = + "Load the Triangulation from a file \n"; - void export_triangulation() + void + export_triangulation() { - boost::python::class_("Triangulation", - boost::python::init()) - .def(boost::python::init()) - .def("n_active_cells", - &TriangulationWrapper::n_active_cells, - n_active_cells_docstring, - boost::python::args("self")) - .def("generate_hyper_cube", - &TriangulationWrapper::generate_hyper_cube, - generate_hyper_cube_overloads( - boost::python::args("self", "left", "right", "colorize"), - generate_hyper_cube_docstring)) - .def("generate_simplex", - &TriangulationWrapper::generate_simplex, - generate_simplex_docstring, - boost::python::args("self", "vertices")) - .def("generate_subdivided_hyper_cube", - &TriangulationWrapper::generate_subdivided_hyper_cube, - generate_subdivided_hyper_cube_overloads( - boost::python::args("self", "repetitions", "left", "right"), - generate_subdivided_hyper_cube_docstring)) - .def("generate_hyper_rectangle", - &TriangulationWrapper::generate_hyper_rectangle, - generate_hyper_rectangle_overloads( - boost::python::args("self", "p1", "p2", "colorize"), - generate_hyper_rectangle_docstring)) - .def("generate_subdivided_hyper_rectangle", - &TriangulationWrapper::generate_subdivided_hyper_rectangle, - generate_subdivided_hyper_rectangle_overloads( - boost::python::args("self", "repetitions", - "p1", "p2", "colorize"), - generate_subdivided_hyper_rectangle_docstring)) - .def("generate_subdivided_steps_hyper_rectangle", - &TriangulationWrapper::generate_subdivided_steps_hyper_rectangle, - generate_subdivided_steps_hyper_rectangle_overloads( - boost::python::args("self", "step_sizes", - "p1", "p2", "colorize"), - generate_subdivided_steps_hyper_rectangle_docstring)) - .def("generate_subdivided_material_hyper_rectangle", - &TriangulationWrapper::generate_subdivided_material_hyper_rectangle, - generate_subdivided_material_hyper_rectangle_overloads( - boost::python::args("self", "spacing", "p", - "material_id", "colorize"), - generate_subdivided_material_hyper_rectangle_docstring)) - .def("generate_cheese", - &TriangulationWrapper::generate_cheese, - generate_cheese_docstring, - boost::python::args("self", "holes")) - .def("generate_general_cell", - &TriangulationWrapper::generate_general_cell, - generate_general_cell_overloads( - boost::python::args("self", "vertices", "colorize"), - generate_general_cell_docstring)) - .def("generate_parallelogram", - &TriangulationWrapper::generate_parallelogram, - generate_parallelogram_overloads( - boost::python::args("self", "corners", "colorize"), - generate_parallelogram_docstring)) - .def("generate_parallelepiped", - &TriangulationWrapper::generate_parallelepiped, - generate_parallelepiped_overloads( - boost::python::args("self", "corners", "colorize"), - generate_parallelepiped_docstring)) - .def("generate_fixed_subdivided_parallelepiped", - &TriangulationWrapper::generate_fixed_subdivided_parallelepiped, - generate_fixed_subdivided_parallelepiped_overloads( - boost::python::args("self", "n_subdivisions", - "corners", "colorize"), - generate_fixed_subdivided_parallelepiped_docstring)) - .def("generate_varying_subdivided_parallelepiped", - &TriangulationWrapper::generate_varying_subdivided_parallelepiped, - generate_varying_subdivided_parallelepiped_overloads( - boost::python::args("self", "n_subdivisions", - "corners", "colorize"), - generate_varying_subdivided_parallelepiped_docstring)) - .def("generate_enclosed_hyper_cube", - &TriangulationWrapper::generate_enclosed_hyper_cube, - generate_enclosed_hyper_cube_overloads( - boost::python::args("self", "left", "right", - "thickness", "colorize"), - generate_enclosed_hyper_cube_docstring)) - .def("generate_hyper_ball", - &TriangulationWrapper::generate_hyper_ball, - generate_hyper_ball_overloads( - boost::python::args("self", "center", "radius"), - generate_hyper_ball_docstring)) - .def("generate_hyper_sphere", - &TriangulationWrapper::generate_hyper_sphere, - generate_hyper_sphere_overloads( - boost::python::args("self", "center", "radius"), - generate_hyper_sphere_docstring)) - .def("generate_quarter_hyper_ball", - &TriangulationWrapper::generate_quarter_hyper_ball, - generate_quarter_hyper_ball_overloads( - boost::python::args("self", "center", "radius"), - generate_quarter_hyper_ball_docstring)) - .def("generate_half_hyper_ball", - &TriangulationWrapper::generate_half_hyper_ball, - generate_half_hyper_ball_overloads( - boost::python::args("self", "center", "radius"), - generate_half_hyper_ball_docstring)) - .def("shift", - &TriangulationWrapper::shift, - shift_docstring, - boost::python::args("self", "shift")) - .def("merge_triangulations", - &TriangulationWrapper::merge_triangulations, - merge_docstring, - boost::python::args("self", "triangulation_1", "triangulation_2")) - .def("flatten_triangulation", - &TriangulationWrapper::flatten_triangulation, - flatten_triangulation_docstring, - boost::python::args("self", "tria_out")) - .def("refine_global", - &TriangulationWrapper::refine_global, - refine_global_docstring, - boost::python::args("self", "times")) - .def("execute_coarsening_and_refinement", - &TriangulationWrapper::execute_coarsening_and_refinement, - execute_coarsening_and_refinement_docstring, - boost::python::args("self")) - .def("active_cells", - &TriangulationWrapper::active_cells, - active_cells_docstring, - boost::python::args("self")) - .def("write", - &TriangulationWrapper::write, - write_docstring, - boost::python::args("self", "filename", "format")) - .def("save", - &TriangulationWrapper::save, - save_docstring, - boost::python::args("self", "filename")) - .def("load", - &TriangulationWrapper::load, - load_docstring, - boost::python::args("self", "filename")); + boost::python::class_( + "Triangulation", boost::python::init()) + .def(boost::python::init()) + .def("n_active_cells", + &TriangulationWrapper::n_active_cells, + n_active_cells_docstring, + boost::python::args("self")) + .def("generate_hyper_cube", + &TriangulationWrapper::generate_hyper_cube, + generate_hyper_cube_overloads( + boost::python::args("self", "left", "right", "colorize"), + generate_hyper_cube_docstring)) + .def("generate_simplex", + &TriangulationWrapper::generate_simplex, + generate_simplex_docstring, + boost::python::args("self", "vertices")) + .def("generate_subdivided_hyper_cube", + &TriangulationWrapper::generate_subdivided_hyper_cube, + generate_subdivided_hyper_cube_overloads( + boost::python::args("self", "repetitions", "left", "right"), + generate_subdivided_hyper_cube_docstring)) + .def("generate_hyper_rectangle", + &TriangulationWrapper::generate_hyper_rectangle, + generate_hyper_rectangle_overloads( + boost::python::args("self", "p1", "p2", "colorize"), + generate_hyper_rectangle_docstring)) + .def("generate_subdivided_hyper_rectangle", + &TriangulationWrapper::generate_subdivided_hyper_rectangle, + generate_subdivided_hyper_rectangle_overloads( + boost::python::args("self", "repetitions", "p1", "p2", "colorize"), + generate_subdivided_hyper_rectangle_docstring)) + .def("generate_subdivided_steps_hyper_rectangle", + &TriangulationWrapper::generate_subdivided_steps_hyper_rectangle, + generate_subdivided_steps_hyper_rectangle_overloads( + boost::python::args("self", "step_sizes", "p1", "p2", "colorize"), + generate_subdivided_steps_hyper_rectangle_docstring)) + .def("generate_subdivided_material_hyper_rectangle", + &TriangulationWrapper::generate_subdivided_material_hyper_rectangle, + generate_subdivided_material_hyper_rectangle_overloads( + boost::python::args( + "self", "spacing", "p", "material_id", "colorize"), + generate_subdivided_material_hyper_rectangle_docstring)) + .def("generate_cheese", + &TriangulationWrapper::generate_cheese, + generate_cheese_docstring, + boost::python::args("self", "holes")) + .def("generate_general_cell", + &TriangulationWrapper::generate_general_cell, + generate_general_cell_overloads( + boost::python::args("self", "vertices", "colorize"), + generate_general_cell_docstring)) + .def("generate_parallelogram", + &TriangulationWrapper::generate_parallelogram, + generate_parallelogram_overloads( + boost::python::args("self", "corners", "colorize"), + generate_parallelogram_docstring)) + .def("generate_parallelepiped", + &TriangulationWrapper::generate_parallelepiped, + generate_parallelepiped_overloads( + boost::python::args("self", "corners", "colorize"), + generate_parallelepiped_docstring)) + .def( + "generate_fixed_subdivided_parallelepiped", + &TriangulationWrapper::generate_fixed_subdivided_parallelepiped, + generate_fixed_subdivided_parallelepiped_overloads( + boost::python::args("self", "n_subdivisions", "corners", "colorize"), + generate_fixed_subdivided_parallelepiped_docstring)) + .def( + "generate_varying_subdivided_parallelepiped", + &TriangulationWrapper::generate_varying_subdivided_parallelepiped, + generate_varying_subdivided_parallelepiped_overloads( + boost::python::args("self", "n_subdivisions", "corners", "colorize"), + generate_varying_subdivided_parallelepiped_docstring)) + .def( + "generate_enclosed_hyper_cube", + &TriangulationWrapper::generate_enclosed_hyper_cube, + generate_enclosed_hyper_cube_overloads( + boost::python::args("self", "left", "right", "thickness", "colorize"), + generate_enclosed_hyper_cube_docstring)) + .def("generate_hyper_ball", + &TriangulationWrapper::generate_hyper_ball, + generate_hyper_ball_overloads( + boost::python::args("self", "center", "radius"), + generate_hyper_ball_docstring)) + .def("generate_hyper_sphere", + &TriangulationWrapper::generate_hyper_sphere, + generate_hyper_sphere_overloads( + boost::python::args("self", "center", "radius"), + generate_hyper_sphere_docstring)) + .def("generate_quarter_hyper_ball", + &TriangulationWrapper::generate_quarter_hyper_ball, + generate_quarter_hyper_ball_overloads( + boost::python::args("self", "center", "radius"), + generate_quarter_hyper_ball_docstring)) + .def("generate_half_hyper_ball", + &TriangulationWrapper::generate_half_hyper_ball, + generate_half_hyper_ball_overloads( + boost::python::args("self", "center", "radius"), + generate_half_hyper_ball_docstring)) + .def("shift", + &TriangulationWrapper::shift, + shift_docstring, + boost::python::args("self", "shift")) + .def("merge_triangulations", + &TriangulationWrapper::merge_triangulations, + merge_docstring, + boost::python::args("self", "triangulation_1", "triangulation_2")) + .def("flatten_triangulation", + &TriangulationWrapper::flatten_triangulation, + flatten_triangulation_docstring, + boost::python::args("self", "tria_out")) + .def("refine_global", + &TriangulationWrapper::refine_global, + refine_global_docstring, + boost::python::args("self", "times")) + .def("execute_coarsening_and_refinement", + &TriangulationWrapper::execute_coarsening_and_refinement, + execute_coarsening_and_refinement_docstring, + boost::python::args("self")) + .def("active_cells", + &TriangulationWrapper::active_cells, + active_cells_docstring, + boost::python::args("self")) + .def("write", + &TriangulationWrapper::write, + write_docstring, + boost::python::args("self", "filename", "format")) + .def("save", + &TriangulationWrapper::save, + save_docstring, + boost::python::args("self", "filename")) + .def("load", + &TriangulationWrapper::load, + load_docstring, + boost::python::args("self", "filename")); } -} +} // namespace python DEAL_II_NAMESPACE_CLOSE diff --git a/contrib/python-bindings/source/point_wrapper.cc b/contrib/python-bindings/source/point_wrapper.cc index 7c63373bcf..b5e77a94c4 100644 --- a/contrib/python-bindings/source/point_wrapper.cc +++ b/contrib/python-bindings/source/point_wrapper.cc @@ -22,8 +22,8 @@ namespace python namespace internal { template - double distance(const Point & p1, - const Point & p2) + double + distance(const Point &p1, const Point &p2) { return p1.distance(p2); } @@ -31,8 +31,8 @@ namespace python template - bool not_equal(const Point &p1, - const Point &p2) + bool + not_equal(const Point &p1, const Point &p2) { return (p1 != p2); } @@ -40,8 +40,8 @@ namespace python template - bool equal(const Point &p1, - const Point &p2) + bool + equal(const Point &p1, const Point &p2) { return (p1 == p2); } @@ -49,37 +49,38 @@ namespace python template - double dot_product (const Point &p1, - const Point &p2) + double + dot_product(const Point &p1, const Point &p2) { - return p1*p2; + return p1 * p2; } - + template - Point add_points(const Point &p1, - const Point &p2) + Point + add_points(const Point &p1, const Point &p2) { - return p1+p2; + return p1 + p2; } - + template - Point subtract_point(const Point &p1, - const Point &p2) + Point + subtract_point(const Point &p1, const Point &p2) { if (dim == 2) - return Point(p1[0]-p2[0], p1[1]-p2[1]); + return Point(p1[0] - p2[0], p1[1] - p2[1]); else - return Point(p1[0]-p2[0], p1[1]-p2[1], p1[2]-p2[2]); + return Point(p1[0] - p2[0], p1[1] - p2[1], p1[2] - p2[2]); } template - Point opposite_point(const Point &p) + Point + opposite_point(const Point &p) { return -p; } @@ -87,23 +88,26 @@ namespace python template - Point divide_point(const Point &p, double factor) + Point + divide_point(const Point &p, double factor) { - return p/factor; + return p / factor; } template - Point multiply_point(const Point &p, double factor) + Point + multiply_point(const Point &p, double factor) { - return p*factor; + return p * factor; } template - void add_and_set(Point &p1, const Point &p2) + void + add_and_set(Point &p1, const Point &p2) { p1 += p2; } @@ -111,7 +115,8 @@ namespace python template - void subtract_and_set(Point &p1, const Point &p2) + void + subtract_and_set(Point &p1, const Point &p2) { p1 -= p2; } @@ -119,7 +124,8 @@ namespace python template - void multiply_and_set(Point &p, double factor) + void + multiply_and_set(Point &p, double factor) { p *= factor; } @@ -127,16 +133,16 @@ namespace python template - void divide_and_set(Point &p, double factor) + void + divide_and_set(Point &p, double factor) { p /= factor; } - } + } // namespace internal PointWrapper::PointWrapper() - : - dim(-1), - point(nullptr) + : dim(-1) + , point(nullptr) {} @@ -144,15 +150,17 @@ namespace python { dim = boost::python::len(coord); if (dim == 2) - point = new Point<2> (boost::python::extract(coord[0]), - boost::python::extract(coord[1])); + point = new Point<2>(boost::python::extract(coord[0]), + boost::python::extract(coord[1])); else if (dim == 3) - point = new Point<3> (boost::python::extract(coord[0]), - boost::python::extract(coord[1]), - boost::python::extract(coord[2])); + point = new Point<3>(boost::python::extract(coord[0]), + boost::python::extract(coord[1]), + boost::python::extract(coord[2])); else - AssertThrow(false, - ExcMessage("The list of coordinates must contain two or three elements.")); + AssertThrow( + false, + ExcMessage( + "The list of coordinates must contain two or three elements.")); } @@ -162,10 +170,10 @@ namespace python { dim = d; if (dim == 2) - point = new Point<2>(p[0],p[1]); - + point = new Point<2>(p[0], p[1]); + else - point = new Point<3>(p[0],p[1],p[2]); + point = new Point<3>(p[0], p[1], p[2]); } @@ -185,42 +193,46 @@ namespace python - double PointWrapper::distance(const PointWrapper &p) const + double + PointWrapper::distance(const PointWrapper &p) const { AssertThrow(p.get_dim() == dim, - ExcMessage("The points do not have the same dimension.")); - + ExcMessage("The points do not have the same dimension.")); + if (dim == 2) - return internal::distance(*static_cast*>(point), - *static_cast*>(p.get_point())); + return internal::distance(*static_cast *>(point), + *static_cast *>(p.get_point())); else - return internal::distance(*static_cast*>(point), - *static_cast*>(p.get_point())); + return internal::distance(*static_cast *>(point), + *static_cast *>(p.get_point())); } - double PointWrapper::norm() const + double + PointWrapper::norm() const { if (dim == 2) - return static_cast*>(point)->norm(); + return static_cast *>(point)->norm(); else - return static_cast*>(point)->norm(); + return static_cast *>(point)->norm(); } - double PointWrapper::norm_square() const + double + PointWrapper::norm_square() const { if (dim == 2) - return static_cast*>(point)->norm_square(); + return static_cast *>(point)->norm_square(); else - return static_cast*>(point)->norm_square(); + return static_cast *>(point)->norm_square(); } - PointWrapper &PointWrapper::operator= (const PointWrapper &other) + PointWrapper & + PointWrapper::operator=(const PointWrapper &other) { clear(); copy(other); @@ -230,262 +242,283 @@ namespace python - bool PointWrapper::operator!= (const PointWrapper &p) const + bool + PointWrapper::operator!=(const PointWrapper &p) const { AssertThrow(p.get_dim() == dim, - ExcMessage("The points do not have the same dimension.")); + ExcMessage("The points do not have the same dimension.")); if (dim == 2) - return internal::not_equal(*static_cast*>(point), - *static_cast*>(p.get_point())); + return internal::not_equal(*static_cast *>(point), + *static_cast *>(p.get_point())); else - return internal::not_equal(*static_cast*>(point), - *static_cast*>(p.get_point())); + return internal::not_equal(*static_cast *>(point), + *static_cast *>(p.get_point())); } - bool PointWrapper::operator== (const PointWrapper &p) const + bool + PointWrapper::operator==(const PointWrapper &p) const { AssertThrow(p.get_dim() == dim, - ExcMessage("The points do not have the same dimension.")); + ExcMessage("The points do not have the same dimension.")); if (dim == 2) - return internal::equal(*static_cast*>(point), - *static_cast*>(p.get_point())); + return internal::equal(*static_cast *>(point), + *static_cast *>(p.get_point())); else - return internal::equal(*static_cast*>(point), - *static_cast*>(p.get_point())); + return internal::equal(*static_cast *>(point), + *static_cast *>(p.get_point())); } - double PointWrapper::operator* (const PointWrapper &p) const + double PointWrapper::operator*(const PointWrapper &p) const { AssertThrow(p.get_dim() == dim, - ExcMessage("The points do not have the same dimension.")); + ExcMessage("The points do not have the same dimension.")); if (dim == 2) - return internal::dot_product(*static_cast*>(point), - *static_cast*>(p.get_point())); + return internal::dot_product(*static_cast *>(point), + *static_cast *>( + p.get_point())); else - return internal::dot_product(*static_cast*>(point), - *static_cast*>(p.get_point())); + return internal::dot_product(*static_cast *>(point), + *static_cast *>( + p.get_point())); } - PointWrapper PointWrapper::operator+ (const PointWrapper &p) const + PointWrapper + PointWrapper::operator+(const PointWrapper &p) const { AssertThrow(p.get_dim() == dim, - ExcMessage("The points do not have the same dimension.")); + ExcMessage("The points do not have the same dimension.")); if (dim == 2) - return PointWrapper(internal::add_points( - *static_cast*>(point), - *static_cast*>(p.get_point()))); + return PointWrapper( + internal::add_points(*static_cast *>(point), + *static_cast *>(p.get_point()))); else - return PointWrapper(internal::add_points( - *static_cast*>(point), - *static_cast*>(p.get_point()))); + return PointWrapper( + internal::add_points(*static_cast *>(point), + *static_cast *>(p.get_point()))); } - PointWrapper PointWrapper::operator- (const PointWrapper &p) const + PointWrapper + PointWrapper::operator-(const PointWrapper &p) const { AssertThrow(p.get_dim() == dim, - ExcMessage("The points do not have the same dimension.")); + ExcMessage("The points do not have the same dimension.")); if (dim == 2) return PointWrapper(internal::subtract_point( - *static_cast*>(point), - *static_cast*>(p.get_point()))); + *static_cast *>(point), + *static_cast *>(p.get_point()))); else return PointWrapper(internal::subtract_point( - *static_cast*>(point), - *static_cast*>(p.get_point()))); + *static_cast *>(point), + *static_cast *>(p.get_point()))); } - PointWrapper PointWrapper::operator-() const + PointWrapper + PointWrapper::operator-() const { if (dim == 2) - return PointWrapper(internal::opposite_point( - *static_cast*>(point))); + return PointWrapper( + internal::opposite_point(*static_cast *>(point))); else - return PointWrapper(internal::opposite_point( - *static_cast*>(point))); + return PointWrapper( + internal::opposite_point(*static_cast *>(point))); } - PointWrapper PointWrapper::operator/(const double factor) const + PointWrapper + PointWrapper::operator/(const double factor) const { AssertThrow(factor != 0., ExcMessage("Dividing by zero.")); if (dim == 2) - return PointWrapper(internal::divide_point( - *static_cast*>(point), factor)); + return PointWrapper( + internal::divide_point(*static_cast *>(point), factor)); else - return PointWrapper(internal::divide_point( - *static_cast*>(point), factor)); + return PointWrapper( + internal::divide_point(*static_cast *>(point), factor)); } - PointWrapper PointWrapper::operator* (const double factor) const + PointWrapper PointWrapper::operator*(const double factor) const { - if (dim == 2) - return PointWrapper(internal::multiply_point( - *static_cast*>(point), factor)); + return PointWrapper( + internal::multiply_point(*static_cast *>(point), factor)); else - return PointWrapper(internal::multiply_point( - *static_cast*>(point), factor)); + return PointWrapper( + internal::multiply_point(*static_cast *>(point), factor)); } - PointWrapper& PointWrapper::operator+= (const PointWrapper &p) + PointWrapper & + PointWrapper::operator+=(const PointWrapper &p) { AssertThrow(p.get_dim() == dim, - ExcMessage("The points do not have the same dimension.")); + ExcMessage("The points do not have the same dimension.")); if (dim == 2) - internal::add_and_set(*static_cast*>(point), - *static_cast*>(p.get_point())); + internal::add_and_set(*static_cast *>(point), + *static_cast *>(p.get_point())); else - internal::add_and_set(*static_cast*>(point), - *static_cast*>(p.get_point())); + internal::add_and_set(*static_cast *>(point), + *static_cast *>(p.get_point())); return *this; } - PointWrapper& PointWrapper::operator-= (const PointWrapper &p) + PointWrapper & + PointWrapper::operator-=(const PointWrapper &p) { AssertThrow(p.get_dim() == dim, - ExcMessage("The points do not have the same dimension.")); + ExcMessage("The points do not have the same dimension.")); if (dim == 2) - internal::subtract_and_set(*static_cast*>(point), - *static_cast*>(p.get_point())); + internal::subtract_and_set(*static_cast *>(point), + *static_cast *>(p.get_point())); else - internal::subtract_and_set(*static_cast*>(point), - *static_cast*>(p.get_point())); + internal::subtract_and_set(*static_cast *>(point), + *static_cast *>(p.get_point())); return *this; } - PointWrapper& PointWrapper::operator*= (const double factor) + PointWrapper & + PointWrapper::operator*=(const double factor) { if (dim == 2) - internal::multiply_and_set(*static_cast*>(point), factor); + internal::multiply_and_set(*static_cast *>(point), factor); else - internal::multiply_and_set(*static_cast*>(point), factor); + internal::multiply_and_set(*static_cast *>(point), factor); return *this; } - PointWrapper& PointWrapper::operator/= (const double factor) + PointWrapper & + PointWrapper::operator/=(const double factor) { AssertThrow(factor != 0., ExcMessage("Dividing by zero.")); if (dim == 2) - internal::divide_and_set(*static_cast*>(point), factor); + internal::divide_and_set(*static_cast *>(point), factor); else - internal::divide_and_set(*static_cast*>(point), factor); + internal::divide_and_set(*static_cast *>(point), factor); return *this; } - double PointWrapper::get_x() const + double + PointWrapper::get_x() const { if (dim == 2) - return (*static_cast*>(point))(0); + return (*static_cast *>(point))(0); else - return (*static_cast*>(point))(0); + return (*static_cast *>(point))(0); } - void PointWrapper::set_x(double x) + void + PointWrapper::set_x(double x) { if (dim == 2) - (*static_cast*>(point))(0) = x; + (*static_cast *>(point))(0) = x; else - (*static_cast*>(point))(0) = x; + (*static_cast *>(point))(0) = x; } - double PointWrapper::get_y() const + double + PointWrapper::get_y() const { if (dim == 2) - return (*static_cast*>(point))(1); + return (*static_cast *>(point))(1); else - return (*static_cast*>(point))(1); + return (*static_cast *>(point))(1); } - void PointWrapper::set_y(double y) + void + PointWrapper::set_y(double y) { if (dim == 2) - (*static_cast*>(point))(1) = y; + (*static_cast *>(point))(1) = y; else - (*static_cast*>(point))(1) = y; + (*static_cast *>(point))(1) = y; } - double PointWrapper::get_z() const + double + PointWrapper::get_z() const { if (dim == 3) - return (*static_cast*>(point))(2); + return (*static_cast *>(point))(2); else - AssertThrow(false, - ExcMessage("The z coordinate is only available for three-dimensional points")); + AssertThrow( + false, + ExcMessage( + "The z coordinate is only available for three-dimensional points")); // Silence a warning return 0.; } - void PointWrapper::set_z(double z) + void + PointWrapper::set_z(double z) { if (dim == 3) - (*static_cast*>(point))(2) = z; + (*static_cast *>(point))(2) = z; else - AssertThrow(false, - ExcMessage("The z coordinate is only available for three-dimensional points")); + AssertThrow( + false, + ExcMessage( + "The z coordinate is only available for three-dimensional points")); } - - void PointWrapper::clear() + void + PointWrapper::clear() { if (point != nullptr) { if (dim == 2) { - // We cannot call delete on a void pointer so cast the void pointer back - // first. - Point<2> *tmp = static_cast*>(point); + // We cannot call delete on a void pointer so cast the void pointer + // back first. + Point<2> *tmp = static_cast *>(point); delete tmp; } else { - Point<3> *tmp = static_cast*>(point); + Point<3> *tmp = static_cast *>(point); delete tmp; } point = nullptr; @@ -494,7 +527,8 @@ namespace python - void PointWrapper::copy(const PointWrapper &other) + void + PointWrapper::copy(const PointWrapper &other) { dim = other.dim; @@ -503,18 +537,19 @@ namespace python if (dim == 2) { - Point<2> *other_point = static_cast*>(other.point); - point = new Point<2> ((*other_point)[0], (*other_point)[1]); + Point<2> *other_point = static_cast *>(other.point); + point = new Point<2>((*other_point)[0], (*other_point)[1]); } else if (dim == 3) { - Point<3> *other_point = static_cast*>(other.point); - point = new Point<3> ((*other_point)[0], (*other_point)[1], (*other_point)[2]); + Point<3> *other_point = static_cast *>(other.point); + point = + new Point<3>((*other_point)[0], (*other_point)[1], (*other_point)[2]); } else AssertThrow(false, ExcMessage("The dimension of the point should be 2 or 3.")); } -} +} // namespace python DEAL_II_NAMESPACE_CLOSE diff --git a/contrib/python-bindings/source/tria_accessor_wrapper.cc b/contrib/python-bindings/source/tria_accessor_wrapper.cc index 61048538e7..49188e9512 100644 --- a/contrib/python-bindings/source/tria_accessor_wrapper.cc +++ b/contrib/python-bindings/source/tria_accessor_wrapper.cc @@ -13,10 +13,10 @@ // // --------------------------------------------------------------------- -#include - #include + #include +#include #include DEAL_II_NAMESPACE_OPEN @@ -26,13 +26,15 @@ namespace python namespace internal { template - PointWrapper get_barycenter(const void *tria_accessor) + PointWrapper + get_barycenter(const void *tria_accessor) { - const TriaAccessor *accessor = - static_cast*>(tria_accessor); - Point barycenter = accessor->barycenter(); + const TriaAccessor *accessor = + static_cast *>( + tria_accessor); + Point barycenter = accessor->barycenter(); boost::python::list barycenter_list; - for (int i=0; i - void set_boundary_id(const int boundary_id, void *tria_accessor) + void + set_boundary_id(const int boundary_id, void *tria_accessor) { - TriaAccessor *accessor = - static_cast*>(tria_accessor); + TriaAccessor *accessor = + static_cast *>(tria_accessor); accessor->set_boundary_id(boundary_id); } template - int get_boundary_id(const void *tria_accessor) + int + get_boundary_id(const void *tria_accessor) { - const TriaAccessor *accessor = - static_cast*>(tria_accessor); + const TriaAccessor *accessor = + static_cast *>( + tria_accessor); return accessor->boundary_id(); } @@ -62,23 +67,23 @@ namespace python template - void set_all_boundary_ids(const int boundary_id, void *tria_accessor) + void + set_all_boundary_ids(const int boundary_id, void *tria_accessor) { - TriaAccessor *accessor = - static_cast*>(tria_accessor); + TriaAccessor *accessor = + static_cast *>(tria_accessor); accessor->set_all_boundary_ids(boundary_id); } template - void set_vertex(const int i, - PointWrapper &point_wrapper, - void *tria_accessor) + void + set_vertex(const int i, PointWrapper &point_wrapper, void *tria_accessor) { - TriaAccessor *accessor = - static_cast*>(tria_accessor); + TriaAccessor *accessor = + static_cast *>(tria_accessor); Point *point = - static_cast*>(point_wrapper.get_point()); + static_cast *>(point_wrapper.get_point()); accessor->vertex(i) = *point; } @@ -86,14 +91,16 @@ namespace python template - PointWrapper get_vertex(const int i, const void *tria_accessor) + PointWrapper + get_vertex(const int i, const void *tria_accessor) { - const TriaAccessor *accessor = - static_cast*>(tria_accessor); + const TriaAccessor *accessor = + static_cast *>( + tria_accessor); Point vertex = accessor->vertex(i); boost::python::list coordinates; - for (int i=0; i - void set_manifold_id(const int manifold_id, void *tria_accessor) + void + set_manifold_id(const int manifold_id, void *tria_accessor) { - TriaAccessor *accessor = - static_cast*>(tria_accessor); + TriaAccessor *accessor = + static_cast *>(tria_accessor); accessor->set_manifold_id(manifold_id); } template - int get_manifold_id(const void *tria_accessor) + int + get_manifold_id(const void *tria_accessor) { - const TriaAccessor *accessor = - static_cast*>(tria_accessor); + const TriaAccessor *accessor = + static_cast *>( + tria_accessor); return accessor->manifold_id(); } template - bool at_boundary(const void *tria_accessor) + bool + at_boundary(const void *tria_accessor) { - const TriaAccessor *accessor = - static_cast*>(tria_accessor); + const TriaAccessor *accessor = + static_cast *>( + tria_accessor); return accessor->at_boundary(); } - } + } // namespace internal TriaAccessorWrapper::TriaAccessorWrapper(const TriaAccessorWrapper &other) - : - structdim(other.structdim), - dim(other.dim), - spacedim(other.spacedim) + : structdim(other.structdim) + , dim(other.dim) + , spacedim(other.spacedim) { if ((dim == 2) && (spacedim == 2) && (structdim == 1)) { - TriaAccessor<1,2,2> *other_accessor = - static_cast*>(other.tria_accessor); - tria_accessor = new TriaAccessor<1,2,2>(*other_accessor); + TriaAccessor<1, 2, 2> *other_accessor = + static_cast *>(other.tria_accessor); + tria_accessor = new TriaAccessor<1, 2, 2>(*other_accessor); } else if ((dim == 2) && (spacedim == 3) && (structdim == 1)) { - TriaAccessor<1,2,3> *other_accessor = - static_cast*>(other.tria_accessor); - tria_accessor = new TriaAccessor<1,2,3>(*other_accessor); + TriaAccessor<1, 2, 3> *other_accessor = + static_cast *>(other.tria_accessor); + tria_accessor = new TriaAccessor<1, 2, 3>(*other_accessor); } else if ((dim == 3) && (spacedim == 3) && (structdim == 2)) { - TriaAccessor<2,3,3> *other_accessor = - static_cast*>(other.tria_accessor); - tria_accessor = new TriaAccessor<2,3,3>(*other_accessor); + TriaAccessor<2, 3, 3> *other_accessor = + static_cast *>(other.tria_accessor); + tria_accessor = new TriaAccessor<2, 3, 3>(*other_accessor); } else - AssertThrow(false, ExcMessage("Wrong structdim-dim-spacedim combination.")); + AssertThrow(false, + ExcMessage("Wrong structdim-dim-spacedim combination.")); } - TriaAccessorWrapper::TriaAccessorWrapper(void* tria_accessor, - const int structdim, - const int dim, - const int spacedim): - structdim(structdim), - dim(dim), - spacedim(spacedim), - tria_accessor(tria_accessor) + TriaAccessorWrapper::TriaAccessorWrapper(void * tria_accessor, + const int structdim, + const int dim, + const int spacedim) + : structdim(structdim) + , dim(dim) + , spacedim(spacedim) + , tria_accessor(tria_accessor) {} @@ -177,145 +189,153 @@ namespace python { if ((dim == 2) && (spacedim == 2) && (structdim == 1)) { - // We cannot call delete on a void pointer so cast the void pointer back - // first. - TriaAccessor<1,2,2> *tmp = - static_cast*>(tria_accessor); + // We cannot call delete on a void pointer so cast the void pointer + // back first. + TriaAccessor<1, 2, 2> *tmp = + static_cast *>(tria_accessor); delete tmp; } else if ((dim == 2) && (spacedim == 3) && (structdim == 1)) { - TriaAccessor<1,2,3> *tmp = - static_cast*>(tria_accessor); + TriaAccessor<1, 2, 3> *tmp = + static_cast *>(tria_accessor); delete tmp; } else { - TriaAccessor<2,3,3> *tmp = - static_cast*>(tria_accessor); + TriaAccessor<2, 3, 3> *tmp = + static_cast *>(tria_accessor); delete tmp; } - dim = -1; - spacedim = -1; - structdim = -1; + dim = -1; + spacedim = -1; + structdim = -1; tria_accessor = nullptr; } } - PointWrapper TriaAccessorWrapper::get_barycenter() const + PointWrapper + TriaAccessorWrapper::get_barycenter() const { if ((dim == 2) && (spacedim == 2) && (structdim == 1)) - return internal::get_barycenter<1,2,2>(tria_accessor); + return internal::get_barycenter<1, 2, 2>(tria_accessor); else if ((dim == 2) && (spacedim == 3) && (structdim == 1)) - return internal::get_barycenter<1,2,3>(tria_accessor); + return internal::get_barycenter<1, 2, 3>(tria_accessor); else - return internal::get_barycenter<2,3,3>(tria_accessor); + return internal::get_barycenter<2, 3, 3>(tria_accessor); } - void TriaAccessorWrapper::set_boundary_id(const int boundary_id) + void + TriaAccessorWrapper::set_boundary_id(const int boundary_id) { if ((dim == 2) && (spacedim == 2) && (structdim == 1)) - internal::set_boundary_id<1,2,2>(boundary_id, tria_accessor); + internal::set_boundary_id<1, 2, 2>(boundary_id, tria_accessor); else if ((dim == 2) && (spacedim == 3) && (structdim == 1)) - internal::set_boundary_id<1,2,3>(boundary_id, tria_accessor); + internal::set_boundary_id<1, 2, 3>(boundary_id, tria_accessor); else - internal::set_boundary_id<2,3,3>(boundary_id, tria_accessor); + internal::set_boundary_id<2, 3, 3>(boundary_id, tria_accessor); } - void TriaAccessorWrapper::set_all_boundary_ids(const int boundary_id) + void + TriaAccessorWrapper::set_all_boundary_ids(const int boundary_id) { if ((dim == 2) && (spacedim == 2) && (structdim == 1)) - internal::set_all_boundary_ids<1,2,2>(boundary_id, tria_accessor); + internal::set_all_boundary_ids<1, 2, 2>(boundary_id, tria_accessor); else if ((dim == 2) && (spacedim == 3) && (structdim == 1)) - internal::set_all_boundary_ids<1,2,3>(boundary_id, tria_accessor); + internal::set_all_boundary_ids<1, 2, 3>(boundary_id, tria_accessor); else - internal::set_all_boundary_ids<2,3,3>(boundary_id, tria_accessor); + internal::set_all_boundary_ids<2, 3, 3>(boundary_id, tria_accessor); } - int TriaAccessorWrapper::get_boundary_id() const + int + TriaAccessorWrapper::get_boundary_id() const { if ((dim == 2) && (spacedim == 2) && (structdim == 1)) - return internal::get_boundary_id<1,2,2>(tria_accessor); + return internal::get_boundary_id<1, 2, 2>(tria_accessor); else if ((dim == 2) && (spacedim == 3) && (structdim == 1)) - return internal::get_boundary_id<1,2,3>(tria_accessor); + return internal::get_boundary_id<1, 2, 3>(tria_accessor); else - return internal::get_boundary_id<2,3,3>(tria_accessor); + return internal::get_boundary_id<2, 3, 3>(tria_accessor); } - void TriaAccessorWrapper::set_vertex(const int i, - PointWrapper &point_wrapper) + void + TriaAccessorWrapper::set_vertex(const int i, PointWrapper &point_wrapper) { - AssertThrow(i(i, point_wrapper, tria_accessor); + internal::set_vertex<1, 2, 2>(i, point_wrapper, tria_accessor); else if ((dim == 2) && (spacedim == 3) && (structdim == 1)) - internal::set_vertex<1,2,3>(i, point_wrapper, tria_accessor); + internal::set_vertex<1, 2, 3>(i, point_wrapper, tria_accessor); else - internal::set_vertex<2,3,3>(i, point_wrapper, tria_accessor); + internal::set_vertex<2, 3, 3>(i, point_wrapper, tria_accessor); } - PointWrapper TriaAccessorWrapper::get_vertex(const int i) const + PointWrapper + TriaAccessorWrapper::get_vertex(const int i) const { - AssertThrow(i(i, tria_accessor); + return internal::get_vertex<1, 2, 2>(i, tria_accessor); else if ((dim == 2) && (spacedim == 3) && (structdim == 1)) - return internal::get_vertex<1,2,3>(i, tria_accessor); + return internal::get_vertex<1, 2, 3>(i, tria_accessor); else - return internal::get_vertex<2,3,3>(i, tria_accessor); + return internal::get_vertex<2, 3, 3>(i, tria_accessor); } - void TriaAccessorWrapper::set_manifold_id(const int manifold_id) + void + TriaAccessorWrapper::set_manifold_id(const int manifold_id) { if ((dim == 2) && (spacedim == 2) && (structdim == 1)) - internal::set_manifold_id<1,2,2>(manifold_id, tria_accessor); + internal::set_manifold_id<1, 2, 2>(manifold_id, tria_accessor); else if ((dim == 2) && (spacedim == 3) && (structdim == 1)) - internal::set_manifold_id<1,2,3>(manifold_id, tria_accessor); + internal::set_manifold_id<1, 2, 3>(manifold_id, tria_accessor); else - internal::set_manifold_id<2,3,3>(manifold_id, tria_accessor); + internal::set_manifold_id<2, 3, 3>(manifold_id, tria_accessor); } - int TriaAccessorWrapper::get_manifold_id() const + int + TriaAccessorWrapper::get_manifold_id() const { if ((dim == 2) && (spacedim == 2) && (structdim == 1)) - return internal::get_manifold_id<1,2,2>(tria_accessor); - else if ((dim== 2) && (spacedim == 3) && (structdim == 1)) - return internal::get_manifold_id<1,2,3>(tria_accessor); + return internal::get_manifold_id<1, 2, 2>(tria_accessor); + else if ((dim == 2) && (spacedim == 3) && (structdim == 1)) + return internal::get_manifold_id<1, 2, 3>(tria_accessor); else - return internal::get_manifold_id<2,3,3>(tria_accessor); + return internal::get_manifold_id<2, 3, 3>(tria_accessor); } - bool TriaAccessorWrapper::at_boundary() const + bool + TriaAccessorWrapper::at_boundary() const { if ((dim == 2) && (spacedim == 2) && (structdim == 1)) - return internal::at_boundary<1,2,2>(tria_accessor); - else if ((dim== 2) && (spacedim == 3) && (structdim == 1)) - return internal::at_boundary<1,2,3>(tria_accessor); + return internal::at_boundary<1, 2, 2>(tria_accessor); + else if ((dim == 2) && (spacedim == 3) && (structdim == 1)) + return internal::at_boundary<1, 2, 3>(tria_accessor); else - return internal::at_boundary<2,3,3>(tria_accessor); + return internal::at_boundary<2, 3, 3>(tria_accessor); } -} +} // namespace python DEAL_II_NAMESPACE_CLOSE diff --git a/contrib/python-bindings/source/triangulation_wrapper.cc b/contrib/python-bindings/source/triangulation_wrapper.cc index b2fcf199b7..cce5a86757 100644 --- a/contrib/python-bindings/source/triangulation_wrapper.cc +++ b/contrib/python-bindings/source/triangulation_wrapper.cc @@ -13,15 +13,19 @@ // // --------------------------------------------------------------------- -#include -#include #include -#include + #include #include #include -#include +#include + #include +#include + +#include +#include + #include DEAL_II_NAMESPACE_OPEN @@ -31,13 +35,14 @@ namespace python namespace internal { template - void generate_hyper_cube(const double left, - const double right, - const bool colorize, - void *triangulation) + void + generate_hyper_cube(const double left, + const double right, + const bool colorize, + void * triangulation) { - Triangulation *tria = - static_cast*>(triangulation); + Triangulation *tria = + static_cast *>(triangulation); tria->clear(); GridGenerator::hyper_cube(*tria, left, right, colorize); } @@ -45,16 +50,18 @@ namespace python template - void generate_simplex(std::vector &wrapped_points, - void *triangulation) + void + generate_simplex(std::vector &wrapped_points, + void * triangulation) { // Cast the PointWrapper objects to Point - std::vector> points(dim+1); - for (int i=0; i*>((wrapped_points[i]).get_point())); + std::vector> points(dim + 1); + for (int i = 0; i < dim + 1; ++i) + points[i] = + *(static_cast *>((wrapped_points[i]).get_point())); Triangulation *tria = - static_cast*>(triangulation); + static_cast *>(triangulation); tria->clear(); GridGenerator::simplex(*tria, points); } @@ -62,13 +69,14 @@ namespace python template - void generate_subdivided_hyper_cube(const unsigned int repetitions, - const double left, - const double right, - void *triangulation) + void + generate_subdivided_hyper_cube(const unsigned int repetitions, + const double left, + const double right, + void * triangulation) { - Triangulation *tria = - static_cast*>(triangulation); + Triangulation *tria = + static_cast *>(triangulation); tria->clear(); GridGenerator::subdivided_hyper_cube(*tria, repetitions, left, right); } @@ -76,21 +84,26 @@ namespace python template - void generate_hyper_rectangle(PointWrapper &p1, - PointWrapper &p2, - const bool colorize, - void *triangulation) + void + generate_hyper_rectangle(PointWrapper &p1, + PointWrapper &p2, + const bool colorize, + void * triangulation) { - AssertThrow(p1.get_dim() == dim, - ExcMessage("Dimension of p1 is not the same as the dimension of the Triangulation.")); - AssertThrow(p2.get_dim() == dim, - ExcMessage("Dimension of p2 is not the same as the dimension of the Triangulation.")); + AssertThrow( + p1.get_dim() == dim, + ExcMessage( + "Dimension of p1 is not the same as the dimension of the Triangulation.")); + AssertThrow( + p2.get_dim() == dim, + ExcMessage( + "Dimension of p2 is not the same as the dimension of the Triangulation.")); // Cast the PointWrapper object to Point - Point point_1 = *(static_cast*>(p1.get_point())); - Point point_2 = *(static_cast*>(p2.get_point())); + Point point_1 = *(static_cast *>(p1.get_point())); + Point point_2 = *(static_cast *>(p2.get_point())); - Triangulation *tria = - static_cast*>(triangulation); + Triangulation *tria = + static_cast *>(triangulation); tria->clear(); GridGenerator::hyper_rectangle(*tria, point_1, point_2, colorize); } @@ -98,79 +111,95 @@ namespace python template - void generate_subdivided_hyper_rectangle(const std::vector &repetitions, - PointWrapper &p1, - PointWrapper &p2, - const bool colorize, - void *triangulation) + void + generate_subdivided_hyper_rectangle( + const std::vector &repetitions, + PointWrapper & p1, + PointWrapper & p2, + const bool colorize, + void * triangulation) { - AssertThrow(p1.get_dim() == dim, - ExcMessage("Dimension of p1 is not the same as the dimension of the Triangulation.")); - AssertThrow(p2.get_dim() == dim, - ExcMessage("Dimension of p2 is not the same as the dimension of the Triangulation.")); + AssertThrow( + p1.get_dim() == dim, + ExcMessage( + "Dimension of p1 is not the same as the dimension of the Triangulation.")); + AssertThrow( + p2.get_dim() == dim, + ExcMessage( + "Dimension of p2 is not the same as the dimension of the Triangulation.")); // Cast the PointWrapper object to Point - Point point_1 = *(static_cast*>(p1.get_point())); - Point point_2 = *(static_cast*>(p2.get_point())); + Point point_1 = *(static_cast *>(p1.get_point())); + Point point_2 = *(static_cast *>(p2.get_point())); - Triangulation *tria = - static_cast*>(triangulation); + Triangulation *tria = + static_cast *>(triangulation); tria->clear(); - GridGenerator::subdivided_hyper_rectangle(*tria, repetitions, point_1, - point_2, colorize); + GridGenerator::subdivided_hyper_rectangle( + *tria, repetitions, point_1, point_2, colorize); } template - void generate_subdivided_steps_hyper_rectangle(const std::vector> &step_sizes, - PointWrapper &p1, - PointWrapper &p2, - const bool colorize, - void *triangulation) + void + generate_subdivided_steps_hyper_rectangle( + const std::vector> &step_sizes, + PointWrapper & p1, + PointWrapper & p2, + const bool colorize, + void * triangulation) { - AssertThrow(p1.get_dim() == dim, - ExcMessage("Dimension of p1 is not the same as the dimension of the Triangulation.")); - AssertThrow(p2.get_dim() == dim, - ExcMessage("Dimension of p2 is not the same as the dimension of the Triangulation.")); + AssertThrow( + p1.get_dim() == dim, + ExcMessage( + "Dimension of p1 is not the same as the dimension of the Triangulation.")); + AssertThrow( + p2.get_dim() == dim, + ExcMessage( + "Dimension of p2 is not the same as the dimension of the Triangulation.")); // Cast the PointWrapper object to Point - Point point_1 = *(static_cast*>(p1.get_point())); - Point point_2 = *(static_cast*>(p2.get_point())); + Point point_1 = *(static_cast *>(p1.get_point())); + Point point_2 = *(static_cast *>(p2.get_point())); Triangulation *tria = - static_cast*>(triangulation); + static_cast *>(triangulation); tria->clear(); - GridGenerator::subdivided_hyper_rectangle(*tria, step_sizes, point_1, - point_2, colorize); + GridGenerator::subdivided_hyper_rectangle( + *tria, step_sizes, point_1, point_2, colorize); } template - void generate_subdivided_material_hyper_rectangle(const std::vector> &spacing, - PointWrapper &p, - const Table &material_ids, - const bool colorize, - void *triangulation) + void + generate_subdivided_material_hyper_rectangle( + const std::vector> &spacing, + PointWrapper & p, + const Table & material_ids, + const bool colorize, + void * triangulation) { - AssertThrow(p.get_dim() == dim, - ExcMessage("Dimension of p is not the same as the dimension of the Triangulation.")); + AssertThrow( + p.get_dim() == dim, + ExcMessage( + "Dimension of p is not the same as the dimension of the Triangulation.")); // Cast the PointWrapper object to Point - Point point = *(static_cast*>(p.get_point())); + Point point = *(static_cast *>(p.get_point())); Triangulation *tria = - static_cast*>(triangulation); + static_cast *>(triangulation); tria->clear(); - GridGenerator::subdivided_hyper_rectangle(*tria, spacing, point, - material_ids, colorize); + GridGenerator::subdivided_hyper_rectangle( + *tria, spacing, point, material_ids, colorize); } template - void generate_cheese(const std::vector &holes, - void *triangulation) + void + generate_cheese(const std::vector &holes, void *triangulation) { - Triangulation *tria = - static_cast*>(triangulation); + Triangulation *tria = + static_cast *>(triangulation); tria->clear(); GridGenerator::cheese(*tria, holes); } @@ -178,18 +207,20 @@ namespace python template - void generate_general_cell(std::vector &wrapped_points, - const bool colorize, - void *triangulation) + void + generate_general_cell(std::vector &wrapped_points, + const bool colorize, + void * triangulation) { // Cast the PointWrapper objects to Point - const unsigned int size = wrapped_points.size(); + const unsigned int size = wrapped_points.size(); std::vector> points(size); - for (unsigned int i=0; i*>((wrapped_points[i]).get_point())); + for (unsigned int i = 0; i < size; ++i) + points[i] = + *(static_cast *>((wrapped_points[i]).get_point())); Triangulation *tria = - static_cast*>(triangulation); + static_cast *>(triangulation); tria->clear(); GridGenerator::general_cell(*tria, points, colorize); } @@ -197,17 +228,19 @@ namespace python template - void generate_parallelogram(std::vector &wrapped_points, - const bool colorize, - void *triangulation) + void + generate_parallelogram(std::vector &wrapped_points, + const bool colorize, + void * triangulation) { // Cast the PointWrapper objects to Point Point points[dim]; - for (unsigned int i=0; i*>((wrapped_points[i]).get_point())); + for (unsigned int i = 0; i < dim; ++i) + points[i] = + *(static_cast *>((wrapped_points[i]).get_point())); Triangulation *tria = - static_cast*>(triangulation); + static_cast *>(triangulation); tria->clear(); GridGenerator::parallelogram(*tria, points, colorize); } @@ -215,17 +248,19 @@ namespace python template - void generate_parallelepiped(std::vector &wrapped_points, - const bool colorize, - void *triangulation) + void + generate_parallelepiped(std::vector &wrapped_points, + const bool colorize, + void * triangulation) { // Cast the PointWrapper objects to Point Point points[dim]; - for (unsigned int i=0; i*>((wrapped_points[i]).get_point())); + for (unsigned int i = 0; i < dim; ++i) + points[i] = + *(static_cast *>((wrapped_points[i]).get_point())); Triangulation *tria = - static_cast*>(triangulation); + static_cast *>(triangulation); tria->clear(); GridGenerator::parallelepiped(*tria, points, colorize); } @@ -233,73 +268,88 @@ namespace python template - void generate_fixed_subdivided_parallelepiped(unsigned int n_subdivisions, - std::vector &wrapped_points, - const bool colorize, - void *triangulation) + void + generate_fixed_subdivided_parallelepiped( + unsigned int n_subdivisions, + std::vector &wrapped_points, + const bool colorize, + void * triangulation) { // Cast the PointWrapper objects to Point Point points[dim]; - for (unsigned int i=0; i*>((wrapped_points[i]).get_point())); + for (unsigned int i = 0; i < dim; ++i) + points[i] = + *(static_cast *>((wrapped_points[i]).get_point())); Triangulation *tria = - static_cast*>(triangulation); + static_cast *>(triangulation); tria->clear(); - GridGenerator::subdivided_parallelepiped(*tria, n_subdivisions, points, colorize); + GridGenerator::subdivided_parallelepiped(*tria, + n_subdivisions, + points, + colorize); } template - void generate_varying_subdivided_parallelepiped(std::vector &n_subdivisions, - std::vector &wrapped_points, - const bool colorize, - void *triangulation) + void + generate_varying_subdivided_parallelepiped( + std::vector &n_subdivisions, + std::vector &wrapped_points, + const bool colorize, + void * triangulation) { // Cast the PointWrapper objects to Point - Point points[dim]; + Point points[dim]; unsigned int subdivisions[dim]; - for (unsigned int i=0; i*>((wrapped_points[i]).get_point())); - subdivisions[i] = n_subdivisions[i]; - } + for (unsigned int i = 0; i < dim; ++i) + { + points[i] = + *(static_cast *>((wrapped_points[i]).get_point())); + subdivisions[i] = n_subdivisions[i]; + } Triangulation *tria = - static_cast*>(triangulation); + static_cast *>(triangulation); tria->clear(); - GridGenerator::subdivided_parallelepiped(*tria, subdivisions, points, colorize); + GridGenerator::subdivided_parallelepiped(*tria, + subdivisions, + points, + colorize); } - + template - void generate_enclosed_hyper_cube(const double left, - const double right, - const double thickness, - const double colorize, - void *triangulation) + void + generate_enclosed_hyper_cube(const double left, + const double right, + const double thickness, + const double colorize, + void * triangulation) { Triangulation *tria = - static_cast*>(triangulation); + static_cast *>(triangulation); tria->clear(); - GridGenerator::enclosed_hyper_cube(*tria, left, right, thickness, colorize); + GridGenerator::enclosed_hyper_cube( + *tria, left, right, thickness, colorize); } - + template - void generate_hyper_ball(PointWrapper ¢er, - const double radius, - void *triangulation) + void + generate_hyper_ball(PointWrapper ¢er, + const double radius, + void * triangulation) { // Cast the PointWrapper object to Point - Point center_point = *(static_cast*>( - center.get_point())); + Point center_point = + *(static_cast *>(center.get_point())); Triangulation *tria = - static_cast*>(triangulation); + static_cast *>(triangulation); tria->clear(); GridGenerator::hyper_ball(*tria, center_point, radius); } @@ -307,50 +357,53 @@ namespace python template - void generate_hyper_sphere(PointWrapper ¢er, - const double radius, - void *triangulation) + void + generate_hyper_sphere(PointWrapper ¢er, + const double radius, + void * triangulation) { // Cast the PointWrapper object to Point - Point center_point = *(static_cast*>( - center.get_point())); + Point center_point = + *(static_cast *>(center.get_point())); - Triangulation *tria = - static_cast*>(triangulation); + Triangulation *tria = + static_cast *>(triangulation); tria->clear(); GridGenerator::hyper_sphere(*tria, center_point, radius); } - + template - void generate_quarter_hyper_ball(PointWrapper ¢er, - const double radius, - void *triangulation) + void + generate_quarter_hyper_ball(PointWrapper ¢er, + const double radius, + void * triangulation) { // Cast the PointWrapper object to Point - Point center_point = *(static_cast*>( - center.get_point())); + Point center_point = + *(static_cast *>(center.get_point())); Triangulation *tria = - static_cast*>(triangulation); + static_cast *>(triangulation); tria->clear(); GridGenerator::quarter_hyper_ball(*tria, center_point, radius); } - + template - void generate_half_hyper_ball(PointWrapper ¢er, - const double radius, - void *triangulation) + void + generate_half_hyper_ball(PointWrapper ¢er, + const double radius, + void * triangulation) { // Cast the PointWrapper object to Point - Point center_point = *(static_cast*>( - center.get_point())); + Point center_point = + *(static_cast *>(center.get_point())); Triangulation *tria = - static_cast*>(triangulation); + static_cast *>(triangulation); tria->clear(); GridGenerator::half_hyper_ball(*tria, center_point, radius); } @@ -358,33 +411,36 @@ namespace python template - void shift(boost::python::list &shift_list, - void *triangulation) + void + shift(boost::python::list &shift_list, void *triangulation) { // Extract the shift vector from the python list - Tensor<1,spacedim> shift_vector; - for (int i=0; i shift_vector; + for (int i = 0; i < spacedim; ++i) shift_vector[i] = boost::python::extract(shift_list[i]); - Triangulation *tria = - static_cast*>(triangulation); + Triangulation *tria = + static_cast *>(triangulation); GridTools::shift(shift_vector, *tria); } template - void merge_triangulations(TriangulationWrapper &triangulation_1, - TriangulationWrapper &triangulation_2, - void *triangulation) + void + merge_triangulations(TriangulationWrapper &triangulation_1, + TriangulationWrapper &triangulation_2, + void * triangulation) { - Triangulation *tria = - static_cast*>(triangulation); + Triangulation *tria = + static_cast *>(triangulation); tria->clear(); - Triangulation *tria_1 = - static_cast*>(triangulation_1.get_triangulation()); - Triangulation *tria_2 = - static_cast*>(triangulation_2.get_triangulation()); + Triangulation *tria_1 = + static_cast *>( + triangulation_1.get_triangulation()); + Triangulation *tria_2 = + static_cast *>( + triangulation_2.get_triangulation()); GridGenerator::merge_triangulations(*tria_1, *tria_2, *tria); // We need to reassign tria to triangulation because tria was cleared // inside merge_triangulations. @@ -394,26 +450,30 @@ namespace python template - void flatten_triangulation(void *triangulation, TriangulationWrapper &tria_out) + void + flatten_triangulation(void *triangulation, TriangulationWrapper &tria_out) { - Triangulation *tria = - static_cast*>(triangulation); - Triangulation *tria_2 = - static_cast*>(tria_out.get_triangulation()); + Triangulation *tria = + static_cast *>(triangulation); + Triangulation *tria_2 = + static_cast *>( + tria_out.get_triangulation()); GridGenerator::flatten_triangulation(*tria, *tria_2); } template - boost::python::list active_cells(TriangulationWrapper &triangulation_wrapper) + boost::python::list + active_cells(TriangulationWrapper &triangulation_wrapper) { - Triangulation *tria = - static_cast*>( + Triangulation *tria = + static_cast *>( triangulation_wrapper.get_triangulation()); boost::python::list cells; - for (auto & cell : tria->active_cell_iterators()) - cells.append(CellAccessorWrapper(triangulation_wrapper, cell->level(), + for (auto &cell : tria->active_cell_iterators()) + cells.append(CellAccessorWrapper(triangulation_wrapper, + cell->level(), cell->index())); return cells; @@ -422,12 +482,13 @@ namespace python template - void write(const std::string &filename, - const std::string &format, - const void *triangulation) + void + write(const std::string &filename, + const std::string &format, + const void * triangulation) { - const Triangulation *tria = - static_cast*>(triangulation); + const Triangulation *tria = + static_cast *>(triangulation); GridOut::OutputFormat output_format; if (format.compare("dx") == 0) @@ -453,20 +514,20 @@ namespace python else output_format = GridOut::OutputFormat::none; - GridOut mesh_writer; + GridOut mesh_writer; std::ofstream ofs(filename); mesh_writer.write(*tria, ofs, output_format); ofs.close(); } - } + } // namespace internal TriangulationWrapper::TriangulationWrapper(const std::string &dimension) { - if ((dimension.compare("2D")==0) || (dimension.compare("2d")==0)) + if ((dimension.compare("2D") == 0) || (dimension.compare("2d") == 0)) setup("2D", "2D"); - else if ((dimension.compare("3D")==0) || (dimension.compare("3d")==0)) + else if ((dimension.compare("3D") == 0) || (dimension.compare("3d") == 0)) setup("3D", "3D"); else AssertThrow(false, ExcMessage("Dimension needs to be 2D or 3D")); @@ -490,22 +551,23 @@ namespace python { if (spacedim == 2) { - // We cannot call delete on a void pointer so cast the void pointer back - // first. - Triangulation<2,2> *tmp = - static_cast*>(triangulation); + // We cannot call delete on a void pointer so cast the void + // pointer back first. + Triangulation<2, 2> *tmp = + static_cast *>(triangulation); delete tmp; } else { - Triangulation<2,3> *tmp = - static_cast*>(triangulation); + Triangulation<2, 3> *tmp = + static_cast *>(triangulation); delete tmp; } } else { - Triangulation<3,3> *tmp = static_cast*>(triangulation); + Triangulation<3, 3> *tmp = + static_cast *>(triangulation); delete tmp; } triangulation = nullptr; @@ -515,41 +577,49 @@ namespace python - unsigned int TriangulationWrapper::n_active_cells() const + unsigned int + TriangulationWrapper::n_active_cells() const { if ((dim == 2) && (spacedim == 2)) - return (*static_cast*>(triangulation)).n_active_cells(); + return (*static_cast *>(triangulation)) + .n_active_cells(); else if ((dim == 2) && (spacedim == 3)) - return (*static_cast*>(triangulation)).n_active_cells(); + return (*static_cast *>(triangulation)) + .n_active_cells(); else - return (*static_cast*>(triangulation)).n_active_cells(); + return (*static_cast *>(triangulation)) + .n_active_cells(); } - void TriangulationWrapper::generate_hyper_cube(const double left, - const double right, - const bool colorize) + void + TriangulationWrapper::generate_hyper_cube(const double left, + const double right, + const bool colorize) { if ((dim == 2) && (spacedim == 2)) - internal::generate_hyper_cube<2,2>(left, right, colorize, triangulation); + internal::generate_hyper_cube<2, 2>(left, right, colorize, triangulation); else if ((dim == 2) && (spacedim == 3)) - internal::generate_hyper_cube<2,3>(left, right, colorize, triangulation); + internal::generate_hyper_cube<2, 3>(left, right, colorize, triangulation); else - internal::generate_hyper_cube<3,3>(left, right, colorize, triangulation); + internal::generate_hyper_cube<3, 3>(left, right, colorize, triangulation); } - void TriangulationWrapper::generate_simplex(boost::python::list &vertices) + void + TriangulationWrapper::generate_simplex(boost::python::list &vertices) { - AssertThrow(boost::python::len(vertices) == dim+1, + AssertThrow(boost::python::len(vertices) == dim + 1, ExcMessage("The number of vertices should be equal to dim+1.")); - AssertThrow(dim == spacedim, - ExcMessage("This function is only implemented for dim equal to spacedim.")); + AssertThrow( + dim == spacedim, + ExcMessage( + "This function is only implemented for dim equal to spacedim.")); // Extract the PointWrapper object from the python list - std::vector wrapped_points(dim+1); - for (int i=0; i wrapped_points(dim + 1); + for (int i = 0; i < dim + 1; ++i) { wrapped_points[i] = boost::python::extract(vertices[i]); AssertThrow(wrapped_points[i].get_dim() == dim, @@ -564,284 +634,369 @@ namespace python - void TriangulationWrapper::generate_subdivided_hyper_cube(const unsigned int repetitions, - const double left, - const double right) + void + TriangulationWrapper::generate_subdivided_hyper_cube( + const unsigned int repetitions, + const double left, + const double right) { if ((dim == 2) && (spacedim == 2)) - internal::generate_subdivided_hyper_cube<2,2>(repetitions, left, right, triangulation); + internal::generate_subdivided_hyper_cube<2, 2>(repetitions, + left, + right, + triangulation); else if ((dim == 2) && (spacedim == 3)) - internal::generate_subdivided_hyper_cube<2,3>(repetitions, left, right, triangulation); + internal::generate_subdivided_hyper_cube<2, 3>(repetitions, + left, + right, + triangulation); else - internal::generate_subdivided_hyper_cube<3,3>(repetitions, left, right, triangulation); + internal::generate_subdivided_hyper_cube<3, 3>(repetitions, + left, + right, + triangulation); } - void TriangulationWrapper::generate_hyper_rectangle(PointWrapper &p1, - PointWrapper &p2, - const bool colorize) + void + TriangulationWrapper::generate_hyper_rectangle(PointWrapper &p1, + PointWrapper &p2, + const bool colorize) { if ((dim == 2) && (spacedim == 2)) - internal::generate_hyper_rectangle<2,2>(p1, p2, colorize, triangulation); + internal::generate_hyper_rectangle<2, 2>(p1, p2, colorize, triangulation); else if ((dim == 2) && (spacedim == 3)) - internal::generate_hyper_rectangle<2,3>(p1, p2, colorize, triangulation); + internal::generate_hyper_rectangle<2, 3>(p1, p2, colorize, triangulation); else - internal::generate_hyper_rectangle<3,3>(p1, p2, colorize, triangulation); + internal::generate_hyper_rectangle<3, 3>(p1, p2, colorize, triangulation); } - void TriangulationWrapper::generate_subdivided_hyper_rectangle(boost::python::list &repetition_list, - PointWrapper &p1, - PointWrapper &p2, - const bool colorize) + void + TriangulationWrapper::generate_subdivided_hyper_rectangle( + boost::python::list &repetition_list, + PointWrapper & p1, + PointWrapper & p2, + const bool colorize) { - AssertThrow(boost::python::len(repetition_list) == dim, - ExcMessage("The list of repetitions must have the same length as the number of dimension.")); + AssertThrow( + boost::python::len(repetition_list) == dim, + ExcMessage( + "The list of repetitions must have the same length as the number of dimension.")); // Extract the repetitions from the python list std::vector repetitions(dim); - for (int i=0; i(repetition_list[i]); if ((dim == 2) && (spacedim == 2)) - internal::generate_subdivided_hyper_rectangle<2,2>(repetitions, p1, p2, colorize, - triangulation); + internal::generate_subdivided_hyper_rectangle<2, 2>( + repetitions, p1, p2, colorize, triangulation); else if ((dim == 2) && (spacedim == 3)) - internal::generate_subdivided_hyper_rectangle<2,3>(repetitions, p1, p2, colorize, - triangulation); + internal::generate_subdivided_hyper_rectangle<2, 3>( + repetitions, p1, p2, colorize, triangulation); else - internal::generate_subdivided_hyper_rectangle<3,3>(repetitions, p1, p2, colorize, - triangulation); + internal::generate_subdivided_hyper_rectangle<3, 3>( + repetitions, p1, p2, colorize, triangulation); } - void TriangulationWrapper::generate_subdivided_steps_hyper_rectangle(boost::python::list &step_sizes_list, - PointWrapper &p1, - PointWrapper &p2, - const bool colorize) + void + TriangulationWrapper::generate_subdivided_steps_hyper_rectangle( + boost::python::list &step_sizes_list, + PointWrapper & p1, + PointWrapper & p2, + const bool colorize) { - AssertThrow(spacedim == dim, - ExcMessage("This function is only implemented for dim equal to spacedim.")); - AssertThrow(boost::python::len(step_sizes_list) == dim, - ExcMessage("The list of step_sizes must have the same length as the number of dimension.")); + AssertThrow( + spacedim == dim, + ExcMessage( + "This function is only implemented for dim equal to spacedim.")); + AssertThrow( + boost::python::len(step_sizes_list) == dim, + ExcMessage( + "The list of step_sizes must have the same length as the number of dimension.")); // Extract the step sizes from the python list std::vector> step_sizes(dim); - for (int i=0; i(step_sizes_list[i][j]); - } + for (int i = 0; i < dim; ++i) + { + step_sizes[i].resize(boost::python::len(step_sizes_list[i])); + for (unsigned int j = 0; j < step_sizes[i].size(); ++j) + step_sizes[i][j] = + boost::python::extract(step_sizes_list[i][j]); + } if (dim == 2) - internal::generate_subdivided_steps_hyper_rectangle<2>(step_sizes, - p1, p2, colorize, triangulation); + internal::generate_subdivided_steps_hyper_rectangle<2>( + step_sizes, p1, p2, colorize, triangulation); else - internal::generate_subdivided_steps_hyper_rectangle<3>(step_sizes, - p1, p2, colorize, triangulation); + internal::generate_subdivided_steps_hyper_rectangle<3>( + step_sizes, p1, p2, colorize, triangulation); } - void TriangulationWrapper::generate_subdivided_material_hyper_rectangle(boost::python::list &spacing_list, - PointWrapper &p, - boost::python::list &material_id_list, - const bool colorize) + void + TriangulationWrapper::generate_subdivided_material_hyper_rectangle( + boost::python::list &spacing_list, + PointWrapper & p, + boost::python::list &material_id_list, + const bool colorize) { - AssertThrow(spacedim == dim, - ExcMessage("This function is only implemented for dim equal to spacedim.")); - AssertThrow(boost::python::len(spacing_list) == dim, - ExcMessage("The list of spacing must have the same length as the number of dimension.")); + AssertThrow( + spacedim == dim, + ExcMessage( + "This function is only implemented for dim equal to spacedim.")); + AssertThrow( + boost::python::len(spacing_list) == dim, + ExcMessage( + "The list of spacing must have the same length as the number of dimension.")); // Extract the spacing and the material ID from the python list std::vector> spacing(dim); - for (int i=0; i(spacing_list[i][j]); - } + for (int i = 0; i < dim; ++i) + { + spacing[i].resize(boost::python::len(spacing_list[i])); + for (unsigned int j = 0; j < spacing[i].size(); ++j) + spacing[i][j] = boost::python::extract(spacing_list[i][j]); + } if (dim == 2) - { - const unsigned int index_0 = boost::python::len(material_id_list); - const unsigned int index_1 = boost::python::len(material_id_list[0]); - Table<2, types::material_id> material_ids(index_0, index_1); - for (unsigned int i=0; i because boost will throw - // an exception if we try to extract -1 - material_ids[i][j] = boost::python::extract(material_id_list[i][j]); - - internal::generate_subdivided_material_hyper_rectangle<2>(spacing, p, - material_ids, colorize, triangulation); - } - else - { - const unsigned int index_0 = boost::python::len(material_id_list); - const unsigned int index_1 = boost::python::len(material_id_list[0]); - const unsigned int index_2 = boost::python::len(material_id_list[0][0]); - Table<3, types::material_id> material_ids(index_0, index_1, index_2); - for (unsigned int i=0; i(material_id_list[i][j][k]); - internal::generate_subdivided_material_hyper_rectangle<3>(spacing, p, - material_ids, colorize, triangulation); - } + { + const unsigned int index_0 = boost::python::len(material_id_list); + const unsigned int index_1 = boost::python::len(material_id_list[0]); + Table<2, types::material_id> material_ids(index_0, index_1); + for (unsigned int i = 0; i < index_0; ++i) + for (unsigned int j = 0; j < index_1; ++j) + // We cannot use extract because boost will + // throw an exception if we try to extract -1 + material_ids[i][j] = + boost::python::extract(material_id_list[i][j]); + + internal::generate_subdivided_material_hyper_rectangle<2>( + spacing, p, material_ids, colorize, triangulation); + } + else + { + const unsigned int index_0 = boost::python::len(material_id_list); + const unsigned int index_1 = boost::python::len(material_id_list[0]); + const unsigned int index_2 = boost::python::len(material_id_list[0][0]); + Table<3, types::material_id> material_ids(index_0, index_1, index_2); + for (unsigned int i = 0; i < index_0; ++i) + for (unsigned int j = 0; j < index_1; ++j) + for (unsigned int k = 0; k < index_2; ++k) + material_ids[i][j][k] = + boost::python::extract(material_id_list[i][j][k]); + internal::generate_subdivided_material_hyper_rectangle<3>( + spacing, p, material_ids, colorize, triangulation); + } } - void TriangulationWrapper::generate_cheese(boost::python::list &holes_list) + void + TriangulationWrapper::generate_cheese(boost::python::list &holes_list) { - const unsigned int size = boost::python::len(holes_list); + const unsigned int size = boost::python::len(holes_list); std::vector holes(size); - for (unsigned int i=0; i(holes_list[i]); if ((dim == 2) && (spacedim == 2)) - internal::generate_cheese<2,2>(holes, triangulation); + internal::generate_cheese<2, 2>(holes, triangulation); else if ((dim == 2) && (spacedim == 3)) - internal::generate_cheese<2,3>(holes, triangulation); + internal::generate_cheese<2, 3>(holes, triangulation); else - internal::generate_cheese<3,3>(holes, triangulation); + internal::generate_cheese<3, 3>(holes, triangulation); } - void TriangulationWrapper::generate_general_cell(boost::python::list &vertices, - const bool colorize) + void + TriangulationWrapper::generate_general_cell(boost::python::list &vertices, + const bool colorize) { - AssertThrow(spacedim == dim, - ExcMessage("This function is only implementd for dim equal to spacedim.")); + AssertThrow( + spacedim == dim, + ExcMessage( + "This function is only implementd for dim equal to spacedim.")); // Extract the PointWrapper object from the python list const int size = boost::python::len(vertices); AssertThrow(size > 0, ExcMessage("The vertices list is empty.")); std::vector wrapped_points(size); - for (int i=0; i(vertices[i]); + for (int i = 0; i < size; ++i) + wrapped_points[i] = boost::python::extract(vertices[i]); if (dim == 2) - internal::generate_general_cell<2>(wrapped_points, colorize, triangulation); + internal::generate_general_cell<2>(wrapped_points, + colorize, + triangulation); else - internal::generate_general_cell<3>(wrapped_points, colorize, triangulation); + internal::generate_general_cell<3>(wrapped_points, + colorize, + triangulation); } - void TriangulationWrapper::generate_parallelogram(boost::python::list &corners, - const bool colorize) + void + TriangulationWrapper::generate_parallelogram(boost::python::list &corners, + const bool colorize) { - AssertThrow(spacedim == dim, - ExcMessage("This function is only implemented for dim equal to spacedim.")); + AssertThrow( + spacedim == dim, + ExcMessage( + "This function is only implemented for dim equal to spacedim.")); // Extract the PointWrapper object from the python list - AssertThrow(boost::python::len(corners) == dim, - ExcMessage("The list of corners must have the same length as the number of dimension.")); + AssertThrow( + boost::python::len(corners) == dim, + ExcMessage( + "The list of corners must have the same length as the number of dimension.")); std::vector wrapped_points(dim); - for (int i=0; i(corners[i]); + for (int i = 0; i < dim; ++i) + wrapped_points[i] = boost::python::extract(corners[i]); if (dim == 2) - internal::generate_parallelogram<2>(wrapped_points, colorize, triangulation); + internal::generate_parallelogram<2>(wrapped_points, + colorize, + triangulation); else - internal::generate_parallelogram<3>(wrapped_points, colorize, triangulation); + internal::generate_parallelogram<3>(wrapped_points, + colorize, + triangulation); } - void TriangulationWrapper::generate_parallelepiped(boost::python::list &corners, - const bool colorize) + void + TriangulationWrapper::generate_parallelepiped(boost::python::list &corners, + const bool colorize) { - AssertThrow(spacedim == dim, - ExcMessage("This function is only implemented for dim equal to spacedim.")); + AssertThrow( + spacedim == dim, + ExcMessage( + "This function is only implemented for dim equal to spacedim.")); // Extract the PointWrapper object from the python list - AssertThrow(boost::python::len(corners) == dim, - ExcMessage("The list of corners must have the same length as the number of dimension.")); + AssertThrow( + boost::python::len(corners) == dim, + ExcMessage( + "The list of corners must have the same length as the number of dimension.")); std::vector wrapped_points(dim); - for (int i=0; i(corners[i]); + for (int i = 0; i < dim; ++i) + wrapped_points[i] = boost::python::extract(corners[i]); if (dim == 2) - internal::generate_parallelepiped<2>(wrapped_points, colorize, triangulation); + internal::generate_parallelepiped<2>(wrapped_points, + colorize, + triangulation); else - internal::generate_parallelepiped<3>(wrapped_points, colorize, triangulation); + internal::generate_parallelepiped<3>(wrapped_points, + colorize, + triangulation); } - void TriangulationWrapper::generate_fixed_subdivided_parallelepiped( - const unsigned int n_subdivisions, + void + TriangulationWrapper::generate_fixed_subdivided_parallelepiped( + const unsigned int n_subdivisions, boost::python::list &corners, const bool colorize) { - AssertThrow(spacedim == dim, - ExcMessage("This function is only implemented for dim equal to spacedim.")); + AssertThrow( + spacedim == dim, + ExcMessage( + "This function is only implemented for dim equal to spacedim.")); // Extract the PointWrapper object from the python list - AssertThrow(boost::python::len(corners) == dim, - ExcMessage("The list of corners must have the same length as the number of dimension.")); + AssertThrow( + boost::python::len(corners) == dim, + ExcMessage( + "The list of corners must have the same length as the number of dimension.")); std::vector wrapped_points(dim); - for (int i=0; i(corners[i]); + for (int i = 0; i < dim; ++i) + wrapped_points[i] = boost::python::extract(corners[i]); if ((dim == 2) && (spacedim == 2)) - internal::generate_fixed_subdivided_parallelepiped<2>(n_subdivisions, - wrapped_points, colorize, triangulation); + internal::generate_fixed_subdivided_parallelepiped<2>(n_subdivisions, + wrapped_points, + colorize, + triangulation); else - internal::generate_fixed_subdivided_parallelepiped<3>(n_subdivisions, - wrapped_points, colorize, triangulation); + internal::generate_fixed_subdivided_parallelepiped<3>(n_subdivisions, + wrapped_points, + colorize, + triangulation); } - void TriangulationWrapper::generate_varying_subdivided_parallelepiped( + void + TriangulationWrapper::generate_varying_subdivided_parallelepiped( boost::python::list &n_subdivisions, boost::python::list &corners, const bool colorize) { - AssertThrow(spacedim == dim, - ExcMessage("This function is only implemented for dim equal to spacedim.")); + AssertThrow( + spacedim == dim, + ExcMessage( + "This function is only implemented for dim equal to spacedim.")); // Extract the subdivisions from the python list - AssertThrow(boost::python::len(n_subdivisions) == dim, - ExcMessage("The list of subdivisions must have the same length as the number of dimension.")); + AssertThrow( + boost::python::len(n_subdivisions) == dim, + ExcMessage( + "The list of subdivisions must have the same length as the number of dimension.")); std::vector subdivisions(dim); - for (int i=0; i(n_subdivisions[i]); + for (int i = 0; i < dim; ++i) + subdivisions[i] = boost::python::extract(n_subdivisions[i]); // Extract the PointWrapper object from the python list - AssertThrow(boost::python::len(corners) == dim, - ExcMessage("The list of corners must have the same length as the number of dimension.")); + AssertThrow( + boost::python::len(corners) == dim, + ExcMessage( + "The list of corners must have the same length as the number of dimension.")); std::vector wrapped_points(dim); - for (int i=0; i(corners[i]); + for (int i = 0; i < dim; ++i) + wrapped_points[i] = boost::python::extract(corners[i]); if (dim == 2) - internal::generate_varying_subdivided_parallelepiped<2>(subdivisions, - wrapped_points, colorize, triangulation); + internal::generate_varying_subdivided_parallelepiped<2>(subdivisions, + wrapped_points, + colorize, + triangulation); else - internal::generate_varying_subdivided_parallelepiped<3>(subdivisions, - wrapped_points, colorize, triangulation); + internal::generate_varying_subdivided_parallelepiped<3>(subdivisions, + wrapped_points, + colorize, + triangulation); } - void TriangulationWrapper::generate_enclosed_hyper_cube(const double left, - const double right, - const double thickness, - const bool colorize) + void + TriangulationWrapper::generate_enclosed_hyper_cube(const double left, + const double right, + const double thickness, + const bool colorize) { - AssertThrow(spacedim == dim, - ExcMessage("This function is only implemented for dim equal to spacedim.")); + AssertThrow( + spacedim == dim, + ExcMessage( + "This function is only implemented for dim equal to spacedim.")); if (dim == 2) - internal::generate_enclosed_hyper_cube<2>(left, right, thickness, colorize, triangulation); + internal::generate_enclosed_hyper_cube<2>( + left, right, thickness, colorize, triangulation); else - internal::generate_enclosed_hyper_cube<3>(left, right, thickness, colorize, triangulation); + internal::generate_enclosed_hyper_cube<3>( + left, right, thickness, colorize, triangulation); } - - void TriangulationWrapper::generate_hyper_ball(PointWrapper ¢er, - const double radius) + + void + TriangulationWrapper::generate_hyper_ball(PointWrapper ¢er, + const double radius) { - AssertThrow(dim == spacedim, - ExcMessage("This function is only implemented for dim equal to spacedim.")); + AssertThrow( + dim == spacedim, + ExcMessage( + "This function is only implemented for dim equal to spacedim.")); if (dim == 2) internal::generate_hyper_ball<2>(center, radius, triangulation); else @@ -849,21 +1004,27 @@ namespace python } - void TriangulationWrapper::generate_hyper_sphere(PointWrapper ¢er, - const double radius) + void + TriangulationWrapper::generate_hyper_sphere(PointWrapper ¢er, + const double radius) { - AssertThrow(spacedim == dim+1, - ExcMessage("This function is only implemented for spacedim equal to dim+1.")); - internal::generate_hyper_sphere<2,3>(center, radius, triangulation); + AssertThrow( + spacedim == dim + 1, + ExcMessage( + "This function is only implemented for spacedim equal to dim+1.")); + internal::generate_hyper_sphere<2, 3>(center, radius, triangulation); } - void TriangulationWrapper::generate_quarter_hyper_ball(PointWrapper ¢er, - const double radius) + void + TriangulationWrapper::generate_quarter_hyper_ball(PointWrapper ¢er, + const double radius) { - AssertThrow(dim == spacedim, - ExcMessage("This function is only implemented for dim equal to spacedim.")); + AssertThrow( + dim == spacedim, + ExcMessage( + "This function is only implemented for dim equal to spacedim.")); if (dim == 2) internal::generate_quarter_hyper_ball<2>(center, radius, triangulation); else @@ -871,11 +1032,14 @@ namespace python } - void TriangulationWrapper::generate_half_hyper_ball(PointWrapper ¢er, + void + TriangulationWrapper::generate_half_hyper_ball(PointWrapper ¢er, const double radius) { - AssertThrow(dim == spacedim, - ExcMessage("This function is only implemented for dim equal to spacedim.")); + AssertThrow( + dim == spacedim, + ExcMessage( + "This function is only implemented for dim equal to spacedim.")); if (dim == 2) internal::generate_half_hyper_ball<2>(center, radius, triangulation); else @@ -884,146 +1048,174 @@ namespace python - void TriangulationWrapper::shift(boost::python::list &shift_list) + void + TriangulationWrapper::shift(boost::python::list &shift_list) { AssertThrow(boost::python::len(shift_list) == spacedim, - ExcMessage("Size of the shift vector is not equal to spacedim.")); + ExcMessage( + "Size of the shift vector is not equal to spacedim.")); if ((dim == 2) && (spacedim == 2)) - internal::shift<2,2>(shift_list, triangulation); - else if ((dim ==2) && (spacedim == 3)) - internal::shift<2,3>(shift_list, triangulation); + internal::shift<2, 2>(shift_list, triangulation); + else if ((dim == 2) && (spacedim == 3)) + internal::shift<2, 3>(shift_list, triangulation); else - internal::shift<3,3>(shift_list, triangulation); + internal::shift<3, 3>(shift_list, triangulation); } - void TriangulationWrapper::merge_triangulations(TriangulationWrapper &triangulation_1, - TriangulationWrapper &triangulation_2) + void + TriangulationWrapper::merge_triangulations( + TriangulationWrapper &triangulation_1, + TriangulationWrapper &triangulation_2) { - AssertThrow(triangulation_1.get_dim() == triangulation_2.get_dim(), - ExcMessage("Triangulation_1 and Triangulation_2 should have the same dimension.")); - AssertThrow(dim == triangulation_2.get_dim(), - ExcMessage("Triangulation and Triangulation_2 should have the same dimension.")); - AssertThrow(triangulation_1.get_spacedim() == triangulation_2.get_spacedim(), - ExcMessage("Triangulation_1 and Triangulation_2 should have the same space dimension.")); - AssertThrow(spacedim == triangulation_2.get_spacedim(), - ExcMessage("Triangulation and Triangulation_2 should have the same space dimension.")); - - if ((triangulation_1.get_dim() == 2) && (triangulation_1.get_spacedim() == 2)) - internal::merge_triangulations<2,2>(triangulation_1, triangulation_2, triangulation); - else if ((triangulation_1.get_dim() == 2) && (triangulation_1.get_spacedim() == 3)) - internal::merge_triangulations<2,3>(triangulation_1, triangulation_2, triangulation); + AssertThrow( + triangulation_1.get_dim() == triangulation_2.get_dim(), + ExcMessage( + "Triangulation_1 and Triangulation_2 should have the same dimension.")); + AssertThrow( + dim == triangulation_2.get_dim(), + ExcMessage( + "Triangulation and Triangulation_2 should have the same dimension.")); + AssertThrow( + triangulation_1.get_spacedim() == triangulation_2.get_spacedim(), + ExcMessage( + "Triangulation_1 and Triangulation_2 should have the same space dimension.")); + AssertThrow( + spacedim == triangulation_2.get_spacedim(), + ExcMessage( + "Triangulation and Triangulation_2 should have the same space dimension.")); + + if ((triangulation_1.get_dim() == 2) && + (triangulation_1.get_spacedim() == 2)) + internal::merge_triangulations<2, 2>(triangulation_1, + triangulation_2, + triangulation); + else if ((triangulation_1.get_dim() == 2) && + (triangulation_1.get_spacedim() == 3)) + internal::merge_triangulations<2, 3>(triangulation_1, + triangulation_2, + triangulation); else - internal::merge_triangulations<3,3>(triangulation_1, triangulation_2, triangulation); + internal::merge_triangulations<3, 3>(triangulation_1, + triangulation_2, + triangulation); } - void TriangulationWrapper::flatten_triangulation(TriangulationWrapper &tria_out) + void + TriangulationWrapper::flatten_triangulation(TriangulationWrapper &tria_out) { - AssertThrow(dim == tria_out.get_dim(), - ExcMessage("The Triangulation and tria_out should have the same dimension.")); + AssertThrow( + dim == tria_out.get_dim(), + ExcMessage( + "The Triangulation and tria_out should have the same dimension.")); AssertThrow(spacedim >= tria_out.get_spacedim(), - ExcMessage("The Triangulation should have a spacedim greater or equal " - "to the spacedim of tria_out.")); + ExcMessage( + "The Triangulation should have a spacedim greater or equal " + "to the spacedim of tria_out.")); int spacedim_out = tria_out.get_spacedim(); if ((dim == 2) && (spacedim == 2) && (spacedim_out == 2)) - internal::flatten_triangulation<2,2,2>(triangulation, tria_out); + internal::flatten_triangulation<2, 2, 2>(triangulation, tria_out); else if ((dim == 2) && (spacedim == 3) && (spacedim_out == 2)) - internal::flatten_triangulation<2,3,2>(triangulation, tria_out); + internal::flatten_triangulation<2, 3, 2>(triangulation, tria_out); else - internal::flatten_triangulation<3,3,3>(triangulation, tria_out); + internal::flatten_triangulation<3, 3, 3>(triangulation, tria_out); } - void TriangulationWrapper::refine_global(const unsigned int n) + void + TriangulationWrapper::refine_global(const unsigned int n) { if ((dim == 2) && (spacedim == 2)) { - Triangulation<2,2> *tria = - static_cast*>(triangulation); + Triangulation<2, 2> *tria = + static_cast *>(triangulation); tria->refine_global(n); } else if ((dim == 2) && (spacedim == 3)) { - Triangulation<2,3> *tria = - static_cast*>(triangulation); + Triangulation<2, 3> *tria = + static_cast *>(triangulation); tria->refine_global(n); } else { - Triangulation<3,3> *tria = - static_cast*>(triangulation); + Triangulation<3, 3> *tria = + static_cast *>(triangulation); tria->refine_global(n); } } - void TriangulationWrapper::execute_coarsening_and_refinement() + void + TriangulationWrapper::execute_coarsening_and_refinement() { if ((dim == 2) && (spacedim == 2)) { - Triangulation<2,2> *tria = - static_cast*>(triangulation); + Triangulation<2, 2> *tria = + static_cast *>(triangulation); tria->execute_coarsening_and_refinement(); } else if ((dim == 2) && (spacedim == 3)) { - Triangulation<2,3> *tria = - static_cast*>(triangulation); + Triangulation<2, 3> *tria = + static_cast *>(triangulation); tria->execute_coarsening_and_refinement(); } else { - Triangulation<3,3> *tria = - static_cast*>(triangulation); + Triangulation<3, 3> *tria = + static_cast *>(triangulation); tria->execute_coarsening_and_refinement(); } } - void TriangulationWrapper::write(const std::string &filename, - const std::string format) const + void + TriangulationWrapper::write(const std::string &filename, + const std::string format) const { if ((dim == 2) && (spacedim == 2)) - internal::write<2,2>(filename, format, triangulation); + internal::write<2, 2>(filename, format, triangulation); else if ((dim == 2) && (spacedim == 3)) - internal::write<2,3>(filename, format, triangulation); + internal::write<2, 3>(filename, format, triangulation); else - internal::write<3,3>(filename, format, triangulation); + internal::write<3, 3>(filename, format, triangulation); } - void TriangulationWrapper::save(const std::string &filename) const + void + TriangulationWrapper::save(const std::string &filename) const { - std::ofstream ofs(filename); + std::ofstream ofs(filename); boost::archive::text_oarchive oa(ofs); if ((dim == 2) && (spacedim == 2)) { - Triangulation<2,2> *tria = - static_cast*>(triangulation); + Triangulation<2, 2> *tria = + static_cast *>(triangulation); oa << *tria; } else if ((dim == 2) && (spacedim == 3)) { { - Triangulation<2,3> *tria = - static_cast*>(triangulation); + Triangulation<2, 3> *tria = + static_cast *>(triangulation); oa << *tria; } } else { - Triangulation<3,3> *tria = - static_cast*>(triangulation); + Triangulation<3, 3> *tria = + static_cast *>(triangulation); oa << *tria; } @@ -1031,29 +1223,30 @@ namespace python - void TriangulationWrapper::load(const std::string &filename) + void + TriangulationWrapper::load(const std::string &filename) { - std::ifstream ifs(filename); + std::ifstream ifs(filename); boost::archive::text_iarchive ia(ifs); if ((dim == 2) && (spacedim == 2)) { - Triangulation<2,2> *tria = - static_cast*>(triangulation); + Triangulation<2, 2> *tria = + static_cast *>(triangulation); ia >> *tria; } else if ((dim == 2) && (spacedim == 3)) { - Triangulation<2,3> *tria = - static_cast*>(triangulation); + Triangulation<2, 3> *tria = + static_cast *>(triangulation); ia >> *tria; } else { Triangulation<3> *tria = - static_cast*>(triangulation); + static_cast *>(triangulation); ia >> *tria; } @@ -1061,19 +1254,21 @@ namespace python - boost::python::list TriangulationWrapper::active_cells() + boost::python::list + TriangulationWrapper::active_cells() { if ((dim == 2) && (spacedim == 2)) - return internal::active_cells<2,2>(*this); + return internal::active_cells<2, 2>(*this); else if ((dim == 2) && (spacedim == 3)) - return internal::active_cells<2,3>(*this); + return internal::active_cells<2, 3>(*this); else - return internal::active_cells<3,3>(*this); + return internal::active_cells<3, 3>(*this); } - void TriangulationWrapper::setup(const std::string &dimension, - const std::string &spacedimension) + void + TriangulationWrapper::setup(const std::string &dimension, + const std::string &spacedimension) { if ((dimension.compare("2D") == 0) || (dimension.compare("2d") == 0)) { @@ -1082,30 +1277,31 @@ namespace python if ((spacedimension.compare("2D") == 0) || (spacedimension.compare("2d") == 0)) { - spacedim = 2; - triangulation = new Triangulation<2,2>(); + spacedim = 2; + triangulation = new Triangulation<2, 2>(); } else if ((spacedimension.compare("3D") == 0) || (spacedimension.compare("3d") == 0)) { - spacedim = 3; - triangulation = new Triangulation<2,3>(); + spacedim = 3; + triangulation = new Triangulation<2, 3>(); } else - AssertThrow(false, ExcMessage("Spacedimension needs to be 2D or 3D.")); + AssertThrow(false, + ExcMessage("Spacedimension needs to be 2D or 3D.")); } else if ((dimension.compare("3D") == 0) || (dimension.compare("3d") == 0)) { if ((spacedimension.compare("3D") != 0) && (spacedimension.compare("3d") != 0)) AssertThrow(false, ExcMessage("Spacedimension needs to be 3D.")); - dim = 3; - spacedim = 3; - triangulation = new Triangulation<3,3>(); + dim = 3; + spacedim = 3; + triangulation = new Triangulation<3, 3>(); } else AssertThrow(false, ExcMessage("Dimension needs to be 2D or 3D.")); } -} +} // namespace python DEAL_II_NAMESPACE_CLOSE diff --git a/contrib/python-bindings/source/wrappers.cc b/contrib/python-bindings/source/wrappers.cc index 52bba15d04..d19257597c 100644 --- a/contrib/python-bindings/source/wrappers.cc +++ b/contrib/python-bindings/source/wrappers.cc @@ -14,6 +14,7 @@ // --------------------------------------------------------------------- #include + #include #include @@ -22,11 +23,15 @@ DEAL_II_NAMESPACE_OPEN namespace python { - void export_tria_accessor(); - void export_cell_accessor(); - void export_point(); - void export_triangulation(); -} + void + export_tria_accessor(); + void + export_cell_accessor(); + void + export_point(); + void + export_triangulation(); +} // namespace python DEAL_II_NAMESPACE_CLOSE @@ -36,8 +41,7 @@ char const *pydealii_docstring = "======== \n" "This module contains the python bindings to deal.II. \n" "The Debug module uses deal.II compiled in Debug mode while \n" - "the Release module uses deal.II compiled in Release mode. \n" - ; + "the Release module uses deal.II compiled in Release mode. \n"; #ifdef DEBUG diff --git a/contrib/utilities/indent b/contrib/utilities/indent index 748eabf3e6..0034b4db1a 100755 --- a/contrib/utilities/indent +++ b/contrib/utilities/indent @@ -56,15 +56,15 @@ checks # Process all source and header files: # -process_changed "tests include source examples" ".*\.(cc|h|cu|cuh)" format_file +process_changed "tests include source examples contrib/python-bindings" ".*\.(cc|h|cu|cuh)" format_file process_changed "source" ".*\.inst.in" format_inst # # Fix permissions and convert to unix line ending if necessary: # -process_changed "tests include source examples" \ +process_changed "tests include source examples contrib/python-bindings" \ ".*\.(cc|h|cu|cuh|inst.in|output.*|cmake)" fix_permissions -process_changed "tests include source examples" \ +process_changed "tests include source examples contrib/python-bindings" \ ".*\.(cc|h|cu|cuh|inst.in|cmake)" dos_to_unix diff --git a/contrib/utilities/indent-all b/contrib/utilities/indent-all index 8682646ac6..0f4e5b3fa1 100755 --- a/contrib/utilities/indent-all +++ b/contrib/utilities/indent-all @@ -60,15 +60,15 @@ checks # Process all source and header files: # -process "tests include source examples" ".*\.(cc|h|cu|cuh)" format_file +process "tests include source examples contrib/python-bindings" ".*\.(cc|h|cu|cuh)" format_file process "source" ".*\.inst.in" format_inst # # Fix permissions and convert to unix line ending if necessary: # -process "tests include source examples" \ +process "tests include source examples contrib/python-bindings" \ ".*\.(cc|h|cu|cuh|inst.in|output.*|cmake)" fix_permissions -process "tests include source examples" \ +process "tests include source examples contrib/python-bindings" \ ".*\.(cc|h|cu|cuh|inst.in|cmake)" dos_to_unix diff --git a/doc/news/changes/minor/20191115Grayver b/doc/news/changes/minor/20191115Grayver new file mode 100644 index 0000000000..dbe21372f0 --- /dev/null +++ b/doc/news/changes/minor/20191115Grayver @@ -0,0 +1,3 @@ +Changed: Indent scripts now also format files related to the python bindings +
+(Alexander Grayver, 2019/11/15) -- 2.39.5