OGS
DirichletBoundaryConditionAuxiliaryFunctions.cpp
Go to the documentation of this file.
1
14
15#include <range/v3/range/conversion.hpp>
16
17#include "MeshLib/Mesh.h"
18#include "MeshLib/Node.h"
22
23namespace ProcessLib
24{
26 MeshLib::Mesh const& bc_mesh,
27 NumLib::LocalToGlobalIndexMap const& dof_table_bulk,
28 int const variable_id,
29 int const component_id)
30{
31 if (variable_id >=
32 static_cast<int>(dof_table_bulk.getNumberOfVariables()) ||
33 component_id >=
34 dof_table_bulk.getNumberOfVariableComponents(variable_id))
35 {
37 "Variable id or component id too high. Actual values: ({:d}, "
38 "{:d}), maximum values: ({:d}, {:d}).",
39 variable_id, component_id, dof_table_bulk.getNumberOfVariables(),
40 dof_table_bulk.getNumberOfVariableComponents(variable_id));
41 }
42
43 if (!bc_mesh.getProperties().hasPropertyVector(
45 {
47 "The required bulk node ids map does not exist in the boundary "
48 "mesh '{:s}'.",
49 bc_mesh.getName());
50 }
51
52 if (!bc_mesh.getProperties().existsPropertyVector<std::size_t>(
54 {
56 "The required bulk node ids map exists in the boundary mesh '{:s}' "
57 "but has wrong data type (should be equivalent to C++ data type "
58 "std::size_t which is an unsigned integer of size {:d} or UInt64 "
59 "in vtk terminology).",
60 bc_mesh.getName(), sizeof(std::size_t));
61 }
62
63 DBUG(
64 "Found {:d} nodes for Dirichlet BCs for the variable {:d} and "
65 "component {:d}",
66 bc_mesh.getNodes().size(), variable_id, component_id);
67}
68
70 ParameterLib::Parameter<double> const& parameter,
71 MeshLib::Mesh const& bc_mesh,
72 std::vector<std::size_t> const& nodes_in_bc_mesh,
73 NumLib::LocalToGlobalIndexMap const& dof_table_boundary,
74 int const variable_id, int const component_id, const double t,
75 GlobalVector const& /*x*/,
77{
79
80 bc_values.ids.clear();
81 bc_values.values.clear();
82
83 // convert mesh node ids to global index for the given component
84 bc_values.ids.reserve(nodes_in_bc_mesh.size());
85 bc_values.values.reserve(nodes_in_bc_mesh.size());
86 for (auto const node_id : nodes_in_bc_mesh)
87 {
88 // TODO: that might be slow, but only done once
89 auto const global_index = dof_table_boundary.getGlobalIndex(
90 {bc_mesh.getID(), MeshLib::MeshItemType::Node, node_id},
91 variable_id, component_id);
92 if (global_index == NumLib::MeshComponentMap::nop)
93 {
94 continue;
95 }
96 // For the DDC approach (e.g. with PETSc option), the negative
97 // index of global_index means that the entry by that index is a ghost
98 // one, which should be dropped. Especially for PETSc routines
99 // MatZeroRows and MatZeroRowsColumns, which are called to apply the
100 // Dirichlet BC, the negative index is not accepted like other matrix or
101 // vector PETSc routines. Therefore, the following if-condition is
102 // applied.
103 if (global_index >= 0)
104 {
105 pos.setNodeID(node_id);
106 pos.setCoordinates(*bc_mesh.getNode(node_id));
107 bc_values.ids.emplace_back(global_index);
108 bc_values.values.emplace_back(parameter(t, pos).front());
109 }
110 }
111}
112
114 ParameterLib::Parameter<double> const& parameter,
115 MeshLib::Mesh const& bc_mesh,
116 NumLib::LocalToGlobalIndexMap const& dof_table_boundary,
117 int const variable_id, int const component_id, const double t,
119{
121 parameter, bc_mesh,
122 bc_mesh.getNodes() | MeshLib::views::ids | ranges::to<std::vector>,
123 dof_table_boundary, variable_id, component_id, t, x, bc_values);
124}
125} // namespace ProcessLib
Defines functions that are shared by DirichletBoundaryCondition and DirichletBoundaryConditionWithinT...
#define OGS_FATAL(...)
Definition Error.h:26
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
Definition of the Mesh class.
Definition of the Node class.
Global vector based on Eigen vector.
Definition EigenVector.h:25
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:106
std::size_t getID() const
Get id of the mesh.
Definition Mesh.h:121
const Node * getNode(std::size_t idx) const
Get the node with the given index.
Definition Mesh.h:91
Properties & getProperties()
Definition Mesh.h:134
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:103
bool hasPropertyVector(std::string_view name) const
bool existsPropertyVector(std::string_view name) const
Definition Properties.h:74
GlobalIndexType getGlobalIndex(MeshLib::Location const &l, int const variable_id, int const component_id) const
int getNumberOfVariableComponents(int variable_id) const
static constexpr NUMLIB_EXPORT GlobalIndexType const nop
void setNodeID(std::size_t node_id)
void setCoordinates(MathLib::Point3d const &coordinates)
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:225
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
Definition Properties.h:188
void getEssentialBCValuesLocal(ParameterLib::Parameter< double > const &parameter, MeshLib::Mesh const &bc_mesh, std::vector< std::size_t > const &nodes_in_bc_mesh, NumLib::LocalToGlobalIndexMap const &dof_table_boundary, int const variable_id, int const component_id, const double t, GlobalVector const &, NumLib::IndexValueVector< GlobalIndexType > &bc_values)
void checkParametersOfDirichletBoundaryCondition(MeshLib::Mesh const &bc_mesh, NumLib::LocalToGlobalIndexMap const &dof_table_bulk, int const variable_id, int const component_id)
std::vector< IndexType > ids
std::vector< double > values