OGS
CreateReleaseNodalForce.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 <limits>
7#include <numeric>
8#include <range/v3/range/conversion.hpp>
9#include <range/v3/view/iota.hpp>
10
11#include "BaseLib/ConfigTree.h"
12#include "BoundaryCondition.h"
14#include "MeshLib/Mesh.h"
18#include "ParameterLib/Utils.h"
19#include "ReleaseNodalForce.h"
20
21namespace ProcessLib
22{
24{
25 DBUG("Parse ReleaseNodalForce boundary condition.");
26
28 {
30 "The compensate_non_equilibrium_initial_residuum must be set for "
31 "the ReleaseNodalForce boundary condition.");
32 }
33
34 auto const& config = bc_config.config;
36 config.checkConfigParameter("type", "ReleaseNodalForce");
37
38 auto const decay_parameter_name =
40 config.getConfigParameter<std::string>("time_decay_parameter");
41 DBUG("decay parameter {:s}", decay_parameter_name);
42
43 return decay_parameter_name;
44}
45
46std::unique_ptr<BoundaryCondition> createReleaseNodalForce(
47 unsigned const global_dim, int const variable_id,
48 std::string const& decay_parameter_name,
49 BoundaryConditionConfig const& bc_config, MeshLib::Mesh const& bc_mesh,
50 NumLib::LocalToGlobalIndexMap const& dof_table_bulk,
51 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
52{
53 DBUG("Create ReleaseNodalForce boundary condition.");
54
56 {
58 "The compensate_non_equilibrium_initial_residuum must be set for "
59 "the ReleaseNodalForce boundary condition.");
60 }
61
62 auto const& time_decay_parameter = ParameterLib::findParameter<double>(
63 decay_parameter_name, parameters, 1, &bc_mesh);
64
65 // In case of partitioned mesh the boundary could be empty, i.e. there
66 // is no boundary condition.
67#ifdef USE_PETSC
68 // This can be extracted to createBoundaryCondition() but then the
69 // config parameters are not read and will cause an error.
70 // TODO (naumov): Add a function to ConfigTree for skipping the tags of
71 // the subtree and move the code up in createBoundaryCondition().
72 if (bc_mesh.getDimension() == 0 && bc_mesh.getNumberOfNodes() == 0 &&
73 bc_mesh.getNumberOfElements() == 0)
74 {
75 return nullptr;
76 }
77#endif // USE_PETSC
78
79 if (bc_mesh.getDimension() >= global_dim)
80 {
82 "The dimension ({:d}) of the given boundary mesh '{:s}' is not "
83 "lower than the bulk dimension ({:d}).",
84 bc_mesh.getDimension(), bc_mesh.getName(), global_dim);
85 }
86
87 // Create component ids vector for the current variable.
88 auto const& number_of_components =
89 dof_table_bulk.getNumberOfVariableComponents(variable_id);
90 std::vector<int> component_ids =
91 ranges::views::iota(0, number_of_components) | ranges::to_vector;
92
93 // BC mesh subset creation
94 std::vector<MeshLib::Node*> const bc_nodes = bc_mesh.getNodes();
95 DBUG("Found {:d} nodes for Natural BCs for the variable {:d}",
96 bc_nodes.size(), variable_id);
97
98 MeshLib::MeshSubset bc_mesh_subset(bc_mesh, bc_nodes);
99
100 // Create local DOF table from the BC mesh subset for the given variable
101 // and component ids.
102 auto dof_table_boundary = dof_table_bulk.deriveBoundaryConstrainedMap(
103 variable_id, std::move(component_ids), std::move(bc_mesh_subset));
104
106 pos.setNodeID(0);
108 if (time_decay_parameter(0, pos).front() - 1.0 >
109 std::numeric_limits<double>::epsilon())
110 {
111 OGS_FATAL(
112 "The time_decay_parameter '{:s}' must be equal to 1.0 at t=0.0. "
113 "and decrease over time to 0. ",
114 decay_parameter_name);
115 }
116
117 return std::make_unique<ReleaseNodalForce>(
118 variable_id, bc_mesh, dof_table_boundary, time_decay_parameter);
119}
120
121} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:19
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
void checkConfigParameter(std::string const &param, std::string_view const value) const
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
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:79
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
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:88
int getNumberOfVariableComponents(int variable_id) const
std::unique_ptr< LocalToGlobalIndexMap > deriveBoundaryConstrainedMap(int const variable_id, std::vector< int > const &component_ids, MeshLib::MeshSubset &&new_mesh_subset) const
void setNodeID(std::size_t node_id)
void setCoordinates(MathLib::Point3d const &coordinates)
OGS_NO_DANGLING Parameter< ParameterDataType > & findParameter(std::string const &parameter_name, std::vector< std::unique_ptr< ParameterBase > > const &parameters, int const num_components, MeshLib::Mesh const *const mesh=nullptr)
std::string parseReleaseNodalForce(BoundaryConditionConfig const &bc_config)
std::unique_ptr< BoundaryCondition > createReleaseNodalForce(unsigned const global_dim, int const variable_id, std::string const &decay_parameter_name, BoundaryConditionConfig const &bc_config, MeshLib::Mesh const &bc_mesh, NumLib::LocalToGlobalIndexMap const &dof_table_bulk, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters)