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 "FEProblem.h"
14#include "DisplacedProblem.h"
15#include "Assembly.h"
16#include "AuxKernel.h"
17#include "SwapBackSentinel.h"
18
19#include "libmesh/threads.h"
20
21template <typename AuxKernelType>
23 FEProblemBase & fe_problem,
25 bool need_materials)
26 : _fe_problem(fe_problem),
27 _aux_sys(fe_problem.getAuxiliarySystem()),
28 _storage(storage),
29 _need_materials(need_materials)
30{
31}
32
33// Splitting Constructor
34template <typename AuxKernelType>
36 Threads::split /*split*/)
37 : _fe_problem(x._fe_problem),
38 _aux_sys(x._aux_sys),
39 _storage(x._storage),
40 _need_materials(x._need_materials)
41{
42}
43
44template <typename AuxKernelType>
45void
47{
49 _tid = puid.id;
50
51 // Reference to all boundary restricted AuxKernels for the current thread
52 const auto & boundary_kernels = _storage.getActiveBoundaryObjects(_tid);
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 // Locate the AuxKernel objects for the current BoundaryID
69 const auto iter = boundary_kernels.find(boundary_id);
70
71 if (iter != boundary_kernels.end() && !(iter->second.empty()))
72 {
73 printBoundaryExecutionInformation(boundary_id, iter->second);
74 const auto sub_id = elem->subdomain_id();
75 if (sub_id != last_sub_id)
76 {
77 _fe_problem.subdomainSetup(sub_id, _tid);
78 last_sub_id = sub_id;
79 }
80 _fe_problem.setCurrentSubdomainID(elem, _tid);
81 _fe_problem.prepare(elem, _tid);
82 _fe_problem.reinitElemFace(elem, side, _tid);
83
84 const Elem * lower_d_elem = _fe_problem.mesh().getLowerDElem(elem, side);
85 _fe_problem.setCurrentLowerDElem(lower_d_elem, _tid);
86 if (lower_d_elem)
87 _fe_problem.reinitLowerDElem(lower_d_elem, _tid);
88
89 const Elem * neighbor = elem->neighbor_ptr(side);
90
91 // The last check here is absolutely necessary otherwise we will attempt to evaluate
92 // neighbor materials on neighbor elements that aren't evaluable, e.g. don't have algebraic
93 // ghosting
94 bool compute_interface =
95 neighbor && neighbor->active() &&
96 _fe_problem.getInterfaceMaterialsWarehouse().hasActiveBoundaryObjects(boundary_id,
97 _tid);
98
99 // Set up Sentinel class so that, even if reinitMaterialsFace() throws, we
100 // still remember to swap back during stack unwinding.
101 SwapBackSentinel sentinel(_fe_problem, &FEProblem::swapBackMaterialsFace, _tid);
102 SwapBackSentinel neighbor_sentinel(
103 _fe_problem, &FEProblem::swapBackMaterialsNeighbor, _tid, compute_interface);
104
105 if (_need_materials)
106 {
107 std::unordered_set<unsigned int> needed_mat_props;
108 for (const auto & aux : iter->second)
109 {
110 const auto & mp_deps = aux->getMatPropDependencies();
111 needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
112 }
113 _fe_problem.setActiveMaterialProperties(needed_mat_props, _tid);
114
115 _fe_problem.reinitMaterialsFaceOnBoundary(boundary_id, sub_id, _tid);
116
117 _fe_problem.reinitMaterialsBoundary(boundary_id, _tid);
118
119 if (compute_interface)
120 {
121 _fe_problem.reinitNeighbor(elem, side, _tid);
122 _fe_problem.reinitMaterialsNeighbor(neighbor->subdomain_id(), _tid);
123 _fe_problem.reinitMaterialsInterface(boundary_id, _tid);
124 }
125 }
126
127 for (const auto & aux : iter->second)
128 {
129 aux->determineWhetherCoincidentLowerDCalc();
130 aux->compute();
131 aux->insert();
132 }
133
134 if (_need_materials)
135 _fe_problem.clearActiveMaterialProperties(_tid);
136 }
137 }
138 }
139}
140
141template <typename AuxKernelType>
142void
146
147template <typename AuxKernelType>
148void
150{
151 if (_fe_problem.shouldPrintExecution(_tid) && _storage.hasActiveObjects())
152 {
153 const auto & console = _fe_problem.console();
154 const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
155 console << "[DBG] Executing boundary restricted auxkernels on boundary elements on "
156 << execute_on << std::endl;
157 }
158}
159
160template <typename AuxKernelType>
161void
163 unsigned int boundary_id, const std::vector<std::shared_ptr<AuxKernelType>> & kernels) const
164{
165 if (!_fe_problem.shouldPrintExecution(_tid) || !_storage.hasActiveObjects() ||
166 _boundaries_exec_printed.count(boundary_id))
167 return;
168
169 const auto & console = _fe_problem.console();
170 console << "[DBG] Ordering on boundary " << boundary_id << std::endl;
171 std::vector<MooseObject *> objs_ptrs;
172 for (auto & kernel_ptr : kernels)
173 if (kernel_ptr->hasBoundary(boundary_id))
174 objs_ptrs.push_back(dynamic_cast<MooseObject *>(kernel_ptr.get()));
175 std::string list_kernels = ConsoleUtils::mooseObjectVectorToString(objs_ptrs);
176 console << ConsoleUtils::formatString(list_kernels, "[DBG]") << std::endl;
177 _boundaries_exec_printed.insert(boundary_id);
178}
179
boundary_id_type BoundaryID
ComputeElemAuxBcsThread(FEProblemBase &fe_problem, const MooseObjectWarehouse< AuxKernelType > &storage, bool need_materials)
void join(const ComputeElemAuxBcsThread &)
void operator()(const ConstBndElemRange &range)
void printBoundaryExecutionInformation(unsigned int boundary_id, const std::vector< std::shared_ptr< AuxKernelType > > &kernels) const
Print list of specific objects executed and in which order.
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)
A storage container for MooseObjects that inherit from SetupInterface.
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,...
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.