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 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
 
QBase *& _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 59 of file ElementLoopUserObject.h.

Constructor & Destructor Documentation

ElementLoopUserObject::ElementLoopUserObject ( const InputParameters &  parameters)

Definition at line 19 of file ElementLoopUserObject.C.

20  : GeneralUserObject(parameters),
21  BlockRestrictable(this),
22  Coupleable(this, false),
23  MooseVariableDependencyInterface(),
24  ZeroInterface(parameters),
25  _mesh(_subproblem.mesh()),
26  _current_elem(_assembly.elem()),
27  _current_elem_volume(_assembly.elemVolume()),
28  _q_point(_assembly.qPoints()),
29  _qrule(_assembly.qRule()),
30  _JxW(_assembly.JxW()),
31  _coord(_assembly.coordTransformation()),
33 {
34  // Keep track of which variables are coupled so we know what we depend on
35  const std::vector<MooseVariable *> & coupled_vars = getCoupledMooseVars();
36  for (unsigned int i = 0; i < coupled_vars.size(); i++)
37  addMooseVariableDependency(coupled_vars[i]);
38 }
const MooseArray< Real > & _JxW
const MooseArray< Point > & _q_point
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...
ElementLoopUserObject::ElementLoopUserObject ( ElementLoopUserObject x,
Threads::split  split 
)

Definition at line 40 of file ElementLoopUserObject.C.

41  : GeneralUserObject(x.parameters()),
42  BlockRestrictable(&x),
43  Coupleable(this, false),
44  MooseVariableDependencyInterface(),
45  ZeroInterface(x.parameters()),
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<MooseVariable *> & coupled_vars = x.getCoupledMooseVars();
57  for (unsigned int i = 0; i < coupled_vars.size(); i++)
58  addMooseVariableDependency(coupled_vars[i]);
59 }
const MooseArray< Real > & _JxW
const MooseArray< Point > & _q_point
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...
ElementLoopUserObject::~ElementLoopUserObject ( )
virtual

Definition at line 61 of file ElementLoopUserObject.C.

61 {}

Member Function Documentation

void ElementLoopUserObject::caughtMooseException ( MooseException &  e)
protectedvirtual

Definition at line 253 of file ElementLoopUserObject.C.

Referenced by execute().

254 {
255  std::string what(e.what());
256  _fe_problem.setException(what);
257 }
void ElementLoopUserObject::computeBoundary ( )
protectedvirtual

Definition at line 231 of file ElementLoopUserObject.C.

Referenced by onBoundary().

232 {
233 }
void ElementLoopUserObject::computeElement ( )
protectedvirtual

Reimplemented in SlopeLimitingBase, and SlopeReconstructionBase.

Definition at line 226 of file ElementLoopUserObject.C.

Referenced by onElement().

227 {
228 }
void ElementLoopUserObject::computeInterface ( )
protectedvirtual

Definition at line 241 of file ElementLoopUserObject.C.

Referenced by onInterface().

242 {
243 }
void ElementLoopUserObject::computeInternalSide ( )
protectedvirtual

Definition at line 236 of file ElementLoopUserObject.C.

Referenced by onInternalSide().

237 {
238 }
void ElementLoopUserObject::execute ( )
virtual

Definition at line 69 of file ElementLoopUserObject.C.

70 {
71  ConstElemRange & elem_range = *_mesh.getActiveLocalElementRange();
72 
73  try
74  {
75  pre();
76 
77  _subdomain = std::numeric_limits<SubdomainID>::max();
78  ConstElemRange::const_iterator el = elem_range.begin();
79  for (el = elem_range.begin(); el != elem_range.end(); ++el)
80  {
81  if (!keepGoing())
82  break;
83 
84  const Elem * elem = *el;
85  unsigned int cur_subdomain = elem->subdomain_id();
86 
88  _subdomain = cur_subdomain;
89 
90  if (this->hasBlocks(_subdomain))
91  {
94 
95  onElement(elem);
96 
97  for (unsigned int side = 0; side < elem->n_sides(); side++)
98  {
99  std::vector<BoundaryID> boundary_ids = _mesh.getBoundaryIDs(elem, side);
100 
101  if (boundary_ids.size() > 0)
102  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
103  it != boundary_ids.end();
104  ++it)
105  onBoundary(elem, side, *it);
106 
107  if (elem->neighbor(side) != NULL)
108  {
109  if (this->hasBlocks(elem->neighbor(side)->subdomain_id()))
110  onInternalSide(elem, side);
111  if (boundary_ids.size() > 0)
112  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
113  it != boundary_ids.end();
114  ++it)
115  onInterface(elem, side, *it);
116  }
117  } // sides
118  }
119  } // range
120 
121  post();
122  }
123  catch (MooseException & e)
124  {
126  }
127 }
virtual void onInterface(const Elem *elem, unsigned int side, BoundaryID bnd_id)
virtual void onInternalSide(const Elem *elem, unsigned int side)
virtual void caughtMooseException(MooseException &e)
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id)
SubdomainID _subdomain
The subdomain for the current element.
virtual void onElement(const Elem *elem)
SubdomainID _old_subdomain
The subdomain for the last element.
void ElementLoopUserObject::finalize ( )
virtual

Reimplemented in SlopeLimitingBase, and SlopeReconstructionBase.

Definition at line 130 of file ElementLoopUserObject.C.

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

131 {
132  _have_interface_elems = true;
133 }
bool _have_interface_elems
true if we have cached interface elements, false if they need to be cached. We want to (re)cache only...
void ElementLoopUserObject::initialize ( )
virtual

Reimplemented in SlopeLimitingBase, and SlopeReconstructionBase.

Definition at line 64 of file ElementLoopUserObject.C.

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

65 {
66 }
void ElementLoopUserObject::join ( const ElementLoopUserObject )

