CoastalME (Coastal Modelling Environment)
Simulates the long-term behaviour of complex coastlines
Loading...
Searching...
No Matches
do_sediment_input_event.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 <cstdio>
21
22#include <iostream>
23using std::endl;
24
25#include <algorithm>
26using std::begin;
27using std::end;
28using std::find;
29
30#include "cme.h"
31#include "simulation.h"
32#include "cell.h"
33#include "coast.h"
35#include "2di_point.h"
36
37//===============================================================================================================================
39//===============================================================================================================================
41{
43
44 // Go through all sediment input events, check for any this timestep
45 int const nEvents = static_cast<int>(m_pVSedInputEvent.size());
46
47 for (int n = 0; n < nEvents; n++)
48 {
49 if (m_pVSedInputEvent[n]->ulGetEventTimeStep() == m_ulIter)
50 {
52
53 int const nRet = nDoSedimentInputEvent(n);
54
55 if (nRet != RTN_OK)
56 return nRet;
57 }
58 }
59
60 return RTN_OK;
61}
62
63//===============================================================================================================================
65//===============================================================================================================================
67{
68 // Get values for the sediment input event
69 int const nLocID = m_pVSedInputEvent[nEvent]->nGetLocationID();
70 double const dFineSedVol = m_pVSedInputEvent[nEvent]->dGetFineSedVol();
71 double const dSandSedVol = m_pVSedInputEvent[nEvent]->dGetSandSedVol();
72 double const dCoarseSedVol = m_pVSedInputEvent[nEvent]->dGetCoarseSedVol();
73 double const dLen = m_pVSedInputEvent[nEvent]->dGetLen();
74 double const dWidth = m_pVSedInputEvent[nEvent]->dGetWidth();
75 // double dThick = m_pVSedInputEvent[nEvent]->dGetThick();
76
77 // TODO 083 Get all three kinds of sediment input events working correctly
78
80 {
81 // The sediment input event is at a user-specified point, or in a block at the nearest point on a coast to a user-specified point. So get the point from values read from the shapefile
82 int const nEvents = static_cast<int>(m_VnSedimentInputLocationID.size());
83 int nPointGridX = -1;
84 int nPointGridY = -1;
85
86 for (int n = 0; n < nEvents; n++)
87 {
88 if (m_VnSedimentInputLocationID[n] == nLocID)
89 {
90 nPointGridX = nRound(m_VdSedimentInputLocationX[n]); // In grid coords
91 nPointGridY = nRound(m_VdSedimentInputLocationY[n]); // In grid coords
92 }
93 }
94
95 if (nPointGridX == -1)
96 // Should never get here
98
99 // All OK, so get landform
100 CRWCellLandform* pLandform = m_pRasterGrid->m_Cell[nPointGridX][nPointGridY].pGetLandform();
101
102 // Is this sediment input event at a pre-specified fixed point, or in a block on a coast, or where a line intersects with a coast?
104 {
105 // Sediment input is at a user-specified point
106 int const nTopLayer = m_pRasterGrid->m_Cell[nPointGridX][nPointGridY].nGetNumOfTopLayerAboveBasement();
107
108 // Is this user-specified point in a polygon?
109 int const nThisPoly = m_pRasterGrid->m_Cell[nPointGridX][nPointGridY].nGetPolygonID();
110 int nThisPolyCoast = INT_NODATA;
111 if (nThisPoly != INT_NODATA)
112 {
113 // Yes we are in a polygon, so get the coast ID of the polygon for this cell
114 nThisPolyCoast = m_pRasterGrid->m_Cell[nPointGridX][nPointGridY].nGetPolygonCoastID();
115
116 // Safety check
117 if (nThisPolyCoast == INT_NODATA)
119 }
120
122 {
123 LogStream << m_ulIter << ": Sediment input event " << nEvent + 1 << " at point [" << nPointGridX << "][" << nPointGridY << "] = {" << dGridXToExtCRSX(nPointGridX) << ", " << dGridYToExtCRSY(nPointGridY) << "] with location ID " << nLocID;
124
125 if (nThisPoly != INT_NODATA)
126 LogStream << " which is within coast " << nThisPolyCoast << " polygon " << nThisPoly << endl;
127 else
128 LogStream << " this is not within a polygon" << endl;
129 }
130
131 // Is some fine unconsolidated sediment being input?
132 double const dFineDepth = dFineSedVol / m_dCellArea;
133 if (dFineDepth > 0)
134 {
135 // Yes, so add to this cell's fine unconsolidated sediment
136 m_pRasterGrid->m_Cell[nPointGridX][nPointGridY].pGetLayerAboveBasement(nTopLayer)->pGetUnconsolidatedSediment()->AddFineSedimentInputDepth(dFineDepth);
137
138 // And update the sediment top elevation value
139 m_pRasterGrid->m_Cell[nPointGridX][nPointGridY].CalcAllLayerElevsAndD50();
140
141 // If we are in a polygon, then add to this polygon's sand sediment input total
142 if (nThisPoly != INT_NODATA)
143 m_VCoast[nThisPolyCoast].pGetPolygon(nThisPoly)->SetSedimentInputUnconsFine(dFineDepth);
144
145 // Add to the this-iteration total of fine sediment input
146 m_dThisiterUnconsFineInput += dFineDepth;
147
148 // And assign the cell's landform category
150 }
151
152 // Is some sand-sized unconsolidated sediment being input?
153 double const dSandDepth = dSandSedVol / m_dCellArea;
154
155 if (dSandDepth > 0)
156 {
157 // Yes, so add to this cell's sand unconsolidated sediment
158 m_pRasterGrid->m_Cell[nPointGridX][nPointGridY].pGetLayerAboveBasement(nTopLayer)->pGetUnconsolidatedSediment()->AddSandSedimentInputDepth(dSandDepth);
159
160 // And update the sediment top elevation value
161 m_pRasterGrid->m_Cell[nPointGridX][nPointGridY].CalcAllLayerElevsAndD50();
162
163 // If we are in a polygon, then add to this polygon's sand sediment input total
164 if (nThisPoly != INT_NODATA)
165 m_VCoast[nThisPolyCoast].pGetPolygon(nThisPoly)->SetSedimentInputUnconsSand(dSandDepth);
166
167 // Add to the this-iteration total of sand sediment input
168 m_dThisiterUnconsSandInput += dSandDepth;
169
170 // And assign the cell's landform category
172 }
173
174 // Is some coarse unconsolidated sediment being input?
175 double const dCoarseDepth = dCoarseSedVol / m_dCellArea;
176
177 if (dCoarseDepth > 0)
178 {
179 // Yes, so add to this cell's coarse unconsolidated sediment
180 m_pRasterGrid->m_Cell[nPointGridX][nPointGridY].pGetLayerAboveBasement(nTopLayer)->pGetUnconsolidatedSediment()->AddCoarseSedimentInputDepth(dCoarseDepth);
181
182 // And update the sediment top elevation value
183 m_pRasterGrid->m_Cell[nPointGridX][nPointGridY].CalcAllLayerElevsAndD50();
184
185 // If we are in a polygon, then add to this polygon's coarse sediment input total
186 if (nThisPoly != INT_NODATA)
187 m_VCoast[nThisPolyCoast].pGetPolygon(nThisPoly)->SetSedimentInputUnconsCoarse(dCoarseDepth);
188
189 // Add to the this-iteration total of coarse sediment input
190 m_dThisiterUnconsCoarseInput += dCoarseDepth;
191
192 // And assign the cell's landform category
194 }
195
197 LogStream << ", depth of fine sediment added = " << dFineDepth << " m, depth of sand sediment added = " << dSandDepth << " m, depth of coarse sediment added = " << dCoarseDepth << " m" << endl;
198 }
200 {
201 // Is in a sediment block, seaward from a coast
203 LogStream << m_ulIter << ": Sediment input event " << nEvent + 1 << " with location ID " << nLocID << " at closest point on coast to [" << nPointGridX << "][" << nPointGridY << "] = {" << dGridXToExtCRSX(nPointGridX) << ", " << dGridYToExtCRSY(nPointGridY) << "]" << endl;
204
205 // Find the closest point on any coastline
206 int nCoastClosest;
207 CGeom2DIPoint const PtiCoastPoint = PtiFindClosestCoastPoint(nPointGridX, nPointGridY, nCoastClosest);
208
209 int const nCoastX = PtiCoastPoint.nGetX();
210 int const nCoastY = PtiCoastPoint.nGetY();
211
213 LogStream << m_ulIter << ": Closest coast point is on coast " << nCoastClosest << " at [" << nCoastX << "][" << nCoastY << "] = {" << dGridXToExtCRSX(nCoastX) << ", " << dGridYToExtCRSY(nCoastY) << "}, along-coast width of sediment block = " << dWidth << " m, coast-normal length of sediment block = " << dLen << " m" << endl;
214
215 int const nCoast = m_pRasterGrid->m_Cell[nCoastX][nCoastY].pGetLandform()->nGetCoast();
216 int const nCoastPoint = m_pRasterGrid->m_Cell[nCoastX][nCoastY].pGetLandform()->nGetPointOnCoast();
217 int const nHalfWidth = nRound(dWidth / m_dCellSide);
218 int const nLength = nRound(dLen / m_dCellSide);
219 int const nCoastLen = m_VCoast[nCoast].nGetCoastlineSize();
220 int nCoastXBefore = nCoastX;
221 int nCoastYBefore = nCoastY;
222 int nCoastXAfter = nCoastX;
223 int nCoastYAfter = nCoastY;
224
225 if (nCoastPoint > 0)
226 {
227 nCoastXBefore = m_VCoast[nCoast].pPtiGetCellMarkedAsCoastline(nCoastPoint - 1)->nGetX();
228 nCoastYBefore = m_VCoast[nCoast].pPtiGetCellMarkedAsCoastline(nCoastPoint - 1)->nGetY();
229 }
230
231 if (nCoastPoint < nCoastLen - 1)
232 {
233 nCoastXAfter = m_VCoast[nCoast].pPtiGetCellMarkedAsCoastline(nCoastPoint + 1)->nGetX();
234 nCoastYAfter = m_VCoast[nCoast].pPtiGetCellMarkedAsCoastline(nCoastPoint + 1)->nGetY();
235 }
236
237 int const nCoastHand = m_VCoast[nCoast].nGetSeaHandedness();
238 int nPerpHand = LEFT_HANDED;
239
240 if (nCoastHand == LEFT_HANDED)
241 nPerpHand = RIGHT_HANDED;
242
243 vector<CGeom2DIPoint> VPoints;
244
245 // If size of plume is smaller than a cell, choose the current coast point
246 if (nHalfWidth == 0)
247 {
248 VPoints.push_back(PtiCoastPoint);
249 }
250
251 else
252 {
253 // It is larger than a cell
254 vector<int> VnCentrePointsXOffset, VnCentrePointsYOffset;
255
256 for (int m = 0; m < nHalfWidth; m++)
257 {
258 if (m == 0)
259 {
260 VPoints.push_back(CGeom2DIPoint(nCoastX, nCoastY));
261
262 for (int n = 1; n < nLength; n++)
263 {
264 CGeom2DIPoint const PtiTmp = PtiGetPerpendicular(nCoastXBefore, nCoastYBefore, nCoastXAfter, nCoastYAfter, n, nPerpHand);
265
266 if (bIsWithinValidGrid(&PtiTmp))
267 {
268 VPoints.push_back(PtiTmp);
269
270 VnCentrePointsXOffset.push_back(PtiTmp.nGetX() - nCoastX);
271 VnCentrePointsYOffset.push_back(PtiTmp.nGetY() - nCoastY);
272 }
273 }
274 }
275 else
276 {
277 int const nCoastPointInBlockBefore = nCoastPoint - m;
278 int const nCoastPointInBlockAfter = nCoastPoint + m;
279
280 if (nCoastPointInBlockBefore >= 0)
281 {
282 int const nCoastXInBlockBefore = m_VCoast[nCoast].pPtiGetCellMarkedAsCoastline(nCoastPointInBlockBefore)->nGetX();
283 int const nCoastYInBlockBefore = m_VCoast[nCoast].pPtiGetCellMarkedAsCoastline(nCoastPointInBlockBefore)->nGetY();
284
285 if (bIsWithinValidGrid(nCoastXInBlockBefore, nCoastYInBlockBefore))
286 {
287 VPoints.push_back(CGeom2DIPoint(nCoastXInBlockBefore, nCoastYInBlockBefore));
288
289 for (unsigned int n = 0; n < VnCentrePointsXOffset.size(); n++)
290 {
291 int const nXTmp = nCoastXInBlockBefore + VnCentrePointsXOffset[n];
292 int const nYTmp = nCoastYInBlockBefore + VnCentrePointsYOffset[n];
293
294 if (bIsWithinValidGrid(nXTmp, nYTmp))
295 VPoints.push_back(CGeom2DIPoint(nXTmp, nYTmp));
296 }
297 }
298 }
299
300 if (nCoastPointInBlockAfter < nCoastLen)
301 {
302 int const nCoastXInBlockAfter = m_VCoast[nCoast].pPtiGetCellMarkedAsCoastline(nCoastPointInBlockAfter)->nGetX();
303 int const nCoastYInBlockAfter = m_VCoast[nCoast].pPtiGetCellMarkedAsCoastline(nCoastPointInBlockAfter)->nGetY();
304
305 if (bIsWithinValidGrid(nCoastXInBlockAfter, nCoastYInBlockAfter))
306 {
307 VPoints.push_back(CGeom2DIPoint(nCoastXInBlockAfter, nCoastYInBlockAfter));
308
309 for (unsigned int n = 0; n < VnCentrePointsXOffset.size(); n++)
310 {
311 int const nXTmp = nCoastXInBlockAfter + VnCentrePointsXOffset[n];
312 int const nYTmp = nCoastYInBlockAfter + VnCentrePointsYOffset[n];
313
314 if (bIsWithinValidGrid(nXTmp, nYTmp))
315 {
316 CGeom2DIPoint const PtiTmp(nXTmp, nYTmp);
317
318 // Is this cell already in the array?
319 if (find(begin(VPoints), end(VPoints), PtiTmp) == end(VPoints))
320 // No it isn't
321 VPoints.push_back(PtiTmp);
322 }
323 }
324 }
325 }
326 }
327 }
328
329 // // DEBUG CODE ===============================================================================================================
330 // LogStream << endl;
331 // unsigned int m = 0;
332 // for (unsigned int n = 0; n < VPoints.size(); n++)
333 // {
334 // LogStream << "[" << VPoints[n].nGetX() << ", " << VPoints[n].nGetY() << "] ";
335 // m++;
336 // if (m == VnCentrePointsXOffset.size() + 1)
337 // {
338 // LogStream << endl;
339 // m = 0;
340 // }
341 // }
342 // LogStream << endl;
343 // // DEBUG CODE ===============================================================================================================
344 }
345
346 // OK we now know which cells are part of the sediment block, and so will receive sediment input. Next calculate the volume per cell
347 double const dFineDepth = dFineSedVol / m_dCellArea;
348 double const dSandDepth = dSandSedVol / m_dCellArea;
349 double const dCoarseDepth = dCoarseSedVol / m_dCellArea;
350
352 LogStream << m_ulIter << ": Total depth of fine sediment added = " << dFineDepth << " m, total depth of sand sediment added = " << dSandDepth << " m, total depth of coarse sediment added = " << dCoarseDepth << " m" << endl;
353
354 size_t const nArea = VPoints.size();
355 double const dArea = static_cast<double>(nArea);
356 double const dFineDepthPerCell = dFineDepth / dArea;
357 double const dSandDepthPerCell = dSandDepth / dArea;
358 double const dCoarseDepthPerCell = dCoarseDepth / dArea;
359
360 // OK, so finally: put some sediment onto each cell in the sediment block
361 int const nTopLayer = m_pRasterGrid->m_Cell[nPointGridX][nPointGridY].nGetNumOfTopLayerAboveBasement();
362
363 for (unsigned int n = 0; n < nArea; n++)
364 {
365 int const nX = VPoints[n].nGetX();
366 int const nY = VPoints[n].nGetY();
367
368 // Add to this cell's fine unconsolidated sediment
369 m_pRasterGrid->m_Cell[nX][nY].pGetLayerAboveBasement(nTopLayer)->pGetUnconsolidatedSediment()->AddFineSedimentInputDepth(dFineDepthPerCell);
370
371 // Add to this cell's sand unconsolidated sediment
372 m_pRasterGrid->m_Cell[nX][nY].pGetLayerAboveBasement(nTopLayer)->pGetUnconsolidatedSediment()->AddSandSedimentInputDepth(dSandDepthPerCell);
373
374 // Add to this cell's coarse unconsolidated sediment
375 m_pRasterGrid->m_Cell[nX][nY].pGetLayerAboveBasement(nTopLayer)->pGetUnconsolidatedSediment()->AddCoarseSedimentInputDepth(dCoarseDepthPerCell);
376 }
377
378 // Add to the this-iteration totals
379 m_dThisiterUnconsFineInput += dFineDepth;
380 m_dThisiterUnconsSandInput += dSandDepth;
381 m_dThisiterUnconsCoarseInput += dCoarseDepth;
382 }
383 }
385 {
386 // The location of the sediment input event is where a line intersects a coast. First get the line, using values read from the shapefile
387 int const nPoints = static_cast<int>(m_VnSedimentInputLocationID.size());
388 vector<int> VnLineGridX;
389 vector<int> VnLineGridY;
390
391 for (int n = 0; n < nPoints; n++)
392 {
393 if (m_VnSedimentInputLocationID[n] == nLocID)
394 {
395 VnLineGridX.push_back(nRound(m_VdSedimentInputLocationX[n]));
396 VnLineGridY.push_back(nRound(m_VdSedimentInputLocationY[n]));
397 }
398 }
399
400 // // DEBUG CODE ===========================================================================================================
401 // string strOutFile = m_strOutPath;
402 // strOutFile += "00_sediment_input_line_CHECK_";
403 // strOutFile += to_string(m_ulIter);
404 // strOutFile += ".tif";
405 //
406 // GDALDriver* pDriver = GetGDALDriverManager()->GetDriverByName("gtiff");
407 // GDALDataset* pDataSet = pDriver->Create(strOutFile.c_str(), m_nXGridSize, m_nYGridSize, 1, GDT_Float64, m_papszGDALRasterOptions);
408 // pDataSet->SetProjection(m_strGDALBasementDEMProjection.c_str());
409 // pDataSet->SetGeoTransform(m_dGeoTransform);
410 //
411 // int nn = 0;
412 // double* pdRaster = new double[m_nXGridSize * m_nYGridSize];
413 // for (int nY = 0; nY < m_nYGridSize; nY++)
414 // {
415 // for (int nX = 0; nX < m_nXGridSize; nX++)
416 // {
417 // pdRaster[nn++] = 0;
418 // }
419 // }
420 //
421 // for (unsigned int n = 0; n < VnLineGridX.size() - 1; n++)
422 // {
423 // int nX = VnLineGridX[n];
424 // int nY = VnLineGridY[n];
425 // int m = (nY * m_nXGridSize) + nX;
426 //
427 // pdRaster[m] = 1;
428 // }
429 //
430 // GDALRasterBand* pBand = pDataSet->GetRasterBand(1);
431 // pBand->SetNoDataValue(m_dMissingValue);
432 // int nRet = pBand->RasterIO(GF_Write, 0, 0, m_nXGridSize, m_nYGridSize, pdRaster, m_nXGridSize, m_nYGridSize, GDT_Float64, 0, 0, NULL);
433 //
434 // if (nRet == CE_Failure)
435 // return RTN_ERR_GRIDCREATE;
436 //
437 // GDALClose(pDataSet);
438 // delete[] pdRaster;
439 // // DEBUG CODE ===========================================================================================================
440
441 // Should never get here
442 if (VnLineGridX.size() == 0)
444
446 LogStream << m_ulIter << ": Sediment input event " << nEvent << " at line/coast intersection for line with ID " << nLocID << endl;
447
448 // Now go along the line, joining each pair of points by a straight line
449 int nCoastX = -1;
450 int nCoastY = -1;
451
452 for (unsigned int n = 0; n < VnLineGridX.size() - 1; n++)
453 {
454 int const nXStart = VnLineGridX[n];
455 int const nXEnd = VnLineGridX[n + 1];
456 int const nYStart = VnLineGridY[n];
457 int const nYEnd = VnLineGridY[n + 1];
458
459 // Interpolate between pairs of points using a simple DDA line algorithm, see http://en.wikipedia.org/wiki/Digital_differential_analyzer_(graphics_algorithm). Bresenham's algorithm gave occasional gaps
460 double dXInc = nXEnd - nXStart;
461 double dYInc = nYEnd - nYStart;
462 double const dLength = tMax(tAbs(dXInc), tAbs(dYInc));
463
464 dXInc /= dLength;
465 dYInc /= dLength;
466
467 double dX = nXStart;
468 double dY = nYStart;
469
470 // Process each interpolated point
471 for (int m = 0; m <= nRound(dLength); m++)
472 {
473 int const nX = nRound(dX);
474 int const nY = nRound(dY);
475
476 // Have we hit a coastline cell?
477 if (bIsWithinValidGrid(nX, nY) && m_pRasterGrid->m_Cell[nX][nY].bIsCoastline())
478 {
479 nCoastX = nX;
480 nCoastY = nY;
481 break;
482 }
483
484 // Two diagonal(ish) raster lines can cross each other without any intersection, so must also test an adjacent cell for intersection (does not matter which adjacent cell)
485 if (bIsWithinValidGrid(nX, nY + 1) && m_pRasterGrid->m_Cell[nX][nY + 1].bIsCoastline())
486 {
487 nCoastX = nX;
488 nCoastY = nY + 1;
489 break;
490 }
491
492 // Increment for next time
493 dX += dXInc;
494 dY += dYInc;
495 }
496
497 // Did we find an intersection?
498 if (nCoastX != -1)
499 break;
500 }
501
502 // Did we find an intersection?
503 if (nCoastX == -1)
504 {
505 // Nope
507 LogStream << m_ulIter << ": No line/coast intersection found" << endl;
508
510 }
511
512 // OK we have an intersection of the line and coast. We will input the sediment here. Get landform and top layer
513 CRWCellLandform* pLandform = m_pRasterGrid->m_Cell[nCoastX][nCoastY].pGetLandform();
514 int const nTopLayer = m_pRasterGrid->m_Cell[nCoastX][nCoastY].nGetNumOfTopLayerAboveBasement();
515
516 // Is this intersection point in a polygon?
517 int const nThisPoly = m_pRasterGrid->m_Cell[nCoastX][nCoastY].nGetPolygonID();
518 int nThisPolyCoast = INT_NODATA;
519 if (nThisPoly != INT_NODATA)
520 {
521 // Yes we are in a polygon, so get the coast ID of the polygon for this cell
522 nThisPolyCoast = m_pRasterGrid->m_Cell[nCoastX][nCoastY].nGetPolygonCoastID();
523
524 // Safety check
525 if (nThisPolyCoast == INT_NODATA)
527 }
528
530 {
531 LogStream << m_ulIter << ": line/coast intersection is at [" << nCoastX << "][" << nCoastY << "] = {" << dGridXToExtCRSX(nCoastX) << ", " << dGridYToExtCRSY(nCoastY) << "}";
532
533 if (nThisPoly != INT_NODATA)
534 LogStream << " which is within coast " << nThisPolyCoast << " polygon " << nThisPoly << endl;
535 else
536 LogStream << " which is not within a polygon" << endl;
537 }
538
539 // Is some fine unconsolidated sediment being input?
540 double const dFineDepth = dFineSedVol / m_dCellArea;
541 if (dFineDepth > 0)
542 {
543 // Yes, so add to this cell's fine unconsolidated sediment
544 m_pRasterGrid->m_Cell[nCoastX][nCoastY].pGetLayerAboveBasement(nTopLayer)->pGetUnconsolidatedSediment()->AddFineSedimentInputDepth(dFineDepth);
545
546 // And update the sediment top elevation value
547 m_pRasterGrid->m_Cell[nCoastX][nCoastY].CalcAllLayerElevsAndD50();
548
549 if (nThisPoly != INT_NODATA)
550 // Add to this polygon's fine sediment input total
551 m_VCoast[nThisPolyCoast].pGetPolygon(nThisPoly)->SetSedimentInputUnconsFine(dFineDepth);
552
553 // Add to the this-iteration total of fine sediment input
554 m_dThisiterUnconsFineInput += dFineDepth;
555
556 // And assign the cell's landform category
558 }
559
560 // Is some sand-sized unconsolidated sediment being input?
561 double const dSandDepth = dSandSedVol / m_dCellArea;
562 if (dSandDepth > 0)
563 {
564 // Yes, so add to this cell's sand unconsolidated sediment
565 m_pRasterGrid->m_Cell[nCoastX][nCoastY].pGetLayerAboveBasement(nTopLayer)->pGetUnconsolidatedSediment()->AddSandSedimentInputDepth(dSandDepth);
566
567 // And update the sediment top elevation value
568 m_pRasterGrid->m_Cell[nCoastX][nCoastY].CalcAllLayerElevsAndD50();
569
570 if (nThisPoly != INT_NODATA)
571 // Add to this polygon's sand sediment input total
572 m_VCoast[nThisPolyCoast].pGetPolygon(nThisPoly)->SetSedimentInputUnconsSand(dSandDepth);
573
574 // Add to the this-iteration total of sand sediment input
575 m_dThisiterUnconsSandInput += dSandDepth;
576
577 // And assign the cell's landform category
579 }
580
581 // Is some coarse unconsolidated sediment being input?
582 double const dCoarseDepth = dCoarseSedVol / m_dCellArea;
583 if (dCoarseDepth > 0)
584 {
585 // Yes, so add to this cell's coarse unconsolidated sediment
586 m_pRasterGrid->m_Cell[nCoastX][nCoastY].pGetLayerAboveBasement(nTopLayer)->pGetUnconsolidatedSediment()->AddCoarseSedimentInputDepth(dCoarseDepth);
587
588 // And update the sediment top elevation value
589 m_pRasterGrid->m_Cell[nCoastX][nCoastY].CalcAllLayerElevsAndD50();
590
591 if (nThisPoly != INT_NODATA)
592 // Add to this polygon's coarse sediment input total
593 m_VCoast[nThisPolyCoast].pGetPolygon(nThisPoly)->SetSedimentInputUnconsCoarse(dCoarseDepth);
594
595 // Add to the this-iteration total of coarse sediment input
596 m_dThisiterUnconsCoarseInput += dCoarseDepth;
597
598 // And assign the cell's landform category
600 }
601
603 LogStream << m_ulIter << "; depth of fine sediment added = " << dFineDepth << " m, depth of sand sediment added = " << dSandDepth << " m, depth of coarse sediment added = " << dCoarseDepth << " m" << endl;
604 }
605
606 return RTN_OK;
607}
Contains CGeom2DIPoint definitions.
Contains CGeomCell definitions.
Geometry class used to represent 2D point objects with integer coordinates.
Definition 2di_point.h:25
int nGetY(void) const
Returns the CGeom2DIPoint object's integer Y coordinate.
Definition 2di_point.cpp:51
int nGetX(void) const
Returns the CGeom2DIPoint object's integer X coordinate.
Definition 2di_point.cpp:45
Real-world class used to represent the landform of a cell.
void SetLFCategory(int const)
Set the landform category.
int m_nLogFileDetail
The level of detail in the log file output. Can be LOG_FILE_LOW_DETAIL, LOG_FILE_MIDDLE_DETAIL,...
Definition simulation.h:588
bool m_bSedimentInputAtPoint
Do we have sediment inputat a point?
Definition simulation.h:396
CGeomRasterGrid * m_pRasterGrid
Pointer to the raster grid object.
ofstream LogStream
vector< CRWCoast > m_VCoast
The coastline objects.
vector< int > m_VnSedimentInputLocationID
ID for sediment input location, this corresponds with the ID in the sediment input time series file.
static CGeom2DIPoint PtiGetPerpendicular(CGeom2DIPoint const *, CGeom2DIPoint const *, double const, int const)
Returns a CGeom2DIPoint (grid CRS) which is the 'other' point of a two-point vector passing through P...
int nCheckForSedimentInputEvent(void)
Check to see if we have any sediment input events this timestep, if so then do the event(s)
bool m_bSedimentInputAlongLine
Do we have sediment input along a line?
Definition simulation.h:402
double m_dThisiterUnconsCoarseInput
Depth (m) of coarse unconsolidated sediment added, at this iteration.
Definition simulation.h:999
int nDoSedimentInputEvent(int const)
Do a sediment input event.
double m_dThisiterUnconsFineInput
Depth (m) of fine unconsolidated sediment added, at this iteration.
Definition simulation.h:993
vector< double > m_VdSedimentInputLocationX
X coordinate (grid CRS) for sediment input event.
bool m_bSedimentInputAtCoast
Do we have sediment input at the coast?
Definition simulation.h:399
double dGridYToExtCRSY(double const) const
Given a real-valued Y-axis ordinate in the raster grid CRS (i.e. not the centroid of a cell),...
vector< double > m_VdSedimentInputLocationY
X coordinate (grid CRS) for sediment input event.
double m_dCellArea
Area of a cell (in external CRS units)
Definition simulation.h:675
bool bIsWithinValidGrid(int const, int const) const
Checks whether the supplied point (an x-y pair, in the grid CRS) is within the raster grid,...
double dGridXToExtCRSX(double const) const
Given a real-valued X-axis ordinate in the raster grid CRS (i.e. not the centroid of a cell),...
Definition gis_utils.cpp:95
unsigned long m_ulIter
The number of the current iteration (time step)
Definition simulation.h:609
double m_dThisiterUnconsSandInput
Depth (m) of sand unconsolidated sediment added, at this iteration.
Definition simulation.h:996
double m_dCellSide
Length of a cell side (in external CRS units)
Definition simulation.h:672
CGeom2DIPoint PtiFindClosestCoastPoint(int const, int const, int &)
Finds the closest point on any coastline to a given point.
vector< CRWSedInputEvent * > m_pVSedInputEvent
Sediment input events.
bool m_bSedimentInputThisIter
Do we have a sediment input event this iteration?
Definition simulation.h:408
This file contains global definitions for CoastalME.
int const INT_NODATA
Definition cme.h:380
int const LOG_FILE_MIDDLE_DETAIL
Definition cme.h:393
int const RTN_ERR_CELL_IN_POLY_BUT_NO_POLY_COAST
Definition cme.h:665
T tMax(T a, T b)
Definition cme.h:1162
int const LF_SEDIMENT_INPUT_UNCONSOLIDATED
Definition cme.h:445
int const RTN_OK
Definition cme.h:585
int const RIGHT_HANDED
Definition cme.h:413
T tAbs(T a)
Definition cme.h:1187
int const RTN_ERR_SEDIMENT_INPUT_EVENT
Definition cme.h:648
int const LEFT_HANDED
Definition cme.h:414
Contains CRWCoast definitions.
Contains CRWSedInputEvent definitions.
Contains CSimulation definitions.
int nRound(double const d)
Correctly rounds doubles, returns an int.