OGS
SolutionDependentDirichletBoundaryCondition.cpp
Go to the documentation of this file.
1
12
13#include <memory>
14#include <vector>
15
16#include "BaseLib/ConfigTree.h"
17#include "BaseLib/Logging.h"
19#include "MeshLib/Mesh.h"
22#include "ParameterLib/Utils.h"
23
24namespace ProcessLib
25{
28 std::string property_name,
29 ParameterLib::Parameter<double> const& parameter,
30 MeshLib::Mesh const& bc_mesh,
31 NumLib::LocalToGlobalIndexMap const& dof_table_bulk,
32 int const variable_id, int const component_id)
33 : _bc_mesh(bc_mesh), _variable_id(variable_id), _component_id(component_id)
34{
37
38 std::vector<MeshLib::Node*> const& bc_nodes = bc_mesh.getNodes();
39 MeshLib::MeshSubset bc_mesh_subset(_bc_mesh, bc_nodes);
40
41 // Create local DOF table from the BC mesh subset for the given variable
42 // and component id.
44 variable_id, {component_id}, std::move(bc_mesh_subset));
45
46 if (bc_mesh.getProperties().existsPropertyVector<double>(property_name))
47 {
49 "Found mesh property '{:s}' in the mesh '{:s}' which is for "
50 "boundary assignment. This mesh property is the built-in property "
51 "of the class SolutionDependentDirichletBoundaryCondition.",
52 property_name, bc_mesh.getName());
53 }
54
55 _solution_dependent_bc = MeshLib::getOrCreateMeshProperty<double>(
56 const_cast<MeshLib::Mesh&>(bc_mesh), property_name,
59
61
62 auto const& nodes = bc_mesh.getNodes();
63 for (std::size_t i = 0; i < _solution_dependent_bc->size(); ++i)
64 {
65 auto const id = nodes[i]->getID();
66 pos.setNodeID(id);
67 (*_solution_dependent_bc)[i] = parameter(0, pos)[0];
68 }
69
70 _parameter = std::make_unique<ParameterLib::MeshNodeParameter<double>>(
71 property_name, bc_mesh, *_solution_dependent_bc);
72}
73
81
83 double const /*t*/, std::vector<GlobalVector*> const& x,
84 int const process_id)
85{
86 auto const& nodes = _bc_mesh.getNodes();
87 for (std::size_t i = 0; i < _solution_dependent_bc->size(); ++i)
88 {
89 auto const id = nodes[i]->getID();
90 auto const global_index = _dof_table_boundary->getGlobalIndex(
93
94 assert(global_index >= 0);
95 (*_solution_dependent_bc)[i] = x[process_id]->get(global_index);
96 }
97}
98
99std::unique_ptr<SolutionDependentDirichletBoundaryCondition>
101 BaseLib::ConfigTree const& config, MeshLib::Mesh const& bc_mesh,
102 NumLib::LocalToGlobalIndexMap const& dof_table_bulk, int const variable_id,
103 int const component_id,
104 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
105{
106 DBUG(
107 "Constructing SolutionDependentDirichletBoundaryCondition from "
108 "config.");
110 config.checkConfigParameter("type", "SolutionDependentDirichlet");
111
112 auto property_name =
114 config.getConfigParameter<std::string>("property_name");
115
116 auto& initial_value_parameter = ParameterLib::findParameter<double>(
118 config.getConfigParameter<std::string>("initial_value_parameter"),
119 parameters, 1, &bc_mesh);
120
121// In case of partitioned mesh the boundary could be empty, i.e. there is no
122// boundary condition.
123#ifdef USE_PETSC
124 // This can be extracted to createBoundaryCondition() but then the config
125 // parameters are not read and will cause an error.
126 // TODO (naumov): Add a function to ConfigTree for skipping the tags of the
127 // subtree and move the code up in createBoundaryCondition().
128 if (bc_mesh.getDimension() == 0 && bc_mesh.getNumberOfNodes() == 0 &&
129 bc_mesh.getNumberOfElements() == 0)
130 {
131 return nullptr;
132 }
133#endif // USE_PETSC
134
135 return std::make_unique<SolutionDependentDirichletBoundaryCondition>(
136 std::move(property_name), initial_value_parameter, bc_mesh,
137 dof_table_bulk, variable_id, component_id);
138}
139
140} // namespace ProcessLib
Defines functions that are shared by DirichletBoundaryCondition and DirichletBoundaryConditionWithinT...
#define OGS_FATAL(...)
Definition Error.h:26
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
Definition of the Mesh class.
T getConfigParameter(std::string const &param) const
void checkConfigParameter(std::string const &param, std::string_view const value) const
Global vector based on Eigen vector.
Definition EigenVector.h:25
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:106
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:88
std::size_t getID() const
Get id of the mesh.
Definition Mesh.h:121
Properties & getProperties()
Definition Mesh.h:134
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:103
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition Mesh.h:100
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:97
bool existsPropertyVector(std::string_view name) const
std::size_t size() 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
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::unique_ptr< SolutionDependentDirichletBoundaryCondition > createSolutionDependentDirichletBoundaryCondition(BaseLib::ConfigTree 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)
void checkParametersOfDirichletBoundaryCondition(MeshLib::Mesh const &bc_mesh, NumLib::LocalToGlobalIndexMap const &dof_table_bulk, int const variable_id, int const component_id)