From a1734fe62b5aa6a822cac9a2feddb797c585a6ad Mon Sep 17 00:00:00 2001
From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be>
Date: Wed, 17 Mar 2010 16:10:15 +0000
Subject: [PATCH] cleaning

---
 Common/LuaBindings.cpp           |  1 +
 Common/LuaBindings.h             | 26 +++++++++++++++
 Solver/dgResidual.cpp            |  8 ++---
 Solver/dgResidual.h              |  2 +-
 Solver/dgRungeKuttaMultirate.cpp | 19 -----------
 Solver/function.cpp              | 56 ++++++++++++++++++++++++++++++--
 Solver/function.h                |  6 ----
 7 files changed, 85 insertions(+), 33 deletions(-)

diff --git a/Common/LuaBindings.cpp b/Common/LuaBindings.cpp
index 82d4d65b00..30d6f9e456 100644
--- a/Common/LuaBindings.cpp
+++ b/Common/LuaBindings.cpp
@@ -104,6 +104,7 @@ static void reportErrors(lua_State *L, int status)
   if ( status!=0 ) {
     std::cerr << "-- " << lua_tostring(L, -1) << std::endl;
     lua_pop(L, 1); // remove error message
+    exit(1); //we need this for automatic test
   }
 }
 
diff --git a/Common/LuaBindings.h b/Common/LuaBindings.h
index aa32cd5d0d..4259e67aba 100644
--- a/Common/LuaBindings.h
+++ b/Common/LuaBindings.h
@@ -160,6 +160,32 @@ class luaStack<std::vector<type > >{
     return name+luaStack<type>::getName();
   }
 };
