Reference documentation for deal.II version 9.5.0
\(\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// Copyright (C) 2010 - 2020 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16
17#ifndef dealii_mesh_worker_functional_h
18#define dealii_mesh_worker_functional_h
19
20#include <deal.II/base/config.h>
21
23
26
28
30
32
33
35
36namespace MeshWorker
37{
38 namespace Assembler
39 {
48 template <typename number = double>
50 {
51 public:
56 void
57 initialize(const unsigned int n);
65 template <class DOFINFO>
66 void
67 initialize_info(DOFINFO &info, bool face);
68
72 template <class DOFINFO>
73 void
74 assemble(const DOFINFO &info);
75
79 template <class DOFINFO>
80 void
81 assemble(const DOFINFO &info1, const DOFINFO &info2);
82
86 number
87 operator()(const unsigned int i) const;
88
89 private:
93 std::vector<double> results;
94 };
95
105 template <typename number = double>
107 {
108 public:
113
131 void
133
141 template <class DOFINFO>
142 void
143 initialize_info(DOFINFO &info, bool face) const;
144
148 template <class DOFINFO>
149 void
150 assemble(const DOFINFO &info);
151
155 template <class DOFINFO>
156 void
157 assemble(const DOFINFO &info1, const DOFINFO &info2);
158
162 number
163 operator()(const unsigned int i) const;
164
165 private:
168 };
169 //----------------------------------------------------------------------//
170
171 template <typename number>
172 inline void
173 Functional<number>::initialize(const unsigned int n)
174 {
175 results.resize(n);
176 std::fill(results.begin(), results.end(), 0.);
177 }
178
179
180 template <typename number>
181 template <class DOFINFO>
182 inline void
184 {
185 info.initialize_numbers(results.size());
186 }
187
188
189 template <typename number>
190 template <class DOFINFO>
191 inline void
192 Functional<number>::assemble(const DOFINFO &info)
193 {
194 for (unsigned int i = 0; i < results.size(); ++i)
195 results[i] += info.value(i);
196 }
197
198
199 template <typename number>
200 template <class DOFINFO>
201 inline void
202 Functional<number>::assemble(const DOFINFO &info1, const DOFINFO &info2)
203 {
204 for (unsigned int i = 0; i < results.size(); ++i)
205 {
206 results[i] += info1.value(i);
207 results[i] += info2.value(i);
208 }
209 }
210
211
212 template <typename number>
213 inline number
214 Functional<number>::operator()(const unsigned int i) const
215 {
216 AssertIndexRange(i, results.size());
217 return results[i];
218 }
219
220 //----------------------------------------------------------------------//
221
222 template <typename number>
224 : separate_faces(true)
225 {}
226
227
228
229 template <typename number>
230 inline void
232 {
233 Assert(r.name(0) == "cells", AnyData::ExcNameMismatch(0, "cells"));
234 if (sep)
235 {
236 Assert(r.name(1) == "faces", AnyData::ExcNameMismatch(1, "faces"));
239 }
240
241 results = r;
242 separate_faces = sep;
243 }
244
245 template <typename number>
246 template <class DOFINFO>
247 inline void
248 CellsAndFaces<number>::initialize_info(DOFINFO &info, bool) const
249 {
250 info.initialize_numbers(
251 results.entry<BlockVector<double> *>(0)->n_blocks());
252 }
253
254
255 template <typename number>
256 template <class DOFINFO>
257 inline void
259 {
261 if (separate_faces && info.face_number != numbers::invalid_unsigned_int)
262 v = results.entry<BlockVector<double> *>(1);
263 else
264 v = results.entry<BlockVector<double> *>(0);
265
266 for (unsigned int i = 0; i < info.n_values(); ++i)
267 v->block(i)(info.cell->user_index()) += info.value(i);
268 }
269
270
271 template <typename number>
272 template <class DOFINFO>
273 inline void
274 CellsAndFaces<number>::assemble(const DOFINFO &info1, const DOFINFO &info2)
275 {
276 for (unsigned int i = 0; i < info1.n_values(); ++i)
277 {
278 if (separate_faces)
279 {
280 BlockVector<double> *v1 = results.entry<BlockVector<double> *>(1);
281 const double J = info1.value(i) + info2.value(i);
282 v1->block(i)(info1.face->user_index()) += J;
283 if (info2.face != info1.face)
284 v1->block(i)(info2.face->user_index()) += J;
285 }
286 else
287 {
288 BlockVector<double> *v0 = results.entry<BlockVector<double> *>(0);
289 v0->block(i)(info1.cell->user_index()) += .5 * info1.value(i);
290 v0->block(i)(info2.cell->user_index()) += .5 * info2.value(i);
291 }
292 }
293 }
294 } // namespace Assembler
295} // namespace MeshWorker
296
298
299#endif
const std::string & name(const unsigned int i) const
Name of object at index.
Definition any_data.h:311
type entry(const std::string &name)
Access to stored data object by name.
Definition any_data.h:351
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:258
void initialize(AnyData &results, bool separate_faces=true)
Definition functional.h:231
void initialize_info(DOFINFO &info, bool face) const
Definition functional.h:248
void initialize(const unsigned int n)
Definition functional.h:173
std::vector< double > results
Definition functional.h:93
void initialize_info(DOFINFO &info, bool face)
Definition functional.h:183
number operator()(const unsigned int i) const
Definition functional.h:214
void assemble(const DOFINFO &info)
Definition functional.h:192
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
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:213