https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
DiracKernelInfo Class Reference

The DiracKernelInfo object is a place where all the Dirac points added by different DiracKernels are collected. More...

#include <DiracKernelInfo.h>

Public Types

typedef std::map< const Elem *, std::pair< std::vector< Point >, std::vector< Real > > > MultiPointMap
 

Public Member Functions

 DiracKernelInfo ()
 
virtual ~DiracKernelInfo ()
 
void addPoint (const Elem *elem, const Point &p, const Real &value=1)
 Adds a point source.
 
void clearPoints ()
 Remove all of the current points and elements.
 
bool hasPoint (const Elem *elem, const Point &p)
 Return true if we have Point 'p' in Element 'elem'.
 
std::set< const Elem * > & getElements ()
 Returns a writeable reference to the _elements container.
 
MultiPointMapgetPoints ()
 Returns a writeable reference to the _points container.
 
void updatePointLocator (const MooseMesh &mesh)
 Called during FEProblemBase::meshChanged() to update the PointLocator object used by the DiracKernels.
 
 CreateMooseEnumClass (PointNotFoundBehavior, ERROR, WARNING, IGNORE)
 Point-not-found behavior.
 
const ElemfindPoint (const Point &p, const MooseMesh &mesh, const std::set< SubdomainID > &blocks, const PointNotFoundBehavior point_not_found_behavior, const MooseBase &consumer)
 Used by client DiracKernel classes to determine the Elem in which the Point p resides.
 

Protected Member Functions

bool pointsFuzzyEqual (const Point &, const Point &)
 Check if two points are equal with respect to a tolerance.
 

Protected Attributes

std::set< const Elem * > _elements
 The list of elements that need distributions.
 
MultiPointMap _points
 The list of physical xyz Points that need to be evaluated in each element.
 
std::unique_ptr< libMesh::PointLocatorBase_point_locator
 The DiracKernelInfo object manages a PointLocator object which is used by all DiracKernels to find Points.
 
const Real _point_equal_distance_sq
 threshold distance squared below which two points are considered identical
 

Detailed Description

The DiracKernelInfo object is a place where all the Dirac points added by different DiracKernels are collected.

It is used, for example, by the FEProblemBase class to determine if finite element data needs to be recomputed on a given element.

Definition at line 37 of file DiracKernelInfo.h.

Member Typedef Documentation

◆ MultiPointMap

typedef std::map<const Elem *, std::pair<std::vector<Point>, std::vector<Real> > > DiracKernelInfo::MultiPointMap

Definition at line 67 of file DiracKernelInfo.h.

Constructor & Destructor Documentation

◆ DiracKernelInfo()

DiracKernelInfo::DiracKernelInfo ( )

Definition at line 24 of file DiracKernelInfo.C.

26{
27}
const Real _point_equal_distance_sq
threshold distance squared below which two points are considered identical
std::unique_ptr< libMesh::PointLocatorBase > _point_locator
The DiracKernelInfo object manages a PointLocator object which is used by all DiracKernels to find Po...
static constexpr Real TOLERANCE

◆ ~DiracKernelInfo()

DiracKernelInfo::~DiracKernelInfo ( )
virtual

Definition at line 29 of file DiracKernelInfo.C.

29{}

Member Function Documentation

◆ addPoint()

void DiracKernelInfo::addPoint ( const Elem elem,
const Point p,
const Real &  value = 1 
)

Adds a point source.

Parameters
elemPointer to the geometric element in which the point is located
pThe (x,y,z) location of the Dirac point
valueThe value accumulated for this point when it coincides with an existing point

Definition at line 32 of file DiracKernelInfo.C.

33{
34 _elements.insert(elem);
35
36 std::pair<std::vector<Point>, std::vector<Real>> & multi_point_list = _points[elem];
37
38 const unsigned int npoint = multi_point_list.first.size();
39 mooseAssert(npoint == multi_point_list.second.size(),
40 "Different sizes for location and point value data");
41
42 for (unsigned int i = 0; i < npoint; ++i)
43 if (pointsFuzzyEqual(multi_point_list.first[i], p))
44 {
45 // A point at the same (within a tolerance) location as p exists, accumulate its value.
46 multi_point_list.second[i] += value;
47 return;
48 }
49
50 // No prior point found at this location, add it with its initial value.
51 multi_point_list.first.push_back(p);
52 multi_point_list.second.push_back(value);
53}
MultiPointMap _points
The list of physical xyz Points that need to be evaluated in each element.
std::set< const Elem * > _elements
The list of elements that need distributions.
bool pointsFuzzyEqual(const Point &, const Point &)
Check if two points are equal with respect to a tolerance.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

Referenced by DiracKernelBase::addPoint().

