netxsimdg
Loading...
Searching...
No Matches
PrognosticData_test.cpp
Go to the documentation of this file.
1
9
10#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
11#include <doctest/doctest.h>
12
14
17#include "include/Module.hpp"
19#include "include/constants.hpp"
20
21#include <sstream>
22
23extern template class Module::Module<Nextsim::IOceanBoundary>;
24
25namespace Nextsim {
26
27TEST_SUITE_BEGIN("PrognosticData");
28TEST_CASE("PrognosticData call order test")
29{
30 ModelArray::setDimensions(ModelArray::Type::H, { 1, 1 });
31 ModelArray::setDimensions(ModelArray::Type::Z, { 1, 1, 1 });
32
33 std::stringstream config;
34 config << "[Modules]" << std::endl;
35 config << "Nextsim::IAtmosphereBoundary = Nextsim::ConfiguredAtmosphere" << std::endl;
36 config << std::endl;
37 config << "[ConfiguredAtmosphere]" << std::endl;
38 config << "t_air = 3" << std::endl;
39 config << "t_dew = 2" << std::endl;
40 config << "pmsl = 100000" << std::endl;
41 config << "sw_in = 50" << std::endl;
42 config << "lw_in = 330" << std::endl;
43 config << "snow = 0" << std::endl;
44 config << "rainfall = 0" << std::endl;
45 config << "wind_speed = 5" << std::endl;
46
47 std::unique_ptr<std::istream> pcstream(new std::stringstream(config.str()));
48 Configurator::addStream(std::move(pcstream));
49
50 ConfiguredModule::parseConfigurator();
51
52 class OceanData : public IOceanBoundary {
53 public:
54 OceanData()
55 : IOceanBoundary()
56 {
57 }
58 void setData(const ModelState::DataMap& state) override { IOceanBoundary::setData(state); }
59 void updateBefore(const TimestepTime& tst) override
60 {
61 UnescoFreezing uf;
62 sst = -1.;
63 sss = 32.;
64 mld = 10.25;
65 tf = uf(sss[0]);
66 cpml = Water::cp * Water::rho * mld[0];
67 u = 0;
68 v = 0;
69 }
70 void updateAfter(const TimestepTime& tst) override { }
71 } ocnBdy;
72 ocnBdy.setData(ModelState().data);
73
75 Module::newImpl<IOceanBoundary, OceanData>);
76
77 HField zeroData;
78 zeroData.resize();
79 zeroData[0] = 0.;
80 ZField zeroDataZ;
81 zeroDataZ.resize();
82 zeroDataZ[0] = 0.;
83
84 ModelState::DataMap initialData = {
85 { "cice", zeroData },
86 { "hice", zeroData },
87 { "hsnow", zeroData },
88 { "tice", zeroDataZ },
89 };
90
91 PrognosticData pData;
92 pData.configure();
93 pData.setData(initialData);
94 TimestepTime tst = { TimePoint("2000-01-01T00:00:00Z"), Duration("P0-0T0:10:0") };
95 pData.update(tst);
96
97 ModelArrayRef<ModelComponent::SharedArray::Q_OW, MARBackingStore> qow(
98 ModelComponent::getSharedArray());
99
100 double prec = 1e-5;
101 // Correct value
102 REQUIRE(qow[0] == doctest::Approx(-109.923).epsilon(prec));
103 // Value if pAtmBdy->update and pOcnBdy->updateBefore are switched in PrognosticData::update
104 REQUIRE(qow[0] != doctest::Approx(-92.1569).epsilon(prec));
105}
106TEST_SUITE_END();
107
108} /* namespace Nextsim */
const double epsilon
Thermal emissivity of smooth ice [0..1].
Definition constants.hpp:43
const double rho
Density of fresh water at 4˚C. [kg m⁻³].
const double cp
Specific heat capacity at constant pressure of water [J kg⁻¹ K⁻¹].