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, const MooseObjectWarehouse< NodalKernel > &nodal_kernels, SparseMatrix< Number > &jacobian)
 
 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

AuxiliarySystem_aux_sys
 
const MooseObjectWarehouse< NodalKernel > & _nodal_kernels
 
SparseMatrix< Number > & _jacobian
 
unsigned int _num_cached
 Number of contributions cached up. More...
 
FEProblemBase_fe_problem
 
THREAD_ID _tid
 

Detailed Description

Definition at line 34 of file ComputeNodalKernelJacobiansThread.h.

Constructor & Destructor Documentation

ComputeNodalKernelJacobiansThread::ComputeNodalKernelJacobiansThread ( FEProblemBase fe_problem,
const MooseObjectWarehouse< NodalKernel > &  nodal_kernels,
SparseMatrix< Number > &  jacobian 
)

Definition at line 27 of file ComputeNodalKernelJacobiansThread.C.

32  _aux_sys(fe_problem.getAuxiliarySystem()),
33  _nodal_kernels(nodal_kernels),
34  _jacobian(jacobian),
35  _num_cached(0)
36 {
37 }
AuxiliarySystem & getAuxiliarySystem()
const MooseObjectWarehouse< NodalKernel > & _nodal_kernels
unsigned int _num_cached
Number of contributions cached up.
ComputeNodalKernelJacobiansThread::ComputeNodalKernelJacobiansThread ( ComputeNodalKernelJacobiansThread x,
Threads::split  split 
)

Definition at line 40 of file ComputeNodalKernelJacobiansThread.C.

43  _aux_sys(x._aux_sys),
44  _nodal_kernels(x._nodal_kernels),
45  _jacobian(x._jacobian),
46  _num_cached(0)
47 {
48 }
static PetscErrorCode Vec x
const MooseObjectWarehouse< NodalKernel > & _nodal_kernels
unsigned int _num_cached
Number of contributions cached up.

Member Function Documentation

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 60 of file ThreadedNodeLoop.h.

61  {
62  std::string what(e.what());
64  };
virtual void setException(const std::string &message)
Set an exception.
virtual const char * what() const
Get out the error message.
void ComputeNodalKernelJacobiansThread::join ( const ComputeNodalKernelJacobiansThread )

Definition at line 133 of file ComputeNodalKernelJacobiansThread.C.

134 {
135 }
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 71 of file ThreadedNodeLoop.h.

71 { return !_fe_problem.hasException(); }
virtual bool hasException()
Whether or not an exception has occurred.
void ComputeNodalKernelJacobiansThread::onNode ( ConstNodeRange::const_iterator &  node_it)
overridevirtual

Called for each node.

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

Definition at line 57 of file ComputeNodalKernelJacobiansThread.C.

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

Called after the node range loop.

virtual 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
void ComputeNodalKernelJacobiansThread::pre ( )
overridevirtual

Called before the node range loop.

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

Definition at line 51 of file ComputeNodalKernelJacobiansThread.C.

52 {
53  _num_cached = 0;
54 }
unsigned int _num_cached
Number of contributions cached up.

Member Data Documentation

AuxiliarySystem& ComputeNodalKernelJacobiansThread::_aux_sys
protected

Definition at line 52 of file ComputeNodalKernelJacobiansThread.h.

Referenced by onNode().

FEProblemBase& ThreadedNodeLoop< ConstNodeRange , ConstNodeRange::const_iterator >::_fe_problem
protectedinherited
SparseMatrix<Number>& ComputeNodalKernelJacobiansThread::_jacobian
protected

Definition at line 56 of file ComputeNodalKernelJacobiansThread.h.

Referenced by onNode().

const MooseObjectWarehouse<NodalKernel>& ComputeNodalKernelJacobiansThread::_nodal_kernels
protected

Definition at line 54 of file ComputeNodalKernelJacobiansThread.h.

Referenced by onNode().

unsigned int ComputeNodalKernelJacobiansThread::_num_cached
protected

Number of contributions cached up.

Definition at line 59 of file ComputeNodalKernelJacobiansThread.h.

Referenced by onNode(), and pre().

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

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