netxsimdg
Loading...
Searching...
No Matches
RectangularGrid.hpp
Go to the documentation of this file.
1
8#ifndef RECTANGULARGRID_HPP
9#define RECTANGULARGRID_HPP
10
11#include "IStructure.hpp"
12
15
16namespace Nextsim {
17
18class RectGridIO;
19
21public:
23 int nx;
24 int ny;
25 int nz;
26 };
27
29 : pio(nullptr)
30 , nx(0)
31 , ny(0)
32 , nz(0)
33 {
34 }
35
36 RectangularGrid(const GridDimensions& dims)
37 : pio(nullptr)
38 {
39 setDimensions(dims);
40 }
41
42 virtual ~RectangularGrid()
43 {
44 if (pio) {
45 delete pio;
46 }
47 }
48
49 // Read/write override functions
50 ModelState getModelState(const std::string& filePath) override
51 {
52 return pio ? pio->getModelState(filePath) : ModelState();
53 }
54
56 const ModelState& state, const ModelMetadata& metadata, const std::string& filePath, bool isRestart = false) const override
57 {
58 if (pio)
59 pio->dumpModelState(state, metadata, filePath, isRestart);
60 }
61 const std::string& structureType() const override { return structureName; };
62
63 int nIceLayers() const override { return nz; };
64
65 void setDimensions(const GridDimensions& dims)
66 {
67 nx = dims.nx;
68 ny = dims.ny;
69 nz = dims.nz;
70 }
71
73 public:
75 : grid(&grid)
76 {
77 }
78 virtual ~IRectGridIO() = default;
79
80 virtual ModelState getModelState(const std::string& filePath) = 0;
81
88 virtual void dumpModelState(
89 const ModelState& state, const ModelMetadata& metadata, const std::string& filePath, bool isRestart) const = 0;
90
91 protected:
92 IRectGridIO() = default;
93
94 private:
95 RectangularGrid* grid;
96 };
97
99 void setIO(IRectGridIO* p) { pio = p; }
100
101 const static std::string structureName;
102
103private:
104 int nx;
105 int ny;
106 int nz; // Number of ice layers
107
108 const static std::string xDimName;
109 const static std::string yDimName;
110 const static std::string nIceLayersName;
111
112 IRectGridIO* pio;
113
114 friend RectGridIO;
115};
116
117} /* namespace Nextsim */
118
119#endif /* RECTANGULARGRID_HPP */
Interface class for the model structure.
virtual void dumpModelState(const ModelState &state, const ModelMetadata &metadata, const std::string &filePath, bool isRestart) const =0
Dumps the given ModelState to the given file path.
ModelState getModelState(const std::string &filePath) override
Dumps the data to a file path.
void setIO(IRectGridIO *p)
Sets the pointer to the class that will perform the IO. Should be an instance of DevGridIO.
const std::string & structureType() const override
Returns the structure name that this class will process.
void dumpModelState(const ModelState &state, const ModelMetadata &metadata, const std::string &filePath, bool isRestart=false) const override
Dumps the data to a file path.
int nIceLayers() const override
The number of ice layers in this data structure.