https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ElementLoopUserObject.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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
11
19
21 : GeneralUserObject(parameters),
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
62void
66
67void
72
73void
75{
76 const ConstElemRange & elem_range = *_mesh.getActiveLocalElementRange();
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
135void
140
141void
145
146void
150
151void
153{
154 _current_elem = elem;
156}
157
158void
159ElementLoopUserObject::onBoundary(const Elem * /*elem*/, unsigned int side, BoundaryID /*bnd_id*/)
160{
161 _current_side = side;
163}
164
165void
166ElementLoopUserObject::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
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
190 }
191}
192
193void
194ElementLoopUserObject::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
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
218 }
219}
220
221void
225
226void
230
231void
235
236void
240
241void
245
246void
250
251void
257
258void
boundary_id_type BoundaryID
const std::vector< double > x
bool hasBlocks(const SubdomainName &name) const
static InputParameters validParams()
const std::vector< MooseVariableFieldBase * > & getCoupledMooseVars() const
A base class that loops over elements and do things.
SubdomainID _subdomain
The subdomain for the current element.
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id)
virtual void onInterface(const Elem *elem, unsigned int side, BoundaryID bnd_id)
virtual void onElement(const Elem *elem)
bool _have_interface_elems
true if we have cached interface elements, false if they need to be cached. We want to (re)cache only...
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.
SubdomainID _old_subdomain
The subdomain for the last element.
virtual void caughtMooseException(MooseException &e)
virtual void preElement(const Elem *elem)
void join(const ElementLoopUserObject &)
virtual void onInternalSide(const Elem *elem, unsigned int side)
static InputParameters validParams()
ElementLoopUserObject(const InputParameters &parameters)
virtual void setException(const std::string &message)
virtual void setCurrentSubdomainID(const Elem *elem, const THREAD_ID tid) override
static InputParameters validParams()
virtual const char * what() const
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
const libMesh::ConstElemRange * getActiveLocalElementRange()
void addMooseVariableDependency(MooseVariableFieldBase *var)
FEProblemBase & _fe_problem
const THREAD_ID _tid
MeshBase & mesh