https://mooseframework.inl.gov
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
14 #include "MooseVariableInterface.h"
15 #include "MooseVariableFE.h"
16 #include "ResidualObject.h"
17 
26 template <typename T>
28 {
29 public:
35 
40  MooseObjectWarehouse(bool threaded = true);
41 
48  virtual void
49  addObject(std::shared_ptr<T> object, THREAD_ID tid = 0, bool recurse = true) override;
50 
52 
55  virtual void initialSetup(THREAD_ID tid = 0) const;
56  virtual void timestepSetup(THREAD_ID tid = 0) const;
57  virtual void customSetup(const ExecFlagType & exec_type, THREAD_ID tid = 0) const;
58  virtual void subdomainSetup(THREAD_ID tid = 0) const;
59  virtual void subdomainSetup(SubdomainID id, THREAD_ID tid = 0) const;
60  virtual void jacobianSetup(THREAD_ID tid = 0) const;
61  virtual void residualSetup(THREAD_ID tid = 0) const;
63 
67  bool hasVariableObjects(unsigned int variable_id, THREAD_ID tid = 0) const;
68 
70 
73  bool hasActiveVariableBlockObjects(unsigned int variable_id,
74  SubdomainID block_id,
75  THREAD_ID tid = 0) const;
76  const std::vector<std::shared_ptr<T>> & getActiveVariableBlockObjects(unsigned int variable_id,
77  SubdomainID block_id,
78  THREAD_ID tid = 0) const;
80 
84  virtual void updateActive(THREAD_ID tid = 0) override;
85 
86 protected:
88  std::map<unsigned int, MooseObjectWarehouse<T>> _variable_objects;
89 };
90 
91 template <typename T>
93  : MooseObjectWarehouseBase<T>(threaded)
94 {
95 }
96 
97 template <typename T>
98 void
99 MooseObjectWarehouse<T>::addObject(std::shared_ptr<T> object,
100  THREAD_ID tid /*= 0*/,
101  bool recurse /* = true */)
102 {
103  MooseObjectWarehouseBase<T>::addObject(object, tid, recurse);
104 
105  if (recurse)
106  {
107  if (auto mvir = std::dynamic_pointer_cast<MooseVariableInterface<Real>>(object); mvir)
108  _variable_objects[mvir->mooseVariableBase()->number()].addObject(object, tid, false);
110  mviv)
111  _variable_objects[mviv->mooseVariableBase()->number()].addObject(object, tid, false);
113  mvie)
114  _variable_objects[mvie->mooseVariableBase()->number()].addObject(object, tid, false);
115  // Some objects, such as ScalarKernels, do not inherit from the MooseVariableInterface (which is
116  // for field variables). These objects *do* inherit from ResidualObject which has this more
117  // generic variable() API
118  else if (auto ro = std::dynamic_pointer_cast<ResidualObject>(object); ro)
119  _variable_objects[ro->variable().number()].addObject(object, tid, false);
120  }
121 }
122 
123 template <typename T>
124 bool
125 MooseObjectWarehouse<T>::hasVariableObjects(const unsigned int variable_id, THREAD_ID tid) const
126 {
127  auto iter = _variable_objects.find(variable_id);
128  return (iter != _variable_objects.end() && iter->second.hasObjects(tid));
129 }
130 
131 template <typename T>
132 bool
134  SubdomainID block_id,
135  THREAD_ID tid) const
136 {
137  auto iter = _variable_objects.find(variable_id);
138  return (iter != _variable_objects.end() && iter->second.hasActiveBlockObjects(block_id, tid));
139 }
140 
141 template <typename T>
142 const std::vector<std::shared_ptr<T>> &
144  SubdomainID block_id,
145  THREAD_ID tid) const
146 {
147  checkThreadID(tid);
148  const auto iter = _variable_objects.find(variable_id);
149  mooseAssert(iter != _variable_objects.end(),
150  "Unable to locate variable kernels for the given variable id: " << variable_id
151  << ".");
152  return iter->second.getActiveBlockObjects(block_id, tid);
153 }
154 
155 template <typename T>
156 void
158 {
159  checkThreadID(tid);
160  // Initial Setup should be called on all objects because they may become active later
161  for (const auto & object : _all_objects[tid])
162  object->initialSetup();
163 }
164 
165 template <typename T>
166 void
168 {
169  checkThreadID(tid);
170  for (const auto & object : _active_objects[tid])
171  object->timestepSetup();
172 }
173 
174 template <typename T>
175 void
176 MooseObjectWarehouse<T>::customSetup(const ExecFlagType & exec_type, THREAD_ID tid /* = 0*/) const
177 {
178  checkThreadID(tid);
179  for (const auto & object : _active_objects[tid])
180  object->customSetup(exec_type);
181 }
182 
183 template <typename T>
184 void
186 {
187  checkThreadID(tid);
188  if (hasActiveBlockObjects(id, tid))
189  {
190  const auto & objects = getActiveBlockObjects(id, tid);
191  for (const auto & object : objects)
192  object->subdomainSetup();
193  }
194 }
195 
196 template <typename T>
197 void
199 {
200  checkThreadID(tid);
201  for (const auto & object : _active_objects[tid])
202  object->subdomainSetup();
203 }
204 
205 template <typename T>
206 void
208 {
209  checkThreadID(tid);
210  for (const auto & object : _active_objects[tid])
211  object->jacobianSetup();
212 }
213 
214 template <typename T>
215 void
217 {
218  checkThreadID(tid);
219  for (const auto & object : _active_objects[tid])
220  object->residualSetup();
221 }
222 
223 template <typename T>
224 void
226 {
228 
229  for (auto & it : _variable_objects)
230  it.second.updateActive(tid);
231 }
virtual void residualSetup(THREAD_ID tid=0) const
const std::vector< std::shared_ptr< T > > & getActiveVariableBlockObjects(unsigned int variable_id, SubdomainID block_id, THREAD_ID tid=0) const
A storage container for MooseObjects that inherit from SetupInterface.
virtual void customSetup(const ExecFlagType &exec_type, THREAD_ID tid=0) const
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
std::map< unsigned int, MooseObjectWarehouse< T > > _variable_objects
Variable based storage.
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 timestepSetup(THREAD_ID tid=0) const
virtual void initialSetup(THREAD_ID tid=0) const
Convenience methods for calling object setup methods.
virtual void jacobianSetup(THREAD_ID tid=0) const
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
virtual void updateActive(THREAD_ID tid=0) override
Update the active status of Kernels.
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true)
Adds an object to the storage structure.
bool hasVariableObjects(unsigned int variable_id, THREAD_ID tid=0) const
Checks for whether this warehouse has objects for a given variable.
MooseObjectWarehouse(bool threaded=true)
Constructor.
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true) override
Adds an object to the storage structure.
A base storage container for MooseObjects.
virtual void subdomainSetup(THREAD_ID tid=0) const
virtual void updateActive(THREAD_ID tid=0)
Updates the active objects storage.
unsigned int THREAD_ID
Definition: MooseTypes.h:209