www.mooseframework.org
ElementLoopUserObject.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
9 
10 template <>
11 InputParameters
13 {
14  InputParameters params = validParams<GeneralUserObject>();
15  params += validParams<BlockRestrictable>();
16  return params;
17 }
18 
19 ElementLoopUserObject::ElementLoopUserObject(const InputParameters & parameters)
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()),
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<MooseVariable *> & 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()),
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 }
60 
62 
63 void
65 {
66 }
67 
68 void
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 }
128 
129 void
131 {
132  _have_interface_elems = true;
133 }
134 
135 void
137 {
138 }
139 
140 void
142 {
143 }
144 
145 void
147 {
148  _current_elem = elem;
149  computeElement();
150 }
151 
152 void
153 ElementLoopUserObject::onBoundary(const Elem * /*elem*/, unsigned int side, BoundaryID /*bnd_id*/)
154 {
155  _current_side = side;
156  computeBoundary();
157 }
158 
159 void
160 ElementLoopUserObject::onInternalSide(const Elem * elem, unsigned int side)
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 }
186 
187 void
188 ElementLoopUserObject::onInterface(const Elem * elem, unsigned int side, BoundaryID /*bnd_id*/)
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 }
214 
215 void
217 {
218 }
219 
220 void
222 {
223 }
224 
225 void
227 {
228 }
229 
230 void
232 {
233 }
234 
235 void
237 {
238 }
239 
240 void
242 {
243 }
244 
245 void
247 {
248  _interface_elem_ids.clear();
249  _have_interface_elems = false;
250 }
251 
252 void
254 {
255  std::string what(e.what());
256  _fe_problem.setException(what);
257 }
const MooseArray< Real > & _JxW
A base class that loops over elements and do things.
const MooseArray< Point > & _q_point
InputParameters validParams< ElementLoopUserObject >()
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)
ElementLoopUserObject(const InputParameters &parameters)
SubdomainID _subdomain
The subdomain for the current element.
virtual void computeInternalSide()
const MooseArray< Real > & _coord
virtual void onElement(const Elem *elem)
SubdomainID _old_subdomain
The subdomain for the last element.
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 join(const ElementLoopUserObject &)