17 #include "libmesh/quadrature.h" 27 params.
addParam<
bool>(
"use_displaced_mesh",
29 "Whether or not this object should use the displaced mesh for computation. " 30 "Note that in the case this is true but no displacements are provided in " 31 "the Mesh block the undisplaced mesh will still be used.");
34 "drop_duplicate_points",
36 "By default points added to a DiracKernel are dropped if a point at the same location" 37 "has been added before. If this option is set to false duplicate points are retained" 38 "and contribute to residual and Jacobian.");
40 MooseEnum point_not_found_behavior(
"ERROR WARNING IGNORE",
"IGNORE");
42 "point_not_found_behavior",
43 point_not_found_behavior,
44 "By default (IGNORE), it is ignored if an added point cannot be located in the " 45 "specified subdomains. If this option is set to ERROR, this situation will result in an " 46 "error. If this option is set to WARNING, then a warning will be issued.");
48 params.
addParam<
bool>(
"allow_moving_sources",
50 "If true, allow Dirac sources to move, even if the mesh does not move, " 51 "during the simulation.");
66 _current_elem(_assembly.elem()),
67 _coord_sys(_assembly.coordSystem()),
68 _dirac_kernel_info(_subproblem.diracKernelInfo()),
69 _q_point(_assembly.qPoints()),
70 _physical_point(_assembly.physicalPoints()),
71 _qrule(_assembly.qRule()),
72 _JxW(_assembly.JxW()),
73 _drop_duplicate_points(parameters.
get<bool>(
"drop_duplicate_points")),
74 _point_not_found_behavior(
76 _allow_moving_sources(getParam<bool>(
"allow_moving_sources"))
91 if (!elem || !
hasBlocks(elem->subdomain_id()))
93 std::stringstream msg;
143 const Elem * return_elem = NULL;
146 const Elem * cached_elem = NULL;
152 unsigned int i_found_it =
static_cast<unsigned int>(it !=
_point_cache.end());
153 unsigned int we_found_it = i_found_it;
171 points.push_back(std::make_pair(p,
id));
185 if (we_found_it && !i_found_it)
191 bool i_need_find_point =
false;
200 Point cached_point = (it->second).second;
202 if (cached_point.relative_fuzzy_equals(p))
205 cached_elem = (it->second).first;
220 bool active = cached_elem->active();
221 bool contains_point = cached_elem->contains_point(p);
226 if (active && contains_point)
229 return_elem = cached_elem;
235 else if (!active && contains_point)
238 std::vector<const Elem *> active_children;
239 cached_elem->active_family_tree(active_children);
242 for (
unsigned c = 0; c < active_children.size(); ++c)
243 if (active_children[c]->contains_point(p))
246 addPoint(active_children[c], p,
id);
247 return_elem = active_children[c];
257 mooseError(
"Error, Point not found in any of the active children!");
269 (active && !contains_point) ||
276 (!active && !contains_point))
278 i_need_find_point =
true;
288 " already exists with ID: ",
290 " and does not match point ",
292 "If Dirac sources are moving, please set 'allow_moving_sources' to true");
302 unsigned int we_need_find_point =
static_cast<unsigned int>(i_need_find_point);
303 comm().
max(we_need_find_point);
305 if (we_need_find_point)
353 if (new_elem && (new_elem->processor_id() ==
processor_id()))
362 reverse_cache_t::mapped_type & points = it->second;
364 reverse_cache_t::mapped_type::iterator points_it = points.begin(), points_end = points.end();
366 for (; points_it != points_end; ++points_it)
369 if (p.relative_fuzzy_equals(points_it->first))
375 points.erase(points_it);
387 if (new_elem && (new_elem->processor_id() ==
processor_id()))
390 points.push_back(std::make_pair(p,
id));
404 reverse_cache_t::mapped_type & points = it->second;
406 for (
const auto & points_it : points)
410 return points_it.second;
MooseMesh & _mesh
Reference to this Kernel's mesh object.
const bool _allow_moving_sources
Whether Dirac sources can move during the simulation.
bool hasPointsOnElem(const Elem *elem)
Whether or not this DiracKernel has something to distribute on this element.
const PointNotFoundBehavior _point_not_found_behavior
bool hasPoint(const Elem *elem, const Point &p)
Return true if we have Point 'p' in Element 'elem'.
const unsigned int invalid_uint
const Elem * findPoint(const Point &p, const MooseMesh &mesh, const std::set< SubdomainID > &blocks)
Used by client DiracKernel classes to determine the Elem in which the Point p resides.
virtual Elem * elemPtr(const dof_id_type i)
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
void clearPoints()
Remove all of the current points and elements.
DiracKernelInfo & _dirac_kernel_info
Place for storing Point/Elem information shared across all DiracKernel objects.
point_cache_t _point_cache
void addPoint(const Elem *elem, Point p, unsigned id=libMesh::invalid_uint)
Add the physical x,y,z point located in the element "elem" to the list of points this DiracKernel wil...
const Parallel::Communicator & comm() const
unsigned currentPointCachedID()
Returns the user-assigned ID of the current Dirac point if it exits, and libMesh::invalid_uint otherw...
static InputParameters validParams()
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object Note, if this is not block restricted, this function returns all mesh subdomain ids.
static InputParameters validParams()
void addPoint(const Elem *elem, const Point &p)
Adds a point source.
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
This gets called by computeOffDiagJacobian() at each quadrature point.
DiracKernelBase(const InputParameters ¶meters)
static InputParameters validParams()
bool isActiveAtPoint(const Elem *elem, const Point &p)
Whether or not this DiracKernel has something to distribute at this Point.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
static InputParameters validParams()
DiracKernelInfo _local_dirac_kernel_info
Place for storing Point/Elem information only for this DiracKernel.
void clearPoints()
Remove all of the current points and elements.
std::string stringify(const T &t)
conversion to string
const Elem *const & _current_elem
reverse_cache_t _reverse_point_cache
void statefulPropertiesAllowed(bool)
Derived classes can declare whether or not they work with stateful material properties.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
This is the common base class for objects that give residual contributions.
const std::set< SubdomainID > EMPTY_BLOCK_IDS
void max(const T &r, T &o, Request &req) const
An interface for accessing Materials.
const std::set< BoundaryID > EMPTY_BOUNDARY_IDS
void clearPointsCaches()
Clear the cache of points because the points may have moved.
An interface that restricts an object to subdomains via the 'blocks' input parameter.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
void updateCaches(const Elem *old_elem, const Elem *new_elem, Point p, unsigned id)
This function is used internally when the Elem for a locally-cached point needs to be updated...
std::set< const Elem * > & getElements()
Returns a writeable reference to the _elements container.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.
static InputParameters validParams()
processor_id_type processor_id() const
const Elem * addPointWithValidId(Point p, unsigned id)
A helper function for addPoint(Point, id) for when id != invalid_uint.
Point _current_point
The current point.