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