From f12d946ba5bf235ec64b746fdedbdf892dd7f8aa Mon Sep 17 00:00:00 2001
From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be>
Date: Wed, 8 Dec 2010 19:10:21 +0000
Subject: [PATCH] dg : add functionConstantByTag

---
 Solver/function.cpp | 24 ++++++++++++++++--------
 Solver/function.h   | 18 +++---------------
 2 files changed, 19 insertions(+), 23 deletions(-)

diff --git a/Solver/function.cpp b/Solver/function.cpp
index ad0b803775..d144ae678d 100644
--- a/Solver/function.cpp
+++ b/Solver/function.cpp
@@ -50,14 +50,14 @@ functionConstant *function::_dtFunction = NULL;
 functionConstant *function::getTime()
 {
   if (! _timeFunction)
-    _timeFunction = functionConstantNew(0.);
+    _timeFunction = new functionConstant(0.);
   return _timeFunction;
 }
 
 functionConstant *function::getDT()
 {
   if (! _dtFunction)
-    _dtFunction = functionConstantNew(0.);
+    _dtFunction = new functionConstant(0.);
   return _dtFunction;
 }
 
@@ -367,16 +367,24 @@ void functionConstant::set(double val)
   _source(0,0) = val;
 }
 
-functionConstant *functionConstantNew(double v) 
+void functionConstant::call(dataCacheMap *m, fullMatrix<double> &val)
 {
-  std::vector<double> vec(1);
-  vec[0]=v;
-  return new functionConstant(vec);
+  for (int i=0; i<val.size1(); i++)
+    for (int j=0; j<_source.size1(); j++)
+      val(i,j)=_source(j,0);
 }
 
-functionConstant *functionConstantNew(const std::vector<double> &v) 
+functionConstant::functionConstant(std::vector<double> source) : function(source.size())
 {
-  return new functionConstant(v);
+  _source = fullMatrix<double>(source.size(),1);
+  for (size_t i=0; i<source.size(); i++)
+    _source(i,0) = source[i];
+}
+
+functionConstant::functionConstant(double source) : function(1)
+{
+  _source.resize(1,1);
+  _source(0,0) = source;
 }
 
 // functionSum
diff --git a/Solver/function.h b/Solver/function.h
index f6558a4277..f9af049036 100644
--- a/Solver/function.h
+++ b/Solver/function.h
@@ -274,18 +274,9 @@ class dataCacheMap {
 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 call(dataCacheMap *m, fullMatrix<double> &val);
+  functionConstant(std::vector<double> source);
+  functionConstant(double source);
   void set(double val); 
 };
 
@@ -300,9 +291,6 @@ class functionC : public function {
              std::vector<const function *> dependencies);
 };
 
-functionConstant *functionConstantNew(const std::vector<double>&);
-functionConstant *functionConstantNew(double);
-
 function *functionSumNew (const function *f0, const function *f1);
 function *functionProdNew (const function *f0, const function *f1);
 function *functionScaleNew (const function *f0, const double s);
-- 
GitLab