www.mooseframework.org
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ElementLoopUserObject Class Reference

A base class that loops over elements and do things. More...

#include <ElementLoopUserObject.h>

Inheritance diagram for ElementLoopUserObject:
[legend]

Public Member Functions

 ElementLoopUserObject (const InputParameters &parameters)
 
 ElementLoopUserObject (ElementLoopUserObject &x, Threads::split split)
 
virtual ~ElementLoopUserObject ()
 
virtual void initialize ()
 
virtual void execute ()
 
virtual void finalize ()
 
virtual void pre ()
 
virtual void preElement (const Elem *elem)
 
virtual void onElement (const Elem *elem)
 
virtual void onBoundary (const Elem *elem, unsigned int side, BoundaryID bnd_id)
 
virtual void onInternalSide (const Elem *elem, unsigned int side)
 
virtual void onInterface (const Elem *elem, unsigned int side, BoundaryID bnd_id)
 
virtual void post ()
 
virtual void subdomainChanged ()
 
virtual bool keepGoing ()
 
virtual void meshChanged ()
 
void join (const ElementLoopUserObject &)
 

Protected Member Functions

virtual void caughtMooseException (MooseException &e)
 
virtual void computeElement ()
 
virtual void computeBoundary ()
 
virtual void computeInternalSide ()
 
virtual void computeInterface ()
 

Protected Attributes

MooseMesh & _mesh
 
const Elem * _current_elem
 
const Real & _current_elem_volume
 
unsigned int _current_side
 
const Elem * _current_neighbor
 
const MooseArray< Point > & _q_point
 
const QBase *const & _qrule
 
const MooseArray< Real > & _JxW
 
const MooseArray< Real > & _coord
 
bool _have_interface_elems
 true if we have cached interface elements, false if they need to be cached. We want to (re)cache only when mesh changed More...
 
std::set< dof_id_type > _interface_elem_ids
 List of element IDs that are on the processor boundary and need to be send to other processors. More...
 
SubdomainID _subdomain
 The subdomain for the current element. More...
 
SubdomainID _old_subdomain
 The subdomain for the last element. More...
 

Detailed Description

A base class that loops over elements and do things.

Notes:

  1. this class is designed to enable more than one element-loop in the execution of user objects. It is necessary because in many numerical schemes, the data required in one element-loop should be pre-computed from another element-loop.

    For example, in the workflow of a cell-centered finite volume method, two element-loops are required in a specific sequence in user objects:

    First, an element-loop is requried to calculate the in-cell gradients of variables using a piecewise linear reconstruction scheme.

    Second, another element-loop is required to calculate the limited in-cell gradients of variables based on the reconstructed gradients from the element and its face-neighboring elements.

Definition at line 58 of file ElementLoopUserObject.h.

Constructor & Destructor Documentation

◆ ElementLoopUserObject() [1/2]

ElementLoopUserObject::ElementLoopUserObject ( const InputParameters &  parameters)

Definition at line 21 of file ElementLoopUserObject.C.

22  : GeneralUserObject(parameters),
23  BlockRestrictable(this),
24  Coupleable(this, false),
25  MooseVariableDependencyInterface(),
26  _mesh(_subproblem.mesh()),
27  _current_elem(_assembly.elem()),
28  _current_elem_volume(_assembly.elemVolume()),
29  _q_point(_assembly.qPoints()),
30  _qrule(_assembly.qRule()),
31  _JxW(_assembly.JxW()),
32  _coord(_assembly.coordTransformation()),
34 {
35  // Keep track of which variables are coupled so we know what we depend on
36  const std::vector<MooseVariableFEBase *> & coupled_vars = getCoupledMooseVars();
37  for (unsigned int i = 0; i < coupled_vars.size(); i++)
38  addMooseVariableDependency(coupled_vars[i]);
39 }

◆ ElementLoopUserObject() [2/2]

ElementLoopUserObject::ElementLoopUserObject ( ElementLoopUserObject x,
Threads::split  split 
)

Definition at line 41 of file ElementLoopUserObject.C.

42  : GeneralUserObject(x.parameters()),
43  BlockRestrictable(&x),
44  Coupleable(this, false),
45  MooseVariableDependencyInterface(),
46  _mesh(x._subproblem.mesh()),
47  _current_elem(x._assembly.elem()),
48  _current_elem_volume(x._assembly.elemVolume()),
49  _q_point(x._assembly.qPoints()),
50  _qrule(x._assembly.qRule()),
51  _JxW(x._assembly.JxW()),
52  _coord(x._assembly.coordTransformation()),
54 {
55  // Keep track of which variables are coupled so we know what we depend on
56  const std::vector<MooseVariableFEBase *> & coupled_vars = x.getCoupledMooseVars();
57  for (unsigned int i = 0; i < coupled_vars.size(); i++)
58  addMooseVariableDependency(coupled_vars[i]);
59 }

