www.mooseframework.org
ComputeNodalKernelsThread.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 "AuxiliarySystem.h"
14 #include "FEProblem.h"
15 #include "MooseMesh.h"
16 #include "MooseVariableFE.h"
17 #include "NodalKernel.h"
18 
19 #include "libmesh/threads.h"
20 
22  FEProblemBase & fe_problem,
24  const std::set<TagID> & tags)
25  : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(fe_problem),
26  _fe_problem(fe_problem),
27  _aux_sys(fe_problem.getAuxiliarySystem()),
28  _tags(tags),
29  _nodal_kernels(nodal_kernels),
30  _num_cached(0)
31 {
32 }
33 
34 // Splitting Constructor
37  : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(x, split),
38  _fe_problem(x._fe_problem),
39  _aux_sys(x._aux_sys),
40  _tags(x._tags),
41  _nodal_kernels(x._nodal_kernels),
42  _num_cached(0)
43 {
44 }
45 
46 void
48 {
49  _num_cached = 0;
50 
51  if (!_tags.size() || _tags.size() == _fe_problem.numVectorTags())
53  else if (_tags.size() == 1)
55  else
57 }
58 
59 void
60 ComputeNodalKernelsThread::onNode(ConstNodeRange::const_iterator & node_it)
61 {
62  const Node * node = *node_it;
63 
64  // prepare variables
65  for (auto * var : _aux_sys._nodal_vars[_tid])
66  var->prepareAux();
67 
69 
70  const std::set<SubdomainID> & block_ids = _aux_sys.mesh().getNodeBlockIds(*node);
71  for (const auto & block : block_ids)
73  {
74  const auto & objects = _nkernel_warehouse->getActiveBlockObjects(block, _tid);
75  for (const auto & nodal_kernel : objects)
76  nodal_kernel->computeResidual();
77  }
78 
79  _num_cached++;
80 
81  if (_num_cached == 20) // Cache 20 nodes worth before adding into the residual
82  {
83  _num_cached = 0;
84  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
86  }
87 }
88 
89 void
91 {
92 }
MooseObjectWarehouse< NodalKernel > * _nkernel_warehouse
bool hasActiveBlockObjects(THREAD_ID tid=0) const
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
void join(const ComputeNodalKernelsThread &)
MooseObjectTagWarehouse< NodalKernel > & _nodal_kernels
virtual void onNode(ConstNodeRange::const_iterator &node_it) override
Called for each node.
ComputeNodalKernelsThread(FEProblemBase &fe_problem, MooseObjectTagWarehouse< NodalKernel > &nodal_kernels, const std::set< TagID > &tags)
MooseObjectWarehouse< T > & getVectorTagsObjectWarehouse(const std::set< TagID > &tags, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object at least has one of the given vector ta...
const std::set< SubdomainID > & getNodeBlockIds(const Node &node) const
Return list of blocks to which the given node belongs.
Definition: MooseMesh.C:847
static PetscErrorCode Vec x
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
std::vector< std::string > split(const std::string &str, const std::string &delimiter)
Python like split function for strings.
Definition: MooseUtils.C:736
const std::set< TagID > & _tags
virtual void addCachedResidual(THREAD_ID tid) override
virtual unsigned int numVectorTags() const
The total number of tags.
Definition: SubProblem.h:122
std::vector< std::vector< MooseVariableFEBase * > > _nodal_vars
virtual void pre() override
Called before the node range loop.
virtual MooseMesh & mesh()
Definition: SystemBase.h:103
unsigned int _num_cached
Number of contributions cached up.
MooseObjectWarehouse< T > & getVectorTagObjectWarehouse(TagID tag_id, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has the given vector tag...
virtual void reinitNode(const Node *node, THREAD_ID tid) override