www.mooseframework.org
ThreadedElementLoopBase.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "ParallelUniqueId.h"
13 #include "MooseMesh.h"
14 #include "MooseTypes.h"
15 #include "MooseException.h"
16 #include "libmesh/libmesh_exceptions.h"
17 #include "libmesh/elem.h"
18 
22 template <typename RangeType>
24 {
25 public:
27 
29 
30  virtual ~ThreadedElementLoopBase();
31 
32  void operator()(const RangeType & range, bool bypass_threading = false);
33 
37  virtual void pre();
38 
42  virtual void post();
43 
49  virtual void onElement(const Elem * elem);
50 
56  virtual void preElement(const Elem * elem);
57 
63  virtual void postElement(const Elem * elem);
64 
72  virtual void onBoundary(const Elem * elem, unsigned int side, BoundaryID bnd_id);
73 
80  virtual void preInternalSide(const Elem * elem, unsigned int side);
81 
88  virtual void postInternalSide(const Elem * elem, unsigned int side);
89 
96  virtual void onInternalSide(const Elem * elem, unsigned int side);
97 
105  virtual void onInterface(const Elem * elem, unsigned int side, BoundaryID bnd_id);
106 
113  virtual void subdomainChanged();
114 
121  virtual void neighborSubdomainChanged();
122 
128 
134  virtual bool keepGoing() { return true; }
135 
136 protected:
139 
142 
145 
148 
151 };
152 
153 template <typename RangeType>
155 {
156 }
157 
158 template <typename RangeType>
160  Threads::split /*split*/)
161  : _mesh(x._mesh)
162 {
163 }
164 
165 template <typename RangeType>
167 {
168 }
169 
170 template <typename RangeType>
171 void
172 ThreadedElementLoopBase<RangeType>::operator()(const RangeType & range, bool bypass_threading)
173 {
174  try
175  {
176  try
177  {
178  ParallelUniqueId puid;
179  _tid = bypass_threading ? 0 : puid.id;
180 
181  pre();
182 
183  _subdomain = Moose::INVALID_BLOCK_ID;
184  _neighbor_subdomain = Moose::INVALID_BLOCK_ID;
185  typename RangeType::const_iterator el = range.begin();
186  for (el = range.begin(); el != range.end(); ++el)
187  {
188  if (!keepGoing())
189  break;
190 
191  const Elem * elem = *el;
192 
193  preElement(elem);
194 
195  _old_subdomain = _subdomain;
196  _subdomain = elem->subdomain_id();
197  if (_subdomain != _old_subdomain)
198  subdomainChanged();
199 
200  onElement(elem);
201 
202  for (unsigned int side = 0; side < elem->n_sides(); side++)
203  {
204  std::vector<BoundaryID> boundary_ids = _mesh.getBoundaryIDs(elem, side);
205 
206  if (boundary_ids.size() > 0)
207  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
208  it != boundary_ids.end();
209  ++it)
210  onBoundary(elem, side, *it);
211 
212  const Elem * neighbor = elem->neighbor_ptr(side);
213  if (neighbor != nullptr)
214  {
215  preInternalSide(elem, side);
216 
217  _old_neighbor_subdomain = _neighbor_subdomain;
218  _neighbor_subdomain = neighbor->subdomain_id();
219  if (_neighbor_subdomain != _old_neighbor_subdomain)
220  neighborSubdomainChanged();
221 
222  onInternalSide(elem, side);
223 
224  if (boundary_ids.size() > 0)
225  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
226  it != boundary_ids.end();
227  ++it)
228  onInterface(elem, side, *it);
229 
230  postInternalSide(elem, side);
231  }
232  } // sides
233  postElement(elem);
234 
235  } // range
236 
237  post();
238  }
239  catch (libMesh::LogicError & e)
240  {
241  throw MooseException("We caught a libMesh error");
242  }
243  }
244  catch (MooseException & e)
245  {
246  caughtMooseException(e);
247  }
248 }
249 
250 template <typename RangeType>
251 void
253 {
254 }
255 
256 template <typename RangeType>
257 void
259 {
260 }
261 
262 template <typename RangeType>
263 void
265 {
266 }
267 
268 template <typename RangeType>
269 void
271 {
272 }
273 
274 template <typename RangeType>
275 void
277 {
278 }
279 
280 template <typename RangeType>
281 void
283  unsigned int /*side*/,
284  BoundaryID /*bnd_id*/)
285 {
286 }
287 
288 template <typename RangeType>
289 void
290 ThreadedElementLoopBase<RangeType>::preInternalSide(const Elem * /*elem*/, unsigned int /*side*/)
291 {
292 }
293 
294 template <typename RangeType>
295 void
296 ThreadedElementLoopBase<RangeType>::postInternalSide(const Elem * /*elem*/, unsigned int /*side*/)
297 {
298 }
299 
300 template <typename RangeType>
301 void
302 ThreadedElementLoopBase<RangeType>::onInternalSide(const Elem * /*elem*/, unsigned int /*side*/)
303 {
304 }
305 
306 template <typename RangeType>
307 void
309  unsigned int /*side*/,
310  BoundaryID /*bnd_id*/)
311 {
312 }
313 
314 template <typename RangeType>
315 void
317 {
318 }
319 
320 template <typename RangeType>
321 void
323 {
324 }
325 
virtual bool keepGoing()
Whether or not the loop should continue.
virtual void onElement(const Elem *elem)
Assembly of the element (not including surface assembly)
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.C:16
std::vector< std::string > split(const std::string &str, const std::string &delimiter)
Python like split function for strings.
Definition: MooseUtils.C:736
virtual void postElement(const Elem *elem)
Called after the element assembly is done (including surface assembling)
boundary_id_type BoundaryID
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.
subdomain_id_type SubdomainID
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:161
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id)
Called when doing boundary assembling.