www.mooseframework.org
ComputeNodalKernelJacobiansThread.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
16 
17 // MOOSE includes
18 #include "Assembly.h"
19 #include "AuxiliarySystem.h"
20 #include "FEProblem.h"
21 #include "MooseMesh.h"
22 #include "MooseVariable.h"
23 #include "NodalKernel.h"
24 
25 #include "libmesh/sparse_matrix.h"
26 
28  FEProblemBase & fe_problem,
29  const MooseObjectWarehouse<NodalKernel> & nodal_kernels,
30  SparseMatrix<Number> & jacobian)
31  : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(fe_problem),
32  _aux_sys(fe_problem.getAuxiliarySystem()),
33  _nodal_kernels(nodal_kernels),
34  _jacobian(jacobian),
35  _num_cached(0)
36 {
37 }
38 
39 // Splitting Constructor
41  ComputeNodalKernelJacobiansThread & x, Threads::split split)
42  : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(x, split),
43  _aux_sys(x._aux_sys),
46  _num_cached(0)
47 {
48 }
49 
50 void
52 {
53  _num_cached = 0;
54 }
55 
56 void
57 ComputeNodalKernelJacobiansThread::onNode(ConstNodeRange::const_iterator & node_it)
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 }
131 
132 void
134 {
135 }
ComputeNodalKernelJacobiansThread(FEProblemBase &fe_problem, const MooseObjectWarehouse< NodalKernel > &nodal_kernels, SparseMatrix< Number > &jacobian)
void join(const ComputeNodalKernelJacobiansThread &)
Class for stuff related to variables.
Definition: MooseVariable.h:43
virtual void onNode(ConstNodeRange::const_iterator &node_it) override
Called for each node.
std::vector< std::map< std::string, MooseVariable * > > _nodal_vars
virtual Assembly & assembly(THREAD_ID tid) override
static PetscErrorCode Vec x
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
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
virtual void pre() override
Called before the node range loop.
const MooseObjectWarehouse< NodalKernel > & _nodal_kernels
unsigned int _num_cached
Number of contributions cached up.