www.mooseframework.org
ElementLoopUserObject.C
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 #include "ElementLoopUserObject.h"
11 
14 {
17  return params;
18 }
19 
21  : GeneralUserObject(parameters),
22  BlockRestrictable(this),
23  Coupleable(this, false),
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()),
32  _have_interface_elems(false)
33 {
34  // Keep track of which variables are coupled so we know what we depend on
35  const std::vector<MooseVariableFEBase *> & coupled_vars = getCoupledMooseVars();
36  for (unsigned int i = 0; i < coupled_vars.size(); i++)
37  addMooseVariableDependency(coupled_vars[i]);
38 }
39 
41  : GeneralUserObject(x.parameters()),
43  Coupleable(this, false),
45  _mesh(x._subproblem.mesh()),
46  _current_elem(x._assembly.elem()),
47  _current_elem_volume(x._assembly.elemVolume()),
48  _q_point(x._assembly.qPoints()),
49  _qrule(x._assembly.qRule()),
50  _JxW(x._assembly.JxW()),
51  _coord(x._assembly.coordTransformation()),
52  _have_interface_elems(false)
53 {
54  // Keep track of which variables are coupled so we know what we depend on
55  const std::vector<MooseVariableFEBase *> & coupled_vars = x.getCoupledMooseVars();
56  for (unsigned int i = 0; i < coupled_vars.size(); i++)
57  addMooseVariableDependency(coupled_vars[i]);
58 }
59 
61 
62 void
64 {
65 }
66 
67 void
69 {
71 }
72 
73 void
75 {
77 
78  try
79  {
80  pre();
81 
82  _subdomain = std::numeric_limits<SubdomainID>::max();
83  ConstElemRange::const_iterator el = elem_range.begin();
84  for (el = elem_range.begin(); el != elem_range.end(); ++el)
85  {
86  if (!keepGoing())
87  break;
88 
89  const Elem * elem = *el;
90  unsigned int cur_subdomain = elem->subdomain_id();
91  preElement(elem);
92 
94  _subdomain = cur_subdomain;
95 
96  if (this->hasBlocks(_subdomain))
97  {
100 
101  onElement(elem);
102 
103  for (unsigned int side = 0; side < elem->n_sides(); side++)
104  {
105  std::vector<BoundaryID> boundary_ids = _mesh.getBoundaryIDs(elem, side);
106 
107  if (boundary_ids.size() > 0)
108  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
109  it != boundary_ids.end();
110  ++it)
111  onBoundary(elem, side, *it);
112 
113  if (elem->neighbor_ptr(side) != NULL)
114  {
115  if (this->hasBlocks(elem->neighbor_ptr(side)->subdomain_id()))
116  onInternalSide(elem, side);
117  if (boundary_ids.size() > 0)
118  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
119  it != boundary_ids.end();
120  ++it)
121  onInterface(elem, side, *it);
122  }
123  } // sides
124  }
125  } // range
126 
127  post();
128  }
129  catch (MooseException & e)
130  {
132  }
133 }
134 
135 void
137 {
138  _have_interface_elems = true;
139 }
140 
141 void
143 {
144 }
145 
146 void
148 {
149 }
150 
151 void
153 {
154  _current_elem = elem;
155  computeElement();
156 }
157 
158 void
159 ElementLoopUserObject::onBoundary(const Elem * /*elem*/, unsigned int side, BoundaryID /*bnd_id*/)
160 {
161  _current_side = side;
162  computeBoundary();
163 }
164 
165 void
166 ElementLoopUserObject::onInternalSide(const Elem * elem, unsigned int side)
167 {
168  _current_elem = elem;
169  // Pointer to the neighbor we are currently working on.
170  _current_neighbor = elem->neighbor_ptr(side);
171 
172  // Get the global id of the element and the neighbor
173  const dof_id_type elem_id = elem->id();
174  const dof_id_type neighbor_id = _current_neighbor->id();
175 
176  // TODO: add if-statement to check if this needs to be executed
177  if ((_current_neighbor->active() && (_current_neighbor->level() == elem->level()) &&
178  (elem_id < neighbor_id)) ||
179  (_current_neighbor->level() < elem->level()))
180  {
182  }
183 
184  if (!_have_interface_elems &&
185  (_current_elem->processor_id() != _current_neighbor->processor_id()))
186  {
187  // if my current neighbor is on another processor store the current element ID for later
188  // communication
189  _interface_elem_ids.insert(_current_elem->id());
190  }
191 }
192 
193 void
194 ElementLoopUserObject::onInterface(const Elem * elem, unsigned int side, BoundaryID /*bnd_id*/)
195 {
196  _current_elem = elem;
197  // Pointer to the neighbor we are currently working on.
198  _current_neighbor = elem->neighbor_ptr(side);
199 
200  // Get the global id of the element and the neighbor
201  const dof_id_type elem_id = elem->id();
202  const dof_id_type neighbor_id = _current_neighbor->id();
203 
204  // TODO: add if-statement to check if this needs to be executed
205  if ((_current_neighbor->active() && (_current_neighbor->level() == elem->level()) &&
206  (elem_id < neighbor_id)) ||
207  (_current_neighbor->level() < elem->level()))
208  {
210  }
211 
212  if (!_have_interface_elems &&
213  (_current_elem->processor_id() != _current_neighbor->processor_id()))
214  {
215  // if my current neighbor is on another processor store the current element
216  // ID for later communication
217  _interface_elem_ids.insert(_current_elem->id());
218  }
219 }
220 
221 void
223 {
224 }
225 
226 void
228 {
229 }
230 
231 void
233 {
234 }
235 
236 void
238 {
239 }
240 
241 void
243 {
244 }
245 
246 void
248 {
249 }
250 
251 void
253 {
254  _interface_elem_ids.clear();
255  _have_interface_elems = false;
256 }
257 
258 void
260 {
261  std::string what(e.what());
263 }
ConstElemRange * getActiveLocalElementRange()
virtual const char * what() const
A base class that loops over elements and do things.
static InputParameters validParams()
virtual void setException(const std::string &message)
MeshBase & mesh
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)
static InputParameters validParams()
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id)
ElementLoopUserObject(const InputParameters &parameters)
StoredRange< MeshBase::const_element_iterator, const Elem *> ConstElemRange
static InputParameters validParams()
SubdomainID _subdomain
The subdomain for the current element.
virtual void computeInternalSide()
virtual void preElement(const Elem *elem)
const std::vector< double > x
boundary_id_type BoundaryID
virtual void onElement(const Elem *elem)
SubdomainID _old_subdomain
The subdomain for the last element.
virtual void setCurrentSubdomainID(const Elem *elem, const THREAD_ID tid) override
const std::vector< MooseVariableFieldBase *> & getCoupledMooseVars() const
void addMooseVariableDependency(MooseVariableFieldBase *var)
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...
FEProblemBase & _fe_problem
bool _have_interface_elems
true if we have cached interface elements, false if they need to be cached. We want to (re)cache only...
const THREAD_ID _tid
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
bool hasBlocks(const SubdomainName &name) const
void join(const ElementLoopUserObject &)
uint8_t dof_id_type