Reference documentation for deal.II version GIT relicensing-487-ge9eb5ab491 2024-04-25 07:20:02+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: LGPL-2.1-or-later
4// Copyright (C) 2011 - 2020 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
16#ifndef dealii_mesh_worker_functional_h
17#define dealii_mesh_worker_functional_h
18
19#include <deal.II/base/config.h>
20
22
25
27
29
31
32
34
35namespace MeshWorker
36{
37 namespace Assembler
38 {
47 template <typename number = double>
49 {
50 public:
55 void
56 initialize(const unsigned int n);
64 template <class DOFINFO>
65 void
66 initialize_info(DOFINFO &info, bool face);
67
71 template <class DOFINFO>
72 void
73 assemble(const DOFINFO &info);
74
78 template <class DOFINFO>
79 void
80 assemble(const DOFINFO &info1, const DOFINFO &info2);
81
85 number
86 operator()(const unsigned int i) const;
87
88 private:
92 std::vector<double> results;
93 };
94
104 template <typename number = double>
106 {
107 public:
112
130 void
132
140 template <class DOFINFO>
141 void
142 initialize_info(DOFINFO &info, bool face) const;
143
147 template <class DOFINFO>
148 void
149 assemble(const DOFINFO &info);
150
154 template <class DOFINFO>
155 void
156 assemble(const DOFINFO &info1, const DOFINFO &info2);
157
161 number
162 operator()(const unsigned int i) const;
163
164 private:
167 };
168 //----------------------------------------------------------------------//
169
170 template <typename number>
171 inline void
172 Functional<number>::initialize(const unsigned int n)
173 {
174 results.resize(n);
175 std::fill(results.begin(), results.end(), 0.);
176 }
177
178
179 template <typename number>
180 template <class DOFINFO>
181 inline void
183 {
184 info.initialize_numbers(results.size());
185 }
186
187
188 template <typename number>
189 template <class DOFINFO>
190 inline void
191 Functional<number>::assemble(const DOFINFO &info)
192 {
193 for (unsigned int i = 0; i < results.size(); ++i)
194 results[i] += info.value(i);
195 }
196
197
198 template <typename number>
199 template <class DOFINFO>
200 inline void
201 Functional<number>::assemble(const DOFINFO &info1, const DOFINFO &info2)
202 {
203 for (unsigned int i = 0; i < results.size(); ++i)
204 {
205 results[i] += info1.value(i);
206 results[i] += info2.value(i);
207 }
208 }
209
210
211 template <typename number>
212 inline number
213 Functional<number>::operator()(const unsigned int i) const
214 {
215 AssertIndexRange(i, results.size());
216 return results[i];
217 }
218
219 //----------------------------------------------------------------------//
220
221 template <typename number>
223 : separate_faces(true)
224 {}
225
226
227
228 template <typename number>
229 inline void
231 {
232 Assert(r.name(0) == "cells", AnyData::ExcNameMismatch(0, "cells"));
233 if (sep)
234 {
235 Assert(r.name(1) == "faces", AnyData::ExcNameMismatch(1, "faces"));
238 }
239
240 results = r;
241 separate_faces = sep;
242 }
243
244 template <typename number>
245 template <class DOFINFO>
246 inline void
247 CellsAndFaces<number>::initialize_info(DOFINFO &info, bool) const
248 {
249 info.initialize_numbers(
250 results.entry<BlockVector<double> *>(0)->n_blocks());
251 }
252
253
254 template <typename number>
255 template <class DOFINFO>
256 inline void
258 {
260 if (separate_faces && info.face_number != numbers::invalid_unsigned_int)
261 v = results.entry<BlockVector<double> *>(1);
262 else
263 v = results.entry<BlockVector<double> *>(0);
264
265 for (unsigned int i = 0; i < info.n_values(); ++i)
266 v->block(i)(info.cell->user_index()) += info.value(i);
267 }
268
269
270 template <typename number>
271 template <class DOFINFO>
272 inline void
273 CellsAndFaces<number>::assemble(const DOFINFO &info1, const DOFINFO &info2)
274 {
275 for (unsigned int i = 0; i < info1.n_values(); ++i)
276 {
277 if (separate_faces)
278 {
279 BlockVector<double> *v1 = results.entry<BlockVector<double> *>(1);
280 const double J = info1.value(i) + info2.value(i);
281 v1->block(i)(info1.face->user_index()) += J;
282 if (info2.face != info1.face)
283 v1->block(i)(info2.face->user_index()) += J;
284 }
285 else
286 {
287 BlockVector<double> *v0 = results.entry<BlockVector<double> *>(0);
288 v0->block(i)(info1.cell->user_index()) += .5 * info1.value(i);
289 v0->block(i)(info2.cell->user_index()) += .5 * info2.value(i);
290 }
291 }
292 }
293 } // namespace Assembler
294} // namespace MeshWorker
295
297
298#endif
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:257
void initialize(AnyData &results, bool separate_faces=true)
Definition functional.h:230
void initialize_info(DOFINFO &info, bool face) const
Definition functional.h:247
void initialize(const unsigned int n)
Definition functional.h:172
std::vector< double > results
Definition functional.h:92
void initialize_info(DOFINFO &info, bool face)
Definition functional.h:182
number operator()(const unsigned int i) const
Definition functional.h:213
void assemble(const DOFINFO &info)
Definition functional.h:191
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
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)
static const unsigned int invalid_unsigned_int
Definition types.h:220