Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesDesign/DesignCalculator.cs =================================================================== diff -u -r1432 -r1465 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesDesign/DesignCalculator.cs (.../DesignCalculator.cs) (revision 1432) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesDesign/DesignCalculator.cs (.../DesignCalculator.cs) (revision 1465) @@ -70,84 +70,96 @@ for (int designScenarioIndex = 0; designScenarioIndex < location.Scenarios.Count; designScenarioIndex++) { DesignScenario designScenario = location.Scenarios[designScenarioIndex]; - try - { - // 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 = soiProfileProbability; - damKernelInput.DamFailureMechanismeCalculationSpecification = damProjectData.DamProjectCalculationSpecification.CurrentSpecification; - damKernelInput.RiverLevelHigh = designScenario.RiverLevel; - damKernelInput.RiverLevelLow = designScenario.RiverLevelLow; - damKernelInput.FilenamePrefix = String.Format("Loc({0})_Sce({1})", designScenario.Location.Name, designScenario.LocationScenarioID); - AnalysisType analysisType = DamProjectCalculationSpecification.SelectedAnalysisType; - SynchronizeScenarioDataWithLocationData(designScenario, location); - IKernelDataInput kernelDataInput; - IKernelDataOutput kernelDataOutput; + var projectPath = damProjectData.ProjectPath != "" ? damProjectData.ProjectPath : Directory.GetCurrentDirectory(); + var designResults = new List(); + var calculationMessages = new List(); + CalculateOneScenario(location, soiProfileProbability, designScenario, projectPath, damProjectData.CalculationMap, + damProjectData.DamProjectCalculationSpecification.CurrentSpecification, + designResults, calculationMessages); + damProjectData.CalculationMessages.AddRange(calculationMessages); + damProjectData.DesignCalculations.AddRange(designResults); + } + current++; + progressDelegate?.Invoke(Convert.ToDouble(current) / Convert.ToDouble(total)); + } + } + } - // Create kernelwrapper - IKernelWrapper kernelWrapper = KernelWrapperHelper.CreateKernelWrapper(damProjectData.DamProjectCalculationSpecification.CurrentSpecification); - if (kernelWrapper == null) - { - throw new NotImplementedException(Resources.DesignCalculatorKernelNotImplemented); - } + private void CalculateOneScenario(Location location, SoilGeometryProbability soiProfileProbability, DesignScenario designScenario, + string projectPath, string calculationMap, DamFailureMechanismeCalculationSpecification damFailureMechanismeCalculationSpecification, + List designResults, List calculationMessages) + { + try + { + // Prepare input + var damKernelInput = new DamKernelInput(); + damKernelInput.ProjectDir = projectPath; + damKernelInput.CalculationDir = Path.Combine(projectPath, calculationMap); + damKernelInput.Location = location; + damKernelInput.SubSoilScenario = soiProfileProbability; + damKernelInput.DamFailureMechanismeCalculationSpecification = damFailureMechanismeCalculationSpecification; + damKernelInput.RiverLevelHigh = designScenario.RiverLevel; + damKernelInput.RiverLevelLow = designScenario.RiverLevelLow; + damKernelInput.FilenamePrefix = String.Format("Loc({0})_Sce({1})", designScenario.Location.Name, designScenario.LocationScenarioID); + AnalysisType analysisType = DamProjectCalculationSpecification.SelectedAnalysisType; + SynchronizeScenarioDataWithLocationData(designScenario, location); + IKernelDataInput kernelDataInput; + IKernelDataOutput kernelDataOutput; - PrepareResult prepareResult = kernelWrapper.Prepare(damKernelInput, 0, out kernelDataInput, out kernelDataOutput); + // Create kernelwrapper + IKernelWrapper kernelWrapper = KernelWrapperHelper.CreateKernelWrapper(damFailureMechanismeCalculationSpecification); + if (kernelWrapper == null) + { + throw new NotImplementedException(Resources.DesignCalculatorKernelNotImplemented); + } - // 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, designScenario, damProjectData.CalculationMessages, - damProjectData.DesignCalculations); - break; - case AnalysisType.NoAdaption: - DesignCalculatorSingle.PerformSingleCalculation( - kernelWrapper, kernelDataInput, kernelDataOutput, - damKernelInput, designScenario, damProjectData.CalculationMessages, - damProjectData.DesignCalculations); - break; + PrepareResult prepareResult = kernelWrapper.Prepare(damKernelInput, 0, out kernelDataInput, out kernelDataOutput); - } - } - else - { - if (prepareResult == PrepareResult.NotRelevant) - { - // Do nothing. Calculation will be skipped. - } - if (prepareResult == PrepareResult.Failed) - { - damProjectData.CalculationMessages.Add(new LogMessage(LogMessageType.Error, null, - string.Format(Resources.DesignCalculatorPrepareError, - location.Name, - soiProfileProbability, - designScenario.LocationScenarioID))); - } - } - } - catch (Exception e) - { - damProjectData.CalculationMessages.Add(new LogMessage(LogMessageType.Error, null, - string.Format(Resources.DesignCalculatorGeneralException, - location.Name, - soiProfileProbability, - designScenario.LocationScenarioID, - e.Message))); - } + // 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, designScenario, calculationMessages, + designResults); + break; + case AnalysisType.NoAdaption: + DesignCalculatorSingle.PerformSingleCalculation( + kernelWrapper, kernelDataInput, kernelDataOutput, + damKernelInput, designScenario, calculationMessages, + designResults); + break; } - current++; - progressDelegate?.Invoke(Convert.ToDouble(current) / Convert.ToDouble(total)); } + else + { + if (prepareResult == PrepareResult.NotRelevant) + { + // Do nothing. Calculation will be skipped. + } + if (prepareResult == PrepareResult.Failed) + { + calculationMessages.Add(new LogMessage(LogMessageType.Error, null, + string.Format(Resources.DesignCalculatorPrepareError, + location.Name, + soiProfileProbability, + designScenario.LocationScenarioID))); + } + } } + catch (Exception e) + { + calculationMessages.Add(new LogMessage(LogMessageType.Error, null, + string.Format(Resources.DesignCalculatorGeneralException, + location.Name, + soiProfileProbability, + designScenario.LocationScenarioID, + e.Message))); + } } ///