www.mooseframework.org
ThreadedElementLoopBase.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef THREADEDELEMENTLOOPBASE_H
16 #define THREADEDELEMENTLOOPBASE_H
17 
18 #include "ParallelUniqueId.h"
19 #include "MooseMesh.h"
20 #include "MooseTypes.h"
21 #include "MooseException.h"
22 
26 template <typename RangeType>
28 {
29 public:
31 
32  ThreadedElementLoopBase(ThreadedElementLoopBase & x, Threads::split split);
33 
34  virtual ~ThreadedElementLoopBase();
35 
36  void operator()(const RangeType & range, bool bypass_threading = false);
37 
41  virtual void pre();
42 
46  virtual void post();
47 
53  virtual void onElement(const Elem * elem);
54 
60  virtual void preElement(const Elem * elem);
61 
67  virtual void postElement(const Elem * elem);
68 
76  virtual void onBoundary(const Elem * elem, unsigned int side, BoundaryID bnd_id);
77 
84  virtual void preInternalSide(const Elem * elem, unsigned int side);
85 
92  virtual void postInternalSide(const Elem * elem, unsigned int side);
93 
100  virtual void onInternalSide(const Elem * elem, unsigned int side);
101 
109  virtual void onInterface(const Elem * elem, unsigned int side, BoundaryID bnd_id);
110 
117  virtual void subdomainChanged();
118 
125  virtual void neighborSubdomainChanged();
126 
132 
138  virtual bool keepGoing() { return true; }
139 
140 protected:
143 
146 
149 
152 
155 };
156 
157 template <typename RangeType>
159 {
160 }
161 
162 template <typename RangeType>
164  Threads::split /*split*/)
165  : _mesh(x._mesh)
166 {
167 }
168 
169 template <typename RangeType>
171 {
172 }
173 
174 template <typename RangeType>
175 void
176 ThreadedElementLoopBase<RangeType>::operator()(const RangeType & range, bool bypass_threading)
177 {
178  try
179  {
180  ParallelUniqueId puid;
181  _tid = bypass_threading ? 0 : puid.id;
182 
183  pre();
184 
187  typename RangeType::const_iterator el = range.begin();
188  for (el = range.begin(); el != range.end(); ++el)
189  {
190  if (!keepGoing())
191  break;
192 
193  const Elem * elem = *el;
194 
195  preElement(elem);
196 
198  _subdomain = elem->subdomain_id();
199  if (_subdomain != _old_subdomain)
201 
202  onElement(elem);
203 
204  for (unsigned int side = 0; side < elem->n_sides(); side++)
205  {
206  std::vector<BoundaryID> boundary_ids = _mesh.getBoundaryIDs(elem, side);
207 
208  if (boundary_ids.size() > 0)
209  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
210  it != boundary_ids.end();
211  ++it)
212  onBoundary(elem, side, *it);
213 
214  const Elem * neighbor = elem->neighbor_ptr(side);
215  if (neighbor != nullptr)
216  {
217  preInternalSide(elem, side);
218 
220  _neighbor_subdomain = neighbor->subdomain_id();
223 
224  onInternalSide(elem, side);
225 
226  if (boundary_ids.size() > 0)
227  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
228  it != boundary_ids.end();
229  ++it)
230  onInterface(elem, side, *it);
231 
232  postInternalSide(elem, side);
233  }
234  } // sides
235  postElement(elem);
236 
237  } // range
238 
239  post();
240  }
241  catch (MooseException & e)
242  {
244  }
245 }
246 
247 template <typename RangeType>
248 void
250 {
251 }
252 
253 template <typename RangeType>
254 void
256 {
257 }
258 
259 template <typename RangeType>
260 void
262 {
263 }
264 
265 template <typename RangeType>
266 void
268 {
269 }
270 
271 template <typename RangeType>
272 void
274 {
275 }
276 
277 template <typename RangeType>
278 void
280  unsigned int /*side*/,
281  BoundaryID /*bnd_id*/)
282 {
283 }
284 
285 template <typename RangeType>
286 void
287 ThreadedElementLoopBase<RangeType>::preInternalSide(const Elem * /*elem*/, unsigned int /*side*/)
288 {
289 }
290 
291 template <typename RangeType>
292 void
293 ThreadedElementLoopBase<RangeType>::postInternalSide(const Elem * /*elem*/, unsigned int /*side*/)
294 {
295 }
296 
297 template <typename RangeType>
298 void
299 ThreadedElementLoopBase<RangeType>::onInternalSide(const Elem * /*elem*/, unsigned int /*side*/)
300 {
301 }
302 
303 template <typename RangeType>
304 void
306  unsigned int /*side*/,
307  BoundaryID /*bnd_id*/)
308 {
309 }
310 
311 template <typename RangeType>
312 void
314 {
315 }
316 
317 template <typename RangeType>
318 void
320 {
321 }
322 
323 #endif // THREADEDELEMENTLOOPBASE_H
virtual bool keepGoing()
Whether or not the loop should continue.
virtual void onElement(const Elem *elem)
Assembly of the element (not including surface assembly)
subdomain_id_type SubdomainID
Definition: MooseTypes.h:77
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
Returns a vector of boundary IDs for the requested element on the requested side. ...
Definition: MooseMesh.C:1990
virtual void pre()
Called before the element range loop.
virtual void subdomainChanged()
Called every time the current subdomain changes (i.e.
virtual void neighborSubdomainChanged()
Called every time the neighbor subdomain changes (i.e.
static PetscErrorCode Vec x
virtual void preInternalSide(const Elem *elem, unsigned int side)
Called before evaluations on an element internal side.
virtual void postInternalSide(const Elem *elem, unsigned int side)
Called after evaluations on an element internal side.
const SubdomainID INVALID_BLOCK_ID
Definition: MooseTypes.h:118
virtual void postElement(const Elem *elem)
Called after the element assembly is done (including surface assembling)
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
virtual void onInterface(const Elem *elem, unsigned int side, BoundaryID bnd_id)
Called when doing interface assembling.
SubdomainID _old_neighbor_subdomain
The subdomain for the last neighbor.
void operator()(const RangeType &range, bool bypass_threading=false)
virtual void onInternalSide(const Elem *elem, unsigned int side)
Called when doing internal edge assembling.
Provides a way for users to bail out of the current solve.
virtual void caughtMooseException(MooseException &)
Called if a MooseException is caught anywhere during the computation.
Base class for assembly-like calculations.
SubdomainID _subdomain
The subdomain for the current element.
SubdomainID _old_subdomain
The subdomain for the last element.
virtual void post()
Called after the element range loop.
virtual void preElement(const Elem *elem)
Called before the element assembly.
ThreadedElementLoopBase(MooseMesh &mesh)
SubdomainID _neighbor_subdomain
The subdomain for the current neighbor.
unsigned int THREAD_ID
Definition: MooseTypes.h:79
boundary_id_type BoundaryID
Definition: MooseTypes.h:75
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id)
Called when doing boundary assembling.