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 FEProblemBase & problem,
26 bool need_materials)
27 : ThreadedElementLoop<ConstElemRange>(problem),
28 _aux_sys(problem.getAuxiliarySystem()),
29 _aux_kernels(storage),
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 _aux_kernels(x._aux_kernels),
41 _need_materials(x._need_materials)
42{
43}
44
45template <typename AuxKernelType>
49
50template <typename AuxKernelType>
51void
53{
54 _fe_problem.subdomainSetup(_subdomain, _tid);
55
56 std::set<MooseVariableFEBase *> needed_moose_vars;
57 std::unordered_set<unsigned int> needed_mat_props;
58 std::set<TagID> needed_fe_var_matrix_tags;
59 std::set<TagID> needed_fe_var_vector_tags;
60
61 _fe_problem.getMaterialWarehouse().updateBlockFEVariableCoupledVectorTagDependency(
62 _subdomain, needed_fe_var_vector_tags, _tid);
63 if (_aux_kernels.hasActiveBlockObjects(_subdomain, _tid))
64 {
65 const std::vector<std::shared_ptr<AuxKernelType>> & kernels =
66 _aux_kernels.getActiveBlockObjects(_subdomain, _tid);
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
83 _fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid);
84 _fe_problem.prepareMaterials(needed_mat_props, _subdomain, _tid);
85 _fe_problem.setActiveFEVariableCoupleableMatrixTags(needed_fe_var_matrix_tags, _tid);
86 _fe_problem.setActiveFEVariableCoupleableVectorTags(needed_fe_var_vector_tags, _tid);
87}
88
89template <typename AuxKernelType>
90void
92{
93 if (_aux_kernels.hasActiveBlockObjects(_subdomain, _tid))
94 {
95 const std::vector<std::shared_ptr<AuxKernelType>> & kernels =
96 _aux_kernels.getActiveBlockObjects(_subdomain, _tid);
97 _fe_problem.prepare(elem, _tid);
98 _fe_problem.reinitElem(elem, _tid);
99
100 // Set up the sentinel so that, even if reinitMaterials() throws, we
101 // still remember to swap back.
102 SwapBackSentinel sentinel(_fe_problem, &FEProblem::swapBackMaterials, _tid, _need_materials);
103
104 if (_need_materials)
105 _fe_problem.reinitMaterials(elem->subdomain_id(), _tid);
106
107 for (const auto & aux : kernels)
108 {
109 aux->compute();
110 aux->variable().insert(_aux_sys.solution());
111
112 // update the aux solution vector if writable coupled variables are used
113 if (aux->hasWritableCoupledVariables())
114 {
115 for (auto * var : aux->getWritableCoupledVariables())
116 var->insert(_aux_sys.solution());
117
118 _fe_problem.reinitElem(elem, _tid);
119 }
120 }
121 }
122}
123
124template <typename AuxKernelType>
125void
127{
128 _fe_problem.clearActiveElementalMooseVariables(_tid);
129 _fe_problem.clearActiveMaterialProperties(_tid);
130
131 _fe_problem.clearActiveFEVariableCoupleableVectorTags(_tid);
132 _fe_problem.clearActiveFEVariableCoupleableMatrixTags(_tid);
133}
134
135template <typename AuxKernelType>
136void
140
141template <typename AuxKernelType>
142void
144{
145 if (!_fe_problem.shouldPrintExecution(_tid) || !_aux_kernels.hasActiveObjects())
146 return;
147
148 const auto & console = _fe_problem.console();
149 const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
150 console << "[DBG] Executing auxiliary kernels on elements on " << execute_on << std::endl;
151}
152
153template <typename AuxKernelType>
154void
156{
157 if (!_fe_problem.shouldPrintExecution(_tid) || _blocks_exec_printed.count(_subdomain) ||
158 !_aux_kernels.hasActiveBlockObjects(_subdomain, _tid))
159 return;
160
161 const auto & console = _fe_problem.console();
162 const auto & kernels = _aux_kernels.getActiveBlockObjects(_subdomain, _tid);
163 console << "[DBG] Ordering of AuxKernels on block " << _subdomain << std::endl;
164 printExecutionOrdering<AuxKernelType>(kernels, false);
165 _blocks_exec_printed.insert(_subdomain);
166}
167
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 MooseObjectWarehouse< AuxKernelType > &storage, 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)
A storage container for MooseObjects that inherit from SetupInterface.
The "SwapBackSentinel" class's destructor guarantees that FEProblemBase::swapBackMaterials{Face,...
Base class for assembly-like calculations.