OGS
ProcessLib::PythonBoundaryCondition Class Referencefinal

Detailed Description

A boundary condition whose values are computed by a Python script.

Definition at line 43 of file PythonBoundaryCondition.h.

#include <PythonBoundaryCondition.h>

Inheritance diagram for ProcessLib::PythonBoundaryCondition:
[legend]
Collaboration diagram for ProcessLib::PythonBoundaryCondition:
[legend]

Public Member Functions

 PythonBoundaryCondition (PythonBoundaryConditionData &&bc_data, unsigned const integration_order, unsigned const shapefunction_order, unsigned const global_dim, bool const flush_stdout)
 
void getEssentialBCValues (const double t, const GlobalVector &x, NumLib::IndexValueVector< GlobalIndexType > &bc_values) const override
 Writes the values of essential BCs to bc_values. More...
 
void applyNaturalBC (const double t, std::vector< GlobalVector * > const &x, int const process_id, GlobalMatrix &K, GlobalVector &b, GlobalMatrix *Jac) override
 
- Public Member Functions inherited from ProcessLib::BoundaryCondition
virtual void preTimestep (const double, std::vector< GlobalVector * > const &, int const)
 
virtual void postTimestep (const double, std::vector< GlobalVector * > const &, int const)
 
virtual ~BoundaryCondition ()=default
 

Private Attributes

PythonBoundaryConditionData _bc_data
 Auxiliary data. More...
 
std::unique_ptr< NumLib::LocalToGlobalIndexMap_dof_table_boundary
 Local dof table for the boundary mesh. More...
 
std::vector< std::unique_ptr< GenericNaturalBoundaryConditionLocalAssemblerInterface > > _local_assemblers
 Local assemblers for all elements of the boundary mesh. More...
 
bool const _flush_stdout
 

Constructor & Destructor Documentation

◆ PythonBoundaryCondition()

ProcessLib::PythonBoundaryCondition::PythonBoundaryCondition ( PythonBoundaryConditionData &&  bc_data,
unsigned const  integration_order,
unsigned const  shapefunction_order,
unsigned const  global_dim,
bool const  flush_stdout 
)

Definition at line 25 of file PythonBoundaryCondition.cpp.

31  : _bc_data(std::move(bc_data)), _flush_stdout(flush_stdout)
32 {
33  std::vector<MeshLib::Node*> const& bc_nodes =
35  MeshLib::MeshSubset bc_mesh_subset(_bc_data.boundary_mesh, bc_nodes);
36 
37  // Create local DOF table from the bc mesh subset for the given variable and
38  // component id.
40  std::move(bc_mesh_subset));
41 
43  PythonBoundaryConditionLocalAssembler>(
45  shapefunction_order, _local_assemblers,
46  _bc_data.boundary_mesh.isAxiallySymmetric(), integration_order,
47  _bc_data);
48 }
A subset of nodes on a single mesh.
Definition: MeshSubset.h:27
bool isAxiallySymmetric() const
Definition: Mesh.h:126
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:95
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:98
LocalToGlobalIndexMap * deriveBoundaryConstrainedMap(int const variable_id, std::vector< int > const &component_ids, MeshLib::MeshSubset &&new_mesh_subset) const
std::unique_ptr< NumLib::LocalToGlobalIndexMap > _dof_table_boundary
Local dof table for the boundary mesh.
std::vector< std::unique_ptr< GenericNaturalBoundaryConditionLocalAssemblerInterface > > _local_assemblers
Local assemblers for all elements of the boundary mesh.
PythonBoundaryConditionData _bc_data
Auxiliary data.
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)
NumLib::LocalToGlobalIndexMap const & dof_table_bulk
DOF table of the entire domain.
const MeshLib::Mesh & boundary_mesh
The boundary mesh, i.e., the domain of this BC.

References _bc_data, _dof_table_boundary, _local_assemblers, ProcessLib::PythonBoundaryConditionData::boundary_mesh, ProcessLib::BoundaryConditionAndSourceTerm::createLocalAssemblers(), NumLib::LocalToGlobalIndexMap::deriveBoundaryConstrainedMap(), ProcessLib::PythonBoundaryConditionData::dof_table_bulk, MeshLib::Mesh::getElements(), MeshLib::Mesh::getNodes(), and MeshLib::Mesh::isAxiallySymmetric().

