OGS
TimeDecayDirichletBoundaryCondition.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
8#include "MeshLib/Mesh.h"
13
14namespace ProcessLib
15{
16std::unique_ptr<NumLib::LocalToGlobalIndexMap> createBoundaryDOFTable(
17 int const variable_id, int const component_id,
18 MeshLib::Mesh const& boundary_mesh,
19 NumLib::LocalToGlobalIndexMap const& dof_table_bulk)
20{
21 checkParametersOfDirichletBoundaryCondition(boundary_mesh, dof_table_bulk,
22 variable_id, component_id);
23
24 std::vector<MeshLib::Node*> const& bc_nodes = boundary_mesh.getNodes();
25 MeshLib::MeshSubset bc_mesh_subset(boundary_mesh, bc_nodes);
26
27 // Create local DOF table from the BC mesh subset for the given variable
28 // and component id.
29 return dof_table_bulk.deriveBoundaryConstrainedMap(
30 variable_id, {component_id}, std::move(bc_mesh_subset));
31}
32
34 int const variable_id, int const component_id,
35 MeshLib::Mesh const& boundary_mesh,
36 NumLib::LocalToGlobalIndexMap const& dof_table_bulk,
37 ParameterLib::Parameter<double> const& time_decay_parameter,
38 double const lower_limit)
39 : variable_id_(variable_id),
40 component_id_(component_id),
41 boundary_mesh_(boundary_mesh),
43 variable_id, component_id, boundary_mesh, dof_table_bulk)),
44 time_decay_parameter_(time_decay_parameter),
45 lower_limit_(lower_limit)
46{
47}
48
50 GlobalVector const& x) const
51{
52 initial_x_values_.clear();
53 for (auto const& l : MeshLib::views::meshLocations(
55 {
56 auto const global_index =
58 if (global_index == NumLib::MeshComponentMap::nop)
59 {
60 continue;
61 }
62 // For the DDC approach (e.g. with PETSc option), the negative
63 // index of global_index means that the entry by that index is
64 // a ghost one, which should be dropped. Especially for PETSc
65 // routines MatZeroRows and MatZeroRowsColumns, which are
66 // called to apply the Dirichlet BC, the negative index is not
67 // accepted like other matrix or vector PETSc routines.
68 // Therefore, the following if-condition is applied.
69 if (global_index >= 0) [[likely]]
70 {
71 initial_x_values_.push_back(x.get(global_index));
72 }
73 }
74}
75
77 const double t, GlobalVector const& x,
79{
80 DBUG("Apply TimeDecayDirichlet boundary bondition.");
81
83 {
86 if (initial_x_values_.empty())
87 {
88 return; // No node in the boundary.
89 }
90 }
91
92 bc_values.ids.clear();
93 bc_values.values.clear();
94
95 bc_values.ids.reserve(initial_x_values_.size());
96 bc_values.values.reserve(initial_x_values_.size());
97
98 std::size_t idx = 0;
99 for (auto const* node : boundary_mesh_.getNodes())
100 {
101 auto const node_id = node->getID();
102 MeshLib::Location const l{boundary_mesh_.getID(),
104
105 auto const global_index =
107
108 if (global_index == NumLib::MeshComponentMap::nop)
109 {
110 continue;
111 }
112 // For the DDC approach (e.g. with PETSc option), the negative
113 // index of global_index means that the entry by that index is a
114 // ghost one, which should be dropped. Especially for PETSc
115 // routines MatZeroRows and MatZeroRowsColumns, which are called
116 // to apply the Dirichlet BC, the negative index is not accepted
117 // like other matrix or vector PETSc routines. Therefore, the
118 // following if-condition is applied.
119 if (global_index >= 0) [[likely]]
120 {
122 pos.setNodeID(node_id);
123 pos.setCoordinates(*node);
124
125 bc_values.values.push_back(
126 time_decay_parameter_(t, pos).front() *
129 bc_values.ids.push_back(global_index);
130 idx++;
131 }
132 }
133}
134
135} // namespace ProcessLib
MathLib::EigenVector GlobalVector
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
double get(IndexType rowId) const
get entry
Definition EigenVector.h:52
A subset of nodes on a single mesh.
Definition MeshSubset.h:17
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:97
std::unique_ptr< LocalToGlobalIndexMap > deriveBoundaryConstrainedMap(int const variable_id, std::vector< int > const &component_ids, MeshLib::MeshSubset &&new_mesh_subset) const
static constexpr NUMLIB_EXPORT GlobalIndexType const nop
void setNodeID(std::size_t node_id)
void setCoordinates(MathLib::Point3d const &coordinates)
void getEssentialBCValues(const double t, GlobalVector const &x, NumLib::IndexValueVector< GlobalIndexType > &bc_values) const override
Writes the values of essential BCs to bc_values.
TimeDecayDirichletBoundaryCondition(int const variable_id, int const component_id, MeshLib::Mesh const &boundary_mesh, NumLib::LocalToGlobalIndexMap const &dof_table_bulk, ParameterLib::Parameter< double > const &time_decay_parameter, double const lower_limit)
Constructs a time decay Dirichlet boundary condition.
std::unique_ptr< NumLib::LocalToGlobalIndexMap > const dof_table_boundary_
ParameterLib::Parameter< double > const & time_decay_parameter_
double const lower_limit_
The lower limit of the boundary value.
auto meshLocations(Mesh const &mesh, MeshItemType const item_type)
Definition Mesh.h:227
std::unique_ptr< NumLib::LocalToGlobalIndexMap > createBoundaryDOFTable(int const variable_id, int const component_id, MeshLib::Mesh const &boundary_mesh, NumLib::LocalToGlobalIndexMap const &dof_table_bulk)
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