OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mesh_worker_loop.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------
2 // $Id: mesh_worker_loop.h 1348 2013-08-16 00:45:07Z secanell $
3 //
4 // Copyright (C) 2006, 2007, 2008, 2009 by Guido Kanschat
5 //
6 // This file is subject to QPL and may not be distributed
7 // without copyright and license information. Please refer
8 // to the file deal.II/doc/license.html for the text and
9 // further information on this license.
10 //
11 //---------------------------------------------------------------------------
12 
13 #ifndef __deal2__mesh_worker_loop_h
14 #define __deal2__mesh_worker_loop_h
15 
16 namespace MeshWorker
17 {
18  namespace internal
19  {
23  template <class DI>
24  bool is_active_iterator(const DI&)
25  {
26  return false;
27  }
28 
29  template <class Accessor>
30  bool is_active_iterator(const TriaActiveIterator<Accessor>&)
31  {
32  return true;
33  }
34  }
35 
36 
55  template<class ITERATOR, class ENDITERATOR, class CELLINFO, class FACEINFO, class LOCALWORKER>
56  void loop(ITERATOR begin, ENDITERATOR end,
57  CELLINFO& cellinfo, FACEINFO& bdryinfo,
58  FACEINFO& faceinfo, FACEINFO& subfaceinfo, FACEINFO& ngbrinfo,
59  LOCALWORKER& localworker,
60  bool cells_first = true)
61  {
63  begin->get_triangulation()).clear_user_flags();
64 
65  // Loop over all cells
66  for (ITERATOR cell = begin; cell != end; ++cell)
67  {
68  // Execute this, if cells
69  // have to be dealt with
70  // before faces
71  if (cells_first)
72  {
73  cellinfo.reinit(cell);
74  localworker.cell(cellinfo);
75  }
76 
77 
78  if (localworker.interior_fluxes || localworker.boundary_fluxes)
79  for (unsigned int face_no=0; face_no < GeometryInfo<ITERATOR::AccessorType::Container::dimension>::faces_per_cell; ++face_no)
80  {
81  typename ITERATOR::AccessorType::Container::face_iterator face = cell->face(face_no);
82  // Treat every face only once
83  if (face->user_flag_set ()) continue;
84 
85  if (cell->at_boundary(face_no))
86  {
87  if (localworker.boundary_fluxes)
88  {
89  bdryinfo.reinit(cell, face, face_no);
90  localworker.bdry(bdryinfo);
91  }
92  }
93  else if (localworker.interior_fluxes)
94  {
95  if (face->user_flag_set ()) continue;
96  face->set_user_flag ();
97  // Interior face
98  typename ITERATOR::AccessorType::Container::cell_iterator
99  neighbor = cell->neighbor(face_no);
100 
101  // Deal with
102  // refinement edges
103  // from the refined
104  // side. Assuming
105  // one-irregular
106  // meshes, this
107  // situation should
108  // only occur if
109  // both cells are
110  // active.
111  if (neighbor->level() < cell->level())
112  {
113  Assert(!cell->has_children(), ExcInternalError());
114  Assert(!neighbor->has_children(), ExcInternalError());
115 
116  std::pair<unsigned int, unsigned int> neighbor_face_no
117  = cell->neighbor_of_coarser_neighbor(face_no);
118  typename ITERATOR::AccessorType::Container::face_iterator nface
119  = neighbor->face(neighbor_face_no.first);
120  faceinfo.reinit(cell, face, face_no);
121  subfaceinfo.reinit(neighbor, nface, neighbor_face_no.first, neighbor_face_no.second);
122  // Neighbor
123  // first to
124  // conform to
125  // old version
126  localworker.face(faceinfo, subfaceinfo);
127  }
128  else
129  {
130  // Neighbor is
131  // on same
132  // level
133 
134  // If iterator
135  // is active
136  // and neighbor
137  // is refined,
138  // skip
139  // internal face.
140  if (internal::is_active_iterator(cell) && neighbor->has_children())
141  continue;
142 
143  unsigned int neighbor_face_no = cell->neighbor_of_neighbor(face_no);
144  Assert (neighbor->face(neighbor_face_no) == face, ExcInternalError());
145  // Regular interior face
146  faceinfo.reinit(cell, face, face_no);
147  ngbrinfo.reinit(neighbor, neighbor->face(neighbor_face_no),
148  neighbor_face_no);
149 
150  localworker.face(faceinfo, ngbrinfo);
151  neighbor->face(neighbor_face_no)->set_user_flag ();
152  }
153 
154  }
155  } // faces
156  // Execute this, if faces
157  // have to be handled first
158  if (!cells_first)
159  {
160  cellinfo.reinit(cell);
161  localworker.cell(cellinfo);
162  }
163  }
164  }
165 
171  template<int dim, class ITERATOR, class ENDITERATOR, class LOCALWORKER>
172  void integration_loop(ITERATOR begin, ENDITERATOR end,
174  LOCALWORKER& localworker,
175  bool cells_first = true)
176  {
177  loop(begin, end, box.cell_info, box.bdry_info,
178  box.face_info, box.subface_info, box.neighbor_info,
179  localworker, cells_first);
180  }
181 }
182 
183 #endif