// Copyright (C) Stichting Deltares 2017. 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.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Xml.Serialization;
using Deltares.DamEngine.Data.Design;
using Deltares.DamEngine.Data.Geometry;
using Deltares.DamEngine.Data.Geotechnics;
using Deltares.DamEngine.Data.Standard.Calculation;
namespace Deltares.DamEngine.Data.General.Results
{
public class DesignResult : ICloneable
{
private string id;
private double xrd;
private double yrd;
private string baseFileName;
private string locationName;
private string scenarioName;
private double? failureProbabilityPiping;
private double? localPipingExitPointX;
private SurfaceLine2 redesignedSurfaceLinePiping;
private double? safetyFactorStability;
private double? failureProbabilityStability;
private double? zone1SafetyFactorStability;
private double? localZone1EntryPointX;
private double? localZone1ExitPointX;
private double? zone2SafetyFactorStability;
private double? localZone2EntryPointX;
private double? localZone2ExitPointX;
private double? upliftFactor;
private double? heaveFactor;
private double? blighPipingFactor;
private double? blighHCritical;
private double? sellmeijer4ForcesPipingFactor;
private double? sellmeijer4ForcesHCritical;
private double? sellmeijerPipingFactor;
private double? sellmeijerHCritical;
private double? wti2017PipingFactor;
private double? wti2017HCritical;
private bool? isUplift;
private double? pl3MinUplift;
private double? pl3HeadAdjusted;
private double? pl3LocalLocationXMinUplift;
private double? pl4MinUplift;
private double? pl4HeadAdjusted;
private double? pl4LocalLocationXMinUplift;
private readonly string nwoId;
private readonly int nwoResultIndex;
private double? locationXrdStart;
private double? locationYrdStart;
private readonly double? locationZrdStart;
private double? locationXrdEnd;
private double? locationYrdEnd;
private readonly double? locationZrdEnd;
private CalculationResult calculationResult = CalculationResult.NoRun;
private string resultMessage = "";
private int numberOfIterations;
private SurfaceLine2 redesignedSurfaceLineStability;
public DesignResult()
{
}
//temp place holders, must be removed/replaced as these are not realy part of results
public DamFailureMechanismeCalculationSpecification DamFailureMechanismeCalculation { get; set; }
public AnalysisType AnalysisType { get; set; } // if realy needed, move to proper location (stability)
public ProbabilisticType ProbabilisticType { get; set; } // if realy needed, move to proper location (stability)
public DesignScenario Scenario { get; set; }
public double? DikeLength { get; set; }
public CalculationResult CalculationResult // derived result, involves ResultMessage, mstabResults (stab) or PipingFactor == null && this.PipingFailureProbability
{
get { return calculationResult;}
set{calculationResult = value;}
}
[XmlIgnore]
public double? SafetyFactor // derived result
{
get
{
double? res = null;
switch (DamFailureMechanismeCalculation.FailureMechanismSystemType)
{
case FailureMechanismSystemType.HorizontalBalance:
case FailureMechanismSystemType.StabilityOutside:
case FailureMechanismSystemType.StabilityInside:
res = StabilitySafetyFactor;
break;
case FailureMechanismSystemType.Piping:
res = PipingFactor;
break;
}
return res;
}
}
[XmlIgnore]
public double? PipingFactor // derived result
{
get
{
double? res = null;
if (DamFailureMechanismeCalculation.FailureMechanismSystemType == FailureMechanismSystemType.Piping)
{
switch (DamFailureMechanismeCalculation.PipingModelType)
{
case PipingModelType.Bligh:
res = BlighPipingFactor;
break;
case PipingModelType.SellmeijerVnk:
res = SellmeijerPipingFactor;
break;
case PipingModelType.Sellmeijer4Forces:
res = Sellmeijer4ForcesPipingFactor;
break;
case PipingModelType.Wti2017:
res = Wti2017PipingFactor;
break;
}
}
return res;
}
}
[XmlIgnore]
public double? FailureProbability // derived result
{
get
{
double? res = null;
switch (DamFailureMechanismeCalculation.FailureMechanismSystemType)
{
case FailureMechanismSystemType.HorizontalBalance:
case FailureMechanismSystemType.StabilityOutside:
case FailureMechanismSystemType.StabilityInside:
res = StabilityFailureProbability;
break;
case FailureMechanismSystemType.Piping:
res = PipingFailureProbability;
break;
}
return res;
}
}
//Identifiers, needed to retrace the origin of the result
public string LocationName
{
get { return locationName; }
}
public string ScenarioName // input, not result
{
get { return scenarioName; }
}
public string StabilityProfileName { get; set; } //methode terughalen uit csvexport indien nodig
public DesignResult(string id, DamFailureMechanismeCalculationSpecification damFailureMechanismeCalculationSpecification, DesignScenario scenario, SoilProfile1D soilProfile,
string soilGeometry2DName, AnalysisType analysisType, int nwoResultIndex, ProbabilisticType probabilisticType)
{
this.id = id;
xrd = scenario.Location.XRd;
yrd = scenario.Location.YRd;
locationName = scenario.Location.Name;
scenarioName = scenario.LocationScenarioID; // terughalen vanuit csvexport indien echt nodig
this.BaseFileName = "";
DamFailureMechanismeCalculation = damFailureMechanismeCalculationSpecification;
// this.scenario = scenario;
// this.soilProfile = soilProfile;
// this.SoilGeometry2DName = soilGeometry2DName;
this.failureProbabilityPiping = null;
this.redesignedSurfaceLinePiping = null;
this.safetyFactorStability = null;
this.failureProbabilityStability = null;
this.redesignedSurfaceLineStability = null;
this.zone1SafetyFactorStability = null;
this.LocalZone1EntryPointX = null;
this.LocalZone1ExitPointX = null;
this.zone2SafetyFactorStability = null;
this.LocalZone2EntryPointX = null;
this.LocalZone2ExitPointX = null;
this.blighPipingFactor = null;
this.blighHCritical = null;
this.sellmeijer4ForcesPipingFactor = null;
this.sellmeijer4ForcesHCritical = null;
this.sellmeijerPipingFactor = null;
this.sellmeijerHCritical = null;
this.wti2017PipingFactor = null;
this.wti2017HCritical = null;
this.isUplift = null;
this.pl3MinUplift = null;
this.pl3HeadAdjusted = null;
this.pl3LocalLocationXMinUplift = null;
this.pl4MinUplift = null;
this.pl4HeadAdjusted = null;
this.pl4LocalLocationXMinUplift = null;
this.nwoId = "";
this.nwoResultIndex = nwoResultIndex;
this.locationXrdStart = null;
this.locationXrdEnd = null;
this.locationYrdStart = null;
this.locationYrdEnd = null;
this.locationZrdStart = null;
this.locationZrdEnd = null;
if (damFailureMechanismeCalculationSpecification != null)
{
switch (damFailureMechanismeCalculationSpecification.FailureMechanismSystemType)
{
case FailureMechanismSystemType.StabilityInside:
case FailureMechanismSystemType.StabilityOutside:
if (analysisType == AnalysisType.AdaptNWO)
{
// an index of 0 can also indicate an error message. That has no futher data so check if there actualy is any.
if (scenario.NwoResults.Count > 0)
{
this.nwoId = scenario.NwoResults[nwoResultIndex].NwoId;
this.locationXrdStart = scenario.NwoResults[nwoResultIndex].LocationXrdStart;
this.locationYrdStart = scenario.NwoResults[nwoResultIndex].LocationYrdStart;
this.locationZrdStart = scenario.NwoResults[nwoResultIndex].LocationZrdStart;
this.locationXrdEnd = scenario.NwoResults[nwoResultIndex].LocationXrdEnd;
this.locationYrdEnd = scenario.NwoResults[nwoResultIndex].LocationYrdEnd;
this.locationZrdEnd = scenario.NwoResults[nwoResultIndex].LocationZrdEnd;
this.BaseFileName = scenario.NwoResults[nwoResultIndex].MStabResults.CalculationName;
this.numberOfIterations = scenario.NwoResults[nwoResultIndex].MStabResults.IterationNumber;
this.safetyFactorStability = scenario.NwoResults[nwoResultIndex].MStabResults.zone1.safetyFactor;
this.zone1SafetyFactorStability = scenario.NwoResults[nwoResultIndex].MStabResults.zone1.safetyFactor;
this.LocalZone1EntryPointX = scenario.NwoResults[nwoResultIndex].MStabResults.zone1.entryPointXCoordinate;
this.LocalZone1ExitPointX = scenario.NwoResults[nwoResultIndex].MStabResults.zone1.exitPointXCoordinate;
if (scenario.NwoResults[nwoResultIndex].MStabResults.zone2 != null)
{
this.zone2SafetyFactorStability = scenario.NwoResults[nwoResultIndex].MStabResults.zone2.Value.safetyFactor;
this.LocalZone2EntryPointX = scenario.NwoResults[nwoResultIndex].MStabResults.zone2.Value.entryPointXCoordinate;
this.LocalZone2ExitPointX = scenario.NwoResults[nwoResultIndex].MStabResults.zone2.Value.exitPointXCoordinate;
}
}
}
else
{
MStabResults? mstabResults = scenario.GetMStabResults(soilProfile, soilGeometry2DName);
this.resultMessage = scenario.GetResultMessage(soilProfile, soilGeometry2DName);
calculationResult = DetermineStabilityCalculationResult(this.resultMessage, mstabResults);
if (mstabResults != null)
{
BaseFileName = mstabResults.Value.CalculationName;
numberOfIterations = mstabResults.Value.IterationNumber;
this.safetyFactorStability = mstabResults.Value.zone1.safetyFactor;
this.zone1SafetyFactorStability = mstabResults.Value.zone1.safetyFactor;
this.LocalZone1EntryPointX = mstabResults.Value.zone1.entryPointXCoordinate;
this.LocalZone1ExitPointX = mstabResults.Value.zone1.exitPointXCoordinate;
if (mstabResults.Value.zone2 != null)
{
this.zone2SafetyFactorStability = mstabResults.Value.zone2.Value.safetyFactor;
this.LocalZone2EntryPointX = mstabResults.Value.zone2.Value.entryPointXCoordinate;
this.LocalZone2ExitPointX = mstabResults.Value.zone2.Value.exitPointXCoordinate;
}
}
}
this.failureProbabilityStability = scenario.GetFailureProbabilityStability(soilProfile, soilGeometry2DName);
this.redesignedSurfaceLineStability = scenario.GetRedesignedSurfaceLine(soilProfile, soilGeometry2DName);
UpliftSituation? upliftSituation = scenario.GetStabilityUpliftSituation(soilProfile, soilGeometry2DName);
if (upliftSituation != null)
{
SetUpliftSituationResults(upliftSituation.Value);
}
break;
case FailureMechanismSystemType.Piping:
this.failureProbabilityPiping = scenario.GetFailureProbabilityPiping(soilProfile, soilGeometry2DName);
this.resultMessage = scenario.GetResultMessage(soilProfile, soilGeometry2DName);
this.redesignedSurfaceLinePiping = scenario.GetRedesignedSurfaceLine(soilProfile, soilGeometry2DName);
UpliftSituation? upliftSituationPiping = scenario.GetStabilityUpliftSituation(soilProfile, soilGeometry2DName);
if (upliftSituationPiping != null)
{
SetUpliftSituationResults(upliftSituationPiping.Value);
}
PipingResults? pipingResults = scenario.GetPipingResults(soilProfile, soilGeometry2DName);
if (pipingResults != null)
{
BaseFileName = pipingResults.Value.CalculationName;
this.blighPipingFactor = pipingResults.Value.BlighPipingFactor;
this.blighHCritical = pipingResults.Value.BlighHCritical;
this.sellmeijer4ForcesPipingFactor = pipingResults.Value.Sellmeijer4ForcesPipingFactor;
this.sellmeijer4ForcesHCritical = pipingResults.Value.Sellmeijer4ForcesHCritical;
this.sellmeijerPipingFactor = pipingResults.Value.SellmeijerVnkPipingFactor;
this.sellmeijerHCritical = pipingResults.Value.SellmeijerVnkHCritical;
this.wti2017PipingFactor = pipingResults.Value.Wti2017PipingFactor;
this.wti2017HCritical = pipingResults.Value.Wti2017HCritical;
this.localPipingExitPointX = pipingResults.Value.PipingExitPointX;
this.heaveFactor = pipingResults.Value.HeaveFactor;
this.upliftFactor = pipingResults.Value.UpliftFactor;
}
this.calculationResult = (this.PipingFactor == null && PipingFailureProbability == null) ? CalculationResult.RunFailed : CalculationResult.Succeeded;
break;
}
}
}
///
/// Determines the stability calculation run result.
///
/// The result message.
/// The mstab results.
///
private CalculationResult DetermineStabilityCalculationResult(string message, MStabResults? mstabResults)
{
CalculationResult result;
if ((message != null) && message.Contains("FAIL"))
{
result = CalculationResult.UnexpectedError;
}
else
{
// If no failure and no results, then no run has been made
result = mstabResults != null ? CalculationResult.Succeeded : CalculationResult.NoRun;
}
return result;
}
///
/// Sets the uplift situation results.
///
/// The uplift situation.
private void SetUpliftSituationResults(UpliftSituation upliftSituation)
{
this.isUplift = upliftSituation.IsUplift;
if (upliftSituation.Pl3MinUplift < double.MaxValue)
{
this.pl3MinUplift = upliftSituation.Pl3MinUplift;
}
if (upliftSituation.Pl3HeadAdjusted < double.MaxValue)
{
this.pl3HeadAdjusted = upliftSituation.Pl3HeadAdjusted;
}
if (upliftSituation.Pl3LocationXMinUplift < double.MaxValue)
{
this.pl3LocalLocationXMinUplift = upliftSituation.Pl3LocationXMinUplift;
}
if (upliftSituation.Pl4MinUplift < double.MaxValue)
{
this.pl4MinUplift = upliftSituation.Pl4MinUplift;
}
if (upliftSituation.Pl4HeadAdjusted < double.MaxValue)
{
this.pl4HeadAdjusted = upliftSituation.Pl4HeadAdjusted;
}
if (upliftSituation.Pl4LocationXMinUplift < double.MaxValue)
{
this.pl4LocalLocationXMinUplift = upliftSituation.Pl4LocationXMinUplift;
}
}
public int NumberOfIterations // real results for NWo
{
get { return numberOfIterations; }
set { numberOfIterations = value; }
}
public string ID
{
get { return this.id; }
}
public string ResultMessage // real result
{
get { return resultMessage; }
set { resultMessage = value; }
}
[XmlIgnore]
public double Xrd //Xrd iput but very usefull as output as well
{
get
{
return xrd;
}
}
[XmlIgnore]
public double Yrd //Yrd iput but very usefull as output as well
{
get
{
return yrd;
}
}
public double? StabilitySafetyFactor // real result stab and nwostab
{
get { return this.safetyFactorStability; }
set { this.safetyFactorStability = value; }
}
public double? StabilityFailureProbability // real result stab
{
get { return this.failureProbabilityStability; }
set { this.failureProbabilityStability = value; }
}
public double? PipingFailureProbability // real result piping
{
get { return this.failureProbabilityPiping; }
set { this.failureProbabilityPiping = value; }
}
public double? Zone1SafetyFactorStability // real result for stab and nwostab
{
get { return this.zone1SafetyFactorStability; }
set { this.zone1SafetyFactorStability = value; }
}
public double? LocalZone1EntryPointX // real result for stab and nwostab
{
get { return localZone1EntryPointX; }
set { localZone1EntryPointX = value; }
}
public double? LocalZone1ExitPointX // real result stab and nwostab
{
get { return localZone1ExitPointX; }
set { localZone1ExitPointX = value; }
}
public double? Zone2SafetyFactorStability // real result stab and nwostab
{
get { return this.zone2SafetyFactorStability; }
set { this.zone2SafetyFactorStability = value; }
}
public double? LocalZone2EntryPointX // real result stab and nwostab
{
get { return localZone2EntryPointX; }
set { localZone2EntryPointX = value; }
}
public double? LocalZone2ExitPointX // real result stab and nwostab
{
get { return localZone2ExitPointX; }
set { localZone2ExitPointX = value; }
}
public bool? IsUplift // real result stab and piping
{
get { return this.isUplift; }
set { this.isUplift = value; }
}
public double? Pl3MinUplift // real result stab and piping
{
get { return this.pl3MinUplift; }
set { this.pl3MinUplift = value; }
}
public double? Pl3HeadAdjusted // real result stab and piping
{
get { return this.pl3HeadAdjusted; }
set { this.pl3HeadAdjusted = value; }
}
public double? Pl3LocalLocationXMinUplift // real result stab and piping
{
get { return this.pl3LocalLocationXMinUplift; }
set { this.pl3LocalLocationXMinUplift = value; }
}
public double? Pl4MinUplift // real result stab and piping
{
get { return this.pl4MinUplift; }
set { this.pl4MinUplift = value; }
}
public double? Pl4HeadAdjusted // real result stab and piping
{
get { return this.pl4HeadAdjusted; }
set { this.pl4HeadAdjusted = value; }
}
public double? Pl4LocalLocationXMinUplift // real result stab and piping
{
get { return this.pl4LocalLocationXMinUplift; }
set { this.pl4LocalLocationXMinUplift = value; }
}
public double? UpliftFactor // real result piping
{
get { return this.upliftFactor; }
set { this.upliftFactor = value; }
}
public double? HeaveFactor // real result piping
{
get { return this.heaveFactor; }
set { this.heaveFactor = value; }
}
public double? BlighPipingFactor // real result piping
{
get { return this.blighPipingFactor; }
set { this.blighPipingFactor = value; }
}
public double? BlighHCritical // real result piping
{
get { return this.blighHCritical; }
set { this.blighHCritical = value; }
}
public double? Sellmeijer4ForcesPipingFactor // real result piping
{
get { return this.sellmeijer4ForcesPipingFactor; }
set { this.sellmeijer4ForcesPipingFactor = value; }
}
public double? Sellmeijer4ForcesHCritical // real result piping
{
get { return this.sellmeijer4ForcesHCritical; }
set { this.sellmeijer4ForcesHCritical = value; }
}
public double? SellmeijerPipingFactor // real result piping
{
get { return this.sellmeijerPipingFactor; }
set { this.sellmeijerPipingFactor = value; }
}
public double? SellmeijerHCritical // real result piping
{
get { return this.sellmeijerHCritical; }
set { this.sellmeijerHCritical = value; }
}
///
/// Gets or sets the wti2017 piping factor.
///
///
/// The wti2017 piping factor.
///
public double? Wti2017PipingFactor // real result piping
{
get { return wti2017PipingFactor; }
set { wti2017PipingFactor = value; }
}
///
/// Gets or sets the wti2017 h critical.
///
///
/// The wti2017 h critical.
///
public double? Wti2017HCritical // real result piping
{
get { return wti2017HCritical; }
set { wti2017HCritical = value; }
}
public string NwoId { get { return this.nwoId; } } // real result nwostab
public int NwoResultIndex // real result nwostab
{
get { return this.nwoResultIndex; }
}
public double? NWOLocationXrdStart // real result nwostab
{
get { return this.locationXrdStart; }
}
public double? NWOLocationYrdStart // real result nwostab
{
get { return this.locationYrdStart; }
}
public double? NWOLocationZrdStart // real result nwostab
{
get { return this.locationZrdStart; }
}
public double? NWOLocationXrdEnd // real result nwostab
{
get { return this.locationXrdEnd; }
}
public double? NWOLocationYrdEnd // real result nwostab
{
get { return this.locationYrdEnd; }
}
public double? NWOLocationZrdEnd { get { return this.locationZrdEnd; } } // real result nwostab
//Note: using SurfaceLine instead of LocalXzSurfaceLine must give the proper RD coors. If this is not the case, error is somewhere else. Do not convert here!
public SurfaceLine2 RedesignedSurfaceLine2Stability // real result stab
{
get { return redesignedSurfaceLineStability; }
set { redesignedSurfaceLineStability = value; }
}
public SurfaceLine2 RedesignedSurfaceLine2Piping // real result piping
{
get { return redesignedSurfaceLinePiping; }
set { redesignedSurfaceLinePiping = value; }
}
public double? LocalPipingExitPointX // real result piping
{
get { return localPipingExitPointX; }
set { localPipingExitPointX = value; }
}
public string BaseFileName // real result for all.
{
get { return baseFileName; }
set { baseFileName = value; }
}
///
/// Copy data
///
///
public void Assign(DesignResult designResult)
{
this.id = designResult.id;
this.BaseFileName = designResult.BaseFileName;
this.NumberOfIterations = designResult.NumberOfIterations;
// this.damFailureMechanismeCalculationSpecification = designResult.damFailureMechanismeCalculationSpecification;
// this.Scenario = designResult.Scenario;
// this.SoilProfile = designResult.SoilProfile;
// this.SoilGeometry2DName = designResult.SoilGeometry2DName;
this.failureProbabilityPiping = designResult.failureProbabilityPiping;
this.redesignedSurfaceLinePiping = designResult.redesignedSurfaceLinePiping;
this.safetyFactorStability = designResult.safetyFactorStability;
this.failureProbabilityStability = designResult.failureProbabilityStability;
this.zone1SafetyFactorStability = designResult.zone1SafetyFactorStability;
this.LocalZone1EntryPointX = designResult.LocalZone1EntryPointX;
this.LocalZone1ExitPointX = designResult.LocalZone1ExitPointX;
this.zone2SafetyFactorStability = designResult.zone2SafetyFactorStability;
this.LocalZone2EntryPointX = designResult.LocalZone2EntryPointX;
this.LocalZone2ExitPointX = designResult.LocalZone2ExitPointX;
this.blighPipingFactor = designResult.blighPipingFactor;
this.blighHCritical = designResult.blighHCritical;
this.sellmeijer4ForcesPipingFactor = designResult.sellmeijer4ForcesPipingFactor;
this.sellmeijer4ForcesHCritical = designResult.sellmeijer4ForcesHCritical;
this.sellmeijerPipingFactor = designResult.sellmeijerPipingFactor;
this.sellmeijerHCritical = designResult.sellmeijerHCritical;
this.wti2017PipingFactor = designResult.wti2017PipingFactor;
this.wti2017HCritical = designResult.wti2017HCritical;
this.redesignedSurfaceLineStability = designResult.redesignedSurfaceLineStability;
this.calculationResult = designResult.calculationResult;
}
///
/// Make a clone of object
///
///
public object Clone()
{
var soilProfile = new SoilProfile1D();
var soilGeometry2DName = "";
DesignResult designResult = new DesignResult(id, DamFailureMechanismeCalculation, Scenario,
soilProfile, soilGeometry2DName, AnalysisType, nwoResultIndex, ProbabilisticType);
designResult.Assign(this);
return designResult;
}
}
}