8#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
9#include <doctest/doctest.h>
19 enum class ProtectedArray {
24 enum class SharedArray {
28 static void registerSharedArray(SharedArray type,
ModelArray* p)
30 sharedArrays[
static_cast<size_t>(type)] = p;
32 static void registerProtectedArray(ProtectedArray type,
ModelArray* p)
34 protectedArrays[
static_cast<size_t>(type)] = p;
36 static const MARConstBackingStore& getProtectedArrays() {
return protectedArrays; }
37 static const MARBackingStore& getSharedArrays() {
return sharedArrays; }
39 static MARBackingStore sharedArrays;
40 static MARConstBackingStore protectedArrays;
43MARBackingStore MiniModelComponent::sharedArrays(
static_cast<size_t>(SharedArray::COUNT));
44MARConstBackingStore MiniModelComponent::protectedArrays(
static_cast<size_t>(ProtectedArray::COUNT));
50 registerProtectedArray(ProtectedArray::H_ICE, &hice);
51 registerProtectedArray(ProtectedArray::SW_IN, &swin);
58 void setData(
const std::vector<double>& values)
72 : hice(MiniModelComponent::getSharedArrays())
76 void update(
int tStep)
78 hice[0] *= (1. + tStep) / tStep;
87 : hice0(MiniModelComponent::getProtectedArrays())
89 registerSharedArray(SharedArray::H_ICE, &hice);
95 void update(
int tStep)
100 void getData(
double& dataOut)
112TEST_SUITE_BEGIN(
"ModelArrayRef");
113TEST_CASE(
"Accessing the data")
120 atmIn.setData({hice0, swin});
125 iceCalc.update(tStep);
128 iceCalc.getData(hicef);
129 double target = hice0 * (1. + tStep) / tStep;
130 REQUIRE(hicef == doctest::Approx(target).
epsilon(1e-8));
133enum class couplFields {
138static const double targetFlux = 320;
147 void update() { swFlux[0] = targetFlux; }
156 : coupledFields(
static_cast<size_t>(couplFields::COUNT))
157 , coupler(coupledFields)
159 registerProtectedArray(ProtectedArray::H_ICE, &hice);
160 registerProtectedArray(ProtectedArray::SW_IN, &swin);
162 coupledFields[
static_cast<size_t>(couplFields::SWIN)] = &swin;
178 const MARBackingStore& bs() {
return coupledFields; }
182 MARBackingStore coupledFields;
186TEST_CASE(
"Accessing the data two ways")
191 ModelArrayRef<couplFields::SWIN, MARBackingStore> swin(couplIn.bs());
194 REQUIRE(swin[0] != targetFlux);
196 REQUIRE(swin[0] == targetFlux);
A class that holds the array data for the model.
static void setDimensions(Type, const MultiDim &)
Sets the number and size of the dimensions of a specified type of ModelArray.
A class which provides indirect access to ModelArray.
const double epsilon
Thermal emissivity of smooth ice [0..1].