+template<class type>
+class luaStack<std::vector<type > &>{
+  public:
+  static std::vector<type>  get(lua_State *L, int ia){
+    std::vector<type> v;
+    size_t size=lua_objlen(L,ia);
+    v.resize(size);
+    for(size_t i=0;i<size;i++){
+      lua_rawgeti(L, ia, i+1);
+      v[i]=luaStack<type>::get(L,-1);
+      lua_pop(L,1);
+    }
+    return v;
+  }
+  static void push(lua_State *L, const std::vector<type>& v){
+    lua_createtable(L, v.size(), 0);
+    for(size_t i=0;i<v.size;i++){
+      luaStack<type>::push(L,v[i]);
+      lua_rawseti(L, 2, i+1);
+    }
+  }
+  static std::string getName(){
+    std::string name="vector of ";
+    return name+luaStack<type>::getName();
+  }
+};
 
 template<>
 class luaStack<double>{
diff --git a/Solver/dgResidual.cpp b/Solver/dgResidual.cpp
index c872c42ea3..bcd51dc7bd 100644
--- a/Solver/dgResidual.cpp
+++ b/Solver/dgResidual.cpp
@@ -270,7 +270,7 @@ dgResidualInterface::dgResidualInterface (const dgConservationLaw &claw):
 void dgResidualInterface::compute1Group ( //dofManager &dof, // the DOF manager (maybe useless here)
 				     dgGroupOfFaces &group, 
 				     const fullMatrix<double> &solution, // solution !! at faces nodes
-             const std::vector<const fullMatrix<double>*> & solutionOnElements,
+             const std::vector<const fullMatrix<double>*> solutionOnElements,
 				     fullMatrix<double> &residual // residual !! at faces nodes
 				      )
 { 
@@ -450,7 +450,7 @@ void dgResidual::registerBindings (binding *b)
   mb = cb->addMethod("computeAndMap1Group",&dgResidualInterface::computeAndMap1Group);
   mb->setDescription("compute the residual for one group given a dgDofContainer solution"); 
   mb->setArgNames("group", "solution", "residual", NULL);
-//  mb = cb->addMethod("compute1Group", &dgResidualInterface::compute1Group);
-  //mb->setDescription("compute the residual for one group given fullMatrices with the solution at faces nodes and at element nodes"); 
-  //mb->setArgNames("group", "solutionFaces", "solutionOnElements", "residual", NULL);
+  mb = cb->addMethod("compute1Group", &dgResidualInterface::compute1Group);
+  mb->setDescription("compute the residual for one group given fullMatrices with the solution at faces nodes and at element nodes"); 
+  mb->setArgNames("group", "solutionFaces", "solutionOnElements", "residual", NULL);
 }
diff --git a/Solver/dgResidual.h b/Solver/dgResidual.h
index e633056eb8..ebd382cb01 100644
--- a/Solver/dgResidual.h
+++ b/Solver/dgResidual.h
@@ -35,7 +35,7 @@ class dgResidualInterface {
   void compute1Group ( //dofManager &dof, // the DOF manager (maybe useless here)
 				     dgGroupOfFaces &group, 
 				     const fullMatrix<double> &solution, // solution !! at faces nodes
-             const std::vector<const fullMatrix<double>*> & solutionOnElements,
+             const std::vector<const fullMatrix<double>*> solutionOnElements,
 				     fullMatrix<double> &residual // residual !! at faces nodes
             );
   void computeAndMap1Group (dgGroupOfFaces &faces, dgDofContainer &solution, dgDofContainer &residual);
diff --git a/Solver/dgRungeKuttaMultirate.cpp b/Solver/dgRungeKuttaMultirate.cpp
index ece9287147..777966fb4d 100644
--- a/Solver/dgRungeKuttaMultirate.cpp
+++ b/Solver/dgRungeKuttaMultirate.cpp
@@ -112,8 +112,6 @@ dgRungeKuttaMultirate::dgRungeKuttaMultirate(dgGroupCollection* gc,dgConservatio
   }
   for(int iGroup=0;iGroup<gc->getNbFaceGroups();iGroup++){
     dgGroupOfFaces *gf=gc->getFaceGroup(iGroup);
-    /*if(gf->getNbGroupOfConnections()!=2)
-      continue;*/
     for(int i=0;i<gf->getNbGroupOfConnections();i++){
       const dgGroupOfElements *ge = &gf->getGroupOfConnections(i).getGroupOfElements();
       if(ge->getIsInnerMultirateBuffer()){
@@ -126,23 +124,6 @@ dgRungeKuttaMultirate::dgRungeKuttaMultirate(dgGroupCollection* gc,dgConservatio
       }
     }
   }
-  /*for(int iGroup=0;iGroup<gc->getNbFaceGroups();iGroup++){
-    dgGroupOfFaces *gf=gc->getFaceGroup(iGroup);
-    if(gf->getNbGroupOfConnections()!=1)
-      continue;
-    const dgGroupOfElements *ge[1];
-    ge[0]=&gf->getGroupOfConnections(0).getGroupOfElements();
-    for(int i=0;i<1;i++){
-      if(ge[i]->getIsInnerMultirateBuffer()){
-        _innerBufferGroupsOfElements[ge[i]->getMultirateExponent()].second.push_back(gf);
-      }
-      else if(ge[i]->getIsOuterMultirateBuffer()){
-        _outerBufferGroupsOfElements[ge[i]->getMultirateExponent()].second.push_back(gf);
-      }else{
-        _bulkGroupsOfElements[ge[i]->getMultirateExponent()].second.push_back(gf);
-      }
-    }
-  }*/
   // Removing duplicate entries
   for(int iExp=0;iExp<=_maxExponent;iExp++){
     std::vector<dgGroupOfFaces*>*v[3];
diff --git a/Solver/function.cpp b/Solver/function.cpp
index db348626dd..8045f47e87 100644
--- a/Solver/function.cpp
+++ b/Solver/function.cpp
@@ -7,11 +7,61 @@
 #include "dgDofContainer.h"
 #include "dgGroupOfElements.h"
 #include "GModel.h"
-
 #if defined(HAVE_DLOPEN)
   #include "dlfcn.h"
 #endif
 
+class functionNew : public function{
+  protected :
+  std::vector<function*> dep;
+  virtual void call (fullMatrix<double> &res) {throw;}
+  virtual void call (const fullMatrix<double> &arg0, const fullMatrix<double> &res) {throw;};
+  virtual void call (const fullMatrix<double> &arg0, const fullMatrix<double> &arg1, const fullMatrix<double> &res) {throw;};
+  virtual void call (const fullMatrix<double> &arg0, const fullMatrix<double> &arg1, const fullMatrix<double> &arg2, fullMatrix<double> &res) {throw;};
+  virtual void call (const fullMatrix<double> &arg0, const fullMatrix<double> &arg1, const fullMatrix<double> &arg2, const fullMatrix<double> &arg3, fullMatrix<double> &res) {throw;};
+  virtual void call (const fullMatrix<double> &arg0, const fullMatrix<double> &arg1, const fullMatrix<double> &arg2, const fullMatrix<double> &arg3, const fullMatrix<double> &arg4, fullMatrix<double> &res) {throw;};
+  virtual void call (const fullMatrix<double> &arg0, const fullMatrix<double> &arg1, const fullMatrix<double> &arg2, const fullMatrix<double> &arg3, const fullMatrix<double> &arg4, const fullMatrix<double> &arg5, fullMatrix<double> &res) {throw;};
+  public :
+  virtual void call (fullMatrix<double> &res, std::vector<const fullMatrix<double>*> &depM) {
+    switch (dep.size()) {
+      case 0 : call(res); break;
+      case 1 : call(*depM[0], res); break;
+      case 2 : call(*depM[0], *depM[1], res); break;
+      case 3 : call(*depM[0], *depM[1], *depM[2], res); break;
+      case 4 : call(*depM[0], *depM[1], *depM[2], *depM[3], res); break;
+      case 5 : call(*depM[0], *depM[1], *depM[2], *depM[3], *depM[4], res); break;
+      case 6 : call(*depM[0], *depM[1], *depM[2], *depM[3], *depM[4], *depM[5], res); break;
+      default : Msg::Error("function are not implemented for %i arguments\n", dep.size());
+    }
+  }
+  int _nbCol;
+  class data : public dataCacheDouble {
+    functionNew *_function;
+    std::vector<dataCacheDouble *> _dependencies;
+    std::vector<const fullMatrix<double> *> _depM;
+    public:
+    data(functionNew *f, dataCacheMap *m):
+      dataCacheDouble(*m,1,f->_nbCol)
+    {
+      _function = f;
+      _dependencies.resize ( _function->dep.size());
+      _depM.resize (_function->dep.size());
+      for (int i=0;i<_function->dep.size();i++)
+        _dependencies[i] = &m->get(_function->dep[i],this);
+    }
+    void _eval()
+    {
+      for(int i=0;i<_dependencies.size(); i++)
+        _depM[i] = &(*_dependencies[i])();
+      _function->call(_value, _depM);
+    }
+  };
+  dataCacheDouble *newDataCache(dataCacheMap *m)
+  {
+    return new data(this, m);
+  }
+};
+
 // dataCache members
 dataCache::dataCache(dataCacheMap *cacheMap) : _valid(false) {
   cacheMap->addDataCache(this); //this dataCache can be deleted when the dataCacheMap is deleted
@@ -395,7 +445,6 @@ void dataCacheDouble::resize() {
   _value = fullMatrix<double>(_nRowByPoint==0?1:_nRowByPoint*_cacheMap.getNbEvaluationPoints(),_value.size2());
 }
 
-#if defined(HAVE_DLOPEN)
 //functionC
 class functionC : public function {
   void (*callback)(void);
@@ -455,6 +504,7 @@ class functionC : public function {
     }
   };
   public:
+#if defined(HAVE_DLOPEN)
   functionC (std::string file, std::string symbol, int nbCol, std::vector<const function *> dependencies):
       _dependenciesF(dependencies),_nbCol(nbCol)
   {
@@ -470,12 +520,12 @@ class functionC : public function {
     _name = oss.str();
     function::add(_name,this);
   }
+#endif
   dataCacheDouble *newDataCache(dataCacheMap *m)
   {
     return new data(this,m);
   }
 };
-#endif
 
 
 #include "Bindings.h"
diff --git a/Solver/function.h b/Solver/function.h
index 74764b99cb..5899982d94 100644
--- a/Solver/function.h
+++ b/Solver/function.h
@@ -187,12 +187,6 @@ class dataCacheMap {
     _toResize.insert(data);
   }
  public:
-  // dg Part
-  //list of dgDofContainer that have to be evaluated, this not work as a function as it depends on the algorithm
-  std::map<dgDofContainer*,dataCacheDouble*> fields;
-  //list of dgDofContainer whom gradient are needed
-  std::map<dgDofContainer*,dataCacheDouble*> gradientFields;
-  // end dg Part
   dataCacheDouble *_solution, *_solutionGradient, *_parametricCoordinates, *_normals;
   dataCacheDouble &getSolution(dataCacheDouble *caller);
   dataCacheDouble &getSolutionGradient(dataCacheDouble *caller);
-- 
GitLab