OGS
DirichletBoundaryCondition.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 <algorithm>
7#include <vector>
8
10#include "BaseLib/Logging.h"
15#include "ParameterLib/Utils.h"
16
17namespace ProcessLib
18{
20 ParameterLib::Parameter<double> const& parameter,
21 MeshLib::Mesh const& bc_mesh,
22 NumLib::LocalToGlobalIndexMap const& dof_table_bulk, int const variable_id,
23 int const component_id)
24 : _parameter(parameter),
25 _bc_mesh(bc_mesh),
26 _variable_id(variable_id),
27 _component_id(component_id)
28{
31
32 std::vector<MeshLib::Node*> const& bc_nodes = _bc_mesh.getNodes();
33 MeshLib::MeshSubset bc_mesh_subset(_bc_mesh, bc_nodes);
34
35 // Create local DOF table from the BC mesh subset for the given variable
36 // and component id.
38 variable_id, {component_id}, std::move(bc_mesh_subset));
39}
40
48
50{
52 config.checkConfigParameter("type", "Dirichlet");
53
55 auto const name = config.getConfigParameter<std::string>("parameter");
56 DBUG("{}: parameter name {:s}", __FUNCTION__, name);
57 return name;
58}
59
60std::unique_ptr<DirichletBoundaryCondition> createDirichletBoundaryCondition(
61 std::string const& parameter_name, MeshLib::Mesh const& bc_mesh,
62 NumLib::LocalToGlobalIndexMap const& dof_table_bulk, int const variable_id,
63 int const component_id,
64 const std::vector<std::unique_ptr<ParameterLib::ParameterBase>>& parameters)
65{
66 DBUG("Constructing DirichletBoundaryCondition.");
67
69 parameter_name, parameters, 1, &bc_mesh);
70
71// In case of partitioned mesh the boundary could be empty, i.e. there is no
72// boundary condition.
73#ifdef USE_PETSC
74 // This can be extracted to createBoundaryCondition() but then the config
75 // parameters are not read and will cause an error.
76 // TODO (naumov): Add a function to ConfigTree for skipping the tags of the
77 // subtree and move the code up in createBoundaryCondition().
78 if (bc_mesh.getDimension() == 0 && bc_mesh.getNumberOfNodes() == 0 &&
79 bc_mesh.getNumberOfElements() == 0)
80 {
81 return nullptr;
82 }
83#endif // USE_PETSC
84
85 return std::make_unique<DirichletBoundaryCondition>(
86 parameter, bc_mesh, dof_table_bulk, variable_id, component_id);
87}
88
89} // namespace ProcessLib
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
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:79
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
std::unique_ptr< LocalToGlobalIndexMap > deriveBoundaryConstrainedMap(int const variable_id, std::vector< int > const &component_ids, MeshLib::MeshSubset &&new_mesh_subset) const
void getEssentialBCValues(const double t, GlobalVector const &x, NumLib::IndexValueVector< GlobalIndexType > &bc_values) const override
Writes the values of essential BCs to bc_values.
DirichletBoundaryCondition(ParameterLib::Parameter< double > const &parameter, MeshLib::Mesh const &bc_mesh, NumLib::LocalToGlobalIndexMap const &dof_table_bulk, int const variable_id, int const component_id)
ParameterLib::Parameter< double > const & _parameter
std::unique_ptr< NumLib::LocalToGlobalIndexMap const > _dof_table_boundary
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)
std::string parseDirichletBCConfig(BaseLib::ConfigTree const &config)
void checkParametersOfDirichletBoundaryCondition(MeshLib::Mesh const &bc_mesh, NumLib::LocalToGlobalIndexMap const &dof_table_bulk, int const variable_id, int const component_id)
std::unique_ptr< DirichletBoundaryCondition > createDirichletBoundaryCondition(std::string const &parameter_name, MeshLib::Mesh const &bc_mesh, NumLib::LocalToGlobalIndexMap const &dof_table_bulk, int const variable_id, int const component_id, const std::vector< std::unique_ptr< ParameterLib::ParameterBase > > &parameters)