ug4
lua_callback_observer.hpp
Go to the documentation of this file.
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 
9 
10 namespace ug {
11 
12 
13 template<class TDomain, class TAlgebra>
15 : public ITimeIntegratorObserver<TDomain, TAlgebra>
16 {
17 public:
21 
24 
25  LuaCallbackObserver(int lua_id)
26  : m_lua_callback(SPNULL), m_lua_id(lua_id) {}
27 
29  {}
30 
31  virtual bool step_process(SmartPtr<grid_function_type> uNew, int step, number time, number dt)
32  {
33  if (!m_lua_callback.valid())
34  return true;
35 
36  number lua_return_value;
37  m_u = uNew;
38  (*m_lua_callback)(lua_return_value, 4, (number) step, time, dt, (number) m_lua_id);
39 
40  return lua_return_value == 1;
41  }
42 
43  void set_callback(const char* luaCallback)
44  {
46  m_lua_callback->set_lua_callback(luaCallback, 4);
47  }
48 
50  { return m_u; }
51 
52 protected:
55  const int m_lua_id;
56 };
57 
58 }
59 
60 #endif
represents numerical solutions on a grid using an algebraic vector
Definition: grid_function.h:121
Abstract base class for time integration observer.
Definition: time_integrator_observer_interface.h:43
Definition: lua_callback_observer.hpp:16
virtual ~LuaCallbackObserver()
Definition: lua_callback_observer.hpp:28
const int m_lua_id
Definition: lua_callback_observer.hpp:55
SmartPtr< grid_function_type > m_u
Definition: lua_callback_observer.hpp:54
GridFunction< TDomain, TAlgebra > grid_function_type
Definition: lua_callback_observer.hpp:19
SmartPtr< grid_function_type > get_current_solution()
Definition: lua_callback_observer.hpp:49
ITimeIntegratorObserver< TDomain, TAlgebra > base_type
Definition: lua_callback_observer.hpp:18
LuaFunction< number, number > lua_function_type
Definition: lua_callback_observer.hpp:20
SmartPtr< lua_function_type > m_lua_callback
Definition: lua_callback_observer.hpp:53
void set_callback(const char *luaCallback)
Definition: lua_callback_observer.hpp:43
LuaCallbackObserver(int lua_id)
Definition: lua_callback_observer.hpp:25
LuaCallbackObserver()
Definition: lua_callback_observer.hpp:22
virtual bool step_process(SmartPtr< grid_function_type > uNew, int step, number time, number dt)
Definition: lua_callback_observer.hpp:31
const NullSmartPtr SPNULL
The equivalent to NULL for smart pointers.
Definition: smart_pointer.h:90
double number
Definition: types.h:124
the ug namespace
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition: smart_pointer.h:836