Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesDesign/DesignCalculator.cs =================================================================== diff -u -r1024 -r1040 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesDesign/DesignCalculator.cs (.../DesignCalculator.cs) (revision 1024) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesDesign/DesignCalculator.cs (.../DesignCalculator.cs) (revision 1040) @@ -22,12 +22,15 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; 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.Geometry; +using Deltares.DamEngine.Data.Geotechnics; using Deltares.DamEngine.Data.Standard.Logging; namespace Deltares.DamEngine.Calculators.DikesDesign @@ -86,12 +89,12 @@ switch (analysisType) { case AnalysisType.AdaptGeometry: -// PerformDesignCalculation(kernelWrapper, kernelDataInput, kernelDataOutput, -// damKernelInput, calculationMessages, damProjectData.DesignCalculations); -// break; + PerformDesignCalculation(kernelWrapper, kernelDataInput, kernelDataOutput, + damKernelInput, calculationMessages, damProjectData.DesignCalculations); + break; case AnalysisType.NoAdaption: PerformSingleCalculation(kernelWrapper, kernelDataInput, kernelDataOutput, - damKernelInput, calculationMessages, damProjectData.DesignCalculations); + damKernelInput, calculationMessages, damProjectData.DesignCalculations); break; } @@ -101,18 +104,18 @@ if (prepareResult == PrepareResult.NotRelevant) { calculationMessages.Add(new LogMessage(LogMessageType.Info, null, - string.Format(Resources.DesignCalculatorIrrelevant, - location.Name, - soiProfileProbability.ToString(), - damKernelInput.DesignScenario.LocationScenarioID))); + string.Format(Resources.DesignCalculatorIrrelevant, + location.Name, + soiProfileProbability.ToString(), + damKernelInput.DesignScenario.LocationScenarioID))); } if (prepareResult == PrepareResult.Failed) { calculationMessages.Add(new LogMessage(LogMessageType.Error, null, - string.Format(Resources.DesignCalculatorPrepareError, - location.Name, - soiProfileProbability.ToString(), - damKernelInput.DesignScenario.LocationScenarioID))); + string.Format(Resources.DesignCalculatorPrepareError, + location.Name, + soiProfileProbability.ToString(), + damKernelInput.DesignScenario.LocationScenarioID))); } } @@ -174,7 +177,7 @@ } private static void PerformSingleCalculation(IKernelWrapper kernelWrapper, IKernelDataInput kernelDataInput, IKernelDataOutput kernelDataOutput, DamKernelInput damKernelInput, - List calculationMessages, List designCalculations) + List calculationMessages, List designCalculations) { // Perform validation List locationCalculationMessages = new List(); @@ -211,10 +214,78 @@ } } + /// + /// Ensures that the points on the surface line are never more than cDiff (0.5) apart. + /// + /// + /// + private static IEnumerable GetCheckedSurfaceLine(IEnumerable originalLine) + { + const double cDiff = 0.5; + var newLine = new List(); + double X = originalLine.First().X; + foreach (var point in originalLine) + { + while (point.X > X + cDiff) + { + var newPoint = new GeometryPoint(point) + { + X = X + cDiff + }; + if (newPoint.X > newLine.Last().X) + { + newPoint.Z = newLine.Last().Z + ((newPoint.X - newLine.Last().X) / (point.X - newLine.Last().X)) * + (point.Z - newLine.Last().Z); + newLine.Add(newPoint); + } + X = newPoint.X; + } + newLine.Add(point); + } + return newLine; + } + private static void PerformDesignCalculation(IKernelWrapper kernelWrapper, IKernelDataInput kernelDataInput, IKernelDataOutput kernelDataOutput, DamKernelInput damKernelInput, List calculationMessages, List designCalculations) { - + List locationCalculationMessages = new List(); + var surfaceLine = damKernelInput.Location.SurfaceLine; + GeometryPoint startSurfacePoint = surfaceLine.GetDikeToeInward(); + + IEnumerable relevantSurfacePointsList = from GeometryPoint point in surfaceLine.Geometry.Points + where point.X >= startSurfacePoint.X + orderby point.X ascending + select point; + relevantSurfacePointsList = GetCheckedSurfaceLine(relevantSurfacePointsList); + double oldDesiredShoulderLength = 0.0; + double desiredShoulderLength; + double desiredShoulderHeight; + double oldDesiredShoulderHeight = 0.0; + int pointCount = 0; + foreach (var point in relevantSurfacePointsList) + { + pointCount++; + // Determine calculation filename to output piping calculation file + //pipingCalculator.PipingCalculationDirectory = GetPipingCalculationBaseDirectory(); + //string fileNameCalculation =String.Format("Calc({0})_Loc({1})_Pro({2})_Pnt({3}))", + // pipingCalculator.CalculationModelIdentifier, scenario.Location.Name, soilProfileProbability.SoilProfile.Name, pointCount.ToString("d4")); ; + //pipingCalculator.FilenameCalculation = Path.Combine(pipingCalculator.PipingCalculationDirectory, fileNameCalculation); + + // Calculate the piping design at the given point. This returns the required adaption (berm length and height) if any. + var pipingDesign = kernelWrapper.CalculateDesignAtPoint(damKernelInput, kernelDataInput, kernelDataOutput, point, out locationCalculationMessages); + if (pipingDesign != null) + { + // Piping is an issue so adapt the surfaceline for it + desiredShoulderLength = pipingDesign.ShoulderLengthFromToe; + desiredShoulderLength = Math.Max(desiredShoulderLength, oldDesiredShoulderLength); + oldDesiredShoulderLength = desiredShoulderLength; + // shoulder height is height above surfacelevel!! + desiredShoulderHeight = pipingDesign.ShoulderHeightFromToe; + desiredShoulderHeight = Math.Max(desiredShoulderHeight, oldDesiredShoulderHeight); + oldDesiredShoulderHeight = desiredShoulderHeight; + + } + } } } }