https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MooseObjectWarehouse.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
15#include "MooseVariableFE.h"
16#include "ResidualObject.h"
17
26template <typename T>
28{
29public:
35
40
47 virtual void
48 addObject(std::shared_ptr<T> object, THREAD_ID tid = 0, bool recurse = true) override;
49
51
54 virtual void initialSetup(THREAD_ID tid = 0) const;
55 virtual void timestepSetup(THREAD_ID tid = 0) const;
56 virtual void customSetup(const ExecFlagType & exec_type, THREAD_ID tid = 0) const;
57 virtual void subdomainSetup(THREAD_ID tid = 0) const;
58 virtual void subdomainSetup(SubdomainID id, THREAD_ID tid = 0) const;
59 virtual void jacobianSetup(THREAD_ID tid = 0) const;
60 virtual void residualSetup(THREAD_ID tid = 0) const;
62
66 bool hasVariableObjects(unsigned int variable_id, THREAD_ID tid = 0) const;
67
69
72 bool hasActiveVariableBlockObjects(unsigned int variable_id,
73 SubdomainID block_id,
74 THREAD_ID tid = 0) const;
75 const std::vector<std::shared_ptr<T>> & getActiveVariableBlockObjects(unsigned int variable_id,
76 SubdomainID block_id,
77 THREAD_ID tid = 0) const;
79
83 virtual void updateActive(THREAD_ID tid = 0) override;
84
85protected:
87 std::map<unsigned int, MooseObjectWarehouse<T>> _variable_objects;
88};
89
90template <typename T>
91MooseObjectWarehouse<T>::MooseObjectWarehouse(THREAD_ID num_threads /*=libMesh::n_threads()*/)
92 : MooseObjectWarehouseBase<T>(num_threads)
93{
94}
95
96template <typename T>
97void
98MooseObjectWarehouse<T>::addObject(std::shared_ptr<T> object,
99 THREAD_ID tid /*= 0*/,
100 bool recurse /* = true */)
101{
102 MooseObjectWarehouseBase<T>::addObject(object, tid, recurse);
103
104 if (recurse)
105 {
106 if (auto mvir = std::dynamic_pointer_cast<MooseVariableInterface<Real>>(object); mvir)
107 _variable_objects[mvir->mooseVariableBase()->number()].addObject(object, tid, false);
108 else if (auto mviv = std::dynamic_pointer_cast<MooseVariableInterface<RealVectorValue>>(object);
109 mviv)
110 _variable_objects[mviv->mooseVariableBase()->number()].addObject(object, tid, false);
111 else if (auto mvie = std::dynamic_pointer_cast<MooseVariableInterface<RealEigenVector>>(object);
112 mvie)
113 _variable_objects[mvie->mooseVariableBase()->number()].addObject(object, tid, false);
114 // Some objects, such as ScalarKernels, do not inherit from the MooseVariableInterface (which is
115 // for field variables). These objects *do* inherit from ResidualObject which has this more
116 // generic variable() API
117 else if (auto ro = std::dynamic_pointer_cast<ResidualObject>(object); ro)
118 _variable_objects[ro->variable().number()].addObject(object, tid, false);
119 }
120}
121
122template <typename T>
123bool
124MooseObjectWarehouse<T>::hasVariableObjects(const unsigned int variable_id, THREAD_ID tid) const
125{
126 auto iter = _variable_objects.find(variable_id);
127 return (iter != _variable_objects.end() && iter->second.hasObjects(tid));
128}
129
130template <typename T>
131bool
133 SubdomainID block_id,
134 THREAD_ID tid) const
135{
136 auto iter = _variable_objects.find(variable_id);
137 return (iter != _variable_objects.end() && iter->second.hasActiveBlockObjects(block_id, tid));
138}
139
140template <typename T>
141const std::vector<std::shared_ptr<T>> &
143 SubdomainID block_id,
144 THREAD_ID tid) const
145{
146 checkThreadID(tid);
147 const auto iter = _variable_objects.find(variable_id);
148 mooseAssert(iter != _variable_objects.end(),
149 "Unable to locate variable kernels for the given variable id: " << variable_id
150 << ".");
151 return iter->second.getActiveBlockObjects(block_id, tid);
152}
153
154template <typename T>
155void
157{
158 checkThreadID(tid);
159 // Initial Setup should be called on all objects because they may become active later
160 for (const auto & object : _all_objects[tid])
161 object->initialSetup();
162}
163
164template <typename T>
165void
167{
168 checkThreadID(tid);
169 for (const auto & object : _active_objects[tid])
170 object->timestepSetup();
171}
172
173template <typename T>
174void
175MooseObjectWarehouse<T>::customSetup(const ExecFlagType & exec_type, THREAD_ID tid /* = 0*/) const
176{
177 checkThreadID(tid);
178 for (const auto & object : _active_objects[tid])
179 object->customSetup(exec_type);
180}
181
182template <typename T>
183void
185{
186 checkThreadID(tid);
187 if (hasActiveBlockObjects(id, tid))
188 {
189 const auto & objects = getActiveBlockObjects(id, tid);
190 for (const auto & object : objects)
191 object->subdomainSetup();
192 }
193}
194
195template <typename T>
196void
198{
199 checkThreadID(tid);
200 for (const auto & object : _active_objects[tid])
201 object->subdomainSetup();
202}
203
204template <typename T>
205void
207{
208 checkThreadID(tid);
209 for (const auto & object : _active_objects[tid])
210 object->jacobianSetup();
211}
212
213template <typename T>
214void
216{
217 checkThreadID(tid);
218 for (const auto & object : _active_objects[tid])
219 object->residualSetup();
220}
221
222template <typename T>
223void
225{
227
228 for (auto & it : _variable_objects)
229 it.second.updateActive(tid);
230}
subdomain_id_type SubdomainID
unsigned int THREAD_ID
Definition MooseTypes.h:237
Class for containing MooseEnum item information.
A base storage container for MooseObjects.
std::vector< std::vector< std::shared_ptr< T > > > _all_objects
Storage container for the ALL pointers (THREAD_ID on outer vector)
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
std::vector< std::vector< std::shared_ptr< T > > > _active_objects
All active objects (THREAD_ID on outer vector)
virtual void updateActive(THREAD_ID tid=0)
Updates the active objects storage.
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true)
Adds an object to the storage structure.
bool hasActiveBlockObjects(THREAD_ID tid=0) const
void checkThreadID(THREAD_ID tid) const
Calls assert on thread id.
A storage container for MooseObjects that inherit from SetupInterface.
virtual void timestepSetup(THREAD_ID tid=0) const
bool hasVariableObjects(unsigned int variable_id, THREAD_ID tid=0) const
Checks for whether this warehouse has objects for a given variable.
virtual void customSetup(const ExecFlagType &exec_type, THREAD_ID tid=0) const
virtual void subdomainSetup(THREAD_ID tid=0) const
bool hasActiveVariableBlockObjects(unsigned int variable_id, SubdomainID block_id, THREAD_ID tid=0) const
Methods for checking/getting variable kernels for a variable and SubdomainID.
virtual void subdomainSetup(SubdomainID id, THREAD_ID tid=0) const
virtual void initialSetup(THREAD_ID tid=0) const
Convenience methods for calling object setup methods.
virtual void residualSetup(THREAD_ID tid=0) const
std::map< unsigned int, MooseObjectWarehouse< T > > _variable_objects
Variable based storage.
const std::vector< std::shared_ptr< T > > & getActiveVariableBlockObjects(unsigned int variable_id, SubdomainID block_id, THREAD_ID tid=0) const
MooseObjectWarehouse(THREAD_ID num_threads=libMesh::n_threads())
Constructor.
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true) override
Adds an object to the storage structure.
virtual void updateActive(THREAD_ID tid=0) override
Update the active status of Kernels.
virtual void jacobianSetup(THREAD_ID tid=0) const
Interface for objects that need to get values of MooseVariables.
unsigned int n_threads()