HArD::Core3D
Hybrid Arbitrary Degree::Core 3D - Library to implement 3D schemes with vertex, edge, face and cell polynomials as unknowns
HHO3D.hpp
Go to the documentation of this file.
1 // Helper methods and assemble and solve routines for implementing 3D 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 #ifndef _HHO3D_HPP
19 #define _HHO3D_HPP
20 
31 // ----------------------------------------------------------------------------
32 // HHO3D class definition
33 // ----------------------------------------------------------------------------
34 
41 typedef std::function<Eigen::MatrixXd(Cell *, ElementQuad &)> MatrixFType;
42 typedef std::function<Eigen::VectorXd(Cell *, ElementQuad &)> VectorFType;
43 
44 class HHO3D
45 {
46 public:
50  HHO3D(
51  HybridCore &,
52  const size_t,
53  const size_t,
54  const bool use_threads = true,
55  size_t doeT = 0,
56  size_t doeF = 0
57  );
58 
60  void assemble();
61 
63  UVector solve();
64 
67 
69  double energy_norm(const UVector);
70 
72  void set_global_operator(const MatrixFType &);
73 
75  void set_load_vector(const VectorFType &);
76 
78  void plot(
79  const std::string,
80  const UVector &,
81  const FType<double> &
82  );
83 
86  const CellFType<double> &
87  );
88 
91  const CellFType<double> &,
92  const CellFType<VectorRd> &,
93  const BoundaryConditions &
94  );
95 
98  const CellFType<double> &,
99  const FType<double> &,
100  const BoundaryConditions &
101  );
102 
104  void set_dirichlet(
105  const FType<double> &,
106  const size_t
107  );
108 
110  void set_dirichlet(
111  const size_t
112  );
113 
115  inline Eigen::SparseMatrix<double> get_SysMat()
116  {
117  return SysMat;
118  };
119 
121  inline double get_assembly_time() const
122  {
123  return double(assembly_time) * pow(10, -9);
124  };
125 
127  inline double get_solving_time() const
128  {
129  return double(solving_time) * pow(10, -9);
130  };
131 
133  inline double get_solving_error() const
134  {
135  return solving_error;
136  };
137 
138 private:
139  HybridCore &m_hho;
140  const size_t m_L;
141  const size_t m_K;
142  const bool m_use_threads;
143  size_t m_doeT;
144  size_t m_doeF;
145 
146  MatrixFType global_operator;
147  VectorFType load_vector;
148 
149  const Mesh *mesh_ptr = m_hho.get_mesh();
150 
151  const size_t n_cells = mesh_ptr->n_cells();
152  const size_t n_faces = mesh_ptr->n_faces();
153 
154  const size_t n_local_cell_dofs = DimPoly<Cell>(m_L);
155  const size_t n_local_face_dofs = DimPoly<Face>(m_K);
156 
157  const size_t n_total_cell_dofs = n_local_cell_dofs * n_cells;
158  const size_t n_total_face_dofs = n_local_face_dofs * n_faces;
159  const size_t n_total_dofs = n_total_cell_dofs + n_total_face_dofs;
160 
161  double solving_error;
162  size_t solving_time;
163  size_t assembly_time;
164 
165  std::vector<Eigen::MatrixXd> AT;
166 
167  Eigen::VectorXd GlobRHS = Eigen::VectorXd::Zero(n_total_face_dofs);
168  Eigen::VectorXd ScRHS = Eigen::VectorXd::Zero(n_total_cell_dofs);
169  Eigen::VectorXd UDir;
170 
171  Eigen::SparseMatrix<double> GlobMat;
172  Eigen::SparseMatrix<double> SysMat;
173  Eigen::SparseMatrix<double> ScBeMat;
174 };
175 
176 #endif
The BoundaryConditions class provides definition of boundary conditions.
Definition: BoundaryConditions.hpp:43
Definition: elementquad.hpp:55
Definition: hybridcore.hpp:174
Definition: hybridcore.hpp:87
Definition: HHO3D.hpp:45
Class to describe a mesh.
Definition: MeshND.hpp:17
std::function< T(const VectorRd &, const Cell *)> CellFType
type for function of point. T is the return type of the function
Definition: basis.hpp:57
std::function< T(const VectorRd &)> FType
type for function of point. T is the return type of the function
Definition: basis.hpp:54
std::function< Eigen::VectorXd(Cell *, ElementQuad &)> VectorFType
type for the load vector as a function of a Cell and an ElementQuad
Definition: HHO3D.hpp:42
void set_dirichlet(const FType< double > &, const size_t)
Set the Dirichlet boundary conditions.
Definition: HHO3D.cpp:166
double get_solving_error() const
Residual after solving the scheme.
Definition: HHO3D.hpp:133
std::function< Eigen::MatrixXd(Cell *, ElementQuad &)> MatrixFType
type for the global operator as a function of a Cell and an ElementQuad
Definition: HHO3D.hpp:41
double get_assembly_time() const
CPU time to assemble the scheme.
Definition: HHO3D.hpp:121
void set_load_vector(const VectorFType &)
Set the load vector.
Definition: HHO3D.cpp:27
void plot(const std::string, const UVector &, const FType< double > &)
Plot the numerical and exact solutions.
Definition: HHO3D.cpp:34
UVector solve()
Solves the statically condensed system.
Definition: HHO3D.cpp:270
UVector neumann_solve()
Solves the system when the model is ill posed (not yet running)
void assemble()
A general assemble routine that calculates the statically condensed matrices required by solve.
Definition: HHO3D.cpp:184
double energy_norm(const UVector)
Returns the energy norm of a given UVector.
Definition: HHO3D.cpp:319
Eigen::SparseMatrix< double > get_SysMat()
Return the (statically condensed) matrix system.
Definition: HHO3D.hpp:115
HHO3D(HybridCore &, const size_t, const size_t, const bool use_threads=true, size_t doeT=0, size_t doeF=0)
Class constructor: initialises the model by providing a HybridCore object, and the exact solution and...
Definition: HHO3D.cpp:3
double get_solving_time() const
CPU time to solve the scheme.
Definition: HHO3D.hpp:127
void set_global_operator(const MatrixFType &)
Set the global operator.
Definition: HHO3D.cpp:20
VectorFType standard_load_vector(const CellFType< double > &)
Returns the standard load vector (f, v_T)_T with no Neumann boundary conditions.
Definition: HHO3D.cpp:65
bool use_threads
Definition: HHO_DiffAdvecReac.hpp:47
const size_t DimPoly< Face >(const int m)
Compute the size of the basis of 2-variate polynomials up to degree m.
Definition: hybridcore.hpp:68
const size_t DimPoly< Cell >(const int m)
Compute the size of the basis of 3-variate polynomials up to degree m.
Definition: hybridcore.hpp:61
const Mesh * get_mesh() const
Returns a pointer to the mesh.
Definition: hybridcore.hpp:198
std::size_t n_faces() const
number of faces in the mesh.
Definition: MeshND.hpp:59
std::size_t n_cells() const
number of cells in the mesh.
Definition: MeshND.hpp:60
MeshND::Cell< 2 > Cell
Definition: Mesh2D.hpp:13