HArD::Core2D
Hybrid Arbitrary Degree::Core 2D - Library to implement 2D schemes with edge and cell polynomials as unknowns
Loading...
Searching...
No Matches
BChandlers.hpp
Go to the documentation of this file.
1// Free functions to help handle BC and DOFs/indices
2//
3// Author: Jerome Droniou (jerome.droniou@monash.edu)
4//
5
6/*
7*
8* This library was developed around HHO methods, although some parts of it have a more
9* general purpose. If you use this code or part of it in a scientific publication,
10* please mention the following book as a reference for the underlying principles
11* of HHO schemes:
12*
13* The Hybrid High-Order Method for Polytopal Meshes: Design, Analysis, and Applications.
14* D. A. Di Pietro and J. Droniou. 2019, 516p.
15* url: https://hal.archives-ouvertes.fr/hal-02151813.
16*
17*/
18
19#ifndef BCHANDLERS_HPP
20#define BCHANDLERS_HPP
21
23#include <globaldofspace.hpp>
24#include <mesh.hpp>
25
26using namespace HArDCore2D;
27
28// ----------------------------------------------------------------------------
29// Class definition
30// ----------------------------------------------------------------------------
31
38void setBCLabels(const BoundaryConditions &BC, GlobalDOFSpace &globaldofspace) {
39
40 for (Vertex *v : globaldofspace.mesh().get_vertices()){
41 int label = 0;
42 if (BC.type(*v)=="dir"){
43 label = 1;
44 }else if (BC.type(*v)=="neu"){
45 label = -1;
46 }
47 size_t offset_v = globaldofspace.globalOffset(*v);
48 for (size_t i=offset_v; i < offset_v + globaldofspace.numLocalDofsVertex(); i++){
49 globaldofspace.setLabelDOF(i, label);
50 }
51 }
52
53 for (Edge *e : globaldofspace.mesh().get_edges()){
54 int label = 0;
55 if (BC.type(*e)=="dir"){
56 label = 1;
57 }else if (BC.type(*e)=="neu"){
58 label = -1;
59 }
60 size_t offset_e = globaldofspace.globalOffset(*e);
61 for (size_t i=offset_e; i < offset_e + globaldofspace.numLocalDofsEdge(); i++){
62 globaldofspace.setLabelDOF(i, label);
63 }
64 }
65
66}
67
68
70
72int offsetIndex(const std::vector<size_t> &c, const int &i){
73 assert( c.size() >= 2 && c.size()%2 == 0);
74
75 int val = -1;
76 int idx = -1;
77 int offset = 0;
78 // Look for index in c such that c[idx]>i and add offsets (every other pair of indices)
79 do {
80 idx++;
81 if (idx%2 == 1){
82 // c.size() even so no risk of having idx=c.size() here
83 offset += c[idx]-c[idx-1];
84 }
85 }
86 while (idx<int(c.size()) && int(c[idx])<=i);
87
88 if (idx%2 == 0){
89 val = i - offset;
90 }
91
92 return val;
93
94}
95
97Eigen::ArrayXi create_mapDOF(const std::vector<size_t> &c, const size_t N){
98 assert( c.size() >= 2 && c.size()%2 == 0);
99
100 Eigen::ArrayXi dofs = Eigen::ArrayXi::LinSpaced(N, 0, N-1);
101 Eigen::ArrayXi map = -Eigen::ArrayXi::Ones(N);
102
103 size_t offset = 0;
104 map.head(c[0]) = dofs.head(c[0]);
105 for (size_t i = 1; i < c.size()-1; i += 2){
106 offset += c[i] - c[i-1];
107 map.segment(c[i], c[i+1]-c[i]) = dofs.segment(c[i], c[i+1]-c[i]) - offset;
108 }
109 offset += c[c.size()-1]-c[c.size()-2];
110 map.tail(N-c[c.size()-1]) = dofs.tail(N-c[c.size()-1]) - offset;
111
112 return map;
113
114}
115
116
118
128template<typename VecType>
130 const VecType &V,
131 const VecType &Z,
132 const std::vector<std::pair<size_t,size_t>> &sec
133 )
134{
135 assert ( sec[sec.size()-1].first + sec[sec.size()-1].second <= size_t(V.rows()) );
136
137 VecType val = V;
138 size_t posZ = 0;
139 for (size_t i=0; i < sec.size(); i++){
140 assert( posZ + sec[i].second <= size_t(Z.rows()) );
141
142 val.segment(sec[i].first, sec[i].second) = Z.segment(posZ, sec[i].second);
143 posZ += sec[i].second;
144 }
145 return val;
146}
147
149
150#endif
The BoundaryConditions class provides definition of boundary conditions.
Definition BoundaryConditions.hpp:45
const std::string type(const Edge &edge) const
Test the boundary condition of an edge.
Definition BoundaryConditions.cpp:41
Base class for global DOF spaces. Provides functions to manipulate global DOFs (the local version bei...
Definition globaldofspace.hpp:16
Compute max and min eigenvalues of all matrices for i
Definition compute_eigs.m:5
VecType replaceSectionsVector(const VecType &V, const VecType &Z, const std::vector< std::pair< size_t, size_t > > &sec)
Replace sections of vector V by values from vector Z into vector V; the sections are determined by 's...
Definition BChandlers.hpp:129
void setBCLabels(const BoundaryConditions &BC, GlobalDOFSpace &globaldofspace)
Adds BC labels do GlobalDOFSpace DOFs. The default label is 0; we leave it 0 for internal DOF,...
Definition BChandlers.hpp:38
Eigen::ArrayXi create_mapDOF(const std::vector< size_t > &c, const size_t N)
Create a map from DOFs 0..N-1 to values obtained by cutting the DOFs corresponding to c (as per offse...
Definition BChandlers.hpp:97
int offsetIndex(const std::vector< size_t > &c, const int &i)
Function to offset and index i according to a vector c0,c1,...,c2n of increasing numbers.
Definition BChandlers.hpp:72
void setLabelDOF(const size_t i, const int label)
Set a label to the DOF number i (default label is -1)
Definition globaldofspace.hpp:91
size_t globalOffset(const Vertex &V) const
Return the global offset for the unknowns on the vertex V.
Definition globaldofspace.hpp:31
size_t numLocalDofsVertex() const
Returns the number of local vertex DOFs.
Definition localdofspace.hpp:39
size_t numLocalDofsEdge() const
Returns the number of local edge DOFs.
Definition localdofspace.hpp:45
const Mesh & mesh() const
Returns the mesh.
Definition localdofspace.hpp:33
std::vector< Edge * > get_edges() const
lists the edges in the mesh.
Definition Mesh2D.hpp:76
std::vector< Vertex * > get_vertices() const
lists the vertices in the mesh.
Definition Mesh2D.hpp:75
Definition ddr-klplate.hpp:27
static auto v
Definition ddrcore-test.hpp:32