OGS
DirichletBoundaryConditionAuxiliaryFunctions.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
6#include <range/v3/range/conversion.hpp>
7
8#include "MeshLib/Mesh.h"
9#include "MeshLib/Node.h"
13
14namespace ProcessLib
15{
17 MeshLib::Mesh const& bc_mesh,
18 NumLib::LocalToGlobalIndexMap const& dof_table_bulk,
19 int const variable_id,
20 int const component_id)
21{
22 if (variable_id >=
23 static_cast<int>(dof_table_bulk.getNumberOfVariables()) ||
24 component_id >=
25 dof_table_bulk.getNumberOfVariableComponents(variable_id))
26 {
28 "Variable id or component id too high. Actual values: ({:d}, "
29 "{:d}), maximum values: ({:d}, {:d}).",
30 variable_id, component_id, dof_table_bulk.getNumberOfVariables(),
31 dof_table_bulk.getNumberOfVariableComponents(variable_id));
32 }
33
34 if (!bc_mesh.getProperties().hasPropertyVector(
36 {
38 "The required bulk node ids map does not exist in the boundary "
39 "mesh '{:s}'.",
40 bc_mesh.getName());
41 }
42
43 if (!bc_mesh.getProperties().existsPropertyVector<std::size_t>(
45 {
47 "The required bulk node ids map exists in the boundary mesh '{:s}' "
48 "but has wrong data type (should be equivalent to C++ data type "
49 "std::size_t which is an unsigned integer of size {:d} or UInt64 "
50 "in vtk terminology).",
51 bc_mesh.getName(), sizeof(std::size_t));
52 }
53
54 DBUG(
55 "Found {:d} nodes for Dirichlet BCs for the variable {:d} and "
56 "component {:d}",
57 bc_mesh.getNumberOfNodes(), variable_id, component_id);
58}
59
61 ParameterLib::Parameter<double> const& parameter,
62 MeshLib::Mesh const& bc_mesh,
63 std::vector<std::size_t> const& nodes_in_bc_mesh,
64 NumLib::LocalToGlobalIndexMap const& dof_table_boundary,
65 int const variable_id, int const component_id, const double t,
66 GlobalVector const& /*x*/,
68{
70
71 bc_values.ids.clear();
72 bc_values.values.clear();
73
74 // convert mesh node ids to global index for the given component
75 bc_values.ids.reserve(nodes_in_bc_mesh.size());
76 bc_values.values.reserve(nodes_in_bc_mesh.size());
77 for (auto const node_id : nodes_in_bc_mesh)
78 {
79 // TODO: that might be slow, but only done once
80 auto const global_index = dof_table_boundary.getGlobalIndex(
81 {bc_mesh.getID(), MeshLib::MeshItemType::Node, node_id},
82 variable_id, component_id);
83 if (global_index == NumLib::MeshComponentMap::nop)
84 {
85 continue;
86 }
87 // For the DDC approach (e.g. with PETSc option), the negative
88 // index of global_index means that the entry by that index is a ghost
89 // one, which should be dropped. Especially for PETSc routines
90 // MatZeroRows and MatZeroRowsColumns, which are called to apply the
91 // Dirichlet BC, the negative index is not accepted like other matrix or
92 // vector PETSc routines. Therefore, the following if-condition is
93 // applied.
94 if (global_index >= 0)
95 {
96 pos.setNodeID(node_id);
97 pos.setCoordinates(*bc_mesh.getNode(node_id));
98 bc_values.ids.emplace_back(global_index);
99 bc_values.values.emplace_back(parameter(t, pos).front());
100 }
101 }
102}
103
105 ParameterLib::Parameter<double> const& parameter,
106 MeshLib::Mesh const& bc_mesh,
107 NumLib::LocalToGlobalIndexMap const& dof_table_boundary,
108 int const variable_id, int const component_id, const double t,
110{
112 parameter, bc_mesh,
113 bc_mesh.getNodes() | MeshLib::views::ids | ranges::to<std::vector>,
114 dof_table_boundary, variable_id, component_id, t, x, bc_values);
115}
116} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:19
MathLib::EigenVector GlobalVector
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:97
std::size_t getID() const
Get id of the mesh.
Definition Mesh.h:112
const Node * getNode(std::size_t idx) const
Get the node with the given index.
Definition Mesh.h:82
Properties & getProperties()
Definition Mesh.h:125
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:94
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition Mesh.h:91
bool hasPropertyVector(std::string_view name) const
bool existsPropertyVector(std::string_view name) const
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:216
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
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