Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesDesign/DesignCalculator.cs =================================================================== diff -u -r1052 -r1075 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesDesign/DesignCalculator.cs (.../DesignCalculator.cs) (revision 1052) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesDesign/DesignCalculator.cs (.../DesignCalculator.cs) (revision 1075) @@ -283,84 +283,95 @@ private static void PerformDesignCalculation(IKernelWrapper kernelWrapper, IKernelDataInput kernelDataInput, IKernelDataOutput kernelDataOutput, DamKernelInput damKernelInput, List calculationMessages, List designCalculations) { - List locationCalculationMessages = new List(); - var location = damKernelInput.Location; - var surfaceLine = location.SurfaceLine; - double orgShoulderLength = surfaceLine.DetermineShoulderWidth(); - double orgShoulderHeight = surfaceLine.DetermineShoulderHeight(); + var designResults = new List(); + try + { + List locationCalculationMessages = new List(); + var location = damKernelInput.Location; + var surfaceLine = location.SurfaceLine; + double orgShoulderLength = surfaceLine.DetermineShoulderWidth(); + double orgShoulderHeight = surfaceLine.DetermineShoulderHeight(); - GeometryPoint startSurfacePoint = surfaceLine.GetDikeToeInward(); + 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 = 0.0; - double desiredShoulderHeight = 0.0; - double oldDesiredShoulderHeight = 0.0; - int pointCount = 0; - foreach (var point in relevantSurfacePointsList) - { - pointCount++; + 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 = 0.0; + double desiredShoulderHeight = 0.0; + double oldDesiredShoulderHeight = 0.0; + int pointCount = 0; + foreach (var point in relevantSurfacePointsList) + { + pointCount++; - // 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) + // 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; + } + + } + if (desiredShoulderLength > 0) { - // 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; + desiredShoulderLength = Math.Max(desiredShoulderLength, CMinimumShoulderWidth); } + if (desiredShoulderLength > 0) + { + desiredShoulderHeight = Math.Max(desiredShoulderHeight, CMinimumShoulderElevation); + } + bool isNewShoulderSameAsOriginal = ((Math.Abs(desiredShoulderLength - orgShoulderLength) < CToleranceShoulderChanges) && + (Math.Abs(desiredShoulderHeight - orgShoulderHeight) < CToleranceShoulderChanges)); + SurfaceLine2 newSurfaceLine = null; + if (isNewShoulderSameAsOriginal) + { + newSurfaceLine = surfaceLine; + } + else + { + // Adapt the surfaceline for the finally required shoulder dimensions. + double maxShoulderLevel = CalculateMaximumShoulderLevel(surfaceLine, 1.0); // no limit to height of shoulder + var surfaceLineShoulderAdapter = new SurfaceLineShoulderAdapter(surfaceLine, location); + surfaceLineShoulderAdapter.MaxShoulderLevel = maxShoulderLevel; + newSurfaceLine = surfaceLineShoulderAdapter.ConstructNewSurfaceLine(desiredShoulderLength, desiredShoulderHeight, true); + } + damKernelInput.Location.SurfaceLine = newSurfaceLine; + kernelWrapper.Prepare(damKernelInput, 0, out kernelDataInput, out kernelDataOutput); + kernelWrapper.Execute(kernelDataInput, kernelDataOutput, out locationCalculationMessages); + // Process output + calculationMessages.AddRange(locationCalculationMessages); + StringBuilder sb = new StringBuilder(); + foreach (var message in locationCalculationMessages) + { + sb.Append(message.Message + Environment.NewLine); + } + string resultMessage = sb.ToString(); + kernelWrapper.PostProcess(damKernelInput, kernelDataOutput, resultMessage, out designResults); } - if (desiredShoulderLength > 0) + catch (Exception exception) { - desiredShoulderLength = Math.Max(desiredShoulderLength, CMinimumShoulderWidth); + string resultMessage = exception.Message; + kernelWrapper.PostProcess(damKernelInput, kernelDataOutput, resultMessage, out designResults); } - if (desiredShoulderLength > 0) + finally { - desiredShoulderHeight = Math.Max(desiredShoulderHeight, CMinimumShoulderElevation); + foreach (var designResult in designResults) + { + designCalculations.Add(designResult); + } } - bool isNewShoulderSameAsOriginal = ((Math.Abs(desiredShoulderLength - orgShoulderLength) < CToleranceShoulderChanges) && - (Math.Abs(desiredShoulderHeight - orgShoulderHeight) < CToleranceShoulderChanges)); - SurfaceLine2 newSurfaceLine = null; - if (isNewShoulderSameAsOriginal) - { - newSurfaceLine = surfaceLine; - } - else - { - // Adapt the surfaceline for the finally required shoulder dimensions. - double maxShoulderLevel = CalculateMaximumShoulderLevel(surfaceLine, 1.0); // no limit to height of shoulder - var surfaceLineShoulderAdapter = new SurfaceLineShoulderAdapter(surfaceLine, location); - surfaceLineShoulderAdapter.MaxShoulderLevel = maxShoulderLevel; - newSurfaceLine = surfaceLineShoulderAdapter.ConstructNewSurfaceLine(desiredShoulderLength, desiredShoulderHeight, true); - - } - damKernelInput.Location.SurfaceLine = newSurfaceLine; - kernelWrapper.Prepare(damKernelInput, 0, out kernelDataInput, out kernelDataOutput); - kernelWrapper.Execute(kernelDataInput, kernelDataOutput, out locationCalculationMessages); - // Process output - calculationMessages.AddRange(locationCalculationMessages); - List designResults; - StringBuilder sb = new StringBuilder(); - foreach (var message in locationCalculationMessages) - { - sb.Append(message.Message + Environment.NewLine); - } - string resultMessage = sb.ToString(); - kernelWrapper.PostProcess(damKernelInput, kernelDataOutput, resultMessage, out designResults); - foreach (var designResult in designResults) - { - designCalculations.Add(designResult); - } // safetyFactor = pipingCalculator.CalculatePipingFactor(location, newSurfaceLine, soilProfileProbability.SoilProfile, scenario.RiverLevel); // if (safetyFactor < scenario.RequiredSafetyFactorPiping) // {