https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ComputeElemAuxVarsThread.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 "SwapBackSentinel.h"
16#include "FEProblem.h"
17#include "MaterialBase.h"
18#include "ThreadedElementLoop.h"
19
20#include "libmesh/threads.h"
21
22template <typename AuxKernelType>
24 const TheWarehouse::Query & query,
25 bool need_materials)
26 : ThreadedElementLoop<ConstElemRange>(problem),
27 _aux_sys(problem.getAuxiliarySystem()),
28 _all_kernels_query(query),
29 _query_subdomain(query),
30 _need_materials(need_materials)
31{
32}
33
34// Splitting Constructor
35template <typename AuxKernelType>
37 Threads::split /*split*/)
38 : ThreadedElementLoop<ConstElemRange>(x._fe_problem),
39 _aux_sys(x._aux_sys),
40 _all_kernels_query(x._all_kernels_query),
41 _query_subdomain(x._query_subdomain),
42 _need_materials(x._need_materials)
43{
44}
45
46template <typename AuxKernelType>
50
51template <typename AuxKernelType>
52void
54{
55 _fe_problem.subdomainSetup(_subdomain, _tid);
56
57 std::set<MooseVariableFEBase *> needed_moose_vars;
58 std::unordered_set<unsigned int> needed_mat_props;
59 std::set<TagID> needed_fe_var_matrix_tags;
60 std::set<TagID> needed_fe_var_vector_tags;
61
62 _fe_problem.getMaterialWarehouse().updateBlockFEVariableCoupledVectorTagDependency(
63 _subdomain, needed_fe_var_vector_tags, _tid);
64
65 std::vector<AuxKernelType *> kernels;
66 _query_subdomain.queryInto(kernels, _tid, _subdomain);
67 for (const auto & aux : kernels)
68 {
69 aux->subdomainSetup();
70 const auto & mv_deps = aux->getMooseVariableDependencies();
71 const auto & mp_deps = aux->getMatPropDependencies();
72 needed_moose_vars.insert(mv_deps.begin(), mv_deps.end());
73 needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
74
75 auto & fe_var_coup_vtags = aux->getFEVariableCoupleableVectorTags();
76 needed_fe_var_vector_tags.insert(fe_var_coup_vtags.begin(), fe_var_coup_vtags.end());
77
78 auto & fe_var_coup_mtags = aux->getFEVariableCoupleableMatrixTags();
79 needed_fe_var_matrix_tags.insert(fe_var_coup_mtags.begin(), fe_var_coup_mtags.end());
80 }
81
82 _fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid);
83 _fe_problem.prepareMaterials(needed_mat_props, _subdomain, _tid);
84 _fe_problem.setActiveFEVariableCoupleableMatrixTags(needed_fe_var_matrix_tags, _tid);
85 _fe_problem.setActiveFEVariableCoupleableVectorTags(needed_fe_var_vector_tags, _tid);
86}
87
88template <typename AuxKernelType>
89void
91{
92 std::vector<AuxKernelType *> kernels;
93 _query_subdomain.queryInto(kernels, _tid, _subdomain);
94 if (kernels.size())
95 {
96 _fe_problem.prepare(elem, _tid);
97 _fe_problem.reinitElem(elem, _tid);
98
99 // Set up the sentinel so that, even if reinitMaterials() throws, we
100 // still remember to swap back.
101 SwapBackSentinel sentinel(_fe_problem, &FEProblem::swapBackMaterials, _tid, _need_materials);
102
103 if (_need_materials)
104 _fe_problem.reinitMaterials(elem->subdomain_id(), _tid);
105
106 for (const auto & aux : kernels)
107 {
108 aux->compute();
109 aux->variable().insert(_aux_sys.solution());
110
111 // update the aux solution vector if writable coupled variables are used
112 if (aux->hasWritableCoupledVariables())
113 {
114 for (auto * var : aux->getWritableCoupledVariables())
115 var->insert(_aux_sys.solution());
116
117 _fe_problem.reinitElem(elem, _tid);
118 }
119 }
120 }
121}
122
123template <typename AuxKernelType>
124void
126{
127 _fe_problem.clearActiveElementalMooseVariables(_tid);
128 _fe_problem.clearActiveMaterialProperties(_tid);
129
130 _fe_problem.clearActiveFEVariableCoupleableVectorTags(_tid);
131 _fe_problem.clearActiveFEVariableCoupleableMatrixTags(_tid);
132}
133
134template <typename AuxKernelType>
135void
139
140template <typename AuxKernelType>
141void
143{
144 if (!_fe_problem.shouldPrintExecution(_tid))
145 return;
146
147 std::vector<AuxKernelType *> all_kernels;
148 // clone the query until we have a const query, see #32362
149 _all_kernels_query.clone().condition<AttribThread>(_tid).queryInto(all_kernels);
150 if (all_kernels.empty())
151 return;
152
153 const auto & console = _fe_problem.console();
154 const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
155 console << "[DBG] Executing auxiliary kernels on elements on " << execute_on << std::endl;
156}
157
158template <typename AuxKernelType>
159void
161{
162 if (!_fe_problem.shouldPrintExecution(_tid) || _blocks_exec_printed.count(_subdomain))
163 return;
164
165 std::vector<AuxKernelType *> kernels;
166 _query_subdomain.queryInto(kernels, _tid, _subdomain);
167 if (kernels.empty())
168 return;
169
170 const auto & console = _fe_problem.console();
171 console << "[DBG] Ordering of AuxKernels on block " << _subdomain << std::endl;
172 printExecutionOrdering<AuxKernelType>(kernels, false);
173 _blocks_exec_printed.insert(_subdomain);
174}
175
void printGeneralExecutionInformation() const override
Print list of object types executed and in which order.
virtual void post() override
Called after the element range loop.
ComputeElemAuxVarsThread(FEProblemBase &problem, const TheWarehouse::Query &query, bool need_materials)
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
void join(const ComputeElemAuxVarsThread &)
virtual void subdomainChanged() override
Called every time the current subdomain changes (i.e.
void printBlockExecutionInformation() const override
Print list of specific objects executed and in which order.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void swapBackMaterials(const THREAD_ID tid)
The "SwapBackSentinel" class's destructor guarantees that FEProblemBase::swapBackMaterials{Face,...
QueryCache is a convenient way to construct and pass around (possible partially constructed) warehous...
Base class for assembly-like calculations.
query_obj query