]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added relative tolerance, and better comment for owns_pointers.
authorLuca Heltai <luca.heltai@sissa.it>
Thu, 7 Aug 2014 13:50:11 +0000 (15:50 +0200)
committerLuca Heltai <luca.heltai@sissa.it>
Thu, 7 Aug 2014 13:50:11 +0000 (15:50 +0200)
include/deal.II/grid/manifold_lib.h
source/grid/manifold_lib.cc

index 462e137969f6e4bdfcc613fc7aa4c2ce591c0067..899083dfa06c99147b01ccbba38b1e3866834fb8 100644 (file)
@@ -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<chartdim> &push_forward_function,
                        const Function<spacedim> &pull_back_function,
-                       const Point<chartdim> periodicity=Point<chartdim>());
+                       const Point<chartdim> periodicity=Point<chartdim>(),
+                       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<chartdim> periodicity=Point<chartdim>(), 
                        const typename FunctionParser<spacedim>::ConstMap = typename FunctionParser<spacedim>::ConstMap(),
                        const std::string chart_vars=FunctionParser<chartdim>::default_variable_names(),
-                       const std::string space_vars=FunctionParser<spacedim>::default_variable_names());
+                       const std::string space_vars=FunctionParser<spacedim>::default_variable_names(),
+                       const double tolerance=1e-10);
 
   /**
    * If needed, we delete the pointers we own.
@@ -271,9 +279,21 @@ private:
    */
   SmartPointer<const Function<spacedim>, 
               FunctionManifoldChart<dim,spacedim,chartdim> > 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;
 };
index 80a7e5003d25cbe1d2e1fad0b523b74664e2d673..ee76066b44283bdcc8d0bbc61c23de9098766c07 100644 (file)
@@ -211,10 +211,12 @@ template <int dim, int spacedim, int chartdim>
 FunctionManifoldChart<dim,spacedim,chartdim>::FunctionManifoldChart
 (const Function<chartdim> &push_forward_function,
  const Function<spacedim> &pull_back_function,
- const Point<chartdim> periodicity):
+ const Point<chartdim> periodicity,
+ const double tolerance):
   ManifoldChart<dim,spacedim,chartdim>(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<dim,spacedim,chartdim>::FunctionManifoldChart
  const Point<chartdim> periodicity, 
  const typename FunctionParser<spacedim>::ConstMap const_map,
  const std::string chart_vars, 
- const std::string space_vars) :
+ const std::string space_vars,
+ const double tolerance) :
   ManifoldChart<dim,spacedim,chartdim>(periodicity),
   const_map(const_map),
+  tolerance(tolerance),
   owns_pointers(true)
 {
   FunctionParser<chartdim> * pf = new FunctionParser<chartdim>(spacedim);
@@ -268,7 +272,9 @@ FunctionManifoldChart<dim,spacedim,chartdim>::push_forward(const Point<chartdim>
   Vector<double> pb(chartdim);
   pull_back_function->vector_value(result, pb);
   for (unsigned int i=0; i<chartdim; ++i)
-    Assert(abs(pb[i]-chart_point[i]) < 1e-10*chart_point.norm(),
+    Assert( (chart_point.norm() > 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
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.