Chi-Tech
fv_diffusion_utils.cc
Go to the documentation of this file.
2#include "chi_lua.h"
4
6
7//###################################################################
8/**Calls a lua function with xyz coordinates.
9 * \param L The lua state.
10 * \param lua_func_name The name used to define this lua function in the lua
11 * state.
12 * \param imat The material ID of the cell
13 * \param xyz The xyz coordinates of the point where the function is called.
14 *
15 * \return The function evaluation.*/
17 lua_State* L,
18 const std::string& lua_func_name,
19 const int imat,
20 const chi_mesh::Vector3& xyz)
21{
22 //============= Load lua function
23 lua_getglobal(L, lua_func_name.c_str());
24
25 //============= Error check lua function
26 if (not lua_isfunction(L, -1))
27 throw std::logic_error("CallLua_iXYZFunction attempted to access lua-function, " +
28 lua_func_name + ", but it seems the function"
29 " could not be retrieved.");
30
31 //============= Push arguments
32 lua_pushinteger(L, imat);
33 lua_pushnumber(L, xyz.x);
34 lua_pushnumber(L, xyz.y);
35 lua_pushnumber(L, xyz.z);
36
37 //============= Call lua function
38 //4 arguments, 1 result (double), 0=original error object
39 double lua_return;
40 if (lua_pcall(L,4,1,0) == 0)
41 {
42 LuaCheckNumberValue("CallLua_iXYZFunction", L, -1);
43 lua_return = lua_tonumber(L,-1);
44 }
45 else
46 throw std::logic_error("CallLua_iXYZFunction attempted to call lua-function, " +
47 lua_func_name + ", but the call failed." +
48 xyz.PrintStr());
49
50 lua_pop(L,1); //pop the double, or error code
51
52 return lua_return;
53}
54
55
56//###################################################################
57/**Updates the field functions with the latest data.*/
59{
60 auto& ff = *field_functions_.front();
61 ff.UpdateFieldVector(x_);
62}
static double CallLua_iXYZFunction(lua_State *L, const std::string &, int, const chi_mesh::Vector3 &)
std::string PrintStr() const
double x
Element-0.
double y
Element-1.
double z
Element-2.