Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesAssessmentRegional/RegionalScenariosCalculation.cs
===================================================================
diff -u -r1117 -r1119
--- DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesAssessmentRegional/RegionalScenariosCalculation.cs (.../RegionalScenariosCalculation.cs) (revision 1117)
+++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesAssessmentRegional/RegionalScenariosCalculation.cs (.../RegionalScenariosCalculation.cs) (revision 1119)
@@ -22,14 +22,21 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
+using Deltares.DamEngine.Calculators.KernelWrappers.Common;
+using Deltares.DamEngine.Calculators.KernelWrappers.Interfaces;
+using Deltares.DamEngine.Calculators.Properties;
using Deltares.DamEngine.Data.General;
+using Deltares.DamEngine.Data.General.Results;
using Deltares.DamEngine.Data.Geotechnics;
using Deltares.DamEngine.Data.RegionalAssessmentResults;
using Deltares.DamEngine.Data.Standard.Calculation;
using Deltares.DamEngine.Data.Standard.Language;
using Deltares.DamEngine.Data.Standard.Logging;
+using Deltares.DamPiping.BlighCalculator;
+using Deltares.DamPiping.Sellmeijer4ForcesCalculator;
namespace Deltares.DamEngine.Calculators.DikesAssessmentRegional
{
@@ -42,27 +49,153 @@
public RegionalScenariosCalculationException(string message) : base(message) { }
}
+ ///
+ /// Class to perform the calculation of reginal scenarios
+ ///
+ ///
public class RegionalScenariosCalculation : ICalculation
{
+ private DamProjectData damProjectData;
+
+ public List Execute(DamProjectData aDamProjectData)
+ {
+ damProjectData = aDamProjectData;
+ maxCalculationCores = damProjectData.MaxCalculationCores;
+ var dj = damProjectData.DikeJob;
+ evaluationJob = damProjectData.GetEvaluationJob();
+ //evaluationJob.Locations.AddRange();
+ Run();
+ return new List();
+ }
+
+ private IKernelWrapper CreateKernelWrapperforJob(DamFailureMechanismeCalculationSpecification currentSpecification,
+ Location location, SoilGeometryProbability soilGeometryProbability, out IKernelDataInput kernelDataInput,
+ out IKernelDataOutput kernelDataOutput)
+ {
+ IKernelWrapper kernelWrapper = KernelWrapperHelper.CreateKernelWrapper(currentSpecification);
+
+ if (kernelWrapper == null)
+ {
+ throw new NotImplementedException(Resources.DesignCalculatorKernelNotImplemented);
+ }
+
+ //damProjectData.DesignCalculations = new List();
+ var calculationMessages = new List();
+ // Prepare input
+ var damKernelInput = new DamKernelInput();
+ var projectPath = damProjectData.ProjectPath != "" ? damProjectData.ProjectPath : Directory.GetCurrentDirectory();
+ damKernelInput.ProjectDir = projectPath;
+ damKernelInput.CalculationDir = Path.Combine(projectPath, damProjectData.CalculationMap);
+ damKernelInput.Location = location;
+ damKernelInput.SubSoilScenario = soilGeometryProbability;
+ //damKernelInput.DesignScenario = location.Scenarios[designScenarioIndex];
+ damKernelInput.DamFailureMechanismeCalculationSpecification = damProjectData.DamProjectCalculationSpecification.CurrentSpecification;
+ damKernelInput.RiverLevelHigh = damKernelInput.DesignScenario.RiverLevel;// #Bka hier geen Dscen
+ damKernelInput.RiverLevelLow = damKernelInput.DesignScenario.RiverLevelLow;// #Bka hier geen Dscen
+ AnalysisType analysisType = DamProjectCalculationSpecification.SelectedAnalysisType;
+ // SynchronizeDesignScenarioDataWithLocationData(damKernelInput.DesignScenario, damKernelInput.Location);
+ // IKernelDataInput kernelDataInput;
+ //IKernelDataOutput kernelDataOutput;
+ PrepareResult prepareResult = kernelWrapper.Prepare(damKernelInput, 0, out kernelDataInput, out kernelDataOutput);
+
+ // Sometimes the kernelDataInput is not created (p.e when soilprofileprobablility is meant for
+ // stability where Piping calc is wanted). In that case, do nothing but just skip.
+ if (prepareResult == PrepareResult.Successful)
+ {
+ // switch (analysisType)
+ // {
+ // case AnalysisType.AdaptGeometry:
+ // PerformDesignCalculation(kernelWrapper, kernelDataInput, kernelDataOutput,
+ // damKernelInput, calculationMessages, damProjectData.DesignCalculations);
+ // break;
+ // case AnalysisType.NoAdaption:
+ // PerformSingleCalculation(kernelWrapper, kernelDataInput, kernelDataOutput,
+ // damKernelInput, calculationMessages, damProjectData.DesignCalculations);
+ // break;
+ //
+ // }
+ }
+ else
+ {
+ if (prepareResult == PrepareResult.NotRelevant)
+ {
+ calculationMessages.Add(new LogMessage(LogMessageType.Info, null,
+ string.Format(Resources.DesignCalculatorIrrelevant,
+ location.Name,
+ soilGeometryProbability.ToString(),
+ damKernelInput.DesignScenario.LocationScenarioID))); // #Bka hier geen Dscen
+ }
+ if (prepareResult == PrepareResult.Failed)
+ {
+ calculationMessages.Add(new LogMessage(LogMessageType.Error, null,
+ string.Format(Resources.DesignCalculatorPrepareError,
+ location.Name,
+ soilGeometryProbability.ToString(),
+ damKernelInput.DesignScenario.LocationScenarioID)));// #Bka hier geen Dscen
+ }
+ }
+ return kernelWrapper;//calculationMessages;
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
private EvaluationJob evaluationJob = null;
- private GetValuesDelegate getValuesDelegate = null;
- private ProgressDelegate progressDelegate = null;
- private SendMessageDelegate sendMessageDelegate = null;
+ private GetValuesDelegate getValuesDelegate;
+ private ProgressDelegate progressDelegate;
+ private SendMessageDelegate sendMessageDelegate;
private string mstabExePath = @".\DGeoStability.exe";
private int maxCalculationCores = 255;
private Dictionary runningJobs = new Dictionary();
private bool isSkipStabilityCalculation = false;
-
+
+ ///
+ /// 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; }
- public RegionalScenariosCalculation()
- {
- }
-
#region ICalculation Members
+ ///
+ /// Gets the results.
+ ///
+ /// The results.
+ ///
public CalculationResult GetResults(ref string results)
{
// try
@@ -78,6 +211,11 @@
return CalculationResult.UnexpectedError;
}
+ ///
+ /// Loads the specified input.
+ ///
+ /// The input.
+ ///
public CalculationResult Load(string input)
{
// try
@@ -93,48 +231,82 @@
return CalculationResult.UnexpectedError;
}
- public CalculationResult RegisterGetValues(GetValuesDelegate getValuesDelegate)
+ ///
+ /// Registers the get values.
+ ///
+ /// The get values delegate.
+ ///
+ public CalculationResult RegisterGetValues(GetValuesDelegate aGetValuesDelegate)
{
- this.getValuesDelegate = getValuesDelegate;
+ getValuesDelegate = aGetValuesDelegate;
return CalculationResult.Succeeded;
}
- public CalculationResult RegisterProgress(ProgressDelegate progressDelegate)
+ ///
+ /// Registers the progress.
+ ///
+ /// The progress delegate.
+ ///
+ public CalculationResult RegisterProgress(ProgressDelegate aProgressDelegate)
{
- this.progressDelegate = progressDelegate;
+ progressDelegate = aProgressDelegate;
return CalculationResult.Succeeded;
}
+ ///
+ /// Registers the send debug information.
+ ///
+ /// The send debug information delegate.
+ ///
public CalculationResult RegisterSendDebugInfo(SendDebugInfodelegate sendDebugInfoDelegate)
{
return CalculationResult.Succeeded;
}
- public CalculationResult RegisterSendMessage(SendMessageDelegate sendMessageDelegate)
+ ///
+ /// Registers the send message.
+ ///
+ /// The send message delegate.
+ ///
+ public CalculationResult RegisterSendMessage(SendMessageDelegate aSendMessageDelegate)
{
- this.sendMessageDelegate = sendMessageDelegate;
+ sendMessageDelegate = aSendMessageDelegate;
return CalculationResult.Succeeded;
}
+ ///
+ /// Registers the set values.
+ ///
+ /// The set values delegate.
+ ///
public CalculationResult RegisterSetValues(SetValuesDelegate setValuesDelegate)
{
return CalculationResult.Succeeded;
}
+ ///
+ /// Registers the user abort.
+ ///
+ /// The user abort delegate.
+ ///
public CalculationResult RegisterUserAbort(UserAbortDelegate userAbortDelegate)
{
return CalculationResult.Succeeded;
}
+ ///
+ /// Runs this instance.
+ ///
+ ///
public CalculationResult Run()
{
try
{
- List tasks = this.FillQueue();
+ List tasks = FillQueue();
- General.Parallel.Run(tasks, this.RunTask, this.progressDelegate, this.MaxCalculationCores);
- this.FillResults(tasks);
+ General.Parallel.Run(tasks, RunTask, progressDelegate, maxCalculationCores);
+ FillResults(tasks);
return CalculationResult.Succeeded;
}
@@ -145,50 +317,66 @@
}
}
+ ///
+ /// Validates this instance.
+ ///
+ ///
public CalculationResult Validate()
{
return CalculationResult.Succeeded;
}
#endregion
+ ///
+ /// Gets the version.
+ ///
+ ///
+ /// The version.
+ ///
public string Version
{
get { return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
}
+ ///
+ /// Gets or sets the mstab executable path.
+ ///
+ ///
+ /// The mstab executable path.
+ ///
public string MStabExePath
{
get { return mstabExePath; }
set { mstabExePath = value; }
}
+ ///
+ /// Gets or sets a value indicating whether this instance is skip stability calculation.
+ ///
+ ///
+ /// true if this instance is skip stability calculation; otherwise, false.
+ ///
public bool IsSkipStabilityCalculation
{
get { return isSkipStabilityCalculation; }
set { isSkipStabilityCalculation = value; }
}
- public int MaxCalculationCores
- {
- get { return maxCalculationCores; }
- set { maxCalculationCores = value; }
- }
-
private List FillQueue()
{
List tasks = new List();
- this.evaluationJob.FailedEvaluatedLocations = new List();
- foreach (Location location in this.evaluationJob.Locations)
+ evaluationJob.FailedEvaluatedLocations = new List();
+ foreach (var location in evaluationJob.Locations)
{
if (location.Segment == null)
{
// Add this location to the failed locations
- if (this.evaluationJob.FailedEvaluatedLocations.IndexOf(location) < 0)
+ if (evaluationJob.FailedEvaluatedLocations.IndexOf(location) < 0)
{
- this.evaluationJob.FailedEvaluatedLocations.Add(location);
- var locationHasNoSegment = LocalizationManager.GetTranslatedText(this.GetType(), "LocationHasNoSegment");
+ evaluationJob.FailedEvaluatedLocations.Add(location);
+ var locationHasNoSegment = LocalizationManager.GetTranslatedText(GetType(), "LocationHasNoSegment");
sendMessageDelegate(new LogMessage(LogMessageType.Error, location, locationHasNoSegment));
}
}
@@ -202,10 +390,10 @@
FailureMechanismSystemType.StabilityInside)).ToList();
if (soilGeometryProbabilities.Count == 0)
{
- this.evaluationJob.FailedEvaluatedLocations.Add(location);
+ evaluationJob.FailedEvaluatedLocations.Add(location);
sendMessageDelegate(
- new LogMessage(LogMessageType.Warning, location, String.Format("Location has no soilprofiles: ") +
- String.Format("Segment: {0}", location.Segment.Name)));
+ new LogMessage(LogMessageType.Warning, location, string.Format("Location has no soilprofiles: ") +
+ string.Format("Segment: {0}", location.Segment.Name)));
}
else
@@ -214,26 +402,26 @@
{
if (soilGeometryProbability.SoilProfileType == SoilProfileType.ProfileType2D || soilGeometryProbability.SoilProfileType == SoilProfileType.ProfileTypeStiFile)
{
- this.evaluationJob.FailedEvaluatedLocations.Add(location);
+ evaluationJob.FailedEvaluatedLocations.Add(location);
sendMessageDelegate(new LogMessage(LogMessageType.Warning, location, LocalizationManager.GetTranslatedText(this, "Geometry2DNotSupportedInRegionalAssessment") +
- String.Format("Segment: {0}", location.Segment.Name)));
+ string.Format("Segment: {0}", location.Segment.Name)));
}
else
{
SoilProfile soilProfile = soilGeometryProbability.SoilProfile1D;
- IList rwScenarios = null;
+ IList rwScenarios;
try
{
- rwScenarios = this.GetRWScenarios(location, soilGeometryProbability);
+ rwScenarios = GetRegionalScenarios(location, soilGeometryProbability);
}
catch (Exception e)
{
rwScenarios = null;
// Add this location to the failed locations
- if (this.evaluationJob.FailedEvaluatedLocations.IndexOf(location) < 0)
+ if (evaluationJob.FailedEvaluatedLocations.IndexOf(location) < 0)
{
- this.evaluationJob.FailedEvaluatedLocations.Add(location);
+ evaluationJob.FailedEvaluatedLocations.Add(location);
sendMessageDelegate(
new LogMessage(LogMessageType.Warning, location, String.Format("Cannot generate scenarios: {0}", e.Message) +
String.Format("Soilprofile: {0}", soilProfile.Name)));
@@ -255,11 +443,13 @@
return tasks;
}
- private IList GetRWScenarios(Location location, SoilGeometryProbability soilGeometryProbability)
+ private IList GetRegionalScenarios(Location location, SoilGeometryProbability soilGeometryProbability)
{
- RegionalScenarioSelector selector = new RegionalScenarioSelector();
- selector.PipingModelType = PipingModelType;
- selector.MStabParameters = MStabParameters;
+ RegionalScenarioSelector selector = new RegionalScenarioSelector
+ {
+ PipingModelType = PipingModelType,
+ MStabParameters = MStabParameters
+ };
return selector.GetScenarios(location, soilGeometryProbability);
}
@@ -311,8 +501,8 @@
///
private void ProcessJobPiping(RegionalScenarioProfileResult job)
{
-// if (job.Location.ModelFactors.UpliftCriterionPiping.HasValue)
-// {
+ if (job.Location.ModelFactors.UpliftCriterionPiping.HasValue)
+ {
// var modelParametersForPLLines = new ModelParametersForPlLines();
// var calculator = GetCalculatorForPipingModel(job, modelParametersForPLLines);
// double waterLevel;
@@ -327,9 +517,9 @@
// }
// //job.SoilGeometryProbability.SoilProfile1D.EnsureUniqueLayerIds();
// var calculationName = GetCalculationNameForPipingCalculator(job);
-// calculator.FilenameCalculation = Path.Combine(Path.Combine(DamProjectData.ProjectWorkingPath, job.FailureMechanismType.ToString()), calculationName);
+// calculator.FilenameCalculation = Path.Combine(Path.Combine(damProjectData.ProjectPath, job.FailureMechanismType.ToString()), calculationName);
// calculator.IsHydraulicShortcut = (job.HydraulicShortcutType == HydraulicShortcutType.HydraulicShortcut);
-// double? pipingFactor = calculator.CalculatePipingFactor(job.Location, job.Location.LocalXZSurfaceLine2, job.SoilGeometryProbability.SoilProfile1D, waterLevel);
+// double? pipingFactor = calculator.CalculatePipingFactor(job.Location, job.Location.SurfaceLine, job.SoilGeometryProbability.SoilProfile1D, waterLevel);
// job.BaseFileName = calculator.FilenameCalculation;
//
// job.RegionalResultType = RegionalResultType.SafetyFactor;
@@ -346,11 +536,11 @@
// job.SafetyFactor = double.NaN;
// job.CalculationResult = CalculationResult.RunFailed;
// }
-// }
-// else
-// {
-// throw new RegionalScenariosCalculationException(String.Format("Uplift criterion not defined for location {0}", job.Location.Name));
-// } //##Bka
+ }
+ else
+ {
+ throw new RegionalScenariosCalculationException(String.Format("Uplift criterion not defined for location {0}", job.Location.Name));
+ }
}
@@ -380,17 +570,14 @@
///
///
/// proper piping calculator
-// private PipingCalculator GetCalculatorForPipingModel(RWScenarioProfileResult job, ModelParametersForPlLines modelParametersForPLLines)
+// private PipingCalculator GetCalculatorForPipingModel(RegionalScenarioProfileResult job, ModelParametersForPLLines modelParametersForPlLines)
// {
// PipingCalculator calculator;
// switch (job.PipingModelOption)
// {
// case PipingModelType.SellmeijerVnk: calculator = new PipingCalculatorSellmeijer(modelParametersForPLLines,
// 1.0, null, null, null, job.Location.ModelFactors.UpliftCriterionPiping.Value);
// break;
-// case PipingModelType.Sellmeijer2Forces: calculator = new PipingCalculatorSellmeijer2Forces(modelParametersForPLLines,
-// 1.0, null, null, job.Location.ModelFactors.UpliftCriterionPiping.Value);
-// break;
// case PipingModelType.Sellmeijer4Forces: calculator = new PipingCalculatorSellmeijer4Forces(modelParametersForPLLines,
// 1.0, null, null, job.Location.ModelFactors.UpliftCriterionPiping.Value);
// break;
@@ -409,52 +596,65 @@
///
private void ProcessJobStability(RegionalScenarioProfileResult job)
{
+
// StabilityCalculation calculator = new StabilityCalculation();
+ var currentSpecification = damProjectData.DamProjectCalculationSpecification.CurrentSpecification;
+ currentSpecification.FailureMechanismSystemType = job.FailureMechanismType;
+ IKernelDataInput kernelDataInput;
+ IKernelDataOutput kernelDataOutput;
+ var calculator = CreateKernelWrapperforJob(currentSpecification, job.Location, job.SoilGeometryProbability,
+ out kernelDataInput, out kernelDataOutput);
+ lock (runningJobs)
+ {
+ runningJobs[calculator] = job;
+ }
-// lock (runningJobs)
-// {
-// runningJobs[calculator] = job;
-// }
-
// calculator.MStabExePath = this.MStabExePath;
// calculator.RegisterSendMessage(this.SendStabilityMessage);
//
-// string soilDatabaseName = job.Location.StabilityOptions.SoilDatabaseName;
- // DamFailureMechanismeCalculationSpecification damCalculation =
- // calculator.GetSpecification(this.evaluationJob.DikeName, soilDatabaseName, job.Location, new SoilGeometry(job.SoilGeometryProbability.SoilProfile1D, null),
- // (MStabModelType)job.MstabModelOption, job.LoadSituation, job.DikeDrySensitivity, job.HydraulicShortcutType, MStabParameters);
+// string soilDatabaseName = job.Location.StabilityOptions.SoilDatabaseName;
+// DamFailureMechanismeCalculationSpecification damCalculation =
+// calculator.GetSpecification(this.evaluationJob.DikeName, soilDatabaseName, job.Location, new SoilGeometry(job.SoilGeometryProbability.SoilProfile1D, null),
+// (MStabModelType)job.MstabModelOption, job.LoadSituation, job.DikeDrySensitivity, job.HydraulicShortcutType, MStabParameters);
//
// calculator.SaveToFile(damCalculation.FailureMechanismParametersMStab);
// string inputFile = damCalculation.FailureMechanismParametersMStab.MStabParameters.ProjectFileName;
//
// job.BaseFileName = inputFile.Replace(DamProject.ProjectWorkingPath, @"").Replace(".sti", "");
// calculator.Load(inputFile);
-// job.CalculationResult = calculator.Run();
+ List messages;
+ calculator.Execute(kernelDataInput, kernelDataOutput, out messages);
+ job.CalculationResult = CalculationResult.Succeeded; //Run();
if (job.CalculationResult == CalculationResult.Succeeded)
{
- string results = "";
-
-// job.CalculationResult = calculator.GetResults(ref results);
- //XmlDeserializer deserializer = new XmlDeserializer();
+ string resultMessage = "";
+ List results;
+ var input = (DamKernelInput) kernelDataInput;
+ calculator.PostProcess(input, kernelDataOutput, resultMessage, out results);
+ //string results = "";
+ job.SafetyFactor = results[0].SafetyFactor.Value;
+ job.CalculationResult = results[0].CalculationResult;
+ job.RegionalResultType = RegionalResultType.SafetyFactor;
+//XmlDeserializer deserializer = new XmlDeserializer();
// RegionalResult result = (RegionalResult)deserializer.XmlDeserializeFromString(results, typeof(RegionalResult));
-// job.SafetyFactor = result.SafetyFactor;
-// job.ProbabilityOfFailure = result.ProbabilityOfFailure;
-// job.RegionalResultType = result.RegionalResultType;
-// job.CalculationResult = result.CalculationResult;
+ // job.SafetyFactor = result.SafetyFactor;
+ // job.ProbabilityOfFailure = result.ProbabilityOfFailure;
+ // job.RegionalResultType = result.RegionalResultType;
+ // job.CalculationResult = result.CalculationResult;
}
else
{
-// job.RegionalResultType = (damCalculation.FailureMechanismParametersMStab.MStabParameters.IsProbabilistic ? RegionalResultType.ProbabilityOfFailure : RegionalResultType.SafetyFactor);
+ job.RegionalResultType = (currentSpecification.FailureMechanismParametersMStab.MStabParameters.IsProbabilistic ? RegionalResultType.ProbabilityOfFailure : RegionalResultType.SafetyFactor);
job.SafetyFactor = double.NaN;
job.ProbabilityOfFailure = double.NaN;
}
lock (runningJobs)
{
-// runningJobs.Remove(calculator);
+ runningJobs.Remove(calculator);
}
}
@@ -535,7 +735,7 @@
}
// scenariosResult are the results of all scenarios for one location.
- this.evaluationJob.Results.Add(scenariosResult);
+ evaluationJob.Results.Add(scenariosResult);
}
catch (Exception e)