41using std::reverse_copy;
57 for (
int nCoast = 0; nCoast < static_cast<int>(
m_VCoast.size()); nCoast++)
59 int nDistFromPrevProfile = 0;
60 int nDistToNextProfile = 0;
62 double dPrevProfileDeepWaterWaveHeight = 0;
63 double dPrevProfileDeepWaterWaveAngle = 0;
64 double dPrevProfileDeepWaterWavePeriod = 0;
65 double dNextProfileDeepWaterWaveHeight = 0;
66 double dNextProfileDeepWaterWaveAngle = 0;
67 double dNextProfileDeepWaterWavePeriod = 0;
70 for (
int nPoint = 0; nPoint <
m_VCoast[nCoast].nGetCoastlineSize(); nPoint++)
73 if (
m_VCoast[nCoast].bIsProfileAtCoastPoint(nPoint))
83 m_VCoast[nCoast].SetCoastDeepWaterWaveHeight(nPoint, dThisDeepWaterWaveHeight);
84 m_VCoast[nCoast].SetCoastDeepWaterWaveAngle(nPoint, dThisDeepWaterWaveAngle);
85 m_VCoast[nCoast].SetCoastDeepWaterWavePeriod(nPoint, dThisDeepWaterWavePeriod);
88 nDistFromPrevProfile = 0;
89 dPrevProfileDeepWaterWaveHeight = dThisDeepWaterWaveHeight;
90 dPrevProfileDeepWaterWaveAngle = dThisDeepWaterWaveAngle;
91 dPrevProfileDeepWaterWavePeriod = dThisDeepWaterWavePeriod;
96 if (pNextProfile == NULL)
104 dDist = nDistToNextProfile;
116 nDistFromPrevProfile++;
117 nDistToNextProfile--;
119 double const dPrevWeight = (dDist - nDistFromPrevProfile) / dDist;
120 double const dNextWeight = (dDist - nDistToNextProfile) / dDist;
121 double const dThisDeepWaterWaveHeight = (dPrevWeight * dPrevProfileDeepWaterWaveHeight) + (dNextWeight * dNextProfileDeepWaterWaveHeight);
122 double const dThisDeepWaterWaveAngle =
dKeepWithin360((dPrevWeight * dPrevProfileDeepWaterWaveAngle) + (dNextWeight * dNextProfileDeepWaterWaveAngle));
123 double const dThisDeepWaterWavePeriod = (dPrevWeight * dPrevProfileDeepWaterWavePeriod) + (dNextWeight * dNextProfileDeepWaterWavePeriod);
125 m_VCoast[nCoast].SetCoastDeepWaterWaveHeight(nPoint, dThisDeepWaterWaveHeight);
126 m_VCoast[nCoast].SetCoastDeepWaterWaveAngle(nPoint, dThisDeepWaterWaveAngle);
127 m_VCoast[nCoast].SetCoastDeepWaterWavePeriod(nPoint, dThisDeepWaterWavePeriod);
146 *pVAllTransects = *pVRealTransects;
152 int const nNumRealTransects =
static_cast<int>(pVRealTransects->size());
153 if (nNumRealTransects < 2)
160 vector<double> VdTransectExtX(nNumRealTransects);
161 vector<double> VdTransectExtY(nNumRealTransects);
163 for (
int i = 0; i < nNumRealTransects; i++)
165 TransectWaveData
const& transect = (*pVRealTransects)[i];
166 if (!transect.VdX.empty())
173 VdTransectExtX[i] = 0.0;
174 VdTransectExtY[i] = 0.0;
179 vector<int> VnNumSyntheticsPerPair(nNumRealTransects - 1, 0);
180 int nTotalSynthetic = 0;
182 for (
int nPair = 0; nPair < nNumRealTransects - 1; nPair++)
184 TransectWaveData
const& transect1 = (*pVRealTransects)[nPair];
185 TransectWaveData
const& transect2 = (*pVRealTransects)[nPair + 1];
188 if (transect1.nCoastID != transect2.nCoastID)
192 if (transect1.VdX.empty() || transect2.VdX.empty())
196 double const dX1 = VdTransectExtX[nPair];
197 double const dY1 = VdTransectExtY[nPair];
198 double const dX2 = VdTransectExtX[nPair + 1];
199 double const dY2 = VdTransectExtY[nPair + 1];
202 double const dDX = dX2 - dX1;
203 double const dDY = dY2 - dY1;
204 double const dDistance = sqrt(dDX * dDX + dDY * dDY);
208 int nNumSynthetics = 0;
213 nNumSynthetics = std::max(0, nNumSynthetics - 1);
216 VnNumSyntheticsPerPair[nPair] = nNumSynthetics;
217 nTotalSynthetic += nNumSynthetics;
220 if (nTotalSynthetic <= 0)
227 vector<TransectWaveData> VSyntheticTransects(nTotalSynthetic);
233 #pragma omp parallel for schedule(dynamic)
234 for (
int nPair = 0; nPair < nNumRealTransects - 1; nPair++)
236 int const nNumSynthetics = VnNumSyntheticsPerPair[nPair];
237 if (nNumSynthetics == 0)
240 TransectWaveData
const& transect1 = (*pVRealTransects)[nPair];
241 TransectWaveData
const& transect2 = (*pVRealTransects)[nPair + 1];
244 int nPairStartIndex = 0;
245 for (
int i = 0; i < nPair; i++)
246 nPairStartIndex += VnNumSyntheticsPerPair[i];
249 for (
int nSynth = 1; nSynth <= nNumSynthetics; nSynth++)
251 int const nSynthIndex = nPairStartIndex + (nSynth - 1);
252 TransectWaveData& synthTransect = VSyntheticTransects[nSynthIndex];
255 double const dAlpha =
static_cast<double>(nSynth) / (nNumSynthetics + 1);
256 double const dOneMinusAlpha = 1.0 - dAlpha;
259 synthTransect.nCoastID = transect1.nCoastID;
260 synthTransect.nProfileID = -1;
261 synthTransect.bIsGridEdge =
false;
264 size_t const nMinLength = std::min(transect1.VdX.size(), transect2.VdX.size());
267 synthTransect.VdX.reserve(nMinLength);
268 synthTransect.VdY.reserve(nMinLength);
269 synthTransect.VdHeightX.reserve(nMinLength);
270 synthTransect.VdHeightY.reserve(nMinLength);
271 synthTransect.VbBreaking.reserve(nMinLength);
274 for (
size_t i = 0; i < nMinLength; i++)
277 synthTransect.VdX.push_back(dOneMinusAlpha * transect1.VdX[i] + dAlpha * transect2.VdX[i]);
278 synthTransect.VdY.push_back(dOneMinusAlpha * transect1.VdY[i] + dAlpha * transect2.VdY[i]);
281 synthTransect.VdHeightX.push_back(dOneMinusAlpha * transect1.VdHeightX[i] + dAlpha * transect2.VdHeightX[i]);
282 synthTransect.VdHeightY.push_back(dOneMinusAlpha * transect1.VdHeightY[i] + dAlpha * transect2.VdHeightY[i]);
285 synthTransect.VbBreaking.push_back(transect1.VbBreaking[i] || transect2.VbBreaking[i]);
291 pVAllTransects->insert(pVAllTransects->end(), VSyntheticTransects.begin(), VSyntheticTransects.end());
302 vector<TransectWaveData> VAllTransects;
308 vector<bool> VbBreakingAll;
310 vector<double> VdXAll;
311 vector<double> VdYAll;
312 vector<double> VdHeightXAll;
313 vector<double> VdHeightYAll;
316 bool bSomeNonStartOrEndOfCoastProfiles =
false;
318 for (
int nCoast = 0; nCoast < static_cast<int>(
m_VCoast.size()); nCoast++)
320 int const nCoastSize =
m_VCoast[nCoast].nGetCoastlineSize();
321 int const nNumProfiles =
m_VCoast[nCoast].nGetNumProfiles();
323 static bool bDownCoast =
true;
326 for (
int nn = 0; nn < nNumProfiles; nn++)
328 TransectWaveData transect;
333 pProfile =
m_VCoast[nCoast].pGetProfileWithDownCoastSeq(nn);
335 pProfile =
m_VCoast[nCoast].pGetProfileWithUpCoastSeq(nn);
337 int const nRet =
nCalcWavePropertiesOnProfile(nCoast, nCoastSize, pProfile, &transect.VdX, &transect.VdY, &transect.VdHeightX, &transect.VdHeightY, &transect.VbBreaking);
357 if (transect.VbBreaking.empty())
364 bSomeNonStartOrEndOfCoastProfiles =
true;
368 transect.nCoastID = nCoast;
373 VAllTransects.push_back(std::move(transect));
376 bDownCoast = ! bDownCoast;
380 if (! bSomeNonStartOrEndOfCoastProfiles)
382 LogStream <<
m_ulIter <<
":\t waves are on-shore only, for start and/or end of coast profiles" << endl;
389 vector<double> VdDeepWaterX;
390 vector<double> VdDeepWaterY;
391 vector<double> VdDeepWaterHeightX;
392 vector<double> VdDeepWaterHeightY;
394 double dDeepWaterWaveX;
395 double dDeepWaterWaveY;
408 int const nPolyID =
m_pRasterGrid->m_Cell[nX][0].nGetPolygonID();
413 VdDeepWaterX.push_back(nX);
414 VdDeepWaterY.push_back(0);
419 dDeepWaterWaveX =
m_pRasterGrid->m_Cell[nX][0].dGetCellDeepWaterWaveHeight() * sin(
m_pRasterGrid->m_Cell[nX][0].dGetCellDeepWaterWaveAngle() *
PI / 180);
420 dDeepWaterWaveY =
m_pRasterGrid->m_Cell[nX][0].dGetCellDeepWaterWaveHeight() * cos(
m_pRasterGrid->m_Cell[nX][0].dGetCellDeepWaterWaveAngle() *
PI / 180);
423 VdDeepWaterHeightX.push_back(dDeepWaterWaveX);
424 VdDeepWaterHeightY.push_back(dDeepWaterWaveY);
435 VdDeepWaterX.push_back(nX);
445 VdDeepWaterHeightX.push_back(dDeepWaterWaveX);
446 VdDeepWaterHeightY.push_back(dDeepWaterWaveY);
459 int const nPolyID =
m_pRasterGrid->m_Cell[0][nY].nGetPolygonID();
464 VdDeepWaterX.push_back(0);
465 VdDeepWaterY.push_back(nY);
470 dDeepWaterWaveX =
m_pRasterGrid->m_Cell[0][nY].dGetCellDeepWaterWaveHeight() * sin(
m_pRasterGrid->m_Cell[0][nY].dGetCellDeepWaterWaveAngle() *
PI / 180);
471 dDeepWaterWaveY =
m_pRasterGrid->m_Cell[0][nY].dGetCellDeepWaterWaveHeight() * cos(
m_pRasterGrid->m_Cell[0][nY].dGetCellDeepWaterWaveAngle() *
PI / 180);
474 VdDeepWaterHeightX.push_back(dDeepWaterWaveX);
475 VdDeepWaterHeightY.push_back(dDeepWaterWaveY);
487 VdDeepWaterY.push_back(nY);
496 VdDeepWaterHeightX.push_back(dDeepWaterWaveX);
497 VdDeepWaterHeightY.push_back(dDeepWaterWaveY);
504 bool bHasBreakingWaves =
false;
505 for (
const auto& transect : VAllTransects)
507 if (!transect.VbBreaking.empty())
509 bHasBreakingWaves =
true;
514 if (!bHasBreakingWaves)
521 vector<TransectWaveData> VAllTransectsWithSynthetic;
670 for (
int nCoast = 0; nCoast < static_cast<int>(
m_VCoast.size()); nCoast++)
672 int const nNumProfiles =
m_VCoast[nCoast].nGetNumProfiles();
674 for (
int nProfile = 0; nProfile < nNumProfiles; nProfile++)
743 for (
int nCoast = 0; nCoast < static_cast<int>(
m_VCoast.size()); nCoast++)
745 int const nCoastSize =
m_VCoast[nCoast].nGetCoastlineSize();
746 int const nNumProfiles =
m_VCoast[nCoast].nGetNumProfiles();
749 for (
int n = 0; n < nNumProfiles - 1; n++)
756 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
759 double const dBreakingWaveHeight =
m_VCoast[nCoast].dGetBreakingWaveHeight(nCoastPoint);
760 double const dCoastPointWavePeriod =
m_VCoast[nCoast].dGetCoastDeepWaterWavePeriod(nCoastPoint);
765 m_VCoast[nCoast].SetBreakingWaveHeight(nCoastPoint, 0);
773 double const dWaveEnergy = dErosiveWaveForce *
m_dTimeStep * 3600;
774 m_VCoast[nCoast].SetWaveEnergyAtBreaking(nCoastPoint, dWaveEnergy);
787 double dWaveToNormalAngle = 0;
791 dWaveToNormalAngle = fmod((dWaveAngle - dCoastAngle + 360), 360) - 90;
795 dWaveToNormalAngle = fmod((dWaveAngle - dCoastAngle + 360), 360) - 270;
797 if ((dWaveToNormalAngle >= 90) || (dWaveToNormalAngle <= -90))
800 return dWaveToNormalAngle;
823 int const nSeaHand =
m_VCoast[nCoast].nGetSeaHandedness();
827 double const dFluxOrientationThis =
m_VCoast[nCoast].dGetFluxOrientation(nCoastPoint);
828 double dFluxOrientationPrev = 0;
829 double dFluxOrientationNext = 0;
831 if (nCoastPoint == 0)
833 dFluxOrientationPrev = dFluxOrientationThis;
834 dFluxOrientationNext =
m_VCoast[nCoast].dGetFluxOrientation(1);
836 else if (nCoastPoint == nCoastSize - 1)
838 dFluxOrientationPrev =
m_VCoast[nCoast].dGetFluxOrientation(nCoastPoint - 2);
839 dFluxOrientationNext = dFluxOrientationThis;
843 dFluxOrientationPrev =
m_VCoast[nCoast].dGetFluxOrientation(nCoastPoint - 1);
844 dFluxOrientationNext =
m_VCoast[nCoast].dGetFluxOrientation(nCoastPoint + 1);
865 double dWaveToNormalAnglePrev;
870 double const dPrevDeepWaterWaveAngle =
m_VCoast[nCoast].dGetCoastDeepWaterWaveAngle(nCoastPoint - 1);
876 dWaveToNormalAnglePrev = dWaveToNormalAngle;
885 double dWaveToNormalAngleNext;
887 if (nCoastPoint < nCoastSize - 1)
890 double const dNextDeepWaterWaveAngle =
m_VCoast[nCoast].dGetCoastDeepWaterWaveAngle(nCoastPoint + 1);
896 dWaveToNormalAngleNext = dWaveToNormalAngle;
907 if (dWaveToNormalAngle > 45)
909 if (dWaveToNormalAnglePrev < 45)
911 dWaveToNormalAngle = 45;
916 dWaveToNormalAngle = dWaveToNormalAnglePrev;
923 if (dWaveToNormalAngle < -45)
925 if (dWaveToNormalAngleNext > -45)
927 dWaveToNormalAngle = -45;
932 dWaveToNormalAngle = dWaveToNormalAngleNext;
942 dWaveToNormalAngle = dFluxOrientationPrev;
949 dWaveToNormalAngle = dFluxOrientationNext;
953 bool bBreaking =
false;
956 int nProfileBreakingDist = 0;
958 double dProfileBreakingWaveHeight =
DBL_NODATA;
959 double dProfileBreakingWaveAngle = 0;
960 double dProfileBreakingDepth = 0;
966 vector<bool> VbWaveIsBreaking(nProfileSize, 0);
968 vector<double> VdWaveHeight(nProfileSize, 0);
969 vector<double> VdWaveSetupSurge(nProfileSize, 0);
971 vector<double>
const VdWaveSetupRunUp(nProfileSize, 0);
972 vector<double> VdWaveDirection(nProfileSize, 0);
977 double const dCShoreTimeStep = 3600;
981 vector<double> VdProfileZ;
982 vector<double> VdProfileDistXY;
983 vector<double> VdProfileFrictionFactor;
991 LogStream <<
m_ulIter <<
": \tcoast " << nCoast <<
" could not create CShore profile elevation vectors for profile " << pProfile->
nGetProfileID() << endl;
1000 if (VdProfileDistXY.empty())
1003 LogStream <<
m_ulIter <<
": \tcoast " << nCoast <<
" could not populate CShore profile elevation vector for profile " << pProfile->
nGetProfileID() << endl;
1009 dWaveToNormalAngle =
tMax(dWaveToNormalAngle, -80.0);
1010 dWaveToNormalAngle =
tMin(dWaveToNormalAngle, 80.0);
1012 int const nProfileDistXYSize =
static_cast<int>(VdProfileDistXY.size());
1013 vector<double> VdFreeSurfaceStd(nProfileDistXYSize, 0);
1014 vector<double> VdSinWaveAngleRadians(nProfileDistXYSize, 0);
1015 vector<double> VdFractionBreakingWaves(nProfileDistXYSize, 0);
1018 int const nILine = 1;
1019 int const nIProfl = 0;
1020 int const nIPerm = 0;
1021 int const nIOver = 0;
1022 int const nIWCInt = 0;
1023 int const nIRoll = 0;
1024 int const nIWind = 0;
1025 int const nITide = 0;
1026 int const nILab = 0;
1027 int const nNWave = 1;
1028 int const nNSurge = 1;
1029 double const dDX = VdProfileDistXY.back() / (
static_cast<double>(VdProfileDistXY.size() - 1));
1030 double const dWaveInitTime = 0;
1031 double const dSurgeInitTime = 0;
1033#if defined CSHORE_FILE_INOUT || CSHORE_BOTH
1042#if defined CSHORE_FILE_INOUT
1044 nRet =
nCreateCShoreInfile(nCoast, nProfile, nILine, nIProfl, nIPerm, nIOver, nIWCInt, nIRoll, nIWind, nITide, nILab, nNWave, nNSurge, dDX, dCShoreTimeStep, dWaveInitTime, dDeepWaterWavePeriod, dProfileDeepWaterWaveHeight, dWaveToNormalAngle, dSurgeInitTime, dSurgeLevel, &VdProfileDistXY, &VdProfileZ, &VdProfileFrictionFactor);
1059 string strErr = to_string(
m_ulIter) +
": \tcoast " + to_string(nCoast) +
" profile " + to_string(pProfile->
nGetProfileID()) +
" profile length " + to_string(nOutSize) +
" ";
1064 strErr +=
"CShore WARNING 1: negative depth at the first node";
1068 strErr +=
"CShore WARNING 2: negative value at end of landward marching computation";
1072 strErr +=
"CShore WARNING 3: large energy gradients at the first node: small waves with short period at sea boundary";
1076 strErr +=
"CShore WARNING 4: zero energy at the first node";
1080 strErr +=
"CShore WARNING 5: at end of landward marching computation, insufficient water depth";
1084 strErr +=
"CShore WARNING 7: did not reach convergence";
1097 string strOSETUP =
"OSETUP";
1098 string strOYVELO =
"OYVELO";
1099 string strOPARAM =
"OPARAM";
1101 nRet =
nReadCShoreOutput(nProfile, &strOSETUP, 4, 4, &VdProfileDistXY, &VdFreeSurfaceStd);
1106 nRet =
nReadCShoreOutput(nProfile, &strOYVELO, 4, 2, &VdProfileDistXY, &VdSinWaveAngleRadians);
1111 nRet =
nReadCShoreOutput(nProfile, &strOPARAM, 4, 3, &VdProfileDistXY, &VdFractionBreakingWaves);
1122 nRet = system(
"./clean.bat");
1127 string strCommand =
"./save_CShore_output.sh ";
1130 strCommand += to_string(nCoast);
1132 strCommand += to_string(nProfile);
1134 nRet = system(strCommand.c_str());
1140 nRet = system(
"./clean.sh");
1154#if defined CSHORE_ARG_INOUT || CSHORE_BOTH
1161 vector<double> VdInitTime = {dWaveInitTime, dCShoreTimeStep};
1162 vector<double> VdTPIn = {dDeepWaterWavePeriod, dDeepWaterWavePeriod};
1163 vector<double> VdHrmsIn = {dProfileDeepWaterWaveHeight, dProfileDeepWaterWaveHeight};
1164 vector<double> VdWangIn = {dWaveToNormalAngle, dWaveToNormalAngle};
1165 vector<double> VdTSurg = {dSurgeInitTime, dCShoreTimeStep};
1166 vector<double> VdSWLin = {dSurgeLevel, dSurgeLevel};
1167 vector<double> VdFPInp = VdProfileFrictionFactor;
1198 &nProfileDistXYSize,
1199 &VdProfileDistXY[0],
1204 &VdXYDistFromCShoreOut[0],
1205 &VdFreeSurfaceStdOut[0],
1206 &VdWaveSetupSurgeOut[0],
1207 &VdSinWaveAngleRadiansOut[0],
1208 &VdFractionBreakingWavesOut[0]);
1215 LogStream <<
m_ulIter <<
": " <<
WARN <<
"for coast " << nCoast <<
" profile " << pProfile->
nGetProfileID() <<
", only " << nOutSize <<
" CShore output rows, abandoning this profile" << endl;
1234 string strErr = to_string(
m_ulIter) +
": \tcoast " + to_string(nCoast) +
" profile " + to_string(pProfile->
nGetProfileID()) +
" profile length " + to_string(nOutSize) +
" ";
1239 strErr +=
"CShore WARNING 1: negative depth at the first node";
1243 strErr +=
"CShore WARNING 2: negative value at end of landward marching computation";
1247 strErr +=
"CShore WARNING 3: large energy gradients at the first node: small waves with short period at sea boundary";
1251 strErr +=
"CShore WARNING 4: zero energy at the first node";
1255 strErr +=
"CShore WARNING 5: at end of landward marching computation, insufficient water depth";
1259 strErr +=
"CShore WARNING 7: did not reach convergence";
1271 InterpolateCShoreOutput(&VdProfileDistXY, nOutSize, nProfileSize, &VdXYDistFromCShoreOut, &VdFreeSurfaceStdOut, &VdWaveSetupSurgeOut, &VdSinWaveAngleRadiansOut, &VdFractionBreakingWavesOut, &VdFreeSurfaceStd, &VdWaveSetupSurge, &VdSinWaveAngleRadians, &VdFractionBreakingWaves);
1274#if defined CSHORE_BOTH
1279 string strCommand =
"./save_CShore_output.sh ";
1282 strCommand += to_string(nCoast);
1284 strCommand += to_string(nProfile);
1286 nRet = system(strCommand.c_str());
1303 for (
int nProfilePoint = (nProfileSize - 1); nProfilePoint >= 0; nProfilePoint--)
1309 if (nProfilePoint >
static_cast<int>(VdFreeSurfaceStd.size()) - 1)
1313 if (isnan(VdFreeSurfaceStd[nProfilePoint]))
1314 VdFreeSurfaceStd[nProfilePoint] = 0;
1316 VdWaveHeight[nProfilePoint] = sqrt(8) * VdFreeSurfaceStd[nProfilePoint];
1319 if (isnan(VdSinWaveAngleRadians[nProfilePoint]))
1321 VdSinWaveAngleRadians[nProfilePoint] = 0;
1322 VdWaveHeight[nProfilePoint] = 0;
1326 if (VdSinWaveAngleRadians[nProfilePoint] < -1)
1327 VdSinWaveAngleRadians[nProfilePoint] = -1;
1329 if (VdSinWaveAngleRadians[nProfilePoint] > 1)
1330 VdSinWaveAngleRadians[nProfilePoint] = 1;
1332 double const dAlpha = asin(VdSinWaveAngleRadians[nProfilePoint]) * (180 /
PI);
1335 VdWaveDirection[nProfilePoint] =
dKeepWithin360(dAlpha + 90 + dFluxOrientationThis);
1337 VdWaveDirection[nProfilePoint] =
dKeepWithin360(dAlpha + 270 + dFluxOrientationThis);
1340 if (isnan(VdFractionBreakingWaves[nProfilePoint]))
1342 VdFractionBreakingWaves[nProfilePoint] = 0;
1343 VdWaveHeight[nProfilePoint] = 0;
1351 dProfileBreakingWaveHeight = VdWaveHeight[nProfilePoint];
1352 dProfileBreakingWaveAngle = VdWaveDirection[nProfilePoint];
1353 dProfileBreakingDepth =
m_pRasterGrid->m_Cell[nX][nY].dGetSeaDepth();
1354 nProfileBreakingDist = nProfilePoint + 1;
1359 VbWaveIsBreaking[nProfilePoint] = bBreaking;
1362 if (dProfileBreakingWaveHeight >= dProfileDeepWaterWaveHeight)
1371 for (
int nProfilePoint = (nProfileSize - 1); nProfilePoint >= 0; nProfilePoint--)
1380 double const dSeaDepth =
m_pRasterGrid->m_Cell[nX][nY].dGetSeaDepth();
1382 if (dSeaDepth > dDepthLookupMax)
1385 dProfileWaveHeight = dProfileDeepWaterWaveHeight;
1386 dProfileWaveAngle = dProfileDeepWaterWaveAngle;
1393 double const dL =
m_dL_0 * sqrt(tanh((2 *
PI * dSeaDepth) /
m_dL_0));
1394 double const dC =
m_dC_0 * tanh((2 *
PI * dSeaDepth) / dL);
1395 double const dk = 2 *
PI / dL;
1396 double const dn = ((2 * dSeaDepth * dk) / (sinh(2 * dSeaDepth * dk)) + 1) / 2;
1397 double const dKs = sqrt(
m_dC_0 / (dn * dC * 2));
1398 double const dAlpha = (180 /
PI) * asin((dC /
m_dC_0) * sin((
PI / 180) * dWaveToNormalAngle));
1399 double const dKr = sqrt(cos((
PI / 180) * dWaveToNormalAngle) / cos((
PI / 180) * dAlpha));
1400 dProfileWaveHeight = dProfileDeepWaterWaveHeight * dKs * dKr;
1403 dProfileWaveAngle =
dKeepWithin360(dAlpha + 90 + dFluxOrientationThis);
1406 dProfileWaveAngle =
dKeepWithin360(dAlpha + 270 + dFluxOrientationThis);
1411 dProfileBreakingWaveHeight = dProfileWaveHeight;
1412 dProfileBreakingWaveAngle = dProfileWaveAngle;
1421 dProfileWaveAngle = dProfileBreakingWaveAngle;
1423 dProfileWaveHeight = dProfileBreakingWaveHeight * (nProfilePoint / nProfileBreakingDist);
1425 dProfileBreakingDepth = dSeaDepth;
1426 nProfileBreakingDist = nProfilePoint;
1431 VdWaveDirection[nProfilePoint] = dProfileWaveAngle;
1432 VdWaveHeight[nProfilePoint] = dProfileWaveHeight;
1433 VbWaveIsBreaking[nProfilePoint] = bBreaking;
1438 for (
int nProfilePoint = (nProfileSize - 1); nProfilePoint >= 0; nProfilePoint--)
1448 double const dWaveHeight = VdWaveHeight[nProfilePoint];
1449 double const dWaveAngle = VdWaveDirection[nProfilePoint];
1451 bBreaking = VbWaveIsBreaking[nProfilePoint];
1454 pVdX->push_back(nX);
1455 pVdY->push_back(nY);
1456 pVdHeightX->push_back(dWaveHeight * sin(dWaveAngle *
PI / 180));
1457 pVdHeightY->push_back(dWaveHeight * cos(dWaveAngle *
PI / 180));
1458 pVbBreaking->push_back(bBreaking);
1479 double const dDiffProfileDistXY = hypot(dXDist, dYDist);
1482 double const dtanBeta = tan(
tAbs(
m_pRasterGrid->m_Cell[nX1][nY1].dGetSeaDepth() -
m_pRasterGrid->m_Cell[nX][nY].dGetSeaDepth()) / dDiffProfileDistXY);
1485 int nValidPointsWaveHeight = 0;
1486 int nValidPointsWaveSetup = 0;
1488 for (
int nPoint = 0; nPoint < static_cast<int>(VdWaveHeight.size()); nPoint++)
1490 if (VdWaveHeight[nPoint] > 1e-4)
1491 nValidPointsWaveHeight += 1;
1496 nValidPointsWaveHeight -= 1;
1498 for (
int nPoint = 0; nPoint < static_cast<int>(VdWaveSetupSurge.size()); nPoint++)
1500 if (
tAbs(VdWaveSetupSurge[nPoint]) < 1)
1501 nValidPointsWaveSetup += 1;
1506 nValidPointsWaveSetup -= 1;
1508 double dWaveHeight = 0;
1512 dWaveHeight = VdWaveHeight[nValidPointsWaveHeight];
1520 dRunUp = 0.36 * pow(9.81, 0.5) * dtanBeta * pow(dWaveHeight, 0.5) * dDeepWaterWavePeriod;
1525 double const dS0 = 2 *
PI * dWaveHeight / (9.81 * dDeepWaterWavePeriod * dDeepWaterWavePeriod);
1526 dRunUp = 1.86 * dWaveHeight * pow(pow(dtanBeta / dS0, 0.5), 0.71);
1531 double const dS0 = 2 *
PI * dWaveHeight / (9.81 * dDeepWaterWavePeriod * dDeepWaterWavePeriod);
1532 dRunUp = 1.1 * ((0.35 * dtanBeta * pow((1.0 / dS0) * dWaveHeight * dWaveHeight, 0.5)) + (0.5 * pow((1.0 / dS0) * dWaveHeight * dWaveHeight * (0.563 * dtanBeta * dtanBeta + 0.004), 0.5)));
1542 if ((
tAbs(dRunUp) < 1e-4) || (isnan(dRunUp)))
1545 double dWaveSetupSurge = 0;
1549 dWaveSetupSurge = VdWaveSetupSurge[nValidPointsWaveSetup];
1551 if ((
tAbs(dWaveSetupSurge) < 1e-4) || (isnan(dWaveSetupSurge)))
1552 dWaveSetupSurge = 0;
1556 m_VCoast[nCoast].SetCoastWaveHeight(nCoastPoint, dWaveHeight);
1557 m_VCoast[nCoast].SetWaveSetupSurge(nCoastPoint, dWaveSetupSurge);
1558 m_VCoast[nCoast].SetRunUp(nCoastPoint, dRunUp);
1560 if (nProfileBreakingDist > 0)
1563 m_VCoast[nCoast].SetBreakingWaveHeight(nCoastPoint, dProfileBreakingWaveHeight);
1564 m_VCoast[nCoast].SetBreakingWaveAngle(nCoastPoint, dProfileBreakingWaveAngle);
1565 m_VCoast[nCoast].SetDepthOfBreaking(nCoastPoint, dProfileBreakingDepth);
1566 m_VCoast[nCoast].SetBreakingDistance(nCoastPoint, nProfileBreakingDist);
1585#if defined CSHORE_FILE_INOUT
1589int CSimulation::nCreateCShoreInfile(
int const nCoast,
int const nProfile,
int const nILine,
int const nIProfl,
int const nIPerm,
int const nIOver,
int const nIWcint,
int const nIRoll,
int const nIWind,
int const nITide,
int const nILab,
int const nWave,
int const nSurge,
double const dX,
double const dTimestep,
double const dWaveInitTime,
double const dWavePeriod,
double const dHrms,
double const dWaveAngle,
double const dSurgeInitTime,
double const dSurgeLevel, vector<double>
const *pVdXdist, vector<double>
const *pVdBottomElevation, vector<double>
const *pVdWaveFriction)
1592 ofstream CShoreOutStream;
1593 CShoreOutStream.open(
CSHORE_INFILE.c_str(), ios::out | ios::app);
1595 if (CShoreOutStream.fail())
1603 CShoreOutStream << 3 << endl;
1604 CShoreOutStream <<
"------------------------------------------------------------" << endl;
1605 CShoreOutStream <<
"CShore input file created by CoastalME for iteration " <<
m_ulIter <<
", coast " << nCoast <<
", profile " << nProfile << endl;
1606 CShoreOutStream <<
"------------------------------------------------------------" << endl;
1607 CShoreOutStream << nILine <<
" -> ILINE" << endl;
1608 CShoreOutStream << nIProfl <<
" -> IPROFL" << endl;
1609 CShoreOutStream << nIPerm <<
" -> IPERM" << endl;
1610 CShoreOutStream << nIOver <<
" -> IOVER" << endl;
1611 CShoreOutStream << nIWcint <<
" -> IWCINT" << endl;
1612 CShoreOutStream << nIRoll <<
" -> IROLL" << endl;
1613 CShoreOutStream << nIWind <<
" -> IWIND" << endl;
1614 CShoreOutStream << nITide <<
" -> ITIDE" << endl;
1615 CShoreOutStream << fixed;
1616 CShoreOutStream << setw(11) << setprecision(4) << dX <<
" -> DX" << endl;
1618 CShoreOutStream << setw(11) << nILab <<
" -> ILAB" << endl;
1619 CShoreOutStream << setw(11) << nWave <<
" -> NWAVE" << endl;
1620 CShoreOutStream << setw(11) << nSurge <<
" -> NSURGE" << endl;
1623 CShoreOutStream << setw(11) << setprecision(2) << dWaveInitTime;
1624 CShoreOutStream << setw(11) << setprecision(4) << dWavePeriod;
1625 CShoreOutStream << setw(11) << dHrms;
1626 CShoreOutStream << setw(11) << dWaveAngle << endl;
1629 CShoreOutStream << setw(11) << setprecision(2) << dTimestep;
1630 CShoreOutStream << setw(11) << setprecision(4) << dWavePeriod;
1631 CShoreOutStream << setw(11) << dHrms;
1632 CShoreOutStream << setw(11) << dWaveAngle << endl;
1635 CShoreOutStream << setw(11) << setprecision(2) << dSurgeInitTime;
1636 CShoreOutStream << setw(11) << setprecision(4) << dSurgeLevel << endl;
1639 CShoreOutStream << setw(11) << setprecision(2) << dTimestep;
1640 CShoreOutStream << setw(11) << setprecision(4) << dSurgeLevel << endl;
1643 CShoreOutStream << setw(8) << pVdXdist->size() <<
" -> NBINP" << endl;
1645 CShoreOutStream << fixed << setprecision(4);
1647 for (
unsigned int i = 0; i < pVdXdist->size(); i++)
1649 CShoreOutStream << setw(11) << pVdXdist->at(i) << setw(11) << pVdBottomElevation->at(i) << setw(11) << pVdWaveFriction->at(i) << endl;
1651 CShoreOutStream << endl;
1654 CShoreOutStream.close();
1665 bool bIsBehindIntervention =
false;
1672 double dProfileDistXY = 0;
1673 double dProfileFricFact;
1674 double dPrevDist = -1;
1676 for (
int i = nProfSize - 1; i >= 0; i--)
1682 if (i == nProfSize - 1)
1688 dProfileDistXY = dProfileDistXY + hypot(dXDist, dYDist);
1693 dProfileDistXY += 0.1;
1700 int const nTopLayer =
m_pRasterGrid->m_Cell[nX][nY].nGetTopNonZeroLayerAboveBasement();
1711 double const dTopElev =
m_pRasterGrid->m_Cell[nX][nY].dGetAllSedTopElevIncTalus() +
m_pRasterGrid->m_Cell[nX][nY].dGetInterventionHeight();
1719 VdVZ->push_back(0.1);
1727 VdVZ->push_back(VdProfileZ);
1733 VdVZ->push_back(VdProfileZ);
1737 VdDistXY->push_back(dProfileDistXY);
1740 double const dInterventionHeight =
m_pRasterGrid->m_Cell[nX][nY].dGetInterventionHeight();
1743 if (dInterventionHeight > 0 || bIsBehindIntervention)
1747 bIsBehindIntervention =
true;
1754 VdFricF->push_back(dProfileFricFact);
1757 dPrevDist = dProfileDistXY;
1763#if defined CSHORE_FILE_INOUT
1767int CSimulation::nReadCShoreOutput(
int const nProfile,
string const *strCShoreFilename,
int const nExpectedColumns,
int const nCShorecolumn, vector<double>
const *pVdProfileDistXYCME, vector<double> *pVdInterpolatedValues)
1771 InStream.open(strCShoreFilename->c_str(), ios::in);
1774 if (!InStream.is_open())
1777 LogStream <<
m_ulIter <<
": " <<
ERR <<
"for profile " << nProfile <<
", cannot open " << *strCShoreFilename <<
" for input" << endl;
1783 vector<double> VdXYDistCShore;
1784 vector<double> VdValuesCShore;
1788 int nExpectedRows = 0;
1791 while (getline(InStream, strLineIn))
1802 string strErr =
ERR +
"invalid integer for number of expected rows '" + VstrItems[1] +
"' in " + *strCShoreFilename +
"\n";
1810 nExpectedRows = stoi(VstrItems[1]);
1818 int nCols =
static_cast<int>(VstrItems.size());
1820 if (nCols != nExpectedColumns)
1823 LogStream <<
m_ulIter <<
": " <<
ERR <<
"for profile " << nProfile <<
", expected " << nExpectedColumns <<
" CShore output columns but read " << nCols <<
" columns from header section of file " << *strCShoreFilename << endl;
1829 VdXYDistCShore.push_back(strtod(VstrItems[0].c_str(), NULL));
1830 VdValuesCShore.push_back(strtod(VstrItems[nCShorecolumn - 1].c_str(), NULL));
1835 int nReadRows =
static_cast<int>(VdXYDistCShore.size());
1837 if (nReadRows != nExpectedRows)
1840 LogStream <<
m_ulIter <<
": " <<
ERR <<
"for profile " << nProfile <<
", expected " << nExpectedRows <<
" CShore output rows, but read " << nReadRows <<
" rows from file " << *strCShoreFilename << endl;
1849 LogStream <<
m_ulIter <<
": " <<
WARN <<
"for profile " << nProfile <<
", only " << nReadRows <<
" CShore output rows in file " << *strCShoreFilename << endl;
1852 VdXYDistCShore.push_back(VdXYDistCShore[0]);
1853 VdValuesCShore.push_back(VdValuesCShore[0]);
1860 vector<double> VdXYDistCShoreTmp(nReadRows, 0);
1862 for (
int i = 0; i < nReadRows; i++)
1863 VdXYDistCShoreTmp[i] = VdXYDistCShore[nReadRows - 1] - VdXYDistCShore[i];
1866 reverse(VdXYDistCShoreTmp.begin(), VdXYDistCShoreTmp.end());
1869 reverse(VdValuesCShore.begin(), VdValuesCShore.end());
1872 vector<double> VdDistXYCopy(pVdProfileDistXYCME->begin(), pVdProfileDistXYCME->end());
1881#if defined CSHORE_ARG_INOUT || CSHORE_BOTH
1885void CSimulation::InterpolateCShoreOutput(vector<double>
const *pVdProfileDistXYCME,
int const nOutSize,
int const nProfileSize, vector<double> *pVdXYDistFromCShore, vector<double> *pVdFreeSurfaceStdCShore, vector<double> *pVdWaveSetupSurgeCShore, vector<double> *pVdSinWaveAngleRadiansCShore, vector<double> *pVdFractionBreakingWavesCShore, vector<double> *pVdFreeSurfaceStdCME, vector<double> *pVdWaveSetupSurgeCME, vector<double> *pVdSinWaveAngleRadiansCME, vector<double> *pVdFractionBreakingWavesCME)
1892 bool bTooShort =
false;
1895 if (nOutSize < nProfileSize)
1898 nTooShort = nProfileSize - nOutSize - 1;
1919 double dLastDiff = pVdXYDistFromCShore->at(nOutSize - 1) - pVdXYDistFromCShore->at(nOutSize - 2);
1921 for (
int n = 0; n < nTooShort; n++)
1922 pVdXYDistFromCShore->at(nOutSize + n) = pVdXYDistFromCShore->at(nOutSize - 1 + n) + dLastDiff;
1924 for (
int n = 0; n < nTooShort; n++)
1925 pVdFreeSurfaceStdCShore->at(nOutSize + n) = pVdFreeSurfaceStdCShore->at(nOutSize - 1);
1927 for (
int n = 0; n < nTooShort; n++)
1928 pVdWaveSetupSurgeCShore->at(nOutSize + n) = pVdWaveSetupSurgeCShore->at(nOutSize - 1);
1932 for (
int n = 0; n < nTooShort; n++)
1933 pVdSinWaveAngleRadiansCShore->at(nOutSize + n) = pVdSinWaveAngleRadiansCShore->at(nOutSize - 1);
1935 dLastDiff = pVdFractionBreakingWavesCShore->at(nOutSize - 1) - pVdFractionBreakingWavesCShore->at(nOutSize - 2);
1937 for (
int n = 0; n < nTooShort; n++)
1938 pVdFractionBreakingWavesCShore->at(nOutSize + n) =
tMin(pVdFractionBreakingWavesCShore->at(nOutSize - 1 + n) + dLastDiff, 1.0);
1949 vector<double> VdXYDistCShoreTmp(nProfileSize);
1950 copy(pVdXYDistFromCShore->begin(), pVdXYDistFromCShore->begin() + nProfileSize, begin(VdXYDistCShoreTmp));
1953 vector<double> VdFreeSurfaceStdCShoreTmp(nProfileSize);
1954 reverse_copy(pVdFreeSurfaceStdCShore->begin(), pVdFreeSurfaceStdCShore->begin() + nProfileSize, begin(VdFreeSurfaceStdCShoreTmp));
1956 vector<double> VdWaveSetupSurgeCShoreTmp(nProfileSize);
1957 reverse_copy(pVdWaveSetupSurgeCShore->begin(), pVdWaveSetupSurgeCShore->begin() + nProfileSize, begin(VdWaveSetupSurgeCShoreTmp));
1959 vector<double> VdSinWaveAngleRadiansCShoreTmp(nProfileSize);
1960 reverse_copy(pVdSinWaveAngleRadiansCShore->begin(), pVdSinWaveAngleRadiansCShore->begin() + nProfileSize, begin(VdSinWaveAngleRadiansCShoreTmp));
1962 vector<double> VdFractionBreakingWavesCShoreTmp(nProfileSize);
1963 reverse_copy(pVdFractionBreakingWavesCShore->begin(), pVdFractionBreakingWavesCShore->begin() + nProfileSize, begin(VdFractionBreakingWavesCShoreTmp));
2000 bool bModfiedWaveHeightisBreaking =
false;
2001 bool bProfileIsinShadowZone =
false;
2004 int nThisBreakingDist =
m_VCoast[nCoast].nGetBreakingDistance(nThisCoastPoint);
2005 double dThisBreakingWaveHeight =
m_VCoast[nCoast].dGetBreakingWaveHeight(nThisCoastPoint);
2006 double dThisBreakingWaveAngle =
m_VCoast[nCoast].dGetBreakingWaveAngle(nThisCoastPoint);
2007 double dThisBreakingDepth =
m_VCoast[nCoast].dGetDepthOfBreaking(nThisCoastPoint);
2010 for (
int nProfilePoint = (nProfileSize - 1); nProfilePoint >= 0; nProfilePoint--)
2018 bProfileIsinShadowZone =
true;
2021 double const dWaveHeight =
m_pRasterGrid->m_Cell[nX][nY].dGetWaveHeight();
2027 bModfiedWaveHeightisBreaking =
true;
2030 dThisBreakingWaveAngle =
m_pRasterGrid->m_Cell[nX][nY].dGetWaveAngle();
2032 nThisBreakingDist = nProfilePoint;
2038 if (bProfileIsinShadowZone && bModfiedWaveHeightisBreaking)
2041 if (dThisBreakingWaveHeight > dThisBreakingDepth * 0.78)
2043 dThisBreakingWaveHeight = dThisBreakingDepth * 0.78;
2047 m_VCoast[nCoast].SetBreakingWaveHeight(nThisCoastPoint, dThisBreakingWaveHeight);
2048 m_VCoast[nCoast].SetBreakingWaveAngle(nThisCoastPoint, dThisBreakingWaveAngle);
2049 m_VCoast[nCoast].SetDepthOfBreaking(nThisCoastPoint, dThisBreakingDepth);
2050 m_VCoast[nCoast].SetBreakingDistance(nThisCoastPoint, nThisBreakingDist);
2055 else if (bProfileIsinShadowZone && (! bModfiedWaveHeightisBreaking))
2083 int const nThisBreakingDist =
m_VCoast[nCoast].nGetBreakingDistance(nThisCoastPoint);
2084 double const dThisBreakingWaveHeight =
m_VCoast[nCoast].dGetBreakingWaveHeight(nThisCoastPoint);
2085 double const dThisBreakingWaveAngle =
m_VCoast[nCoast].dGetBreakingWaveAngle(nThisCoastPoint);
2086 double const dThisBreakingDepth =
m_VCoast[nCoast].dGetDepthOfBreaking(nThisCoastPoint);
2087 double const dThisWaveSetupSurge =
m_VCoast[nCoast].dGetWaveSetupSurge(nThisCoastPoint);
2089 double const dThisRunUp =
m_VCoast[nCoast].dGetRunUp(nThisCoastPoint);
2106 pTmpProfile = pNextProfile;
2117 int const nDistBetween = nNextCoastPoint - nThisCoastPoint;
2120 if (nDistBetween <= 0)
2124 int const nNextBreakingDist =
m_VCoast[nCoast].nGetBreakingDistance(nNextCoastPoint);
2125 double const dNextBreakingWaveHeight =
m_VCoast[nCoast].dGetBreakingWaveHeight(nNextCoastPoint);
2126 double const dNextBreakingWaveAngle =
m_VCoast[nCoast].dGetBreakingWaveAngle(nNextCoastPoint);
2127 double const dNextBreakingDepth =
m_VCoast[nCoast].dGetDepthOfBreaking(nNextCoastPoint);
2128 double const dNextWaveSetupSurge =
m_VCoast[nCoast].dGetWaveSetupSurge(nNextCoastPoint);
2129 double const dNextRunUp =
m_VCoast[nCoast].dGetRunUp(nNextCoastPoint);
2132 for (
int n = nThisCoastPoint; n <= nNextCoastPoint; n++)
2135 int const nDist = n - nThisCoastPoint;
2136 double const dThisWeight = (nDistBetween - nDist) /
static_cast<double>(nDistBetween);
2137 double const dNextWeight = 1 - dThisWeight;
2138 double dWaveSetupSurge = 0;
2141 dWaveSetupSurge = (dThisWeight * dThisWaveSetupSurge) + (dNextWeight * dNextWaveSetupSurge);
2142 m_VCoast[nCoast].SetWaveSetupSurge(n, dWaveSetupSurge);
2144 dRunUp = (dThisWeight * dThisRunUp) + (dNextWeight * dNextRunUp);
2145 m_VCoast[nCoast].SetRunUp(n, dRunUp);
2157 for (
int n = nThisCoastPoint; n < nNextCoastPoint; n++)
2172 for (
int n = nThisCoastPoint; n < nNextCoastPoint; n++)
2176 m_VCoast[nCoast].SetBreakingWaveHeight(n, dNextBreakingWaveHeight);
2177 m_VCoast[nCoast].SetBreakingWaveAngle(n, dNextBreakingWaveAngle);
2178 m_VCoast[nCoast].SetDepthOfBreaking(n, dNextBreakingDepth);
2179 m_VCoast[nCoast].SetBreakingDistance(n, nNextBreakingDist);
2188 for (
int n = nThisCoastPoint + 1; n <= nNextCoastPoint; n++)
2192 m_VCoast[nCoast].SetBreakingWaveHeight(n, dThisBreakingWaveHeight);
2193 m_VCoast[nCoast].SetBreakingWaveAngle(n, dThisBreakingWaveAngle);
2194 m_VCoast[nCoast].SetDepthOfBreaking(n, dThisBreakingDepth);
2195 m_VCoast[nCoast].SetBreakingDistance(n, nThisBreakingDist);
2202 for (
int n = nThisCoastPoint + 1; n < nNextCoastPoint; n++)
2204 int const nDist = n - nThisCoastPoint;
2211 if ((dNextBreakingDepth > 0) && (dThisBreakingDepth > 0))
2213 double const dThisWeight = (nDistBetween - nDist) /
static_cast<double>(nDistBetween);
2214 double const dNextWeight = 1 - dThisWeight;
2216 dBreakingWaveHeight = (dThisWeight * dThisBreakingWaveHeight) + (dNextWeight * dNextBreakingWaveHeight),
2217 dBreakingWaveAngle = (dThisWeight * dThisBreakingWaveAngle) + (dNextWeight * dNextBreakingWaveAngle),
2218 dBreakingDepth = (dThisWeight * dThisBreakingDepth) + (dNextWeight * dNextBreakingDepth),
2219 dBreakingDist = (dThisWeight * nThisBreakingDist) + (dNextWeight * nNextBreakingDist);
2222 else if (dNextBreakingDepth > 0)
2224 dBreakingWaveHeight = dNextBreakingWaveHeight,
2225 dBreakingWaveAngle = dNextBreakingWaveAngle,
2226 dBreakingDepth = dNextBreakingDepth,
2227 dBreakingDist = nNextBreakingDist;
2230 else if (dThisBreakingDepth > 0)
2232 dBreakingWaveHeight = dThisBreakingWaveHeight,
2233 dBreakingWaveAngle = dThisBreakingWaveAngle,
2234 dBreakingDepth = dThisBreakingDepth,
2235 dBreakingDist = nThisBreakingDist;
2240 m_VCoast[nCoast].SetBreakingWaveHeight(n, dBreakingWaveHeight);
2241 m_VCoast[nCoast].SetBreakingWaveAngle(n, dBreakingWaveAngle);
2242 m_VCoast[nCoast].SetDepthOfBreaking(n, dBreakingDepth);
2252 int const nCoastPoints =
m_VCoast[nCoast].nGetCoastlineSize();
2255 vector<int> nVCoastWaveHeightX;
2256 vector<double> dVCoastWaveHeightY;
2259 for (
int n = 0; n < nCoastPoints; n++)
2261 double const dCoastWaveHeight =
m_VCoast[nCoast].dGetCoastWaveHeight(n);
2265 nVCoastWaveHeightX.push_back(n);
2266 dVCoastWaveHeightY.push_back(dCoastWaveHeight);
2271 if ((nVCoastWaveHeightX.size() >= 3) && (nVCoastWaveHeightX.size() == dVCoastWaveHeightY.size()))
2273 for (
int n = 0; n < nCoastPoints; n++)
2275 double const dInterpCoastWaveHeight =
dGetInterpolatedValue(&nVCoastWaveHeightX, &dVCoastWaveHeightY, n,
false);
2276 m_VCoast[nCoast].SetCoastWaveHeight(n, dInterpCoastWaveHeight);
2282 for (
int n = 0; n < nCoastPoints; n++)
2284 m_VCoast[nCoast].SetCoastWaveHeight(n, 0);
2294 int const nCoastSize =
m_VCoast[nCoast].nGetCoastlineSize();
2296 for (
int nCoastPoint = 0; nCoastPoint < nCoastSize; nCoastPoint++)
2301 if (nCoastPoint == 0)
2311 else if (nCoastPoint == nCoastSize - 1)
2337 m_VCoast[nCoast].SetFluxOrientation(nCoastPoint, 90);
2341 m_VCoast[nCoast].SetFluxOrientation(nCoastPoint, 270);
2349 m_VCoast[nCoast].SetFluxOrientation(nCoastPoint, 0);
2353 m_VCoast[nCoast].SetFluxOrientation(nCoastPoint, 180);
2359 double dAzimuthAngle;
2362 dAzimuthAngle = (180 /
PI) * (
PI * 0.5 - atan(dYDiff / dXDiff));
2365 dAzimuthAngle = (180 /
PI) * (
PI * 1.5 - atan(dYDiff / dXDiff));
2367 m_VCoast[nCoast].SetFluxOrientation(nCoastPoint, dAzimuthAngle);
2380 int nTotPolygonAllCoasts = 0;
2381 for (
int nCoast = 0; nCoast < static_cast<int>(
m_VCoast.size()); nCoast++)
2382 nTotPolygonAllCoasts +=
m_VCoast[nCoast].nGetNumPolygons();
2385 vector<int> VnPolygonD50Count(nTotPolygonAllCoasts, 0);
2386 vector<double> VdPolygonD50(nTotPolygonAllCoasts, 0);
2395 int const nPolyID =
m_pRasterGrid->m_Cell[nX][nY].nGetPolygonID();
2398 bool const bActive =
m_pRasterGrid->m_Cell[nX][nY].bIsInActiveZone();
2403 double const dTmpd50 =
m_pRasterGrid->m_Cell[nX][nY].dGetUnconsD50();
2410 VnPolygonD50Count[nPolyID]++;
2411 VdPolygonD50[nPolyID] += dTmpd50;
2436 int nDownDriftNum = 0;
2439 double dWaveHeight = 0;
2440 double dWaveAngle = 0;
2448 if (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].bIsInContiguousSea())
2451 dWaveHeight +=
m_pRasterGrid->m_Cell[nXTmp][nYTmp].dGetWaveHeight();
2452 dWaveAngle += (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].dGetWaveAngle());
2457 int nTmp =
m_pRasterGrid->m_Cell[nXTmp][nYTmp].nGetShadowZoneNumber();
2465 nTmp =
m_pRasterGrid->m_Cell[nXTmp][nYTmp].nGetDownDriftZoneNumber();
2470 nDownDriftNum = nTmp;
2484 if (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].bIsInContiguousSea())
2487 dWaveHeight +=
m_pRasterGrid->m_Cell[nXTmp][nYTmp].dGetWaveHeight();
2488 dWaveAngle += (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].dGetWaveAngle());
2493 int nTmp =
m_pRasterGrid->m_Cell[nXTmp][nYTmp].nGetShadowZoneNumber();
2501 nTmp =
m_pRasterGrid->m_Cell[nXTmp][nYTmp].nGetDownDriftZoneNumber();
2506 nDownDriftNum = nTmp;
2520 if (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].bIsInContiguousSea())
2523 dWaveHeight +=
m_pRasterGrid->m_Cell[nXTmp][nYTmp].dGetWaveHeight();
2524 dWaveAngle += (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].dGetWaveAngle());
2529 int nTmp =
m_pRasterGrid->m_Cell[nXTmp][nYTmp].nGetShadowZoneNumber();
2537 nTmp =
m_pRasterGrid->m_Cell[nXTmp][nYTmp].nGetDownDriftZoneNumber();
2542 nDownDriftNum = nTmp;
2556 if (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].bIsInContiguousSea())
2559 dWaveHeight +=
m_pRasterGrid->m_Cell[nXTmp][nYTmp].dGetWaveHeight();
2560 dWaveAngle += (
m_pRasterGrid->m_Cell[nXTmp][nYTmp].dGetWaveAngle());
2565 int nTmp =
m_pRasterGrid->m_Cell[nXTmp][nYTmp].nGetShadowZoneNumber();
2573 nTmp =
m_pRasterGrid->m_Cell[nXTmp][nYTmp].nGetDownDriftZoneNumber();
2578 nDownDriftNum = nTmp;
2589 dWaveHeight /= nRead;
2590 dWaveAngle /= nRead;
2602 double const dDeepWaterWaveHeight =
m_pRasterGrid->m_Cell[nX][nY].dGetCellDeepWaterWaveHeight();
2610 double const dDeepWaterWaveAngle =
m_pRasterGrid->m_Cell[nX][nY].dGetCellDeepWaterWaveAngle();
2618 int const nShadowZoneCode =
m_pRasterGrid->m_Cell[nX][nY].nGetShadowZoneNumber();
2620 if (nShadowZoneCode <= 0)
2623 if ((nShadow == 4) || (nShadow + nDownDrift == 4) || (nShadow + nCoast == 4))
2625 m_pRasterGrid->m_Cell[nX][nY].SetShadowZoneNumber(nShadowNum);
2632 int const nDownDriftZoneCode =
m_pRasterGrid->m_Cell[nX][nY].nGetDownDriftZoneNumber();
2634 if ((nDownDriftZoneCode == 0) && (nDownDrift == 4))
2636 m_pRasterGrid->m_Cell[nX][nY].SetDownDriftZoneNumber(nDownDriftNum);
2646 for (
int nCoast = 0; nCoast < static_cast<int>(
m_VCoast.size()); nCoast++)
2648 for (
int nPoly = 0; nPoly <
m_VCoast[nCoast].nGetNumPolygons(); nPoly++)
2653 if (VnPolygonD50Count[nPolyID] > 0)
2654 VdPolygonD50[nPolyID] /= VnPolygonD50Count[nPolyID];
Contains CGeom2DPoint definitions.
int nGetY(void) const
Returns the CGeom2DIPoint object's integer Y coordinate.
int nGetX(void) const
Returns the CGeom2DIPoint object's integer X coordinate.
Geometry class used to represent 2D point objects with floating-point coordinates.
double dGetY(void) const
Returns the CGeom2DPoint object's double Y coordinate.
double dGetX(void) const
Returns the CGeom2DPoint object's double X coordinate.
Geometry class used for coast polygon objects.
int nGetPolygonCoastID(void) const
Get the coast ID, this is the same as the down-coast sequence of polygons.
void SetAvgUnconsD50(double const)
Set the average d50 for unconsolidated sediment on this polygon.
Geometry class used to represent coast profile objects.
double dGetProfileDeepWaterWaveAngle(void) const
Returns the deep-water wave orientation for this profile.
double dGetProfileDeepWaterWaveHeight(void) const
Returns the deep-water wave height for this profile.
int nGetProfileID(void) const
Returns the profile's this-coast ID.
int nGetCoastPoint(void) const
Returns the coast point at which the profile starts.
CGeomProfile * pGetDownCoastAdjacentProfile(void) const
Returns the down-coast adjacent profile, returns NULL if there is no down-coast adjacent profile.
CGeom2DIPoint * pPtiGetCellInProfile(int const)
Returns a single cell (grid CRS) in the profile.
bool bIsGridEdge(void) const
Returns true if this is a start-of-coast or an end-of-coast profile.
int nGetNumCellsInProfile(void) const
Returns the number of cells in the profile.
void SetCShoreProblem(bool const)
Sets a switch to indicate whether this profile has a CShore problem.
bool bOKIncStartAndEndOfCoast(void) const
Returns true if this is a problem-free profile (however it could be a start-of-coast or an end-of-coa...
vector< CGeom2DIPoint > * pPtiVGetCellsInProfile(void)
Returns all cells (grid CRS) in the profile.
bool bEndOfCoast(void) const
Returns the switch to indicate whether this is an end-of-coast profile.
double dGetProfileDeepWaterWavePeriod(void) const
Returns the deep-water wave period for this profile.
int m_nLogFileDetail
The level of detail in the log file output. Can be LOG_FILE_LOW_DETAIL, LOG_FILE_MIDDLE_DETAIL,...
double m_dAllCellsDeepWaterWaveHeight
Deep water wave height (m) for all sea cells.
double m_dSyntheticTransectSpacing
Approximate minimum spacing (m) between wave transects (real and synthetic) for wave interpolation de...
void InterpolateCShoreOutput(vector< double > const *, int const, int const, vector< double > *, vector< double > *, vector< double > *, vector< double > *, vector< double > *, vector< double > *, vector< double > *, vector< double > *, vector< double > *)
double m_dG
Gravitational acceleration (m**2/sec)
double m_dThisIterSWL
The still water level for this timestep (this includes tidal changes and any long-term SWL change)
CGeomRasterGrid * m_pRasterGrid
Pointer to the raster grid object.
int nCalcWavePropertiesOnProfile(int const, int const, CGeomProfile *, vector< double > *, vector< double > *, vector< double > *, vector< double > *, vector< bool > *)
Calculates wave properties along a coastline-normal profile using either the COVE linear wave theory ...
int m_nXGridSize
The size of the grid in the x direction.
double m_dL_0
Deep water wave length (m)
vector< CRWCoast > m_VCoast
The coastline objects.
bool m_bSingleDeepWaterWaveValues
Do we have just a point source for (i.e. only a single measurement of) deep water wave values.
vector< TransectWaveData > m_VAllTransectsWithSynthetic
Storage for wave transect points (real and synthetic) for debug output.
int m_nYGridSize
The size of the grid in the y direction.
int nDoAllShadowZones(void)
Finds wave shadow zones and modifies waves in and near them. Note that where up-coast and down-coast ...
static double dKeepWithin360(double const)
Constrains the supplied angle to be within 0 and 360 degrees.
void CalcCoastTangents(int const)
Calculates tangents to a coastline: the tangent is assumed to be the orientation of energy/sediment f...
double m_dWaveDepthRatioForWaveCalcs
Start depth for wave calculations.
int nCreateCShoreInfile(int const, int const, int const, int const, int const, int const, int const, int const, int const, int const, int const, int const, int const, double const, double const, double const, double const, double const, double const, double const, double const, vector< double > const *, vector< double > const *, vector< double > const *)
void InterpolateWavePropertiesBetweenProfiles(int const, int const)
Interpolates wave properties from profiles to the coastline points between two profiles....
int m_nRunUpEquation
The run-up equation used TODO 007 Finish surge and runup stuff.
double m_dBreakingWaveHeightDepthRatio
Breaking wave height-to-depth ratio.
int nReadCShoreOutput(int const, string const *, int const, int const, vector< double > const *, vector< double > *)
double dGridCentroidYToExtCRSY(int const) const
Given the integer Y-axis ordinate of a cell in the raster grid CRS, returns the external CRS Y-axis o...
void CalcD50AndFillWaveCalcHoles(void)
Calculates an average d50 for each polygon. Also fills in 'holes' in active zone and wave calcs i....
string m_strCMEDir
The CME folder.
vector< double > VdInterpolateCShoreProfileOutput(vector< double > const *, vector< double > const *, vector< double > const *)
Returns a linearly interpolated vector of doubles, to make CShore profile output compatible with CME....
int m_nWavePropagationModel
The wave propagation model used. Possible values are WAVE_MODEL_CSHORE and WAVE_MODEL_COVE.
double m_dAllCellsDeepWaterWaveAngle
Deep water wave angle for all sea cells.
void GenerateSyntheticTransects(vector< TransectWaveData > const *, vector< TransectWaveData > *)
int nInterpolateWavesToPolygonCells(vector< TransectWaveData > const *, vector< double > const *, vector< double > const *, vector< double > const *, vector< double > const *)
int nSetAllCoastpointDeepWaterWaveValues(void)
Give every coast point a value for deep water wave height and direction TODO 005 This may not be real...
double m_dTimeStep
The length of an iteration (a timestep) in hours.
int nGetThisProfileElevationsForCShore(int const, CGeomProfile *, int const, vector< double > *, vector< double > *, vector< double > *)
Get profile horizontal distance and bottom elevation vectors in CShore units.
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,...
void ModifyBreakingWavePropertiesWithinShadowZoneToCoastline(int const, int const)
Modifies the wave breaking properties at coastline points of profiles within the shadow zone.
double m_dC_0
Deep water wave speed (m/s)
unsigned long m_ulIter
The number of the current iteration (time step)
double dGridCentroidXToExtCRSX(int const) const
Given the integer X-axis ordinate of a cell in the raster grid CRS, returns the external CRS X-axis o...
double dGetInterpolatedValue(vector< double > const *, vector< double > const *, double, bool)
int nDoAllPropagateWaves(void)
Simulates wave propagation along all coastline-normal profiles, on all coasts.
double m_dDepthOfClosure
Depth of closure (in m) TODO 007 can be calculated using Hallermeier, R.J. (1978) or Birkemeier (1985...
void InterpolateWaveHeightToCoastPoints(int const)
Linearly interpolates wave properties from profiles to the coastline cells between two profiles.
static vector< string > * VstrSplit(string const *, char const, vector< string > *)
From http://stackoverflow.com/questions/236129/split-a-string-in-c They implement (approximately) Pyt...
static double dCalcWaveAngleToCoastNormal(double const, double const, int const)
Calculates the angle between the wave direction and a normal to the coastline tangent....
This file contains global definitions for CoastalME.
int const NO_NONZERO_THICKNESS_LAYERS
int const WAVE_MODEL_COVE
int const RTN_ERR_NO_TOP_LAYER
int const RTN_ERR_CSHORE_FILE_INPUT
int const RUNUP_EQUATION_NIELSEN_HANSLOW
double const CSHORE_FRICTION_FACTOR
int const WAVE_MODEL_CSHORE
int const RUNUP_EQUATION_MASE
int const LOG_FILE_MIDDLE_DETAIL
int const RTN_ERR_CSHORE_ERROR
bool bFPIsEqual(const T d1, const T d2, const T dEpsilon)
double const WALKDEN_HALL_PARAM_2
int const RTN_ERR_READING_CSHORE_FILE_OUTPUT
double const CSHORE_SURGE_LEVEL
bool const SAVE_CSHORE_OUTPUT
int const CSHOREARRAYOUTSIZE
The size of the arrays output by CShore. If this is changed, then must also set the same value on lin...
double const WALKDEN_HALL_PARAM_1
int const RTN_ERR_CSHORE_EMPTY_PROFILE
int const RUNUP_EQUATION_STOCKDON
string const CSHORE_INFILE
Contains CRWCoast definitions.
void CShoreWrapper(int const *, int const *, int const *, int const *, int const *, int const *, int const *, int const *, int const *, int const *, int const *, double const *, double const *, double[], double[], double[], double[], double[], double[], int const *, double[], double[], double[], int *, int *, double[], double[], double[], double[], double[])
Contains CSimulation definitions.
bool bIsStringValidInt(string &str)
Checks to see if a string can be read as a valid integer, from https://stackoverflow....
int nRound(double const d)
Correctly rounds doubles, returns an int.