https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ComputeNodalKernelJacobiansThread.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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 "NodalKernelBase.h"
19#include "NonlinearSystemBase.h"
20
21#include "libmesh/sparse_matrix.h"
22
24 FEProblemBase & fe_problem,
27 const std::set<TagID> & tags)
28 : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(fe_problem),
29 _fe_problem(fe_problem),
30 _nl(nl),
31 _aux_sys(fe_problem.getAuxiliarySystem()),
32 _tags(tags),
33 _nodal_kernels(nodal_kernels),
34 _num_cached(0)
35{
36}
37
38// Splitting Constructor
41 : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(x, split),
42 _fe_problem(x._fe_problem),
43 _nl(x._nl),
44 _aux_sys(x._aux_sys),
45 _tags(x._tags),
46 _nodal_kernels(x._nodal_kernels),
47 _num_cached(0)
48{
49}
50
51void
63
64void
65ComputeNodalKernelJacobiansThread::onNode(ConstNodeRange::const_iterator & node_it)
66{
67 const Node * node = *node_it;
68
70 for (const auto & it : ce)
71 {
72 MooseVariableFEBase & ivariable = *(it.first);
73 MooseVariableFEBase & jvariable = *(it.second);
74
75 unsigned int ivar = ivariable.number();
76 unsigned int jvar = jvariable.number();
77
78 // The NodalKernels that are active and are coupled to the jvar in question
79 std::vector<std::shared_ptr<NodalKernelBase>> active_involved_kernels;
80 // A NodalKernel active on several of the node's blocks must contribute only once
81 std::set<const NodalKernelBase *> involved_kernels;
82
83 const auto & block_ids = _aux_sys.mesh().getNodeBlockIds(*node);
84 for (const auto & block : block_ids)
85 {
87 {
88 // Loop over each NodalKernel to see if it's involved with the jvar
89 const auto & objects = _nkernel_warehouse->getActiveBlockObjects(block, _tid);
90 for (const auto & nodal_kernel : objects)
91 {
92 if (nodal_kernel->variable().number() == ivar)
93 {
94 // If this NodalKernel is acting on the jvar add it to the list and short-circuit the
95 // loop
96 if (nodal_kernel->variable().number() == jvar)
97 {
98 if (involved_kernels.insert(nodal_kernel.get()).second)
99 active_involved_kernels.push_back(nodal_kernel);
100 continue;
101 }
102
103 // See if this NodalKernel is coupled to the jvar
104 const std::vector<MooseVariableFEBase *> & coupled_vars =
105 nodal_kernel->getCoupledMooseVars();
106 for (const auto & var : coupled_vars)
107 if (var->number() == jvar)
108 {
109 if (involved_kernels.insert(nodal_kernel.get()).second)
110 active_involved_kernels.push_back(nodal_kernel);
111 break; // It only takes one
112 }
113 }
114 }
115 }
116 }
117
118 // Did we find any NodalKernels coupled to this jvar?
119 if (!active_involved_kernels.empty())
120 {
121 // prepare variables
122 for (auto * var : _aux_sys._nodal_vars[_tid])
123 var->prepareAux();
124
126
127 for (const auto & nodal_kernel : active_involved_kernels)
128 {
129 nodal_kernel->setSubdomains(block_ids);
130 nodal_kernel->computeOffDiagJacobian(jvar);
131 }
132
133 _num_cached++;
134
135 if (_num_cached == 20) // Cache 20 nodes worth before adding into the residual
136 {
137 _num_cached = 0;
139 }
140 }
141 }
142}
143
144void
148
149void
151{
153 return;
154
155 const auto & console = _fe_problem.console();
156 const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
157 console << "[DBG] Executing nodal kernels contribution to Jacobian on nodes on " << execute_on
158 << std::endl;
159 console << _nkernel_warehouse->activeObjectsToFormattedString() << std::endl;
160}
std::vector< std::vector< MooseVariableFEBase * > > _nodal_vars
MooseObjectTagWarehouse< NodalKernelBase > & _nodal_kernels
virtual void pre() override
Called before the node range loop.
void printGeneralExecutionInformation() const override
Print information about the loop, mostly order of execution of objects.
ComputeNodalKernelJacobiansThread(FEProblemBase &fe_problem, NonlinearSystemBase &nl, MooseObjectTagWarehouse< NodalKernelBase > &nodal_kernels, const std::set< TagID > &tags)
unsigned int _num_cached
Number of contributions cached up.
void join(const ComputeNodalKernelJacobiansThread &)
MooseObjectWarehouse< NodalKernelBase > * _nkernel_warehouse
virtual void onNode(ConstNodeRange::const_iterator &node_it) override
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void addCachedJacobian(const THREAD_ID tid) override
virtual void reinitNode(const Node *node, const THREAD_ID tid) override
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
bool shouldPrintExecution(const THREAD_ID tid) const
Check whether the problem should output execution orders at this time.
std::vector< std::pair< MooseVariableFieldBase *, MooseVariableFieldBase * > > & couplingEntries(const THREAD_ID tid, const unsigned int nl_sys_num)
const std::set< SubdomainID > & getNodeBlockIds(const Node &node) const
Return list of blocks to which the given node belongs.
Definition MooseMesh.C:1447
A storage container for MooseObjects that inherit from SetupInterface.
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.
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::string activeObjectsToFormattedString(THREAD_ID tid=0, const std::string &prefix="[DBG]") const
Output the active content of the warehouse to a string, meant to be output to the console.
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
bool hasActiveObjects(THREAD_ID tid=0) const
bool hasActiveBlockObjects(THREAD_ID tid=0) const
unsigned int number() const
Get variable number coming from libMesh.
This class provides an interface for common operations on field variables of both FE and FV types wit...
Nonlinear system to be solved.
const ConsoleStream & console() const
Return console handle.
Definition Problem.h:48
virtual unsigned int numMatrixTags() const
The total number of tags.
Definition SubProblem.h:251
unsigned int number() const
Gets the number of this system.
MooseMesh & mesh()
Definition SystemBase.h:100