HArD::Core2D
Hybrid Arbitrary Degree::Core 2D - Library to implement 2D schemes with edge and cell polynomials as unknowns
Loading...
Searching...
No Matches
HHO2D.hpp
Go to the documentation of this file.
1// Helper methods and assemble and solve routines for implementing 2D Hybrid High Order schemes.
2
3#include <basis.hpp>
4#include <Eigen/Sparse>
5#include <Eigen/Dense>
6
7#include <parallel_for.hpp>
8
9//#include <mesh_builder.hpp>
10#include <hybridcore.hpp>
11#include <elementquad.hpp>
12
13#include <TestCase/TestCase.hpp>
15
16#include <boost/timer/timer.hpp>
17#include "vtu_writer.hpp"
18
19#ifndef _HHO2D_HPP
20#define _HHO2D_HPP
21
38// ----------------------------------------------------------------------------
39// HHO2D class definition
40// ----------------------------------------------------------------------------
41
42
43typedef std::function<Eigen::MatrixXd(Cell *, ElementQuad &)> MatrixFType;
44typedef std::function<Eigen::VectorXd(Cell *, ElementQuad &)> VectorFType;
45
46class HHO2D
47{
48public:
52 HHO2D(
53 HybridCore &,
54 const size_t,
55 const size_t,
56 const bool use_threads = true,
57 size_t doeT = 0,
58 size_t doeF = 0
59 );
60
62 void assemble();
63
65 UVector solve();
66
69
71 double energy_norm(const UVector);
72
74 void set_global_operator(const MatrixFType &);
75
77 void set_load_vector(const VectorFType &);
78
80 void plot(
81 const std::string,
82 const UVector &,
83 const FType<double> &
84 );
85
88 const CellFType<double> &
89 );
90
93 const CellFType<double> &,
94 const CellFType<VectorRd> &,
95 const BoundaryConditions &
96 );
97
100 const CellFType<double> &,
101 const FType<double> &,
102 const BoundaryConditions &
103 );
104
106 void set_dirichlet(
107 const FType<double> &,
108 const size_t
109 );
110
112 void set_dirichlet(
113 const size_t
114 );
115
117 inline Eigen::SparseMatrix<double> get_SysMat()
118 {
119 return SysMat;
120 };
121
123 inline double get_assembly_time() const
124 {
125 return double(assembly_time) * pow(10, -9);
126 };
127
129 inline double get_solving_time() const
130 {
131 return double(solving_time) * pow(10, -9);
132 };
133
135 inline double get_solving_error() const
136 {
137 return solving_error;
138 };
139
140private:
141 HybridCore &m_hho;
142 const size_t m_L;
143 const size_t m_K;
144 const bool m_use_threads;
145 size_t m_doeT;
146 size_t m_doeF;
147
148 MatrixFType global_operator;
149 VectorFType load_vector;
150
151 const Mesh *mesh_ptr = m_hho.get_mesh();
152
153 const size_t n_cells = mesh_ptr->n_cells();
154 const size_t n_edges = mesh_ptr->n_edges();
155
156 const size_t n_local_cell_dofs = DimPoly<Cell>(m_L);
157 const size_t n_local_edge_dofs = DimPoly<Edge>(m_K);
158
159 const size_t n_total_cell_dofs = n_local_cell_dofs * n_cells;
160 const size_t n_total_edge_dofs = n_local_edge_dofs * n_edges;
161 const size_t n_total_dofs = n_total_cell_dofs + n_total_edge_dofs;
162
163 double solving_error;
164 size_t solving_time;
165 size_t assembly_time;
166
167 std::vector<Eigen::MatrixXd> AT;
168
169 Eigen::VectorXd GlobRHS = Eigen::VectorXd::Zero(n_total_edge_dofs);
170 Eigen::VectorXd ScRHS = Eigen::VectorXd::Zero(n_total_cell_dofs);
171 Eigen::VectorXd UDir;
172
173 Eigen::SparseMatrix<double> GlobMat;
174 Eigen::SparseMatrix<double> SysMat;
175 Eigen::SparseMatrix<double> ScBeMat;
176};
177
178#endif
std::function< T(const VectorRd &, const Cell *)> CellFType
type for function of a point, that could be discontinuous between cells. T is the type of value of th...
Definition TestCase.hpp:42
The BoundaryConditions class provides definition of boundary conditions.
Definition BoundaryConditions.hpp:45
Definition elementquad.hpp:49
Definition hybridcore.hpp:179
Definition hybridcore.hpp:82
Definition HHO2D.hpp:47
Definition Mesh2D.hpp:26
std::function< T(const VectorRd &)> FType
type for function of point. T is the type of value of the function
Definition basis.hpp:62
void assemble()
A general assemble routine that calculates the statically condensed matrices required by solve.
Definition HHO2D.cpp:219
void set_load_vector(const VectorFType &)
Set the load vector.
Definition HHO2D.cpp:34
std::function< Eigen::VectorXd(Cell *, ElementQuad &)> VectorFType
type for the load vector as a function of a Cell and an ElementQuad
Definition HHO2D.hpp:44
VectorFType standard_load_vector(const CellFType< double > &)
Returns the standard load vector (f, v_T)_T with no Neumann boundary conditions.
Definition HHO2D.cpp:75
std::function< Eigen::MatrixXd(Cell *, ElementQuad &)> MatrixFType
type for the global operator as a function of a Cell and an ElementQuad
Definition HHO2D.hpp:43
double get_solving_time() const
CPU time to solve the scheme.
Definition HHO2D.hpp:129
double get_solving_error() const
Residual after solving the scheme.
Definition HHO2D.hpp:135
void set_global_operator(const MatrixFType &)
Set the global operator.
Definition HHO2D.cpp:26
UVector neumann_solve()
Solves the system when the model is ill posed (not yet running)
double energy_norm(const UVector)
Returns the energy norm of a given UVector.
Definition HHO2D.cpp:368
void set_dirichlet(const FType< double > &, const size_t)
Set the Dirichlet boundary conditions.
Definition HHO2D.cpp:200
Eigen::SparseMatrix< double > get_SysMat()
Return the (statically condensed) matrix system.
Definition HHO2D.hpp:117
void plot(const std::string, const UVector &, const FType< double > &)
Plot the numerical and exact solutions.
Definition HHO2D.cpp:42
double get_assembly_time() const
CPU time to assemble the scheme.
Definition HHO2D.hpp:123
UVector solve()
Solves the statically condensed system.
Definition HHO2D.cpp:312
bool use_threads
Definition HHO_DiffAdvecReac.hpp:47
const size_t DimPoly< Cell >(const int m)
Compute the size of the basis of 2-variate polynomials up to degree m.
Definition hybridcore.hpp:63
const Mesh * get_mesh() const
Returns a pointer to the mesh.
Definition hybridcore.hpp:201
const size_t DimPoly< Edge >(const int m)
Compute the size of the basis of 1-variate polynomials up to degree m.
Definition hybridcore.hpp:70
std::size_t n_cells() const
number of cells in the mesh.
Definition Mesh2D.hpp:63
std::size_t n_edges() const
number of edges in the mesh.
Definition Mesh2D.hpp:61