www.mooseframework.org
ComputeNodalKernelBCJacobiansThread.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 "MooseVariable.h"
22 #include "NodalKernel.h"
23 
24 #include "libmesh/threads.h"
25 
27  FEProblemBase & fe_problem,
28  const MooseObjectWarehouse<NodalKernel> & nodal_kernels,
29  SparseMatrix<Number> & jacobian)
30  : ThreadedNodeLoop<ConstBndNodeRange, ConstBndNodeRange::const_iterator>(fe_problem),
31  _aux_sys(fe_problem.getAuxiliarySystem()),
32  _nodal_kernels(nodal_kernels),
33  _jacobian(jacobian),
34  _num_cached(0)
35 {
36 }
37 
38 // Splitting Constructor
40  ComputeNodalKernelBCJacobiansThread & x, Threads::split split)
41  : ThreadedNodeLoop<ConstBndNodeRange, ConstBndNodeRange::const_iterator>(x, split),
42  _aux_sys(x._aux_sys),
45  _num_cached(0)
46 {
47 }
48 
49 void
51 {
52  _num_cached = 0;
53 }
54 
55 void
56 ComputeNodalKernelBCJacobiansThread::onNode(ConstBndNodeRange::const_iterator & node_it)
57 {
58  const BndNode * bnode = *node_it;
59 
60  BoundaryID boundary_id = bnode->_bnd_id;
61 
62  std::vector<std::pair<MooseVariable *, MooseVariable *>> & ce = _fe_problem.couplingEntries(_tid);
63  for (const auto & it : ce)
64  {
65  MooseVariable & ivariable = *(it.first);
66  MooseVariable & jvariable = *(it.second);
67 
68  unsigned int ivar = ivariable.number();
69  unsigned int jvar = jvariable.number();
70 
71  // The NodalKernels that are active and are coupled to the jvar in question
72  std::vector<std::shared_ptr<NodalKernel>> active_involved_kernels;
73 
75  {
76  // Loop over each NodalKernel to see if it's involved with the jvar
77  const auto & objects = _nodal_kernels.getActiveBoundaryObjects(boundary_id, _tid);
78  for (const auto & nodal_kernel : objects)
79  {
80  // If this NodalKernel isn't operating on this ivar... skip it
81  if (nodal_kernel->variable().number() != ivar)
82  break;
83 
84  // If this NodalKernel is acting on the jvar add it to the list and short-circuit the loop
85  if (nodal_kernel->variable().number() == jvar)
86  {
87  active_involved_kernels.push_back(nodal_kernel);
88  continue;
89  }
90 
91  // See if this NodalKernel is coupled to the jvar
92  const std::vector<MooseVariable *> & coupled_vars = nodal_kernel->getCoupledMooseVars();
93  for (const auto & var : coupled_vars)
94  {
95  if (var->number() == jvar)
96  {
97  active_involved_kernels.push_back(nodal_kernel);
98  break; // It only takes one
99  }
100  }
101  }
102  }
103 
104  // Did we find any NodalKernels coupled to this jvar?
105  if (!active_involved_kernels.empty())
106  {
107  // prepare variables
108  for (const auto & it : _aux_sys._nodal_vars[_tid])
109  {
110  MooseVariable * var = it.second;
111  var->prepareAux();
112  }
113 
114  if (_nodal_kernels.hasActiveBoundaryObjects(boundary_id, _tid))
115  {
116  Node * node = bnode->_node;
117  if (node->processor_id() == _fe_problem.processor_id())
118  {
119  _fe_problem.reinitNodeFace(node, boundary_id, _tid);
120  for (const auto & nodal_kernel : active_involved_kernels)
121  nodal_kernel->computeOffDiagJacobian(jvar);
122 
123  _num_cached++;
124  }
125  }
126 
127  if (_num_cached == 20) // cache 20 nodes worth before adding into the jacobian
128  {
129  _num_cached = 0;
130  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
132  }
133  }
134  }
135 }
136 
137 void
139 {
140 }
const MooseObjectWarehouse< NodalKernel > & _nodal_kernels
Class for stuff related to variables.
Definition: MooseVariable.h:43
std::vector< std::map< std::string, MooseVariable * > > _nodal_vars
virtual void pre() override
Called before the node range loop.
virtual Assembly & assembly(THREAD_ID tid) override
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
static PetscErrorCode Vec x
BoundaryID _bnd_id
boundary id for the node
Definition: BndNode.h:28
Node * _node
pointer to the node
Definition: BndNode.h:26
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void onNode(ConstBndNodeRange::const_iterator &node_it) override
Called for each node.
void join(const ComputeNodalKernelBCJacobiansThread &)
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
unsigned int _num_cached
Number of contributions cached up.
ComputeNodalKernelBCJacobiansThread(FEProblemBase &fe_problem, const MooseObjectWarehouse< NodalKernel > &nodal_kernels, SparseMatrix< Number > &jacobian)
virtual void reinitNodeFace(const Node *node, BoundaryID bnd_id, THREAD_ID tid) override
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.
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > ConstBndNodeRange
Some useful StoredRange typedefs.
Definition: MooseMesh.h:1213
boundary_id_type BoundaryID
Definition: MooseTypes.h:75