14 unsigned int face_index,
15 unsigned int face_node_index,
18 const std::vector<int>& quadrature_angle_indices,
19 const std::vector<chi_mesh::Vector3>& quadrature_angle_vectors,
20 const std::vector<std::pair<double, double>>& quadrature_phi_theta_angles,
21 const std::vector<int>& group_indices,
24 const std::string fname =
"LinearBoltzmann::BoundaryFunctionToLua";
30 lua_pushstring(L,
"x");
31 lua_pushnumber(L, vec.x);
34 lua_pushstring(L,
"y");
35 lua_pushnumber(L, vec.y);
38 lua_pushstring(L,
"z");
39 lua_pushnumber(L, vec.z);
43 auto PushVecIntAsTable = [](lua_State* L,
const std::vector<int>& vec)
47 for (
int i=0; i<static_cast<int>(vec.size()); ++i)
49 lua_pushinteger(L, i+1);
50 lua_pushinteger(L,
static_cast<lua_Integer
>(vec[i]));
55 auto PushPhiThetaPairTable = [](lua_State* L,
const std::pair<double, double>& phi_theta)
59 lua_pushstring(L,
"phi");
60 lua_pushnumber(L, phi_theta.first);
63 lua_pushstring(L,
"theta");
64 lua_pushnumber(L, phi_theta.second);
73 if (not lua_isfunction(L, -1))
74 throw std::logic_error(fname +
" attempted to access lua-function, " +
76 " could not be retrieved.");
79 lua_pushinteger(L,
static_cast<lua_Integer
>(cell_global_id));
80 lua_pushinteger(L,
static_cast<lua_Integer
>(cell_material_id));
82 PushVector3AsTable(L, face_node_location);
83 PushVector3AsTable(L, face_node_normal);
85 PushVecIntAsTable(L, quadrature_angle_indices);
90 for (
auto& omega : quadrature_angle_vectors)
92 lua_pushinteger(L, n+1);
93 PushVector3AsTable(L, omega);
102 for (
auto& phi_theta : quadrature_phi_theta_angles)
104 lua_pushinteger(L, n+1);
105 PushPhiThetaPairTable(L, phi_theta);
111 PushVecIntAsTable(L, group_indices);
113 lua_pushnumber(L, time);
115 std::vector<double> psi;
117 if (lua_pcall(L,9,1,0) == 0)
119 LuaCheckTableValue(fname, L, -1);
120 size_t table_length = lua_rawlen(L, -1);
121 psi.reserve(table_length);
122 for (
size_t i=0; i<table_length; ++i)
124 lua_pushinteger(L,
static_cast<lua_Integer
>(i)+1);
126 psi.push_back(lua_tonumber(L,-1));
131 throw std::logic_error(fname +
" attempted to call lua-function, " +
137 size_t num_angles = quadrature_angle_indices.size();
138 size_t num_groups = group_indices.size();
140 if (psi.size() != (num_angles*num_groups))
141 throw std::logic_error(fname +
" the returned vector from lua-function, " +
143 "The size must equal num_angles*num_groups, " +
144 std::to_string(num_angles*num_groups) +
", but the size is " +
145 std::to_string(psi.size()) +
".");
static chi::Console & console
lua_State *& GetConsoleState()
const std::string m_lua_function_name
std::vector< double > Evaluate(size_t cell_global_id, int cell_material_id, unsigned int face_index, unsigned int face_node_index, const chi_mesh::Vector3 &face_node_location, const chi_mesh::Vector3 &face_node_normal, const std::vector< int > &quadrature_angle_indices, const std::vector< chi_mesh::Vector3 > &quadrature_angle_vectors, const std::vector< std::pair< double, double > > &quadrature_phi_theta_angles, const std::vector< int > &group_indices, double time) override