26using std::stable_sort;
37bool bPolygonAndAdjCompare(
const vector<int>& nVLeft,
const vector<int>& nVRight)
44 bool const bDownCoastLeft = nVLeft[1];
45 bool const bDownCoastRight = nVRight[1];
58 if ((nVLeft.size() >= 3) && (nVRight.size() >= 3))
61 bool bLHSOffEdge =
false;
63 for (
unsigned int n = 2; n < nVLeft.size(); n++)
77 bool bRHSOffEdge =
false;
79 for (
unsigned int n = 2; n < nVRight.size(); n++)
93 if (! bDownCoastRight)
98 bool bLeftFound =
false;
100 for (
unsigned int n = 2; n < nVLeft.size(); n++)
102 if (nVLeft[n] == nVRight[0])
111 bool bRightFound =
false;
113 for (
unsigned int n = 2; n < nVRight.size(); n++)
115 if (nVRight[n] == nVLeft[0])
125 if (nVLeft[0] < nVRight[0])
141 if ((nVLeft.size() >= 3) && (nVRight.size() >= 3))
144 bool bLHSOffEdge =
false;
146 for (
unsigned int n = 2; n < nVLeft.size(); n++)
160 bool bRHSOffEdge =
false;
162 for (
unsigned int n = 2; n < nVRight.size(); n++)
176 if (! bDownCoastRight)
181 bool bLeftFound =
false;
183 for (
unsigned int n = 2; n < nVLeft.size(); n++)
185 if (nVLeft[n] == nVRight[0])
194 bool bRightFound =
false;
196 for (
unsigned int n = 2; n < nVRight.size(); n++)
198 if (nVRight[n] == nVLeft[0])
208 if (nVLeft[0] < nVRight[0])
225 LogStream <<
m_ulIter <<
": Calculating unconsolidated sediment transport" << endl;
227 int const nCoastSize =
static_cast<int>(
m_VCoast.size());
229 for (
int nCoast = 0; nCoast < nCoastSize; nCoast++)
245 vector<int> nVPolyAndAdj;
248 vector<vector<int>> nVVCoastPolyAndAdjacent;
251 vector<vector<vector<int>>> nVVVAllCoastPolyAndAdjacent;
254 for (
int nCoast = 0; nCoast < nCoastSize; nCoast++)
259 nVVCoastPolyAndAdjacent.clear();
260 for (
int nn = 0; nn <
m_VCoast[nCoast].nGetNumPolygons(); nn++)
263 nVPolyAndAdj.clear();
271 nVPolyAndAdj.push_back(
true);
278 nVPolyAndAdj.push_back(nAdjPolyID);
284 nVPolyAndAdj.push_back(
false);
291 nVPolyAndAdj.push_back(nAdjPolyID);
295 nVVCoastPolyAndAdjacent.push_back(nVPolyAndAdj);
298 nVVVAllCoastPolyAndAdjacent.push_back(nVVCoastPolyAndAdjacent);
307 for (
int nCoast = 0; nCoast < nCoastSize; nCoast++)
310 stable_sort(nVVVAllCoastPolyAndAdjacent[nCoast].begin(), nVVVAllCoastPolyAndAdjacent[nCoast].end(), bPolygonAndAdjCompare);
313 vector<int> VnSourcePolygons;
315 for (
int n = 0; n < static_cast<int>(nVVVAllCoastPolyAndAdjacent[nCoast].size()); n++)
317 int const nThisPoly = nVVVAllCoastPolyAndAdjacent[nCoast][n][0];
318 VnSourcePolygons.push_back(nThisPoly);
320 for (
int m = 2; m < static_cast<int>(nVVVAllCoastPolyAndAdjacent[nCoast][n].size()); m++)
323 int const nToFind = nVVVAllCoastPolyAndAdjacent[nCoast][n][m];
326 if (it != VnSourcePolygons.end())
332 pPoly =
m_VCoast[nCoast].pGetPolygon(nToFind);
346 for (
int nCoast = 0; nCoast < nCoastSize; nCoast++)
349 int const nNumPolygons =
m_VCoast[nCoast].nGetNumPolygons();
351 for (
int nPoly = 0; nPoly < nNumPolygons; nPoly++)
353 int const nPolygon = nVVVAllCoastPolyAndAdjacent[nCoast][nPoly][0];
388 if (dCoarseDepositionTarget > 0)
401 LogStream <<
" dCoarseDepositionTarget now = " << dCoarseDepositionTarget << endl;
405 double dCoarseDeposited = 0;
411 double const dCoarseNotDeposited = dCoarseDepositionTarget - dCoarseDeposited;
413 if (dCoarseNotDeposited > 0)
422 if (dSandDepositionTarget > 0)
435 LogStream <<
" dSandDepositionTarget now = " << dSandDepositionTarget << endl;
439 double dSandDeposited = 0;
445 double const dSandNotDeposited = dSandDepositionTarget - dSandDeposited;
447 if (dSandNotDeposited > 0)
474 if (dPotentialErosion > 0)
479 if (dExistingUnconsFine > 0)
485 double const dFineErosionTarget =
tMin(dFinePotentialErosion, dExistingUnconsFine);
488 double dFineEroded = 0;
509 double dSandEroded = 0;
511 if (dExistingUnconsSand > 0)
517 double const dSandErosionTarget =
tMin(dSandPotentialErosion, dExistingUnconsSand);
555 double dCoarseEroded = 0;
557 if (dExistingUnconsCoarse > 0)
563 double const dCoarseErosionTarget =
tMin(dCoarsePotentialErosion, dExistingUnconsCoarse);
571 if (dCoarseEroded > 0)
582 if ((dSandEroded + dCoarseEroded) > 0)
589 for (
int nn = 0; nn < nNumAdjPoly; nn++)
603 LogStream <<
m_ulIter <<
": " <<
ERR <<
"in sediment export. Unconsolidated sediment movement is DOWN-COAST, and sediment is leaving the grid, but polygon " << nPolygon <<
" is at the up-coast end of the coastline. This will result in mass balance problems." << endl;
612 LogStream <<
m_ulIter <<
": when adjusting sediment export, polygon " << nPolygon <<
" is at the down-coast end of the coastline, and actual sediment movement is DOWN-COAST. Since grid edges are closed, no sand or coarse unconsolidated sediment goes off-grid so cannot adjust sediment export. This will result in mass balance problems." << endl;
623 int const nOtherEndPoly = 0;
632 if (dCoarseEroded > 0)
658 if (dCoarseEroded > 0)
680 for (
int nn = 0; nn < nNumAdjPoly; nn++)
693 LogStream <<
m_ulIter <<
": " <<
ERR <<
"in sediment export. Unconsolidated sediment movement is UP-COAST, and sediment is leaving the grid, but polygon " << nPolygon <<
" is at the down-coast end of the coastline. This will result in mass balance problems." << endl;
702 LogStream <<
m_ulIter <<
": when adjusting sediment export, polygon " << nPolygon <<
" is at the up-coast end of the coastline, and actual sediment movement is UP-COAST. Since grid edges are closed, no sand or coarse unconsolidated sediment goes off-grid so cannot adjust sediment export" << endl;
713 int const nOtherEndPoly = 0;
722 if (dCoarseEroded > 0)
748 if (dCoarseEroded > 0)
806 int const nPolygons =
m_VCoast[nCoast].nGetNumPolygons();
809 for (
int nn = nPolygons - 1; nn >= 0; nn--)
811 int const nThisPoly = nVVVAllCoastPolyAndAdjacent[nCoast][nn][0];
816 if (dSandToDepositOnPoly > 0)
819 double dSandDeposited = 0;
825 double const dSandNotDeposited = dSandToDepositOnPoly - dSandDeposited;
827 if (dSandNotDeposited > 0)
836 if (dCoarseToDepositOnPoly > 0)
839 double dCoarseDeposited = 0;
845 double const dCoarseNotDeposited = dCoarseToDepositOnPoly - dCoarseDeposited;
847 if (dCoarseNotDeposited > 0)
870 int const nNumPolygons =
m_VCoast[nCoast].nGetNumPolygons();
872 for (
int nPoly = 0; nPoly < nNumPolygons; nPoly++)
Geometry class used for coast polygon objects.
bool bIsCoastStartPolygon(void) const
Is this polygon the coast-start polygon?
double dGetSedimentInputUnconsSand(void) const
Get the value of sand sediment on the polygon derived from sediment input events(s)
double dGetPotentialErosion(void) const
Returns this timestep's total change in depth of unconsolidated sediment (all size classes) due to be...
double dGetCliffCollapseUnconsSandDeposition(void) const
Get the this-iteration total of unconsolidated sand sediment deposited from cliff collapse on this po...
bool bIsCoastEndPolygon(void) const
Is this polygon the coast-end polygon?
void SetPreExistingUnconsFine(double const)
Set the value of pre-existing unconsolidated fine sediment stored on this polygon.
double dGetPreExistingUnconsSand(void) const
Get the value of pre-existing unconsolidated sand sediment stored on this polygon.
void AddToDoBeachDepositionUnconsSand(double const)
Adds a depth (in m) of sand-sized unconsolidated sediment to this timestep's still-to-do deposition o...
void SetPreExistingUnconsSand(double const)
Set the value of pre-existing unconsolidated sand sediment stored on this polygon.
double dGetUpCoastAdjacentPolygonBoundaryShare(int const) const
Gets the boundary shares for all up-coast adjacent polygons.
int nGetUpCoastAdjacentPolygon(int const) const
Gets a single up-coast adjacent polygon.
double dGetPlatformErosionUnconsCoarse(void) const
Get the this-iteration total of unconsolidated coarse sediment derived from shore platform erosion on...
double dGetSedimentInputUnconsFine(void) const
Get the value of fine sediment on the polygon derived from sediment input events(s)
int nGetNumUpCoastAdjacentPolygons(void) const
Gets all up-coast adjacent polygons.
double dGetCliffCollapseUnconsCoarseDeposition(void) const
Get the this-iteration total of unconsolidated coarse sediment deposited from cliff collapse on this ...
double dGetDownCoastAdjacentPolygonBoundaryShare(int const) const
Gets the boundary shares for all down-coast adjacent polygons.
void SetBeachErosionUnconsFine(double const)
Sets a value (must be < 0) for this timestep's erosion of fine unconsolidated sediment (beach redistr...
double dGetPreExistingUnconsFine(void) const
Get the value of pre-existing unconsolidated fine sediment stored on this polygon.
int nGetPolygonCoastID(void) const
Get the coast ID, this is the same as the down-coast sequence of polygons.
void AddToDoBeachDepositionUnconsCoarse(double const)
Adds a depth (in m) of coarse unconsolidated sediment to this timestep's still-to-do deposition of un...
int nGetDownCoastAdjacentPolygon(int const) const
Gets a single down-coast adjacent polygon.
int nGetNumDownCoastAdjacentPolygons(void) const
Gets all down-coast adjacent polygons.
double dGetToDoBeachDepositionUnconsSand(void) const
Returns this timestep's still-to-do deposition of sand-sized unconsolidated sediment (from beach redi...
void SetPreExistingUnconsCoarse(double const)
Set the value of pre-existing unconsolidated coarse sediment stored on this polygon.
double dGetPlatformErosionUnconsSand(void) const
Get the this-iteration total of unconsolidated sand sediment derived from shore platform erosion on t...
double dGetPreExistingUnconsCoarse(void) const
Get the value of pre-existing unconsolidated coarse sediment stored on this polygon.
void SetBeachErosionUnconsSand(double const)
Sets a value (must be < 0) for this timestep's erosion of sand-sized unconsolidated sediment (beach r...
double dGetSedimentInputUnconsCoarse(void) const
Get the value of coarse sediment on the polygon derived from sediment input events(s)
bool bDownCoastThisIter(void) const
Is sediment movement on this polygon down-coast this iteration?
void AddCircularity(int const)
Add a circularity to this polygon.
void SetBeachErosionUnconsCoarse(double const)
Sets a value (must be < 0) for this timestep's erosion of coarse unconsolidated sediment (beach redis...
double dGetToDoBeachDepositionUnconsCoarse(void) const
Returns this timestep's still-to-do deposition of coarse unconsolidated sediment (from beach redistri...
int m_nLogFileDetail
The level of detail in the log file output. Can be LOG_FILE_LOW_DETAIL, LOG_FILE_MIDDLE_DETAIL,...
double m_dThisIterBeachErosionCoarse
Total actual beach erosion (coarse unconsolidated sediment) for this iteration (depth in m)
vector< CRWCoast > m_VCoast
The coastline objects.
double m_dFineErodibilityNormalized
Relative erodibility of fine unconsolidated beach sediment, normalized.
int m_nUnconsSedimentHandlingAtGridEdges
How sediment which moves off an edge of the grid is handled. Possible values are GRID_EDGE_CLOSED,...
double m_dCoarseErodibilityNormalized
Relative erodibility of coarse unconsolidated beach sediment, normalized.
double m_dDepositionCoarseDiff
Error term: if we are unable to deposit enough unconslidated coarse on polygon(s),...
int nDoAllActualBeachErosionAndDeposition(void)
Does between-polygon and within-polygon actual (supply-limited) redistribution of transported beach s...
double m_dDepositionSandDiff
Error term: if we are unable to deposit enough unconslidated sand on polygon(s), this is held over to...
void WritePolygonSortedSequence(vector< vector< vector< int > > > &)
Writes to the log file a table showing the sorted sequence of polygon processing for all coasts,...
void WritePolygonSedimentBeforeMovement(void)
Writes to the log file a table showing per-polygon totals of stored unconsolidated beach sediment pri...
int nDoUnconsDepositionOnPolygon(int const, CGeomCoastPolygon *, int const, double, double &)
Deposits unconsolidated beach sediment (sand or coarse) on the cells within a polygon....
double m_dSandErodibilityNormalized
Relative erodibility of sand unconsolidated beach sediment, normalized.
double m_dThisIterBeachErosionSand
Total actual beach erosion (sand unconsolidated sediment) for this iteration (depth in m)
double m_dThisIterFineSedimentToSuspension
Total fine unconsolidated sediment in suspension for this iteration (depth in m)
double m_dThisIterBeachErosionFine
Total actual beach erosion (fine unconsolidated sediment) for this iteration (depth in m)
void WritePolygonUnsortedSequence(vector< vector< vector< int > > > &)
Writes to the log file a table showing the unsorted sequence of polygon processing for all coasts.
void AllPolygonsUpdateStoredUncons(int const)
Before simulating beach erosion, update the per-polygon values of pre-existing unconsolidated sedimen...
int nDoUnconsErosionOnPolygon(int const, CGeomCoastPolygon *, int const, double const, double &)
Erodes unconsolidated beach sediment of one texture class on the cells within a polygon....
double m_dCellArea
Area of a cell (in external CRS units)
void WritePolygonPotentialErosion(void)
Writes to the log file a table showing per-polygon potential erosion of all size classes of unconsoli...
double m_dThisIterLeftGridUnconsCoarse
Total coarse unconsolidated sediment lost from the grid this iteration (depth in m)
unsigned long m_ulIter
The number of the current iteration (time step)
double m_dThisIterLeftGridUnconsSand
Total sand unconsolidated sediment lost from the grid this iteration (depth in m)
void WritePolygonActualMovement(vector< vector< vector< int > > > &)
Writes to the log file a table showing per-polygon actual movement of unconsolidated beach sediment f...
This file contains global definitions for CoastalME.
int const LOG_FILE_MIDDLE_DETAIL
int const GRID_EDGE_CLOSED
int const GRID_EDGE_RECIRCULATE
double const MASS_BALANCE_TOLERANCE
int const LOG_FILE_HIGH_DETAIL
Contains CRWCoast definitions.
Contains CSimulation definitions.