38using std::stable_sort;
49bool bPolygonAndAdjCompare(
const vector<int>& nVLeft,
const vector<int>& nVRight)
57 bool const bDownCoastLeft = nVLeft[2];
58 bool const bDownCoastRight = nVRight[2];
71 if ((nVLeft.size() >= 4) && (nVRight.size() >= 4))
74 bool bLHSOffEdge =
false;
76 for (
unsigned int n = 3; n < nVLeft.size(); n++)
90 bool bRHSOffEdge =
false;
92 for (
unsigned int n = 3; n < nVRight.size(); n++)
106 if (!bDownCoastRight)
111 bool bLeftFound =
false;
113 for (
unsigned int n = 3; n < nVLeft.size(); n++)
115 if (nVLeft[n] == nVRight[1])
124 bool bRightFound =
false;
126 for (
unsigned int n = 3; n < nVRight.size(); n++)
128 if (nVRight[n] == nVLeft[1])
138 if (nVLeft[1] < nVRight[1])
156 if ((nVLeft.size() >= 4) && (nVRight.size() >= 4))
159 bool bLHSOffEdge =
false;
161 for (
unsigned int n = 3; n < nVLeft.size(); n++)
175 bool bRHSOffEdge =
false;
177 for (
unsigned int n = 3; n < nVRight.size(); n++)
191 if (!bDownCoastRight)
196 bool bLeftFound =
false;
198 for (
unsigned int n = 3; n < nVLeft.size(); n++)
200 if (nVLeft[n] == nVRight[1])
209 bool bRightFound =
false;
211 for (
unsigned int n = 3; n < nVRight.size(); n++)
213 if (nVRight[n] == nVLeft[1])
223 if (nVLeft[1] < nVRight[1])
240 for (
int nCoast = 0; nCoast < static_cast<int>(
m_VCoast.size()); nCoast++)
245 LogStream <<
m_ulIter <<
": Calculating unconsolidated sediment transport" << endl;
262 vector<vector<int>> nVVPolyAndAdjacent;
263 vector<int> nVPolyAndAdj;
265 for (
int nn = 0; nn <
m_VCoast[nCoast].nGetNumPolygons(); nn++)
268 nVPolyAndAdj.clear();
279 nVPolyAndAdj.push_back(
true);
286 nVPolyAndAdj.push_back(nAdjPolyID);
293 nVPolyAndAdj.push_back(
false);
300 nVPolyAndAdj.push_back(nAdjPolyID);
305 nVVPolyAndAdjacent.push_back(nVPolyAndAdj);
313 stable_sort(nVVPolyAndAdjacent.begin(), nVVPolyAndAdjacent.end(), bPolygonAndAdjCompare);
316 vector<int> VnSourcePolygons;
318 for (
int n = 0; n < static_cast<int>(nVVPolyAndAdjacent.size()); n++)
320 int const nThisPoly = nVVPolyAndAdjacent[n][1];
321 VnSourcePolygons.push_back(nThisPoly);
323 for (
int m = 3; m < static_cast<int>(nVVPolyAndAdjacent[n].size()); m++)
326 int const nToFind = nVVPolyAndAdjacent[n][m];
329 if (it != VnSourcePolygons.end())
335 pPoly =
m_VCoast[nCoast].pGetPolygon(nToFind);
344 int const nNumPolygons =
m_VCoast[nCoast].nGetNumPolygons();
347 for (
int nPoly = 0; nPoly < nNumPolygons; nPoly++)
349 int const nPolygon = nVVPolyAndAdjacent[nPoly][1];
384 if (dCoarseDepositionTarget > 0)
397 LogStream <<
" dCoarseDepositionTarget now = " << dCoarseDepositionTarget << endl;
401 double dCoarseDeposited = 0;
407 double const dCoarseNotDeposited = dCoarseDepositionTarget - dCoarseDeposited;
409 if (dCoarseNotDeposited > 0)
418 if (dSandDepositionTarget > 0)
431 LogStream <<
" dSandDepositionTarget now = " << dSandDepositionTarget << endl;
435 double dSandDeposited = 0;
441 double const dSandNotDeposited = dSandDepositionTarget - dSandDeposited;
443 if (dSandNotDeposited > 0)
470 if (dPotentialErosion > 0)
475 if (dExistingUnconsFine > 0)
481 double const dFineErosionTarget =
tMin(dFinePotentialErosion, dExistingUnconsFine);
484 double dFineEroded = 0;
505 double dSandEroded = 0;
507 if (dExistingUnconsSand > 0)
513 double const dSandErosionTarget =
tMin(dSandPotentialErosion, dExistingUnconsSand);
551 double dCoarseEroded = 0;
553 if (dExistingUnconsCoarse > 0)
559 double const dCoarseErosionTarget =
tMin(dCoarsePotentialErosion, dExistingUnconsCoarse);
567 if (dCoarseEroded > 0)
578 if ((dSandEroded + dCoarseEroded) > 0)
585 for (
int nn = 0; nn < nNumAdjPoly; nn++)
599 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;
609 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;
629 int const nOtherEndPoly = 0;
638 if (dCoarseEroded > 0)
665 if (dCoarseEroded > 0)
688 for (
int nn = 0; nn < nNumAdjPoly; nn++)
701 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;
711 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;
724 int const nOtherEndPoly = 0;
733 if (dCoarseEroded > 0)
760 if (dCoarseEroded > 0)
818 int const nPolygons =
m_VCoast[nCoast].nGetNumPolygons();
821 for (
int nn = nPolygons - 1; nn >= 0; nn--)
823 int const nThisPoly = nVVPolyAndAdjacent[nn][1];
828 if (dSandToDepositOnPoly > 0)
831 double dSandDeposited = 0;
837 double const dSandNotDeposited = dSandToDepositOnPoly - dSandDeposited;
839 if (dSandNotDeposited > 0)
848 if (dCoarseToDepositOnPoly > 0)
851 double dCoarseDeposited = 0;
857 double const dCoarseNotDeposited = dCoarseToDepositOnPoly - dCoarseDeposited;
859 if (dCoarseNotDeposited > 0)
879 int const nNumPolygons =
m_VCoast[nCoast].nGetNumPolygons();
881 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.
int nGetGlobalID(void) const
Get the global ID.
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.
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?
int nGetCoastID(void) const
Get the coast ID, this is the same as the down-coast sequence of polygons.
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.