DUBeat  1.0.1
High-order discontinuous Galerkin methods and applications to cardiac electrophysiology
volume_handler_DG.hpp
Go to the documentation of this file.
1 /********************************************************************************
2  Copyright (C) 2024 by the DUBeat authors.
3 
4  This file is part of DUBeat.
5 
6  DUBeat is free software; you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  DUBeat is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with DUBeat. If not, see <http://www.gnu.org/licenses/>.
18 ********************************************************************************/
19 
27 #ifndef VOLUME_HANDLER_DG_HPP_
28 #define VOLUME_HANDLER_DG_HPP_
29 
30 #include <deal.II/base/quadrature_lib.h>
31 #include <deal.II/base/tensor.h>
32 
33 #include <deal.II/dofs/dof_handler.h>
34 
35 #include <deal.II/fe/fe.h>
36 #include <deal.II/fe/fe_simplex_p.h>
37 #include <deal.II/fe/fe_values.h>
38 #include <deal.II/fe/mapping_fe.h>
39 
40 #include <cmath>
41 #include <memory>
42 #include <utility>
43 
45 
49 template <unsigned int dim>
51 {
52 protected:
55  const unsigned int n_quad_points_1D;
56 
59 
64  const std::unique_ptr<dealii::FE_SimplexDGP<dim>> fe_dg;
65 
68  const std::unique_ptr<dealii::MappingFE<dim>> mapping;
69 
72 
77  std::unique_ptr<dealii::FEValues<dim>> fe_values;
78 
80  bool initialized = false;
81 
82 public:
84  VolumeHandlerDG<dim>(const unsigned int degree)
85  : n_quad_points_1D(degree + 2)
86  , fe_dg(std::make_unique<dealii::FE_SimplexDGP<dim>>(1))
87  , mapping(std::make_unique<dealii::MappingFE<dim>>(*fe_dg))
89  , fe_values(std::make_unique<dealii::FEValues<dim>>(
90  *mapping,
91  *fe_dg,
92  QGLpoints,
93  dealii::update_inverse_jacobians | dealii::update_quadrature_points |
94  dealii::update_values))
95  {}
96 
99 
102 
105 
107  void
109  const typename dealii::DoFHandler<dim>::active_cell_iterator &new_cell);
110 
113  virtual dealii::Point<dim>
114  quadrature_real(const unsigned int q) const;
115 
118  virtual dealii::Point<dim>
119  quadrature_ref(const unsigned int q) const;
120 
123  virtual double
124  quadrature_weight(const unsigned int q) const;
125 
127  dealii::Tensor<2, dim>
129 
131  unsigned int
133 
135  virtual ~VolumeHandlerDG() = default;
136 };
137 
138 template <unsigned int dim>
139 void
141  const typename dealii::DoFHandler<dim>::active_cell_iterator &new_cell)
142 {
143  cell = new_cell;
144  fe_values->reinit(new_cell);
145  initialized = true;
146 }
147 
148 template <unsigned int dim>
149 dealii::Point<dim>
150 VolumeHandlerDG<dim>::quadrature_real(const unsigned int q) const
151 {
152  AssertThrow(initialized, dealii::StandardExceptions::ExcNotInitialized());
153 
154  AssertThrow(q < pow(n_quad_points_1D, dim),
155  dealii::StandardExceptions::ExcMessage(
156  "Index of quadrature point outside the limit."));
157 
158  return fe_values->quadrature_point(q);
159 }
160 
161 template <unsigned int dim>
162 dealii::Point<dim>
163 VolumeHandlerDG<dim>::quadrature_ref(const unsigned int q) const
164 {
165  AssertThrow(initialized, dealii::StandardExceptions::ExcNotInitialized());
166 
167  AssertThrow(q < pow(n_quad_points_1D, dim),
168  dealii::StandardExceptions::ExcMessage(
169  "Index of quadrature point outside the limit."));
170 
171  return mapping->transform_real_to_unit_cell(cell, quadrature_real(q));
172 }
173 
174 template <unsigned int dim>
175 double
176 VolumeHandlerDG<dim>::quadrature_weight(const unsigned int q) const
177 {
178  AssertThrow(initialized, dealii::StandardExceptions::ExcNotInitialized());
179 
180  AssertThrow(q < pow(n_quad_points_1D, dim),
181  dealii::StandardExceptions::ExcMessage(
182  "Index of quadrature point outside the limit."));
183 
184  return QGLpoints.weight(q);
185 }
186 
187 template <unsigned int dim>
188 dealii::Tensor<2, dim>
190 {
191  AssertThrow(initialized, dealii::StandardExceptions::ExcNotInitialized());
192 
193  dealii::Tensor<2, dim> BJinv;
194 
195  const dealii::DerivativeForm<1, dim, dim> jac_inv =
196  fe_values->inverse_jacobian(0);
197 
198  // We now copy jac_inv in BJinv.
199  for (unsigned int i = 0; i < dim; ++i)
200  {
201  for (unsigned int j = 0; j < dim; ++j)
202  {
203  BJinv[i][j] = jac_inv[i][j];
204  }
205  }
206 
207  return BJinv;
208 }
209 
210 template <unsigned int dim>
211 unsigned int
213 {
214  AssertThrow(initialized, dealii::StandardExceptions::ExcNotInitialized());
215 
216  return fe_values.get_n_quad_points.size();
217 }
218 
219 #endif /* VOLUME_HANDLER_DG_HPP_*/
Class representing the Gauss-Legendre quadrature formula on simplex elements.
Class for the main operations on a discontinuous Galerkin volume element.
const std::unique_ptr< dealii::MappingFE< dim > > mapping
Mapping of the discretized space, needed for geometrical reference-to-actual operations.
const unsigned int n_quad_points_1D
Number of quadrature points in one dimensional elements.
const QGaussLegendreSimplex< dim > QGLpoints
Quadrature formula for volume elements.
const std::unique_ptr< dealii::FE_SimplexDGP< dim > > fe_dg
Internal Lagrangian basis class.
virtual double quadrature_weight(const unsigned int q) const
Return the quadrature weight associated to the -th quadrature point.
std::unique_ptr< dealii::FEValues< dim > > fe_values
Internal FEM basis class.
dealii::DoFHandler< dim >::active_cell_iterator cell
Actual DG cell.
void reinit(const typename dealii::DoFHandler< dim >::active_cell_iterator &new_cell)
Reinit objects on the current new_cell.
virtual dealii::Point< dim > quadrature_ref(const unsigned int q) const
Return the -th spatial quadrature point position on the reference element.
virtual dealii::Point< dim > quadrature_real(const unsigned int q) const
Return the -th spatial quadrature point position on the actual element.
bool initialized
A condition to inform if the class is initialized on an element or not.
unsigned int get_n_quad_points() const
Get the number of quadrature points on the current element.
dealii::Tensor< 2, dim > get_jacobian_inverse() const
Inverse of the Jacobian of the reference-to-actual transformation.
virtual ~VolumeHandlerDG()=default
Destructor.
typename ActiveSelector::active_cell_iterator active_cell_iterator