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
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 <mesh.hpp>
24
25using namespace HArDCore3D;
26
27// ----------------------------------------------------------------------------
28// Class definition
29// ----------------------------------------------------------------------------
30
38
40int offsetIndex(const std::vector<size_t> &c, const int &i){
41 assert( c.size() >= 2 && c.size()%2 == 0);
42
43 int val = -1;
44 int idx = -1;
45 int offset = 0;
46 // Look for index in c such that c[idx]>i and add offsets (every other pair of indices)
47 do {
48 idx++;
49 if (idx%2 == 1){
50 // c.size() even so no risk of having idx=c.size() here
51 offset += c[idx]-c[idx-1];
52 }
53 }
54 while (idx<int(c.size()) && int(c[idx])<=i);
55
56 if (idx%2 == 0){
57 val = i - offset;
58 }
59
60 return val;
61
62}
63
65Eigen::ArrayXi create_mapDOF(const std::vector<size_t> &c, const size_t N){
66 assert( c.size() >= 2 && c.size()%2 == 0);
67
68 Eigen::ArrayXi dofs = Eigen::ArrayXi::LinSpaced(N, 0, N-1);
69 Eigen::ArrayXi map = -Eigen::ArrayXi::Ones(N);
70
71 size_t offset = 0;
72 map.head(c[0]) = dofs.head(c[0]);
73 for (size_t i = 1; i < c.size()-1; i += 2){
74 offset += c[i] - c[i-1];
75 map.segment(c[i], c[i+1]-c[i]) = dofs.segment(c[i], c[i+1]-c[i]) - offset;
76 }
77 offset += c[c.size()-1]-c[c.size()-2];
78 map.tail(N-c[c.size()-1]) = dofs.tail(N-c[c.size()-1]) - offset;
79
80 return map;
81
82}
83
84
86
96template<typename VecType>
98 const VecType &V,
99 const VecType &Z,
100 const std::vector<std::pair<size_t,size_t>> &sec
101 )
102{
103 assert ( sec[sec.size()-1].first + sec[sec.size()-1].second <= size_t(V.rows()) );
104
105 VecType val = V;
106 size_t posZ = 0;
107 for (size_t i=0; i < sec.size(); i++){
108 assert( posZ + sec[i].second <= size_t(Z.rows()) );
109
110 val.segment(sec[i].first, sec[i].second) = Z.segment(posZ, sec[i].second);
111 posZ += sec[i].second;
112 }
113 return val;
114}
115
117
118#endif
@ Matrix
Definition basis.hpp:67
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:97
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:65
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:40
Definition ddr-magnetostatics.hpp:41