13 #include <pybind11/pybind11.h>
27 unsigned const integration_order,
28 unsigned const shapefunction_order,
29 unsigned const global_dim,
30 bool const flush_stdout)
31 : _bc_data(std::move(bc_data)), _flush_stdout(flush_stdout)
33 std::vector<MeshLib::Node*>
const& bc_nodes =
40 std::move(bc_mesh_subset));
59 auto const& bulk_node_ids_map =
63 bc_values.
ids.clear();
69 std::vector<double> primary_variables;
73 auto const boundary_node_id = node->getID();
74 auto const bulk_node_id = bulk_node_ids_map[boundary_node_id];
77 primary_variables.clear();
79 for (
int var = 0; var < num_var; ++var)
83 for (
int comp = 0; comp < num_comp; ++comp)
95 "No d.o.f. found for (node={:d}, var={:d}, comp={:d}). "
96 " That might be due to the use of mixed FEM ansatz "
97 "functions, which is currently not supported by the "
98 "implementation of Python BCs. That excludes, e.g., "
100 bulk_node_id, var, comp);
103 primary_variables.push_back(x[dof_idx]);
107 auto* xs = nodes[boundary_node_id]->getCoords();
109 t, {xs[0], xs[1], xs[2]}, boundary_node_id, primary_variables);
113 "Method `getDirichletBCValue' not overridden in Python "
118 if (!pair_flag_value.first)
130 "Logic error. This error should already have occurred while "
131 "gathering primary variables. Something nasty is going on!");
143 bc_values.
ids.emplace_back(dof_idx);
144 bc_values.
values.emplace_back(pair_flag_value.second);
150 const double t, std::vector<GlobalVector*>
const& x,
int const process_id,
164 DBUG(
"Method `getFlux' not overridden in Python script.");
171 int const variable_id,
int const component_id,
172 unsigned const integration_order,
unsigned const shapefunction_order,
173 unsigned const global_dim)
184 pybind11::object scope =
185 pybind11::module::import(
"__main__").attr(
"__dict__");
187 if (!scope.contains(bc_object))
190 "Function `{:s}' is not defined in the python script file, or "
191 "there was no python script file specified.",
195 auto* bc = scope[bc_object.c_str()]
202 "Variable id or component id too high. Actual values: ({:d}, "
203 "{:d}), maximum values: ({:d}, {:d}).",
223 return std::make_unique<PythonBoundaryCondition>(
225 bc, dof_table, bulk_mesh_id,
228 integration_order, shapefunction_order, global_dim, flush_stdout);
void DBUG(char const *fmt, Args const &... args)
void checkConfigParameter(std::string const ¶m, T const &value) const
T getConfigParameter(std::string const ¶m) const
Global vector based on Eigen vector.
A subset of nodes on a single mesh.
bool isAxiallySymmetric() const
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Properties & getProperties()
std::size_t getNumberOfNodes() const
Get the number of nodes.
std::size_t getNumberOfElements() const
Get the number of elements.
PropertyVector< T > const * getPropertyVector(std::string const &name) const
int getGlobalComponent(int const variable_id, int const component_id) const
int getNumberOfVariables() const
GlobalIndexType getGlobalIndex(MeshLib::Location const &l, int const variable_id, int const component_id) const
int getNumberOfVariableComponents(int variable_id) const
LocalToGlobalIndexMap * deriveBoundaryConstrainedMap(int const variable_id, std::vector< int > const &component_ids, MeshLib::MeshSubset &&new_mesh_subset) const
static 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
bool isOverriddenEssential() const
virtual std::pair< bool, double > getDirichletBCValue(double, std::array< double, 3 >, std::size_t, std::vector< double > const &) const
std::unique_ptr< NumLib::LocalToGlobalIndexMap > _dof_table_boundary
Local dof table for 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.
std::vector< std::unique_ptr< GenericNaturalBoundaryConditionLocalAssemblerInterface > > _local_assemblers
Local assemblers for all elements of the boundary mesh.
PythonBoundaryConditionData _bc_data
Auxiliary data.
PythonBoundaryCondition(PythonBoundaryConditionData &&bc_data, unsigned const integration_order, unsigned const shapefunction_order, unsigned const global_dim, bool const flush_stdout)
void applyNaturalBC(const double t, std::vector< GlobalVector * > const &x, int const process_id, GlobalMatrix &K, GlobalVector &b, GlobalMatrix *Jac) override
void createLocalAssemblers(const unsigned dimension, std::vector< MeshLib::Element * > const &mesh_elements, NumLib::LocalToGlobalIndexMap const &dof_table, const unsigned shapefunction_order, std::vector< std::unique_ptr< LocalAssemblerInterface >> &local_assemblers, ExtraCtorArgs &&... extra_ctor_args)
std::unique_ptr< PythonBoundaryCondition > createPythonBoundaryCondition(BaseLib::ConfigTree const &config, MeshLib::Mesh const &boundary_mesh, NumLib::LocalToGlobalIndexMap const &dof_table, std::size_t bulk_mesh_id, int const variable_id, int const component_id, unsigned const integration_order, unsigned const shapefunction_order, unsigned const global_dim)
Creates a new PythonBoundaryCondition object.
std::vector< IndexType > ids
std::vector< double > values
static void executeMemberOnDereferenced(Method method, Container const &container, Args &&... args)
NumLib::LocalToGlobalIndexMap const & dof_table_bulk
DOF table of the entire domain.
PythonBoundaryConditionPythonSideInterface * bc_object
Python object computing BC values.
const MeshLib::Mesh & boundary_mesh
The boundary mesh, i.e., the domain of this BC.
int const global_component_id
std::size_t const bulk_mesh_id
Mesh ID of the entire domain.