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