Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
functional.h
1 // ---------------------------------------------------------------------
2 // @f$Id: functional.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 2010 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 
18 #ifndef __deal2__mesh_worker_functional_h
19 #define __deal2__mesh_worker_functional_h
20 
21 #include <deal.II/base/named_data.h>
22 #include <deal.II/base/smartpointer.h>
23 #include <deal.II/base/mg_level_object.h>
24 #include <deal.II/lac/block_vector.h>
25 #include <deal.II/meshworker/dof_info.h>
26 #include <deal.II/multigrid/mg_constrained_dofs.h>
27 
28 
30 
31 namespace MeshWorker
32 {
33  namespace Assembler
34  {
44  template <typename number = double>
45  class Functional
46  {
47  public:
55  void initialize(const unsigned int n);
67  template <class DOFINFO>
68  void initialize_info(DOFINFO &info, bool face);
69 
74  template<class DOFINFO>
75  void assemble(const DOFINFO &info);
76 
81  template<class DOFINFO>
82  void assemble(const DOFINFO &info1,
83  const DOFINFO &info2);
84 
89  number operator() (const unsigned int i) const;
90  private:
95  std::vector<double> results;
96  };
97 
105  template <typename number = double>
107  {
108  public:
115 
152  void initialize(DataVectors &results,
153  bool separate_faces = true);
167  template <class DOFINFO>
168  void initialize_info(DOFINFO &info, bool face) const;
169 
174  template<class DOFINFO>
175  void assemble(const DOFINFO &info);
176 
181  template<class DOFINFO>
182  void assemble(const DOFINFO &info1,
183  const DOFINFO &info2);
184 
189  number operator() (const unsigned int i) const;
190  private:
191  DataVectors results;
192  bool separate_faces;
193  };
194 //----------------------------------------------------------------------//
195 
196  template <typename number>
197  inline void
198  Functional<number>::initialize(const unsigned int n)
199  {
200  results.resize(n);
201  std::fill(results.begin(), results.end(), 0.);
202  }
203 
204 
205  template <typename number>
206  template <class DOFINFO>
207  inline void
209  {
210  info.initialize_numbers(results.size());
211  }
212 
213 
214  template <typename number>
215  template <class DOFINFO>
216  inline void
217  Functional<number>::assemble(const DOFINFO &info)
218  {
219  for (unsigned int i=0; i<results.size(); ++i)
220  results[i] += info.value(i);
221  }
222 
223 
224  template <typename number>
225  template <class DOFINFO>
226  inline void
227  Functional<number>::assemble(const DOFINFO &info1,
228  const DOFINFO &info2)
229  {
230  for (unsigned int i=0; i<results.size(); ++i)
231  {
232  results[i] += info1.value(i);
233  results[i] += info2.value(i);
234  }
235  }
236 
237 
238  template <typename number>
239  inline number
240  Functional<number>::operator() (const unsigned int i) const
241  {
242  AssertIndexRange(i, results.size());
243  return results[i];
244  }
245 
246 //----------------------------------------------------------------------//
247 
248  template <typename number>
249  inline void
251  {
252  Assert(r.name(0) == "cells", typename DataVectors::ExcNameMismatch(0, "cells"));
253  if (sep)
254  {
255  Assert(r.name(1) == "faces", typename DataVectors::ExcNameMismatch(1, "faces"));
256  AssertDimension(r(0)->n_blocks(), r(1)->n_blocks());
257  }
258 
259  results = r;
260  separate_faces = sep;
261  }
262 
263 
264  template <typename number>
265  template <class DOFINFO>
266  inline void
267  CellsAndFaces<number>::initialize_info(DOFINFO &info, bool) const
268  {
269  info.initialize_numbers(results(0)->n_blocks());
270  }
271 
272 
273  template <typename number>
274  template <class DOFINFO>
275  inline void
276  CellsAndFaces<number>::assemble(const DOFINFO &info)
277  {
278  for (unsigned int i=0; i<info.n_values(); ++i)
279  {
280  if (separate_faces &&
281  info.face_number != deal_II_numbers::invalid_unsigned_int)
282  results(1)->block(i)(info.face->user_index()) += info.value(i);
283  else
284  results(0)->block(i)(info.cell->user_index()) += info.value(i);
285  }
286  }
287 
288 
289  template <typename number>
290  template <class DOFINFO>
291  inline void
292  CellsAndFaces<number>::assemble(const DOFINFO &info1,
293  const DOFINFO &info2)
294  {
295  for (unsigned int i=0; i<info1.n_values(); ++i)
296  {
297  if (separate_faces)
298  {
299  const double J = info1.value(i) + info2.value(i);
300  results(1)->block(i)(info1.face->user_index()) += J;
301  if (info2.face != info1.face)
302  results(1)->block(i)(info2.face->user_index()) += J;
303  }
304  else
305  {
306  results(0)->block(i)(info1.cell->user_index()) += .5*info1.value(i);
307  results(0)->block(i)(info2.cell->user_index()) += .5*info2.value(i);
308  }
309  }
310  }
311  }
312 }
313 
314 DEAL_II_NAMESPACE_CLOSE
315 
316 #endif
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:858
const std::string & name(unsigned int i) const
Name of object at index.
Definition: named_data.h:374
void initialize(const unsigned int n)
Definition: functional.h:198
#define AssertIndexRange(index, range)
Definition: exceptions.h:888
number operator()(const unsigned int i) const
Definition: functional.h:240
NamedData< BlockVector< number > * > DataVectors
Definition: functional.h:114
#define Assert(cond, exc)
Definition: exceptions.h:299
void initialize_info(DOFINFO &info, bool face)
Definition: functional.h:208
void initialize_info(DOFINFO &info, bool face) const
Definition: functional.h:267
void assemble(const DOFINFO &info)
Definition: functional.h:217
std::vector< double > results
Definition: functional.h:95
void initialize(DataVectors &results, bool separate_faces=true)
Definition: functional.h:250
void assemble(const DOFINFO &info)
Definition: functional.h:276
number operator()(const unsigned int i) const