◆ ~ElementLoopUserObject()

ElementLoopUserObject::~ElementLoopUserObject ( )
virtual

Definition at line 61 of file ElementLoopUserObject.C.

61 {}

Member Function Documentation

◆ caughtMooseException()

void ElementLoopUserObject::caughtMooseException ( MooseException &  e)
protectedvirtual

Definition at line 260 of file ElementLoopUserObject.C.

261 {
262  std::string what(e.what());
263  _fe_problem.setException(what);
264 }

Referenced by execute().

◆ computeBoundary()

void ElementLoopUserObject::computeBoundary ( )
protectedvirtual

Definition at line 238 of file ElementLoopUserObject.C.

239 {
240 }

Referenced by onBoundary().

◆ computeElement()

void ElementLoopUserObject::computeElement ( )
protectedvirtual

Reimplemented in SlopeReconstructionBase, and SlopeLimitingBase.

Definition at line 233 of file ElementLoopUserObject.C.

234 {
235 }

Referenced by onElement().

◆ computeInterface()

void ElementLoopUserObject::computeInterface ( )
protectedvirtual

Definition at line 248 of file ElementLoopUserObject.C.

249 {
250 }

Referenced by onInterface().

◆ computeInternalSide()

void ElementLoopUserObject::computeInternalSide ( )
protectedvirtual

Definition at line 243 of file ElementLoopUserObject.C.

244 {
245 }

Referenced by onInternalSide().

◆ execute()

void ElementLoopUserObject::execute ( )
virtual

Definition at line 75 of file ElementLoopUserObject.C.

76 {
77  ConstElemRange & elem_range = *_mesh.getActiveLocalElementRange();
78 
79  try
80  {
81  pre();
82 
83  _subdomain = std::numeric_limits<SubdomainID>::max();
84  ConstElemRange::const_iterator el = elem_range.begin();
85  for (el = elem_range.begin(); el != elem_range.end(); ++el)
86  {
87  if (!keepGoing())
88  break;
89 
90  const Elem * elem = *el;
91  unsigned int cur_subdomain = elem->subdomain_id();
92  preElement(elem);
93 
95  _subdomain = cur_subdomain;
96 
97  if (this->hasBlocks(_subdomain))
98  {
101 
102  onElement(elem);
103 
104  for (unsigned int side = 0; side < elem->n_sides(); side++)
105  {
106  std::vector<BoundaryID> boundary_ids = _mesh.getBoundaryIDs(elem, side);
107 
108  if (boundary_ids.size() > 0)
109  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
110  it != boundary_ids.end();
111  ++it)
112  onBoundary(elem, side, *it);
113 
114  if (elem->neighbor_ptr(side) != NULL)
115  {
116  if (this->hasBlocks(elem->neighbor_ptr(side)->subdomain_id()))
117  onInternalSide(elem, side);
118  if (boundary_ids.size() > 0)
119  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
120  it != boundary_ids.end();
121  ++it)
122  onInterface(elem, side, *it);
123  }
124  } // sides
125  }
126  } // range
127 
128  post();
129  }
130  catch (MooseException & e)
131  {
133  }
134 }

◆ finalize()

void ElementLoopUserObject::finalize ( )
virtual

Reimplemented in SlopeReconstructionBase, and SlopeLimitingBase.

Definition at line 137 of file ElementLoopUserObject.C.

138 {
139  _have_interface_elems = true;
140 }

Referenced by SlopeLimitingBase::finalize(), and SlopeReconstructionBase::finalize().

◆ initialize()

void ElementLoopUserObject::initialize ( )
virtual

Reimplemented in SlopeReconstructionBase, and SlopeLimitingBase.

Definition at line 64 of file ElementLoopUserObject.C.

65 {
66 }

Referenced by SlopeLimitingBase::initialize(), and SlopeReconstructionBase::initialize().

◆ join()

void ElementLoopUserObject::join ( const ElementLoopUserObject )

Definition at line 228 of file ElementLoopUserObject.C.

229 {
230 }

◆ keepGoing()

virtual bool ElementLoopUserObject::keepGoing ( )
inlinevirtual

Definition at line 80 of file ElementLoopUserObject.h.

80 { return true; }

Referenced by execute().

◆ meshChanged()

void ElementLoopUserObject::meshChanged ( )
virtual

Reimplemented in SlopeReconstructionBase.

Definition at line 253 of file ElementLoopUserObject.C.

254 {
255  _interface_elem_ids.clear();
256  _have_interface_elems = false;
257 }

Referenced by SlopeReconstructionBase::meshChanged().

◆ onBoundary()

void ElementLoopUserObject::onBoundary ( const Elem *  elem,
unsigned int  side,
BoundaryID  bnd_id 
)
virtual

