Debian Codegraph @

include/deal.II/matrix_free/mapping_info_storage.templates.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2021 - 2023 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // Part of the source code is dual licensed under Apache-2.0 WITH
9 // LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10 // governing the source code and code contributions can be found in
11 // LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12 //
13 // ------------------------------------------------------------------------
14
15 #ifndef dealii_matrix_free_mapping_info_storage_templates_h
16 #define dealii_matrix_free_mapping_info_storage_templates_h
17
18 #include <deal.II/base/config.h>
19
20 #include <deal.II/base/memory_consumption.h>
21 #include <deal.II/base/utilities.h>
22
23 #include <deal.II/fe/fe_dgq.h>
24 #include <deal.II/fe/fe_nothing.h>
25 #include <deal.II/fe/fe_values.h>
26
27 #include <deal.II/matrix_free/evaluation_template_factory.h>
28 #include <deal.II/matrix_free/mapping_info_storage.h>
29 #include <deal.II/matrix_free/task_info.h>
30 #include <deal.II/matrix_free/util.h>
31
32 DEAL_II_NAMESPACE_OPEN
33
34
35 namespace internal
36 {
37 namespace MatrixFreeFunctions
38 {
39 template <int structdim, int spacedim, typename Number>
40 MappingInfoStorage<structdim, spacedim, Number>::QuadratureDescriptor::
41 QuadratureDescriptor()
42 : n_q_points(numbers::invalid_unsigned_int)
43 {}
44
45
46
47 template <int structdim, int spacedim, typename Number>
48 template <int dim_q>
49 void
50 MappingInfoStorage<structdim, spacedim, Number>::QuadratureDescriptor::
51 initialize(const Quadrature<dim_q> &quadrature)
52 {
53 this->quadrature = quadrature;
54 n_q_points = quadrature.size();
55 quadrature_weights.resize(n_q_points);
56 for (unsigned int i = 0; i < n_q_points; ++i)
57 quadrature_weights[i] = quadrature.weight(i);
58
59 // note: quadrature_1d and tensor_quadrature_weights are not set up
60 }
61
62
63
64 template <int structdim, int spacedim, typename Number>
65 void
66 MappingInfoStorage<structdim, spacedim, Number>::QuadratureDescriptor::
67 initialize(const Quadrature<1> &quadrature_1d)
68 {
69 this->quadrature_1d = quadrature_1d;
70 quadrature = Quadrature<structdim>(quadrature_1d);
71 n_q_points = quadrature.size();
72 quadrature_weights.resize(n_q_points);
73 for (unsigned int i = 0; i < n_q_points; ++i)
74 quadrature_weights[i] = quadrature.weight(i);
75
76 for (int d = 0; d < structdim; ++d)
77 {
78 tensor_quadrature_weights[d].resize(quadrature_1d.size());
79 for (unsigned int i = 0; i < quadrature_1d.size(); ++i)
80 tensor_quadrature_weights[d][i] = quadrature_1d.weight(i);
81 }
82 }
83
84
85
86 template <int structdim, int spacedim, typename Number>
87 std::size_t
88 MappingInfoStorage<structdim, spacedim, Number>::QuadratureDescriptor::
89 memory_consumption() const
90 {
91 std::size_t memory = sizeof(this) + quadrature.memory_consumption() +
92 quadrature_weights.memory_consumption();
93 for (int d = 0; d < structdim; ++d)
94 memory += tensor_quadrature_weights[d].memory_consumption();
95 return memory;
96 }
97
98
99
100 template <int structdim, int spacedim, typename Number>
101 void
102 MappingInfoStorage<structdim, spacedim, Number>::clear_data_fields()
103 {
104 data_index_offsets.clear();
105 JxW_values.clear();
106 normal_vectors.clear();
107 for (unsigned int i = 0; i < 2; ++i)
108 {
109 jacobians[i].clear();
110 jacobian_gradients[i].clear();
111 jacobian_gradients_non_inverse[i].clear();
112 normals_times_jacobians[i].clear();
113 }
114 quadrature_point_offsets.clear();
115 quadrature_points.clear();
116 }
117
118
119
120 template <int structdim, int spacedim, typename Number>
121 UpdateFlags
122 MappingInfoStorage<structdim, spacedim, Number>::compute_update_flags(
123 const UpdateFlags update_flags,
124 const std::vector<dealii::hp::QCollection<spacedim>> &quads,
125 const bool piola_transform)
126 {
127 // this class is build around the evaluation of jacobians, so compute
128 // them in any case. The Jacobians will be inverted manually. Since we
129 // always do support integration, we also include the JxW values
130 UpdateFlags new_flags = update_jacobians | update_JxW_values;
131
132 // for Hessian information, need inverse Jacobians and the derivative of
133 // Jacobians (these two together will give use the gradients of the
134 // inverse Jacobians, which is what we need)
135 if ((update_flags & update_hessians) != 0u ||
136 (update_flags & update_jacobian_grads) != 0u ||
137 (piola_transform &&
138 ((update_flags &
139 (update_gradients | update_contravariant_transformation)) != 0u)))
140 new_flags |= update_jacobian_grads;
141
142 if ((update_flags & update_quadrature_points) != 0u)
143 new_flags |= update_quadrature_points;
144
145 // there is one more thing: if we have a quadrature formula with only
146 // one quadrature point on the first component, but more points on later
147 // components, we need to have Jacobian gradients anyway in order to
148 // determine whether the Jacobian is constant throughout a cell
149 if (quads.empty() == false)
150 {
151 bool formula_with_one_point = false;
152 for (unsigned int i = 0; i < quads[0].size(); ++i)
153 if (quads[0][i].size() == 1)
154 {
155 formula_with_one_point = true;
156 break;
157 }
158 if (formula_with_one_point == true)
159 for (unsigned int comp = 1; comp < quads.size(); ++comp)
160 for (unsigned int i = 0; i < quads[comp].size(); ++i)
161 if (quads[comp][i].size() > 1)
162 {
163 new_flags |= update_jacobian_grads;
164 }
165 }
166 return new_flags;
167 }
168
169
170
171 template <int structdim, int spacedim, typename Number>
172 std::size_t
173 MappingInfoStorage<structdim, spacedim, Number>::memory_consumption() const
174 {
175 return MemoryConsumption::memory_consumption(descriptor) +
176 MemoryConsumption::memory_consumption(data_index_offsets) +
177 MemoryConsumption::memory_consumption(JxW_values) +
178 MemoryConsumption::memory_consumption(normal_vectors) +
179 MemoryConsumption::memory_consumption(jacobians[0]) +
180 MemoryConsumption::memory_consumption(jacobians[1]) +
181 MemoryConsumption::memory_consumption(jacobian_gradients[0]) +
182 MemoryConsumption::memory_consumption(jacobian_gradients[1]) +
183 MemoryConsumption::memory_consumption(
184 jacobian_gradients_non_inverse[0]) +
185 MemoryConsumption::memory_consumption(
186 jacobian_gradients_non_inverse[1]) +
187 MemoryConsumption::memory_consumption(normals_times_jacobians[0]) +
188 MemoryConsumption::memory_consumption(normals_times_jacobians[1]) +
189 MemoryConsumption::memory_consumption(quadrature_point_offsets) +
190 MemoryConsumption::memory_consumption(quadrature_points);
191 }
192
193
194
195 template <int structdim, int spacedim, typename Number>
196 template <typename StreamType>
197 void
198 MappingInfoStorage<structdim, spacedim, Number>::print_memory_consumption(
199 StreamType &out,
200 const TaskInfo &task_info) const
201 {
202 // print_memory_statistics involves global communication, so we can
203 // disable the check here only if no processor has any such data
204 const std::size_t size =
205 Utilities::MPI::sum(jacobians[0].size(), task_info.communicator);
206 if (size > 0)
207 {
208 out << " Memory JxW data: ";
209 task_info.print_memory_statistics(
210 out,
211 MemoryConsumption::memory_consumption(data_index_offsets) +
212 MemoryConsumption::memory_consumption(JxW_values));
213 out << " Memory Jacobian data: ";
214 task_info.print_memory_statistics(
215 out,
216 MemoryConsumption::memory_consumption(jacobians[0]) +
217 MemoryConsumption::memory_consumption(jacobians[1]));
218 out << " Memory second derivative data: ";
219 task_info.print_memory_statistics(
220 out,
221 MemoryConsumption::memory_consumption(jacobian_gradients[0]) +
222 MemoryConsumption::memory_consumption(jacobian_gradients[1]) +
223 MemoryConsumption::memory_consumption(
224 jacobian_gradients_non_inverse[0]) +
225 MemoryConsumption::memory_consumption(
226 jacobian_gradients_non_inverse[1]));
227 }
228 const std::size_t normal_size =
229 Utilities::MPI::sum(normal_vectors.size(), task_info.communicator);
230 if (normal_size > 0)
231 {
232 out << " Memory normal vectors data: ";
233 task_info.print_memory_statistics(
234 out,
235 MemoryConsumption::memory_consumption(normal_vectors) +
236 MemoryConsumption::memory_consumption(
237 normals_times_jacobians[0]) +
238 MemoryConsumption::memory_consumption(
239 normals_times_jacobians[1]));
240 }
241
242 const std::size_t quad_size =
243 Utilities::MPI::sum(quadrature_points.size(), task_info.communicator);
244 if (quad_size > 0)
245 {
246 out << " Memory quadrature points: ";
247 task_info.print_memory_statistics(
248 out,
249 MemoryConsumption::memory_consumption(quadrature_point_offsets) +
250 MemoryConsumption::memory_consumption(quadrature_points));
251 }
252 }
253
254 } // namespace MatrixFreeFunctions
255 } // end of namespace internal
256
257 DEAL_II_NAMESPACE_CLOSE
258
259 #endif