Skip to content
Snippets Groups Projects
Commit 44458a86 authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

merge function::data into dataCacheDouble

parent 02524835
No related branches found
No related tags found
No related merge requests found
...@@ -24,35 +24,7 @@ void function::call (dataCacheMap *m, fullMatrix<double> &res, std::vector<const ...@@ -24,35 +24,7 @@ void function::call (dataCacheMap *m, fullMatrix<double> &res, std::vector<const
default : Msg::Error("function are not implemented for %i arguments\n", dep.size()); default : Msg::Error("function are not implemented for %i arguments\n", dep.size());
} }
} }
class function::data : public dataCacheDouble {
function *_function;
dataCacheMap *_m;
std::vector<dataCacheDouble *> _dependencies;
std::vector<const fullMatrix<double> *> _depM;
public:
data(function *f, dataCacheMap *m):
dataCacheDouble(*m,1,f->_nbCol)
{
_function = f;
_m = m;
_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(_m, _value, _depM);
}
};
function::function(int nbCol):_nbCol(nbCol){}; function::function(int nbCol):_nbCol(nbCol){};
dataCacheDouble *function::newDataCache(dataCacheMap *m)
{
return new data(this, m);
}
void dataCacheDouble::addMeAsDependencyOf (dataCacheDouble *newDep) void dataCacheDouble::addMeAsDependencyOf (dataCacheDouble *newDep)
{ {
...@@ -78,7 +50,7 @@ dataCacheDouble &dataCacheMap::get(const function *f, dataCacheDouble *caller) ...@@ -78,7 +50,7 @@ dataCacheDouble &dataCacheMap::get(const function *f, dataCacheDouble *caller)
{ {
dataCacheDouble *&r= _cacheDoubleMap[f]; dataCacheDouble *&r= _cacheDoubleMap[f];
if(r==NULL) if(r==NULL)
r = const_cast<function*>(f)->newDataCache(this); r = new dataCacheDouble(this, const_cast<function*>(f));
return returnDataCacheDouble(r,caller); return returnDataCacheDouble(r,caller);
} }
dataCacheDouble &dataCacheMap::getSolution(dataCacheDouble *caller) dataCacheDouble &dataCacheMap::getSolution(dataCacheDouble *caller)
...@@ -337,6 +309,19 @@ dataCacheDouble::dataCacheDouble(dataCacheMap &map,int nRowByPoint, int nCol): ...@@ -337,6 +309,19 @@ dataCacheDouble::dataCacheDouble(dataCacheMap &map,int nRowByPoint, int nCol):
_nRowByPoint=nRowByPoint; _nRowByPoint=nRowByPoint;
map.addDataCacheDouble(this); map.addDataCacheDouble(this);
}; };
dataCacheDouble::dataCacheDouble(dataCacheMap *m, function *f):
_cacheMap(*m),_value(m->getNbEvaluationPoints(),f->getNbCol())
{
_nRowByPoint=1;
m->addDataCacheDouble(this);
_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 dataCacheDouble::resize() { void dataCacheDouble::resize() {
_value = fullMatrix<double>(_nRowByPoint==0?1:_nRowByPoint*_cacheMap.getNbEvaluationPoints(),_value.size2()); _value = fullMatrix<double>(_nRowByPoint==0?1:_nRowByPoint*_cacheMap.getNbEvaluationPoints(),_value.size2());
} }
......
...@@ -29,6 +29,28 @@ class dgDofContainer; ...@@ -29,6 +29,28 @@ class dgDofContainer;
// a node in the dependency tree. The usefull field is _dependOnMe which is the set of every other nodes that depend on me. When the value of this node change all nodes depending on this one are marked as "invalid" and will be recomputed the next time their data are accessed. To be able to maintain _dependOnMe up to date when a new node is inserted in the tree, we need _iDependOn list. So we do not really store a tree but instead each node contain a complete list of all it's parents and all it's children (and the parents of the parents of ... of its parents and the children of the children of ... of it's children). This way invalidate all the dependencies of a node is really fast and does not involve a complex walk accross the tree structure. // a node in the dependency tree. The usefull field is _dependOnMe which is the set of every other nodes that depend on me. When the value of this node change all nodes depending on this one are marked as "invalid" and will be recomputed the next time their data are accessed. To be able to maintain _dependOnMe up to date when a new node is inserted in the tree, we need _iDependOn list. So we do not really store a tree but instead each node contain a complete list of all it's parents and all it's children (and the parents of the parents of ... of its parents and the children of the children of ... of it's children). This way invalidate all the dependencies of a node is really fast and does not involve a complex walk accross the tree structure.
class function; class function;
class dataCacheDouble;
// An abstract interface to functions
// more explanation at the head of this file
class function {
int _nbCol;
protected :
virtual void call (dataCacheMap *m, fullMatrix<double> &res) {throw;}
virtual void call (dataCacheMap *m, const fullMatrix<double> &arg0, const fullMatrix<double> &res) {throw;};
virtual void call (dataCacheMap *m, const fullMatrix<double> &arg0, const fullMatrix<double> &arg1, const fullMatrix<double> &res) {throw;};
virtual void call (dataCacheMap *m, const fullMatrix<double> &arg0, const fullMatrix<double> &arg1, const fullMatrix<double> &arg2, fullMatrix<double> &res) {throw;};
virtual void call (dataCacheMap *m, const fullMatrix<double> &arg0, const fullMatrix<double> &arg1, const fullMatrix<double> &arg2, const fullMatrix<double> &arg3, fullMatrix<double> &res) {throw;};
virtual void call (dataCacheMap *m, 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 (dataCacheMap *m, 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 :
std::vector<const function*> dep;
virtual ~function(){};
static void registerBindings(binding *b);
virtual void call (dataCacheMap *m, fullMatrix<double> &res, std::vector<const fullMatrix<double>*> &depM);
function(int nbCol);
inline int getNbCol()const {return _nbCol;}
};
// dataCache when the value is a matrix of double // dataCache when the value is a matrix of double
// the user should provide the number of rows by evaluating points and the number of columns // the user should provide the number of rows by evaluating points and the number of columns
...@@ -61,16 +83,21 @@ public : ...@@ -61,16 +83,21 @@ public :
return _iDependOn.size(); return _iDependOn.size();
} }
std::vector<dataCacheDouble*> _dependencies;
std::vector<const fullMatrix<double>*> _depM;
int _nRowByPoint; int _nRowByPoint;
dataCacheMap &_cacheMap; dataCacheMap &_cacheMap;
function *_function;
protected: protected:
fullMatrix<double> _value; fullMatrix<double> _value;
// do the actual computation and put the result into _value // do the actual computation and put the result into _value
virtual void _eval()=0; virtual void _eval()
{
for(int i=0;i<_dependencies.size(); i++)
_depM[i] = &(*_dependencies[i])();
_function->call(&_cacheMap, _value, _depM);
}
public: public:
//set the value (without computing it by _eval) and invalidate the dependencies //set the value (without computing it by _eval) and invalidate the dependencies
inline void set(const fullMatrix<double> &mat) { inline void set(const fullMatrix<double> &mat) {
...@@ -123,30 +150,10 @@ public : ...@@ -123,30 +150,10 @@ public :
} }
void resize(); void resize();
dataCacheDouble(dataCacheMap &map,int nRowByPoints, int nCol); dataCacheDouble(dataCacheMap &map,int nRowByPoints, int nCol);
dataCacheDouble(dataCacheMap *,function *f);
virtual ~dataCacheDouble(){}; virtual ~dataCacheDouble(){};
}; };
// An abstract interface to functions
// more explanation at the head of this file
class function {
int _nbCol;
protected :
std::vector<const function*> dep;
virtual void call (dataCacheMap *m, fullMatrix<double> &res) {throw;}
virtual void call (dataCacheMap *m, const fullMatrix<double> &arg0, const fullMatrix<double> &res) {throw;};
virtual void call (dataCacheMap *m, const fullMatrix<double> &arg0, const fullMatrix<double> &arg1, const fullMatrix<double> &res) {throw;};
virtual void call (dataCacheMap *m, const fullMatrix<double> &arg0, const fullMatrix<double> &arg1, const fullMatrix<double> &arg2, fullMatrix<double> &res) {throw;};
virtual void call (dataCacheMap *m, const fullMatrix<double> &arg0, const fullMatrix<double> &arg1, const fullMatrix<double> &arg2, const fullMatrix<double> &arg3, fullMatrix<double> &res) {throw;};
virtual void call (dataCacheMap *m, 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 (dataCacheMap *m, 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 ~function(){};
static void registerBindings(binding *b);
virtual void call (dataCacheMap *m, fullMatrix<double> &res, std::vector<const fullMatrix<double>*> &depM);
class data;
function(int nbCol);
dataCacheDouble *newDataCache(dataCacheMap *m);
};
// more explanation at the head of this file // more explanation at the head of this file
class dataCacheMap { class dataCacheMap {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment