www.mooseframework.org
ComputeNodalKernelsThread.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 "AuxiliarySystem.h"
19 #include "FEProblem.h"
20 #include "MooseMesh.h"
21 #include "MooseVariable.h"
22 #include "NodalKernel.h"
23 
24 #include "libmesh/threads.h"
25 
27  FEProblemBase & fe_problem, const MooseObjectWarehouse<NodalKernel> & nodal_kernels)
28  : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(fe_problem),
29  _aux_sys(fe_problem.getAuxiliarySystem()),
30  _nodal_kernels(nodal_kernels),
31  _num_cached(0)
32 {
33 }
34 
35 // Splitting Constructor
37  Threads::split split)
38  : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(x, split),
39  _aux_sys(x._aux_sys),
41  _num_cached(0)
42 {
43 }
44 
45 void
47 {
48  _num_cached = 0;
49 }
50 
51 void
52 ComputeNodalKernelsThread::onNode(ConstNodeRange::const_iterator & node_it)
53 {
54  const Node * node = *node_it;
55 
56  // prepare variables
57  for (const auto & it : _aux_sys._nodal_vars[_tid])
58  {
59  MooseVariable * var = it.second;
60  var->prepareAux();
61  }
62 
63  _fe_problem.reinitNode(node, _tid);
64 
65  const std::set<SubdomainID> & block_ids = _aux_sys.mesh().getNodeBlockIds(*node);
66  for (const auto & block : block_ids)
67  if (_nodal_kernels.hasActiveBlockObjects(block, _tid))
68  {
69  const auto & objects = _nodal_kernels.getActiveBlockObjects(block, _tid);
70  for (const auto & nodal_kernel : objects)
71  nodal_kernel->computeResidual();
72  }
73 
74  _num_cached++;
75 
76  if (_num_cached == 20) // Cache 20 nodes worth before adding into the residual
77  {
78  _num_cached = 0;
79  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
81  }
82 }
83 
84 void
86 {
87 }
const MooseObjectWarehouse< NodalKernel > & _nodal_kernels
Class for stuff related to variables.
Definition: MooseVariable.h:43
std::vector< std::map< std::string, MooseVariable * > > _nodal_vars
void join(const ComputeNodalKernelsThread &)
virtual void onNode(ConstNodeRange::const_iterator &node_it) override
Called for each node.
ComputeNodalKernelsThread(FEProblemBase &fe_problem, const MooseObjectWarehouse< NodalKernel > &nodal_kernels)
static PetscErrorCode Vec x
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void addCachedResidual(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
virtual void pre() override
Called before the node range loop.
virtual MooseMesh & mesh()
Definition: SystemBase.h:102
unsigned int _num_cached
Number of contributions cached up.
bool hasActiveBlockObjects(THREAD_ID tid=0) const
virtual void reinitNode(const Node *node, THREAD_ID tid) override