◆ clearPoints()

void DiracKernelInfo::clearPoints ( )

Remove all of the current points and elements.

Definition at line 56 of file DiracKernelInfo.C.

57{
58 _elements.clear();
59 _points.clear();
60}

Referenced by DisplacedProblem::clearDiracInfo(), FEProblemBase::clearDiracInfo(), and DiracKernelBase::clearPoints().

◆ CreateMooseEnumClass()

DiracKernelInfo::CreateMooseEnumClass ( PointNotFoundBehavior  ,
ERROR  ,
WARNING  ,
IGNORE   
)

Point-not-found behavior.

◆ findPoint()

const Elem * DiracKernelInfo::findPoint ( const Point p,
const MooseMesh mesh,
const std::set< SubdomainID > &  blocks,
const PointNotFoundBehavior  point_not_found_behavior,
const MooseBase consumer 
)

Used by client DiracKernel classes to determine the Elem in which the Point p resides.

Uses the PointLocator owned by this object.

Parameters
pthe point to find the element which contains it
meshthe mesh with elements to look at
blocksblock restriction to find the element in
point_not_found_behaviorwhat to do if the point is not found
consumerthe object calling calling this routine

Definition at line 116 of file DiracKernelInfo.C.

121{
122 // If the PointLocator has never been created, do so now. NOTE - WE
123 // CAN'T DO THIS if findPoint() is only called on some processors,
124 // PointLocatorBase::build() is a 'parallel_only' method!
125 if (_point_locator.get() == NULL)
126 {
127 _point_locator = PointLocatorBase::build(TREE_LOCAL_ELEMENTS, mesh);
128 _point_locator->enable_out_of_mesh_mode();
129 }
130
131 // Check that the PointLocator is ready to start locating points.
132 // So far I do not have any tests that trip this...
133 if (_point_locator->initialized() == false)
134 consumer.mooseError("PointLocator is not initialized!");
135
136 // Note: The PointLocator object returns NULL when the Point is not
137 // found within the Mesh. This is not considered to be an error as
138 // far as the DiracKernels are concerned: sometimes the Mesh moves
139 // out from the Dirac point entirely and in that case the Point just
140 // gets "deactivated".
141 const Elem * elem = (*_point_locator)(p, &blocks);
142
143 // The processors may not agree on which Elem the point is in. This
144 // can happen if a Dirac point lies on the processor boundary, and
145 // two or more neighboring processors think the point is in the Elem
146 // on *their* side.
147 dof_id_type elem_id = elem ? elem->id() : DofObject::invalid_id;
148
149 // We are going to let the element with the smallest ID "win", all other
150 // procs will return NULL.
151 dof_id_type min_elem_id = elem_id;
152 mesh.comm().min(min_elem_id);
153
154 if (min_elem_id == DofObject::invalid_id)
155 {
156 std::stringstream msg;
157 msg << "Point " << p << " not found in block(s) " << Moose::stringify(blocks, ", ") << ".\n";
158 switch (point_not_found_behavior)
159 {
160 case PointNotFoundBehavior::ERROR:
161 consumer.mooseError(msg.str());
162 break;
163 case PointNotFoundBehavior::WARNING:
164 mooseDoOnce(consumer.mooseWarning(msg.str() + "This message will not be repeated."));
165 break;
166 case PointNotFoundBehavior::IGNORE:
167 break;
168 default:
169 consumer.mooseError("Internal enum error.");
170 }
171 }
172
173 // But we notably need the processor which owns elem_id to return it!
174 if (min_elem_id != DofObject::invalid_id)
175 if (const auto min_elem = mesh.queryElemPtr(min_elem_id);
176 min_elem && min_elem->processor_id() == mesh.processor_id())
177 return min_elem;
178 return nullptr;
179}
char ** blocks
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...
Definition MooseBase.h:271
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
Definition MooseBase.h:299
void min(const T &r, T &o, Request &req) const
static constexpr dof_id_type invalid_id
dof_id_type id() const
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
static std::unique_ptr< PointLocatorBase > build(PointLocatorType t, const MeshBase &mesh, const PointLocatorBase *master=nullptr)
MeshBase & mesh
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:64
uint8_t dof_id_type

Referenced by DiracKernelBase::addPoint(), and DiracKernelBase::addPointWithValidId().

◆ getElements()

std::set< const Elem * > & DiracKernelInfo::getElements ( )
inline

Returns a writeable reference to the _elements container.

Definition at line 65 of file DiracKernelInfo.h.

65{ return _elements; }

Referenced by DisplacedProblem::getDiracElements(), FEProblemBase::getDiracElements(), and DiracKernelBase::hasPointsOnElem().

◆ getPoints()

