HArD::Core2D
Hybrid Arbitrary Degree::Core 2D - Library to implement 2D schemes with edge and cell polynomials as unknowns
Loading...
Searching...
No Matches
bgg-klplate.hpp
Go to the documentation of this file.
1// Implementation of the DDR-BGG scheme for the Kirchhoff-Love plate problem.
2//
3// Author: Arax Leroy (arax.leroy@umontpellier.fr)
4//
5
6
7#ifndef BGG_KLPLATE_HPP
8#define BGG_KLPLATE_HPP
9
10#include <iostream>
11
12#include <boost/math/constants/constants.hpp>
13
14#include <Eigen/Sparse>
15#include <unsupported/Eigen/SparseExtra>
16
17#include <mesh.hpp>
18#include <BoundaryConditions/BoundaryConditions.hpp> // To re-order the boundary edges and vertices
20
21#include <vsxgrad.hpp>
22#include <xhess.hpp>
23
29namespace HArDCore2D
30{
31
38 struct KLNorms
39 {
41 KLNorms(double norm_displacement):
42 displacement(norm_displacement),
43 energy(norm_displacement)
44 {
45 // do nothing
46 };
47 double displacement;
48 double energy;
49 };
50
53 {
54 typedef Eigen::SparseMatrix<double> SystemMatrixType;
55 typedef std::function<double(const Eigen::Vector2d &)> ForcingTermType;
56 typedef std::function<double(const Eigen::Vector2d &)> SolutionDisplacementType;
57 typedef std::function<Eigen::Vector2d(const Eigen::Vector2d&)> GradientDisplacementType;
58
59
62 const DDRCore & ddrcore,
63 const DDRCore & ddrcore_plus,
64 const SerendipityProblem & sp,
65 const SerendipityProblem & sp_plus,
66 const BoundaryConditions & BC_u,
67 bool use_threads,
68 std::ostream & output = std::cout
69 );
70
73 const ForcingTermType & f,
74 const SolutionDisplacementType & u,
75 const GradientDisplacementType & grad_u,
76 size_t iT_dirac
77 );
78
80 inline size_t dimensionSpace() const
81 {
82 return m_xhess.dimension();
83 }
84
86 inline size_t nb_bdryDOFs() const
87 {
88 return m_BC_u.n_dir_edges() * m_xhess.numLocalDofsEdge()
89 + m_BC_u.n_dir_vertices() * m_xhess.numLocalDofsVertex();
90 }
91
93 inline size_t sizeSystem() const
94 {
95 return dimensionSpace() - nb_bdryDOFs();
96 }
97
99 inline const std::vector<std::pair<size_t,size_t>> & locUKN() const {
100 return m_locUKN;
101 }
102
104 std::vector<size_t> globalDOFIndices(const Cell &T) const
105 {
106 return m_xhess.globalDOFIndices(T);
107 }
108
110 inline const VSXGrad & vsxGrad() const
111 {
112 return m_vsxgrad;
113 }
114
116 inline const XHess & xHess() const
117 {
118 return m_xhess;
119 }
120
122 inline const SystemMatrixType & systemMatrix() const {
123 return m_A;
124 }
125
128 return m_A;
129 }
130
132 inline const Eigen::VectorXd & systemVector() const {
133 return m_b;
134 }
135
137 inline Eigen::VectorXd & systemVector() {
138 return m_b;
139 }
140
142 inline const SystemMatrixType & bdryMatrix() const {
143 return m_bdryMatrix;
144 }
145
147 inline const Eigen::VectorXd & bdryValues() const {
148 return m_bdryValues;
149 }
150
152 inline const double & stabilizationParameter() const {
153 return m_stab_par;
154 }
155
157 inline double & stabilizationParameter() {
158 return m_stab_par;
159 }
160
163 const Eigen::VectorXd & v
164 ) const;
165
167 template<typename outValue, typename Fct>
168 std::function<outValue(const Eigen::Vector2d &)> contractPara(const Fct &F) const
169 {
170 std::function<outValue(const Eigen::Vector2d &)> f = [this, &F](const Eigen::Vector2d &x)->outValue { return F(x);};
171 return f;
172 }
173
174 private:
176 std::pair<Eigen::MatrixXd, Eigen::VectorXd>
177 _compute_local_contribution(
178 size_t iT,
179 const ForcingTermType & f,
180 size_t iT_dirac
181 );
182
183
185
187 void _assemble_local_contribution(
188 size_t iT,
189 const std::pair<Eigen::MatrixXd, Eigen::VectorXd> & lsT,
190 std::list<Eigen::Triplet<double> > & A1,
191 Eigen::VectorXd & b1,
192 std::list<Eigen::Triplet<double> > & A2
193 );
194
195 const DDRCore & m_ddrcore;
196 bool m_use_threads;
197 std::ostream & m_output;
198 VSXGrad m_vsxgrad;
199 XHess m_xhess;
200 BoundaryConditions m_BC_u;
201 SystemMatrixType m_bdryMatrix; // Matrix with columns corresponding to Dirichlet DOFs; multiplied by the boundary values, yields the modification to the system RHS for non-homogeneous BC
202 Eigen::VectorXd m_bdryValues; // Boundary values
203 SystemMatrixType m_A; // Matrix and RHS for system (after removing Dirichlet DOFs)
204 Eigen::VectorXd m_b;
205 double m_stab_par;
206 std::vector<std::pair<size_t,size_t>> m_locUKN; // Indicates the location, among the DOFs, of the unknowns after the Dirichlet DOFs are removed (the unknowns are between m_locUCK[i].first and m_locUCK[i].first+m_locUKN[i].second for all i)
207 Eigen::VectorXi m_DOFtoUKN; // Maps a dof i to its unknown in the system without BC, or to -1 if the DOF is a Dirichlet DOF
208 };
209
210 //------------------------------------------------------------------------------
211 // Exact solutions
212 //------------------------------------------------------------------------------
213
214 static const double PI = boost::math::constants::pi<double>();
215 using std::sin;
216 using std::cos;
217 using std::exp;
218 using std::pow;
219
220 //------------------------------------------------------------------------------
221 // Constant
223 constant_u = [](const VectorRd & x) -> double {
224 return 1.;
225 };
226
228 constant_grad_u = [](const VectorRd & /*x*/) -> VectorRd{
229 return VectorRd::Zero();
230 };
231
233 constant_f = [](const VectorRd & x) -> double {
234 return 0.;
235 };
236
237 //------------------------------------------------------------------------------
238 // Polynomial
239
241 polynomial_u = [](const VectorRd & x) -> double {
242 return pow(x(0), 5) + pow(x(1), 5);
243 };
244
247 VectorRd grad;
248 grad(0) = 5.0 * pow(x(0), 4);
249 grad(1) = 5.0 * pow(x(1), 4);
250 return grad;
251 };
252
254 polynomial_f = [](const VectorRd & x) -> double {
255 return 120. * (x(0) + x(1));
256 };
257
258//------------------------------------------------------------------------------
259// Trigonometric solution
260
262trigo_u = [](const VectorRd & x) -> double {
263 return std::sin(M_PI * x(0)) * std::sin(M_PI * x(1));
264};
265
267trigo_grad_u = [](const VectorRd & x) -> VectorRd {
268 VectorRd grad;
269 grad(0) = M_PI * std::cos(M_PI * x(0)) * std::sin(M_PI * x(1));
270 grad(1) = M_PI * std::sin(M_PI * x(0)) * std::cos(M_PI * x(1));
271 return grad;
272};
273
275trigo_f = [](const VectorRd & x) -> double {
276 double u = std::sin(M_PI * x(0)) * std::sin(M_PI * x(1));
277 return 4.0 * std::pow(M_PI, 4) * u;
278};
279
280//------------------------------------------------------------------------------
281// Dirac function f
282
284dirac_u = [](const VectorRd & x) -> double {
285 return 1.0;
286};
287
289dirac_grad_u = [](const VectorRd & x) -> VectorRd {
290 VectorRd grad;
291 grad(0) = 0.0;
292 grad(1) = 0.0;
293 return grad;
294};
295
296// static KirchhoffLove::ForcingTermType
297// dirac_f = [](const VectorRd & x) -> double {
298// return 0.0;
299// };
300
301//Dirac-like solution
303dirac_f = [](const VectorRd & x) -> double {
304 const double rayon = 1e-2;
305 const VectorRd center(0.3, 0.7);
306
307 if ((x - center).squaredNorm() < rayon*rayon) {
308 return 1.0 / (M_PI*rayon*rayon); // to normalise //
309 } else {
310 return 0.0;
311 }
312};
313} // end of namespace HArDCore2D
314
315#endif
The BoundaryConditions class provides definition of boundary conditions.
Definition BoundaryConditions.hpp:45
const size_t n_dir_vertices() const
Returns the number of Dirichlet vertices.
Definition BoundaryConditions.hpp:75
const size_t n_dir_edges() const
Returns the number of Dirichlet edges.
Definition BoundaryConditions.hpp:70
Construct all polynomial spaces for the DDR sequence.
Definition ddrcore.hpp:63
Construct all polynomial spaces for the DDR sequence.
Definition serendipity_problem.hpp:20
Vector version of sXgrad, the arbitrary order space with nodal primal unknowns.
Definition vsxgrad.hpp:32
Discrete H2 space: local operators, L2 product and global interpolator.
Definition xhess.hpp:21
Create grid points x
Definition generate_cartesian_mesh.m:22
Eigen::VectorXd & systemVector()
Returns the linear system right-hand side vector.
Definition bgg-klplate.hpp:137
std::function< Eigen::Vector2d(const Eigen::Vector2d &)> GradientDisplacementType
Definition bgg-klplate.hpp:57
const Eigen::VectorXd & bdryValues() const
Returns the boundary values.
Definition bgg-klplate.hpp:147
double & stabilizationParameter()
Returns the stabilization parameter.
Definition bgg-klplate.hpp:157
const std::vector< std::pair< size_t, size_t > > & locUKN() const
Returns the location of the unknowns among the DOFs.
Definition bgg-klplate.hpp:99
KLNorms computeNorms(const Eigen::VectorXd &v) const
Compute the discrete norms: displacement,and energy.
Definition bgg-klplate.cpp:500
std::vector< size_t > globalDOFIndices(const Cell &T) const
Create the vector of DOF indices for cell T, which combines the DOFs for the spaces VSXgrad and Xhess...
Definition bgg-klplate.hpp:104
const SystemMatrixType & bdryMatrix() const
Returns the Matrix for BC.
Definition bgg-klplate.hpp:142
static KirchhoffLove::GradientDisplacementType dirac_grad_u
Definition bgg-klplate.hpp:289
size_t nb_bdryDOFs() const
Returns the nb of DOFs for BC.
Definition bgg-klplate.hpp:86
static KirchhoffLove::SolutionDisplacementType constant_u
Definition bgg-klplate.hpp:223
void assembleLinearSystem(const ForcingTermType &f, const SolutionDisplacementType &u, const GradientDisplacementType &grad_u, size_t iT_dirac)
Assemble the global system
Definition bgg-klplate.cpp:312
std::function< outValue(const Eigen::Vector2d &)> contractPara(const Fct &F) const
Takes a function dependent on KLParameter and a position x, and returns a function depending only on ...
Definition bgg-klplate.hpp:168
static KirchhoffLove::GradientDisplacementType polynomial_grad_u
Definition bgg-klplate.hpp:246
const XHess & xHess() const
Returns the space XHess.
Definition bgg-klplate.hpp:116
static KirchhoffLove::SolutionDisplacementType trigo_u
Definition bgg-klplate.hpp:262
Eigen::SparseMatrix< double > SystemMatrixType
Definition bgg-klplate.hpp:54
static const double PI
Definition bgg-klplate.hpp:214
std::function< double(const Eigen::Vector2d &)> ForcingTermType
Definition bgg-klplate.hpp:55
const SystemMatrixType & systemMatrix() const
Returns the linear system matrix.
Definition bgg-klplate.hpp:122
const Eigen::VectorXd & systemVector() const
Returns the linear system right-hand side vector.
Definition bgg-klplate.hpp:132
SystemMatrixType & systemMatrix()
Returns the linear system matrix.
Definition bgg-klplate.hpp:127
static KirchhoffLove::ForcingTermType constant_f
Definition bgg-klplate.hpp:233
static KirchhoffLove::ForcingTermType polynomial_f
Definition bgg-klplate.hpp:254
std::function< double(const Eigen::Vector2d &)> SolutionDisplacementType
Definition bgg-klplate.hpp:56
double displacement
Norm of displacement.
Definition bgg-klplate.hpp:47
size_t sizeSystem() const
Returns the size of the system without BC.
Definition bgg-klplate.hpp:93
KLNorms(double norm_displacement)
Constructor.
Definition bgg-klplate.hpp:41
const VSXGrad & vsxGrad() const
Returns the space VSXGrad.
Definition bgg-klplate.hpp:110
static KirchhoffLove::GradientDisplacementType constant_grad_u
Definition bgg-klplate.hpp:228
static KirchhoffLove::ForcingTermType dirac_f
Definition bgg-klplate.hpp:303
double energy
Total energy.
Definition bgg-klplate.hpp:48
const double & stabilizationParameter() const
Returns the stabilization parameter.
Definition bgg-klplate.hpp:152
static KirchhoffLove::SolutionDisplacementType polynomial_u
Definition bgg-klplate.hpp:241
static KirchhoffLove::GradientDisplacementType trigo_grad_u
Definition bgg-klplate.hpp:267
static KirchhoffLove::SolutionDisplacementType dirac_u
Definition bgg-klplate.hpp:284
size_t dimensionSpace() const
Returns the dimension of the rotation + displacement space (with BC)
Definition bgg-klplate.hpp:80
static KirchhoffLove::ForcingTermType trigo_f
Definition bgg-klplate.hpp:275
Eigen::Vector2d VectorRd
Definition basis.hpp:55
std::vector< size_t > globalDOFIndices(const Cell &T) const
Definition globaldofspace.cpp:98
size_t numLocalDofsVertex() const
Returns the number of local vertex DOFs.
Definition localdofspace.hpp:39
size_t dimension() const
Returns the dimension of the global space (all DOFs for all geometric entities)
Definition localdofspace.hpp:61
size_t numLocalDofsEdge() const
Returns the number of local edge DOFs.
Definition localdofspace.hpp:45
bool use_threads
Definition HHO_DiffAdvecReac.hpp:45
if(strcmp(field, 'real')) % real valued entries T
Definition mmread.m:93
Definition bgg-klplate.hpp:30
static auto v
Definition ddrcore-test.hpp:32
Structure to store component norms (displacement total energy)
Definition bgg-klplate.hpp:39
Assemble a RM problem.
Definition bgg-klplate.hpp:53