OGS
PythonBoundaryCondition.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <string>
7
13#include "Utils/BcOrStData.h"
14
15namespace ProcessLib
16{
17class ProcessVariable;
18
24
30
31struct PythonBcData final
33 PythonBoundaryConditionPythonSideInterface>
34{
40 getFlagAndFluxAndDFlux(double const t, std::array<double, 3> const coords,
41 std::vector<double> const& prim_vars_data) const
42 {
43 auto [flag, flux, dFlux] =
44 bc_or_st_object->getFlux(t, coords, prim_vars_data);
45
46 if (!bc_or_st_object->isOverriddenNatural())
47 {
48 // getFlux() is not overridden in Python, so we can skip the
49 // whole BC assembly (i.e., for all boundary elements).
51 }
52
53 return {flag, flux, std::move(dFlux)};
54 }
55};
56
59{
60public:
62 PythonBcData&& bc_data,
63 unsigned const integration_order,
64 bool const flush_stdout,
65 unsigned const bulk_mesh_dimension,
66 NumLib::LocalToGlobalIndexMap const& dof_table_bulk);
67
69 const double t, const GlobalVector& x,
70 NumLib::IndexValueVector<GlobalIndexType>& bc_values) const override;
71
72 void applyNaturalBC(const double t, std::vector<GlobalVector*> const& x,
73 int const process_id, GlobalMatrix* K, GlobalVector& b,
74 GlobalMatrix* Jac) override;
75
76private:
85 void collectPrimaryVariables(std::vector<double>& primary_variables,
86 MeshLib::Node const& boundary_node,
87 GlobalVector const& x) const;
88
91 GlobalIndexType getDofIdx(std::size_t const boundary_node_id) const;
92
95 GlobalIndexType getDofIdx(std::size_t const boundary_node_id, int const var,
96 int const comp) const;
97
101 GlobalVector const& x, int const var, int const comp,
102 MeshLib::Node const& boundary_node) const;
103
106
108 std::unique_ptr<NumLib::LocalToGlobalIndexMap> _dof_table_boundary;
109
111 std::vector<std::unique_ptr<PythonBoundaryConditionLocalAssemblerInterface>>
113
117 bool const _flush_stdout;
118};
119
121 BaseLib::ConfigTree const& config);
122
124std::unique_ptr<PythonBoundaryCondition> createPythonBoundaryCondition(
125 PythonBoundaryConditionConfig const& config,
126 MeshLib::Mesh const& boundary_mesh,
127 NumLib::LocalToGlobalIndexMap const& dof_table_bulk,
128 MeshLib::Mesh const& bulk_mesh, int const variable_id,
129 int const component_id, unsigned const integration_order,
130 unsigned const shapefunction_order,
131 std::vector<std::reference_wrapper<ProcessVariable>> const&
132 all_process_variables_for_this_process);
133
134} // namespace ProcessLib
MathLib::EigenMatrix GlobalMatrix
MathLib::EigenVector GlobalVector
GlobalMatrix::IndexType GlobalIndexType
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.
void applyNaturalBC(const double t, std::vector< GlobalVector * > const &x, int const process_id, GlobalMatrix *K, GlobalVector &b, GlobalMatrix *Jac) override
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)
std::unique_ptr< PythonBoundaryCondition > createPythonBoundaryCondition(PythonBoundaryConditionConfig 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.
PythonBoundaryConditionConfig parsePythonBoundaryCondition(BaseLib::ConfigTree const &config)
ProcessLib::BoundaryConditionAndSourceTerm::Python::FlagAndFluxAndDFlux getFlagAndFluxAndDFlux(double const t, std::array< double, 3 > const coords, std::vector< double > const &prim_vars_data) const