MultiPointMap & DiracKernelInfo::getPoints ( )
inline

Returns a writeable reference to the _points container.

Definition at line 72 of file DiracKernelInfo.h.

72{ return _points; }

Referenced by ADDiracKernel::computeADResiduals(), DisplacedProblem::reinitDirac(), and FEProblemBase::reinitDirac().

◆ hasPoint()

bool DiracKernelInfo::hasPoint ( const Elem elem,
const Point p 
)

Return true if we have Point 'p' in Element 'elem'.

Definition at line 63 of file DiracKernelInfo.C.

64{
65 std::vector<Point> & point_list = _points[elem].first;
66
67 for (const auto & pt : point_list)
68 if (pointsFuzzyEqual(pt, p))
69 return true;
70
71 // If we haven't found it, we don't have it.
72 return false;
73}
if(subdm)

Referenced by DiracKernelBase::isActiveAtPoint().

◆ pointsFuzzyEqual()

bool DiracKernelInfo::pointsFuzzyEqual ( const Point ,
const Point  
)
protected

Check if two points are equal with respect to a tolerance.

Definition at line 182 of file DiracKernelInfo.C.

183{
184 const Real dist_sq = (a - b).norm_sq();
185 return dist_sq < _point_equal_distance_sq;
186}
auto norm_sq(const T &a)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

Referenced by addPoint(), and hasPoint().

◆ updatePointLocator()

void DiracKernelInfo::updatePointLocator ( const MooseMesh mesh)

Called during FEProblemBase::meshChanged() to update the PointLocator object used by the DiracKernels.

Definition at line 76 of file DiracKernelInfo.C.

77{
78 // Note: we could update the PointLocator *every* time we call this
79 // function, but that may introduce an unacceptable overhead in
80 // problems which don't need a PointLocator at all. This issue will
81 // most likely become a moot point when we eventually add a shared
82 // "CachingPointLocator" to MOOSE.
83 // _point_locator = PointLocatorBase::build(TREE_LOCAL_ELEMENTS, mesh);
84
85 // Construct the PointLocator object if *any* processors have Dirac
86 // points. Note: building a PointLocator object is a parallel_only()
87 // function, so this is an all-or-nothing thing.
88 unsigned pl_needs_rebuild = _elements.size();
89 mesh.comm().max(pl_needs_rebuild);
90
91 if (pl_needs_rebuild)
92 {
93 // PointLocatorBase::build() is a parallel_only function! So we
94 // can't skip building it just becuase our local _elements is
95 // empty, it might be non-empty on some other processor!
96 _point_locator = PointLocatorBase::build(TREE_LOCAL_ELEMENTS, mesh);
97
98 // We may be querying for points which are not in the semilocal
99 // part of a distributed mesh.
100 _point_locator->enable_out_of_mesh_mode();
101 }
102 else
103 {
104 // There are no elements with Dirac points, but we have been
105 // requested to update the PointLocator so we have to assume the
106 // old one is invalid. Therefore we reset it to NULL... however
107 // adding this line causes the code to hang because it triggers
108 // the PointLocator to be rebuilt in a non-parallel-only segment
109 // of the code later... so it's commented out for now even though
110 // it's probably the right behavior.
111 // _point_locator.reset(NULL);
112 }
113}
void max(const T &r, T &o, Request &req) const

Referenced by FEProblemBase::meshChanged(), and DisplacedProblem::updateMesh().

Member Data Documentation

◆ _elements

std::set<const Elem *> DiracKernelInfo::_elements
protected

The list of elements that need distributions.

Definition at line 105 of file DiracKernelInfo.h.

Referenced by addPoint(), clearPoints(), getElements(), and updatePointLocator().

◆ _point_equal_distance_sq

const Real DiracKernelInfo::_point_equal_distance_sq
protected

threshold distance squared below which two points are considered identical

Definition at line 117 of file DiracKernelInfo.h.

Referenced by pointsFuzzyEqual().

◆ _point_locator

std::unique_ptr<libMesh::PointLocatorBase> DiracKernelInfo::_point_locator
protected

The DiracKernelInfo object manages a PointLocator object which is used by all DiracKernels to find Points.

It needs to be centrally managed and it also needs to be rebuilt in FEProblemBase::meshChanged() to work with Mesh adaptivity.

Definition at line 114 of file DiracKernelInfo.h.

Referenced by findPoint(), and updatePointLocator().

◆ _points

MultiPointMap DiracKernelInfo::_points
protected

The list of physical xyz Points that need to be evaluated in each element.

Definition at line 108 of file DiracKernelInfo.h.

Referenced by addPoint(), clearPoints(), getPoints(), and hasPoint().


The documentation for this class was generated from the following files: