https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ComputeElemAuxBcsThread.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
10// MOOSE includes
12#include "AuxiliarySystem.h"
13#include "Attributes.h"
14#include "FEProblem.h"
15#include "DisplacedProblem.h"
16#include "Assembly.h"
17#include "AuxKernel.h"
18#include "SwapBackSentinel.h"
19#include "TheWarehouse.h"
20
21#include "libmesh/threads.h"
22
23template <typename AuxKernelType>
25 const TheWarehouse::Query & query,
26 bool need_materials)
27 : _fe_problem(fe_problem),
28 _aux_sys(fe_problem.getAuxiliarySystem()),
29 _all_kernels_query(query),
30 _query_boundary(query),
31 _need_materials(need_materials)
32{
33}
34
35// Splitting Constructor
36template <typename AuxKernelType>
38 Threads::split /*split*/)
39 : _fe_problem(x._fe_problem),
40 _aux_sys(x._aux_sys),
41 _all_kernels_query(x._all_kernels_query),
42 _query_boundary(x._query_boundary),
43 _need_materials(x._need_materials)
44{
45}
46
47template <typename AuxKernelType>
48void
50{
52 _tid = puid.id;
53
54 printGeneralExecutionInformation();
55
56 for (const auto & belem : range)
57 {
58 const Elem * elem = belem->_elem;
59 unsigned short int side = belem->_side;
60 BoundaryID boundary_id = belem->_bnd_id;
61 SubdomainID last_sub_id = Elem::invalid_subdomain_id;
62
63 // need to update the boundary ID in assembly
64 _fe_problem.setCurrentBoundaryID(boundary_id, _tid);
65
66 if (elem->processor_id() == _fe_problem.processor_id())
67 {
68 // Only kernels actually restricted to this boundary - unrestricted ones are already
69 // handled by the block-based element loop.
70 std::vector<AuxKernelType *> kernels;
71 _query_boundary.queryInto(
72 kernels, _tid, std::make_tuple(boundary_id, /*must_be_restricted=*/true));
73
74 if (!kernels.empty())
75 {
76 printBoundaryExecutionInformation(boundary_id, kernels);
77 const auto sub_id = elem->subdomain_id();
78 if (sub_id != last_sub_id)
79 {
80 _fe_problem.subdomainSetup(sub_id, _tid);
81 last_sub_id = sub_id;
82 }
83 _fe_problem.setCurrentSubdomainID(elem, _tid);
84 _fe_problem.prepare(elem, _tid);
85 _fe_problem.reinitElemFace(elem, side, _tid);
86
87 const Elem * lower_d_elem = _fe_problem.mesh().getLowerDElem(elem, side);
88 _fe_problem.setCurrentLowerDElem(lower_d_elem, _tid);
89 if (lower_d_elem)
90 _fe_problem.reinitLowerDElem(lower_d_elem, _tid);
91
92 const Elem * neighbor = elem->neighbor_ptr(side);
93
94 // The last check here is absolutely necessary otherwise we will attempt to evaluate
95 // neighbor materials on neighbor elements that aren't evaluable, e.g. don't have algebraic
96 // ghosting
97 bool compute_interface =
98 neighbor && neighbor->active() &&
99 _fe_problem.getInterfaceMaterialsWarehouse().hasActiveBoundaryObjects(boundary_id,
100 _tid);
101
102 // Set up Sentinel class so that, even if reinitMaterialsFace() throws, we
103 // still remember to swap back during stack unwinding.
104 SwapBackSentinel sentinel(_fe_problem, &FEProblem::swapBackMaterialsFace, _tid);
105 SwapBackSentinel neighbor_sentinel(
106 _fe_problem, &FEProblem::swapBackMaterialsNeighbor, _tid, compute_interface);
107
108 if (_need_materials)
109 {
110 std::unordered_set<unsigned int> needed_mat_props;
111 for (const auto & aux : kernels)
112 {
113 const auto & mp_deps = aux->getMatPropDependencies();
114 needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
115 }
116 _fe_problem.setActiveMaterialProperties(needed_mat_props, _tid);
117
118 _fe_problem.reinitMaterialsFaceOnBoundary(boundary_id, sub_id, _tid);
119
120 _fe_problem.reinitMaterialsBoundary(boundary_id, _tid);
121
122 if (compute_interface)
123 {
124 _fe_problem.reinitNeighbor(elem, side, _tid);
125 _fe_problem.reinitMaterialsNeighbor(neighbor->subdomain_id(), _tid);
126 _fe_problem.reinitMaterialsInterface(boundary_id, _tid);
127 }
128 }
129
130 for (const auto & aux : kernels)
131 {
132 aux->determineWhetherCoincidentLowerDCalc();
133 aux->compute();
134 aux->insert();
135 }
136
137 if (_need_materials)
138 _fe_problem.clearActiveMaterialProperties(_tid);
139 }
140 }
141 }
142}
143
144template <typename AuxKernelType>
145void
149
150template <typename AuxKernelType>
151void
153{
154 if (!_fe_problem.shouldPrintExecution(_tid))
155 return;
156
157 std::vector<AuxKernelType *> all_kernels;
158 _all_kernels_query.clone().condition<AttribThread>(_tid).queryInto(all_kernels);
159 if (all_kernels.empty())
160 return;
161
162 const auto & console = _fe_problem.console();
163 const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
164 console << "[DBG] Executing boundary restricted auxkernels on boundary elements on " << execute_on
165 << std::endl;
166}
167
168template <typename AuxKernelType>
169void
171 unsigned int boundary_id, const std::vector<AuxKernelType *> & kernels) const
172{
173 if (!_fe_problem.shouldPrintExecution(_tid) || _boundaries_exec_printed.count(boundary_id))
174 return;
175
176 const auto & console = _fe_problem.console();
177 console << "[DBG] Ordering on boundary " << boundary_id << std::endl;
178 std::vector<MooseObject *> objs_ptrs;
179 for (auto * kernel_ptr : kernels)
180 if (kernel_ptr->hasBoundary(boundary_id))
181 objs_ptrs.push_back(dynamic_cast<MooseObject *>(kernel_ptr));
182 std::string list_kernels = ConsoleUtils::mooseObjectVectorToString(objs_ptrs);
183 console << ConsoleUtils::formatString(list_kernels, "[DBG]") << std::endl;
184 _boundaries_exec_printed.insert(boundary_id);
185}
186
boundary_id_type BoundaryID
subdomain_id_type SubdomainID
void printBoundaryExecutionInformation(unsigned int boundary_id, const std::vector< AuxKernelType * > &kernels) const
Print list of specific objects executed and in which order.
void join(const ComputeElemAuxBcsThread &)
void operator()(const ConstBndElemRange &range)
ComputeElemAuxBcsThread(FEProblemBase &fe_problem, const TheWarehouse::Query &query, bool need_materials)
void printGeneralExecutionInformation() const
Print list of object types executed and in which order.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void swapBackMaterialsFace(const THREAD_ID tid)
virtual void swapBackMaterialsNeighbor(const THREAD_ID tid)
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
The "SwapBackSentinel" class's destructor guarantees that FEProblemBase::swapBackMaterials{Face,...
QueryCache is a convenient way to construct and pass around (possible partially constructed) warehous...
query_obj query
std::string formatString(std::string message, const std::string &prefix)
Add new lines and prefixes to a string for pretty display in output NOTE: This makes a copy of the st...
std::string mooseObjectVectorToString(const std::vector< MooseObject * > &objs, const std::string &sep=" ")
Routine to output the name of MooseObjects in a string.