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

LuaBindings : accept reference as argument

parent 16ffea1d
Branches
Tags
No related merge requests found
......@@ -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>
......
--[[
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 ***'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment