From 7613e60b6b0513213b917c09d642dd3230bb617d Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Thu, 7 Aug 2014 15:50:11 +0200 Subject: [PATCH] Added relative tolerance, and better comment for owns_pointers. --- include/deal.II/grid/manifold_lib.h | 30 ++++++++++++++++++++++++----- source/grid/manifold_lib.cc | 12 +++++++++--- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/include/deal.II/grid/manifold_lib.h b/include/deal.II/grid/manifold_lib.h index 462e137969..899083dfa0 100644 --- a/include/deal.II/grid/manifold_lib.h +++ b/include/deal.II/grid/manifold_lib.h @@ -209,10 +209,14 @@ public: * spacedim components, and a pull_back function of chartdim * components. See the documentation of the base class ManifoldChart * for the meaning of the optional #periodicity argument. + * + * The tolerance argument is used in debug mode to actually check + * that the two functions are one the inverse of the other. */ FunctionManifoldChart(const Function &push_forward_function, const Function &pull_back_function, - const Point periodicity=Point()); + const Point periodicity=Point(), + const double tolerance=1e-10); /** * Expressions constructor. Takes the expressions of the @@ -224,14 +228,18 @@ public: * The strings should be the readable by the default constructor of * the FunctionParser classes. You can specify custom variable * expressions with the last two optional arguments. If you don't, - * the default names are used, i.e., "x,y,z" + * the default names are used, i.e., "x,y,z". + * + * The tolerance argument is used in debug mode to actually check + * that the two functions are one the inverse of the other. */ FunctionManifoldChart(const std::string push_forward_expression, const std::string pull_back_expression, const Point periodicity=Point(), const typename FunctionParser::ConstMap = typename FunctionParser::ConstMap(), const std::string chart_vars=FunctionParser::default_variable_names(), - const std::string space_vars=FunctionParser::default_variable_names()); + const std::string space_vars=FunctionParser::default_variable_names(), + const double tolerance=1e-10); /** * If needed, we delete the pointers we own. @@ -271,9 +279,21 @@ private: */ SmartPointer, FunctionManifoldChart > pull_back_function; - + + /** + * Relative tolerance. In debug mode, we check that the two + * functions provided at construction time are actually one the + * inverse of the other. This value is used as relative tolerance in + * this check. + */ + const double tolerance; + /** - * Check ownership of the smart pointers. + * Check ownership of the smart pointers. Indicates whether this + * class is the owner of the objects pointed to by the previous two + * member variables. This value is set in the constructor of the + * class. If #true, then the destructor will delete the function + * objects pointed to be the two pointers. */ const bool owns_pointers; }; diff --git a/source/grid/manifold_lib.cc b/source/grid/manifold_lib.cc index 80a7e5003d..ee76066b44 100644 --- a/source/grid/manifold_lib.cc +++ b/source/grid/manifold_lib.cc @@ -211,10 +211,12 @@ template FunctionManifoldChart::FunctionManifoldChart (const Function &push_forward_function, const Function &pull_back_function, - const Point periodicity): + const Point periodicity, + const double tolerance): ManifoldChart(periodicity), push_forward_function(&push_forward_function), pull_back_function(&pull_back_function), + tolerance(tolerance), owns_pointers(false) { AssertDimension(push_forward_function.n_components, spacedim); @@ -228,9 +230,11 @@ FunctionManifoldChart::FunctionManifoldChart const Point periodicity, const typename FunctionParser::ConstMap const_map, const std::string chart_vars, - const std::string space_vars) : + const std::string space_vars, + const double tolerance) : ManifoldChart(periodicity), const_map(const_map), + tolerance(tolerance), owns_pointers(true) { FunctionParser * pf = new FunctionParser(spacedim); @@ -268,7 +272,9 @@ FunctionManifoldChart::push_forward(const Point Vector pb(chartdim); pull_back_function->vector_value(result, pb); for (unsigned int i=0; i tolerance && + (abs(pb[i]-chart_point[i]) < tolerance*chart_point.norm() ) || + (abs(pb[i]-chart_point[i]) < tolerance) ), ExcMessage("The push forward is not the inverse of the pull back! Bailing out.")); #endif -- 2.39.5