Reference documentation for deal.II version 9.2.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\}}\)
functional.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2010 - 2019 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 
36 namespace MeshWorker
37 {
38  namespace Assembler
39  {
49  template <typename number = double>
50  class Functional
51  {
52  public:
57  void
58  initialize(const unsigned int n);
66  template <class DOFINFO>
67  void
68  initialize_info(DOFINFO &info, bool face);
69 
73  template <class DOFINFO>
74  void
75  assemble(const DOFINFO &info);
76 
80  template <class DOFINFO>
81  void
82  assemble(const DOFINFO &info1, const DOFINFO &info2);
83 
87  number
88  operator()(const unsigned int i) const;
89 
90  private:
94  std::vector<double> results;
95  };
96 
107  template <typename number = double>
109  {
110  public:
114  CellsAndFaces();
115 
133  void
134  initialize(AnyData &results, bool separate_faces = true);
135 
143  template <class DOFINFO>
144  void
145  initialize_info(DOFINFO &info, bool face) const;
146 
150  template <class DOFINFO>
151  void
152  assemble(const DOFINFO &info);
153 
157  template <class DOFINFO>
158  void
159  assemble(const DOFINFO &info1, const DOFINFO &info2);
160 
164  number
165  operator()(const unsigned int i) const;
166 
167  private:
170  };
171  //----------------------------------------------------------------------//
172 
173  template <typename number>
174  inline void
175  Functional<number>::initialize(const unsigned int n)
176  {
177  results.resize(n);
178  std::fill(results.begin(), results.end(), 0.);
179  }
180 
181 
182  template <typename number>
183  template <class DOFINFO>
184  inline void
186  {
187  info.initialize_numbers(results.size());
188  }
189 
190 
191  template <typename number>
192  template <class DOFINFO>
193  inline void
194  Functional<number>::assemble(const DOFINFO &info)
195  {
196  for (unsigned int i = 0; i < results.size(); ++i)
197  results[i] += info.value(i);
198  }
199 
200 
201  template <typename number>
202  template <class DOFINFO>
203  inline void
204  Functional<number>::assemble(const DOFINFO &info1, const DOFINFO &info2)
205  {
206  for (unsigned int i = 0; i < results.size(); ++i)
207  {
208  results[i] += info1.value(i);
209  results[i] += info2.value(i);
210  }
211  }
212 
213 
214  template <typename number>
215  inline number
216  Functional<number>::operator()(const unsigned int i) const
217  {
218  AssertIndexRange(i, results.size());
219  return results[i];
220  }
221 
222  //----------------------------------------------------------------------//
223 
224  template <typename number>
226  : separate_faces(true)
227  {}
228 
229 
230 
231  template <typename number>
232  inline void
234  {
235  Assert(r.name(0) == "cells", AnyData::ExcNameMismatch(0, "cells"));
236  if (sep)
237  {
238  Assert(r.name(1) == "faces", AnyData::ExcNameMismatch(1, "faces"));
240  r.entry<BlockVector<double> *>(1)->n_blocks());
241  }
242 
243  results = r;
244  separate_faces = sep;
245  }
246 
247  template <typename number>
248  template <class DOFINFO>
249  inline void
250  CellsAndFaces<number>::initialize_info(DOFINFO &info, bool) const
251  {
252  info.initialize_numbers(
253  results.entry<BlockVector<double> *>(0)->n_blocks());
254  }
255 
256 
257  template <typename number>
258  template <class DOFINFO>
259  inline void
260  CellsAndFaces<number>::assemble(const DOFINFO &info)
261  {
263  if (separate_faces && info.face_number != numbers::invalid_unsigned_int)
264  v = results.entry<BlockVector<double> *>(1);
265  else
266  v = results.entry<BlockVector<double> *>(0);
267 
268  for (unsigned int i = 0; i < info.n_values(); ++i)
269  v->block(i)(info.cell->user_index()) += info.value(i);
270  }
271 
272 
273  template <typename number>
274  template <class DOFINFO>
275  inline void
276  CellsAndFaces<number>::assemble(const DOFINFO &info1, const DOFINFO &info2)
277  {
278  for (unsigned int i = 0; i < info1.n_values(); ++i)
279  {
280  if (separate_faces)
281  {
282  BlockVector<double> *v1 = results.entry<BlockVector<double> *>(1);
283  const double J = info1.value(i) + info2.value(i);
284  v1->block(i)(info1.face->user_index()) += J;
285  if (info2.face != info1.face)
286  v1->block(i)(info2.face->user_index()) += J;
287  }
288  else
289  {
290  BlockVector<double> *v0 = results.entry<BlockVector<double> *>(0);
291  v0->block(i)(info1.cell->user_index()) += .5 * info1.value(i);
292  v0->block(i)(info2.cell->user_index()) += .5 * info2.value(i);
293  }
294  }
295  }
296  } // namespace Assembler
297 } // namespace MeshWorker
298 
300 
301 #endif
MeshWorker::Assembler::Functional
Definition: functional.h:50
AnyData
Definition: any_data.h:37
MeshWorker::Assembler::CellsAndFaces::initialize_info
void initialize_info(DOFINFO &info, bool face) const
Definition: functional.h:250
MeshWorker::Assembler::Functional::initialize
void initialize(const unsigned int n)
Definition: functional.h:175
BlockVector< double >
AnyData::name
const std::string & name(const unsigned int i) const
Name of object at index.
Definition: any_data.h:311
MeshWorker
Definition: assemble_flags.h:30
AssertIndexRange
#define AssertIndexRange(index, range)
Definition: exceptions.h:1649
MeshWorker::Assembler::CellsAndFaces::CellsAndFaces
CellsAndFaces()
Definition: functional.h:225
MeshWorker::Assembler::CellsAndFaces
Definition: functional.h:108
MeshWorker::Assembler::Functional::assemble
void assemble(const DOFINFO &info)
Definition: functional.h:194
AnyData::entry
type entry(const std::string &name)
Access to stored data object by name.
Definition: any_data.h:351
MeshWorker::Assembler::Functional::initialize_info
void initialize_info(DOFINFO &info, bool face)
Definition: functional.h:185
block_vector.h
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
BlockVectorBase::n_blocks
unsigned int n_blocks() const
AssertDimension
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1579
smartpointer.h
MeshWorker::Assembler::CellsAndFaces::separate_faces
bool separate_faces
Definition: functional.h:169
mg_level_object.h
dof_info.h
AnyData::ExcNameMismatch
static ::ExceptionBase & ExcNameMismatch(int arg1, std::string arg2)
MeshWorker::Assembler::CellsAndFaces::assemble
void assemble(const DOFINFO &info)
Definition: functional.h:260
mg_constrained_dofs.h
any_data.h
Assert
#define Assert(cond, exc)
Definition: exceptions.h:1419
MeshWorker::Assembler::CellsAndFaces::operator()
number operator()(const unsigned int i) const
numbers::invalid_unsigned_int
static const unsigned int invalid_unsigned_int
Definition: types.h:191
config.h
MeshWorker::Assembler::Functional::operator()
number operator()(const unsigned int i) const
Definition: functional.h:216
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
BlockVectorBase::block
BlockType & block(const unsigned int i)
MeshWorker::Assembler::Functional::results
std::vector< double > results
Definition: functional.h:94
MeshWorker::Assembler::CellsAndFaces::results
AnyData results
Definition: functional.h:168
MeshWorker::Assembler::CellsAndFaces::initialize
void initialize(AnyData &results, bool separate_faces=true)
Definition: functional.h:233