CoastalME (Coastal Modelling Environment)
Simulates the long-term behaviour of complex coastlines
Loading...
Searching...
No Matches
init_grid.cpp
Go to the documentation of this file.
1
12
13/*==============================================================================================================================
14
15This file is part of CoastalME, the Coastal Modelling Environment.
16
17CoastalME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
18
19This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23==============================================================================================================================*/
24#include <assert.h>
25
26#include <string>
27using std::to_string;
28
29#include <iostream>
30using std::cerr;
31using std::endl;
32
33#include <gdal_priv.h>
34#include <gdal_alg.h>
35
36#include "cme.h"
37#include "line.h"
38#include "cell.h"
39#include "coast.h"
40#include "simulation.h"
41#include "raster_grid.h"
42
43//===============================================================================================================================
45//===============================================================================================================================
47{
48 // Clear all vector coastlines, profiles, and polygons
49 for (int i = 0; i < static_cast<int>(m_pVCoastPolygon.size()); i++)
50 delete m_pVCoastPolygon[i];
51
52 m_pVCoastPolygon.clear();
53 m_VCoast.clear();
54
55 // m_VFloodWaveSetup.clear();
58
59 // Do some every-timestep initialization
60 m_nXMinBoundingBox = INT_MAX;
61 m_nXMaxBoundingBox = INT_MIN;
62 m_nYMinBoundingBox = INT_MAX;
63 m_nYMaxBoundingBox = INT_MIN;
64
69
73
95 m_dThisIterLeftGridUnconsFine = // TODO 067 Suspended fine sediment never decreases i.e. no suspended fine sediment ever leaves the grid. Is this OK?
101
102 for (int n = 0; n < m_nLayers; n++)
103 {
104 m_bConsChangedThisIter[n] = false;
105 m_bUnconsChangedThisIter[n] = false;
106 }
107
108 // Re-calculate the depth of closure, in case deep water wave properties have changed
110
111 int nZeroThickness = 0;
112
121
122 // And go through all cells in the RasterGrid array
123 for (int nX = 0; nX < m_nXGridSize; nX++)
124 {
125 for (int nY = 0; nY < m_nYGridSize; nY++)
126 {
127 // Re-initialize values for this cell
128 m_pRasterGrid->m_Cell[nX][nY].InitCell();
129
130 if (m_ulIter == 1)
131 {
132 // For the first timestep only, check to see that all cells have some sediment on them
133 double dSedThickness = m_pRasterGrid->m_Cell[nX][nY].dGetTotAllSedThickness();
134 if (dSedThickness <= 0)
135 {
136 nZeroThickness++;
137
139 LogStream << m_ulIter << ": " << WARN << "total sediment thickness is " << dSedThickness << " at [" << nX << "][" << nY << "] = {" << dGridCentroidXToExtCRSX(nX) << ", " << dGridCentroidYToExtCRSY(nY) << "}" << endl;
140 }
141
142 // For the first timestep only, calculate the elevation of all this cell's layers. During the rest of the simulation, each cell's elevation is re-calculated just after any change occurs on that cell
143 m_pRasterGrid->m_Cell[nX][nY].CalcAllLayerElevsAndD50();
144 }
145
146 // Note that these totals include sediment which is both within and outside the polygons (because we have not yet defined polygons for this iteration, duh!)
147 m_dStartIterConsFineAllCells += m_pRasterGrid->m_Cell[nX][nY].dGetTotConsFineThickConsiderNotch();
148 m_dStartIterConsSandAllCells += m_pRasterGrid->m_Cell[nX][nY].dGetTotConsSandThickConsiderNotch();
149 m_dStartIterConsCoarseAllCells += m_pRasterGrid->m_Cell[nX][nY].dGetTotConsCoarseThickConsiderNotch();
150
151 m_dStartIterSuspFineAllCells += m_pRasterGrid->m_Cell[nX][nY].dGetSuspendedSediment();
152 m_dStartIterUnconsFineAllCells += m_pRasterGrid->m_Cell[nX][nY].dGetTotUnconsFine();
153 m_dStartIterUnconsSandAllCells += m_pRasterGrid->m_Cell[nX][nY].dGetTotUnconsSand();
154 m_dStartIterUnconsCoarseAllCells += m_pRasterGrid->m_Cell[nX][nY].dGetTotUnconsCoarse();
155
157 {
158 // If we have just a single measurement for deep water waves (either given by the user, or from a single wave station) then set all cells, even dry land cells, to the same value for deep water wave height, deep water wave orientation, and deep water period
159 m_pRasterGrid->m_Cell[nX][nY].SetCellDeepWaterWaveHeight(m_dAllCellsDeepWaterWaveHeight);
160 m_pRasterGrid->m_Cell[nX][nY].SetCellDeepWaterWaveAngle(m_dAllCellsDeepWaterWaveAngle);
161 m_pRasterGrid->m_Cell[nX][nY].SetCellDeepWaterWavePeriod(m_dAllCellsDeepWaterWavePeriod);
162 }
163 }
164 }
165
167 {
168 // Each cell's value for deep water wave height and deep water wave orientation is interpolated from multiple user-supplied values
170 if (nRet != RTN_OK)
171 return nRet;
172
173 /*for (int n = 0; n < m_VlDeepWaterWaveValuesAtTimestep.size(); n++)
174 {
175 if (m_ulIter == m_VlDeepWaterWaveValuesAtTimestep[n])
176 {
177 // OK, this timestep we are doing the calculation
178 if (m_VlDeepWaterWaveValuesAtTimestep[n] > 1)
179 {
180 // TODO 036 For every timestep after the first, read in new values before doing the interpolation
181 }
182
183 // Interpolate values each cell's values for deep water height and orientation from user-supplied values
184 int nRet = nInterpolateAllDeepWaterWaveValues();
185 if (nRet != RTN_OK)
186 return nRet;
187 }
188 }*/
189 }
190
191 if (nZeroThickness > 0)
192 {
193 cerr << m_ulIter << ": " << WARN << nZeroThickness << " cells have no sediment, is this correct?" << endl;
194 LogStream << m_ulIter << ": " << WARN << nZeroThickness << " cells have no sediment, is this correct?" << endl;
195 }
196
197 // // DEBUG CODE ===========================================================================================================
198 // string strOutFile = m_strOutPath;
199 // strOutFile += "init_deep_water_wave_height_";
200 // strOutFile += to_string(m_ulIter);
201 // strOutFile += ".tif";
202 // GDALDriver* pDriver = GetGDALDriverManager()->GetDriverByName("gtiff");
203 // GDALDataset* pDataSet = pDriver->Create(strOutFile.c_str(), m_nXGridSize, m_nYGridSize, 1, GDT_Float64, m_papszGDALRasterOptions);
204 // pDataSet->SetProjection(m_strGDALBasementDEMProjection.c_str());
205 // pDataSet->SetGeoTransform(m_dGeoTransform);
206 // double* pdRaster = new double[m_ulNumCells];
207 // int nn = 0;
208 // for (int nY = 0; nY < m_nYGridSize; nY++)
209 // {
210 // for (int nX = 0; nX < m_nXGridSize; nX++)
211 // {
212 // // Write this value to the array
213 // pdRaster[nn] = m_pRasterGrid->m_Cell[nX][nY].dGetCellDeepWaterWaveHeight();
214 // nn++;
215 // }
216 // }
217 //
218 // GDALRasterBand* pBand = pDataSet->GetRasterBand(1);
219 // pBand->SetNoDataValue(m_nMissingValue);
220 // int nRet = pBand->RasterIO(GF_Write, 0, 0, m_nXGridSize, m_nYGridSize, pdRaster, m_nXGridSize, m_nYGridSize, GDT_Float64, 0, 0, NULL);
221 //
222 // if (nRet == CE_Failure)
223 // return RTN_ERR_GRIDCREATE;
224 //
225 // GDALClose(pDataSet);
226 // // DEBUG CODE ===========================================================================================================
227
228 // // DEBUG CODE ===========================================================================================================
229 // strOutFile = m_strOutPath;
230 // strOutFile += "init_deep_water_wave_angle_";
231 // strOutFile += to_string(m_ulIter);
232 // strOutFile += ".tif";
233 // pDataSet = pDriver->Create(strOutFile.c_str(), m_nXGridSize, m_nYGridSize, 1, GDT_Float64, m_papszGDALRasterOptions);
234 // pDataSet->SetProjection(m_strGDALBasementDEMProjection.c_str());
235 // pDataSet->SetGeoTransform(m_dGeoTransform);
236 // nn = 0;
237 // for (int nY = 0; nY < m_nYGridSize; nY++)
238 // {
239 // for (int nX = 0; nX < m_nXGridSize; nX++)
240 // {
241 // // Write this value to the array
242 // pdRaster[nn] = m_pRasterGrid->m_Cell[nX][nY].dGetCellDeepWaterWaveAngle();
243 // nn++;
244 // }
245 // }
246 //
247 // pBand = pDataSet->GetRasterBand(1);
248 // pBand->SetNoDataValue(m_nMissingValue);
249 // nRet = pBand->RasterIO(GF_Write, 0, 0, m_nXGridSize, m_nYGridSize, pdRaster, m_nXGridSize, m_nYGridSize, GDT_Float64, 0, 0, NULL);
250 //
251 // if (nRet == CE_Failure)
252 // return RTN_ERR_GRIDCREATE;
253 //
254 // GDALClose(pDataSet);
255 // // DEBUG CODE ===========================================================================================================
256
257 // // DEBUG CODE ===========================================================================================================
258 // strOutFile = m_strOutPath;
259 // strOutFile += "init_water_wave_angle_";
260 // strOutFile += to_string(m_ulIter);
261 // strOutFile += ".tif";
262 // pDataSet = pDriver->Create(strOutFile.c_str(), m_nXGridSize, m_nYGridSize, 1, GDT_Float64, m_papszGDALRasterOptions);
263 // pDataSet->SetProjection(m_strGDALBasementDEMProjection.c_str());
264 // pDataSet->SetGeoTransform(m_dGeoTransform);
265 // nn = 0;
266 // for (int nY = 0; nY < m_nYGridSize; nY++)
267 // {
268 // for (int nX = 0; nX < m_nXGridSize; nX++)
269 // {
270 // // Write this value to the array
271 // pdRaster[nn] = m_pRasterGrid->m_Cell[nX][nY].dGetWaveAngle();
272 // nn++;
273 // }
274 // }
275 //
276 // pBand = pDataSet->GetRasterBand(1);
277 // pBand->SetNoDataValue(m_nMissingValue);
278 // nRet = pBand->RasterIO(GF_Write, 0, 0, m_nXGridSize, m_nYGridSize, pdRaster, m_nXGridSize, m_nYGridSize, GDT_Float64, 0, 0, NULL);
279 //
280 // if (nRet == CE_Failure)
281 // return RTN_ERR_GRIDCREATE;
282 //
283 // GDALClose(pDataSet);
284 // // DEBUG CODE ===========================================================================================================
285
286 // // DEBUG CODE ===========================================================================================================
287 // strOutFile = m_strOutPath;
288 // strOutFile += "init_water_wave_height_";
289 // strOutFile += to_string(m_ulIter);
290 // strOutFile += ".tif";
291 // pDataSet = pDriver->Create(strOutFile.c_str(), m_nXGridSize, m_nYGridSize, 1, GDT_Float64, m_papszGDALRasterOptions);
292 // pDataSet->SetProjection(m_strGDALBasementDEMProjection.c_str());
293 // pDataSet->SetGeoTransform(m_dGeoTransform);
294 // nn = 0;
295 // for (int nY = 0; nY < m_nYGridSize; nY++)
296 // {
297 // for (int nX = 0; nX < m_nXGridSize; nX++)
298 // {
299 // // Write this value to the array
300 // pdRaster[nn] = m_pRasterGrid->m_Cell[nX][nY].dGetWaveHeight();
301 // nn++;
302 // }
303 // }
304 //
305 // pBand = pDataSet->GetRasterBand(1);
306 // pBand->SetNoDataValue(m_nMissingValue);
307 // nRet = pBand->RasterIO(GF_Write, 0, 0, m_nXGridSize, m_nYGridSize, pdRaster, m_nXGridSize, m_nYGridSize, GDT_Float64, 0, 0, NULL);
308 //
309 // if (nRet == CE_Failure)
310 // return RTN_ERR_GRIDCREATE;
311 //
312 // GDALClose(pDataSet);
313 // delete[] pdRaster;
314 // // DEBUG CODE ===========================================================================================================
315
316 return RTN_OK;
317}
Contains CGeomCell definitions.
double m_dThisIterPotentialBeachErosion
Total potential beach erosion (all size classes of unconsolidated sediment) for this iteration (depth...
Definition simulation.h:796
void CalcDepthOfClosure(void)
Calculate the depth of closure.
Definition utils.cpp:2437
int m_nLogFileDetail
The level of detail in the log file output. Can be LOG_FILE_LOW_DETAIL, LOG_FILE_MIDDLE_DETAIL,...
Definition simulation.h:530
double m_dAllCellsDeepWaterWaveHeight
Deep water wave height (m) for all sea cells.
Definition simulation.h:709
int m_nYMinBoundingBox
The minimum y value of the bounding box.
Definition simulation.h:500
CGeomRasterGrid * m_pRasterGrid
Pointer to the raster grid object.
int m_nXGridSize
The size of the grid in the x direction.
Definition simulation.h:431
ofstream LogStream
double m_dThisIterBeachErosionCoarse
Total actual beach erosion (coarse unconsolidated sediment) for this iteration (depth in m)
Definition simulation.h:805
vector< CRWCoast > m_VFloodWaveSetupSurgeRunup
TODO 007 Info needed.
double m_dStartIterUnconsCoarseAllCells
Depth (m) of coarse unconsolidated sediment at the start of the simulation, all cells (both inside an...
Definition simulation.h:943
vector< CRWCoast > m_VCoast
The coastline objects.
bool m_bSingleDeepWaterWaveValues
Do we have just a point source for (i.e. only a single measurement of) deep water wave values.
Definition simulation.h:362
double m_dThisIterActualPlatformErosionCoarseCons
Total actual platform erosion (coarse consolidated sediment) for this iteration (depth in m)
Definition simulation.h:793
int m_nYGridSize
The size of the grid in the y direction.
Definition simulation.h:434
double m_dStartIterSuspFineInPolygons
Depth (m) of fine suspended sediment at the start of the simulation (only cells in polygons)
Definition simulation.h:934
unsigned long m_ulThisIterNumCoastCells
The number of grid cells which are marked as coast, for this iteration.
Definition simulation.h:568
double m_dThisIterCliffCollapseErosionCoarseUncons
This-iteration total of coarse unconsolidated sediment produced by cliff collapse (m^3)
Definition simulation.h:886
vector< CRWCoast > m_VFloodWaveSetupSurge
TODO 007 Info needed.
unsigned long m_ulThisIterNumActualPlatformErosionCells
The number of grid cells on which actual platform erosion occurs, for this iteration.
Definition simulation.h:574
int m_nXMaxBoundingBox
The maximum x value of the bounding box.
Definition simulation.h:497
double m_dThisIterCliffCollapseErosionFineUncons
This-iteration total of fine unconsolidated sediment produced by cliff collapse (m^3)
Definition simulation.h:880
int m_nLayers
The number of sediment layers.
Definition simulation.h:437
double m_dStartIterConsCoarseAllCells
Depth (m) of coarse consolidated sediment at the start of the simulation, all cells (both inside and ...
Definition simulation.h:952
double m_dStartIterConsSandAllCells
Depth (m) of sand consolidated sediment at the start of the simulation, all cells (both inside and ou...
Definition simulation.h:949
unsigned long m_ulThisIterNumBeachDepositionCells
The number of grid cells on which beach (unconsolidated sediment) deposition occurs,...
Definition simulation.h:583
double m_dThisiterUnconsCoarseInput
Depth (m) of coarse unconsolidated sediment added, at this iteration.
Definition simulation.h:928
double m_dThisIterPotentialPlatformErosion
Total potential platform erosion (all size classes of consolidated sediment) for this iteration (dept...
Definition simulation.h:784
double m_dThisiterUnconsFineInput
Depth (m) of fine unconsolidated sediment added, at this iteration.
Definition simulation.h:922
bool m_bHaveWaveStationData
Do we have wave station data?
Definition simulation.h:365
double m_dThisIterActualPlatformErosionSandCons
Total actual platform erosion (sand consolidated sediment) for this iteration (depth in m)
Definition simulation.h:790
double m_dThisIterBeachDepositionCoarse
Total beach deposition (coarse unconsolidated sediment) for this iteration (depth in m)
Definition simulation.h:811
double dGridCentroidYToExtCRSY(int const) const
Given the integer Y-axis ordinate of a cell in the raster grid CRS, returns the external CRS Y-axis o...
Definition gis_utils.cpp:71
double m_dAllCellsDeepWaterWaveAngle
Deep water wave angle for all sea cells.
Definition simulation.h:712
double m_dThisIterUnconsCoarseCliffDeposition
This-iteration total of coarse unconsolidated sediment deposited due to cliff collapse (m^3)
Definition simulation.h:901
double m_dThisIterTotSeaDepth
Total sea depth (m) for this iteration.
Definition simulation.h:781
double m_dThisIterUnconsSandCliffDeposition
This-iteration total of sand unconsolidated sediment deposited due to cliff collapse (m^3)
Definition simulation.h:898
int nInterpolateAllDeepWaterWaveValues(void)
If the user supplies multiple deep water wave height and angle values, this routine interplates these...
double m_dThisIterPotentialSedLostBeachErosion
Total unconsolidated sediment from beach erosion (all size classes) lost from the grid this iteration...
Definition simulation.h:817
double m_dStartIterConsFineAllCells
Depth (m) of fine consolidated sediment at the start of the simulation, all cells (both inside and ou...
Definition simulation.h:946
double m_dThisIterBeachErosionSand
Total actual beach erosion (sand unconsolidated sediment) for this iteration (depth in m)
Definition simulation.h:802
double m_dThisIterFineSedimentToSuspension
Total fine unconsolidated sediment in suspension for this iteration (depth in m)
Definition simulation.h:814
double m_dThisIterBeachErosionFine
Total actual beach erosion (fine unconsolidated sediment) for this iteration (depth in m)
Definition simulation.h:799
unsigned long m_ulThisIterNumActualBeachErosionCells
The number of grid cells on which actual beach (unconsolidated sediment) erosion occurs,...
Definition simulation.h:580
int m_nYMaxBoundingBox
The maximum y value of the bounding box.
Definition simulation.h:503
vector< bool > m_bUnconsChangedThisIter
One element per layer: has the consolidated sediment of this layer been changed during this iteration...
unsigned long m_ulThisIterNumPotentialPlatformErosionCells
The number of grid cells on which potential platform erosion occurs, for this iteration.
Definition simulation.h:571
double m_dStartIterUnconsSandAllCells
Depth (m) of sand unconsolidated sediment at the start of the simulation, all cells (both inside and ...
Definition simulation.h:940
double m_dThisIterCliffCollapseErosionFineCons
This-iteration total of fine consolidated sediment produced by cliff collapse (m^3)
Definition simulation.h:889
unsigned long m_ulThisIterNumSeaCells
The number of grid cells which are marked as sea, for this iteration.
Definition simulation.h:565
double m_dStartIterUnconsFineAllCells
Depth (m) of fine unconsolidated sediment at the start of the simulation, all cells (both inside and ...
Definition simulation.h:937
int m_nXMinBoundingBox
The minimum x value of the bounding box.
Definition simulation.h:494
unsigned long m_ulThisIterNumPotentialBeachErosionCells
The number of grid cells on which potential beach (unconsolidated sediment) erosion occurs,...
Definition simulation.h:577
double m_dThisIterCliffCollapseErosionSandCons
This-iteration total of sand consolidated sediment produced by cliff collapse (m^3)
Definition simulation.h:892
double m_dThisIterBeachDepositionSand
Total beach deposition (sand unconsolidated sediment) for this iteration (depth in m)
Definition simulation.h:808
double m_dThisIterLeftGridUnconsCoarse
Total coarse unconsolidated sediment lost from the grid this iteration (depth in m)
Definition simulation.h:826
double m_dThisIterCliffCollapseErosionSandUncons
This-iteration total of sand unconsolidated sediment produced by cliff collapse (m^3)
Definition simulation.h:883
unsigned long m_ulIter
The number of the current iteration (time step)
Definition simulation.h:553
double dGridCentroidXToExtCRSX(int const) const
Given the integer X-axis ordinate of a cell in the raster grid CRS, returns the external CRS X-axis o...
Definition gis_utils.cpp:62
double m_dThisiterUnconsSandInput
Depth (m) of sand unconsolidated sediment added, at this iteration.
Definition simulation.h:925
double m_dAllCellsDeepWaterWavePeriod
Deep water wave period for all sea cells.
Definition simulation.h:715
double m_dThisIterActualPlatformErosionFineCons
Total actual platform erosion (fine consolidated sediment) for this iteration (depth in m)
Definition simulation.h:787
double m_dThisIterCliffCollapseErosionCoarseCons
This-iteration total of coarse consolidated sediment produced by cliff collapse (m^3)
Definition simulation.h:895
double m_dThisIterLeftGridUnconsSand
Total sand unconsolidated sediment lost from the grid this iteration (depth in m)
Definition simulation.h:823
int nInitGridAndCalcStillWaterLevel(void)
At the beginning of each timestep: clear vector coasts, profiles, and polygons, initialize the raster...
Definition init_grid.cpp:46
double m_dStartIterSuspFineAllCells
Depth (m) of fine suspended sediment at the start of the simulation, all cells (both inside and outsi...
Definition simulation.h:931
vector< bool > m_bConsChangedThisIter
One element per layer: has the consolidated sediment of this layer been changed during this iteration...
vector< CGeomCoastPolygon * > m_pVCoastPolygon
Pointers to coast polygon objects, in down-coast sequence TODO 044 Will need to use global polygon ID...
double m_dThisIterLeftGridUnconsFine
Total fine unconsolidated sediment lost from the grid this iteration (depth in m)
Definition simulation.h:820
This file contains global definitions for CoastalME.
int const LOG_FILE_MIDDLE_DETAIL
Definition cme.h:377
string const WARN
Definition cme.h:776
int const RTN_OK
Definition cme.h:577
Contains CRWCoast definitions.
Contains CGeomLine definitions.
Contains CGeomRasterGrid definitions.
Contains CSimulation definitions.