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

Merge dataCache and dataCacheDouble

parent ab2bfed8
No related branches found
No related tags found
No related merge requests found
...@@ -53,16 +53,12 @@ dataCacheDouble *function::newDataCache(dataCacheMap *m) ...@@ -53,16 +53,12 @@ dataCacheDouble *function::newDataCache(dataCacheMap *m)
return new data(this, 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
}
void dataCache::addMeAsDependencyOf (dataCache *newDep) void dataCacheDouble::addMeAsDependencyOf (dataCacheDouble *newDep)
{ {
_dependOnMe.insert(newDep); _dependOnMe.insert(newDep);
newDep->_iDependOn.insert(this); newDep->_iDependOn.insert(this);
for(std::set<dataCache*>::iterator it = _iDependOn.begin(); for(std::set<dataCacheDouble*>::iterator it = _iDependOn.begin();
it != _iDependOn.end(); it++) { it != _iDependOn.end(); it++) {
(*it)->_dependOnMe.insert(newDep); (*it)->_dependOnMe.insert(newDep);
newDep->_iDependOn.insert(*it); newDep->_iDependOn.insert(*it);
...@@ -71,14 +67,14 @@ void dataCache::addMeAsDependencyOf (dataCache *newDep) ...@@ -71,14 +67,14 @@ void dataCache::addMeAsDependencyOf (dataCache *newDep)
//dataCacheMap members //dataCacheMap members
static dataCacheDouble &returnDataCacheDouble(dataCacheDouble *data, dataCache *caller) static dataCacheDouble &returnDataCacheDouble(dataCacheDouble *data, dataCacheDouble *caller)
{ {
if(data==NULL) throw; if(data==NULL) throw;
if(caller) if(caller)
data->addMeAsDependencyOf(caller); data->addMeAsDependencyOf(caller);
return *data; return *data;
} }
dataCacheDouble &dataCacheMap::get(const function *f, dataCache *caller) dataCacheDouble &dataCacheMap::get(const function *f, dataCacheDouble *caller)
{ {
dataCacheDouble *&r= _cacheDoubleMap[f]; dataCacheDouble *&r= _cacheDoubleMap[f];
if(r==NULL) if(r==NULL)
...@@ -125,7 +121,7 @@ dataCacheDouble &dataCacheMap::provideNormals() ...@@ -125,7 +121,7 @@ dataCacheDouble &dataCacheMap::provideNormals()
dataCacheMap::~dataCacheMap() dataCacheMap::~dataCacheMap()
{ {
for (std::set<dataCache*>::iterator it = _toDelete.begin(); for (std::set<dataCacheDouble*>::iterator it = _toDelete.begin();
it!=_toDelete.end(); it++) { it!=_toDelete.end(); it++) {
delete *it; delete *it;
} }
...@@ -337,7 +333,7 @@ void dataCacheMap::setNbEvaluationPoints(int nbEvaluationPoints) { ...@@ -337,7 +333,7 @@ void dataCacheMap::setNbEvaluationPoints(int nbEvaluationPoints) {
} }
dataCacheDouble::dataCacheDouble(dataCacheMap &map,int nRowByPoint, int nCol): dataCacheDouble::dataCacheDouble(dataCacheMap &map,int nRowByPoint, int nCol):
dataCache(&map),_cacheMap(map),_value(nRowByPoint==0?1:nRowByPoint*map.getNbEvaluationPoints(),nCol){ _cacheMap(map),_value(nRowByPoint==0?1:nRowByPoint*map.getNbEvaluationPoints(),nCol){
_nRowByPoint=nRowByPoint; _nRowByPoint=nRowByPoint;
map.addDataCacheDouble(this); map.addDataCacheDouble(this);
}; };
......
...@@ -30,26 +30,27 @@ class dgDofContainer; ...@@ -30,26 +30,27 @@ class dgDofContainer;
class function; class function;
class dataCache { // 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
// then the size of the matrix is automatically adjusted
class dataCacheDouble {
friend class dataCacheMap; friend class dataCacheMap;
// pointers to all of the dataCache depending on me // pointers to all of the dataCache depending on me
std::set<dataCache*> _dependOnMe; std::set<dataCacheDouble*> _dependOnMe;
std::set<dataCache*> _iDependOn; std::set<dataCacheDouble*> _iDependOn;
protected : protected :
bool _valid; bool _valid;
// invalidates all the cached data that depends on me // invalidates all the cached data that depends on me
inline void _invalidateDependencies() inline void _invalidateDependencies()
{ {
// if this is too slow we can keep a C array cache of the _dependOnMe set // if this is too slow we can keep a C array cache of the _dependOnMe set
for(std::set<dataCache*>::iterator it = _dependOnMe.begin(); for(std::set<dataCacheDouble*>::iterator it = _dependOnMe.begin();
it!=_dependOnMe.end(); it++) it!=_dependOnMe.end(); it++)
(*it)->_valid=false; (*it)->_valid=false;
} }
dataCache(dataCacheMap *cacheMap);
virtual ~dataCache(){};
public : public :
// dataCacheMap is the only one supposed to call this // dataCacheMap is the only one supposed to call this
void addMeAsDependencyOf (dataCache *newDep); void addMeAsDependencyOf (dataCacheDouble *newDep);
inline bool somethingDependOnMe() { inline bool somethingDependOnMe() {
return !_dependOnMe.empty(); return !_dependOnMe.empty();
} }
...@@ -60,12 +61,10 @@ public : ...@@ -60,12 +61,10 @@ public :
return _iDependOn.size(); return _iDependOn.size();
} }
};
// 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
// then the size of the matrix is automatically adjusted
class dataCacheDouble : public dataCache {
int _nRowByPoint; int _nRowByPoint;
dataCacheMap &_cacheMap; dataCacheMap &_cacheMap;
protected: protected:
...@@ -75,21 +74,24 @@ class dataCacheDouble : public dataCache { ...@@ -75,21 +74,24 @@ class dataCacheDouble : public dataCache {
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) {
_invalidateDependencies(); if(_valid)
_invalidateDependencies();
_value=mat; _value=mat;
_valid=true; _valid=true;
} }
// take care if you use this you must ensure that the value pointed to are not modified // take care if you use this you must ensure that the value pointed to are not modified
// without further call to setAsProxy because the dependencies won't be invalidate // without further call to setAsProxy because the dependencies won't be invalidate
inline void setAsProxy(const fullMatrix<double> &mat, int cShift, int c) { inline void setAsProxy(const fullMatrix<double> &mat, int cShift, int c) {
_invalidateDependencies(); if(_valid)
_invalidateDependencies();
_value.setAsProxy(mat,cShift,c); _value.setAsProxy(mat,cShift,c);
_valid=true; _valid=true;
} }
// take care if you use this you must ensure that the value pointed to are not modified // take care if you use this you must ensure that the value pointed to are not modified
// without further call to setAsProxy because the dependencies won't be invalidate // without further call to setAsProxy because the dependencies won't be invalidate
inline void setAsProxy(const fullMatrix<double> &mat) { inline void setAsProxy(const fullMatrix<double> &mat) {
_invalidateDependencies(); if(_valid)
_invalidateDependencies();
_value.setAsProxy(mat,0,mat.size2()); _value.setAsProxy(mat,0,mat.size2());
_valid=true; _valid=true;
} }
...@@ -97,7 +99,8 @@ class dataCacheDouble : public dataCache { ...@@ -97,7 +99,8 @@ class dataCacheDouble : public dataCache {
// but you cannot keep the reference to the _value, you should always use the set function // but you cannot keep the reference to the _value, you should always use the set function
// to modify the _value // to modify the _value
inline fullMatrix<double> &set() { inline fullMatrix<double> &set() {
_invalidateDependencies(); if(_valid)
_invalidateDependencies();
_valid=true; _valid=true;
return _value; return _value;
} }
...@@ -147,7 +150,6 @@ class function { ...@@ -147,7 +150,6 @@ class function {
// more explanation at the head of this file // more explanation at the head of this file
class dataCacheMap { class dataCacheMap {
friend class dataCache;
friend class dataCacheDouble; friend class dataCacheDouble;
private: private:
int _nbEvaluationPoints; int _nbEvaluationPoints;
...@@ -165,14 +167,14 @@ class dataCacheMap { ...@@ -165,14 +167,14 @@ class dataCacheMap {
map._toInvalidateOnElement.erase(this); map._toInvalidateOnElement.erase(this);
} }
}; };
std::set<dataCache*> _toDelete; std::set<dataCacheDouble*> _toDelete;
std::set<dataCacheDouble*> _toResize; std::set<dataCacheDouble*> _toResize;
std::set<dataCacheDouble*> _toInvalidateOnElement; std::set<dataCacheDouble*> _toInvalidateOnElement;
MElement *_element; MElement *_element;
protected: protected:
void addDataCache(dataCache *data){ void addDataCache(dataCacheDouble *data){
_toDelete.insert(data); _toDelete.insert(data);
} }
void addDataCacheDouble(dataCacheDouble *data){ void addDataCacheDouble(dataCacheDouble *data){
...@@ -190,7 +192,7 @@ class dataCacheMap { ...@@ -190,7 +192,7 @@ class dataCacheMap {
dataCacheDouble &provideParametricCoordinates(); dataCacheDouble &provideParametricCoordinates();
dataCacheDouble &provideNormals(); dataCacheDouble &provideNormals();
dataCacheDouble &get(const function *f, dataCache *caller=0); dataCacheDouble &get(const function *f, dataCacheDouble *caller=0);
inline void setElement(MElement *element) { inline void setElement(MElement *element) {
_element=element; _element=element;
for(std::set<dataCacheDouble*>::iterator it = _toInvalidateOnElement.begin(); it!= _toInvalidateOnElement.end(); it++) { for(std::set<dataCacheDouble*>::iterator it = _toInvalidateOnElement.begin(); it!= _toInvalidateOnElement.end(); it++) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment