]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Simpler implementation of the square of x.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 3 Jul 2000 07:07:09 +0000 (07:07 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 3 Jul 2000 07:07:09 +0000 (07:07 +0000)
git-svn-id: https://svn.dealii.org/trunk@3119 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/source/function_lib.cc

index 5dfefbf5c13d9994ca7e196fa184f71c4e435884..1f3845a959dbc9ca1295872655f2627a15cff2be 100644 (file)
@@ -86,27 +86,11 @@ Tensor<1,dim>
 SquareFunction<dim>::gradient (const Point<dim>   &p,
                               const unsigned int) const
 {
-  Tensor<1,dim> result;
-  switch(dim)
-    {
-      case 1:
-           result[0] = 2.*p(0);
-           break;
-      case 2:
-           result[0] = 2.*p(0);
-           result[1] = 2.*p(1);
-           break;
-      case 3:
-           result[0] = 2.*p(0);
-           result[1] = 2.*p(1);
-           result[2] = 2.*p(2);
-           break;
-      default:
-           Assert(false, ExcNotImplemented());
-    }
-  return result;
+  return p*2;
 }
 
+
+
 template<int dim>
 void
 SquareFunction<dim>::gradient_list (const vector<Point<dim> > &points,
@@ -116,31 +100,14 @@ SquareFunction<dim>::gradient_list (const vector<Point<dim> > &points,
   Assert (gradients.size() == points.size(),
          ExcDimensionMismatch(gradients.size(), points.size()));
 
-  for (unsigned int i=0;i<points.size();++i)
-    {
-      const Point<dim>& p = points[i];
-      switch(dim)
-       {
-         case 1:
-               gradients[i][0] = 2.*p(0);
-               break;
-         case 2:
-               gradients[i][0] = 2.*p(0);
-               gradients[i][1] = 2.*p(1);
-               break;
-         case 3:
-               gradients[i][0] = 2.*p(0);
-               gradients[i][1] = 2.*p(1);
-               gradients[i][2] = 2.*p(2);
-               break;
-         default:
-               Assert(false, ExcNotImplemented());
-       }
-    }
+  for (unsigned int i=0; i<points.size(); ++i)
+    gradients[i] = points[i]*2;
 }
 
+
 //////////////////////////////////////////////////////////////////////
 
+
 template<int dim>
 double
 PillowFunction<dim>::value (const Point<dim>   &p,

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.