www.mooseframework.org
ComputeNodalKernelJacobiansThread.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 
12 // MOOSE includes
13 #include "Assembly.h"
14 #include "AuxiliarySystem.h"
15 #include "FEProblem.h"
16 #include "MooseMesh.h"
17 #include "MooseVariableFE.h"
18 #include "NodalKernel.h"
19 
20 #include "libmesh/sparse_matrix.h"
21 
23  FEProblemBase & fe_problem,
25  const std::set<TagID> & tags)
26  : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(fe_problem),
27  _fe_problem(fe_problem),
28  _aux_sys(fe_problem.getAuxiliarySystem()),
29  _tags(tags),
30  _nodal_kernels(nodal_kernels),
31  _num_cached(0)
32 {
33 }
34 
35 // Splitting Constructor
38  : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(x, split),
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 }
46 
47 void
49 {
50  _num_cached = 0;
51 
52  if (!_tags.size() || _tags.size() == _fe_problem.numMatrixTags())
54  else if (_tags.size() == 1)
56  else
58 }
59 
60 void
61 ComputeNodalKernelJacobiansThread::onNode(ConstNodeRange::const_iterator & node_it)
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 (auto * var : _aux_sys._nodal_vars[_tid])
116  var->prepareAux();
117 
118  _fe_problem.reinitNode(node, _tid);
119 
120  for (const auto & nodal_kernel : active_involved_kernels)
121  nodal_kernel->computeOffDiagJacobian(jvar);
122 
123  _num_cached++;
124 
125  if (_num_cached == 20) // Cache 20 nodes worth before adding into the residual
126  {
127  _num_cached = 0;
128  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
130  }
131  }
132  }
133 }
134 
135 void
137 {
138 }
bool hasActiveBlockObjects(THREAD_ID tid=0) const
void join(const ComputeNodalKernelJacobiansThread &)
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
virtual void onNode(ConstNodeRange::const_iterator &node_it) override
Called for each node.
unsigned int number() const
Get variable number coming from libMesh.
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:847
ComputeNodalKernelJacobiansThread(FEProblemBase &fe_problem, MooseObjectTagWarehouse< NodalKernel > &nodal_kernels, const std::set< TagID > &tags)
static PetscErrorCode Vec x
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
std::vector< std::pair< MooseVariableFEBase *, MooseVariableFEBase * > > & couplingEntries(THREAD_ID tid)
std::vector< std::string > split(const std::string &str, const std::string &delimiter)
Python like split function for strings.
Definition: MooseUtils.C:736
MooseObjectWarehouse< T > & getMatrixTagObjectWarehouse(TagID tag_id, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has the given matrix tag...
std::vector< std::vector< MooseVariableFEBase * > > _nodal_vars
virtual unsigned int numMatrixTags() const
The total number of tags.
Definition: SubProblem.h:157
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 MooseMesh & mesh()
Definition: SystemBase.h:103
void addCachedJacobianContributions()
Adds previously-cached Jacobian values via SparseMatrix::add() calls.
Definition: Assembly.C:3488
virtual void reinitNode(const Node *node, THREAD_ID tid) override
virtual void pre() override
Called before the node range loop.
unsigned int _num_cached
Number of contributions cached up.