Definition at line 160 of file ElementLoopUserObject.C.

161 {
162  _current_side = side;
163  computeBoundary();
164 }

Referenced by execute().

◆ onElement()

void ElementLoopUserObject::onElement ( const Elem *  elem)
virtual

Definition at line 153 of file ElementLoopUserObject.C.

154 {
155  _current_elem = elem;
156  computeElement();
157 }

Referenced by execute().

◆ onInterface()

void ElementLoopUserObject::onInterface ( const Elem *  elem,
unsigned int  side,
BoundaryID  bnd_id 
)
virtual

Definition at line 195 of file ElementLoopUserObject.C.

196 {
197  _current_elem = elem;
198  // Pointer to the neighbor we are currently working on.
199  _current_neighbor = elem->neighbor_ptr(side);
200 
201  // Get the global id of the element and the neighbor
202  const dof_id_type elem_id = elem->id();
203  const dof_id_type neighbor_id = _current_neighbor->id();
204 
205  // TODO: add if-statement to check if this needs to be executed
206  if ((_current_neighbor->active() && (_current_neighbor->level() == elem->level()) &&
207  (elem_id < neighbor_id)) ||
208  (_current_neighbor->level() < elem->level()))
209  {
211  }
212 
213  if (!_have_interface_elems &&
214  (_current_elem->processor_id() != _current_neighbor->processor_id()))
215  {
216  // if my current neighbor is on another processor store the current element
217  // ID for later communication
218  _interface_elem_ids.insert(_current_elem->id());
219  }
220 }

Referenced by execute().

◆ onInternalSide()

void ElementLoopUserObject::onInternalSide ( const Elem *  elem,
unsigned int  side 
)
virtual

Definition at line 167 of file ElementLoopUserObject.C.

168 {
169  _current_elem = elem;
170  // Pointer to the neighbor we are currently working on.
171  _current_neighbor = elem->neighbor_ptr(side);
172 
173  // Get the global id of the element and the neighbor
174  const dof_id_type elem_id = elem->id();
175  const dof_id_type neighbor_id = _current_neighbor->id();
176 
177  // TODO: add if-statement to check if this needs to be executed
178  if ((_current_neighbor->active() && (_current_neighbor->level() == elem->level()) &&
179  (elem_id < neighbor_id)) ||
180  (_current_neighbor->level() < elem->level()))
181  {
183  }
184 
185  if (!_have_interface_elems &&
186  (_current_elem->processor_id() != _current_neighbor->processor_id()))
187  {
188  // if my current neighbor is on another processor store the current element ID for later
189  // communication
190  _interface_elem_ids.insert(_current_elem->id());
191  }
192 }

Referenced by execute().

◆ post()

void ElementLoopUserObject::post ( )
virtual

Definition at line 223 of file ElementLoopUserObject.C.

224 {
225 }

Referenced by execute().

◆ pre()

void ElementLoopUserObject::pre ( )
virtual

Definition at line 143 of file ElementLoopUserObject.C.

144 {
145 }

Referenced by execute().

◆ preElement()

void ElementLoopUserObject::preElement ( const Elem *  elem)
virtual

Definition at line 69 of file ElementLoopUserObject.C.

70 {
71  _fe_problem.setCurrentSubdomainID(elem, _tid);
72 }

Referenced by execute().

◆ subdomainChanged()

void ElementLoopUserObject::subdomainChanged ( )
virtual

Definition at line 148 of file ElementLoopUserObject.C.

149 {
150 }

Referenced by execute().

Member Data Documentation

◆ _coord

const MooseArray<Real>& ElementLoopUserObject::_coord
protected

Definition at line 99 of file ElementLoopUserObject.h.

◆ _current_elem

const Elem* ElementLoopUserObject::_current_elem
protected

◆ _current_elem_volume

const Real& ElementLoopUserObject::_current_elem_volume
protected

Definition at line 92 of file ElementLoopUserObject.h.

◆ _current_neighbor

const Elem* ElementLoopUserObject::_current_neighbor
protected

Definition at line 94 of file ElementLoopUserObject.h.

Referenced by onInterface(), and onInternalSide().

◆ _current_side

unsigned int ElementLoopUserObject::_current_side
protected

Definition at line 93 of file ElementLoopUserObject.h.

Referenced by onBoundary().

◆ _have_interface_elems

bool ElementLoopUserObject::_have_interface_elems
protected

true if we have cached interface elements, false if they need to be cached. We want to (re)cache only when mesh changed

Definition at line 102 of file ElementLoopUserObject.h.

Referenced by finalize(), meshChanged(), onInterface(), and onInternalSide().

◆ _interface_elem_ids

std::set<dof_id_type> ElementLoopUserObject::_interface_elem_ids
protected

List of element IDs that are on the processor boundary and need to be send to other processors.

