34using std::stable_sort;
45bool bPolygonAndAdjCompare(
const vector<int>& nVLeft,
const vector<int>& nVRight)
52 bool const bDownCoastLeft = nVLeft[1];
53 bool const bDownCoastRight = nVRight[1];
66 if ((nVLeft.size() >= 3) && (nVRight.size() >= 3))
69 bool bLHSOffEdge =
false;
71 for (
unsigned int n = 2; n < nVLeft.size(); n++)
85 bool bRHSOffEdge =
false;
87 for (
unsigned int n = 2; n < nVRight.size(); n++)
101 if (! bDownCoastRight)
106 bool bLeftFound =
false;
108 for (
unsigned int n = 2; n < nVLeft.size(); n++)
110 if (nVLeft[n] == nVRight[0])
119 bool bRightFound =
false;
121 for (
unsigned int n = 2; n < nVRight.size(); n++)
123 if (nVRight[n] == nVLeft[0])
133 if (nVLeft[0] < nVRight[0])
151 if ((nVLeft.size() >= 3) && (nVRight.size() >= 3))
154 bool bLHSOffEdge =
false;
156 for (
unsigned int n = 2; n < nVLeft.size(); n++)
170 bool bRHSOffEdge =
false;
172 for (
unsigned int n = 2; n < nVRight.size(); n++)
186 if (! bDownCoastRight)
191 bool bLeftFound =
false;
193 for (
unsigned int n = 2; n < nVLeft.size(); n++)
195 if (nVLeft[n] == nVRight[0])
204 bool bRightFound =
false;
206 for (
unsigned int n = 2; n < nVRight.size(); n++)
208 if (nVRight[n] == nVLeft[0])
218 if (nVLeft[0] < nVRight[0])
235 for (
int nCoast = 0; nCoast < static_cast<int>(
m_VCoast.size()); nCoast++)
240 LogStream <<
m_ulIter <<
": Calculating unconsolidated sediment transport" << endl;
256 vector<vector<int>> nVVPolyAndAdjacent;
257 vector<int> nVPolyAndAdj;
259 for (
int nn = 0; nn <
m_VCoast[nCoast].nGetNumPolygons(); nn++)
262 nVPolyAndAdj.clear();
270 nVPolyAndAdj.push_back(
true);
277 nVPolyAndAdj.push_back(nAdjPolyID);
284 nVPolyAndAdj.push_back(
false);
291 nVPolyAndAdj.push_back(nAdjPolyID);
296 nVVPolyAndAdjacent.push_back(nVPolyAndAdj);
304 stable_sort(nVVPolyAndAdjacent.begin(), nVVPolyAndAdjacent.end(), bPolygonAndAdjCompare);
307 vector<int> VnSourcePolygons;
309 for (
int n = 0; n < static_cast<int>(nVVPolyAndAdjacent.size()); n++)
311 int const nThisPoly = nVVPolyAndAdjacent[n][0];
312 VnSourcePolygons.push_back(nThisPoly);
314 for (
int m = 2; m < static_cast<int>(nVVPolyAndAdjacent[n].size()); m++)
317 int const nToFind = nVVPolyAndAdjacent[n][m];
320 if (it != VnSourcePolygons.end())
326 pPoly =
m_VCoast[nCoast].pGetPolygon(nToFind);
335 int const nNumPolygons =
m_VCoast[nCoast].nGetNumPolygons();
338 for (
int nPoly = 0; nPoly < nNumPolygons; nPoly++)
340 int const nPolygon = nVVPolyAndAdjacent[nPoly][0];
375 if (dCoarseDepositionTarget > 0)
388 LogStream <<
" dCoarseDepositionTarget now = " << dCoarseDepositionTarget << endl;
392 double dCoarseDeposited = 0;
398 double const dCoarseNotDeposited = dCoarseDepositionTarget - dCoarseDeposited;
400 if (dCoarseNotDeposited > 0)
409 if (dSandDepositionTarget > 0)
422 LogStream <<
" dSandDepositionTarget now = " << dSandDepositionTarget << endl;
426 double dSandDeposited = 0;
432 double const dSandNotDeposited = dSandDepositionTarget - dSandDeposited;
434 if (dSandNotDeposited > 0)
461 if (dPotentialErosion > 0)
466 if (dExistingUnconsFine > 0)
472 double const dFineErosionTarget =
tMin(dFinePotentialErosion, dExistingUnconsFine);
475 double dFineEroded = 0;
496 double dSandEroded = 0;
498 if (dExistingUnconsSand > 0)
504 double const dSandErosionTarget =
tMin(dSandPotentialErosion, dExistingUnconsSand);
542 double dCoarseEroded = 0;
544 if (dExistingUnconsCoarse > 0)
550 double const dCoarseErosionTarget =
tMin(dCoarsePotentialErosion, dExistingUnconsCoarse);
558 if (dCoarseEroded > 0)
569 if ((dSandEroded + dCoarseEroded) > 0)
576 for (
int nn = 0; nn < nNumAdjPoly; nn++)
590 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;
600 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;
620 int const nOtherEndPoly = 0;
629 if (dCoarseEroded > 0)
656 if (dCoarseEroded > 0)
679 for (
int nn = 0; nn < nNumAdjPoly; nn++)
692 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;
715 int const nOtherEndPoly = 0;
724 if (dCoarseEroded > 0)
751 if (dCoarseEroded > 0)
809 int const nPolygons =
m_VCoast[nCoast].nGetNumPolygons();
812 for (
int nn = nPolygons - 1; nn >= 0; nn--)
814 int const nThisPoly = nVVPolyAndAdjacent[nn][0];
819 if (dSandToDepositOnPoly > 0)
822 double dSandDeposited = 0;
828 double const dSandNotDeposited = dSandToDepositOnPoly - dSandDeposited;
830 if (dSandNotDeposited > 0)
839 if (dCoarseToDepositOnPoly > 0)
842 double dCoarseDeposited = 0;
848 double const dCoarseNotDeposited = dCoarseToDepositOnPoly - dCoarseDeposited;
850 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.
void WritePolygonSedimentBeforeMovement(int const)
Writes to the log file a table showing per-polygon totals of stored unconsolidated beach sediment pri...
void WritePolygonSortedSequence(int const, vector< vector< int > > &)
Writes to the log file a table showing the sorted sequence of polygon processing, and any circulariti...
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 WritePolygonPotentialErosion(int const)
Writes to the log file a table showing per-polygon potential erosion of all size classes of unconsoli...
void WritePolygonActualMovement(int const, vector< vector< int > > const &)
Writes to the log file a table showing per-polygon actual movement of unconsolidated beach sediment.
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 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)
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)
void WritePolygonUnsortedSequence(int const, vector< vector< int > > &)
Writes to the log file a table showing the unsorted sequence of polygon processing.
double m_dThisIterLeftGridUnconsSand
Total sand unconsolidated sediment lost from the grid this iteration (depth in m)
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.