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