[PATCH] Add relation like constructor to ScalarCode

Richard Guenther rguenth at tat.physik.uni-tuebingen.de
Fri Apr 2 11:52:30 UTC 2004


Hi!

This adds a relation functor required constructor to ScalarCode to be able
to use ScalarCode objects as relation functors.  It also updates
TestBasicRelations check to excercise this and also adds actual checking
to the test.

Tested partly (relation and scalarcode tests) on ia32-linux, ok?

Richard.


2004Apr02  Richard Guenther <richard.guenther at uni-tuebingen.de>

	* src/Evaluator/ScalarCode.h: add copy constructor with
	extra LHS argument for relation functor compatibility.
	src/Field/tests/TestBasicRelations.cpp: check using
	ScalarCode object as relation functor.

===== Evaluator/ScalarCode.h 1.5 vs edited =====
--- 1.5/r2/src/Evaluator/ScalarCode.h	Thu Oct 23 14:41:02 2003
+++ edited/Evaluator/ScalarCode.h	Fri Apr  2 13:29:26 2004
@@ -403,6 +403,14 @@
   {
   }

+  /// Constructor to allow ScalarCode being used as RelationFunctor
+
+  template <class LHS>
+  ScalarCode(const ScalarCode<Function>& sc, const LHS&)
+    : function_m(sc.function_m)
+  {
+  }
+
   template<class F>
   static inline bool checkValidity(const F& f, WrappedInt<false>)
   {
===== Field/tests/TestBasicRelations.cpp 1.1 vs edited =====
--- 1.1/r2/src/Field/tests/TestBasicRelations.cpp	Mon May 13 17:47:37 2002
+++ edited/Field/tests/TestBasicRelations.cpp	Fri Apr  2 13:37:14 2004
@@ -54,10 +54,31 @@
   }
 };

-void computePotentialEnergy(const Field_t &U, const Field_t &m, const Field_t &h)
-{
-  U = m * g * h;
-}
+template<int Dim>
+struct computePotentialEnergy {
+  computePotentialEnergy() {}
+  void scalarCodeInfo(ScalarCodeInfo& info) const
+  {
+    info.dimensions(Dim);
+    info.arguments(3);
+    info.write(0, true);
+    info.write(1, false);
+    info.write(2, false);
+    info.useGuards(0, false);
+    info.useGuards(1, false);
+    info.useGuards(2, false);
+    for (int i=0; i<Dim; ++i)
+    {
+      info.lowerExtent(i) = 0;
+      info.upperExtent(i) = 0;
+    }
+  }
+  template <class F1, class F2, class F3>
+  void operator()(const F1& U, const F2& m, const F3& h, const Loc<Dim>& loc) const
+  {
+    U(loc) = m(loc) * g * h(loc);
+  }
+};

 struct ComputeVelocity
 {
@@ -102,14 +123,16 @@

   Pooma::newRelation(Pooma::functionPtr(computeTotalEnergy), E, K, U);
   Pooma::newRelation(ComputeKineticEnergy(), K, m, v);
-  Pooma::newRelation(Pooma::functionPtr(computePotentialEnergy), U, m, h);
+  Pooma::newRelation(ScalarCode<computePotentialEnergy<2> >(), U, m, h);
   Pooma::newRelation(Pooma::memberPtr(obj, &ComputeVelocity::doit), v, p, m);

   tester.out() << E << std::endl;
+  tester.check("Total energy at h=4.0", all(E == 3.0*g*4.0 + 0.5*3.0*pow(2.0/3.0, 2)));

   h = 0;

   tester.out() << E << std::endl;
+  tester.check("Total energy at h=0.0", all(E == 3.0*g*0.0 + 0.5*3.0*pow(2.0/3.0, 2)));

   int ret = tester.results("TestBasicRelations");
   Pooma::finalize();



More information about the pooma-dev mailing list