8#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
9#include <doctest/doctest.h>
15class MiniModelComponent {
17 enum class ProtectedArray {
22 enum class SharedArray {
26 static void registerSharedArray(SharedArray type, ModelArray* p)
28 sharedArrays[
static_cast<size_t>(type)] = p;
30 static void registerProtectedArray(ProtectedArray type, ModelArray* p)
32 protectedArrays[
static_cast<size_t>(type)] = p;
34 static const MARConstBackingStore& getProtectedArrays() {
return protectedArrays; }
35 static const MARBackingStore& getSharedArrays() {
return sharedArrays; }
37 static MARBackingStore sharedArrays;
38 static MARConstBackingStore protectedArrays;
41MARBackingStore MiniModelComponent::sharedArrays(
static_cast<size_t>(SharedArray::COUNT));
42MARConstBackingStore MiniModelComponent::protectedArrays(
static_cast<size_t>(ProtectedArray::COUNT));
44class IceThermo :
public MiniModelComponent {
47 : hice(MiniModelComponent::getSharedArrays())
51 void update(
int tStep)
53 hice[0] *= (1. + tStep) / tStep;
56 ModelArrayRef<SharedArray::H_ICE, MARBackingStore, RW> hice;
59class IceCalc :
public MiniModelComponent {
62 : hice0(MiniModelComponent::getProtectedArrays())
64 registerSharedArray(SharedArray::H_ICE, &hice);
70 void update(
int tStep)
75 void getData(
double& dataOut)
82 ModelArrayRef<ProtectedArray::H_ICE, MARConstBackingStore> hice0;
87TEST_SUITE_BEGIN(
"ModelArrayRefDebug");
88TEST_CASE(
"No registered array")
93 REQUIRE_THROWS_AS(iceThermo.update(1), std::invalid_argument);
96TEST_CASE(
"Correct access")
103 REQUIRE_NOTHROW(iceThermo.update(1));
static void setDimensions(Type, const MultiDim &)
Sets the number and size of the dimensions of a specified type of ModelArray.