// Copyright (C) Stichting Deltares 2018. All rights reserved.
//
// This file is part of the Dam Engine.
//
// The Dam Engine is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using System.Collections.Generic;
using System.Linq;
using Deltares.DamEngine.Calculators.RegionalAssessment.Evaluator;
using Deltares.DamEngine.Calculators.RegionalAssessment.HydraulicShortcut;
using Deltares.DamEngine.Data.General;
using Deltares.DamEngine.Data.RegionalAssessmentResults;
namespace Deltares.DamEngine.Calculators.DikesAssessmentRegional
{
///
/// Class to select all scenarios which have to be assessed in th regional assessment.
///
public class RegionalScenarioSelector
{
///
/// Gets or sets the type of the piping model.
///
///
/// The type of the piping model.
///
public PipingModelType PipingModelType { get; set; }
///
/// Gets or sets the m stab parameters.
///
///
/// The m stab parameters.
///
public MStabParameters MStabParameters { get; set; }
///
/// Gets the scenarios.
///
/// The location.
/// The soil geometry probability.
///
public RegionalScenarioProfileResult[] GetScenarios(Location location, SoilGeometryProbability soilGeometryProbability)
{
List scenarios = new List();
Evaluator[] evaluators = new Evaluator[]
{
new DikeMaterialEvaluator(),
new HydraulicShortcutEvaluator(),
new UpliftEvaluator()
};
Enum[] choices = new Enum[evaluators.Length + 1];
foreach (LoadSituation loadSituation in Enum.GetValues(typeof(LoadSituation)))
{
choices[0] = loadSituation;
bool resultsInScenarios = true;
for (int i = 1; i < evaluators.Length + 1; i++)
{
choices[i] = evaluators[i - 1].Evaluate(location, new SoilGeometry(soilGeometryProbability.SoilProfile1D, null), choices.ToArray());
//Is het een doorlopende tak? Zo niet break af (afbreken als geen veenkade en droge belastingsituatie
resultsInScenarios = WillChoicesResultInScenarios(choices.ToArray());
if (!resultsInScenarios)
{
break;
}
}
if (resultsInScenarios)
{
if (choices[0].Equals(LoadSituation.Wet))
{
if (choices[1].Equals(DikeDrySensitivity.None))
{
if (choices[2].Equals(HydraulicShortcutType.NoHydraulicShortcut))
{
if (choices[3].Equals(UpliftType.NoUplift))
{
scenarios.Add(GetScenario(ScenarioType.Scenario08, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.Bishop));
}
else // UpliftType.Uplift
{
scenarios.Add(GetScenario(ScenarioType.Scenario04, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.UpliftVan));
scenarios.Add(GetScenario(ScenarioType.Scenario08, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.Bishop));
scenarios.Add(GetScenario(ScenarioType.Scenario10, choices, location, soilGeometryProbability, FailureMechanismSystemType.Piping, PipingModelType));
}
}
else // HydraulicShortcutType.HydraulicShortcut
{
if (choices[3].Equals(UpliftType.NoUplift))
{
scenarios.Add(GetScenario(ScenarioType.Scenario07, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.Bishop));
}
else // UpliftType.Uplift
{
scenarios.Add(GetScenario(ScenarioType.Scenario03, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.UpliftVan));
scenarios.Add(GetScenario(ScenarioType.Scenario07, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.Bishop));
scenarios.Add(GetScenario(ScenarioType.Scenario10, choices, location, soilGeometryProbability, FailureMechanismSystemType.Piping, PipingModelType));
}
}
}
else // DikeDrySensitivity.Dry
{
if (choices[2].Equals(HydraulicShortcutType.NoHydraulicShortcut))
{
if (choices[3].Equals(UpliftType.NoUplift))
{
scenarios.Add(GetScenario(ScenarioType.Scenario08, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.Bishop));
}
else // UpliftType.Uplift
{
scenarios.Add(GetScenario(ScenarioType.Scenario04, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.UpliftVan));
scenarios.Add(GetScenario(ScenarioType.Scenario08, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.Bishop));
scenarios.Add(GetScenario(ScenarioType.Scenario10, choices, location, soilGeometryProbability, FailureMechanismSystemType.Piping, PipingModelType));
}
}
else // HydraulicShortcutType.HydraulicShortcut
{
if (choices[3].Equals(UpliftType.NoUplift))
{
scenarios.Add(GetScenario(ScenarioType.Scenario07, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.Bishop));
}
else // UpliftType.Uplift
{
scenarios.Add(GetScenario(ScenarioType.Scenario03, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.UpliftVan));
scenarios.Add(GetScenario(ScenarioType.Scenario07, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.Bishop));
scenarios.Add(GetScenario(ScenarioType.Scenario10, choices, location, soilGeometryProbability, FailureMechanismSystemType.Piping, PipingModelType));
}
}
}
}
else // LoadSituation.Dry
{
if (choices[1].Equals(DikeDrySensitivity.Dry))
{
if (choices[2].Equals(HydraulicShortcutType.NoHydraulicShortcut))
{
if (choices[3].Equals(UpliftType.NoUplift))
{
scenarios.Add(GetScenario(ScenarioType.Scenario06, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.Bishop));
}
else // UpliftType.Uplift
{
scenarios.Add(GetScenario(ScenarioType.Scenario02, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.UpliftVan));
scenarios.Add(GetScenario(ScenarioType.Scenario06, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.Bishop));
scenarios.Add(GetScenario(ScenarioType.Scenario09, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.HorizontalBalance));
scenarios.Add(GetScenario(ScenarioType.Scenario11, choices, location, soilGeometryProbability, FailureMechanismSystemType.Piping, PipingModelType));
}
}
else // HydraulicShortcutType.HydraulicShortcut
{
if (choices[3].Equals(UpliftType.NoUplift))
{
scenarios.Add(GetScenario(ScenarioType.Scenario05, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.Bishop));
}
else // UpliftType.Uplift
{
scenarios.Add(GetScenario(ScenarioType.Scenario01, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.UpliftVan));
scenarios.Add(GetScenario(ScenarioType.Scenario05, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.Bishop));
scenarios.Add(GetScenario(ScenarioType.Scenario09, choices, location, soilGeometryProbability, FailureMechanismSystemType.StabilityInside, MStabModelType.HorizontalBalance));
scenarios.Add(GetScenario(ScenarioType.Scenario11, choices, location, soilGeometryProbability, FailureMechanismSystemType.Piping, PipingModelType));
}
}
}
}
}
}
return scenarios.ToArray();
}
private RegionalScenarioProfileResult GetScenario(ScenarioType scenarioType, Enum[] choices, Location location,
SoilGeometryProbability soilGeometryProbability, FailureMechanismSystemType failureMechanismType, MStabModelType modelOption)
{
var scenario = new RegionalScenarioProfileResult(location, soilGeometryProbability)
{
FailureMechanismType = failureMechanismType,
MstabModelOption = modelOption,
PipingModelOption = PipingModelType,
LoadSituation = (LoadSituation) choices[0],
DikeDrySensitivity = (DikeDrySensitivity) choices[1],
HydraulicShortcutType = (HydraulicShortcutType) choices[2],
UpliftType = (UpliftType) choices[3],
ScenarioType = scenarioType
};
//if (scenario.IsDry)
//{
// // Soils are not transferred to the computational core at the moment, therefore this code has no meaning at the moment
// // You could say the same about soils in general in the DAM C# code
// SoilProfile1D drySoilProfile = soilProfile.Clone();
// foreach (Layer layer in drySoilProfile.Layers)
// {
// layer.Soil.AbovePhreaticLevel = layer.Soil.DryUnitWeight;
// }
//}
return scenario;
}
private RegionalScenarioProfileResult GetScenario(ScenarioType scenarioType, Enum[] choices, Location location,
SoilGeometryProbability soilGeometryProbability, FailureMechanismSystemType failureMechanismType, PipingModelType pipingModelType)
{
var scenario = new RegionalScenarioProfileResult(location, soilGeometryProbability)
{
FailureMechanismType = failureMechanismType,
MstabModelOption = MStabModelType.Bishop,
PipingModelOption = pipingModelType,
LoadSituation = (LoadSituation) choices[0],
DikeDrySensitivity = (DikeDrySensitivity) choices[1],
HydraulicShortcutType = (HydraulicShortcutType) choices[2],
UpliftType = (UpliftType) choices[3],
ScenarioType = scenarioType
};
//if (scenario.IsDry)
//{
// // Soils are not transferred to the computational core at the moment, therefore this code has no meaning at the moment
// // You could say the same about soils in general in the DAM C# code
// SoilProfile1D drySoilProfile = soilProfile.Clone();
// foreach (Layer layer in drySoilProfile.Layers)
// {
// layer.Soil.AbovePhreaticLevel = layer.Soil.DryUnitWeight;
// }
//}
return scenario;
}
private bool WillChoicesResultInScenarios(params Enum[] previousChoices)
{
if (previousChoices.Length >= 2)
{
if (previousChoices[0].Equals(LoadSituation.Dry) && previousChoices[1].Equals(DikeDrySensitivity.None))
{
return false;
}
}
return true;
}
}
}