Member Function Documentation

◆ applyNaturalBC()

void ProcessLib::PythonBoundaryCondition::applyNaturalBC ( const double  ,
std::vector< GlobalVector * > const &  ,
int const  ,
GlobalMatrix ,
GlobalVector ,
GlobalMatrix  
)
overridevirtual

Applies natural BCs (i.e. non-Dirichlet BCs) to the stiffness matrix K and the vector b.

Reimplemented from ProcessLib::BoundaryCondition.

Definition at line 149 of file PythonBoundaryCondition.cpp.

152 {
153  FlushStdoutGuard guard(_flush_stdout);
154 
155  try
156  {
159  _local_assemblers, *_dof_table_boundary, t, x, process_id, K, b,
160  Jac);
161  }
162  catch (MethodNotOverriddenInDerivedClassException const& /*e*/)
163  {
164  DBUG("Method `getFlux' not overridden in Python script.");
165  }
166 }
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27
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
static void executeMemberOnDereferenced(Method method, Container const &container, Args &&... args)

References _dof_table_boundary, _flush_stdout, _local_assemblers, ProcessLib::GenericNaturalBoundaryConditionLocalAssemblerInterface::assemble(), DBUG(), and NumLib::SerialExecutor::executeMemberOnDereferenced().

◆ getEssentialBCValues()

void ProcessLib::PythonBoundaryCondition::getEssentialBCValues ( const double  ,
const GlobalVector ,
NumLib::IndexValueVector< GlobalIndexType > &   
) const
overridevirtual

Writes the values of essential BCs to bc_values.

Reimplemented from ProcessLib::BoundaryCondition.

Definition at line 50 of file PythonBoundaryCondition.cpp.

53 {
54  FlushStdoutGuard guard(_flush_stdout);
55  (void)guard;
56 
57  auto const nodes = _bc_data.boundary_mesh.getNodes();
58 
59  auto const& bulk_node_ids_map =
61  "bulk_node_ids", MeshLib::MeshItemType::Node, 1);
62 
63  bc_values.ids.clear();
64  bc_values.values.clear();
65 
66  bc_values.ids.reserve(_bc_data.boundary_mesh.getNumberOfNodes());
67  bc_values.values.reserve(_bc_data.boundary_mesh.getNumberOfNodes());
68 
69  std::vector<double> primary_variables;
70 
71  for (auto const* node : _bc_data.boundary_mesh.getNodes())
72  {
73  auto const boundary_node_id = node->getID();
74  auto const bulk_node_id = bulk_node_ids_map[boundary_node_id];
75 
76  // gather primary variable values
77  primary_variables.clear();
78  auto const num_var = _dof_table_boundary->getNumberOfVariables();
79  for (int var = 0; var < num_var; ++var)
80  {
81  auto const num_comp =
82  _dof_table_boundary->getNumberOfVariableComponents(var);
83  for (int comp = 0; comp < num_comp; ++comp)
84  {
87  bulk_node_id};
88  auto const dof_idx =
89  _bc_data.dof_table_bulk.getGlobalIndex(loc, var, comp);
90 
91  if (dof_idx == NumLib::MeshComponentMap::nop)
92  {
93  // TODO extend Python BC to mixed FEM ansatz functions
94  OGS_FATAL(
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., "
99  "the HM process.",
100  bulk_node_id, var, comp);
101  }
102 
103  primary_variables.push_back(x[dof_idx]);
104  }
105  }
106 
107  auto* xs = nodes[boundary_node_id]->getCoords(); // TODO DDC problems?
108  auto pair_flag_value = _bc_data.bc_object->getDirichletBCValue(
109  t, {xs[0], xs[1], xs[2]}, boundary_node_id, primary_variables);
111  {
112  DBUG(
113  "Method `getDirichletBCValue' not overridden in Python "
114  "script.");
115  return;
116  }
117 
118  if (!pair_flag_value.first)
119  {
120  continue;
121  }
122 
124  bulk_node_id);
125  const auto dof_idx = _bc_data.dof_table_bulk.getGlobalIndex(
127  if (dof_idx == NumLib::MeshComponentMap::nop)
128  {
129  OGS_FATAL(
130  "Logic error. This error should already have occurred while "
131  "gathering primary variables. Something nasty is going on!");
132  }
133 
134  // For the DDC approach (e.g. with PETSc option), the negative
135  // index of g_idx means that the entry by that index is a ghost
136  // one, which should be dropped. Especially for PETSc routines
137  // MatZeroRows and MatZeroRowsColumns, which are called to apply
138  // the Dirichlet BC, the negative index is not accepted like
139  // other matrix or vector PETSc routines. Therefore, the
140  // following if-condition is applied.
141  if (dof_idx >= 0)
142  {
143  bc_values.ids.emplace_back(dof_idx);
144  bc_values.values.emplace_back(pair_flag_value.second);
145  }
146  }
147 }
#define OGS_FATAL(...)
Definition: Error.h:26
Properties & getProperties()
Definition: Mesh.h:123
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:89
PropertyVector< T > const * getPropertyVector(std::string const &name) const
GlobalIndexType getGlobalIndex(MeshLib::Location const &l, int const variable_id, int const component_id) const
static NUMLIB_EXPORT GlobalIndexType const nop
virtual std::pair< bool, double > getDirichletBCValue(double, std::array< double, 3 >, std::size_t, std::vector< double > const &) const
PythonBoundaryConditionPythonSideInterface * bc_object
Python object computing BC values.
std::size_t const bulk_mesh_id
Mesh ID of the entire domain.

