HArD::Core3D
Hybrid Arbitrary Degree::Core 3D - Library to implement 3D schemes with vertex, edge, face and cell polynomials as unknowns
Loading...
Searching...
No Matches
BoundaryConditions.hpp
Go to the documentation of this file.
1// Class to provide description of boundary conditions
2//
3//
4// Author: Jerome Droniou (jerome.droniou@monash.edu)
5//
6
7/*
8*
9* This library was developed around HHO methods, although some parts of it have a more
10* general purpose. If you use this code or part of it in a scientific publication,
11* please mention the following book as a reference for the underlying principles
12* of HHO schemes:
13*
14* The Hybrid High-Order Method for Polytopal Meshes: Design, Analysis, and Applications.
15* D. A. Di Pietro and J. Droniou. 2019, 516p.
16* url: https://hal.archives-ouvertes.fr/hal-02151813.
17*
18*/
19
20
21#ifndef _BOUNDARY_CONDITIONS_HPP
22#define _BOUNDARY_CONDITIONS_HPP
23
24#include <iostream>
25#include <string>
26#include <mesh.hpp>
27
28using namespace HArDCore3D;
29
35// ----------------------------------------------------------------------------
36// Class definition
37// ----------------------------------------------------------------------------
38
39// @addtogroup TestCases
41
43struct Plane {
45 Plane(const VectorRd & point, const VectorRd & normal):
46 point(point),
48 {
49 // do nothing
50 };
51
52 VectorRd point;
53 VectorRd normal;
54
56 bool is_in(const VectorRd & x) const;
58 inline bool is_in(const Vertex & V) const { return is_in(V.coords()); };
60 template<typename MeshEntity>
61 bool is_in(const MeshEntity & E) const{
62 for (auto V : E.get_vertices()){
63 if (! is_in(*V) ) return false;
64 }
65 return true;
66 };
67
69 bool is_on_side(const VectorRd & x, const double & side) const;
71 inline bool is_on_side(const Vertex & V, const double & side) const { return is_on_side(V.coords(), side); };
73 template<typename MeshEntity>
74 bool is_on_side(const MeshEntity & E, const double & side) const{
75 for (auto V : E.get_vertices()){
76 if (! is_on_side(*V, side) ) return false;
77 }
78 return true;
79 };
80
81};
82
84struct Hull {
86 Hull(const std::vector<VectorRd> & nodes, const VectorRd & normal):
87 nodes(nodes),
89 {
90 // Create center and apex
91 center = VectorRd::Zero();
92 for (size_t i=0; i<nodes.size(); i++){
93 center += nodes[i];
94 }
95 center /= nodes.size();
96 apex = center + normal;
97 };
98
99 std::vector<VectorRd> nodes;
100 VectorRd normal;
101 VectorRd center;
102 VectorRd apex;
103
105 bool is_in(const VectorRd & x) const;
107 inline bool is_in(const Vertex & V) const { return is_in(V.coords()); };
109 template<typename MeshEntity>
110 bool is_in(const MeshEntity & E) const{
111 for (auto V : E.get_vertices()){
112 if (! is_in(*V) ) return false;
113 }
114 return true;
115 };
116
117};
118
119
120// Various definitions of planes and convex hulls used in the BCs below
121const Plane plane_x_zero(VectorRd::Zero(), VectorRd(1., 0., 0.));
122const Plane plane_x_quarter(VectorRd(.25,0.,0.), VectorRd(1.,0.,0.));
123const Plane plane_x_half(VectorRd(.5,0.,0.), VectorRd(1.,0.,0.));
124const Hull lower_bottom_corner_x_zero({VectorRd(0.,0.,0.), VectorRd(0.,.25,0.), VectorRd(0.,.25,.25), VectorRd(0.,0.,.25)}, VectorRd(1., 0., 0.));
125const Hull lower_bottom_corner_x_one({VectorRd(1.,0.,0.), VectorRd(1.,.25,0.), VectorRd(1.,.25,.25), VectorRd(1.,0.,.25)}, VectorRd(1., 0., 0.));
126
127
130
131public:
134 const std::string bc_id,
135 Mesh& mesh
136 );
137
139 const std::string type(
140 const Face& face
141 ) const ;
149 const std::string type(
150 const Edge& edge
151 ) const ;
152
154 const std::string type(
155 const Vertex& vertex
156 ) const ;
157
158
160 inline const size_t n_dir_faces() const {
161 return m_n_dir_faces;
162 };
163
165 inline const size_t n_dir_edges() const {
166 return m_n_dir_edges;
167 };
168
170 inline const size_t n_dir_vertices() const {
171 return m_n_dir_vertices;
172 };
173
175 inline const std::string id() { return m_bc_id; };
176
178 inline const std::string name() const {
179 if (m_bc_id == "D"){
180 return "Dirichlet";
181 }else if (m_bc_id == "N"){
182 return "Neumann";
183 }else if (m_bc_id == "M0"){
184 return "Mixed #0 (Dirichlet at x=0, Neumann elsewhere)";
185 }else if (m_bc_id == "M1"){
186 return "Mixed #1 (Dirichlet at x=0 a small rectangle, Neumann elsewhere)";
187 }else if (m_bc_id == "M2"){
188 return "Mixed #2 (Dirichlet between planes x=.25 and x=.5, Neumann elsewhere)";
189 }
190 std::cout << "Unknown boundary conditions: " << m_bc_id << "\n";
191 exit(1);
192 };
193
195 void reorder_faces(const std::string pos = "end");
196
198 void reorder_edges(const std::string pos = "end");
199
201 void reorder_vertices(const std::string pos = "end");
202
203
204private:
205 // Parameters: id of boundary condition, reference to mesh
206 const std::string m_bc_id;
207 Mesh& m_mesh;
208
209 // Number of Dirichlet faces, edges and vertices
210 size_t m_n_dir_faces;
211 size_t m_n_dir_edges;
212 size_t m_n_dir_vertices;
213
214};
215
216
218
219#endif //_BOUNDARY_CONDITION_HPP
const Hull lower_bottom_corner_x_zero({VectorRd(0., 0., 0.), VectorRd(0.,.25, 0.), VectorRd(0.,.25,.25), VectorRd(0., 0.,.25)}, VectorRd(1., 0., 0.))
const Plane plane_x_quarter(VectorRd(.25, 0., 0.), VectorRd(1., 0., 0.))
const Plane plane_x_zero(VectorRd::Zero(), VectorRd(1., 0., 0.))
const Plane plane_x_half(VectorRd(.5, 0., 0.), VectorRd(1., 0., 0.))
const Hull lower_bottom_corner_x_one({VectorRd(1., 0., 0.), VectorRd(1.,.25, 0.), VectorRd(1.,.25,.25), VectorRd(1., 0.,.25)}, VectorRd(1., 0., 0.))
The BoundaryConditions class provides definition of boundary conditions.
Definition BoundaryConditions.hpp:129
const std::string type(const Face &face) const
Test the boundary condition of an face.
Definition BoundaryConditions.cpp:81
const size_t n_dir_vertices() const
Returns the number of Dirichlet vertices.
Definition BoundaryConditions.hpp:170
void reorder_vertices(const std::string pos="end")
Re-order vertices of the mesh to put the Dirichlet vertices at the position "pos" (=end or start)
Definition BoundaryConditions.cpp:241
void reorder_edges(const std::string pos="end")
Re-order edges of the mesh to put the Dirichlet edges at the position "pos" (=end or start)
Definition BoundaryConditions.cpp:195
const std::string name() const
Returns the complete name of the boundary condition.
Definition BoundaryConditions.hpp:178
void reorder_faces(const std::string pos="end")
Re-order faces of the mesh to put the Dirichlet faces at the position "pos" (=end or start)
Definition BoundaryConditions.cpp:149
const size_t n_dir_edges() const
Returns the number of Dirichlet edges.
Definition BoundaryConditions.hpp:165
const std::string id()
Returns the identifier of the BC.
Definition BoundaryConditions.hpp:175
const size_t n_dir_faces() const
Returns the number of Dirichlet faces.
Definition BoundaryConditions.hpp:160
Class to describe a mesh.
Definition MeshND.hpp:17
@ Matrix
Definition basis.hpp:67
std::string bc_id
Definition HHO_DiffAdvecReac.hpp:44
Definition ddr-magnetostatics.hpp:41
MeshND::VectorRd< 2 > VectorRd
Definition Mesh2D.hpp:14
Structure to define a flat convex hull (nodes and normal) and check if a mesh entity is inside.
Definition BoundaryConditions.hpp:84
VectorRd center
"Center" of the hull
Definition BoundaryConditions.hpp:101
bool is_in(const MeshEntity &E) const
Check if a mesh entity is in the convex hull.
Definition BoundaryConditions.hpp:110
VectorRd apex
A point outside the plane of the convex hull (in the direction of normal)
Definition BoundaryConditions.hpp:102
bool is_in(const Vertex &V) const
Check if a vertex is in the convex hull.
Definition BoundaryConditions.hpp:107
VectorRd normal
Normal to the planar convex hull.
Definition BoundaryConditions.hpp:100
Hull(const std::vector< VectorRd > &nodes, const VectorRd &normal)
Constructor.
Definition BoundaryConditions.hpp:86
std::vector< VectorRd > nodes
Nodes defining the planar convex hull.
Definition BoundaryConditions.hpp:99
bool is_in(const VectorRd &x) const
Check if a point is in the convex hull.
Definition BoundaryConditions.cpp:26
Structure to define a plane (by a point and a normal) and check position of a mesh entity with respec...
Definition BoundaryConditions.hpp:43
bool is_on_side(const MeshEntity &E, const double &side) const
Check if a mesh entity is on one side of the plane (side=+/-1 depending on the normal to the plane)
Definition BoundaryConditions.hpp:74
bool is_in(const MeshEntity &E) const
Check if a mesh entity is inside the plane.
Definition BoundaryConditions.hpp:61
bool is_on_side(const Vertex &V, const double &side) const
Check if a vertex is on one side of the plane (side=+/-1 depending on the normal to the plane)
Definition BoundaryConditions.hpp:71
VectorRd normal
Normal to the plane.
Definition BoundaryConditions.hpp:53
bool is_in(const Vertex &V) const
Check if a vertex is inside the plane.
Definition BoundaryConditions.hpp:58
bool is_on_side(const VectorRd &x, const double &side) const
Check if a point is on one side of the plane (side=+/-1 depending on the normal to the plane)
Definition BoundaryConditions.cpp:21
bool is_in(const VectorRd &x) const
Check if a point is inside the plane.
Definition BoundaryConditions.cpp:17
VectorRd point
One point on the plane.
Definition BoundaryConditions.hpp:52
Plane(const VectorRd &point, const VectorRd &normal)
Constructor.
Definition BoundaryConditions.hpp:45