13#include <pybind11/pybind11.h>
27 std::size_t
const nnodes)
29 bc_values.
ids.clear();
32 bc_values.
ids.reserve(nnodes);
33 bc_values.
values.reserve(nnodes);
38 std::vector<std::reference_wrapper<ProcessLib::ProcessVariable>>
const& pvs)
41 auto const num_vars_pv = pvs.size();
43 if (
static_cast<std::size_t
>(num_vars_dt) != num_vars_pv)
46 "The number of variables in the d.o.f. table does not match the "
47 "number of process variables: {} != {}.",
48 num_vars_dt, num_vars_pv);
51 for (std::size_t var = 0; var < num_vars_pv; ++var)
54 auto const num_comp_pv = pvs[var].get().getNumberOfGlobalComponents();
56 if (num_comp_dt != num_comp_pv)
59 "The number of components of variable #{} in the d.o.f. table "
60 "does not match the number of components of process variable "
61 "#{} ({}): {} != {}.",
62 var, var, pvs[var].get().
getName(), num_vars_dt, num_vars_pv);
71 PythonBcData&& bc_data,
unsigned const integration_order,
72 bool const flush_stdout,
unsigned const bulk_mesh_dimension,
74 : _bc_data(std::move(bc_data)), _flush_stdout(flush_stdout)
76 checkConsistency(dof_table_bulk,
79 std::vector<MeshLib::Node*>
const& bc_nodes =
102 auto const& boundary_nodes = boundary_mesh.
getNodes();
105 initBCValues(bc_values, boundary_nodes.size());
107 std::vector<double> primary_variables;
109 for (
auto const* boundary_node : boundary_nodes)
111 auto const boundary_node_id = boundary_node->getID();
112 auto const dof_idx =
getDofIdx(boundary_node_id);
132 auto const [apply_bc, bc_value] = bc_object->getDirichletBCValue(
133 t, {(*boundary_node)[0], (*boundary_node)[1], (*boundary_node)[2]},
134 boundary_node_id, primary_variables);
136 if (!bc_object->isOverriddenEssential())
139 "Method `getDirichletBCValue' not overridden in Python "
149 bc_values.
ids.emplace_back(dof_idx);
150 bc_values.
values.emplace_back(bc_value);
155 std::size_t
const boundary_node_id)
const
164 std::size_t
const boundary_node_id,
int const var,
int const comp)
const
172 std::vector<double>& primary_variables,
MeshLib::Node const& boundary_node,
175 primary_variables.clear();
177 auto const boundary_node_id = boundary_node.
getID();
179 for (
int var = 0; var < num_var; ++var)
181 auto const num_comp =
183 for (
int comp = 0; comp < num_comp; ++comp)
185 auto const dof_idx =
getDofIdx(boundary_node_id, var, comp);
187 double const pv_value =
192 primary_variables.push_back(pv_value);
201 auto const& boundary_elements =
203 boundary_node.
getID());
205 if (boundary_elements.size() != 1)
208 "Boundary node {} is associated with {} elements in the boundary "
210 boundary_node.
getID(),
211 boundary_elements.size());
216 auto const& boundary_element = *boundary_elements.front();
218 assert(boundary_element.getNumberOfBaseNodes() <
219 boundary_element.getNumberOfNodes() &&
220 "We expect that the boundary element is a higher order element. "
221 "Otherwise no interpolation should take place.");
224 auto const local_node_id_within_boundary_element =
225 getNodeIDinElement(boundary_element, &boundary_node);
227 auto const boundary_element_id = boundary_element.getID();
233 return loc_asm.interpolate(local_node_id_within_boundary_element,
238 const double t, std::vector<GlobalVector*>
const& x,
int const process_id,
252 DBUG(
"Method `getFlux' not overridden in Python script.");
260 int const component_id,
unsigned const integration_order,
261 unsigned const shapefunction_order,
262 std::vector<std::reference_wrapper<ProcessVariable>>
const&
263 all_process_variables_for_this_process)
274 pybind11::object scope =
275 pybind11::module::import(
"__main__").attr(
"__dict__");
277 if (!scope.contains(bc_object))
280 "Function `{:s}' is not defined in the python script file, or "
281 "there was no python script file specified.",
285 auto* bc = scope[bc_object.c_str()]
294 "Variable id or component id too high. Actual values: ({:d}, "
295 "{:d}), maximum values: ({:d}, {:d}).",
315 return std::make_unique<PythonBoundaryCondition>(
318 boundary_mesh, all_process_variables_for_this_process,
319 shapefunction_order}},
320 integration_order, flush_stdout, bulk_mesh.
getDimension(),
GlobalMatrix::IndexType GlobalIndexType
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
void checkConfigParameter(std::string const ¶m, T const &value) const
T getConfigParameter(std::string const ¶m) const
Global vector based on Eigen vector.
std::size_t getID() const
A subset of nodes on a single mesh.
bool isAxiallySymmetric() const
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
std::size_t getID() const
Get id of the mesh.
std::size_t getNumberOfNodes() const
Get the number of nodes.
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
std::size_t getNumberOfElements() const
Get the number of elements.
int getGlobalComponent(int const variable_id, int const component_id) const
int getNumberOfVariables() const
int getNumberOfVariableComponents(int variable_id) const
std::unique_ptr< LocalToGlobalIndexMap > deriveBoundaryConstrainedMap(int const variable_id, std::vector< int > const &component_ids, MeshLib::MeshSubset &&new_mesh_subset) const
static constexpr NUMLIB_EXPORT GlobalIndexType const nop
virtual void assemble(std::size_t const id, NumLib::LocalToGlobalIndexMap const &dof_table_boundary, double const t, std::vector< GlobalVector * > const &x, int const process_id, GlobalMatrix &K, GlobalVector &b, GlobalMatrix *Jac)=0
std::unique_ptr< NumLib::LocalToGlobalIndexMap > _dof_table_boundary
Local dof table for the boundary mesh.
double interpolateToHigherOrderNode(GlobalVector const &x, int const var, int const comp, MeshLib::Node const &boundary_node) const
PythonBcData _bc_data
Auxiliary data used by the local assemblers.
std::vector< std::unique_ptr< PythonBoundaryConditionLocalAssemblerInterface > > _local_assemblers
Local assemblers for all elements of the boundary mesh.
void getEssentialBCValues(const double t, const GlobalVector &x, NumLib::IndexValueVector< GlobalIndexType > &bc_values) const override
Writes the values of essential BCs to bc_values.
GlobalIndexType getDofIdx(std::size_t const boundary_node_id) const
void collectPrimaryVariables(std::vector< double > &primary_variables, MeshLib::Node const &boundary_node, GlobalVector const &x) const
PythonBoundaryCondition(PythonBcData &&bc_data, unsigned const integration_order, bool const flush_stdout, unsigned const bulk_mesh_dimension, NumLib::LocalToGlobalIndexMap const &dof_table_bulk)
void applyNaturalBC(const double t, std::vector< GlobalVector * > const &x, int const process_id, GlobalMatrix &K, GlobalVector &b, GlobalMatrix *Jac) override
void createLocalAssemblersPython(const unsigned dimension, std::vector< MeshLib::Element * > const &mesh_elements, NumLib::LocalToGlobalIndexMap const &dof_table, std::vector< std::unique_ptr< LocalAssemblerInterface > > &local_assemblers, NumLib::IntegrationOrder const integration_order, ExtraCtorArgs &&... extra_ctor_args)
std::unique_ptr< PythonBoundaryCondition > createPythonBoundaryCondition(BaseLib::ConfigTree const &config, MeshLib::Mesh const &boundary_mesh, NumLib::LocalToGlobalIndexMap const &dof_table_bulk, MeshLib::Mesh const &bulk_mesh, int const variable_id, int const component_id, unsigned const integration_order, unsigned const shapefunction_order, std::vector< std::reference_wrapper< ProcessVariable > > const &all_process_variables_for_this_process)
Creates a new PythonBoundaryCondition object.
void checkConsistency(NumLib::LocalToGlobalIndexMap const &dof_table, std::vector< std::reference_wrapper< ProcessLib::ProcessVariable > > const &pvs)
void initBCValues(NumLib::IndexValueVector< GlobalIndexType > &bc_values, std::size_t const nnodes)
std::vector< IndexType > ids
std::vector< double > values
static void executeMemberOnDereferenced(Method method, Container const &container, Args &&... args)
MeshLib::Mesh const & bc_or_st_mesh
The domain, where this BC or ST will be applied.
std::vector< std::reference_wrapper< ProcessVariable > > const & all_process_variables_for_this_process
int const global_component_id
BcOrStPythonSideInterface const *const bc_or_st_object
Python object computing BC or ST values.