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

simplify functions

parent 30c743fa
No related branches found
No related tags found
No related merge requests found
...@@ -104,6 +104,7 @@ static void reportErrors(lua_State *L, int status) ...@@ -104,6 +104,7 @@ static void reportErrors(lua_State *L, int status)
if ( status!=0 ) { if ( status!=0 ) {
std::cerr << "-- " << lua_tostring(L, -1) << std::endl; std::cerr << "-- " << lua_tostring(L, -1) << std::endl;
lua_pop(L, 1); // remove error message lua_pop(L, 1); // remove error message
printf("exit now\n");
exit(1); //we need this for automatic test exit(1); //we need this for automatic test
} }
} }
...@@ -368,7 +369,6 @@ binding::binding(){ ...@@ -368,7 +369,6 @@ binding::binding(){
dgFunctionIntegrator::registerBindings(this); dgFunctionIntegrator::registerBindings(this);
fullMatrix<double>::registerBindings(this); fullMatrix<double>::registerBindings(this);
function::registerBindings(this); function::registerBindings(this);
functionLua::registerBindings(this);
gmshOptions::registerBindings(this); gmshOptions::registerBindings(this);
Msg::registerBindings(this); Msg::registerBindings(this);
linearSystemCSRGmm<double>::registerBindings(this); linearSystemCSRGmm<double>::registerBindings(this);
......
...@@ -487,7 +487,6 @@ static int luaCall(lua_State *L,tRet (*_f)(t0)) { ...@@ -487,7 +487,6 @@ static int luaCall(lua_State *L,tRet (*_f)(t0)) {
}; };
template < typename tRet> template < typename tRet>
static int luaCall(lua_State *L,tRet (*_f)()) { static int luaCall(lua_State *L,tRet (*_f)()) {
printf("top=%i\n",lua_gettop(L));
if (lua_gettop(L)==1) if (lua_gettop(L)==1)
lua_remove(L,1); lua_remove(L,1);
luaStack<tRet>::push(L,(*(_f))()); luaStack<tRet>::push(L,(*(_f))());
......
...@@ -155,6 +155,15 @@ class fullMatrix ...@@ -155,6 +155,15 @@ class fullMatrix
} }
return false; // no reallocation return false; // no reallocation
} }
void setAsProxy(const fullMatrix<scalar> &original)
{
if(_data && _own_data)
delete [] _data;
_c = original._c;
_r = original._r;
_own_data = false;
_data = original._data;
}
void setAsProxy(const fullMatrix<scalar> &original, int c_start, int c) void setAsProxy(const fullMatrix<scalar> &original, int c_start, int c)
{ {
if(_data && _own_data) if(_data && _own_data)
......
model = GModel() model = GModel()
model:load ('stommel_square.msh') model:load ('stommel_square.msh')
order = 2 order = 1
dimension = 2 dimension = 2
CFunctions =[[ CFunctions =[[
...@@ -45,8 +45,6 @@ for i=1,60000 do ...@@ -45,8 +45,6 @@ for i=1,60000 do
norm = rk:iterate33(claw,150*(3/(2.*order+1)/2),solution) norm = rk:iterate33(claw,150*(3/(2.*order+1)/2),solution)
if ( i%100 ==0 ) then if ( i%100 ==0 ) then
print ('iter ', i, norm) print ('iter ', i, norm)
end
if ( i%100 ==0 ) then
solution:exportMsh(string.format('output/solution-%06d',i)) solution:exportMsh(string.format('output/solution-%06d',i))
end end
end end
......
...@@ -24,9 +24,7 @@ class dgConservationLawShallowWater1d : public dgConservationLaw { ...@@ -24,9 +24,7 @@ class dgConservationLawShallowWater1d : public dgConservationLaw {
dgConservationLawShallowWater1d() dgConservationLawShallowWater1d()
{ {
_nbf = 2; // eta u _nbf = 2; // eta u
fullMatrix<double> zero(1,1); function *fzero = functionConstantNew(0.);
zero(0,0) = 0.0;
functionConstant *fzero = new functionConstant(&zero);
_pressure = fzero; _pressure = fzero;
_celerity = fzero; _celerity = fzero;
_bathymetry = fzero; _bathymetry = fzero;
......
...@@ -25,9 +25,7 @@ class dgConservationLawShallowWater2d : public dgConservationLaw { ...@@ -25,9 +25,7 @@ class dgConservationLawShallowWater2d : public dgConservationLaw {
dgConservationLawShallowWater2d() dgConservationLawShallowWater2d()
{ {
_nbf = 3; // eta u v _nbf = 3; // eta u v
fullMatrix<double> zero(1,1); function *fzero = functionConstantNew(0.);
zero(0,0) = 0.0;
functionConstant *fzero = new functionConstant(&zero);
_bathymetry = fzero; _bathymetry = fzero;
_linearDissipation = fzero; _linearDissipation = fzero;
_coriolisFactor = fzero; _coriolisFactor = fzero;
......
This diff is collapsed.
...@@ -126,20 +126,23 @@ class dataCacheDouble : public dataCache { ...@@ -126,20 +126,23 @@ class dataCacheDouble : public dataCache {
// 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 {
private: int _nbCol;
static std::map<std::string, function*> _allFunctions; protected :
protected: std::vector<const function*> dep;
std::string _name; virtual void call (dataCacheMap *m, fullMatrix<double> &res) {throw;}
public: virtual void call (dataCacheMap *m, const fullMatrix<double> &arg0, const fullMatrix<double> &res) {throw;};
static bool add(const std::string functionName, function *f); virtual void call (dataCacheMap *m, const fullMatrix<double> &arg0, const fullMatrix<double> &arg1, const fullMatrix<double> &res) {throw;};
static function *get(std::string functionName, bool acceptNull=false); 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 dataCacheDouble *newDataCache(dataCacheMap *m) =0; 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;};
inline std::string getName()const {return _name;} public :
virtual ~function(){}; virtual ~function(){};
static void registerBindings(binding *b); 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);
}; };
// A special node in the dependency tree for which all the leafs // A special node in the dependency tree for which all the leafs
...@@ -209,20 +212,8 @@ class dataCacheMap { ...@@ -209,20 +212,8 @@ class dataCacheMap {
inline int getNbEvaluationPoints(){return _nbEvaluationPoints;} inline int getNbEvaluationPoints(){return _nbEvaluationPoints;}
~dataCacheMap(); ~dataCacheMap();
}; };
class functionConstant : public function {
public:
class data ;
fullMatrix<double> _source;
dataCacheDouble *newDataCache(dataCacheMap *m);
functionConstant(const fullMatrix<double> *source);
functionConstant(std::vector<double> source);
};
class functionMesh2Mesh : public function { function *functionConstantNew(const std::vector<double>&);
dgDofContainer *_dofContainer; function *functionConstantNew(double);
public:
class data ;
dataCacheDouble *newDataCache(dataCacheMap *m);
functionMesh2Mesh(dgDofContainer *dofc) ;
};
#endif #endif
...@@ -7,53 +7,4 @@ ...@@ -7,53 +7,4 @@
#include "function.h" #include "function.h"
#include "Bindings.h" #include "Bindings.h"
// function that is defined in Lua // function that is defined in Lua
class functionLua::data : public dataCacheDouble{
private:
const functionLua *_function;
std::vector<dataCacheDouble *> _dependencies;
public:
data(const functionLua *f, dataCacheMap *m):
dataCacheDouble(*m,1,f->_nbCol),
_function(f)
{
_dependencies.resize ( _function->_dependenciesF.size());
for (int i=0;i<_function->_dependenciesF.size();i++)
_dependencies[i] = &m->get(_function->_dependenciesF[i],this);
}
void _eval()
{
lua_getfield(_function->_L, LUA_GLOBALSINDEX, _function->_luaFunctionName.c_str());
for (int i=0;i< _dependencies.size();i++){
const fullMatrix<double> *data = &(*_dependencies[i])();
luaStack<const fullMatrix<double>*>::push(_function->_L,data);
}
luaStack<const fullMatrix<double>*>::push(_function->_L,&_value);
lua_call(_function->_L,_dependencies.size()+1,0); /* call Lua function */
}
};
functionLua::functionLua (int nbCol, std::string luaFunctionName, std::vector<const function*> dependencies, lua_State *L)
: _luaFunctionName(luaFunctionName), _dependenciesF(dependencies),_L(L),_nbCol(nbCol)
{
static int c=0;
std::ostringstream oss;
oss<<"luaFunction_"<<c++;
_name = oss.str();
function::add(_name,this);
}
dataCacheDouble *functionLua::newDataCache(dataCacheMap *m)
{
return new data(this,m);
}
void functionLua::registerBindings(binding *b){
classBinding *cb= b->addClass<functionLua>("functionLua");
cb->setDescription("A function (see the 'function' documentation entry) defined in LUA.");
methodBinding *mb;
mb = cb->setConstructor<functionLua,int,std::string,std::vector<const function*>,lua_State*>();
mb->setArgNames("d", "f", "dep", NULL);
mb->setDescription("A new functionLua which evaluates a vector of dimension 'd' using the lua function 'f'. This function can take other functions as arguments listed by the 'dep' vector.");
cb->setParentClass<function>();
}
#endif // HAVE LUA #endif // HAVE LUA
...@@ -2,22 +2,7 @@ ...@@ -2,22 +2,7 @@
#ifndef _LUA_FUNCTION_H_ #ifndef _LUA_FUNCTION_H_
#define _LUA_FUNCTION_H_ #define _LUA_FUNCTION_H_
#if defined(HAVE_LUA) #if defined(HAVE_LUA)
#include "function.h"
class lua_State;
#include <string>
#include <vector>
class binding; class binding;
class functionLua : public function { void functionLuaRegisterBindings(binding *b);
lua_State *_L;
std::string _luaFunctionName;
std::vector<const function*> _dependenciesF;
int _nbCol;
class data;
public:
functionLua (int nbCol, std::string luaFunctionName, std::vector<const function*> dependencies, lua_State *L);
dataCacheDouble *newDataCache(dataCacheMap *m);
static void registerBindings(binding *b);
};
#endif // HAVE LUA #endif // HAVE LUA
#endif // _LUA_FUNCTION_H_ #endif // _LUA_FUNCTION_H_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment