]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
throw exception if Mapping iteration fails
authorkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 7 Dec 2011 18:45:56 +0000 (18:45 +0000)
committerkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 7 Dec 2011 18:45:56 +0000 (18:45 +0000)
git-svn-id: https://svn.dealii.org/trunk@24798 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/fe/mapping_q1.h
deal.II/source/fe/mapping_q1.cc

index 38bebfed55b73cf479b42f099fad5d5be0bb0900..065f24849c71f8a93936f09fcf67c2421f5b0e2b 100644 (file)
@@ -521,6 +521,18 @@ class MappingQ1 : public Mapping<dim,spacedim>
     virtual
     bool preserves_vertex_locations () const;
 
+                                    /**
+                                     * The Newton iteration computing
+                                     * the mapping between a
+                                     * real space point and a point
+                                     * in reference space did not
+                                     * converge, thus resulting in a
+                                     * wrong mapping.
+                                     *
+                                     * @ingroup Exceptions
+                                     */
+    DeclException0(ExcTransformationFailed);
+    
   private:
                                     /**
                                      * Implementation of the interface in
index d68e56654a43b1d56331647df7fbaed8483a4a42..07917df35fa4559502ce1e7f9511c0581ebfe1e3 100644 (file)
@@ -1519,8 +1519,10 @@ transform_real_to_unit_cell_internal
   Point<spacedim> f = p_real-p;
 
   const double eps=1e-15*cell->diameter();
+  const unsigned int loop_limit = 10;
+  
   unsigned int loop=0;
-  while (f.square()>eps*eps && loop++<10)
+  while (f.square()>eps*eps && loop++<loop_limit)
     {
                                       // f'(x)
       Tensor<2,spacedim> df;
@@ -1552,7 +1554,7 @@ transform_real_to_unit_cell_internal
              df = transpose(df);
            }
        }
-
+      
                                       // Solve  [f'(x)]d=f(x)
       Tensor<1,spacedim> d;
       Tensor<2,spacedim> df_1;
@@ -1587,6 +1589,15 @@ transform_real_to_unit_cell_internal
       if(dim<spacedim)
        f -= (transpose(df)[dim]*f)*f;
     }
+                                  // Here we check that in the last
+                                  // execution of while the first
+                                  // condition was already wrong,
+                                  // menaing the residual was below
+                                  // eps. Only if the first condition
+                                  // failed, loop will have been
+                                  // increased and tested, and thus
+                                  // havereached the limit.
+  AssertThrow(loop<loop_limit, ExcTransformationFailed());
 }
 
 

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.