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.try_emplace(mvir->mooseVariableBase()->number(), this->_num_threads)
108 .first->second.addObject(object, tid, false);
109 else if (auto mviv = std::dynamic_pointer_cast<MooseVariableInterface<RealVectorValue>>(object);
110 mviv)
111 _variable_objects.try_emplace(mviv->mooseVariableBase()->number(), this->_num_threads)
112 .first->second.addObject(object, tid, false);
113 else if (auto mvie = std::dynamic_pointer_cast<MooseVariableInterface<RealEigenVector>>(object);
114 mvie)
115 _variable_objects.try_emplace(mvie->mooseVariableBase()->number(), this->_num_threads)
116 .first->second.addObject(object, tid, false);
117 // Some objects, such as ScalarKernels, do not inherit from the MooseVariableInterface (which is
118 // for field variables). These objects *do* inherit from ResidualObject which has this more
119 // generic variable() API
120 else if (auto ro = std::dynamic_pointer_cast<ResidualObject>(object); ro)
121 for (const auto var : ro->variables())
122 _variable_objects.try_emplace(var->number(), this->_num_threads)
123 .first->second.addObject(object, tid, false);
124 }
125}
126
127template <typename T>
128bool
129MooseObjectWarehouse<T>::hasVariableObjects(const unsigned int variable_id, THREAD_ID tid) const
130{
131 auto iter = _variable_objects.find(variable_id);
132 return (iter != _variable_objects.end() && iter->second.hasObjects(tid));
133}
134
135template <typename T>
136bool
138 SubdomainID block_id,
139 THREAD_ID tid) const
140{
141 auto iter = _variable_objects.find(variable_id);
142 return (iter != _variable_objects.end() && iter->second.hasActiveBlockObjects(block_id, tid));
143}
144
145template <typename T>
146const std::vector<std::shared_ptr<T>> &
148 SubdomainID block_id,
149 THREAD_ID tid) const
150{
151 checkThreadID(tid);
152 const auto iter = _variable_objects.find(variable_id);
153 mooseAssert(iter != _variable_objects.end(),
154 "Unable to locate variable kernels for the given variable id: " << variable_id
155 << ".");
156 return iter->second.getActiveBlockObjects(block_id, tid);
157}
158
159template <typename T>
160void
162{
163 checkThreadID(tid);
164 // Initial Setup should be called on all objects because they may become active later
165 for (const auto & object : _all_objects[tid])
166 object->initialSetup();
167}
168
169template <typename T>
170void
172{
173 checkThreadID(tid);
174 for (const auto & object : _active_objects[tid])
175 object->timestepSetup();
176}
177
178template <typename T>
179void
180MooseObjectWarehouse<T>::customSetup(const ExecFlagType & exec_type, THREAD_ID tid /* = 0*/) const
181{
182 checkThreadID(tid);
183 for (const auto & object : _active_objects[tid])
184 object->customSetup(exec_type);
185}
186
187template <typename T>
188void
190{
191 checkThreadID(tid);
192 if (hasActiveBlockObjects(id, tid))
193 {
194 const auto & objects = getActiveBlockObjects(id, tid);
195 for (const auto & object : objects)
196 object->subdomainSetup();
197 }
198}
199
200template <typename T>
201void
203{
204 checkThreadID(tid);
205 for (const auto & object : _active_objects[tid])
206 object->subdomainSetup();
207}
208
209template <typename T>
210void
212{
213 checkThreadID(tid);
214 for (const auto & object : _active_objects[tid])
215 object->jacobianSetup();
216}
217
218template <typename T>
219void
221{
222 checkThreadID(tid);
223 for (const auto & object : _active_objects[tid])
224 object->residualSetup();
225}
226
227template <typename T>
228void
230{
232
233 for (auto & it : _variable_objects)
234 it.second.updateActive(tid);
235}
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()