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