OGS
SolutionDependentDirichletBoundaryCondition.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 <memory>
7#include <vector>
8
10#include "BaseLib/Logging.h"
12#include "MeshLib/Mesh.h"
15#include "ParameterLib/Utils.h"
16
17namespace ProcessLib
18{
21 std::string property_name,
22 ParameterLib::Parameter<double> const& parameter,
23 MeshLib::Mesh const& bc_mesh,
24 NumLib::LocalToGlobalIndexMap const& dof_table_bulk,
25 int const variable_id, int const component_id)
26 : _bc_mesh(bc_mesh), _variable_id(variable_id), _component_id(component_id)
27{
30
31 std::vector<MeshLib::Node*> const& bc_nodes = bc_mesh.getNodes();
32 MeshLib::MeshSubset bc_mesh_subset(_bc_mesh, bc_nodes);
33
34 // Create local DOF table from the BC mesh subset for the given variable
35 // and component id.
37 variable_id, {component_id}, std::move(bc_mesh_subset));
38
39 if (bc_mesh.getProperties().existsPropertyVector<double>(property_name))
40 {
42 "Found mesh property '{:s}' in the mesh '{:s}' which is for "
43 "boundary assignment. This mesh property is the built-in property "
44 "of the class SolutionDependentDirichletBoundaryCondition.",
45 property_name, bc_mesh.getName());
46 }
47
49 const_cast<MeshLib::Mesh&>(bc_mesh), property_name,
51 assert(_solution_dependent_bc->size() == bc_mesh.getNumberOfNodes());
52
54
55 auto const& nodes = bc_mesh.getNodes();
56 for (std::size_t i = 0; i < _solution_dependent_bc->size(); ++i)
57 {
58 auto const id = nodes[i]->getID();
59 pos.setNodeID(id);
60 (*_solution_dependent_bc)[i] = parameter(0, pos)[0];
61 }
62
63 _parameter = std::make_unique<ParameterLib::MeshNodeParameter<double>>(
64 property_name, bc_mesh, *_solution_dependent_bc);
65}
66
74
76 double const /*t*/, std::vector<GlobalVector*> const& x,
77 int const process_id)
78{
79 auto const& nodes = _bc_mesh.getNodes();
80 for (std::size_t i = 0; i < _solution_dependent_bc->size(); ++i)
81 {
82 auto const id = nodes[i]->getID();
83 auto const global_index = _dof_table_boundary->getGlobalIndex(
86
87 assert(global_index >= 0);
88 (*_solution_dependent_bc)[i] = x[process_id]->get(global_index);
89 }
90}
91
94 BaseLib::ConfigTree const& config)
95{
96 DBUG("Parsing SolutionDependentDirichletBoundaryCondition.");
97
99 config.checkConfigParameter("type", "SolutionDependentDirichlet");
100
101 auto property_name =
103 config.getConfigParameter<std::string>("property_name");
104
105 auto const initial_value_parameter_string =
107 config.getConfigParameter<std::string>("initial_value_parameter");
108
109 return {property_name, initial_value_parameter_string};
110}
111
112std::unique_ptr<SolutionDependentDirichletBoundaryCondition>
115 MeshLib::Mesh const& bc_mesh,
116 NumLib::LocalToGlobalIndexMap const& dof_table_bulk, int const variable_id,
117 int const component_id,
118 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
119{
120 DBUG("Constructing SolutionDependentDirichletBoundaryCondition.");
121
122 auto& initial_value_parameter = ParameterLib::findParameter<double>(
123 config.initial_value_parameter_string, parameters, 1, &bc_mesh);
124
125// In case of partitioned mesh the boundary could be empty, i.e. there is no
126// boundary condition.
127#ifdef USE_PETSC
128 // This can be extracted to createBoundaryCondition() but then the config
129 // parameters are not read and will cause an error.
130 // TODO (naumov): Add a function to ConfigTree for skipping the tags of the
131 // subtree and move the code up in createBoundaryCondition().
132 if (bc_mesh.getDimension() == 0 && bc_mesh.getNumberOfNodes() == 0 &&
133 bc_mesh.getNumberOfElements() == 0)
134 {
135 return nullptr;
136 }
137#endif // USE_PETSC
138
139 return std::make_unique<SolutionDependentDirichletBoundaryCondition>(
140 config.property_name, initial_value_parameter, bc_mesh, dof_table_bulk,
141 variable_id, component_id);
142}
143
144} // 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
T getConfigParameter(std::string const &param) const
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
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
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:88
bool existsPropertyVector(std::string_view name) 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 getEssentialBCValues(double const t, GlobalVector const &x, NumLib::IndexValueVector< GlobalIndexType > &bc_values) const override
Writes the values of essential BCs to bc_values.
std::unique_ptr< NumLib::LocalToGlobalIndexMap const > _dof_table_boundary
std::unique_ptr< ParameterLib::MeshNodeParameter< double > > _parameter
SolutionDependentDirichletBoundaryCondition(std::string property_name, ParameterLib::Parameter< double > const &parameter, MeshLib::Mesh const &bc_mesh, NumLib::LocalToGlobalIndexMap const &dof_table_bulk, int const variable_id, int const component_id)
void postTimestep(double const, std::vector< GlobalVector * > const &x, int const process_id) override
PropertyVector< T > * getOrCreateMeshProperty(Mesh &mesh, std::string const &property_name, MeshItemType const item_type, int const number_of_components)
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)
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::unique_ptr< SolutionDependentDirichletBoundaryCondition > createSolutionDependentDirichletBoundaryCondition(SolutionDependentDirichletBoundaryConditionConfig const &config, MeshLib::Mesh const &bc_mesh, NumLib::LocalToGlobalIndexMap const &dof_table_bulk, int const variable_id, int const component_id, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters)
SolutionDependentDirichletBoundaryConditionConfig parseSolutionDependentDirichletBoundaryCondition(BaseLib::ConfigTree const &config)