From 3a06398c8217dcba6d84ab179b0a89bd290d6457 Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Fri, 6 Apr 2018 15:04:08 +0200 Subject: [PATCH] Implement clone for each standard Manifold class. --- include/deal.II/grid/manifold_lib.h | 74 ++++++++++++++++++++++--- source/grid/manifold_lib.cc | 85 ++++++++++++++++++++++++++++- 2 files changed, 148 insertions(+), 11 deletions(-) diff --git a/include/deal.II/grid/manifold_lib.h b/include/deal.II/grid/manifold_lib.h index 9bfc7b3f66..4fd7cf0b61 100644 --- a/include/deal.II/grid/manifold_lib.h +++ b/include/deal.II/grid/manifold_lib.h @@ -71,13 +71,18 @@ public: */ PolarManifold(const Point center = Point()); + /** + * Make a clone of this Manifold object. + */ + virtual std::unique_ptr > clone() const override; + /** * Pull back the given point from the Euclidean space. Will return the polar * coordinates associated with the point @p space_point. Only used when * spacedim = 2. */ virtual Point - pull_back(const Point &space_point) const; + pull_back(const Point &space_point) const override; /** * Given a point in the spherical coordinate system, this method returns the @@ -85,7 +90,7 @@ public: * Only used when spacedim = 3. */ virtual Point - push_forward(const Point &chart_point) const; + push_forward(const Point &chart_point) const override; /** * Given a point in the spacedim dimensional Euclidean space, this @@ -101,7 +106,7 @@ public: */ virtual DerivativeForm<1,spacedim,spacedim> - push_forward_gradient(const Point &chart_point) const; + push_forward_gradient(const Point &chart_point) const override; /** * The center of the spherical coordinate system. @@ -220,6 +225,11 @@ public: */ SphericalManifold(const Point center = Point()); + /** + * Make a clone of this Manifold object. + */ + virtual std::unique_ptr > clone() const override; + /** * Given any two points in space, first project them on the surface * of a sphere with unit radius, then connect them with a geodesic @@ -388,6 +398,11 @@ public: const Point &point_on_axis, const double tolerance = 1e-10); + /** + * Make a clone of this Manifold object. + */ + virtual std::unique_ptr > clone() const override; + /** * Compute the Cartesian coordinates for a point given in cylindrical * coordinates. @@ -509,13 +524,18 @@ public: */ ~FunctionManifold(); + /** + * Make a clone of this Manifold object. + */ + virtual std::unique_ptr > clone() const override; + /** * Given a point in the @p chartdim coordinate system, uses the * push_forward_function to compute the push_forward of points in @p * chartdim space dimensions to @p spacedim space dimensions. */ virtual Point - push_forward(const Point &chart_point) const; + push_forward(const Point &chart_point) const override; /** * Given a point in the chartdim dimensional Euclidean space, this @@ -539,7 +559,7 @@ public: */ virtual DerivativeForm<1,chartdim,spacedim> - push_forward_gradient(const Point &chart_point) const; + push_forward_gradient(const Point &chart_point) const override; /** * Given a point in the spacedim coordinate system, uses the @@ -547,7 +567,7 @@ public: * space dimensions to @p chartdim space dimensions. */ virtual Point - pull_back(const Point &space_point) const; + pull_back(const Point &space_point) const override; private: /** @@ -582,10 +602,36 @@ private: * pointers. */ const bool owns_pointers; + + /** + * The expresssion used to construct the push_forward function. + */ + const std::string push_forward_expression; + + /** + * The expresssion used to construct the pull_back function. + */ + const std::string pull_back_expression; + + /** + * Variable names in the chart domain. + */ + const std::string chart_vars; + + /** + * Variable names in the space domain. + */ + const std::string space_vars; + + /** + * The finite difference step to use internally. + */ + const double finite_difference_step; }; + /** * Manifold description for the surface of a Torus in three dimensions. The * Torus is assumed to be in the x-z plane. The reference coordinate system @@ -614,24 +660,29 @@ public: */ TorusManifold (const double R, const double r); + /** + * Make a clone of this Manifold object. + */ + virtual std::unique_ptr > clone() const override; + /** * Pull back operation. */ virtual Point<3> - pull_back(const Point<3> &p) const; + pull_back(const Point<3> &p) const override; /** * Push forward operation. */ virtual Point<3> - push_forward(const Point<3> &chart_point) const; + push_forward(const Point<3> &chart_point) const override; /** * Gradient. */ virtual DerivativeForm<1,3,3> - push_forward_gradient(const Point<3> &chart_point) const; + push_forward_gradient(const Point<3> &chart_point) const override; private: double r, R; @@ -781,6 +832,11 @@ public: */ TransfiniteInterpolationManifold(); + /** + * Make a clone of this Manifold object. + */ + virtual std::unique_ptr > clone() const override; + /** * Initializes the manifold with a coarse mesh. The prerequisite for using * this class is that the input triangulation is uniformly refined and the diff --git a/source/grid/manifold_lib.cc b/source/grid/manifold_lib.cc index 06547a4d54..36dff043d2 100644 --- a/source/grid/manifold_lib.cc +++ b/source/grid/manifold_lib.cc @@ -122,6 +122,15 @@ PolarManifold::PolarManifold(const Point center): +template +std::unique_ptr > +PolarManifold::clone() const +{ + return std::unique_ptr >(new PolarManifold(center)); +} + + + template Tensor<1,spacedim> PolarManifold::get_periodicity() @@ -268,6 +277,15 @@ SphericalManifold::SphericalManifold(const Point center) +template +std::unique_ptr > +SphericalManifold::clone() const +{ + return std::unique_ptr >(new SphericalManifold(center)); +} + + + template Point SphericalManifold:: @@ -948,6 +966,16 @@ CylindricalManifold::CylindricalManifold(const Tensor<1, spacedim +template +std::unique_ptr > +CylindricalManifold::clone() const +{ + return std::unique_ptr > + (new CylindricalManifold(direction, point_on_axis, tolerance)); +} + + + template Point CylindricalManifold:: @@ -1077,7 +1105,8 @@ FunctionManifold::FunctionManifold push_forward_function(&push_forward_function), pull_back_function(&pull_back_function), tolerance(tolerance), - owns_pointers(false) + owns_pointers(false), + finite_difference_step(0) { AssertDimension(push_forward_function.n_components, spacedim); AssertDimension(pull_back_function.n_components, chartdim); @@ -1098,7 +1127,12 @@ FunctionManifold::FunctionManifold ChartManifold(periodicity), const_map(const_map), tolerance(tolerance), - owns_pointers(true) + owns_pointers(true), + push_forward_expression(push_forward_expression), + pull_back_expression(pull_back_expression), + chart_vars(chart_vars), + space_vars(space_vars), + finite_difference_step(h) { FunctionParser *pf = new FunctionParser(spacedim, 0.0, h); FunctionParser *pb = new FunctionParser(chartdim, 0.0, h); @@ -1127,6 +1161,32 @@ FunctionManifold::~FunctionManifold() +template +std::unique_ptr > +FunctionManifold::clone() const +{ + if (owns_pointers == true) + { + return std::unique_ptr > + (new FunctionManifold(push_forward_expression, + pull_back_expression, + this->get_periodicity(), + const_map, + chart_vars, + space_vars, + tolerance, + finite_difference_step)); + } + else + return std::unique_ptr > + (new FunctionManifold(*push_forward_function, + *pull_back_function, + this->get_periodicity(), + tolerance)); +} + + + template Point FunctionManifold::push_forward(const Point &chart_point) const @@ -1229,6 +1289,15 @@ TorusManifold::TorusManifold (const double R, const double r) +template +std::unique_ptr > +TorusManifold::clone() const +{ + return std::unique_ptr >(new TorusManifold(R,r)); +} + + + template DerivativeForm<1,3,3> TorusManifold::push_forward_gradient(const Point<3> &chart_point) const @@ -1270,6 +1339,18 @@ TransfiniteInterpolationManifold::TransfiniteInterpolationManifold +template +std::unique_ptr > +TransfiniteInterpolationManifold::clone() const +{ + auto ptr = new TransfiniteInterpolationManifold(); + if (triangulation) + ptr->initialize(*triangulation); + return std::unique_ptr >(ptr); +} + + + template void TransfiniteInterpolationManifold -- 2.39.5