CoastalME (Coastal Modelling Environment)
Simulates the long-term behaviour of complex coastlines
Loading...
Searching...
No Matches
update_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 <cfloat>
25#include <iostream>
26using std::endl;
27
28#include "cme.h"
29#include "simulation.h"
30#include "raster_grid.h"
31#include "coast.h"
32
33//===============================================================================================================================
35//===============================================================================================================================
37{
38 // Go through all cells in the raster grid and calculate some this-timestep totals
39 m_dThisIterTopElevMax = -DBL_MAX;
40 m_dThisIterTopElevMin = DBL_MAX;
41 for (int nX = 0; nX < m_nXGridSize; nX++)
42 {
43 for (int nY = 0; nY < m_nYGridSize; nY++)
44 {
45 if (m_pRasterGrid->m_Cell[nX][nY].bIsCoastline())
47
48 if (m_pRasterGrid->m_Cell[nX][nY].bIsInContiguousSea())
49 {
50 // Is a sea cell
51 m_dThisIterTotSeaDepth += m_pRasterGrid->m_Cell[nX][nY].dGetSeaDepth();
52 }
53
54 double dTopElev = m_pRasterGrid->m_Cell[nX][nY].dGetOverallTopElev();
55
56 // Get highest and lowest elevations of the top surface of the DEM
57 if (dTopElev > m_dThisIterTopElevMax)
58 m_dThisIterTopElevMax = dTopElev;
59
60 if (dTopElev < m_dThisIterTopElevMin)
61 m_dThisIterTopElevMin = dTopElev;
62 }
63 }
64
65 // No sea cells?
67 // All land, assume this is an error
68 return RTN_ERR_NOSEACELLS;
69
70 // Now go through all cells again and sort out suspended sediment load
71 double dSuspPerSeaCell = m_dThisIterFineSedimentToSuspension / static_cast<double>(m_ulThisIterNumSeaCells);
72 for (int nX = 0; nX < m_nXGridSize; nX++)
73 {
74 for (int nY = 0; nY < m_nYGridSize; nY++)
75 {
76 if (m_pRasterGrid->m_Cell[nX][nY].bIsInContiguousSea())
77 m_pRasterGrid->m_Cell[nX][nY].AddSuspendedSediment(dSuspPerSeaCell);
78 }
79 }
80
81 // Go along each coastline and update the grid with landform attributes, ready for next timestep
82 for (int i = 0; i < static_cast<int>(m_VCoast.size()); i++)
83 {
84 for (int j = 0; j < m_VCoast[i].nGetCoastlineSize(); j++)
85 {
86 int nRet = nLandformToGrid(i, j);
87 if (nRet != RTN_OK)
88 return nRet;
89 }
90 }
91
92 return RTN_OK;
93}
94
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
vector< CRWCoast > m_VCoast
The coastline objects.
int m_nYGridSize
The size of the grid in the y direction.
Definition simulation.h:434
double m_dThisIterTopElevMin
This-iteration lowest elevation of DEM.
Definition simulation.h:919
unsigned long m_ulThisIterNumCoastCells
The number of grid cells which are marked as coast, for this iteration.
Definition simulation.h:568
double m_dThisIterTotSeaDepth
Total sea depth (m) for this iteration.
Definition simulation.h:781
int nUpdateGrid(void)
Update all cells in the raster raster grid and do some per-timestep accounting.
double m_dThisIterFineSedimentToSuspension
Total fine unconsolidated sediment in suspension for this iteration (depth in m)
Definition simulation.h:814
unsigned long m_ulThisIterNumSeaCells
The number of grid cells which are marked as sea, for this iteration.
Definition simulation.h:565
double m_dThisIterTopElevMax
This-iteration highest elevation of DEM.
Definition simulation.h:916
int nLandformToGrid(int const, int const)
At the end of each timestep, this routine stores the attributes from a single coastal landform object...
This file contains global definitions for CoastalME.
int const RTN_ERR_NOSEACELLS
Definition cme.h:608
int const RTN_OK
Definition cme.h:577
Contains CRWCoast definitions.
Contains CGeomRasterGrid definitions.
Contains CSimulation definitions.