27 #ifndef DOF_HANDLER_DG_HPP_
28 #define DOF_HANDLER_DG_HPP_
30 #include <deal.II/base/quadrature.h>
32 #include <deal.II/dofs/dof_handler.h>
34 #include <deal.II/fe/fe.h>
35 #include <deal.II/fe/mapping_q1_eulerian.h>
37 #include <deal.II/lac/trilinos_vector.h>
44 #include "source/init.hpp"
48 Iterators<lifex::dim, lifex::dim, false>;
64 template <
class basis>
72 std::map<active_cell_iterator, std::vector<unsigned int>>
dof_map;
77 : dealii::DoFHandler<lifex::dim>()
110 std::vector<lifex::types::global_dof_index>
119 template <
class basis>
123 AssertThrow(degree > 0,
124 dealii::StandardExceptions::ExcMessage(
125 "Dofs have not been distributed yet. Please, use "
126 "distribute_dofs before."));
132 unsigned int denominator = 1;
133 unsigned int nominator = 1;
135 for (
unsigned int i = 1; i <= lifex::dim; i++)
138 nominator *= degree + i;
141 return (
int)(nominator / denominator);
144 template <
class basis>
148 AssertThrow(degree > 0,
149 dealii::StandardExceptions::ExcMessage(
150 "Dofs have not been distributed yet. Please, use "
151 "distribute_dofs before."));
153 unsigned int n_cells = 0;
155 for (
const auto &cell : this->active_cell_iterators())
160 return n_cells * n_dofs_per_cell();
169 const dealii::FE_SimplexDGP<lifex::dim> &fe)
171 AssertThrow(fe.degree < 3,
172 dealii::StandardExceptions::ExcMessage(
173 "deal.II library does not provide yet FEM spaces with "
174 "polynomial order > 2."));
176 dealii::DoFHandler<lifex::dim>::distribute_dofs(fe);
185 const dealii::FE_SimplexDGP<lifex::dim> &fe)
187 AssertThrow(fe.degree < 3,
188 dealii::StandardExceptions::ExcMessage(
189 "deal.II library does not provide yet FEM spaces with "
190 "polynomial order > 2."));
191 dealii::DoFHandler<lifex::dim>::distribute_dofs(fe);
194 std::vector<lifex::types::global_dof_index> dof_indices(
195 this->n_dofs_per_cell());
198 for (
const auto &cell : this->active_cell_iterators())
201 cell->get_dof_indices(dof_indices);
202 dof_map.emplace(cell, dof_indices);
211 const unsigned int degree)
215 dealii::StandardExceptions::ExcMessage(
216 "deal.II library does not provide yet the Lagrangian DG basis with "
217 "polynomial order > 2."));
218 dealii::FE_SimplexDGP<lifex::dim> fe(degree);
219 this->distribute_dofs(fe);
231 this->degree = degree;
232 unsigned int n_dofs_per_cell = this->n_dofs_per_cell();
235 for (
const auto &cell : this->active_cell_iterators())
237 std::vector<unsigned int> local_dofs;
239 for (
unsigned int i = 0; i < n_dofs_per_cell; ++i)
240 local_dofs.push_back(
n + i);
242 dof_map.emplace(cell, local_dofs);
244 n =
n + n_dofs_per_cell;
251 std::vector<lifex::types::global_dof_index>
255 std::vector<lifex::types::global_dof_index> dof_indices(
256 this->n_dofs_per_cell());
257 cell->get_dof_indices(dof_indices);
265 std::vector<lifex::types::global_dof_index>
269 std::vector<lifex::types::global_dof_index> dof_indices(
270 this->n_dofs_per_cell());
271 dof_indices = dof_map.at(cell);
275 template <
class basis>
279 dealii::IndexSet owned_dofs(this->n_dofs());
281 owned_dofs.add_range(0, this->n_dofs());
Class to work with global and local degrees of freedom and their mapping.
void distribute_dofs(const dealii::FE_SimplexDGP< lifex::dim > &fe)
Distribute dofs through the elements.
void distribute_dofs(const unsigned int degree)
Same method but avoids to use FiniteElement classes that might be invalid with higher order polynomia...
unsigned int n_dofs() const
Return copy of n_dofs.
std::vector< lifex::types::global_dof_index > get_dof_indices(active_cell_iterator cell) const
Returns the global dofs referred to the input cell.
unsigned int n_dofs_per_cell() const
Return copy of n_dofs_per_cell.
unsigned int degree
Polynomial space degree.
std::map< active_cell_iterator, std::vector< unsigned int > > dof_map
Local to global dof map.
dealii::IndexSet locally_owned_dofs() const
Return a set of all the locally owned dofs (for the time being, it is equivalent to return all the do...
typename ActiveSelector::active_cell_iterator active_cell_iterator
dealii::internal::DoFHandlerImplementation::Iterators< lifex::dim, lifex::dim, false > ActiveSelector