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

add time function and remove dgSystemOfEquation

parent 02456621
No related branches found
No related tags found
No related merge requests found
...@@ -132,33 +132,24 @@ dataCacheMap::~dataCacheMap() ...@@ -132,33 +132,24 @@ dataCacheMap::~dataCacheMap()
// now some example of functions // now some example of functions
// constant values copied over each line // constant values copied over each line
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];
}
}
};
function *functionConstantNew(double v) { functionConstant *functionConstantNew(double v) {
std::vector<double> vec(1); std::vector<double> vec(1);
vec[0]=v; vec[0]=v;
return new functionConstant(vec); return new functionConstant(vec);
} }
function *functionConstantNew(const std::vector<double> &v) { functionConstant *functionConstantNew(const std::vector<double> &v) {
return new functionConstant(v); return new functionConstant(v);
} }
void functionConstant::set(double val) {
if(getNbCol() != 1) {
Msg::Error ("set scalar value on a vectorial constant function");
}
_source(0,0) = val;
}
class functionSum : public function { class functionSum : public function {
...@@ -430,10 +421,13 @@ class functionC : public function { ...@@ -430,10 +421,13 @@ class functionC : public function {
}; };
void function::registerBindings(binding *b){ void function::registerBindings(binding *b){
classBinding *cb = b->addClass<function>("function"); classBinding *cb = b->addClass<function>("Function");
cb->setDescription("A generic function that can be evaluated on a set of points. Functions can call other functions and their values are cached so that if two different functions call the same function f, f is only evaluated once."); cb->setDescription("A generic function that can be evaluated on a set of points. Functions can call other functions and their values are cached so that if two different functions call the same function f, f is only evaluated once.");
methodBinding *mb; methodBinding *mb;
mb = cb->addMethod("getTime", &function::getTime);
mb->setDescription("Return function constant in space which contains the time value");
cb = b->addClass<functionConstant>("functionConstant"); cb = b->addClass<functionConstant>("functionConstant");
cb->setDescription("A constant (scalar or vector) function"); cb->setDescription("A constant (scalar or vector) function");
mb = cb->setConstructor<functionConstant,std::vector <double> >(); mb = cb->setConstructor<functionConstant,std::vector <double> >();
...@@ -529,3 +523,9 @@ functionReplaceCache::~functionReplaceCache() { ...@@ -529,3 +523,9 @@ functionReplaceCache::~functionReplaceCache() {
} }
delete map; delete map;
} }
functionConstant *function::_timeFunction = NULL;
functionConstant *function::getTime() {
if (! _timeFunction)
_timeFunction = functionConstantNew(0.);
return _timeFunction;
}
...@@ -14,12 +14,14 @@ class binding; ...@@ -14,12 +14,14 @@ class binding;
class function; class function;
class dataCacheDouble; class dataCacheDouble;
class functionConstant;
class functionReplace; class functionReplace;
class functionReplaceCache; class functionReplaceCache;
// An abstract interface to functions // An abstract interface to functions
// more explanation at the head of this file // more explanation at the head of this file
class function { class function {
static functionConstant *_timeFunction;
public : public :
class argument { class argument {
//iMap is the id of the dataCacheMap, e.g. on interfaces //iMap is the id of the dataCacheMap, e.g. on interfaces
...@@ -71,6 +73,7 @@ class function { ...@@ -71,6 +73,7 @@ class function {
static function *getSolutionGradient(); static function *getSolutionGradient();
static function *getParametricCoordinates(); static function *getParametricCoordinates();
static function *getNormals(); static function *getNormals();
static functionConstant *getTime();
}; };
// dataCache when the value is a matrix of double // dataCache when the value is a matrix of double
...@@ -240,8 +243,8 @@ class functionReplaceCache { ...@@ -240,8 +243,8 @@ class functionReplaceCache {
}; };
function *functionConstantNew(const std::vector<double>&); functionConstant *functionConstantNew(const std::vector<double>&);
function *functionConstantNew(double); functionConstant *functionConstantNew(double);
function *functionSumNew (const function *f0, const function *f1); function *functionSumNew (const function *f0, const function *f1);
class functionSolution : public function { class functionSolution : public function {
...@@ -261,4 +264,22 @@ class functionSolution : public function { ...@@ -261,4 +264,22 @@ class functionSolution : public function {
return _instance; return _instance;
} }
}; };
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 set(double val);
};
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment