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"
21 #include "ParameterLib/Utils.h"
22 
23 namespace ProcessLib
24 {
27  std::string property_name,
28  ParameterLib::Parameter<double> const& parameter,
29  MeshLib::Mesh const& bc_mesh,
30  NumLib::LocalToGlobalIndexMap const& dof_table_bulk,
31  int const variable_id, int const component_id)
32  : _bc_mesh(bc_mesh), _variable_id(variable_id), _component_id(component_id)
33 {
36 
37  std::vector<MeshLib::Node*> const& bc_nodes = bc_mesh.getNodes();
38  MeshLib::MeshSubset bc_mesh_subset(_bc_mesh, bc_nodes);
39 
40  // Create local DOF table from the BC mesh subset for the given variable
41  // and component id.
43  variable_id, {component_id}, std::move(bc_mesh_subset)));
44 
45  if (bc_mesh.getProperties().existsPropertyVector<double>(property_name))
46  {
47  OGS_FATAL(
48  "Found mesh property '{:s}' in the mesh '{:s}' which is for "
49  "boundary assignment. This mesh property is the built-in property "
50  "of the class SolutionDependentDirichletBoundaryCondition.",
51  property_name, bc_mesh.getName());
52  }
53 
54  _solution_dependent_bc = MeshLib::getOrCreateMeshProperty<double>(
55  const_cast<MeshLib::Mesh&>(bc_mesh), property_name,
57  _solution_dependent_bc->resize(bc_mesh.getNumberOfNodes());
58 
60 
61  auto const& nodes = bc_mesh.getNodes();
62  for (std::size_t i = 0; i < _solution_dependent_bc->size(); ++i)
63  {
64  auto const id = nodes[i]->getID();
65  pos.setNodeID(id);
66  (*_solution_dependent_bc)[i] = parameter(0, pos)[0];
67  }
68 
69  _parameter = std::make_unique<ParameterLib::MeshNodeParameter<double>>(
70  property_name, bc_mesh, *_solution_dependent_bc);
71 }
72 
74  double const t, GlobalVector const& x,
76 {
79  t, x, bc_values);
80 }
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 
99 std::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(char const *fmt, Args const &... args)
Definition: Logging.h:27
Definition of the Mesh class.
void checkConfigParameter(std::string const &param, T const &value) const
T getConfigParameter(std::string const &param) const
Global vector based on Eigen vector.
Definition: EigenVector.h:26
A subset of nodes on a single mesh.
Definition: MeshSubset.h:27
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:95
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition: Mesh.h:71
std::size_t getID() const
Get id of the mesh.
Definition: Mesh.h:110
const std::string getName() const
Get name of the mesh.
Definition: Mesh.h:92
Properties & getProperties()
Definition: Mesh.h:123
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:89
std::size_t getNumberOfElements() const
Get the number of elements.
Definition: Mesh.h:86
bool existsPropertyVector(std::string const &name) const
std::size_t size() const
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< MeshLib::Node * > 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)