OGS 6.1.0-1721-g6382411ad
NonuniformDirichletBoundaryCondition.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include "BoundaryCondition.h"
15 
16 #include "MeshLib/PropertyVector.h"
22 
23 namespace ProcessLib
24 {
26 {
27 public:
29  // int const bulk_mesh_dimension,
30  MeshLib::Mesh const& boundary_mesh,
31  MeshLib::PropertyVector<double> const& values,
32  NumLib::LocalToGlobalIndexMap const& dof_table_bulk,
33  int const variable_id,
34  int const component_id)
35  : _values(values),
36  _boundary_mesh(boundary_mesh),
37  _variable_id(variable_id),
38  _component_id(component_id)
39  {
40  if (_variable_id >=
41  static_cast<int>(dof_table_bulk.getNumberOfVariables()) ||
42  _component_id >=
44  {
45  OGS_FATAL(
46  "Variable id or component id too high. Actual values: (%d, "
47  "%d), "
48  "maximum values: (%d, %d).",
50  dof_table_bulk.getNumberOfVariables(),
52  }
53 
55  "bulk_node_ids"))
56  {
57  OGS_FATAL(
58  "The required bulk node ids map does not exist in the boundary "
59  "mesh '%s'.",
60  _boundary_mesh.getName().c_str());
61  }
62 
63  std::vector<MeshLib::Node*> const& bc_nodes = _boundary_mesh.getNodes();
64  DBUG(
65  "Found %d nodes for Natural BCs for the variable %d and component "
66  "%d",
67  bc_nodes.size(), variable_id, component_id);
68 
69  MeshLib::MeshSubset boundary_mesh_subset(_boundary_mesh, bc_nodes);
70 
71  // Create local DOF table from the BC mesh subset for the given variable
72  // and component id.
74  variable_id, {component_id}, std::move(boundary_mesh_subset)));
75  }
76 
78  const double /*t*/, GlobalVector const& /*x*/,
79  NumLib::IndexValueVector<GlobalIndexType>& bc_values) const override
80  {
81  bc_values.ids.clear();
82  bc_values.values.clear();
83 
84  // Convert mesh node ids to global index for the given component.
85  bc_values.ids.reserve(_values.size());
86  bc_values.values.reserve(_values.size());
87 
88  // Map boundary dof indices to bulk dof indices and the corresponding
89  // values.
90  for (auto const* const node : _boundary_mesh.getNodes())
91  {
92  auto const node_id = node->getID();
93  auto const global_index = _dof_table_boundary->getGlobalIndex(
96  if (global_index == NumLib::MeshComponentMap::nop)
97  continue;
98  // For the DDC approach (e.g. with PETSc option), the negative index
99  // of global_index means that the entry by that index is a ghost
100  // one, which should be dropped. Especially for PETSc routines
101  // MatZeroRows and MatZeroRowsColumns, which are called to apply the
102  // Dirichlet BC, the negative index is not accepted like other
103  // matrix or vector PETSc routines. Therefore, the following
104  // if-condition is applied.
105  if (global_index >= 0)
106  {
107  bc_values.ids.emplace_back(global_index);
108  bc_values.values.push_back(_values[node_id]);
109  }
110  }
111  }
112 
113 private:
116  std::unique_ptr<NumLib::LocalToGlobalIndexMap const> _dof_table_boundary;
117  int const _variable_id;
118  int const _component_id;
119 };
120 
121 std::unique_ptr<NonuniformDirichletBoundaryCondition>
123  BaseLib::ConfigTree const& config, MeshLib::Mesh const& boundary_mesh,
124  NumLib::LocalToGlobalIndexMap const& dof_table, int const variable_id,
125  int const component_id);
126 
127 } // ProcessLib
void getEssentialBCValues(const double, GlobalVector const &, NumLib::IndexValueVector< GlobalIndexType > &bc_values) const override
Writes the values of essential BCs to bc_values.
std::size_t getID() const
Get id of the mesh.
Definition: Mesh.h:123
int getNumberOfVariableComponents(int variable_id) const
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:105
MeshLib::Properties & getProperties()
Definition: Mesh.h:134
std::unique_ptr< NumLib::LocalToGlobalIndexMap const > _dof_table_boundary
std::unique_ptr< NonuniformDirichletBoundaryCondition > createNonuniformDirichletBoundaryCondition(BaseLib::ConfigTree const &config, MeshLib::Mesh const &boundary_mesh, NumLib::LocalToGlobalIndexMap const &dof_table, int const variable_id, int const component_id)
const std::string getName() const
Get name of the mesh.
Definition: Mesh.h:102
NonuniformDirichletBoundaryCondition(MeshLib::Mesh const &boundary_mesh, MeshLib::PropertyVector< double > const &values, NumLib::LocalToGlobalIndexMap const &dof_table_bulk, int const variable_id, int const component_id)
std::vector< IndexType > ids
bool existsPropertyVector(std::string const &name) const
Definition: Properties.h:79
LocalToGlobalIndexMap * deriveBoundaryConstrainedMap(int const variable_id, std::vector< int > const &component_ids, MeshLib::MeshSubset &&new_mesh_subset) const
#define OGS_FATAL(fmt,...)
Definition: Error.h:71
A subset of nodes on a single mesh.
Definition: MeshSubset.h:26
std::size_t size() const
Method returns the number of tuples times the number of tuple components.
std::vector< double > values
static NUMLIB_EXPORT GlobalIndexType const nop