deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
functional.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2011 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13
14#ifndef dealii_mesh_worker_functional_h
15#define dealii_mesh_worker_functional_h
16
17#include <deal.II/base/config.h>
18
20
23
25
27
29
30
32
33namespace MeshWorker
34{
35 namespace Assembler
36 {
45 template <typename number = double>
47 {
48 public:
53 void
54 initialize(const unsigned int n);
62 template <class DOFINFO>
63 void
64 initialize_info(DOFINFO &info, bool face);
65
69 template <class DOFINFO>
70 void
71 assemble(const DOFINFO &info);
72
76 template <class DOFINFO>
77 void
78 assemble(const DOFINFO &info1, const DOFINFO &info2);
79
83 number
84 operator()(const unsigned int i) const;
85
86 private:
90 std::vector<double> results;
91 };
92
102 template <typename number = double>
104 {
105 public:
110
128 void
129 initialize(AnyData &results, bool separate_faces = true);
130
138 template <class DOFINFO>
139 void
140 initialize_info(DOFINFO &info, bool face) const;
141
145 template <class DOFINFO>
146 void
147 assemble(const DOFINFO &info);
148
152 template <class DOFINFO>
153 void
154 assemble(const DOFINFO &info1, const DOFINFO &info2);
155
159 number
160 operator()(const unsigned int i) const;
161
162 private:
165 };
166 //----------------------------------------------------------------------//
167
168 template <typename number>
169 inline void
170 Functional<number>::initialize(const unsigned int n)
171 {
172 results.resize(n);
173 std::fill(results.begin(), results.end(), 0.);
174 }
175
176
177 template <typename number>
178 template <class DOFINFO>
179 inline void
181 {
182 info.initialize_numbers(results.size());
183 }
184
185
186 template <typename number>
187 template <class DOFINFO>
188 inline void
189 Functional<number>::assemble(const DOFINFO &info)
190 {
191 for (unsigned int i = 0; i < results.size(); ++i)
192 results[i] += info.value(i);
193 }
194
195
196 template <typename number>
197 template <class DOFINFO>
198 inline void
199 Functional<number>::assemble(const DOFINFO &info1, const DOFINFO &info2)
200 {
201 for (unsigned int i = 0; i < results.size(); ++i)
202 {
203 results[i] += info1.value(i);
204 results[i] += info2.value(i);
205 }
206 }
207
208
209 template <typename number>
210 inline number
211 Functional<number>::operator()(const unsigned int i) const
212 {
213 AssertIndexRange(i, results.size());
214 return results[i];
215 }
216
217 //----------------------------------------------------------------------//
218
219 template <typename number>
221 : separate_faces(true)
222 {}
223
224
225
226 template <typename number>
227 inline void
229 {
230 Assert(r.name(0) == "cells", AnyData::ExcNameMismatch(0, "cells"));
231 if (sep)
232 {
233 Assert(r.name(1) == "faces", AnyData::ExcNameMismatch(1, "faces"));
236 }
237
238 results = r;
239 separate_faces = sep;
240 }
241
242 template <typename number>
243 template <class DOFINFO>
244 inline void
245 CellsAndFaces<number>::initialize_info(DOFINFO &info, bool) const
246 {
247 info.initialize_numbers(
248 results.entry<BlockVector<double> *>(0)->n_blocks());
249 }
250
251
252 template <typename number>
253 template <class DOFINFO>
254 inline void
256 {
258 if (separate_faces && info.face_number != numbers::invalid_unsigned_int)
259 v = results.entry<BlockVector<double> *>(1);
260 else
261 v = results.entry<BlockVector<double> *>(0);
262
263 for (unsigned int i = 0; i < info.n_values(); ++i)
264 v->block(i)(info.cell->user_index()) += info.value(i);
265 }
266
267
268 template <typename number>
269 template <class DOFINFO>
270 inline void
271 CellsAndFaces<number>::assemble(const DOFINFO &info1, const DOFINFO &info2)
272 {
273 for (unsigned int i = 0; i < info1.n_values(); ++i)
274 {
275 if (separate_faces)
276 {
277 BlockVector<double> *v1 = results.entry<BlockVector<double> *>(1);
278 const double J = info1.value(i) + info2.value(i);
279 v1->block(i)(info1.face->user_index()) += J;
280 if (info2.face != info1.face)
281 v1->block(i)(info2.face->user_index()) += J;
282 }
283 else
284 {
285 BlockVector<double> *v0 = results.entry<BlockVector<double> *>(0);
286 v0->block(i)(info1.cell->user_index()) += .5 * info1.value(i);
287 v0->block(i)(info2.cell->user_index()) += .5 * info2.value(i);
288 }
289 }
290 }
291 } // namespace Assembler
292} // namespace MeshWorker
293
295
296#endif
*  *  Point< dim > operator()(const Point< dim > &p) const * 
const std::string & name(const unsigned int i) const
Name of object at index.
Definition any_data.h:309
type entry(const std::string &name)
Access to stored data object by name.
Definition any_data.h:349
unsigned int n_blocks() const
BlockType & block(const unsigned int i)
number operator()(const unsigned int i) const
void assemble(const DOFINFO &info)
Definition functional.h:255
void initialize(AnyData &results, bool separate_faces=true)
Definition functional.h:228
void initialize_info(DOFINFO &info, bool face) const
Definition functional.h:245
void initialize(const unsigned int n)
Definition functional.h:170
std::vector< double > results
Definition functional.h:90
void initialize_info(DOFINFO &info, bool face)
Definition functional.h:180
number operator()(const unsigned int i) const
Definition functional.h:211
void assemble(const DOFINFO &info)
Definition functional.h:189
#define DEAL_II_DEPRECATED
Definition config.h:294
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
const unsigned int v0
const unsigned int v1
static ::ExceptionBase & ExcNameMismatch(int arg1, std::string arg2)
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
constexpr unsigned int invalid_unsigned_int
Definition types.h:228