https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ComputeNodalAuxVarsThread.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 "AuxiliarySystem.h"
14#include "AuxKernel.h"
15#include "FEProblem.h"
16#include "MooseMesh.h"
17
18#include "libmesh/threads.h"
19
20template <typename AuxKernelType>
22
23template <typename AuxKernelType>
25 FEProblemBase & fe_problem, const TheWarehouse::Query & query)
26 : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(fe_problem),
27 _aux_sys(fe_problem.getAuxiliarySystem()),
28 _all_kernels_query(query),
29 _query_subdomain(query)
30{
31}
32
33// Splitting Constructor
34template <typename AuxKernelType>
36 Threads::split split)
37 : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(x, split),
38 _aux_sys(x._aux_sys),
39 _all_kernels_query(x._all_kernels_query),
40 _query_subdomain(x._query_subdomain)
41{
42}
43
44template <typename AuxKernelType>
45void
47{
48 std::set<TagID> needed_vector_tags;
49 std::set<TagID> needed_matrix_tags;
50
51 for (const auto & block : _block_ids)
52 {
53 std::vector<AuxKernelType *> block_kernels;
54 _query_subdomain.queryInto(block_kernels, _tid, block);
55
56 if (block_kernels.size())
57 for (const auto & aux : block_kernels)
58 {
59 auto & matrix_tags = aux->getFEVariableCoupleableMatrixTags();
60 needed_matrix_tags.insert(matrix_tags.begin(), matrix_tags.end());
61 auto & vector_tags = aux->getFEVariableCoupleableVectorTags();
62 needed_vector_tags.insert(vector_tags.begin(), vector_tags.end());
63 }
64 }
65
66 _fe_problem.setActiveFEVariableCoupleableMatrixTags(needed_matrix_tags, _tid);
67 _fe_problem.setActiveFEVariableCoupleableVectorTags(needed_vector_tags, _tid);
68}
69
70template <typename AuxKernelType>
71void
72ComputeNodalAuxVarsThread<AuxKernelType>::onNode(ConstNodeRange::const_iterator & node_it)
73{
74 const Node * node = *node_it;
75
76 const auto & block_ids = _aux_sys.mesh().getNodeBlockIds(*node);
77
78 if (_block_ids != block_ids)
79 {
80 _block_ids.clear();
81 _block_ids.insert(block_ids.begin(), block_ids.end());
82 subdomainChanged();
83 }
84
85 _fe_problem.reinitNode(node, _tid);
86
87 // Loop over all SubdomainIDs for the current node, if an AuxKernel is active on this block then
88 // compute it.
89 for (const auto & block : _block_ids)
90 {
91 std::vector<AuxKernelType *> block_kernels;
92 _query_subdomain.queryInto(block_kernels, _tid, block);
93
94 if (block_kernels.size())
95 for (const auto & aux : block_kernels)
96 {
97 aux->compute();
98 // This is the same conditional check that the aux kernel performs internally before calling
99 // computeValue and _var.setNodalValue. We don't want to attempt to insert into the solution
100 // if we don't actually have any dofs on this node
101 if (aux->variable().isNodalDefined())
102 aux->variable().insert(_aux_sys.solution());
103
104 // update the aux solution vector if writable coupled variables are used
105 if (aux->hasWritableCoupledVariables())
106 {
107 for (auto * var : aux->getWritableCoupledVariables())
108 if (var->isNodalDefined())
109 // insert into the global solution vector
110 var->insert(_aux_sys.solution());
111
112 // make solution values available for dependent AuxKernels
113 _fe_problem.reinitNode(node, _tid);
114 }
115 }
116 }
117}
118
119template <typename AuxKernelType>
120void
122{
123 _fe_problem.clearActiveFEVariableCoupleableVectorTags(_tid);
124 _fe_problem.clearActiveFEVariableCoupleableMatrixTags(_tid);
125}
126
127template <typename AuxKernelType>
128void
132
133template <typename AuxKernelType>
134void
136{
137 if (!_fe_problem.shouldPrintExecution(_tid))
138 return;
139
140 std::vector<AuxKernelType *> all_kernels;
141 // clone the query until we have a const query, see #32362
142 // This is "general" execution ordering so we query for all subdomains
143 _all_kernels_query.clone().condition<AttribThread>(_tid).queryInto(all_kernels);
144 if (all_kernels.empty())
145 return;
146
147 const auto & console = _fe_problem.console();
148 const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
149 console << "[DBG] Beginning nodal loop of nodal " << MooseUtils::prettyCppType<AuxKernelType>()
150 << " on " << execute_on << std::endl;
151 console << "[DBG] Ordering of the kernels on each block they are defined on:" << std::endl;
152 // TODO Check that all objects are active at this point
153 printExecutionOrdering<AuxKernelType>(all_kernels, /*print_header=*/false);
154}
155
void printGeneralExecutionInformation() const override
Print information about the loop, mostly order of execution of objects.
void join(const ComputeNodalAuxVarsThread &)
ComputeNodalAuxVarsThread(FEProblemBase &fe_problem, const TheWarehouse::Query &query)
void onNode(ConstNodeRange::const_iterator &nd) override
void post() override
Called after the node range loop.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
QueryCache is a convenient way to construct and pass around (possible partially constructed) warehous...
query_obj query