Definition at line 104 of file ElementLoopUserObject.h.

Referenced by meshChanged(), onInterface(), onInternalSide(), SlopeLimitingBase::serialize(), and SlopeReconstructionBase::serialize().

◆ _JxW

const MooseArray<Real>& ElementLoopUserObject::_JxW
protected

Definition at line 98 of file ElementLoopUserObject.h.

◆ _mesh

MooseMesh& ElementLoopUserObject::_mesh
protected

◆ _old_subdomain

SubdomainID ElementLoopUserObject::_old_subdomain
protected

The subdomain for the last element.

Definition at line 110 of file ElementLoopUserObject.h.

Referenced by execute().

◆ _q_point

const MooseArray<Point>& ElementLoopUserObject::_q_point
protected

Definition at line 96 of file ElementLoopUserObject.h.

◆ _qrule

const QBase* const & ElementLoopUserObject::_qrule
protected

Definition at line 97 of file ElementLoopUserObject.h.

◆ _subdomain

SubdomainID ElementLoopUserObject::_subdomain
protected

The subdomain for the current element.

Definition at line 107 of file ElementLoopUserObject.h.

Referenced by execute().


The documentation for this class was generated from the following files:
ElementLoopUserObject::_mesh
MooseMesh & _mesh
Definition: ElementLoopUserObject.h:89
ElementLoopUserObject::computeInternalSide
virtual void computeInternalSide()
Definition: ElementLoopUserObject.C:243
ElementLoopUserObject::computeBoundary
virtual void computeBoundary()
Definition: ElementLoopUserObject.C:238
ElementLoopUserObject::_current_side
unsigned int _current_side
Definition: ElementLoopUserObject.h:93
ElementLoopUserObject::_interface_elem_ids
std::set< dof_id_type > _interface_elem_ids
List of element IDs that are on the processor boundary and need to be send to other processors.
Definition: ElementLoopUserObject.h:104
ElementLoopUserObject::keepGoing
virtual bool keepGoing()
Definition: ElementLoopUserObject.h:80
ElementLoopUserObject::_coord
const MooseArray< Real > & _coord
Definition: ElementLoopUserObject.h:99
ElementLoopUserObject::computeInterface
virtual void computeInterface()
Definition: ElementLoopUserObject.C:248
ElementLoopUserObject::_subdomain
SubdomainID _subdomain
The subdomain for the current element.
Definition: ElementLoopUserObject.h:107
ElementLoopUserObject::preElement
virtual void preElement(const Elem *elem)
Definition: ElementLoopUserObject.C:69
ElementLoopUserObject::onBoundary
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id)
Definition: ElementLoopUserObject.C:160
ElementLoopUserObject::_have_interface_elems
bool _have_interface_elems
true if we have cached interface elements, false if they need to be cached. We want to (re)cache only...
Definition: ElementLoopUserObject.h:102
ElementLoopUserObject::pre
virtual void pre()
Definition: ElementLoopUserObject.C:143
ElementLoopUserObject::onElement
virtual void onElement(const Elem *elem)
Definition: ElementLoopUserObject.C:153
ElementLoopUserObject::post
virtual void post()
Definition: ElementLoopUserObject.C:223
ElementLoopUserObject::onInternalSide
virtual void onInternalSide(const Elem *elem, unsigned int side)
Definition: ElementLoopUserObject.C:167
ElementLoopUserObject::_old_subdomain
SubdomainID _old_subdomain
The subdomain for the last element.
Definition: ElementLoopUserObject.h:110
ElementLoopUserObject::_current_elem_volume
const Real & _current_elem_volume
Definition: ElementLoopUserObject.h:92
ElementLoopUserObject::_q_point
const MooseArray< Point > & _q_point
Definition: ElementLoopUserObject.h:96
ElementLoopUserObject::caughtMooseException
virtual void caughtMooseException(MooseException &e)
Definition: ElementLoopUserObject.C:260
ElementLoopUserObject::onInterface
virtual void onInterface(const Elem *elem, unsigned int side, BoundaryID bnd_id)
Definition: ElementLoopUserObject.C:195
ElementLoopUserObject::subdomainChanged
virtual void subdomainChanged()
Definition: ElementLoopUserObject.C:148
ElementLoopUserObject::_JxW
const MooseArray< Real > & _JxW
Definition: ElementLoopUserObject.h:98
ElementLoopUserObject::computeElement
virtual void computeElement()
Definition: ElementLoopUserObject.C:233
ElementLoopUserObject::_qrule
const QBase *const & _qrule
Definition: ElementLoopUserObject.h:97
ElementLoopUserObject::_current_elem
const Elem * _current_elem
Definition: ElementLoopUserObject.h:91
ElementLoopUserObject::_current_neighbor
const Elem * _current_neighbor
Definition: ElementLoopUserObject.h:94