using System;
using System.Collections.Generic;
using Deltares.Mathematics;
using Deltares.Standard;
// =======================================================================================================================
// Class name:
//
// Description:
//
// Copyright (c) 2010 Deltares
//
// Date ID Modification
// 2010-04-20 Sel Created
// =======================================================================================================================
namespace Deltares.Stability.Calculation.Inner
{
public abstract class TStabilityCalculation
{
// Protected fields
public ProgressDelegate DoProgress = null;
public TSetValuesDelegate DoSetValues = null;
protected TDump FDumpData = null;
protected TInterfaceData FInterfaceData = null;
protected double FInvalidFitness = 0;
protected bool FIsProbabilisticCalculation = false;
protected double FMinStabilityFactor = 0;
protected double FSafety = Constants.CFMinStart;
protected double FSafetyZone1 = Constants.CFMinStart;
protected double FSafetyZone2 = Constants.CFMinStart;
protected TZones FZone = null;
protected bool useZone1Search = true;
protected double zonePenalty = 0;
public TStabilityCalculation() : base()
{
FMinStabilityFactor = Constants.CFMinStart;
}
public double InvalidFitness
{
get
{
return FInvalidFitness;
}
set
{
FInvalidFitness = value;
}
}
public TInterfaceData InterfaceData
{
get
{
return FInterfaceData;
}
set
{
FInterfaceData = value;
}
}
public TDump DumpData
{
get
{
return FDumpData;
}
set
{
FDumpData = value;
}
}
public bool UseZone1Search
{
get
{
return useZone1Search;
}
set
{
useZone1Search = value;
}
}
public double ZonePenalty
{
get
{
return zonePenalty;
}
set
{
zonePenalty = value;
}
}
public double Safety
{
get
{
return FSafety;
}
set
{
FSafety = value;
}
}
public abstract void CalculationGrid();
public abstract void CalculationGA(GeneticAlgorithm AGeneticAlgorithm);
public abstract void CalculationLM(LevenbergMarquardtExtreme ALevenbergMarquardt);
// =======================================================================================================================
// Date ID Modification
// 2010-04-20 Sel Created
// =======================================================================================================================
//Constructor Create()
// Public methods
public virtual void CreateShortCuts()
{
FIsProbabilisticCalculation = (FInterfaceData.ModelData.IsProbabilistic) && (FInterfaceData.CalculationOptions.ProbabilisticCalculationType == TProbCalculationType.pctProbabilistic);
}
public void CreateZones()
{
if ((FInterfaceData.ModelData.HasZonePlot))
{
FZone = new TZones();
FZone.InterfaceData = FInterfaceData;
FZone.CreateRestProfile();
FDumpData.RestProfile = FZone.RestProfile;
FDumpData.SafeProfile = FZone.SafeProfile;
}
}
public double DeterminMinimalYAtSurface(double AXStart, double AXEnd)
{
double result = 0;
int LStartIndex = 0;
int LEndIndex = 0;
double LStart = Math.Min(AXStart, AXEnd);
double LEnd = Math.Max(AXStart, AXEnd);
TPoints[] LSurfaceLine = FInterfaceData.SurfaceLine;
for (int i = 0; i < LSurfaceLine.GetUpperBound(0); i++)
{
if ((LStart >= LSurfaceLine[i].XCoor) && (LStart <= LSurfaceLine[i + 1].XCoor))
{
LStartIndex = i + 1;
result = MStabDatafunctions.LinInpolY(LSurfaceLine[i].XCoor, LSurfaceLine[i].ZCoor,
LSurfaceLine[i + 1].XCoor, LSurfaceLine[i + 1].ZCoor, AXStart);
break;
}
}
for (int i = 0; i < LSurfaceLine.GetUpperBound(0); i++)
{
if ((LEnd >= LSurfaceLine[i].XCoor) && (LEnd <= LSurfaceLine[i + 1].XCoor))
{
LEndIndex = i - 1;
result = Math.Min(result, MStabDatafunctions.LinInpolY(LSurfaceLine[i].XCoor, LSurfaceLine[i].ZCoor,
LSurfaceLine[i + 1].XCoor, LSurfaceLine[i + 1].ZCoor, AXEnd));
break;
}
}
for (int i = LStartIndex; i <= LEndIndex; i++)
{
result = Math.Min(result, LSurfaceLine[i].ZCoor);
}
return result;
}
public void ProbCalculationIncludingExternalWaterlevels()
{
TDesignpointExternalLevel DesignPointCalculation;
DesignPointCalculation = new TDesignpointExternalLevel();
DesignPointCalculation.Exceed = FInterfaceData.ExternallevelFrequency;
DesignPointCalculation.Dump = FDumpData;
DesignPointCalculation.AddexternalLevelData();
}
///
/// Notifies changes back to the caller/observer while calculating
///
/// The subject of the changes.
/// The changed data.
internal void NotifyChange(string subject, object data)
{
if (DoSetValues == null)
{
return; // cant use the callback, do nothing
}
if (string.IsNullOrWhiteSpace(subject))
{
return; // no subject, dont send
}
object message = data;
if (data is TSlipCircleData)
{
var slipCircle = (TSlipCircleData) data;
message = new Dictionary
{
{
Constants.XLeftTag, slipCircle.XLeftCenterPoint
},
{
Constants.XRightTag, slipCircle.XRightCenterPoint
},
{
Constants.ZBottomTag, slipCircle.ZBottomCenterPoint
},
{
Constants.ZTopTag, slipCircle.ZTopCenterPoint
},
{
Constants.ZIntervalTag, slipCircle.ZIntervalCount
},
{
Constants.XIntervalTag, slipCircle.XIntervalCount
}
};
}
if (message == null)
{
return; // nothing to send
}
// send the data to the subscriber
DoSetValues(subject, message);
}
}
// end TStabilityCalculation
}