From d71514e74ca88140d21edd88c37f6532282cbe33 Mon Sep 17 00:00:00 2001
From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be>
Date: Thu, 22 Apr 2010 14:50:16 +0000
Subject: [PATCH] add time function and remove dgSystemOfEquation

---
 Solver/function.cpp | 38 +++++++++++++++++++-------------------
 Solver/function.h   | 25 +++++++++++++++++++++++--
 2 files changed, 42 insertions(+), 21 deletions(-)

diff --git a/Solver/function.cpp b/Solver/function.cpp
index c50a86dd39..57beb24cbb 100644
--- a/Solver/function.cpp
+++ b/Solver/function.cpp
@@ -132,33 +132,24 @@ dataCacheMap::~dataCacheMap()
 // now some example of functions
 
 // constant values copied over each line
-class functionConstant : public function {
-  public:
-  fullMatrix<double> _source;
-  void call(dataCacheMap *m, fullMatrix<double> &val) {
-    for(int i=0;i<val.size1();i++)
-      for(int j=0;j<_source.size1();j++){
-        val(i,j)=_source(j,0);
-        }
-  }
-  functionConstant(std::vector<double> source):function(source.size()){
-    _source = fullMatrix<double>(source.size(),1);
-    for(size_t i=0; i<source.size(); i++){
-      _source(i,0) = source[i];
-    }
-  }
-};
 
-function *functionConstantNew(double v) {
+functionConstant *functionConstantNew(double v) {
   std::vector<double> vec(1);
   vec[0]=v;
   return new functionConstant(vec);
 }
 
-function *functionConstantNew(const std::vector<double> &v) {
+functionConstant *functionConstantNew(const std::vector<double> &v) {
   return new functionConstant(v);
 }
 
+void functionConstant::set(double val) {
+  if(getNbCol() != 1) {
+    Msg::Error ("set scalar value on a vectorial constant function");
+  }
+  _source(0,0) = val;
+}
+
 
 
 class functionSum : public function {
@@ -430,10 +421,13 @@ class functionC : public function {
 };
 
 void function::registerBindings(binding *b){
-  classBinding *cb = b->addClass<function>("function");
+  classBinding *cb = b->addClass<function>("Function");
   cb->setDescription("A generic function that can be evaluated on a set of points. Functions can call other functions and their values are cached so that if two different functions call the same function f, f is only evaluated once.");
   methodBinding *mb;
 
+  mb = cb->addMethod("getTime", &function::getTime);
+  mb->setDescription("Return function constant in space which contains the time value");
+
   cb = b->addClass<functionConstant>("functionConstant");
   cb->setDescription("A constant (scalar or vector) function");
   mb = cb->setConstructor<functionConstant,std::vector <double> >();
@@ -529,3 +523,9 @@ functionReplaceCache::~functionReplaceCache() {
   }
   delete map;
 }
+functionConstant *function::_timeFunction = NULL;
+functionConstant *function::getTime() {
+  if (! _timeFunction)
+    _timeFunction = functionConstantNew(0.);
+  return _timeFunction;
+}
diff --git a/Solver/function.h b/Solver/function.h
index a7242f4fa2..7c4d318f64 100644
--- a/Solver/function.h
+++ b/Solver/function.h
@@ -14,12 +14,14 @@ class binding;
 class function;
 class dataCacheDouble;
 
+class functionConstant;
 class functionReplace;
 class functionReplaceCache;
 
 // An abstract interface to functions 
 // more explanation at the head of this file
 class function {
+  static functionConstant *_timeFunction; 
   public :
   class argument {
     //iMap is the id of the dataCacheMap, e.g. on interfaces
@@ -71,6 +73,7 @@ class function {
   static function *getSolutionGradient();
   static function *getParametricCoordinates();
   static function *getNormals();
+  static functionConstant *getTime();
 };
 
 // dataCache when the value is a  matrix of double 
@@ -240,8 +243,8 @@ class functionReplaceCache {
 };
 
 
-function *functionConstantNew(const std::vector<double>&);
-function *functionConstantNew(double);
+functionConstant *functionConstantNew(const std::vector<double>&);
+functionConstant *functionConstantNew(double);
 function *functionSumNew (const function *f0, const function *f1);
 
 class functionSolution : public function {
@@ -261,4 +264,22 @@ class functionSolution : public function {
     return _instance;
   }
 };
+
+class functionConstant : public function {
+  public:
+  fullMatrix<double> _source;
+  void call(dataCacheMap *m, fullMatrix<double> &val) {
+    for(int i=0;i<val.size1();i++)
+      for(int j=0;j<_source.size1();j++){
+        val(i,j)=_source(j,0);
+        }
+  }
+  functionConstant(std::vector<double> source):function(source.size()){
+    _source = fullMatrix<double>(source.size(),1);
+    for(size_t i=0; i<source.size(); i++){
+      _source(i,0) = source[i];
+    }
+  }
+  void set(double val); 
+};
 #endif
-- 
GitLab