using System;
using System.Collections.Generic;
namespace Deltares.DamPiping.ExitPointDeterminator
{
///
/// Exception class for UpliftCalculator
///
public class UpliftCalculatorException : Exception
{
public UpliftCalculatorException(string message) : base(message) {}
}
///
/// Class for calculating the Uplift output parameters
///
public class UpliftCalculator
{
// Input parameters
private double deltaPhiCu = Double.NaN;
private double foSu = Double.NaN;
private double hcu = Double.NaN;
private double volumetricWeightOfWater = PipingConstants.UnitWeightOfWater;
private double zu = Double.NaN;
// private LanguageType language = LanguageType.Dutch;
// ///
// /// Language for (validation) messages
// ///
// public LanguageType Language
// {
// get { return language; }
// set { language = value; }
// }
///
/// Gets or sets the volumic weight of water.
///
///
/// The volumic weight of water.
///
public double VolumetricWeightOfWater
{
get
{
return volumetricWeightOfWater;
}
set
{
volumetricWeightOfWater = value;
}
}
///
/// Gets or sets the model factor uplift.
///
///
/// The model factor uplift.
///
public double ModelFactorUplift { get; set; }
///
/// Gets or sets the effective stress.
///
///
/// The effective stress.
///
public double EffectiveStress { get; set; }
///
/// Gets or sets the h-river.
///
///
/// The h river.
///
public double HRiver { get; set; }
///
/// Gets or sets the phi-exit.
///
///
/// The phi exit.
///
public double PhiExit { get; set; }
///
/// Gets or sets the R-Exit.
///
///
/// The r exit.
///
public double RExit { get; set; }
///
/// Gets or sets the H-exit.
///
///
/// The h exit.
///
public double HExit { get; set; }
public double PhiPolder { get; set; }
// Output parameters
///
/// Gets the Zu.
///
///
/// The Zu.
///
public double Zu
{
get
{
return zu;
}
set {}
}
///
/// Gets the Fo_su.
///
///
/// The fo su.
///
public double FoSu
{
get
{
return foSu;
}
set {}
}
///
/// Gets the delta phi cu.
///
///
/// The delta phi cu.
///
public double DeltaPhiCu
{
get
{
return deltaPhiCu;
}
set {}
}
///
/// Gets the hcu.
///
///
/// The hcu.
///
public double Hcu
{
get
{
return hcu;
}
set {}
}
///
/// Calculates the output parameters from the input.
///
public void Calculate()
{
// var restoreLanguage = LocalizationManager.CurrentLanguage;
// LocalizationManager.CurrentLanguage = Language;
// var dumper = new XmlDumper();
try
{
// DumpThis(dumper);
if (EffectiveStress < 0)
{
var message = Helper.Translate("EffectiveStressNegative");
throw new UpliftCalculatorException(message);
}
if (Math.Abs(RExit) < PipingConstants.Epsilon)
{
var message = Helper.Translate("RexitIsZero");
throw new PipingException(message);
}
deltaPhiCu = EffectiveStress/VolumetricWeightOfWater;
zu = ModelFactorUplift*deltaPhiCu - (PhiExit - HExit);
DetermineFactorOfSafety();
hcu = (deltaPhiCu + HExit - PhiPolder) / RExit + PhiPolder;
}
finally
{
// DumpThis(dumper);
// LocalizationManager.CurrentLanguage = restoreLanguage;
}
}
private void DetermineFactorOfSafety()
{
foSu = 0;
var reducedDeltaPhiCu = ModelFactorUplift*deltaPhiCu;
if (Math.Abs(reducedDeltaPhiCu) > PipingConstants.Epsilon)
{
foSu = reducedDeltaPhiCu / Math.Max(0, PhiExit - HExit);
}
}
private void LogParameterIsNaN(IList list, string paramName)
{
var msg = string.Format(Helper.Translate("NaNParameterError"), paramName);
list.Add(msg);
}
///
/// Validates the input
///
/// a filled list when errors are found else an empty list
public List Validate()
{
// var restoreLanguage = LocalizationManager.CurrentLanguage;
// LocalizationManager.CurrentLanguage = Language;
var errors = new List();
// var dumper = new XmlDumper();
try
{
// DumpThis(dumper);
if (double.IsNaN(VolumetricWeightOfWater))
LogParameterIsNaN(errors, "VolumetricWeightOfWater");
if (double.IsNaN(ModelFactorUplift))
LogParameterIsNaN(errors, "ModelFactorUplift");
if (double.IsNaN(EffectiveStress))
LogParameterIsNaN(errors, "EffectiveStress");
if (double.IsNaN(HRiver))
LogParameterIsNaN(errors, "HRiver");
if (double.IsNaN(PhiExit))
LogParameterIsNaN(errors, "PhiExit");
if (double.IsNaN(RExit))
LogParameterIsNaN(errors, "RExit");
if (double.IsNaN(HExit))
LogParameterIsNaN(errors, "HExit");
if (double.IsNaN(PhiPolder))
LogParameterIsNaN(errors, "PhiPolder");
if (Math.Abs(RExit) < PipingConstants.Epsilon)
{
errors.Add(Helper.Translate("RexitIsZero"));
}
}
finally
{
// DumpThis(dumper);
// LocalizationManager.CurrentLanguage = restoreLanguage;
}
return errors;
}
// #region DebugOut
// private bool isDebugOutputEnabled = false;
//
// private void DumpThis(XmlDumper dumper)
// {
// if (isDebugOutputEnabled)
// {
// dumper.DumpObject(this);
// }
// }
//
// ///
// /// Enables debug-dumping to XML
// ///
// public void EnableDebugOutput()
// {
// isDebugOutputEnabled = true;
// }
//
// ///
// /// Fills the data from debug file.
// ///
// public WTIUpliftCalculator FillFromDebugFile(string content)
// {
// var serializer = new Deltares.Standard.IO.Xml.XmlDeserializer();
// if (!string.IsNullOrEmpty(content))
// {
// var res = (WTIUpliftCalculator) serializer.XmlDeserializeFromString(content);
// return res;
// }
// return null;
// }
//
// ///
// /// Gets the main result
// ///
// public string GetMainResult()
// {
// return "FoS = " + foSu.ToString();
// }
//
// #endregion
}
}