diff --git a/Common/LuaBindings.h b/Common/LuaBindings.h index 9d201a57e98aa23d2a72be5b7a0c12cc4172db8c..6e28eb222e8ecc66840a1195003f9e25da492bc4 100644 --- a/Common/LuaBindings.h +++ b/Common/LuaBindings.h @@ -58,7 +58,7 @@ class luaStack { printf("error cannot get generic class in lua, only pointers are implemented\n"); } static void push(lua_State *L, type obj){ - printf("error cannot push generic class in lua, only pointers are implemented\n"); + Msg::Error("cannot push generic class in lua, only pointers are implemented\n"); } }; @@ -69,7 +69,7 @@ class luaStack<lua_State *>{ return L; } static void push(lua_State *L, int i){ - printf("error cannot push a lua_State in lua\n"); + Msg::Error("error cannot push a lua_State in lua\n"); } }; @@ -159,6 +159,42 @@ class luaStack<const type *>{ } }; +template <typename type> +class luaStack<type &>{ + typedef struct { type *pT;} userdataType; + public: + static type& get(lua_State *L, int ia){ + userdataType *ud = static_cast<userdataType*>(lua_touserdata(L, ia)); + if(!ud) luaL_typerror(L, ia, className<type>::get().c_str()); + return *ud->pT; + } + static void push(lua_State *L,type &obj){ +/* userdataType *ud = static_cast<userdataType*>(lua_newuserdata(L, sizeof(userdataType))); + ud->pT=&obj; + luaL_getmetatable(L,className<type>::get().c_str()); // lookup metatable in Lua registry + lua_setmetatable(L, -2);*/ + Msg::Error("cannot push a reference lua\n"); + } +}; + +template <typename type> +class luaStack<const type &>{ + typedef struct { type *pT;} userdataType; + public: + static type& get(lua_State *L, int ia){ + userdataType *ud = static_cast<userdataType*>(lua_touserdata(L, ia)); + if(!ud) luaL_typerror(L, ia, className<type>::get().c_str()); + return *ud->pT; + } + static void push(lua_State *L,const type &obj){ + /*userdataType *ud = static_cast<userdataType*>(lua_newuserdata(L, sizeof(userdataType))); + ud->pT=(type*)&obj; + luaL_getmetatable(L,className<type>::get().c_str()); // lookup metatable in Lua registry + lua_setmetatable(L, -2);*/ + Msg::Error("cannot push a reference lua\n"); + } +}; + /*** template to call c function from the lua stack ***/ //static, return template < typename tRet, typename t0, typename t1, typename t2, typename t3> diff --git a/Solver/TESTCASES/WavePulse.lua b/Solver/TESTCASES/WavePulse.lua deleted file mode 100644 index 93adba1dab9cffcffb162edd55a567b5f08d3d36..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/WavePulse.lua +++ /dev/null @@ -1,64 +0,0 @@ ---[[ - Function for initial conditions ---]] -function initial_condition( xyz , f ) - for i=0,xyz:size1()-1 do - X = xyz:get(i,0) - .5 - Y = xyz:get(i,1) - .5 - Z = xyz:get(i,2) --- X2 = xyz:get(i,0) - 1.5 --- Y2 = xyz:get(i,1) - .5 --- Z2 = xyz:get(i,2) - VALUE = math.exp(-40*(X*X+Y*Y+Z*Z)) --- + math.exp(-40*(X2*X2+Y2*Y2+Z2*Z2)); - f:set(i,0,VALUE) - f:set(i,1,0.0) - f:set(i,2,0.0) - end -end - - -print'*** Loading the mesh and the model ***' -myModel = GModel () ---myModel:load('box.geo') ---myModel:load('box.msh') ---myModel:load('square_quads.msh') -myModel:load('square_mixed.msh') - - -print'*** Create a dg solver ***' -DG = dgSystemOfEquations (myModel) -DG:setOrder(3) -law=dgConservationLawWaveEquation(2) -DG:setConservationLaw(law) -law:addBoundaryCondition('Border',law:newBoundaryWall()) -DG:setup() - -initialCondition = functionLua(3,'initial_condition',{'XYZ'}):getName() - -print'*** setting the initial solution ***' - -DG:L2Projection(initialCondition) - -print'*** export ***' - -DG:exportSolution('output/solution_000') - -print'*** solve ***' - -N = 100; -CFL = 2.1; -dt = CFL * DG:computeInvSpectralRadius(); -print('DT = ',dt) -for i=1,N do --- norm = DG:multirateRK43(dt) - norm = DG:RK44(dt) - if (i % 100 == 0) then - print('*** ITER ***',i,norm) - DG:exportSolution(string.format("output/solution-%04d", i)) - end -end - -print'*** done ***' - -