OGS
TimeDecayDirichletBoundaryCondition.cpp
Go to the documentation of this file.
1
13
16#include "MeshLib/Mesh.h"
17#include "MeshLib/MeshSubset.h"
21
22namespace ProcessLib
23{
24std::unique_ptr<NumLib::LocalToGlobalIndexMap> createBoundaryDOFTable(
25 int const variable_id, int const component_id,
26 MeshLib::Mesh const& boundary_mesh,
27 NumLib::LocalToGlobalIndexMap const& dof_table_bulk)
28{
29 checkParametersOfDirichletBoundaryCondition(boundary_mesh, dof_table_bulk,
30 variable_id, component_id);
31
32 std::vector<MeshLib::Node*> const& bc_nodes = boundary_mesh.getNodes();
33 MeshLib::MeshSubset bc_mesh_subset(boundary_mesh, bc_nodes);
34
35 // Create local DOF table from the BC mesh subset for the given variable
36 // and component id.
37 return dof_table_bulk.deriveBoundaryConstrainedMap(
38 variable_id, {component_id}, std::move(bc_mesh_subset));
39}
40
42 int const variable_id, int const component_id,
43 MeshLib::Mesh const& boundary_mesh,
44 NumLib::LocalToGlobalIndexMap const& dof_table_bulk,
45 ParameterLib::Parameter<double> const& time_decay_parameter,
46 double const lower_limit)
47 : variable_id_(variable_id),
48 component_id_(component_id),
49 boundary_mesh_(boundary_mesh),
50 dof_table_boundary_(createBoundaryDOFTable(
51 variable_id, component_id, boundary_mesh, dof_table_bulk)),
52 time_decay_parameter_(time_decay_parameter),
53 lower_limit_(lower_limit)
54{
55}
56
58 GlobalVector const& x) const
59{
60 initial_x_values_.clear();
61 for (auto const& l : MeshLib::views::meshLocations(
63 {
64 auto const global_index =
66 if (global_index == NumLib::MeshComponentMap::nop)
67 {
68 continue;
69 }
70 // For the DDC approach (e.g. with PETSc option), the negative
71 // index of global_index means that the entry by that index is
72 // a ghost one, which should be dropped. Especially for PETSc
73 // routines MatZeroRows and MatZeroRowsColumns, which are
74 // called to apply the Dirichlet BC, the negative index is not
75 // accepted like other matrix or vector PETSc routines.
76 // Therefore, the following if-condition is applied.
77 if (global_index >= 0) [[likely]]
78 {
79 initial_x_values_.push_back(x.get(global_index));
80 }
81 }
82}
83
85 const double t, GlobalVector const& x,
87{
88 DBUG("Apply TimeDecayDirichlet boundary bondition.");
89
91 {
94 if (initial_x_values_.empty())
95 {
96 return; // No node in the boundary.
97 }
98 }
99
100 bc_values.ids.clear();
101 bc_values.values.clear();
102
103 bc_values.ids.reserve(initial_x_values_.size());
104 bc_values.values.reserve(initial_x_values_.size());
105
106 std::size_t idx = 0;
107 for (auto const* node : boundary_mesh_.getNodes())
108 {
109 auto const node_id = node->getID();
112
113 auto const global_index =
115
116 if (global_index == NumLib::MeshComponentMap::nop)
117 {
118 continue;
119 }
120 // For the DDC approach (e.g. with PETSc option), the negative
121 // index of global_index means that the entry by that index is a
122 // ghost one, which should be dropped. Especially for PETSc
123 // routines MatZeroRows and MatZeroRowsColumns, which are called
124 // to apply the Dirichlet BC, the negative index is not accepted
125 // like other matrix or vector PETSc routines. Therefore, the
126 // following if-condition is applied.
127 if (global_index >= 0) [[likely]]
128 {
130 pos.setNodeID(node_id);
131 pos.setCoordinates(*node);
132
133 bc_values.values.push_back(
134 time_decay_parameter_(t, pos).front() *
137 bc_values.ids.push_back(global_index);
138 idx++;
139 }
140 }
141}
142
143} // namespace ProcessLib
Defines functions that are shared by DirichletBoundaryCondition and DirichletBoundaryConditionWithinT...
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
Definition of the Mesh class.
Global vector based on Eigen vector.
Definition EigenVector.h:26
double get(IndexType rowId) const
get entry
Definition EigenVector.h:59
A subset of nodes on a single mesh.
Definition MeshSubset.h:26
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:108
std::size_t getID() const
Get id of the mesh.
Definition Mesh.h:123
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:238
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