netxsimdg
Loading...
Searching...
No Matches
ParametricGrid.hpp
Go to the documentation of this file.
1
8#ifndef PARAMETRICGRID_HPP
9#define PARAMETRICGRID_HPP
10
11#include "IStructure.hpp"
12
14
15#include <set>
16
17namespace Nextsim {
18
19class ParaGridIO;
20
22class ParametricGrid : public IStructure {
23public:
24 typedef ModelArray::MultiDim GridDimensions;
26 : pio(nullptr)
27 {
28 }
29 virtual ~ParametricGrid()
30 {
31 if (pio) {
32 delete pio;
33 }
34 }
35
36 // Read/write override functions
37 ModelState getModelState(const std::string& filePath) override
38 {
39 return pio ? pio->getModelState(filePath) : ModelState();
40 }
41
42 void dumpModelState(const ModelState& state, const ModelMetadata& metadata,
43 const std::string& filePath, bool isRestart = false) const override
44 {
45 if (pio) {
46 if (isRestart) {
47 pio->dumpModelState(state, metadata, filePath);
48 } else {
49 pio->writeDiagnosticTime(state, metadata, filePath);
50 }
51 }
52 }
53 const std::string& structureType() const override { return structureName; };
54
55 int nIceLayers() const override
56 {
57 return ModelArray::definedDimensions.at(ModelArray::Dimension::Z).length;
58 };
59
61 public:
63 : grid(grid)
64 {
65 }
66 virtual ~IParaGridIO() = default;
67
68 virtual ModelState getModelState(const std::string& filePath) = 0;
69 virtual void dumpModelState(
70 const ModelState& state, const ModelMetadata& metadata, const std::string& filePath)
71 = 0;
72 virtual ModelState readForcingTime(const std::set<std::string>& forcings,
73 const TimePoint& time, const std::string& filePath)
74 = 0;
75 virtual void writeDiagnosticTime(
76 const ModelState& state, const ModelMetadata& meta, const std::string& filePath)
77 = 0;
78
79 protected:
80 IParaGridIO() = delete;
81
82 private:
83 ParametricGrid& grid;
84 };
85
90 void setIO(IParaGridIO* p) { pio = p; }
91
92 const static std::string structureName;
93
94private:
95 IParaGridIO* pio;
96
97 friend ParaGridIO;
98};
99
100} /* namespace Nextsim */
101
102#endif /* PARAMETRICGRID_HPP */
Interface class for the model structure.
static std::map< Dimension, DimensionSpec > definedDimensions
The name and length of each dimension that is defined.
A class to hold the grid data for parameterised rectangular grids.
void dumpModelState(const ModelState &state, const ModelMetadata &metadata, const std::string &filePath, bool isRestart=false) const override
Dumps the data to a file path.
ModelState getModelState(const std::string &filePath) override
Dumps the data to a file path.
void setIO(IParaGridIO *p)
int nIceLayers() const override
The number of ice layers in this data structure.
const std::string & structureType() const override
Returns the structure name that this class will process.