https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ComputeUserObjectsThread.h
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#pragma once
11
12// MOOSE includes
13#include "ThreadedElementLoop.h"
14#include "ExecFlagEnum.h"
15#include "AuxiliarySystem.h"
16
17#include "libmesh/elem_range.h"
18
19#include <map>
20
26
27// libMesh forward declarations
28namespace libMesh
29{
30template <typename T>
31class NumericVector;
32}
33
37class ComputeUserObjectsThread : public ThreadedElementLoop<ConstElemRange>
38{
39public:
41 // Splitting Constructor
43
45
46 virtual void onElement(const Elem * elem) override;
47 virtual void onBoundary(const Elem * elem,
48 unsigned int side,
49 BoundaryID bnd_id,
50 const Elem * lower_d_elem = nullptr) override;
51 virtual void onInternalSide(const Elem * elem, unsigned int side) override;
52 virtual void onExternalSide(const Elem * elem, unsigned int side) override;
53 virtual void onInterface(const Elem * elem, unsigned int side, BoundaryID bnd_id) override;
54 virtual void post() override;
55 virtual void subdomainChanged() override;
56
57 void join(const ComputeUserObjectsThread & /*y*/);
58
59protected:
61 void printGeneralExecutionInformation() const override;
62
64 void printBlockExecutionInformation() const override;
65
67 template <typename T>
68 void printVectorOrdering(std::vector<T *> uos, const std::string & name) const;
69
70private:
71 template <typename T>
72 void querySubdomain(Interfaces iface, std::vector<T> & results)
73 {
74 _query_subdomain.queryInto(results, _tid, _subdomain, iface);
75 }
76 template <typename T>
77 void queryBoundary(Interfaces iface, BoundaryID bnd, std::vector<T> & results)
78 {
79 _query_boundary.queryInto(results, _tid, std::make_tuple(bnd, false), iface);
80 }
81
83 {
84 std::deque<MaterialBase *> face_materials;
85 std::deque<MaterialBase *> boundary_materials;
86 };
87
89 {
90 std::deque<MaterialBase *> face_materials;
91 std::deque<MaterialBase *> neighbor_materials;
92 };
93
95 {
96 std::deque<MaterialBase *> face_materials;
97 std::deque<MaterialBase *> boundary_materials;
98 std::deque<MaterialBase *> neighbor_materials;
99 };
100
103 SubdomainID subdomain_id);
104
107 getInternalSideMaterialReinitCache(SubdomainID subdomain_id, SubdomainID neighbor_subdomain_id);
111 SubdomainID subdomain_id,
112 SubdomainID neighbor_subdomain_id,
113 const std::vector<UserObject *> & interface_objs);
117 std::vector<InternalSideUserObject *> _internal_side_objs;
118 std::vector<InterfaceUserObject *> _interface_user_objects;
119 std::vector<ElementUserObject *> _element_objs;
120 std::vector<ShapeElementUserObject *> _shape_element_objs;
121 std::vector<DomainUserObject *> _domain_objs;
122 std::vector<DomainUserObject *> _all_domain_objs;
123
125
126 // Exact material sets required for each boundary/subdomain pair. This cache is valid only for
127 // this ComputeUserObjectsThread mesh traversal; a new ComputeUserObjectsThread, and therefore a
128 // new cache, is created for each computeUserObjectsInternal() execution.
129 std::map<std::pair<BoundaryID, SubdomainID>, BoundaryMaterialReinitCache>
131 std::map<std::pair<SubdomainID, SubdomainID>, InternalSideMaterialReinitCache>
133 std::map<std::tuple<BoundaryID, SubdomainID, SubdomainID>, InterfaceMaterialReinitCache>
135};
136
137// determine when we need to run user objects based on whether any initial conditions or aux
138// kernels depend on the user objects. If so we need to run them either before ics, before aux
139// kernels, or after aux kernels (if nothing depends on them). Mark/store this information as
140// attributes in the warehouse for later reference.
141template <typename T>
142void
144 AuxiliarySystem & aux,
145 const ExecFlagEnum & execute_flags,
146 const std::vector<T *> & objs,
147 const std::set<std::string> & ic_deps)
148{
149 // These flags indicate when a user object will be executed for a given exec flag time.
150 // The attributes are set by this function and their values are queried in
151 // FEProblemBase::computeUserObjectsInternal(). If a UO is found to be in one of the
152 // three groups: PRE_IC, PRE_AUX, or POST_AUX, then that UO is executed with that group.
153 //
154 // PRE_IC objects are run before initial conditions during the "INITIAL" exec flag time.
155 // On any other exec flag time, they are run in POST_AUX by default or if there is
156 // an dependency for some exec flag or if force_preaux is set, they are run in
157 // PRE_AUX
158 //
159 // PRE_AUX objects are run before the dependent AuxKernels exec flag
160 //
161 // POST_AUX objects are run after AuxKernels on any given exec flag time, and is the
162 // default group for UOs. Dependencies that would otherwise move a UO into the
163 // PRE_AUX group can be overridden by specifying the parameter force_postaux
164 //
165 // This function attempts to sort a UO based on any ICs or AuxKernels which depend on
166 // it. Alternatively, a user may select which group to execute their object with by
167 // controlling the force_preic, force_preaux and force_postaux input parameters.
168 //
169
170 std::map<T *, std::set<int>> pre_aux_dependencies;
171 std::map<T *, std::set<int>> post_aux_dependencies;
172 // This map is used to indicate, after all dependencies have
173 // been looked through, whether the UO has been flagged to
174 // execute on EXEC_INITIAL, either through a dependency or
175 // because force_preic was indicated. If neither of these
176 // are true, the UO needs to be run in POST_AUX for EXEC_INITIAL
177 std::map<T *, bool> is_pre_ic;
178
179 for (const auto obj : objs)
180 is_pre_ic[obj] = false;
181
182 for (const ExecFlagType & flag : execute_flags.items())
183 {
184 std::set<std::string> depend_objects_aux = aux.getDependObjects(flag);
185 for (const auto obj : objs)
186 {
187 if (depend_objects_aux.count(obj->name()) > 0)
188 {
189 pre_aux_dependencies[obj].insert(flag);
190 if (flag == EXEC_INITIAL)
191 is_pre_ic.at(obj) = true;
192 }
193 else if (flag != EXEC_INITIAL)
194 // default is for UO to be post_aux. If EXEC_INITIAL, check first if UO
195 // will be dependent on IC or have force_preic before deciding to put in
196 // post_aux
197 post_aux_dependencies[obj].insert(flag);
198 }
199 }
200
201 for (const auto obj : objs)
202 {
203 if (ic_deps.count(obj->name()) > 0 ||
204 (obj->isParamValid("force_preic") && obj->template getParam<bool>("force_preic")))
205 {
206 w.update(obj, AttribPreIC(w, true));
207 is_pre_ic.at(obj) = true;
208 }
209
210 if ((obj->isParamValid("force_preaux") && obj->template getParam<bool>("force_preaux")))
211 {
212 post_aux_dependencies[obj].clear();
213 for (const ExecFlagType & flag : execute_flags.items())
214 pre_aux_dependencies[obj].insert(flag);
215 }
216 else if (obj->isParamValid("force_postaux") && obj->template getParam<bool>("force_postaux"))
217 {
218 pre_aux_dependencies[obj].clear();
219 for (const ExecFlagType & flag : execute_flags.items())
220 post_aux_dependencies[obj].insert(flag);
221 }
222 else
223 {
224 // If at this point, then check if the UO has already been set to execute
225 // by either the force_preic param, an IC dependency, or a dependency
226 // already found for exec flage EXEC_INITIAL. If none of these are true,
227 // then is_pre_ic.at(obj) is false and the UO is added to the default
228 // post_aux group for the EXEC_INITIAL flag
229 if (!is_pre_ic.at(obj))
230 post_aux_dependencies[obj].insert(EXEC_INITIAL);
231 }
232 }
233
234 for (auto & item : pre_aux_dependencies)
235 w.update(item.first, AttribPreAux(w, item.second));
236
237 for (auto & item : post_aux_dependencies)
238 w.update(item.first, AttribPostAux(w, item.second));
239}
Interfaces
Definition Attributes.h:21
boundary_id_type BoundaryID
subdomain_id_type SubdomainID
void groupUserObjects(TheWarehouse &w, AuxiliarySystem &aux, const ExecFlagEnum &execute_flags, const std::vector< T * > &objs, const std::set< std::string > &ic_deps)
const ExecFlagType EXEC_INITIAL
Definition Moose.C:31
TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies.
Definition Attributes.h:346
TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies.
Definition Attributes.h:315
TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies.
Definition Attributes.h:296
A system that holds auxiliary variables.
std::set< std::string > getDependObjects(ExecFlagType type)
Get a list of dependent UserObjects for this exec type.
Class for threaded computation of UserObjects.
std::vector< DomainUserObject * > _all_domain_objs
std::vector< ElementUserObject * > _element_objs
const InterfaceMaterialReinitCache & getInterfaceMaterialReinitCache(BoundaryID bnd_id, SubdomainID subdomain_id, SubdomainID neighbor_subdomain_id, const std::vector< UserObject * > &interface_objs)
Return the face, boundary, and neighbor materials required while executing on this interface.
virtual void post() override
Called after the element range loop.
virtual void onInternalSide(const Elem *elem, unsigned int side) override
Called when doing internal edge assembling.
const TheWarehouse::Query _query
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
virtual void onInterface(const Elem *elem, unsigned int side, BoundaryID bnd_id) override
Called when doing interface assembling.
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id, const Elem *lower_d_elem=nullptr) override
Called when doing boundary assembling.
TheWarehouse::QueryCache< AttribThread, AttribBoundaries, AttribInterfaces > _query_boundary
void printBlockExecutionInformation() const override
Print information about the loop, mostly order of execution of particular objects.
std::vector< InterfaceUserObject * > _interface_user_objects
const InternalSideMaterialReinitCache & getInternalSideMaterialReinitCache(SubdomainID subdomain_id, SubdomainID neighbor_subdomain_id)
Return the face and neighbor materials required while executing on this internal side.
void queryBoundary(Interfaces iface, BoundaryID bnd, std::vector< T > &results)
void printGeneralExecutionInformation() const override
Print general information about the loop, like the ordering of class of objects.
void join(const ComputeUserObjectsThread &)
const BoundaryMaterialReinitCache & getBoundaryMaterialReinitCache(BoundaryID bnd_id, SubdomainID subdomain_id)
Return the exact face and boundary materials required while executing on this boundary.
void printVectorOrdering(std::vector< T * > uos, const std::string &name) const
Format output of vector of UOs.
std::map< std::pair< BoundaryID, SubdomainID >, BoundaryMaterialReinitCache > _boundary_material_reinit_cache
virtual void onExternalSide(const Elem *elem, unsigned int side) override
Called when iterating over external sides (no side neighbor)
std::vector< ShapeElementUserObject * > _shape_element_objs
std::map< std::pair< SubdomainID, SubdomainID >, InternalSideMaterialReinitCache > _internal_side_material_reinit_cache
TheWarehouse::QueryCache< AttribThread, AttribSubdomains, AttribInterfaces > _query_subdomain
void querySubdomain(Interfaces iface, std::vector< T > &results)
std::vector< DomainUserObject * > _domain_objs
std::map< std::tuple< BoundaryID, SubdomainID, SubdomainID >, InterfaceMaterialReinitCache > _interface_material_reinit_cache
virtual void subdomainChanged() override
Called every time the current subdomain changes (i.e.
std::vector< InternalSideUserObject * > _internal_side_objs
This user object allows related evaluations on elements, boundaries, internal sides,...
A MultiMooseEnum object to hold "execute_on" flags.
const std::set< ExecFlagType > & items() const
Reference the all the available items.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Base class for implementing interface user objects.
Base class for user objects executed on all element sides internal to one or more blocks,...
Class for containing MooseEnum item information.
ElementUserObject class in which the _phi and _grad_phi shape function data is available and correctl...
QueryCache is a convenient way to construct and pass around (possible partially constructed) warehous...
std::vector< T * > & queryInto(std::vector< T * > &results, Args &&... args)
queryInto executes the query and stores the results in the given vector.
TheWarehouse is a container for MooseObjects that allows querying/filtering over various customizeabl...
void update(MooseObject *obj)
update updates the metadata/attribute-info stored for the given object obj that must already exists i...
SubdomainID _subdomain
The subdomain for the current element.
Base class for assembly-like calculations.
query_obj query
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...