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
15 This file is part of CoastalME, the Coastal Modelling Environment.
16
17 CoastalME 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
19 This 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
21 You 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
26#ifdef _OPENMP
27#include <omp.h>
28#endif
29
30#include "cme.h"
31#include "simulation.h"
32#include "raster_grid.h"
33#include "coast.h"
34
35//===============================================================================================================================
37//===============================================================================================================================
39{
40 // Go through all cells in the raster grid and calculate some this-timestep totals
41 m_dThisIterTopElevMax = -DBL_MAX;
42 m_dThisIterTopElevMin = DBL_MAX;
43
44 // Initialize reduction variables to zero
47
48 // Use OpenMP parallel reduction for thread-safe accumulation and min/max calculations
49#ifdef _OPENMP
50#pragma omp parallel for collapse(2) \
51 reduction(+ : m_ulThisIterNumCoastCells, m_dThisIterTotSeaDepth) \
52 reduction(max : m_dThisIterTopElevMax) \
53 reduction(min : m_dThisIterTopElevMin)
54#endif
55
56 for (int nX = 0; nX < m_nXGridSize; nX++)
57 {
58 for (int nY = 0; nY < m_nYGridSize; nY++)
59 {
60 if (m_pRasterGrid->m_Cell[nX][nY].bIsCoastline())
62
63 if (m_pRasterGrid->m_Cell[nX][nY].bIsInContiguousSea())
64 {
65 // Is a sea cell
66 m_dThisIterTotSeaDepth += m_pRasterGrid->m_Cell[nX][nY].dGetSeaDepth();
67 }
68
69 double const dTopElev = m_pRasterGrid->m_Cell[nX][nY].dGetOverallTopElev();
70
71 // Get highest and lowest elevations of the top surface of the DEM
72 if (dTopElev > m_dThisIterTopElevMax)
73 m_dThisIterTopElevMax = dTopElev;
74
75 if (dTopElev < m_dThisIterTopElevMin)
76 m_dThisIterTopElevMin = dTopElev;
77 }
78 }
79
80 // No sea cells?
82 // All land, assume this is an error
83 return RTN_ERR_NOSEACELLS;
84
85 // Now go through all cells again and sort out suspended sediment load
86 double const dSuspPerSeaCell = m_dThisIterFineSedimentToSuspension / static_cast<double>(m_ulThisIterNumSeaCells);
87
88 // Parallelize the sediment distribution loop
89#ifdef _OPENMP
90#pragma omp parallel for collapse(2)
91#endif
92
93 for (int nX = 0; nX < m_nXGridSize; nX++)
94 {
95 for (int nY = 0; nY < m_nYGridSize; nY++)
96 {
97 if (m_pRasterGrid->m_Cell[nX][nY].bIsInContiguousSea())
98 m_pRasterGrid->m_Cell[nX][nY].AddSuspendedSediment(dSuspPerSeaCell);
99 }
100 }
101
102 // Go along each coastline and update the grid with landform attributes, ready for next timestep
103 for (int i = 0; i < static_cast<int>(m_VCoast.size()); i++)
104 {
105 for (int j = 0; j < m_VCoast[i].nGetCoastlineSize(); j++)
106 {
107 int const nRet = nLandformToGrid(i, j);
108
109 if (nRet != RTN_OK)
110 return nRet;
111 }
112 }
113
114 return RTN_OK;
115}
CGeomRasterGrid * m_pRasterGrid
Pointer to the raster grid object.
int m_nXGridSize
The size of the grid in the x direction.
Definition simulation.h:457
vector< CRWCoast > m_VCoast
The coastline objects.
int m_nYGridSize
The size of the grid in the y direction.
Definition simulation.h:460
double m_dThisIterTopElevMin
This-iteration lowest elevation of DEM.
Definition simulation.h:970
unsigned long m_ulThisIterNumCoastCells
The number of grid cells which are marked as coast, for this iteration.
Definition simulation.h:613
double m_dThisIterTotSeaDepth
Total sea depth (m) for this iteration.
Definition simulation.h:829
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:862
unsigned long m_ulThisIterNumSeaCells
The number of grid cells which are marked as sea, for this iteration.
Definition simulation.h:610
double m_dThisIterTopElevMax
This-iteration highest elevation of DEM.
Definition simulation.h:967
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:725
int const RTN_OK
Definition cme.h:694
Contains CRWCoast definitions.
Contains CGeomRasterGrid definitions.
Contains CSimulation definitions.