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

#include <ComputeNodalKernelJacobiansThread.h>

Inheritance diagram for ComputeNodalKernelJacobiansThread:
[legend]

Public Member Functions

 ComputeNodalKernelJacobiansThread (FEProblemBase &fe_problem, MooseObjectTagWarehouse< NodalKernel > &nodal_kernels, const std::set< TagID > &tags)
 
 ComputeNodalKernelJacobiansThread (ComputeNodalKernelJacobiansThread &x, Threads::split split)
 
virtual void pre () override
 Called before the node range loop. More...
 
virtual void onNode (ConstNodeRange::const_iterator &node_it) override
 Called for each node. More...
 
void join (const ComputeNodalKernelJacobiansThread &)
 
void operator() (const ConstNodeRange &range)
 
virtual void post ()
 Called after the node range loop. More...
 
virtual void postNode (ConstNodeRange::const_iterator &node_it)
 Called after the node assembly is done (including surface assembling) More...
 
virtual void caughtMooseException (MooseException &e)
 Called if a MooseException is caught anywhere during the computation. More...
 
virtual bool keepGoing ()
 Whether or not the loop should continue. More...
 

Protected Attributes

FEProblemBase_fe_problem
 
AuxiliarySystem_aux_sys
 
const std::set< TagID > & _tags
 
MooseObjectTagWarehouse< NodalKernel > & _nodal_kernels
 
MooseObjectWarehouse< NodalKernel > * _nkernel_warehouse
 
unsigned int _num_cached
 Number of contributions cached up. More...
 
THREAD_ID _tid
 

Detailed Description

Definition at line 30 of file ComputeNodalKernelJacobiansThread.h.

Constructor & Destructor Documentation

◆ ComputeNodalKernelJacobiansThread() [1/2]

ComputeNodalKernelJacobiansThread::ComputeNodalKernelJacobiansThread ( FEProblemBase fe_problem,
MooseObjectTagWarehouse< NodalKernel > &  nodal_kernels,
const std::set< TagID > &  tags 
)

◆ ComputeNodalKernelJacobiansThread() [2/2]

ComputeNodalKernelJacobiansThread::ComputeNodalKernelJacobiansThread ( ComputeNodalKernelJacobiansThread x,
Threads::split  split 
)

Definition at line 36 of file ComputeNodalKernelJacobiansThread.C.

39  _fe_problem(x._fe_problem),
40  _aux_sys(x._aux_sys),
41  _tags(x._tags),
42  _nodal_kernels(x._nodal_kernels),
43  _num_cached(0)
44 {
45 }
static PetscErrorCode Vec x
MooseObjectTagWarehouse< NodalKernel > & _nodal_kernels
unsigned int _num_cached
Number of contributions cached up.

Member Function Documentation

◆ caughtMooseException()

virtual void ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::caughtMooseException ( MooseException e)
inlinevirtualinherited

Called if a MooseException is caught anywhere during the computation.

The single input parameter taken is a MooseException object.

Definition at line 55 of file ThreadedNodeLoop.h.

56  {
57  std::string what(e.what());
59  };
virtual const char * what() const
Get out the error message.
virtual void setException(const std::string &message)
Set an exception.

◆ join()

void ComputeNodalKernelJacobiansThread::join ( const ComputeNodalKernelJacobiansThread )

Definition at line 139 of file ComputeNodalKernelJacobiansThread.C.

140 {
141 }

◆ keepGoing()

virtual bool ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::keepGoing ( )
inlinevirtualinherited

Whether or not the loop should continue.

Returns
true to keep going, false to stop.

Definition at line 66 of file ThreadedNodeLoop.h.

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

◆ onNode()

void ComputeNodalKernelJacobiansThread::onNode ( ConstNodeRange::const_iterator &  node_it)
overridevirtual

Called for each node.

Reimplemented from ThreadedNodeLoop< ConstNodeRange, ConstNodeRange::const_iterator >.

Definition at line 61 of file ComputeNodalKernelJacobiansThread.C.

