www.mooseframework.org
MooseObjectWarehouse.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
25 template <typename T>
27 {
28 public:
34 
39  MooseObjectWarehouse(bool threaded = true);
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 
64 
67  bool hasActiveVariableBlockObjects(unsigned int variable_id,
68  SubdomainID block_id,
69  THREAD_ID tid = 0) const;
70  const std::vector<std::shared_ptr<T>> & getActiveVariableBlockObjects(unsigned int variable_id,
71  SubdomainID block_id,
72  THREAD_ID tid = 0) const;
74 
78  virtual void updateActive(THREAD_ID tid = 0) override;
79 
80 protected:
82  std::map<unsigned int, MooseObjectWarehouse<T>> _variable_objects;
83 };
84 
85 template <typename T>
87  : MooseObjectWarehouseBase<T>(threaded)
88 {
89 }
90 
91 template <typename T>
92 void
93 MooseObjectWarehouse<T>::addObject(std::shared_ptr<T> object,
94  THREAD_ID tid /*= 0*/,
95  bool recurse /* = true */)
96 {
97  MooseObjectWarehouseBase<T>::addObject(object, tid, recurse);
98 
99  if (recurse)
100  {
101  {
103 
104  if (mvi)
105  _variable_objects[mvi->mooseVariableBase()->number()].addObject(object, tid, false);
106  }
107 
108  {
110 
111  if (mvi)
112  _variable_objects[mvi->mooseVariableBase()->number()].addObject(object, tid, false);
113  }
114 
115  {
117 
118  if (mvi)
119  _variable_objects[mvi->mooseVariableBase()->number()].addObject(object, tid, false);
120  }
121  }
122 }
123 
124 template <typename T>
125 bool
127  SubdomainID block_id,
128  THREAD_ID tid) const
129 {
130  auto iter = _variable_objects.find(variable_id);
131  return (iter != _variable_objects.end() && iter->second.hasActiveBlockObjects(block_id, tid));
132 }
133 
134 template <typename T>
135 const std::vector<std::shared_ptr<T>> &
137  SubdomainID block_id,
138  THREAD_ID tid) const
139 {
140  checkThreadID(tid);
141  const auto iter = _variable_objects.find(variable_id);
142  mooseAssert(iter != _variable_objects.end(),
143  "Unable to locate variable kernels for the given variable id: " << variable_id
144  << ".");
145  return iter->second.getActiveBlockObjects(block_id, tid);
146 }
147 
148 template <typename T>
149 void
151 {
152  checkThreadID(tid);
153  // Initial Setup should be called on all objects because they may become active later
154  for (const auto & object : _all_objects[tid])
155  object->initialSetup();
156 }
157 
158 template <typename T>
159 void
161 {
162  checkThreadID(tid);
163  for (const auto & object : _active_objects[tid])
164  object->timestepSetup();
165 }
166 
167 template <typename T>
168 void
169 MooseObjectWarehouse<T>::customSetup(const ExecFlagType & exec_type, THREAD_ID tid /* = 0*/) const
170 {
171  checkThreadID(tid);
172  for (const auto & object : _active_objects[tid])
173  object->customSetup(exec_type);
174 }
175 
176 template <typename T>
177 void
179 {
180  checkThreadID(tid);
181  if (hasActiveBlockObjects(id, tid))
182  {
183  const auto & objects = getActiveBlockObjects(id, tid);
184  for (const auto & object : objects)
185  object->subdomainSetup();
186  }
187 }
188 
189 template <typename T>
190 void
192 {
193  checkThreadID(tid);
194  for (const auto & object : _active_objects[tid])
195  object->subdomainSetup();
196 }
197 
198 template <typename T>
199 void
201 {
202  checkThreadID(tid);
203  for (const auto & object : _active_objects[tid])
204  object->jacobianSetup();
205 }
206 
207 template <typename T>
208 void
210 {
211  checkThreadID(tid);
212  for (const auto & object : _active_objects[tid])
213  object->residualSetup();
214 }
215 
216 template <typename T>
217 void
219 {
221 
222  for (auto & it : _variable_objects)
223  it.second.updateActive(tid);
224 }
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
subdomain_id_type SubdomainID
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.
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:198