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

dg : functionPython/functionC (I forgot to commit this one week ago)

parent b44d1db7
No related branches found
No related tags found
No related merge requests found
...@@ -34,6 +34,24 @@ ...@@ -34,6 +34,24 @@
#include "DivideAndConquer.h" #include "DivideAndConquer.h"
#include "Gmsh.h" #include "Gmsh.h"
#include "functionPython.h" #include "functionPython.h"
class errorHandler: public GmshMessage {
void operator()(std::string level, std::string message){
//const char *color = colorDefault;
std::cout<<level<<" : "<<message<<std::endl;
if (level=="Error" || level == "Fatal") {
//color = colorRed;
//color confuses ctest/cdash
//std::cout<<color<<level<<" : "<<message<<colorDefault<<"\n";
throw;
}
}
};
%}
%init %{
errorHandler *eH = new errorHandler;
Msg::SetCallback(eH);
GmshInitialize();
%} %}
namespace std { namespace std {
......
...@@ -71,25 +71,19 @@ function *function::getSolution() ...@@ -71,25 +71,19 @@ function *function::getSolution()
// Get Solution Gradient + Additionnal class // Get Solution Gradient + Additionnal class
class functionSolutionGradient : public function { functionSolutionGradient::functionSolutionGradient():function(0){}
static functionSolutionGradient *_instance; void functionSolutionGradient::call(dataCacheMap *m, fullMatrix<double> &sol)
// constructor is private only 1 instance can exists, call get to
// access the instance
functionSolutionGradient():function(0){}
public:
void call(dataCacheMap *m, fullMatrix<double> &sol)
{ {
Msg::Error("a function requires the gradient of the solution but " Msg::Error("a function requires the gradient of the solution but "
"this algorithm does not provide the gradient of the solution"); "this algorithm does not provide the gradient of the solution");
throw; throw;
} }
static function *get() function *functionSolutionGradient::get()
{ {
if(!_instance) if(!_instance)
_instance = new functionSolutionGradient(); _instance = new functionSolutionGradient();
return _instance; return _instance;
} }
};
functionSolutionGradient *functionSolutionGradient::_instance = NULL; functionSolutionGradient *functionSolutionGradient::_instance = NULL;
...@@ -606,11 +600,7 @@ class functionLua : public function { ...@@ -606,11 +600,7 @@ class functionLua : public function {
// functionC // functionC
class functionC : public function { void functionC::buildLibrary(std::string code, std::string filename)
std::vector<fullMatrix<double> > args;
void (*callback)(void);
public:
static void buildLibrary(std::string code, std::string filename)
{ {
//todo use CMAKE_CXX_COMPILER //todo use CMAKE_CXX_COMPILER
//todo use clean temporary file names //todo use clean temporary file names
...@@ -630,7 +620,7 @@ class functionC : public function { ...@@ -630,7 +620,7 @@ class functionC : public function {
UnlinkFile("_tmpSrc.cpp"); UnlinkFile("_tmpSrc.cpp");
UnlinkFile("_tmpMake.cpp"); UnlinkFile("_tmpMake.cpp");
} }
void call (dataCacheMap *m, fullMatrix<double> &val) void functionC::call (dataCacheMap *m, fullMatrix<double> &val)
{ {
switch (args.size()) { switch (args.size()) {
case 0 : case 0 :
...@@ -673,7 +663,7 @@ class functionC : public function { ...@@ -673,7 +663,7 @@ class functionC : public function {
Msg::Error("C callback not implemented for %i argurments", args.size()); Msg::Error("C callback not implemented for %i argurments", args.size());
} }
} }
functionC (std::string file, std::string symbol, int nbCol, functionC::functionC (std::string file, std::string symbol, int nbCol,
std::vector<const function *> dependencies): std::vector<const function *> dependencies):
function(nbCol) function(nbCol)
{ {
...@@ -691,7 +681,6 @@ class functionC : public function { ...@@ -691,7 +681,6 @@ class functionC : public function {
Msg::Error("Cannot construct functionC without dlopen"); Msg::Error("Cannot construct functionC without dlopen");
#endif #endif
} }
};
void function::registerBindings(binding *b) void function::registerBindings(binding *b)
......
...@@ -110,6 +110,16 @@ class functionSolution : public function { ...@@ -110,6 +110,16 @@ class functionSolution : public function {
} }
}; };
class functionSolutionGradient : public function {
static functionSolutionGradient *_instance;
// constructor is private only 1 instance can exists, call get to
// access the instance
functionSolutionGradient();
public:
void call(dataCacheMap *m, fullMatrix<double> &sol);
static function *get();
};
class functionReplaceCache { class functionReplaceCache {
public: public:
dataCacheMap *map; dataCacheMap *map;
...@@ -270,6 +280,16 @@ class functionConstant : public function { ...@@ -270,6 +280,16 @@ class functionConstant : public function {
void set(double val); void set(double val);
}; };
class functionC : public function {
std::vector<fullMatrix<double> > args;
void (*callback)(void);
public:
static void buildLibrary(std::string code, std::string filename) ;
void call (dataCacheMap *m, fullMatrix<double> &val) ;
functionC (std::string file, std::string symbol, int nbCol,
std::vector<const function *> dependencies);
};
functionConstant *functionConstantNew(const std::vector<double>&); functionConstant *functionConstantNew(const std::vector<double>&);
functionConstant *functionConstantNew(double); functionConstant *functionConstantNew(double);
......
...@@ -26,14 +26,15 @@ class functionPython : public function { ...@@ -26,14 +26,15 @@ class functionPython : public function {
} }
switch(args.size()) { switch(args.size()) {
case 0 : _pyargs = Py_BuildValue("(O)", _swigR); break; case 0 : _pyargs = Py_BuildValue("(O)", _swigR); break;
case 1 : _pyargs = Py_BuildValue("(OO)", _swigR, _swigA[0], _swigA[1], _swigA[2], _swigA[3], _swigA[4], _swigA[5], _swigA[6]); break; case 1 : _pyargs = Py_BuildValue("(OO)", _swigR, _swigA[0]); break;
case 2 : _pyargs = Py_BuildValue("(OOO)", _swigR, _swigA[0], _swigA[1], _swigA[2], _swigA[3], _swigA[4], _swigA[5], _swigA[6]); break; case 2 : _pyargs = Py_BuildValue("(OOO)", _swigR, _swigA[0], _swigA[1]); break;
case 3 : _pyargs = Py_BuildValue("(OOOO)", _swigR, _swigA[0], _swigA[1], _swigA[2], _swigA[3], _swigA[4], _swigA[5], _swigA[6]); break; case 3 : _pyargs = Py_BuildValue("(OOOO)", _swigR, _swigA[0], _swigA[1], _swigA[2]); break;
case 4 : _pyargs = Py_BuildValue("(OOOOO)", _swigR, _swigA[0], _swigA[1], _swigA[2], _swigA[3], _swigA[4], _swigA[5], _swigA[6]); break; case 4 : _pyargs = Py_BuildValue("(OOOOO)", _swigR, _swigA[0], _swigA[1], _swigA[2], _swigA[3]); break;
case 5 : _pyargs = Py_BuildValue("(OOOOOO)", _swigR, _swigA[0], _swigA[1], _swigA[2], _swigA[3], _swigA[4], _swigA[5], _swigA[6]); break; case 5 : _pyargs = Py_BuildValue("(OOOOOO)", _swigR, _swigA[0], _swigA[1], _swigA[2], _swigA[3], _swigA[4]); break;
case 6 : _pyargs = Py_BuildValue("(OOOOOOO)", _swigR, _swigA[0], _swigA[1], _swigA[2], _swigA[3], _swigA[4], _swigA[5], _swigA[6]); break; case 6 : _pyargs = Py_BuildValue("(OOOOOOO)", _swigR, _swigA[0], _swigA[1], _swigA[2], _swigA[3], _swigA[4], _swigA[5]); break;
case 7 : _pyargs = Py_BuildValue("(OOOOOOOO)", _swigR, _swigA[0], _swigA[1], _swigA[2], _swigA[3], _swigA[4], _swigA[5], _swigA[6]); break; case 7 : _pyargs = Py_BuildValue("(OOOOOOOO)", _swigR, _swigA[0], _swigA[1], _swigA[2], _swigA[3], _swigA[4], _swigA[5], _swigA[6]); break;
default:Msg::Error("python function not implemented for more than 7 arguments"); case 8 : _pyargs = Py_BuildValue("(OOOOOOOOO)", _swigR, _swigA[0], _swigA[1], _swigA[2], _swigA[3], _swigA[4], _swigA[5], _swigA[6], _swigA[7]); break;
default:Msg::Error("python function not implemented for more than 8 arguments");
} }
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment