8#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
9#include <doctest/doctest.h>
20 using std::runtime_error::runtime_error;
26 std::string
getName()
const override {
return "Module1"; }
27 void setData(
const ModelState::DataMap& st)
override
33 std::unordered_set<std::string>
uFields()
const override {
return {
"u1" }; }
34 std::unordered_set<std::string>
vFields()
const override {
return {
"v1",
"v2" }; }
35 std::unordered_set<std::string>
zFields()
const override {
return {
"z1",
"z2",
"z3" }; }
38TEST_CASE(
"Register a new module")
41 REQUIRE_THROWS_AS(ModelComponent::setAllModuleData(ModelState()), HappyExcept);
43 std::unordered_set<std::string> uu;
44 std::unordered_set<std::string> vv;
45 std::unordered_set<std::string> zz;
47 ModelComponent::getAllFieldNames(uu, vv, zz);
48 REQUIRE(uu.size() == 1);
49 REQUIRE(vv.size() == 2);
50 REQUIRE(zz.size() == 3);
52 ModelComponent::unregisterAllModules();
58 : hice(ModelArray::HField())
64 void setData(
const ModelState::DataMap& ms)
override { hice[0] = hiceData; }
65 std::string
getName()
const override {
return "SupplyAndWait"; }
74 const double hiceData = 1.2;
75 double data() {
return hice[0]; }
76 double refData() {
return cice_ref[0]; }
80 ModelArrayRef<ProtectedArray::C_ICE, MARConstBackingStore> cice_ref;
86 : cice(ModelArray::HField())
92 void setData(
const ModelState::DataMap& ms)
override { cice[0] = ciceData; }
93 std::string
getName()
const override {
return "SupplyAndWait"; }
102 const double ciceData = 0.6;
103 double data() {
return cice[0]; }
104 double refData() {
return hice_ref[0]; }
108 ModelArrayRef<ProtectedArray::H_ICE, MARConstBackingStore> hice_ref;
111TEST_SUITE_BEGIN(
"ModelComponent");
112TEST_CASE(
"Test array registration")
115 ModuleSupplyAndWait saw;
116 ModuleRequestAndSupply ras;
118 REQUIRE(ras.data() == saw.refData());
119 REQUIRE(saw.data() == ras.refData());
125 : qic(ModelArray::HField())
131 void setData(
const ModelState::DataMap& ms)
override { qic[0] = qicData; }
132 std::string
getName()
const override {
return "SemiShared"; }
141 const double qicData = 123;
142 double data() {
return qic[0]; }
143 double refData() {
return qio_ref[0]; }
147 ModelArrayRef<SharedArray::Q_IO, MARBackingStore, RO> qio_ref;
153 : qio(ModelArray::HField())
159 void setData(
const ModelState::DataMap& ms)
override { qio[0]; }
160 std::string
getName()
const override {
return "Shared"; }
169 const double qioData = 234;
170 const double qicData = 246;
171 double data() {
return qio[0]; }
172 double& refData() {
return qic_ref[0]; }
173 void setRefData() { qic_ref[0] = qicData; }
177 ModelArrayRef<SharedArray::Q_IC, MARBackingStore, RW> qic_ref;
180TEST_CASE(
"Shared and semi-protected arrays")
184 ModuleSemiShared semi;
187 REQUIRE(share.data() == semi.refData());
188 REQUIRE(semi.data() == share.refData());
190 share.refData() = share.qicData;
192 REQUIRE(semi.data() == share.qicData);
static void setDimensions(Type, const MultiDim &)
Sets the number and size of the dimensions of a specified type of ModelArray.
static void registerProtectedArray(ProtectedArray type, const ModelArray *addr)
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 void registerSharedArray(SharedArray type, ModelArray *addr)
ModelState getState(const OutputLevel &lvl) const override
Returns a ModelState from this component at a specified level.
std::unordered_set< std::string > zFields() const override
Returns the names of all Type::Z ModelArrays defined in this component.
ModelState getState() const override
Returns a ModelState from this component.
std::string getName() const override
Returns the name of the component.
std::unordered_set< std::string > vFields() const override
Returns the names of all Type::V ModelArrays defined in this component.
std::unordered_set< std::string > uFields() const override
Returns the names of all Type::U ModelArrays defined in this component.
void setData(const ModelState::DataMap &st) override
Set the initial data of the component from the passed ModelState.
void setData(const ModelState::DataMap &ms) override
Set the initial data of the component from the passed ModelState.
ModelState getState(const OutputLevel &lvl) const override
Returns a ModelState from this component at a specified level.
ModelState getState() const override
Returns a ModelState from this component.
std::string getName() const override
Returns the name of the component.
std::string getName() const override
Returns the name of the component.
ModelState getState() const override
Returns a ModelState from this component.
ModelState getState(const OutputLevel &lvl) const override
Returns a ModelState from this component at a specified level.
void setData(const ModelState::DataMap &ms) override
Set the initial data of the component from the passed ModelState.
void setData(const ModelState::DataMap &ms) override
Set the initial data of the component from the passed ModelState.
ModelState getState() const override
Returns a ModelState from this component.
std::string getName() const override
Returns the name of the component.
ModelState getState(const OutputLevel &lvl) const override
Returns a ModelState from this component at a specified level.
std::string getName() const override
Returns the name of the component.
void setData(const ModelState::DataMap &ms) override
Set the initial data of the component from the passed ModelState.
ModelState getState() const override
Returns a ModelState from this component.
ModelState getState(const OutputLevel &lvl) const override
Returns a ModelState from this component at a specified level.