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 subdomainSetup(THREAD_ID tid = 0) const;
57  virtual void subdomainSetup(SubdomainID id, THREAD_ID tid = 0) const;
58  virtual void jacobianSetup(THREAD_ID tid = 0) const;
59  virtual void residualSetup(THREAD_ID tid = 0) const;
61 
63 
66  bool hasActiveVariableBlockObjects(unsigned int variable_id,
67  SubdomainID block_id,
68  THREAD_ID tid = 0) const;
69  const std::vector<std::shared_ptr<T>> & getActiveVariableBlockObjects(unsigned int variable_id,
70  SubdomainID block_id,
71  THREAD_ID tid = 0) const;
73 
77  virtual void updateActive(THREAD_ID tid = 0) override;
78 
79 protected:
81  std::map<unsigned int, MooseObjectWarehouse<T>> _variable_objects;
82 };
83 
84 template <typename T>
86  : MooseObjectWarehouseBase<T>(threaded)
87 {
88 }
89 
90 template <typename T>
91 void
92 MooseObjectWarehouse<T>::addObject(std::shared_ptr<T> object,
93  THREAD_ID tid /*= 0*/,
94  bool recurse /* = true */)
95 {
96  MooseObjectWarehouseBase<T>::addObject(object, tid, recurse);
97 
98  if (recurse)
99  {
100  {
102 
103  if (mvi)
104  _variable_objects[mvi->mooseVariable()->number()].addObject(object, tid, false);
105  }
106 
107  {
109 
110  if (mvi)
111  _variable_objects[mvi->mooseVariable()->number()].addObject(object, tid, false);
112  }
113  }
114 }
115 
116 template <typename T>
117 bool
119  SubdomainID block_id,
120  THREAD_ID tid) const
121 {
122  auto iter = _variable_objects.find(variable_id);
123  return (iter != _variable_objects.end() && iter->second.hasActiveBlockObjects(block_id, tid));
124 }
125 
126 template <typename T>
127 const std::vector<std::shared_ptr<T>> &
129  SubdomainID block_id,
130  THREAD_ID tid) const
131 {
132  checkThreadID(tid);
133  const auto iter = _variable_objects.find(variable_id);
134  mooseAssert(iter != _variable_objects.end(),
135  "Unable to locate variable kernels for the given variable id: " << variable_id
136  << ".");
137  return iter->second.getActiveBlockObjects(block_id, tid);
138 }
139 
140 template <typename T>
141 void
143 {
144  checkThreadID(tid);
145  // Initial Setup should be called on all objects because they may become active later
146  for (const auto & object : _all_objects[tid])
147  object->initialSetup();
148 }
149 
150 template <typename T>
151 void
153 {
154  checkThreadID(tid);
155  for (const auto & object : _active_objects[tid])
156  object->timestepSetup();
157 }
158 
159 template <typename T>
160 void
162 {
163  checkThreadID(tid);
164  if (hasActiveBlockObjects(id, tid))
165  {
166  const auto & objects = getActiveBlockObjects(id, tid);
167  for (const auto & object : objects)
168  object->subdomainSetup();
169  }
170 }
171 
172 template <typename T>
173 void
175 {
176  checkThreadID(tid);
177  for (const auto & object : _active_objects[tid])
178  object->subdomainSetup();
179 }
180 
181 template <typename T>
182 void
184 {
185  checkThreadID(tid);
186  for (const auto & object : _active_objects[tid])
187  object->jacobianSetup();
188 }
189 
190 template <typename T>
191 void
193 {
194  checkThreadID(tid);
195  for (const auto & object : _active_objects[tid])
196  object->residualSetup();
197 }
198 
199 template <typename T>
200 void
202 {
204 
205  for (auto & it : _variable_objects)
206  it.second.updateActive(tid);
207 }
208 
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.
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
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:161