DiFfRG
Loading...
Searching...
No Matches
cg.hh
Go to the documentation of this file.
1#pragma once
2
3// external libraries
4#include <deal.II/base/point.h>
5#include <deal.II/dofs/dof_handler.h>
6#include <deal.II/dofs/dof_renumbering.h>
7#include <deal.II/dofs/dof_tools.h>
8#include <deal.II/fe/fe_q.h>
9#include <deal.II/fe/fe_system.h>
10#include <deal.II/fe/mapping_q1.h>
11#include <deal.II/lac/affine_constraints.h>
12#include <spdlog/spdlog.h>
13
14// DiFfRG
17
18namespace DiFfRG
19{
20 namespace CG
21 {
22 using namespace dealii;
23
30 template <typename Components_, typename NumberType_, typename Mesh_> class Discretization
31 {
32 public:
33 using Components = Components_;
34 using NumberType = NumberType_;
35 using VectorType = Vector<NumberType>;
36 using SparseMatrixType = SparseMatrix<NumberType>;
37 using Mesh = Mesh_;
38 static constexpr uint dim = Mesh::dim;
39
41 : mesh(mesh), json(json),
42 fe(std::make_shared<FESystem<dim>>(FE_Q<dim>(json.get_uint("/discretization/fe_order")),
43 Components::count_fe_functions(0))),
45 {
46 setup_dofs();
47 };
48
49 const auto &get_constraints(const uint i = 0) const
50 {
51 (void)i;
52 return constraints;
53 }
54 auto &get_constraints(const uint i = 0)
55 {
56 (void)i;
57 return constraints;
58 }
59 const auto &get_dof_handler(const uint i = 0) const
60 {
61 (void)i;
62 return dof_handler;
63 }
64 auto &get_dof_handler(const uint i = 0)
65 {
66 (void)i;
67 return dof_handler;
68 }
69 const auto &get_fe(const uint i = 0) const
70 {
71 if (i != 0) throw std::runtime_error("Wrong FE index");
72 return *fe;
73 }
74 const auto &get_mapping() const { return mapping; }
75 const auto &get_triangulation() const { return mesh.get_triangulation(); }
76 auto &get_triangulation() { return mesh.get_triangulation(); }
77 const Point<dim> &get_support_point(const uint dof) const { return support_points[dof]; }
78 const auto &get_support_points() const { return support_points; }
79 const auto &get_json() const { return json; }
80
81 void reinit() { setup_dofs(); }
82
83 std::vector<uint> get_block_structure() const
84 {
85 std::vector<uint> block_structure{dof_handler.n_dofs()};
86 if (Components::count_variables() > 0) block_structure.push_back(Components::count_variables());
87 return block_structure;
88 }
89
90 protected:
92 {
93 dof_handler.distribute_dofs(*fe);
94 // DoFRenumbering::component_wise(dof_handler);
95
96 spdlog::get("log")->info("FEM: Number of active cells: {}", mesh.get_triangulation().n_active_cells());
97 spdlog::get("log")->info("FEM: Number of degrees of freedom: {}", dof_handler.n_dofs());
98
99 constraints.clear();
100 DoFTools::make_hanging_node_constraints(dof_handler, constraints);
101 constraints.close();
102
103 support_points.resize(dof_handler.n_dofs());
104 DoFTools::map_dofs_to_support_points(mapping, dof_handler, support_points);
105 }
106
109
110 std::shared_ptr<FESystem<dim>> fe;
111 DoFHandler<dim> dof_handler;
112 AffineConstraints<NumberType> constraints;
113 MappingQ1<dim> mapping;
114 std::vector<Point<dim>> support_points;
115 };
116 } // namespace CG
117} // namespace DiFfRG
Class to manage the system on which we solve, i.e. fe spaces, grids, etc. This class is a System for ...
Definition cg.hh:31
Mesh & mesh
Definition cg.hh:107
AffineConstraints< NumberType > constraints
Definition cg.hh:112
MappingQ1< dim > mapping
Definition cg.hh:113
NumberType_ NumberType
Definition cg.hh:34
const auto & get_constraints(const uint i=0) const
Definition cg.hh:49
Components_ Components
Definition cg.hh:33
auto & get_dof_handler(const uint i=0)
Definition cg.hh:64
SparseMatrix< NumberType > SparseMatrixType
Definition cg.hh:36
auto & get_constraints(const uint i=0)
Definition cg.hh:54
std::vector< Point< dim > > support_points
Definition cg.hh:114
const auto & get_fe(const uint i=0) const
Definition cg.hh:69
auto & get_triangulation()
Definition cg.hh:76
JSONValue json
Definition cg.hh:108
const auto & get_support_points() const
Definition cg.hh:78
void reinit()
Definition cg.hh:81
std::vector< uint > get_block_structure() const
Definition cg.hh:83
const auto & get_json() const
Definition cg.hh:79
const auto & get_mapping() const
Definition cg.hh:74
void setup_dofs()
Definition cg.hh:91
Vector< NumberType > VectorType
Definition cg.hh:35
static constexpr uint dim
Definition cg.hh:38
std::shared_ptr< FESystem< dim > > fe
Definition cg.hh:110
Mesh_ Mesh
Definition cg.hh:37
Discretization(Mesh &mesh, const JSONValue &json)
Definition cg.hh:40
const auto & get_dof_handler(const uint i=0) const
Definition cg.hh:59
const Point< dim > & get_support_point(const uint dof) const
Definition cg.hh:77
const auto & get_triangulation() const
Definition cg.hh:75
DoFHandler< dim > dof_handler
Definition cg.hh:111
A wrapper around the boost json value class.
Definition json.hh:19
Definition complex_math.hh:14
unsigned int uint
Definition utils.hh:22
Definition tuples.hh:117