Line data Source code
1 :
2 :
3 : #ifndef __H__UG__LIB_DISC__TIME_DISC__TIME_INTEGRATOR_OBSERVERS__LUA_CALLBACK_OBSERVER
4 : #define __H__UG__LIB_DISC__TIME_DISC__TIME_INTEGRATOR_OBSERVERS__LUA_CALLBACK_OBSERVER
5 :
6 :
7 :
8 : #include "time_integrator_observer_interface.h"
9 :
10 : namespace ug {
11 :
12 :
13 : template<class TDomain, class TAlgebra>
14 : class LuaCallbackObserver
15 : : public ITimeIntegratorObserver<TDomain, TAlgebra>
16 : {
17 : public:
18 : typedef ITimeIntegratorObserver<TDomain, TAlgebra> base_type;
19 : typedef GridFunction<TDomain, TAlgebra> grid_function_type;
20 : typedef LuaFunction<number, number> lua_function_type;
21 :
22 0 : LuaCallbackObserver()
23 0 : : m_lua_callback(SPNULL), m_lua_id(0) {}
24 :
25 0 : LuaCallbackObserver(int lua_id)
26 0 : : m_lua_callback(SPNULL), m_lua_id(lua_id) {}
27 :
28 0 : virtual ~LuaCallbackObserver()
29 0 : {}
30 :
31 0 : virtual bool step_process(SmartPtr<grid_function_type> uNew, int step, number time, number dt)
32 : {
33 0 : if (!m_lua_callback.valid())
34 : return true;
35 :
36 : number lua_return_value;
37 0 : m_u = uNew;
38 0 : (*m_lua_callback)(lua_return_value, 4, (number) step, time, dt, (number) m_lua_id);
39 :
40 0 : return lua_return_value == 1;
41 : }
42 :
43 0 : void set_callback(const char* luaCallback)
44 : {
45 0 : m_lua_callback = make_sp(new lua_function_type());
46 0 : m_lua_callback->set_lua_callback(luaCallback, 4);
47 0 : }
48 :
49 0 : SmartPtr<grid_function_type> get_current_solution()
50 0 : { return m_u; }
51 :
52 : protected:
53 : SmartPtr<lua_function_type> m_lua_callback;
54 : SmartPtr<grid_function_type> m_u;
55 : const int m_lua_id;
56 : };
57 :
58 : }
59 :
60 : #endif
|