]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Replace floating point comparison with fabs(...)<eps
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 7 Dec 2006 20:40:30 +0000 (20:40 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 7 Dec 2006 20:40:30 +0000 (20:40 +0000)
git-svn-id: https://svn.dealii.org/trunk@14222 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/examples/step-7/step-7.cc

index 43474c223a37c3f160b0a75822f6e3dbf461c11d..6a226f9568cf8682a1b3473090a0776614b2e369 100644 (file)
@@ -1379,25 +1379,31 @@ void HelmholtzProblem<dim>::process_solution (const unsigned int cycle)
                                  // For this, we will use the
                                  // following convention: Faces
                                  // belonging to Gamma1 will have the
-                                 // boundary indicator <code>0</code> (which is
-                                 // the default, so we don't have to
-                                 // set it explicitely), and faces
-                                 // belonging to Gamma2 will use <code>1</code>
-                                 // as boundary indicator.  To set
-                                 // these values, we loop over all
-                                 // cells, then over all faces of a
-                                 // given cell, check whether it is
-                                 // part of the boundary that we want
-                                 // to denote by Gamma2, and if so set
-                                 // its boundary indicator to
-                                 // <code>1</code>. For the present program, we
-                                 // consider the left and bottom
-                                 // boundaries as Gamma2. We determine
-                                 // whether a face is part of that
-                                 // boundary by asking whether the x
-                                 // or y coordinates (i.e. vector
+                                 // boundary indicator <code>0</code>
+                                 // (which is the default, so we don't
+                                 // have to set it explicitely), and
+                                 // faces belonging to Gamma2 will use
+                                 // <code>1</code> as boundary
+                                 // indicator.  To set these values,
+                                 // we loop over all cells, then over
+                                 // all faces of a given cell, check
+                                 // whether it is part of the boundary
+                                 // that we want to denote by Gamma2,
+                                 // and if so set its boundary
+                                 // indicator to <code>1</code>. For
+                                 // the present program, we consider
+                                 // the left and bottom boundaries as
+                                 // Gamma2. We determine whether a
+                                 // face is part of that boundary by
+                                 // asking whether the x or y
+                                 // coordinates (i.e. vector
                                  // components 0 and 1) of the
-                                 // midpoint of a face equals -1.
+                                 // midpoint of a face equals -1, up
+                                 // to some small wiggle room that we
+                                 // have to give since it is instable
+                                 // to compare floating point numbers
+                                 // that are subject to round off in
+                                 // intermediate computations.
                                  //
                                  // It is worth noting that we have to
                                  // loop over all cells here, not only
@@ -1438,9 +1444,9 @@ void HelmholtzProblem<dim>::run ()
            for (unsigned int face=0;
                  face<GeometryInfo<dim>::faces_per_cell;
                  ++face)
-             if ((cell->face(face)->center()(0) == -1)
+             if ((std::fabs(cell->face(face)->center()(0) - (-1)) < 1e-12)
                  ||
-                 (cell->face(face)->center()(1) == -1))
+                 (std::fabs(cell->face(face)->center()(1) - (-1)) < 1e-12))
                cell->face(face)->set_boundary_indicator (1);
        }
       else

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.