www.mooseframework.org
Public Member Functions | Protected Attributes | List of all members
ComputeDiracThread Class Reference

#include <ComputeDiracThread.h>

Inheritance diagram for ComputeDiracThread:
[legend]

Public Member Functions

 ComputeDiracThread (FEProblemBase &feproblem, const std::set< TagID > &tags, bool _is_jacobian)
 
 ComputeDiracThread (ComputeDiracThread &x, Threads::split)
 
virtual ~ComputeDiracThread ()
 
virtual void subdomainChanged () override
 Called every time the current subdomain changes (i.e. More...
 
virtual void pre () override
 Called before the element range loop. More...
 
virtual void onElement (const Elem *elem) override
 Assembly of the element (not including surface assembly) More...
 
virtual void postElement (const Elem *) override
 Called after the element assembly is done (including surface assembling) More...
 
virtual void post () override
 Called after the element range loop. More...
 
void join (const ComputeDiracThread &)
 
virtual void caughtMooseException (MooseException &e) override
 Called if a MooseException is caught anywhere during the computation. More...
 
virtual bool keepGoing () override
 Whether or not the loop should continue. More...
 
virtual void preElement (const Elem *elem) override
 Called before the element assembly. More...
 
virtual void preInternalSide (const Elem *elem, unsigned int side) override
 Called before evaluations on an element internal side. More...
 
virtual void neighborSubdomainChanged () override
 Called every time the neighbor subdomain changes (i.e. More...
 
void operator() (const DistElemRange &range, bool bypass_threading=false)
 
virtual void onBoundary (const Elem *elem, unsigned int side, BoundaryID bnd_id)
 Called when doing boundary assembling. More...
 
virtual void postInternalSide (const Elem *elem, unsigned int side)
 Called after evaluations on an element internal side. More...
 
virtual void onInternalSide (const Elem *elem, unsigned int side)
 Called when doing internal edge assembling. More...
 
virtual void onInterface (const Elem *elem, unsigned int side, BoundaryID bnd_id)
 Called when doing interface assembling. More...
 

Protected Attributes

bool _is_jacobian
 
NonlinearSystemBase_nl
 
const std::set< TagID > & _tags
 
MooseObjectTagWarehouse< DiracKernel > & _dirac_kernels
 Storage for DiracKernel objects. More...
 
MooseObjectWarehouse< DiracKernel > * _dirac_warehouse
 
FEProblemBase_fe_problem
 
MooseMesh_mesh
 
THREAD_ID _tid
 
SubdomainID _subdomain
 The subdomain for the current element. More...
 
SubdomainID _old_subdomain
 The subdomain for the last element. More...
 
SubdomainID _neighbor_subdomain
 The subdomain for the current neighbor. More...
 
SubdomainID _old_neighbor_subdomain
 The subdomain for the last neighbor. More...
 

Detailed Description

Definition at line 28 of file ComputeDiracThread.h.

Constructor & Destructor Documentation

◆ ComputeDiracThread() [1/2]

ComputeDiracThread::ComputeDiracThread ( FEProblemBase feproblem,
const std::set< TagID > &  tags,
bool  _is_jacobian 
)

Definition at line 23 of file ComputeDiracThread.C.

27  _is_jacobian(is_jacobian),
28  _nl(feproblem.getNonlinearSystemBase()),
29  _tags(tags),
31 {
32 }
NonlinearSystemBase & getNonlinearSystemBase()
MooseObjectTagWarehouse< DiracKernel > & getDiracKernelWarehouse()
const std::set< TagID > & _tags
NonlinearSystemBase & _nl
MooseObjectTagWarehouse< DiracKernel > & _dirac_kernels
Storage for DiracKernel objects.

◆ ComputeDiracThread() [2/2]

ComputeDiracThread::ComputeDiracThread ( ComputeDiracThread x,
Threads::split  split 
)

Definition at line 35 of file ComputeDiracThread.C.

37  _is_jacobian(x._is_jacobian),
38  _nl(x._nl),
39  _tags(x._tags),
40  _dirac_kernels(x._dirac_kernels)
41 {
42 }
static PetscErrorCode Vec x
const std::set< TagID > & _tags
NonlinearSystemBase & _nl
MooseObjectTagWarehouse< DiracKernel > & _dirac_kernels
Storage for DiracKernel objects.

◆ ~ComputeDiracThread()

ComputeDiracThread::~ComputeDiracThread ( )
virtual

Definition at line 44 of file ComputeDiracThread.C.

44 {}

Member Function Documentation

◆ caughtMooseException()

void ThreadedElementLoop< DistElemRange >::caughtMooseException ( MooseException e)
overridevirtualinherited

Called if a MooseException is caught anywhere during the computation.

The single input parameter taken is a MooseException object.

Reimplemented from ThreadedElementLoopBase< DistElemRange >.

Definition at line 77 of file ThreadedElementLoop.h.

78 {
79  Threads::spin_mutex::scoped_lock lock(threaded_element_mutex);
80 
81  std::string what(e.what());
83 }
virtual const char * what() const
Get out the error message.
virtual void setException(const std::string &message)
Set an exception.
static Threads::spin_mutex threaded_element_mutex
This mutex is used by all derived classes of the ThreadedElementLoop.

◆ join()

void ComputeDiracThread::join ( const ComputeDiracThread )

Definition at line 166 of file ComputeDiracThread.C.

167 {
168 }

◆ keepGoing()

virtual bool ThreadedElementLoop< DistElemRange >::keepGoing ( )
inlineoverridevirtualinherited

Whether or not the loop should continue.

Returns
true to keep going, false to stop.

Reimplemented from ThreadedElementLoopBase< DistElemRange >.

Definition at line 45 of file ThreadedElementLoop.h.

45 { return !_fe_problem.hasException(); }
virtual bool hasException()
Whether or not an exception has occurred.

◆ neighborSubdomainChanged()

void ThreadedElementLoop< DistElemRange >::neighborSubdomainChanged ( )
overridevirtualinherited

Called every time the neighbor subdomain changes (i.e.

the subdomain of this neighbor is not the same as the subdomain of the last neighbor). Beware of over-using this! You might think that you can do some expensive stuff in here and get away with it... but there are applications that have TONS of subdomains....

Reimplemented from ThreadedElementLoopBase< DistElemRange >.

Definition at line 101 of file ThreadedElementLoop.h.

102 {
105 }
virtual void neighborSubdomainSetup(SubdomainID subdomain, THREAD_ID tid)
Base class for assembly-like calculations.

◆ onBoundary()

void ThreadedElementLoopBase< DistElemRange >::onBoundary ( const Elem *  elem,
unsigned int  side,
BoundaryID  bnd_id 
)
virtualinherited

Called when doing boundary assembling.

Parameters
elem- The element we are checking is on the boundary.
side- The side of the element in question.
bnd_id- ID of the boundary we are at

Definition at line 274 of file ThreadedElementLoopBase.h.

277 {
278 }

◆ onElement()

void ComputeDiracThread::onElement ( const Elem *  elem)
overridevirtual

Assembly of the element (not including surface assembly)

Parameters
elem- active element

Reimplemented from ThreadedElementLoopBase< DistElemRange >.

Definition at line 85 of file ComputeDiracThread.C.

86 {
87  const bool has_dirac_kernels_on_elem = _fe_problem.reinitDirac(elem, _tid);
88  if (!has_dirac_kernels_on_elem)
89  return;
90 
91  std::set<MooseVariableFEBase *> needed_moose_vars;
92  const auto & dkernels = _dirac_warehouse->getActiveObjects(_tid);
93 
94  // Only call reinitMaterials() if one or more DiracKernels has
95  // actually called getMaterialProperty(). Loop over all the
96  // DiracKernels and check whether this is the case.
97  for (const auto & dirac_kernel : dkernels)
98  {
99  // If any of the DiracKernels have had getMaterialProperty()
100  // called, we need to reinit Materials.
101  if (dirac_kernel->getMaterialPropertyCalled())
102  {
103  _fe_problem.reinitMaterials(_subdomain, _tid, /*swap_stateful=*/false);
104  break;
105  }
106  }
107 
108  for (const auto & dirac_kernel : dkernels)
109  {
110  if (!dirac_kernel->hasPointsOnElem(elem))
111  continue;
112  else if (!_is_jacobian)
113  {
114  dirac_kernel->computeResidual();
115  continue;
116  }
117 
118  // Get a list of coupled variables from the SubProblem
119  std::vector<std::pair<MooseVariableFEBase *, MooseVariableFEBase *>> & coupling_entries =
120  dirac_kernel->subProblem().assembly(_tid).couplingEntries();
121 
122  // Loop over the list of coupled variable pairs
123  for (auto & it : coupling_entries)
124  {
125  MooseVariableFEBase * ivariable = it.first;
126  MooseVariableFEBase * jvariable = it.second;
127 
128  // A variant of the check that is in
129  // ComputeFullJacobianThread::computeJacobian(). We
130  // only want to call computeOffDiagJacobian() if both
131  // variables are active on this subdomain, and the
132  // off-diagonal variable actually has dofs.
133  if (dirac_kernel->variable().number() == ivariable->number() &&
134  ivariable->activeOnSubdomain(_subdomain) && jvariable->activeOnSubdomain(_subdomain) &&
135  (jvariable->numberOfDofs() > 0))
136  {
137  dirac_kernel->subProblem().prepareShapes(jvariable->number(), _tid);
138  dirac_kernel->computeOffDiagJacobian(jvariable->number());
139  }
140  }
141  }
142 
143  // Note that we do not call swapBackMaterials() here as they were
144  // never swapped in the first place. This avoids messing up
145  // stored values of stateful material properties.
146 }
virtual bool reinitDirac(const Elem *elem, THREAD_ID tid) override
Returns true if the Problem has Dirac kernels it needs to compute on elem.
unsigned int number() const
Get variable number coming from libMesh.
unsigned int numberOfDofs()
virtual bool activeOnSubdomain(SubdomainID subdomain) const =0
Is the variable active on the subdomain?
virtual void reinitMaterials(SubdomainID blk_id, THREAD_ID tid, bool swap_stateful=true)
const std::vector< std::shared_ptr< T > > & getActiveObjects(THREAD_ID tid=0) const
Retrieve complete vector to the active all/block/boundary restricted objects for a given thread...
MooseObjectWarehouse< DiracKernel > * _dirac_warehouse
SubdomainID _subdomain
The subdomain for the current element.

◆ onInterface()

void ThreadedElementLoopBase< DistElemRange >::onInterface ( const Elem *  elem,
unsigned int  side,
BoundaryID  bnd_id 
)
virtualinherited

Called when doing interface assembling.

Parameters
elem- Element we are on
side- local side number of the element 'elem'
bnd_id- ID of the interface we are at

Definition at line 300 of file ThreadedElementLoopBase.h.

303 {
304 }

◆ onInternalSide()

void ThreadedElementLoopBase< DistElemRange >::onInternalSide ( const Elem *  elem,
unsigned int  side 
)
virtualinherited

Called when doing internal edge assembling.

Parameters
elem- Element we are on
side- local side number of the element 'elem'

Definition at line 294 of file ThreadedElementLoopBase.h.

295 {
296 }

◆ operator()()

void ThreadedElementLoopBase< DistElemRange >::operator() ( const DistElemRange range,
bool  bypass_threading = false 
)
inherited

Definition at line 171 of file ThreadedElementLoopBase.h.

172 {
173  try
174  {
175  ParallelUniqueId puid;
176  _tid = bypass_threading ? 0 : puid.id;
177 
178  pre();
179 
182  typename RangeType::const_iterator el = range.begin();
183  for (el = range.begin(); el != range.end(); ++el)
184  {
185  if (!keepGoing())
186  break;
187 
188  const Elem * elem = *el;
189 
190  preElement(elem);
191 
193  _subdomain = elem->subdomain_id();
194  if (_subdomain != _old_subdomain)
196 
197  onElement(elem);
198 
199  for (unsigned int side = 0; side < elem->n_sides(); side++)
200  {
201  std::vector<BoundaryID> boundary_ids = _mesh.getBoundaryIDs(elem, side);
202 
203  if (boundary_ids.size() > 0)
204  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
205  it != boundary_ids.end();
206  ++it)
207  onBoundary(elem, side, *it);
208 
209  const Elem * neighbor = elem->neighbor_ptr(side);
210  if (neighbor != nullptr)
211  {
212  preInternalSide(elem, side);
213 
215  _neighbor_subdomain = neighbor->subdomain_id();
218 
219  onInternalSide(elem, side);
220 
221  if (boundary_ids.size() > 0)
222  for (std::vector<BoundaryID>::iterator it = boundary_ids.begin();
223  it != boundary_ids.end();
224  ++it)
225  onInterface(elem, side, *it);
226 
227  postInternalSide(elem, side);
228  }
229  } // sides
230  postElement(elem);
231 
232  } // range
233 
234  post();
235  }
236  catch (MooseException & e)
237  {
239  }
240 }
virtual bool keepGoing()
Whether or not the loop should continue.
virtual void onElement(const Elem *elem)
Assembly of the element (not including surface assembly)
virtual void pre()
Called before the element range loop.
virtual void subdomainChanged()
Called every time the current subdomain changes (i.e.
virtual void neighborSubdomainChanged()
Called every time the neighbor subdomain changes (i.e.
virtual void preInternalSide(const Elem *elem, unsigned int side)
Called before evaluations on an element internal side.
virtual void postInternalSide(const Elem *elem, unsigned int side)
Called after evaluations on an element internal side.
const SubdomainID INVALID_BLOCK_ID
Definition: MooseTypes.h:320
virtual void postElement(const Elem *elem)
Called after the element assembly is done (including surface assembling)
virtual void onInterface(const Elem *elem, unsigned int side, BoundaryID bnd_id)
Called when doing interface assembling.
SubdomainID _old_neighbor_subdomain
The subdomain for the last neighbor.
virtual void onInternalSide(const Elem *elem, unsigned int side)
Called when doing internal edge assembling.
Provides a way for users to bail out of the current solve.
virtual void caughtMooseException(MooseException &)
Called if a MooseException is caught anywhere during the computation.
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
Returns a vector of boundary IDs for the requested element on the requested side. ...
Definition: MooseMesh.C:2105
SubdomainID _subdomain
The subdomain for the current element.
SubdomainID _old_subdomain
The subdomain for the last element.
virtual void post()
Called after the element range loop.
virtual void preElement(const Elem *elem)
Called before the element assembly.
SubdomainID _neighbor_subdomain
The subdomain for the current neighbor.
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id)
Called when doing boundary assembling.

◆ post()

void ComputeDiracThread::post ( )
overridevirtual

Called after the element range loop.

Reimplemented from ThreadedElementLoopBase< DistElemRange >.

Definition at line 159 of file ComputeDiracThread.C.

160 {
163 }
virtual void clearActiveMaterialProperties(THREAD_ID tid) override
Clear the active material properties.
virtual void clearActiveElementalMooseVariables(THREAD_ID tid) override
Clear the active elemental MooseVariableFEBase.

◆ postElement()

void ComputeDiracThread::postElement ( const Elem *  elem)
overridevirtual

Called after the element assembly is done (including surface assembling)

Parameters
elem- active element

Reimplemented from ThreadedElementLoopBase< DistElemRange >.

Definition at line 149 of file ComputeDiracThread.C.

150 {
151  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
152  if (!_is_jacobian)
154  else
156 }
virtual void addResidual(THREAD_ID tid) override
virtual void addJacobian(THREAD_ID tid) override

◆ postInternalSide()

void ThreadedElementLoopBase< DistElemRange >::postInternalSide ( const Elem *  elem,
unsigned int  side 
)
virtualinherited

Called after evaluations on an element internal side.

Parameters
elem- Element we are on
side- local side number of the element 'elem'

Definition at line 288 of file ThreadedElementLoopBase.h.

289 {
290 }

◆ pre()

void ComputeDiracThread::pre ( )
overridevirtual

Called before the element range loop.

Reimplemented from ThreadedElementLoopBase< DistElemRange >.

Definition at line 47 of file ComputeDiracThread.C.

48 {
49  // Force TID=0 because we run this object _NON THREADED_
50  // Take this out if we ever get Dirac's working with threads!
51  _tid = 0;
52 }

◆ preElement()

void ThreadedElementLoop< DistElemRange >::preElement ( const Elem *  elem)
overridevirtualinherited

Called before the element assembly.

Parameters
elem- active element

Reimplemented from ThreadedElementLoopBase< DistElemRange >.

Definition at line 87 of file ThreadedElementLoop.h.

88 {
90 }
virtual void setCurrentSubdomainID(const Elem *elem, THREAD_ID tid) override
Base class for assembly-like calculations.

◆ preInternalSide()

void ThreadedElementLoop< DistElemRange >::preInternalSide ( const Elem *  elem,
unsigned int  side 
)
overridevirtualinherited

Called before evaluations on an element internal side.

Parameters
elem- Element we are on
side- local side number of the element 'elem'

Reimplemented from ThreadedElementLoopBase< DistElemRange >.

Definition at line 94 of file ThreadedElementLoop.h.

95 {
97 }
Base class for assembly-like calculations.
virtual void setNeighborSubdomainID(const Elem *elem, unsigned int side, THREAD_ID tid) override

◆ subdomainChanged()

void ComputeDiracThread::subdomainChanged ( )
overridevirtual

Called every time the current subdomain changes (i.e.

the subdomain of this element is not the same as the subdomain of the last element). Beware of over-using this! You might think that you can do some expensive stuff in here and get away with it... but there are applications that have TONS of subdomains....

Reimplemented from ThreadedElementLoopBase< DistElemRange >.

Definition at line 55 of file ComputeDiracThread.C.

56 {
58 
59  std::set<MooseVariableFEBase *> needed_moose_vars;
60  _dirac_kernels.updateVariableDependency(needed_moose_vars, _tid);
61 
62  // Update material dependencies
63  std::set<unsigned int> needed_mat_props;
64  _dirac_kernels.updateMatPropDependency(needed_mat_props, _tid);
65 
67  _fe_problem.setActiveMaterialProperties(needed_mat_props, _tid);
68 
69  // If users pass a empty vector or a full size of vector,
70  // we take all kernels
71  if (!_tags.size() || _tags.size() == _fe_problem.numMatrixTags())
73  // If we have one tag only, We call tag based storage
74  else if (_tags.size() == 1)
78  // This one may be expensive, and hopefully we do not use it so often
79  else
82 }
virtual void setActiveElementalMooseVariables(const std::set< MooseVariableFEBase *> &moose_vars, THREAD_ID tid) override
Set the MOOSE variables to be reinited on each element.
MooseObjectWarehouse< T > & getVectorTagsObjectWarehouse(const std::set< TagID > &tags, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object at least has one of the given vector ta...
virtual void setActiveMaterialProperties(const std::set< unsigned int > &mat_prop_ids, THREAD_ID tid) override
Record and set the material properties required by the current computing thread.
virtual void subdomainSetup(SubdomainID subdomain, THREAD_ID tid)
const std::set< TagID > & _tags
MooseObjectWarehouse< T > & getMatrixTagObjectWarehouse(TagID tag_id, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has the given matrix tag...
void updateVariableDependency(std::set< MooseVariableFEBase *> &needed_moose_vars, THREAD_ID tid=0) const
Update variable dependency vector.
MooseObjectWarehouse< T > & getMatrixTagsObjectWarehouse(const std::set< TagID > &tags, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has one of the given matrix tags...
MooseObjectWarehouse< T > & getVectorTagObjectWarehouse(TagID tag_id, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has the given vector tag...
MooseObjectWarehouse< DiracKernel > * _dirac_warehouse
SubdomainID _subdomain
The subdomain for the current element.
MooseObjectTagWarehouse< DiracKernel > & _dirac_kernels
Storage for DiracKernel objects.
void updateMatPropDependency(std::set< unsigned int > &needed_mat_props, THREAD_ID tid=0) const
Update material property dependency vector.
virtual unsigned int numMatrixTags()
The total number of tags.
Definition: SubProblem.h:145

Member Data Documentation

◆ _dirac_kernels

MooseObjectTagWarehouse<DiracKernel>& ComputeDiracThread::_dirac_kernels
protected

Storage for DiracKernel objects.

Definition at line 53 of file ComputeDiracThread.h.

Referenced by subdomainChanged().

◆ _dirac_warehouse

MooseObjectWarehouse<DiracKernel>* ComputeDiracThread::_dirac_warehouse
protected

Definition at line 55 of file ComputeDiracThread.h.

Referenced by onElement(), and subdomainChanged().

◆ _fe_problem

FEProblemBase& ThreadedElementLoop< DistElemRange >::_fe_problem
protectedinherited

Definition at line 54 of file ThreadedElementLoop.h.

Referenced by onElement(), post(), postElement(), and subdomainChanged().

◆ _is_jacobian

bool ComputeDiracThread::_is_jacobian
protected

Definition at line 47 of file ComputeDiracThread.h.

Referenced by onElement(), postElement(), and subdomainChanged().

◆ _mesh

MooseMesh& ThreadedElementLoopBase< DistElemRange >::_mesh
protectedinherited

Definition at line 136 of file ThreadedElementLoopBase.h.

◆ _neighbor_subdomain

SubdomainID ThreadedElementLoopBase< DistElemRange >::_neighbor_subdomain
protectedinherited

The subdomain for the current neighbor.

Definition at line 146 of file ThreadedElementLoopBase.h.

◆ _nl

NonlinearSystemBase& ComputeDiracThread::_nl
protected

Definition at line 48 of file ComputeDiracThread.h.

◆ _old_neighbor_subdomain

SubdomainID ThreadedElementLoopBase< DistElemRange >::_old_neighbor_subdomain
protectedinherited

The subdomain for the last neighbor.

Definition at line 149 of file ThreadedElementLoopBase.h.

◆ _old_subdomain

SubdomainID ThreadedElementLoopBase< DistElemRange >::_old_subdomain
protectedinherited

The subdomain for the last element.

Definition at line 143 of file ThreadedElementLoopBase.h.

◆ _subdomain

SubdomainID ThreadedElementLoopBase< DistElemRange >::_subdomain
protectedinherited

The subdomain for the current element.

Definition at line 140 of file ThreadedElementLoopBase.h.

Referenced by onElement(), and subdomainChanged().

◆ _tags

const std::set<TagID>& ComputeDiracThread::_tags
protected

Definition at line 50 of file ComputeDiracThread.h.

Referenced by subdomainChanged().

◆ _tid

THREAD_ID ThreadedElementLoopBase< DistElemRange >::_tid
protectedinherited

Definition at line 137 of file ThreadedElementLoopBase.h.

Referenced by onElement(), post(), postElement(), pre(), and subdomainChanged().


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