From af556263fb8dac5f7fd9d7e946c03f0f2cefe6ca Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Sun, 8 Apr 2018 10:25:50 +0200 Subject: [PATCH] Fixed failing tests. --- examples/step-53/step-53.cc | 18 +++++++- include/deal.II/grid/composition_manifold.h | 14 ++++++ include/deal.II/grid/manifold_lib.h | 2 +- .../deal.II/grid/tensor_product_manifold.h | 23 ++++++++-- source/grid/grid_tools.cc | 4 +- source/grid/manifold.cc | 3 +- source/grid/manifold_lib.cc | 46 +++++++++++-------- tests/bits/distorted_cells_06.cc | 5 ++ tests/grid/grid_test.cc | 7 ++- tests/manifold/chart_manifold_01.cc | 12 +++-- tests/manifold/chart_manifold_01_embedded.cc | 12 +++-- tests/manifold/chart_manifold_02.cc | 14 ++++-- tests/manifold/chart_manifold_02_embedded.cc | 13 ++++-- tests/manifold/chart_manifold_03.cc | 11 +++-- tests/manifold/chart_manifold_04.cc | 12 +++-- tests/manifold/chart_manifold_04_embedded.cc | 13 ++++-- tests/manifold/chart_manifold_05.cc | 12 +++-- tests/manifold/chart_manifold_05_embedded.cc | 12 +++-- tests/manifold/chart_manifold_06.cc | 7 +++ tests/manifold/chart_manifold_06_embedded.cc | 12 +++-- tests/manifold/chart_manifold_07.cc | 13 ++++-- tests/manifold/chart_manifold_08.cc | 12 +++-- tests/manifold/projection_manifold_01.cc | 6 +++ tests/manifold/transfinite_manifold_05.cc | 8 ++-- tests/mappings/mapping_q_convergence.cc | 12 ++++- tests/mappings/mapping_q_manifold_01.cc | 12 ++++- 26 files changed, 242 insertions(+), 73 deletions(-) diff --git a/examples/step-53/step-53.cc b/examples/step-53/step-53.cc index eb20352517..e8d4a9b2ce 100644 --- a/examples/step-53/step-53.cc +++ b/examples/step-53/step-53.cc @@ -46,6 +46,13 @@ #include #include +// The last include file is required because we will be using a feature that is +// not part of the cxx11 standard. The deal.II library, however, can be installed +// with a cxx11 compliant compiler, without assuming that cxx14 or cxx17 features are +// available. As some of these features are very useful, we provide their +// implementation in an internal namespace, if the compiler does not support them: +#include + #include #include @@ -254,11 +261,18 @@ namespace Step53 // This function is required by the interface of the Manifold base - // class, and allows you to clone the AfricaGeometry class: + // class, and allows you to clone the AfricaGeometry class. This is + // where we use a feature that is only available in cxx14, namely the + // make_unique function, that simplifies the creation of + // std::unique_ptr objects. Notice that, while the function returns a + // std::unique_ptr >, we internally create a + // unique_ptr. C++11 knows how to handle these cases, + // and is able to transform a unique pointer to a derived class to a + // unique pointer to its base class automatically: std::unique_ptr > AfricaGeometry::clone() const { - return std::unique_ptr >(new AfricaGeometry()); + return std_cxx14::make_unique(); } diff --git a/include/deal.II/grid/composition_manifold.h b/include/deal.II/grid/composition_manifold.h index 02b8164224..da5ca09562 100644 --- a/include/deal.II/grid/composition_manifold.h +++ b/include/deal.II/grid/composition_manifold.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -75,6 +76,11 @@ public: CompositionManifold(const ChartManifold &F, const ChartManifold &G); + /** + * Make a clone of this Manifold. + */ + virtual std::unique_ptr > clone() const override; + /** * Pull back the given point in spacedim to the Euclidean chartdim * dimensional space. This function calls the pull_back() function @@ -135,6 +141,14 @@ CompositionManifold::Compositi } +template +std::unique_ptr > +CompositionManifold::clone() const +{ + return std_cxx14::make_unique >(*F, *G); +} + template diff --git a/include/deal.II/grid/manifold_lib.h b/include/deal.II/grid/manifold_lib.h index 4fd7cf0b61..6756e21761 100644 --- a/include/deal.II/grid/manifold_lib.h +++ b/include/deal.II/grid/manifold_lib.h @@ -993,7 +993,7 @@ private: std::vector coarse_cell_is_flat; /** - * A flat manifold used to compute new points in the chart space where it we + * A flat manifold used to compute new points in the chart space where we * use a FlatManifold description. */ FlatManifold chart_manifold; diff --git a/include/deal.II/grid/tensor_product_manifold.h b/include/deal.II/grid/tensor_product_manifold.h index 3253b3d34d..34fa3b6a5e 100644 --- a/include/deal.II/grid/tensor_product_manifold.h +++ b/include/deal.II/grid/tensor_product_manifold.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -82,26 +83,32 @@ public: const ChartManifold &manifold_A, const ChartManifold &manifold_B); + /** + * Clone this manifold. + */ + virtual std::unique_ptr > + clone() const override; + /** * Pull back operation. */ virtual Point - pull_back(const Point &space_point) const; + pull_back(const Point &space_point) const override; /** * Push forward operation. */ virtual Point - push_forward(const Point &chart_point) const; + push_forward(const Point &chart_point) const override; /** * Gradient. */ virtual DerivativeForm<1,chartdim,spacedim> - push_forward_gradient(const Point &chart_point) const; + push_forward_gradient(const Point &chart_point) const override; private: SmartPointer, @@ -170,6 +177,16 @@ TensorProductManifold +std::unique_ptr > +TensorProductManifold::clone() const +{ + return std_cxx14::make_unique > + (*manifold_A, *manifold_B); +} + template diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index 71d05f6dc4..803ab44fd7 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -3681,11 +3681,11 @@ next_cell: // Save manifolds auto manifold_ids = tria.get_manifold_ids(); - std::map*> manifolds; + std::map > > manifolds; // Set manifolds in new Triangulation for (auto manifold_id: manifold_ids) if (manifold_id != numbers::invalid_manifold_id) - manifolds[manifold_id] = &tria.get_manifold(manifold_id); + manifolds[manifold_id] = tria.get_manifold(manifold_id).clone(); tria.clear(); diff --git a/source/grid/manifold.cc b/source/grid/manifold.cc index 94b0f266e2..2692746c63 100644 --- a/source/grid/manifold.cc +++ b/source/grid/manifold.cc @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -516,7 +517,7 @@ template std::unique_ptr > FlatManifold::clone() const { - return std::unique_ptr >(new FlatManifold(periodicity, tolerance)); + return std_cxx14::make_unique >(periodicity, tolerance); } diff --git a/source/grid/manifold_lib.cc b/source/grid/manifold_lib.cc index 36dff043d2..ea5f129b64 100644 --- a/source/grid/manifold_lib.cc +++ b/source/grid/manifold_lib.cc @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -126,7 +127,7 @@ template std::unique_ptr > PolarManifold::clone() const { - return std::unique_ptr >(new PolarManifold(center)); + return std_cxx14::make_unique >(center); } @@ -281,7 +282,7 @@ template std::unique_ptr > SphericalManifold::clone() const { - return std::unique_ptr >(new SphericalManifold(center)); + return std_cxx14::make_unique >(center); } @@ -970,8 +971,7 @@ template std::unique_ptr > CylindricalManifold::clone() const { - return std::unique_ptr > - (new CylindricalManifold(direction, point_on_axis, tolerance)); + return std_cxx14::make_unique >(direction, point_on_axis, tolerance); } @@ -1165,24 +1165,32 @@ template std::unique_ptr > FunctionManifold::clone() const { + // This manifold can be constructed either by providing an expression for the + // push forward and the pull back charts, or by providing two Function + // objects. In the first case, the push_forward and pull_back functions are + // created internally in FunctionManifold, and destroyed when this object is + // deleted. We need to make sure that our cloned object is constructed in the + // same way this class was constructed, and that its internal Function + // pointers point either to the same Function objects used to construct this + // function (owns_pointers == false) or that the newly generated manifold + // creates internally the push_forward and pull_back functions using the same + // expressions that were used to construct this class (own_pointers == true). 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)); + return std_cxx14::make_unique >(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)); + return std_cxx14::make_unique >(*push_forward_function, + *pull_back_function, + this->get_periodicity(), + tolerance); } @@ -1293,7 +1301,7 @@ template std::unique_ptr > TorusManifold::clone() const { - return std::unique_ptr >(new TorusManifold(R,r)); + return std_cxx14::make_unique >(R,r); } diff --git a/tests/bits/distorted_cells_06.cc b/tests/bits/distorted_cells_06.cc index f55a9061c7..4cb3fda265 100644 --- a/tests/bits/distorted_cells_06.cc +++ b/tests/bits/distorted_cells_06.cc @@ -37,6 +37,11 @@ template class MyManifold : public Manifold { + virtual std::unique_ptr > clone() const override + { + return std::unique_ptr >(new MyManifold()); + } + virtual Point get_new_point_on_line (const typename Triangulation::line_iterator &line) const { diff --git a/tests/grid/grid_test.cc b/tests/grid/grid_test.cc index d31ee45a93..ee86071797 100644 --- a/tests/grid/grid_test.cc +++ b/tests/grid/grid_test.cc @@ -38,7 +38,7 @@ class Ball : public: virtual Point get_new_point (const ArrayView> &surrounding_points, - const ArrayView &weights) const + const ArrayView &weights) const override { Point middle = FlatManifold::get_new_point(surrounding_points, weights); @@ -50,6 +50,11 @@ public: return middle; } + + virtual std::unique_ptr > clone() const override + { + return std::unique_ptr >(new Ball()); + } }; diff --git a/tests/manifold/chart_manifold_01.cc b/tests/manifold/chart_manifold_01.cc index b0823e6505..e1d5943d3d 100644 --- a/tests/manifold/chart_manifold_01.cc +++ b/tests/manifold/chart_manifold_01.cc @@ -29,9 +29,15 @@ template class MyFlatManifold : public ChartManifold { public: + virtual std::unique_ptr > + clone () const override + { + return std::unique_ptr >(new MyFlatManifold()); + } + virtual Point - pull_back(const Point &space_point) const + pull_back(const Point &space_point) const override { return space_point; } @@ -39,14 +45,14 @@ public: virtual Point - push_forward(const Point &chart_point) const + push_forward(const Point &chart_point) const override { return chart_point; } virtual DerivativeForm<1,spacedim,spacedim> - push_forward_gradient(const Point &chart_point) const + push_forward_gradient(const Point &chart_point) const override { DerivativeForm<1,spacedim,spacedim> x; for (unsigned int d=0; d class MyFlatManifold : public ChartManifold { public: + virtual std::unique_ptr > + clone () const override + { + return std::unique_ptr >(new MyFlatManifold()); + } + virtual Point - pull_back(const Point &space_point) const + pull_back(const Point &space_point) const override { Point p; for (unsigned int d=0; d - push_forward(const Point &chart_point) const + push_forward(const Point &chart_point) const override { Point p; for (unsigned int d=0; d - push_forward_gradient(const Point &chart_point) const + push_forward_gradient(const Point &chart_point) const override { DerivativeForm<1,spacedim+1,spacedim> x; for (unsigned int d=0; d class MyFlatManifold : public ChartManifold { public: + virtual + std::unique_ptr > + clone() const override + { + return std::unique_ptr >(new MyFlatManifold()); + } + virtual Point - pull_back(const Point &space_point) const + pull_back(const Point &space_point) const override { return space_point; } - virtual Point - push_forward(const Point &chart_point) const + push_forward(const Point &chart_point) const override { return chart_point; } virtual DerivativeForm<1,spacedim,spacedim> - push_forward_gradient(const Point &chart_point) const + push_forward_gradient(const Point &chart_point) const override { DerivativeForm<1,spacedim,spacedim> x; for (unsigned int d=0; d class MyFlatManifold : public ChartManifold { public: + + virtual std::unique_ptr > + clone () const override + { + return std::unique_ptr >(new MyFlatManifold()); + } + virtual Point - pull_back(const Point &space_point) const + pull_back(const Point &space_point) const override { Point p; for (unsigned int d=0; d - push_forward(const Point &chart_point) const + push_forward(const Point &chart_point) const override { Point p; for (unsigned int d=0; d - push_forward_gradient(const Point &chart_point) const + push_forward_gradient(const Point &chart_point) const override { DerivativeForm<1,spacedim+1,spacedim> x; for (unsigned int d=0; d (periodicity) {} + virtual std::unique_ptr > + clone () const override + { + return std::unique_ptr >(new MyFlatManifold(this->get_periodicity())); + } virtual Point - pull_back(const Point &space_point) const + pull_back(const Point &space_point) const override { return space_point; } @@ -45,14 +50,14 @@ public: virtual Point - push_forward(const Point &chart_point) const + push_forward(const Point &chart_point) const override { return chart_point; } virtual DerivativeForm<1,spacedim,spacedim> - push_forward_gradient(const Point &chart_point) const + push_forward_gradient(const Point &chart_point) const override { DerivativeForm<1,spacedim,spacedim> x; for (unsigned int d=0; d class MyFlatManifold : public ChartManifold { public: + virtual std::unique_ptr > + clone () const override + { + return std::unique_ptr >(new MyFlatManifold()); + } + virtual Point - pull_back(const Point &space_point) const + pull_back(const Point &space_point) const override { return space_point; } @@ -44,14 +50,14 @@ public: virtual Point - push_forward(const Point &chart_point) const + push_forward(const Point &chart_point) const override { return chart_point; } virtual DerivativeForm<1,spacedim,spacedim> - push_forward_gradient(const Point &chart_point) const + push_forward_gradient(const Point &chart_point) const override { DerivativeForm<1,spacedim,spacedim> x; for (unsigned int d=0; d class MyFlatManifold : public ChartManifold { public: + std::unique_ptr > + clone () const override + { + return std::unique_ptr >(new MyFlatManifold()); + } + + virtual Point - pull_back(const Point &space_point) const + pull_back(const Point &space_point) const override { Point p; for (unsigned int d=0; d - push_forward(const Point &chart_point) const + push_forward(const Point &chart_point) const override { Point p; for (unsigned int d=0; d - push_forward_gradient(const Point &chart_point) const + push_forward_gradient(const Point &chart_point) const override { DerivativeForm<1,spacedim+1,spacedim> x; for (unsigned int d=0; d class MyFlatManifold : public ChartManifold { public: + virtual std::unique_ptr > + clone () const override + { + return std::unique_ptr >(new MyFlatManifold()); + } + virtual Point - pull_back(const Point &space_point) const + pull_back(const Point &space_point) const override { return space_point; } @@ -31,14 +37,14 @@ public: virtual Point - push_forward(const Point &chart_point) const + push_forward(const Point &chart_point) const override { return chart_point; } virtual DerivativeForm<1,spacedim,spacedim> - push_forward_gradient(const Point &chart_point) const + push_forward_gradient(const Point &chart_point) const override { DerivativeForm<1,spacedim,spacedim> x; for (unsigned int d=0; d class MyFlatManifold : public ChartManifold { public: + virtual std::unique_ptr > + clone () const override + { + return std::unique_ptr >(new MyFlatManifold()); + } + virtual Point - pull_back(const Point &space_point) const + pull_back(const Point &space_point) const override { Point p; for (unsigned int d=0; d - push_forward(const Point &chart_point) const + push_forward(const Point &chart_point) const override { Point p; for (unsigned int d=0; d - push_forward_gradient(const Point &chart_point) const + push_forward_gradient(const Point &chart_point) const override { DerivativeForm<1,spacedim,spacedim> x; for (unsigned int d=0; d > + clone () const override + { + return std::unique_ptr >(new MyFlatManifold(this->get_periodicity())); + } + + virtual Point pull_back(const Point &space_point) const diff --git a/tests/manifold/chart_manifold_06_embedded.cc b/tests/manifold/chart_manifold_06_embedded.cc index afcf21d7d0..c082491410 100644 --- a/tests/manifold/chart_manifold_06_embedded.cc +++ b/tests/manifold/chart_manifold_06_embedded.cc @@ -27,9 +27,15 @@ public: ChartManifold(periodicity) {} + virtual std::unique_ptr > + clone () const override + { + return std::unique_ptr >(new MyFlatManifold(this->get_periodicity())); + } + virtual Point - pull_back(const Point &space_point) const + pull_back(const Point &space_point) const override { Point p; for (unsigned int d=0; d - push_forward(const Point &chart_point) const + push_forward(const Point &chart_point) const override { Point p; for (unsigned int d=0; d - push_forward_gradient(const Point &chart_point) const + push_forward_gradient(const Point &chart_point) const override { DerivativeForm<1,spacedim,spacedim> x; for (unsigned int d=0; d > + clone () const override + { + return std::unique_ptr >(new MyCylinderManifold()); + } + + virtual Point - pull_back(const Point &space_point) const + pull_back(const Point &space_point) const override { const double x = space_point[0]; const double y = space_point[1]; @@ -51,7 +58,7 @@ public: virtual Point - push_forward(const Point &chart_point) const + push_forward(const Point &chart_point) const override { const double r = chart_point[0]; const double phi = chart_point[1]; @@ -64,7 +71,7 @@ public: virtual DerivativeForm<1,spacedim,spacedim> - push_forward_gradient(const Point &chart_point) const + push_forward_gradient(const Point &chart_point) const override { DerivativeForm<1,spacedim,spacedim> g; diff --git a/tests/manifold/chart_manifold_08.cc b/tests/manifold/chart_manifold_08.cc index 8d19bcfca5..178e353ab3 100644 --- a/tests/manifold/chart_manifold_08.cc +++ b/tests/manifold/chart_manifold_08.cc @@ -31,10 +31,16 @@ public: ChartManifold(periodicity) {} + virtual + std::unique_ptr > + clone() const override + { + return std::unique_ptr > (new MyCylinderManifold()); + } virtual Point - pull_back(const Point &space_point) const + pull_back(const Point &space_point) const override { const double x = space_point[0]; const double y = space_point[1]; @@ -51,7 +57,7 @@ public: virtual Point - push_forward(const Point &chart_point) const + push_forward(const Point &chart_point) const override { const double r = chart_point[0]; const double phi = chart_point[1]; @@ -64,7 +70,7 @@ public: virtual DerivativeForm<1,spacedim,spacedim> - push_forward_gradient(const Point &chart_point) const + push_forward_gradient(const Point &chart_point) const override { DerivativeForm<1,spacedim,spacedim> g; diff --git a/tests/manifold/projection_manifold_01.cc b/tests/manifold/projection_manifold_01.cc index 40f01ff702..1f50016311 100644 --- a/tests/manifold/projection_manifold_01.cc +++ b/tests/manifold/projection_manifold_01.cc @@ -19,6 +19,7 @@ // all include files you need here +#include #include #include #include @@ -40,6 +41,11 @@ public: p[1] = 4*p[0]*(1-p[0]); return p; } + + std::unique_ptr > clone() const override + { + return std_cxx14::make_unique >(); + } }; // Helper function diff --git a/tests/manifold/transfinite_manifold_05.cc b/tests/manifold/transfinite_manifold_05.cc index 3b77101529..1076dfa3d9 100644 --- a/tests/manifold/transfinite_manifold_05.cc +++ b/tests/manifold/transfinite_manifold_05.cc @@ -47,9 +47,11 @@ int main () } static const SphericalManifold spherical_manifold; tria.set_manifold(1, spherical_manifold); - static TransfiniteInterpolationManifold transfinite; - transfinite.initialize(tria); - tria.set_manifold(0, transfinite); + static TransfiniteInterpolationManifold transfinite0; + transfinite0.initialize(tria); + tria.set_manifold(0, transfinite0); + + const auto &transfinite = tria.get_manifold(0); const std::array, 2> points({{Point<3>(0, 0.360566, 0), Point<3>(0, 0.321132, 0)}}); const std::array weights({{0.4, 0.6}}); diff --git a/tests/mappings/mapping_q_convergence.cc b/tests/mappings/mapping_q_convergence.cc index a0eab4efb8..0bfd2318b0 100644 --- a/tests/mappings/mapping_q_convergence.cc +++ b/tests/mappings/mapping_q_convergence.cc @@ -15,6 +15,7 @@ #include #include +#include #include @@ -103,8 +104,9 @@ template class Geometry: public ChartManifold { public: - virtual Point pull_back(const Point &space_point) const; - virtual Point push_forward(const Point &chart_point) const; + virtual Point pull_back(const Point &space_point) const override; + virtual Point push_forward(const Point &chart_point) const override; + virtual std::unique_ptr >clone() const override; }; template @@ -147,6 +149,12 @@ Point Geometry::push_forward(const Point &chart_point) const return p; } +template +std::unique_ptr > +Geometry::clone() const +{ + return std_cxx14::make_unique >(); +} template diff --git a/tests/mappings/mapping_q_manifold_01.cc b/tests/mappings/mapping_q_manifold_01.cc index 4b531fcfc0..60098c207d 100644 --- a/tests/mappings/mapping_q_manifold_01.cc +++ b/tests/mappings/mapping_q_manifold_01.cc @@ -46,8 +46,9 @@ template class Geometry: public ChartManifold { public: - virtual Point pull_back(const Point &space_point) const; - virtual Point push_forward(const Point &chart_point) const; + virtual Point pull_back(const Point &space_point) const override; + virtual Point push_forward(const Point &chart_point) const override; + virtual std::unique_ptr >clone() const override; }; template @@ -90,6 +91,13 @@ Point Geometry::push_forward(const Point &chart_point) const return p; } +template +std::unique_ptr > +Geometry::clone() const +{ + return std_cxx14::make_unique >(); +} + template class VectorFunction : public Function { -- 2.39.5