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// #include <iostream>
27// using std::endl;
28
29#ifdef _OPENMP
30#include <omp.h>
31#endif
32
33#include "cme.h"
34#include "simulation.h"
35#include "raster_grid.h"
36#include "coast.h"
37
38//===============================================================================================================================
40//===============================================================================================================================
42{
43 // Go through all cells in the raster grid and calculate some this-timestep totals
44 m_dThisIterTopElevMax = -DBL_MAX;
45 m_dThisIterTopElevMin = DBL_MAX;
46
47 // Initialize reduction variables to zero
50
51 // Use OpenMP parallel reduction for thread-safe accumulation and min/max calculations
52#ifdef _OPENMP
53#pragma omp parallel for collapse(2) \
54 reduction(+ : m_ulThisIterNumCoastCells, m_dThisIterTotSeaDepth) \
55 reduction(max : m_dThisIterTopElevMax) \
56 reduction(min : m_dThisIterTopElevMin)
57#endif
58
59 for (int nX = 0; nX < m_nXGridSize; nX++)
60 {
61 for (int nY = 0; nY < m_nYGridSize; nY++)
62 {
63 if (m_pRasterGrid->m_Cell[nX][nY].bIsCoastline())
65
66 if (m_pRasterGrid->m_Cell[nX][nY].bIsInContiguousSea())
67 {
68 // Is a sea cell
69 m_dThisIterTotSeaDepth += m_pRasterGrid->m_Cell[nX][nY].dGetSeaDepth();
70 }
71
72 double const dTopElev = m_pRasterGrid->m_Cell[nX][nY].dGetOverallTopElev();
73
74 // Get highest and lowest elevations of the top surface of the DEM
75 if (dTopElev > m_dThisIterTopElevMax)
76 m_dThisIterTopElevMax = dTopElev;
77
78 if (dTopElev < m_dThisIterTopElevMin)
79 m_dThisIterTopElevMin = dTopElev;
80 }
81 }
82
83 // No sea cells?
85 // All land, assume this is an error
86 return RTN_ERR_NOSEACELLS;
87
88 // Now go through all cells again and sort out suspended sediment load
89 double const dSuspPerSeaCell = m_dThisIterFineSedimentToSuspension / static_cast<double>(m_ulThisIterNumSeaCells);
90
91 // Parallelize the sediment distribution loop
92#ifdef _OPENMP
93#pragma omp parallel for collapse(2)
94#endif
95
96 for (int nX = 0; nX < m_nXGridSize; nX++)
97 {
98 for (int nY = 0; nY < m_nYGridSize; nY++)
99 {
100 if (m_pRasterGrid->m_Cell[nX][nY].bIsInContiguousSea())
101 m_pRasterGrid->m_Cell[nX][nY].AddSuspendedSediment(dSuspPerSeaCell);
102 }
103 }
104
105 // Go along each coastline and update the grid with landform attributes, ready for next timestep
106 for (int i = 0; i < static_cast<int>(m_VCoast.size()); i++)
107 {
108 for (int j = 0; j < m_VCoast[i].nGetCoastlineSize(); j++)
109 {
110 int const nRet = nLandformToGrid(i, j);
111
112 if (nRet != RTN_OK)
113 return nRet;
114 }
115 }
116
117 return RTN_OK;
118}
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:976
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:835
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:868
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:973
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:726
int const RTN_OK
Definition cme.h:695
Contains CRWCoast definitions.
Contains CGeomRasterGrid definitions.
Contains CSimulation definitions.