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()
// now some example of functions
// 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);
vec[0]=v;
return new functionConstant(vec);
}
function *functionConstantNew(const std::vector<double> &v) {
functionConstant *functionConstantNew(const std::vector<double> &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 {
......@@ -430,10 +421,13 @@ class functionC : public function {
};
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.");
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->setDescription("A constant (scalar or vector) function");
mb = cb->setConstructor<functionConstant,std::vector <double> >();
......@@ -529,3 +523,9 @@ functionReplaceCache::~functionReplaceCache() {
}
delete map;
}
functionConstant *function::_timeFunction = NULL;
functionConstant *function::getTime() {
if (! _timeFunction)
_timeFunction = functionConstantNew(0.);
return _timeFunction;
}
......@@ -14,12 +14,14 @@ class binding;
class function;
class dataCacheDouble;
class functionConstant;
class functionReplace;
class functionReplaceCache;
// An abstract interface to functions
// more explanation at the head of this file
class function {
static functionConstant *_timeFunction;
public :
class argument {
//iMap is the id of the dataCacheMap, e.g. on interfaces
......@@ -71,6 +73,7 @@ class function {
static function *getSolutionGradient();
static function *getParametricCoordinates();
static function *getNormals();
static functionConstant *getTime();
};
// dataCache when the value is a matrix of double
......@@ -240,8 +243,8 @@ class functionReplaceCache {
};
function *functionConstantNew(const std::vector<double>&);
function *functionConstantNew(double);
functionConstant *functionConstantNew(const std::vector<double>&);
functionConstant *functionConstantNew(double);
function *functionSumNew (const function *f0, const function *f1);
class functionSolution : public function {
......@@ -261,4 +264,22 @@ class functionSolution : public function {
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment