OGS
NormalTractionBoundaryCondition-impl.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <numeric>
7#include <range/v3/range/conversion.hpp>
8#include <range/v3/view/transform.hpp>
9
13#include "ParameterLib/Utils.h"
15
16namespace ProcessLib
17{
19{
20
26template <int GlobalDim>
27Eigen::Vector3d computeElementNormal(const MeshLib::Element& element,
28 const MeshLib::Element& bulk_element)
29{
31 {
32 auto const n = MeshLib::FaceRule::getSurfaceNormal(bulk_element);
33 Eigen::Vector3d const e = element.getNode(1)->asEigenVector3d() -
34 element.getNode(0)->asEigenVector3d();
35 Eigen::Vector3d const normal = e.cross(n).normalized();
36
37 // Compute center of the bulk element to correctly orient the
38 // normal.
39 auto const c =
41 // Flip n if the normal points toward c:
42 // <normal, c - n0> > 0.
43 if (normal.dot(c - element.getNode(0)->asEigenVector3d()) > 0)
44 {
45 return -normal;
46 }
47 return normal;
48 }
49
50 Eigen::Vector3d normal = MeshLib::FaceRule::getSurfaceNormal(element);
51 normal.tail<3 - GlobalDim>().setZero();
52 return normal.normalized();
53}
54
55template <int GlobalDim, template <typename /* shp fct */, int /* global dim */>
56 class LocalAssemblerImplementation>
57NormalTractionBoundaryCondition<GlobalDim, LocalAssemblerImplementation>::
59 unsigned const integration_order, unsigned const shapefunction_order,
60 MeshLib::Mesh const& bulk_mesh,
61 NumLib::LocalToGlobalIndexMap const& dof_table_bulk,
62 int const variable_id, MeshLib::Mesh const& bc_mesh,
63 ParameterLib::Parameter<double> const& pressure)
64 : _bc_mesh(bc_mesh),
65 _integration_order(integration_order),
66 _pressure(pressure)
67{
68 // Create component ids vector for the current variable.
69 auto const& number_of_components =
70 dof_table_bulk.getNumberOfVariableComponents(variable_id);
71 std::vector<int> component_ids(number_of_components);
72 std::iota(std::begin(component_ids), std::end(component_ids), 0);
73
74 // BC mesh subset creation
75 std::vector<MeshLib::Node*> const bc_nodes = _bc_mesh.getNodes();
76 DBUG("Found {:d} nodes for Natural BCs for the variable {:d}",
77 bc_nodes.size(), variable_id);
78
79 MeshLib::MeshSubset bc_mesh_subset(_bc_mesh, bc_nodes);
80
81 // Compute normal vectors for each element in the boundary condition mesh.
82 auto const* const bulk_element_ids = MeshLib::bulkElementIDs(_bc_mesh);
83 assert(bulk_element_ids != nullptr);
84 auto const& elements = _bc_mesh.getElements();
86 elements |
87 ranges::views::transform(
88 [&](const MeshLib::Element* e_ptr)
89 {
90 // Compute the corresponding bulk element for normal orientation
91 auto const* bulk_element =
92 bulk_mesh.getElement((*bulk_element_ids)[e_ptr->getID()]);
93 assert(bulk_element != nullptr);
94
95 return computeElementNormal<GlobalDim>(*e_ptr, *bulk_element);
96 }) |
97 ranges::to<std::vector<Eigen::Vector3d>>();
98
99 // Create local DOF table from the BC mesh subset for the given variable and
100 // component ids.
101 _dof_table_boundary = dof_table_bulk.deriveBoundaryConstrainedMap(
102 variable_id, component_ids, std::move(bc_mesh_subset));
103
105 GlobalDim, LocalAssemblerImplementation>(
106 *_dof_table_boundary, shapefunction_order, _bc_mesh.getElements(),
108 _bc_mesh.isAxiallySymmetric(), _pressure, _element_normals);
109}
110
111template <int GlobalDim, template <typename /* shp fct */, int /* global dim */>
112 class LocalAssemblerImplementation>
113void NormalTractionBoundaryCondition<GlobalDim, LocalAssemblerImplementation>::
114 applyNaturalBC(const double t, std::vector<GlobalVector*> const& x,
115 int const /*process_id*/, GlobalMatrix* K, GlobalVector& b,
116 GlobalMatrix* Jac)
117{
120 _local_assemblers, *_dof_table_boundary, t, x, K, b, Jac);
121}
122
124 BaseLib::ConfigTree const& config)
125{
126 DBUG("Parsing NormalTractionBoundaryCondition.");
127
129 config.checkConfigParameter("type", "NormalTraction");
130
131 auto const parameter_name =
133 config.getConfigParameter<std::string>("parameter");
134 DBUG("parameter {:s}", parameter_name);
135
136 return parameter_name;
137}
138
139template <int GlobalDim>
140std::unique_ptr<NormalTractionBoundaryCondition<
141 GlobalDim, NormalTractionBoundaryConditionLocalAssembler>>
143 std::string const& parameter_name, MeshLib::Mesh const& bc_mesh,
144 MeshLib::Mesh const& bulk_mesh,
145 NumLib::LocalToGlobalIndexMap const& dof_table, int const variable_id,
146 unsigned const integration_order, unsigned const shapefunction_order,
147 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
148{
149 DBUG("Constructing NormalTractionBoundaryCondition.");
150
151 auto const& pressure = ParameterLib::findParameter<double>(
152 parameter_name, parameters, 1, &bc_mesh);
153
154 return std::make_unique<NormalTractionBoundaryCondition<
156 integration_order, shapefunction_order, bulk_mesh, dof_table,
157 variable_id, bc_mesh, pressure);
158}
159
160} // namespace NormalTractionBoundaryCondition
161} // namespace ProcessLib
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
Eigen::Vector3d const & asEigenVector3d() const
Definition Point3d.h:55
virtual MeshElemType getGeomType() const =0
virtual const Node * getNode(unsigned idx) const =0
std::size_t getID() const
Returns the ID of the element.
Definition Element.h:80
static Eigen::Vector3d getSurfaceNormal(Element const &e)
Returns the surface normal of a 2D element.
Definition FaceRule.cpp:33
A subset of nodes on a single mesh.
Definition MeshSubset.h:17
virtual void assemble(std::size_t const id, NumLib::LocalToGlobalIndexMap const &dof_table_boundary, double const t, std::vector< GlobalVector * > const &, GlobalMatrix *, GlobalVector &b, GlobalMatrix *)=0
void applyNaturalBC(const double t, std::vector< GlobalVector * > const &x, int const process_id, GlobalMatrix *K, GlobalVector &b, GlobalMatrix *Jac) override
std::vector< Eigen::Vector3d > _element_normals
Normal vectors for each element in the boundary condition mesh.
unsigned const _integration_order
Integration order for integration over the lower-dimensional elements.
NormalTractionBoundaryCondition(unsigned const integration_order, unsigned const shapefunction_order, MeshLib::Mesh const &bulk_mesh, NumLib::LocalToGlobalIndexMap const &dof_table_bulk, int const variable_id, MeshLib::Mesh const &bc_mesh, ParameterLib::Parameter< double > const &pressure)
std::vector< std::unique_ptr< NormalTractionBoundaryConditionLocalAssemblerInterface > > _local_assemblers
Local assemblers for each element of number of _elements.
PropertyVector< std::size_t > const * bulkElementIDs(Mesh const &mesh)
Definition Mesh.cpp:290
MathLib::Point3d getCenterOfGravity(Element const &element)
Calculates the center of gravity for the mesh element.
Definition Element.cpp:131
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 createLocalAssemblers(NumLib::LocalToGlobalIndexMap const &dof_table, const unsigned shapefunction_order, std::vector< MeshLib::Element * > const &mesh_elements, std::vector< std::unique_ptr< LocalAssemblerInterface > > &local_assemblers, NumLib::IntegrationOrder const integration_order, ExtraCtorArgs &&... extra_ctor_args)
std::unique_ptr< NormalTractionBoundaryCondition< GlobalDim, NormalTractionBoundaryConditionLocalAssembler > > createNormalTractionBoundaryCondition(std::string const &parameter_name, MeshLib::Mesh const &bc_mesh, MeshLib::Mesh const &bulk_mesh, NumLib::LocalToGlobalIndexMap const &dof_table, int const variable_id, unsigned const integration_order, unsigned const shapefunction_order, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters)
Eigen::Vector3d computeElementNormal(const MeshLib::Element &element, const MeshLib::Element &bulk_element)
std::string parseNormalTractionBoundaryCondition(BaseLib::ConfigTree const &config)
static void executeMemberOnDereferenced(Method method, Container const &container, Args &&... args)