Definition at line 221 of file ElementLoopUserObject.C.

222 {
223 }
virtual bool ElementLoopUserObject::keepGoing ( )
inlinevirtual

Definition at line 81 of file ElementLoopUserObject.h.

Referenced by execute().

81 { return true; }
void ElementLoopUserObject::meshChanged ( )
virtual

Reimplemented in SlopeReconstructionBase.

Definition at line 246 of file ElementLoopUserObject.C.

Referenced by SlopeReconstructionBase::meshChanged().

247 {
248  _interface_elem_ids.clear();
249  _have_interface_elems = false;
250 }
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...
bool _have_interface_elems
true if we have cached interface elements, false if they need to be cached. We want to (re)cache only...
void ElementLoopUserObject::onBoundary ( const Elem *  elem,
unsigned int  side,
BoundaryID  bnd_id 
)
virtual

Definition at line 153 of file ElementLoopUserObject.C.

Referenced by execute().

154 {
155  _current_side = side;
156  computeBoundary();
157 }
void ElementLoopUserObject::onElement ( const Elem *  elem)
virtual

Definition at line 146 of file ElementLoopUserObject.C.

Referenced by execute().

147 {
148  _current_elem = elem;
149  computeElement();
150 }
void ElementLoopUserObject::onInterface ( const Elem *  elem,
unsigned int  side,
BoundaryID  bnd_id 
)
virtual

Definition at line 188 of file ElementLoopUserObject.C.

Referenced by execute().

189 {
190  _current_elem = elem;
191  // Pointer to the neighbor we are currently working on.
192  _current_neighbor = elem->neighbor(side);
193 
194  // Get the global id of the element and the neighbor
195  const dof_id_type elem_id = elem->id();
196  const dof_id_type neighbor_id = _current_neighbor->id();
197 
198  // TODO: add if-statement to check if this needs to be executed
199  if ((_current_neighbor->active() && (_current_neighbor->level() == elem->level()) &&
200  (elem_id < neighbor_id)) ||
201  (_current_neighbor->level() < elem->level()))
202  {
204  }
205 
206  if (!_have_interface_elems &&
207  (_current_elem->processor_id() != _current_neighbor->processor_id()))
208  {
209  // if my current neighbor is on another processor store the current element
210  // ID for later communication
211  _interface_elem_ids.insert(_current_elem->id());
212  }
213 }
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...
bool _have_interface_elems
true if we have cached interface elements, false if they need to be cached. We want to (re)cache only...
void ElementLoopUserObject::onInternalSide ( const Elem *  elem,
unsigned int  side 
)
virtual

Definition at line 160 of file ElementLoopUserObject.C.

Referenced by execute().

161 {
162  _current_elem = elem;
163  // Pointer to the neighbor we are currently working on.
164  _current_neighbor = elem->neighbor(side);
165 
166  // Get the global id of the element and the neighbor
167  const dof_id_type elem_id = elem->id();
168  const dof_id_type neighbor_id = _current_neighbor->id();
169 
170  // TODO: add if-statement to check if this needs to be executed
171  if ((_current_neighbor->active() && (_current_neighbor->level() == elem->level()) &&
172  (elem_id < neighbor_id)) ||
173  (_current_neighbor->level() < elem->level()))
174  {
176  }
177 
178  if (!_have_interface_elems &&
179  (_current_elem->processor_id() != _current_neighbor->processor_id()))
180  {
181  // if my current neighbor is on another processor store the current element ID for later
182  // communication
183  _interface_elem_ids.insert(_current_elem->id());
184  }
185 }
virtual void computeInternalSide()
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...
bool _have_interface_elems
true if we have cached interface elements, false if they need to be cached. We want to (re)cache only...
void ElementLoopUserObject::post ( )
virtual

Definition at line 216 of file ElementLoopUserObject.C.

Referenced by execute().

217 {
218 }
void ElementLoopUserObject::pre ( )
virtual

Definition at line 136 of file ElementLoopUserObject.C.

Referenced by execute().

137 {
138 }
void ElementLoopUserObject::subdomainChanged ( )
virtual

Definition at line 141 of file ElementLoopUserObject.C.

Referenced by execute().

142 {
143 }

Member Data Documentation

const MooseArray<Real>& ElementLoopUserObject::_coord
protected

Definition at line 100 of file ElementLoopUserObject.h.

const Elem* ElementLoopUserObject::_current_elem
protected
const Real& ElementLoopUserObject::_current_elem_volume
protected
const Elem* ElementLoopUserObject::_current_neighbor
protected

Definition at line 95 of file ElementLoopUserObject.h.

Referenced by onInterface(), and onInternalSide().

unsigned int ElementLoopUserObject::_current_side
protected

Definition at line 94 of file ElementLoopUserObject.h.

Referenced by onBoundary().

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 103 of file ElementLoopUserObject.h.

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

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 105 of file ElementLoopUserObject.h.

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

const MooseArray<Real>& ElementLoopUserObject::_JxW
protected

Definition at line 99 of file ElementLoopUserObject.h.

MooseMesh& ElementLoopUserObject::_mesh
protected
SubdomainID ElementLoopUserObject::_old_subdomain
protected

The subdomain for the last element.

Definition at line 111 of file ElementLoopUserObject.h.

Referenced by execute().

const MooseArray<Point>& ElementLoopUserObject::_q_point
protected

Definition at line 97 of file ElementLoopUserObject.h.

QBase*& ElementLoopUserObject::_qrule
protected

Definition at line 98 of file ElementLoopUserObject.h.

SubdomainID ElementLoopUserObject::_subdomain
protected

The subdomain for the current element.

Definition at line 108 of file ElementLoopUserObject.h.

Referenced by execute().


The documentation for this class was generated from the following files: