8#ifndef MODELCOMPONENT_HPP
9#define MODELCOMPONENT_HPP
19#include <unordered_map>
20#include <unordered_set>
33 typedef Logged::level OutputLevel;
35 enum class ProtectedArray {
75#ifdef DEBUG_MODELARRAYREF
76 static const size_t SharedArrayOffset =
static_cast<size_t>(ProtectedArray::COUNT);
78 static const size_t SharedArrayOffset = 0;
80 enum class SharedArray {
82 H_ICE = SharedArrayOffset,
103 typedef std::function<void(
size_t,
const TimestepTime&)> IteratedFn;
116 virtual void setData(
const ModelState::DataMap& state) = 0;
151 virtual std::unordered_set<std::string>
hFields()
const {
return {}; }
153 virtual std::unordered_set<std::string>
uFields()
const {
return {}; }
155 virtual std::unordered_set<std::string>
vFields()
const {
return {}; }
157 virtual std::unordered_set<std::string>
zFields()
const {
return {}; }
159 static void setAllModuleData(
const ModelState& stateIn);
161 static void unregisterAllModules();
163 static void getAllFieldNames(std::unordered_set<std::string>& uF,
164 std::unordered_set<std::string>& vF, std::unordered_set<std::string>& zF);
194 void registerModule();
212 inline static void overElements(IteratedFn fn,
const TimestepTime& tst)
214 for (
size_t i = 0; i < nOcean; ++i) {
215 fn(oceanIndex[i], tst);
236 static ModelArray
mask(
const ModelArray& data);
244 static ModelArray* p_oceanMaskH;
247 static MARBackingStore sharedArrays;
248 static MARConstBackingStore protectedArrays;
249 static std::unordered_map<std::string, ModelComponent*> registeredModules;
251 static size_t nOcean;
252 static std::vector<size_t> oceanIndex;
A class that holds the array data for the model.
virtual std::unordered_set< std::string > vFields() const
Returns the names of all Type::V ModelArrays defined in this component.
virtual std::unordered_set< std::string > zFields() const
Returns the names of all Type::Z ModelArrays defined in this component.
static const ModelArray & oceanMask()
Returns the ocean mask.
virtual ModelState getStateRecursive(const OutputSpec &os) const
Returns the state of the ModelComponent and any ModelComponents it depends on.
virtual std::string getName() const =0
Returns the name of the component.
virtual void setData(const ModelState::DataMap &state)=0
Set the initial data of the component from the passed ModelState.
static void registerProtectedArray(ProtectedArray type, const ModelArray *addr)
virtual ModelState getState() const =0
Returns a ModelState from this component.
static const MARBackingStore & getSharedArray()
Returns a const reference to the store for SharedArray fields.
static const MARConstBackingStore & getProtectedArray()
Returns a const reference to the store for ProtectedArray fields.
static ModelArray mask(const ModelArray &data)
Returns a copy of the provided ModelArray, masked according to the land-ocean mask.
static void setOceanMask(const ModelArray &mask)
Sets the model-wide land-ocean mask (for HField arrays).
static void registerExternalProtectedArray(ProtectedArray type, ModelArray *addr)
Registers a ModelArray into a ProtectedArray slot from outside any ModelComponent object....
virtual std::unordered_set< std::string > uFields() const
Returns the names of all Type::U ModelArrays defined in this component.
static void registerSharedArray(SharedArray type, ModelArray *addr)
virtual std::unordered_set< std::string > hFields() const
Returns the names of all Type::H ModelArrays defined in this component.
static void registerExternalSharedArray(SharedArray type, ModelArray *addr)
Registers a ModelArray into a SharedArray slot from outside any ModelComponent object....
virtual ModelState getState(const OutputLevel &) const =0
Returns a ModelState from this component at a specified level.