References _bc_data, _dof_table_boundary, _flush_stdout, ProcessLib::PythonBoundaryConditionData::bc_object, ProcessLib::PythonBoundaryConditionData::boundary_mesh, ProcessLib::PythonBoundaryConditionData::bulk_mesh_id, DBUG(), ProcessLib::PythonBoundaryConditionData::dof_table_bulk, ProcessLib::PythonBoundaryConditionPythonSideInterface::getDirichletBCValue(), NumLib::LocalToGlobalIndexMap::getGlobalIndex(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getNumberOfNodes(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), ProcessLib::PythonBoundaryConditionData::global_component_id, NumLib::IndexValueVector< IndexType >::ids, ProcessLib::PythonBoundaryConditionPythonSideInterface::isOverriddenEssential(), MeshLib::Node, NumLib::MeshComponentMap::nop, OGS_FATAL, and NumLib::IndexValueVector< IndexType >::values.

Member Data Documentation

◆ _bc_data

PythonBoundaryConditionData ProcessLib::PythonBoundaryCondition::_bc_data
private

Auxiliary data.

Definition at line 62 of file PythonBoundaryCondition.h.

Referenced by PythonBoundaryCondition(), and getEssentialBCValues().

◆ _dof_table_boundary

std::unique_ptr<NumLib::LocalToGlobalIndexMap> ProcessLib::PythonBoundaryCondition::_dof_table_boundary
private

Local dof table for the boundary mesh.

Definition at line 65 of file PythonBoundaryCondition.h.

Referenced by PythonBoundaryCondition(), applyNaturalBC(), and getEssentialBCValues().

◆ _flush_stdout

bool const ProcessLib::PythonBoundaryCondition::_flush_stdout
private

Whether or not to flush standard output before and after each call to Python code. Ensures right order of output messages and therefore simplifies debugging.

Definition at line 75 of file PythonBoundaryCondition.h.

Referenced by applyNaturalBC(), and getEssentialBCValues().

◆ _local_assemblers

std::vector< std::unique_ptr<GenericNaturalBoundaryConditionLocalAssemblerInterface> > ProcessLib::PythonBoundaryCondition::_local_assemblers
private

Local assemblers for all elements of the boundary mesh.

Definition at line 70 of file PythonBoundaryCondition.h.

Referenced by PythonBoundaryCondition(), and applyNaturalBC().


The documentation for this class was generated from the following files: