From 01c6b759eb901631cf4b5d417f0821a59fab8238 Mon Sep 17 00:00:00 2001
From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be>
Date: Tue, 20 Apr 2010 22:19:08 +0000
Subject: [PATCH] dg : dgBoundaryConditionOutsideValue as term

---
 Solver/function.cpp | 13 +++++++++++++
 Solver/function.h   | 34 ++++++++++++++++++++++++++--------
 2 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/Solver/function.cpp b/Solver/function.cpp
index 742d0221c1..72ab7d407a 100644
--- a/Solver/function.cpp
+++ b/Solver/function.cpp
@@ -42,6 +42,16 @@ dataCacheDouble::dataCacheDouble(dataCacheMap *m, function *f):
   _nRowByPoint=1;
   m->addDataCacheDouble(this, f->isInvalitedOnElement());
   _function = f;
+  for(int i=0; i<f->_childrenCache.size(); i++) {
+    dataCacheMap *m2 = m->newChild();
+    m->addSecondaryCache(m2);
+  }
+  _substitutions.resize(f->_substitutedFunctions.size());
+  for(int i=0; i<f->_substitutedFunctions.size(); i++) {
+    function::substitutedFunction s = f->_substitutedFunctions[i];
+    _substitutions[i].first = &m->getSecondaryCache(s.iMap)->substitute(s.f0);
+    _substitutions[i].second = &m->get(s.f1,this);
+  }
   _dependencies.resize ( _function->arguments.size());
   for (unsigned int i=0;i<_function->arguments.size();i++) {
     int iCache = _function->arguments[i]->iMap;
@@ -55,6 +65,9 @@ void dataCacheDouble::resize() {
 }
 
 void dataCacheDouble::_eval() {
+  for(unsigned int i=0;i<_substitutions.size(); i++){
+    _substitutions[i].first->set() = (*_substitutions[i].second)();
+  }
   for(unsigned int i=0;i<_dependencies.size(); i++){
     _function->arguments[i]->val.setAsProxy((*_dependencies[i])());
   }
diff --git a/Solver/function.h b/Solver/function.h
index 84a38f783c..265aed94ef 100644
--- a/Solver/function.h
+++ b/Solver/function.h
@@ -34,6 +34,7 @@ class dataCacheDouble;
 // An abstract interface to functions 
 // more explanation at the head of this file
 class function {
+  public :
   class argument {
     //iMap is the id of the dataCacheMap, e.g. on interfaces
     public:
@@ -45,10 +46,15 @@ class function {
       f = f_;
     }
   };
+  class substitutedFunction {
+    public:
+    int iMap;
+    const function *f0, *f1; // f1 replaces f0
+  };
   int _nbCol;
   bool _invalidatedOnElement;
-  protected :
-  public :
+  std::vector<int> _childrenCache;
+  std::vector<substitutedFunction> _substitutedFunctions;
   virtual void call (dataCacheMap *m, fullMatrix<double> &res)=0;
   std::vector<argument*> arguments;
   const fullMatrix<double> &addArgument(const function *f, int iMap = 0) {
@@ -57,6 +63,16 @@ class function {
     arguments.push_back(new argument(iMap, f));
     return arguments.back()->val;
   }
+  void addChildDataCacheMap(int parent) {
+    _childrenCache.push_back(parent);
+  }
+  void substituteFunction( int iMap, const function *f0, const function *f1) {
+    substitutedFunction s;
+    s.iMap= iMap;
+    s.f0 = f0;
+    s.f1 = f1;
+    _substitutedFunctions.push_back(s);
+  }
   virtual ~function();
   static void registerBindings(binding *b);
   function(int nbCol, bool invalidatedOnElement = true);
@@ -97,6 +113,7 @@ public :
     return (_iDependOn.find(&other)!=_iDependOn.end());
   }
   std::vector<dataCacheDouble*> _dependencies;
+  std::vector<std::pair<dataCacheDouble*, dataCacheDouble*> > _substitutions;
 
   int _nRowByPoint;
   function *_function;
@@ -147,7 +164,7 @@ class dgDataCacheMap;
 // more explanation at the head of this file
 class dataCacheMap {
   friend class dataCacheDouble;
- protected:
+ public:
   dataCacheMap  *_parent;
   std::list<dataCacheMap*> _children;
   std::vector<dataCacheMap*> _secondaryCaches;
@@ -163,7 +180,6 @@ class dataCacheMap {
     if(invalidatedOnElement)
       _toInvalidateOnElement.insert(data);
   }
- public:
   void printList() {
     for(std::set<dataCacheDouble*>::iterator it = _toInvalidateOnElement.begin(); it!= _toInvalidateOnElement.end(); it++)
       printf("%p\n",*it);
@@ -199,10 +215,12 @@ class dataCacheMap {
     _nbEvaluationPoints = 0;
     _parent=NULL;
   }
-  void setParent(dataCacheMap *parent) {
-    _parent = parent;
-    _parent->_children.push_back(this);
-    _nbEvaluationPoints = 0;
+  virtual dataCacheMap *newChild() {
+    dataCacheMap *m = new dataCacheMap();
+    m->_parent = this;
+    _children.push_back(m);
+    m->_nbEvaluationPoints = 0;
+    return m;
   }
   void setNbEvaluationPoints(int nbEvaluationPoints);
 
-- 
GitLab