// Copyright (C) Stichting Deltares 2023. 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 Deltares.DamEngine.Data.Design;
using Deltares.DamEngine.Data.Geotechnics;
using Deltares.DamEngine.Data.Standard;
using Deltares.DamEngine.Data.Standard.Calculation;
namespace Deltares.DamEngine.Data.General.Results;
///
/// Contains the results for the design calculations.
///
///
public class DesignResult : ICloneable
{
private double? safetyFactor;
///
/// Initializes a new instance of the class.
/// Is only to be used by this.Clone() and in FillDamFromXmlOutput (used in tests), nowhere else
///
internal DesignResult()
{
// only for Clone() method
}
///
/// Initializes a new instance of the class.
/// Needed for testing purposes.
///
/// Name of the location.
/// Name of the scenario.
public DesignResult(string locationName, string scenarioName)
{
this.LocationName = locationName;
this.ScenarioName = scenarioName;
}
///
/// Initializes a new instance of the class.
///
/// The dam failure mechanisme calculation specification.
/// The scenario.
/// The soil profile.
/// Name of the soil geometry2 d.
public DesignResult(DamFailureMechanismeCalculationSpecification damFailureMechanismeCalculationSpecification,
DesignScenario scenario, SoilProfile1D soilProfile, string soilGeometry2DName)
{
if (scenario != null)
{
LocationName = scenario.Location.Name;
ScenarioName = scenario.LocationScenarioID;
}
BaseFileName = "";
CalculationSubDir = "";
DamFailureMechanismeCalculation = damFailureMechanismeCalculationSpecification;
Scenario = scenario;
if (damFailureMechanismeCalculationSpecification != null)
{
switch (damFailureMechanismeCalculationSpecification.FailureMechanismSystemType)
{
case FailureMechanismSystemType.StabilityInside:
case FailureMechanismSystemType.StabilityOutside:
ProfileName = soilGeometry2DName;
break;
case FailureMechanismSystemType.Piping:
ProfileName = soilProfile.Name;
break;
}
}
}
///
/// Gets or sets the safety factor.
/// Note: this is a placeholder, not to be part of the results as written to xml
///
///
/// The safety factor.
///
public double? SafetyFactor
{
get
{
if (DamFailureMechanismeCalculation != null)
{
switch (DamFailureMechanismeCalculation.FailureMechanismSystemType)
{
case FailureMechanismSystemType.StabilityInside:
case FailureMechanismSystemType.StabilityOutside:
return StabilityDesignResults.SafetyFactor;
case FailureMechanismSystemType.Piping:
return PipingDesignResults.SafetyFactor;
}
}
return safetyFactor;
}
set
{
if (DamFailureMechanismeCalculation != null)
{
if (DamFailureMechanismeCalculation.FailureMechanismSystemType == FailureMechanismSystemType.Piping)
{
PipingDesignResults.SafetyFactor = value;
}
else
{
StabilityDesignResults.SafetyFactor = value;
}
}
safetyFactor = value;
}
}
///
/// Gets or sets the dam failure mechanisme calculation.
/// Note: this is a placeholder, not to be part of the results as written to xml
///
///
/// The dam failure mechanisme calculation.
///
public DamFailureMechanismeCalculationSpecification DamFailureMechanismeCalculation { get; set; }
///
/// Gets or sets the scenario.
/// Note: this is a placeholder, not to be part of the results as written to xml
///
///
/// The scenario.
///
public DesignScenario Scenario { get; set; }
//Identifiers, needed to retrace the origin of the result
///
/// Gets the name of the location.
/// For identification purpose
///
///
/// The name of the location.
///
public string LocationName { get; private set; }
///
/// Gets the name of the scenario.
/// For identification purpose
///
///
/// The name of the scenario.
///
public string ScenarioName { get; private set; }
///
/// Gets or sets the name of the profile.
/// For identification purpose
///
///
/// The name of the profile.
///
public string ProfileName { get; set; }
///
/// Gets or sets the name of the base file.
///
///
/// The name of the base file.
/// Can be used to retrace results files.
///
public string BaseFileName // real result for all.
{
get;
set;
}
///
/// Gets or sets the calculation sub dir (as relative path).
///
///
/// The calculation sub dir.
///
public string CalculationSubDir { get; set; }
///
/// Gets or sets the calculation result.
/// This is a derived result.
///
///
/// The calculation result.
///
public CalculationResult CalculationResult { get; set; } = CalculationResult.NoRun;
///
/// Gets or sets the stability design results.
///
///
/// The stability design results.
///
public StabilityDesignResults StabilityDesignResults { get; set; }
///
/// Gets or sets the piping design results.
///
///
/// The piping design results.
///
public PipingDesignResults PipingDesignResults { get; set; }
///
/// Make a clone of object
///
///
public object Clone()
{
var designResult = new DesignResult();
designResult.Assign(this);
return designResult;
}
///
/// Copy data
///
///
private void Assign(DesignResult designResult)
{
// copy place holders
DamFailureMechanismeCalculation = designResult.DamFailureMechanismeCalculation;
Scenario = designResult.Scenario;
// copy direct data
BaseFileName = designResult.BaseFileName;
CalculationSubDir = designResult.CalculationSubDir;
LocationName = designResult.LocationName;
ScenarioName = designResult.ScenarioName;
ProfileName = designResult.ProfileName;
CalculationResult = designResult.CalculationResult;
safetyFactor = designResult.SafetyFactor;
StabilityDesignResults = new StabilityDesignResults();
designResult.StabilityDesignResults.CloneProperties(StabilityDesignResults);
PipingDesignResults = new PipingDesignResults(DamFailureMechanismeCalculation.PipingModelType);
designResult.PipingDesignResults.CloneProperties(PipingDesignResults);
}
}