ExaDG
Loading...
Searching...
No Matches
matrix_free_data.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2021 by the ExaDG authors
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * ______________________________________________________________________
20 */
21
22#ifndef INCLUDE_FUNCTIONALITIES_MATRIX_FREE_DATA_H_
23#define INCLUDE_FUNCTIONALITIES_MATRIX_FREE_DATA_H_
24
25// deal.II
26#include <deal.II/base/quadrature.h>
27#include <deal.II/distributed/tria.h>
28#include <deal.II/dofs/dof_handler.h>
29#include <deal.II/lac/affine_constraints.h>
30#include <deal.II/matrix_free/matrix_free.h>
31
32// ExaDG
33#include <exadg/matrix_free/categorization.h>
34#include <exadg/operators/mapping_flags.h>
35
36namespace ExaDG
37{
38template<int dim, typename Number>
40{
41public:
46 {
47 data.tasks_parallel_scheme = dealii::MatrixFree<dim, Number>::AdditionalData::none;
48 }
49
54 template<typename Operator>
55 void
56 append(std::shared_ptr<Operator> pde_operator)
57 {
58 pde_operator->fill_matrix_free_data(*this);
59 }
60
61 std::vector<dealii::DoFHandler<dim> const *> const &
62 get_dof_handler_vector() const
63 {
64 return dof_handler_vec;
65 }
66
67 std::vector<dealii::AffineConstraints<Number> const *> const &
68 get_constraint_vector() const
69 {
70 return constraint_vec;
71 }
72
73 std::vector<dealii::Quadrature<dim>> const &
74 get_quadrature_vector() const
75 {
76 return quadrature_vec;
77 }
78
79 dealii::DoFHandler<dim> const &
80 get_dof_handler(std::string const & name) const
81 {
82 return *dof_handler_vec.at(get_dof_index(name));
83 }
84
85 void
86 append_mapping_flags(MappingFlags const & flags_other)
87 {
88 MappingFlags flags;
89
90 flags.cells = this->data.mapping_update_flags;
91 flags.inner_faces = this->data.mapping_update_flags_inner_faces;
92 flags.boundary_faces = this->data.mapping_update_flags_boundary_faces;
93
94 // append
95 flags = flags || flags_other;
96
97 this->data.mapping_update_flags = flags.cells;
98 this->data.mapping_update_flags_inner_faces = flags.inner_faces;
99 this->data.mapping_update_flags_boundary_faces = flags.boundary_faces;
100 }
101
102 void
103 insert_dof_handler(dealii::DoFHandler<dim> const * dof_handler, std::string const & name)
104 {
105 insert_element(dof_handler_vec, dof_index_map, dof_handler, name);
106 }
107
108 void
109 insert_constraint(dealii::AffineConstraints<Number> const * constraint, std::string const & name)
110 {
111 insert_element(constraint_vec, constraint_index_map, constraint, name);
112 }
113
114 template<int dim_quad>
115 void
116 insert_quadrature(dealii::Quadrature<dim_quad> const & quadrature, std::string const & name)
117 {
118 insert_element(quadrature_vec, quad_index_map, dealii::Quadrature<dim>(quadrature), name);
119 }
120
121 unsigned int
122 get_dof_index(std::string const & name) const
123 {
124 return get_index(dof_index_map, name);
125 }
126
127 unsigned int
128 get_constraint_index(std::string const & name) const
129 {
130 return get_index(constraint_index_map, name);
131 }
132
133 unsigned int
134 get_quad_index(std::string const & name) const
135 {
136 return get_index(quad_index_map, name);
137 }
138
139 // additional data
140 typename dealii::MatrixFree<dim, Number>::AdditionalData data;
141
142private:
143 template<typename T>
144 void
145 insert_element(std::vector<T> & vector,
146 std::map<std::string, unsigned int> & map,
147 T const & element,
148 std::string const & name)
149 {
150 unsigned int index = vector.size();
151
152 auto it = map.find(name);
153
154 // make sure that this element does not already exist
155 if(it == map.end())
156 {
157 map.insert(std::pair<std::string, unsigned int>(name, index));
158 }
159 else
160 {
161 AssertThrow(it == map.end(), dealii::ExcMessage("Element already exists. Aborting."));
162 }
163
164 vector.resize(index + 1);
165 vector.at(index) = element;
166 }
167
168 unsigned int
169 get_index(std::map<std::string, unsigned int> const & map, std::string const & name) const
170 {
171 auto it = map.find(name);
172
173 unsigned int index = dealii::numbers::invalid_unsigned_int;
174
175 if(it != map.end())
176 {
177 index = it->second;
178 }
179 else
180 {
181 AssertThrow(it != map.end(), dealii::ExcMessage("Could not find element. Aborting."));
182 }
183
184 return index;
185 }
186
187 // maps between names and indices for dealii::DoFHandler, Constraint, dealii::Quadrature
188 std::map<std::string, unsigned int> dof_index_map;
189 std::map<std::string, unsigned int> constraint_index_map;
190 std::map<std::string, unsigned int> quad_index_map;
191
192 // collection of data structures required for initialization and update of matrix_free
193 std::vector<dealii::DoFHandler<dim> const *> dof_handler_vec;
194 std::vector<dealii::AffineConstraints<Number> const *> constraint_vec;
195 std::vector<dealii::Quadrature<dim>> quadrature_vec;
196};
197} // namespace ExaDG
198
199#endif /* INCLUDE_FUNCTIONALITIES_MATRIX_FREE_DATA_H_ */
Definition driver.cpp:33
Definition matrix_free_data.h:40
void append(std::shared_ptr< Operator > pde_operator)
Definition matrix_free_data.h:56
MatrixFreeData()
Definition matrix_free_data.h:45