62 {
63  const Node * node = *node_it;
64 
65  std::vector<std::pair<MooseVariableFEBase *, MooseVariableFEBase *>> & ce =
67  for (const auto & it : ce)
68  {
69  MooseVariableFEBase & ivariable = *(it.first);
70  MooseVariableFEBase & jvariable = *(it.second);
71 
72  unsigned int ivar = ivariable.number();
73  unsigned int jvar = jvariable.number();
74 
75  // The NodalKernels that are active and are coupled to the jvar in question
76  std::vector<std::shared_ptr<NodalKernel>> active_involved_kernels;
77 
78  const std::set<SubdomainID> & block_ids = _aux_sys.mesh().getNodeBlockIds(*node);
79  for (const auto & block : block_ids)
80  {
82  {
83  // Loop over each NodalKernel to see if it's involved with the jvar
84  const auto & objects = _nkernel_warehouse->getActiveBlockObjects(block, _tid);
85  for (const auto & nodal_kernel : objects)
86  {
87  if (nodal_kernel->variable().number() == ivar)
88  {
89  // If this NodalKernel is acting on the jvar add it to the list and short-circuit the
90  // loop
91  if (nodal_kernel->variable().number() == jvar)
92  {
93  active_involved_kernels.push_back(nodal_kernel);
94  continue;
95  }
96 
97  // See if this NodalKernel is coupled to the jvar
98  const std::vector<MooseVariableFEBase *> & coupled_vars =
99  nodal_kernel->getCoupledMooseVars();
100  for (const auto & var : coupled_vars)
101  if (var->number() == jvar)
102  {
103  active_involved_kernels.push_back(nodal_kernel);
104  break; // It only takes one
105  }
106  }
107  }
108  }
109  }
110 
111  // Did we find any NodalKernels coupled to this jvar?
112  if (!active_involved_kernels.empty())
113  {
114  // prepare variables
115  for (const auto & it : _aux_sys._nodal_vars[_tid])
116  {
117  MooseVariable * var = it.second;
118  var->prepareAux();
119  }
120 
121  _fe_problem.reinitNode(node, _tid);
122 
123  for (const auto & nodal_kernel : active_involved_kernels)
124  nodal_kernel->computeOffDiagJacobian(jvar);
125 
126  _num_cached++;
127 
128  if (_num_cached == 20) // Cache 20 nodes worth before adding into the residual
129  {
130  _num_cached = 0;
131  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
133  }
134  }
135  }
136 }
bool hasActiveBlockObjects(THREAD_ID tid=0) const
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
std::vector< std::map< std::string, MooseVariable * > > _nodal_vars
unsigned int number() const
Get variable number coming from libMesh.
virtual Assembly & assembly(THREAD_ID tid) override
const std::set< SubdomainID > & getNodeBlockIds(const Node &node) const
Return list of blocks to which the given node belongs.
Definition: MooseMesh.C:883
std::vector< std::pair< MooseVariableFEBase *, MooseVariableFEBase * > > & couplingEntries(THREAD_ID tid)
MooseObjectWarehouse< NodalKernel > * _nkernel_warehouse
virtual MooseMesh & mesh()
Definition: SystemBase.h:102
void addCachedJacobianContributions()
Adds previously-cached Jacobian values via SparseMatrix::add() calls.
Definition: Assembly.C:2201
virtual void reinitNode(const Node *node, THREAD_ID tid) override
unsigned int _num_cached
Number of contributions cached up.
void prepareAux() override

◆ operator()()

void ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::operator() ( const ConstNodeRange &  range)
inherited

Definition at line 88 of file ThreadedNodeLoop.h.

89 {
90  try
91  {
92  ParallelUniqueId puid;
93  _tid = puid.id;
94 
95  pre();
96 
97  for (IteratorType nd = range.begin(); nd != range.end(); ++nd)
98  {
99  if (!keepGoing())
100  break;
101 
102  onNode(nd);
103 
104  postNode(nd);
105  }
106 
107  post();
108  }
109  catch (MooseException & e)
110  {
112  }
113 }
virtual void caughtMooseException(MooseException &e)
Called if a MooseException is caught anywhere during the computation.
virtual bool keepGoing()
Whether or not the loop should continue.
Provides a way for users to bail out of the current solve.
virtual void pre()
Called before the node range loop.
virtual void post()
Called after the node range loop.
virtual void postNode(ConstNodeRange::const_iterator &node_it)
Called after the node assembly is done (including surface assembling)
virtual void onNode(ConstNodeRange::const_iterator &node_it)
Called for each node.

◆ post()

void ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::post ( )
virtualinherited

Called after the node range loop.

Reimplemented in ComputeNodalAuxVarsThread.

Definition at line 123 of file ThreadedNodeLoop.h.

124 {
125 }

◆ postNode()

void ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::postNode ( ConstNodeRange::const_iterator &  node_it)
virtualinherited

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

Parameters
node- active node

Definition at line 135 of file ThreadedNodeLoop.h.

136 {
137 }

◆ pre()

void ComputeNodalKernelJacobiansThread::pre ( )
overridevirtual

Called before the node range loop.

Reimplemented from ThreadedNodeLoop< ConstNodeRange, ConstNodeRange::const_iterator >.

Definition at line 48 of file ComputeNodalKernelJacobiansThread.C.

49 {
50  _num_cached = 0;
51 
52  if (!_tags.size() || _tags.size() == _fe_problem.numMatrixTags())
54  else if (_tags.size() == 1)
56  else
58 }
MooseObjectWarehouse< T > & getMatrixTagObjectWarehouse(TagID tag_id, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has the given matrix tag...
MooseObjectTagWarehouse< NodalKernel > & _nodal_kernels
MooseObjectWarehouse< NodalKernel > * _nkernel_warehouse
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...
virtual unsigned int numMatrixTags()
The total number of tags.
Definition: SubProblem.h:145
unsigned int _num_cached
Number of contributions cached up.

Member Data Documentation

◆ _aux_sys

AuxiliarySystem& ComputeNodalKernelJacobiansThread::_aux_sys
protected

Definition at line 50 of file ComputeNodalKernelJacobiansThread.h.

Referenced by onNode().

◆ _fe_problem

FEProblemBase& ComputeNodalKernelJacobiansThread::_fe_problem
protected

Definition at line 48 of file ComputeNodalKernelJacobiansThread.h.

Referenced by onNode(), and pre().

◆ _nkernel_warehouse

MooseObjectWarehouse<NodalKernel>* ComputeNodalKernelJacobiansThread::_nkernel_warehouse
protected

Definition at line 56 of file ComputeNodalKernelJacobiansThread.h.

Referenced by onNode(), and pre().

◆ _nodal_kernels

MooseObjectTagWarehouse<NodalKernel>& ComputeNodalKernelJacobiansThread::_nodal_kernels
protected

Definition at line 54 of file ComputeNodalKernelJacobiansThread.h.

Referenced by pre().

◆ _num_cached

unsigned int ComputeNodalKernelJacobiansThread::_num_cached
protected

Number of contributions cached up.

Definition at line 59 of file ComputeNodalKernelJacobiansThread.h.

Referenced by onNode(), and pre().

◆ _tags

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

Definition at line 52 of file ComputeNodalKernelJacobiansThread.h.

Referenced by pre().

◆ _tid

THREAD_ID ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::_tid
protectedinherited

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