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 
12 template <>
13 InputParameters
15 {
16  InputParameters params = validParams<GeneralUserObject>();
17  params += validParams<BlockRestrictable>();
18  return params;
19 }
20 
21 ElementLoopUserObject::ElementLoopUserObject(const InputParameters & parameters)
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()),
33  _have_interface_elems(false)
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 }
40 
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()),
53  _have_interface_elems(false)
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 }
60 
62 
63 void
65 {
66 }
67 
68 void
70 {
71  _fe_problem.setCurrentSubdomainID(elem, _tid);
72 }
73 
74 void
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 }
135 
136 void
138 {
139  _have_interface_elems = true;
140 }
141 
142 void
144 {
145 }
146 
147 void
149 {
150 }
151 
152 void
154 {
155  _current_elem = elem;
156  computeElement();
157 }
158 
159 void
160 ElementLoopUserObject::onBoundary(const Elem * /*elem*/, unsigned int side, BoundaryID /*bnd_id*/)
161 {
162  _current_side = side;
163  computeBoundary();
164 }
165 
166 void
167 ElementLoopUserObject::onInternalSide(const Elem * elem, unsigned int side)
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 }
193 
194 void
195 ElementLoopUserObject::onInterface(const Elem * elem, unsigned int side, BoundaryID /*bnd_id*/)
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 }
221 
222 void
224 {
225 }
226 
227 void
229 {
230 }
231 
232 void
234 {
235 }
236 
237 void
239 {
240 }
241 
242 void
244 {
245 }
246 
247 void
249 {
250 }
251 
252 void
254 {
255  _interface_elem_ids.clear();
256  _have_interface_elems = false;
257 }
258 
259 void
261 {
262  std::string what(e.what());
263  _fe_problem.setException(what);
264 }
ElementLoopUserObject::initialize
virtual void initialize()
Definition: ElementLoopUserObject.C:64
ElementLoopUserObject::execute
virtual void execute()
Definition: ElementLoopUserObject.C:75
ElementLoopUserObject
A base class that loops over elements and do things.
Definition: ElementLoopUserObject.h:58
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::join
void join(const ElementLoopUserObject &)
Definition: ElementLoopUserObject.C:228
validParams< ElementLoopUserObject >
InputParameters validParams< ElementLoopUserObject >()
Definition: ElementLoopUserObject.C:14
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::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::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::computeElement
virtual void computeElement()
Definition: ElementLoopUserObject.C:233
ElementLoopUserObject::_current_elem
const Elem * _current_elem
Definition: ElementLoopUserObject.h:91
ElementLoopUserObject::~ElementLoopUserObject
virtual ~ElementLoopUserObject()
Definition: ElementLoopUserObject.C:61
ElementLoopUserObject::finalize
virtual void finalize()
Definition: ElementLoopUserObject.C:137
ElementLoopUserObject::_current_neighbor
const Elem * _current_neighbor
Definition: ElementLoopUserObject.h:94
ElementLoopUserObject.h
ElementLoopUserObject::ElementLoopUserObject
ElementLoopUserObject(const InputParameters &parameters)
Definition: ElementLoopUserObject.C:21
ElementLoopUserObject::meshChanged
virtual void meshChanged()
Definition: ElementLoopUserObject.C:253