Index: dam engine/branches/Initial Source/Deltares.DamEngine.Calculators/General/DamProjectCalculator.cs =================================================================== diff -u -r303 -r330 --- dam engine/branches/Initial Source/Deltares.DamEngine.Calculators/General/DamProjectCalculator.cs (.../DamProjectCalculator.cs) (revision 303) +++ dam engine/branches/Initial Source/Deltares.DamEngine.Calculators/General/DamProjectCalculator.cs (.../DamProjectCalculator.cs) (revision 330) @@ -27,12 +27,19 @@ using System.Linq; using System.Threading.Tasks; using System.Xml.Serialization; +using Deltares.DamEngine.Calculators.Uplift; using Deltares.DamEngine.Data.Design; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.General.PlLines; +using Deltares.DamEngine.Data.General.TimeSeries; using Deltares.DamEngine.Data.Geometry; +using Deltares.DamEngine.Data.Geotechnics; using Deltares.DamEngine.Data.Standard.Calculation; using Deltares.DamEngine.Data.Standard.Logging; +using Deltares.DamEngine.Calculators.General; +using Deltares.DamEngine.Calculators.PlLinesCreator; +using Deltares.DamEngine.Calculators.Stability; +using Parallel = Deltares.DamEngine.Calculators.General.Parallel; namespace Deltares.DamEngine.Calculators { @@ -186,7 +193,7 @@ SurfaceLine = surfaceLine, SoilProfile = soilProfile, SoilGeometry2DName = soilGeometry2DName, - SoilBaseDB = location.SoilbaseDB, + //SoilBaseDB = location.SoilbaseDB, SoilList = location.SoilList, DikeEmbankmentMaterial = location.GetDikeEmbankmentSoil(), PLLines = plLines, @@ -222,122 +229,120 @@ var scenario = (Scenario) scenarioTask; var scenarioName = scenario.Location.Name; Debug.WriteLine(String.Format("Start thread for location '{0}'", scenarioName)); - DataEventPublisher.InvokeWithoutPublishingEvents(() => + + Location oldLocation = null; + + try { - Location oldLocation = null; + oldLocation = scenario.Location; + var scenarioId = scenario.LocationScenarioID; + Debug.WriteLine("Location '{0}', scenario '{1}'", scenarioName, scenarioId); + scenario.ClearResults(); + scenario.ClearErrors(); - try + CloneLocationOnScenario(scenario); + + if (scenario.PlLineOffsetBelowDikeToeAtPolder.HasValue) { - oldLocation = scenario.Location; - var scenarioId = scenario.LocationScenarioID; - Debug.WriteLine("Location '{0}', scenario '{1}'", scenarioName, scenarioId); - scenario.ClearResults(); - scenario.ClearErrors(); + scenario.Location.PlLineOffsetBelowDikeToeAtPolder = scenario.PlLineOffsetBelowDikeToeAtPolder.Value; + } + if (scenario.PlLineOffsetBelowDikeTopAtPolder.HasValue) + { + scenario.Location.PlLineOffsetBelowDikeTopAtPolder = scenario.PlLineOffsetBelowDikeTopAtPolder.Value; + } + if (scenario.PlLineOffsetBelowDikeTopAtRiver.HasValue) + { + scenario.Location.PlLineOffsetBelowDikeTopAtRiver = scenario.PlLineOffsetBelowDikeTopAtRiver.Value; + } + if (scenario.PlLineOffsetBelowShoulderBaseInside.HasValue) + { + scenario.Location.PlLineOffsetBelowShoulderBaseInside = scenario.PlLineOffsetBelowShoulderBaseInside.Value; + } + if (scenario.PlLineOffsetBelowDikeCrestMiddle.HasValue) + { + scenario.Location.PlLineOffsetBelowDikeCrestMiddle = scenario.PlLineOffsetBelowDikeCrestMiddle; + } + if (scenario.PlLineOffsetFactorBelowShoulderCrest.HasValue) + { + scenario.Location.PlLineOffsetFactorBelowShoulderCrest = scenario.PlLineOffsetFactorBelowShoulderCrest; + } + if (scenario.UsePlLineOffsetBelowDikeCrestMiddle.HasValue) + { + scenario.Location.UsePlLineOffsetBelowDikeCrestMiddle = scenario.UsePlLineOffsetBelowDikeCrestMiddle; + } + if (scenario.UsePlLineOffsetFactorBelowShoulderCrest.HasValue) + { + scenario.Location.UsePlLineOffsetFactorBelowShoulderCrest = scenario.UsePlLineOffsetFactorBelowShoulderCrest; + } + if (scenario.HeadPl3.HasValue) + { + scenario.Location.HeadPl3 = scenario.HeadPl3.Value; + } + if (scenario.HeadPl4.HasValue) + { + scenario.Location.HeadPl4 = scenario.HeadPl4.Value; + } - CloneLocationOnScenario(scenario); + var selectedKernelType = StabilityKernelType.DamClassic; + var damProjectCalculationSpecification = damProjectData.DamProjectCalculationSpecification; + var spec = damProjectCalculationSpecification.DamCalculationSpecifications.First(); + if (spec != null) + { + selectedKernelType = spec.StabilityKernelType; + } + if (DetermineStabilityUpliftForScenarios(scenario, selectedKernelType)) + { - if (scenario.PlLineOffsetBelowDikeToeAtPolder.HasValue) - { - scenario.Location.PlLineOffsetBelowDikeToeAtPolder = scenario.PlLineOffsetBelowDikeToeAtPolder.Value; - } - if (scenario.PlLineOffsetBelowDikeTopAtPolder.HasValue) - { - scenario.Location.PlLineOffsetBelowDikeTopAtPolder = scenario.PlLineOffsetBelowDikeTopAtPolder.Value; - } - if (scenario.PlLineOffsetBelowDikeTopAtRiver.HasValue) - { - scenario.Location.PlLineOffsetBelowDikeTopAtRiver = scenario.PlLineOffsetBelowDikeTopAtRiver.Value; - } - if (scenario.PlLineOffsetBelowShoulderBaseInside.HasValue) - { - scenario.Location.PlLineOffsetBelowShoulderBaseInside = scenario.PlLineOffsetBelowShoulderBaseInside.Value; - } - if (scenario.PlLineOffsetBelowDikeCrestMiddle.HasValue) - { - scenario.Location.PlLineOffsetBelowDikeCrestMiddle = scenario.PlLineOffsetBelowDikeCrestMiddle; - } - if (scenario.PlLineOffsetFactorBelowShoulderCrest.HasValue) - { - scenario.Location.PlLineOffsetFactorBelowShoulderCrest = scenario.PlLineOffsetFactorBelowShoulderCrest; - } - if (scenario.UsePlLineOffsetBelowDikeCrestMiddle.HasValue) - { - scenario.Location.UsePlLineOffsetBelowDikeCrestMiddle = scenario.UsePlLineOffsetBelowDikeCrestMiddle; - } - if (scenario.UsePlLineOffsetFactorBelowShoulderCrest.HasValue) - { - scenario.Location.UsePlLineOffsetFactorBelowShoulderCrest = scenario.UsePlLineOffsetFactorBelowShoulderCrest; - } - if (scenario.HeadPl3.HasValue) - { - scenario.Location.HeadPl3 = scenario.HeadPl3.Value; - } - if (scenario.HeadPl4.HasValue) - { - scenario.Location.HeadPl4 = scenario.HeadPl4.Value; - } + // Save the results after each calculation, because these will be deleted in the next calculation + var calculationresults = new List(); - var selectedKernelType = StabilityKernelType.DamClassic; - var damProjectCalculationSpecification = damProjectData.DamProjectCalculationSpecification; - var spec = damProjectCalculationSpecification.DamCalculationSpecifications.First(); - if (spec != null) + foreach (var calculationSpecification in damProjectCalculationSpecification.DamCalculationSpecifications) { - selectedKernelType = spec.StabilityKernelType; - } - if (DetermineStabilityUpliftForScenarios(scenario, selectedKernelType)) - { + var selectedProbabilisticType = damProjectCalculationSpecification.SelectedProbabilisticType; + var analysisType = DamProjectCalculationSpecification.SelectedAnalysisType; - // Save the results after each calculation, because these will be deleted in the next calculation - var calculationresults = new List(); - - foreach (var calculationSpecification in damProjectCalculationSpecification.DamCalculationSpecifications) + Debug.WriteLine("Location '{0}', scenario '{1}' 10", scenarioName, scenarioId); + ValidateSpecification(); + if (IsStabilityBishopLiftVanCalculation(calculationSpecification)) { - var selectedProbabilisticType = damProjectCalculationSpecification.SelectedProbabilisticType; - var analysisType = DamProjectCalculationSpecification.SelectedAnalysisType; - - Debug.WriteLine("Location '{0}', scenario '{1}' 10", scenarioName, scenarioId); - ValidateSpecification(); - if (IsStabilityBishopLiftVanCalculation(calculationSpecification)) - { - Debug.WriteLine("Location '{0}', scenario '{1}' 11", scenarioName, scenarioId); - CalculateStabilityBishopUpliftvanForScenario(scenario, calculationSpecification, selectedProbabilisticType, analysisType); - } - else - { - Debug.WriteLine("Location '{0}', scenario '{1}' 15", scenarioName, scenarioId); - CalculateOneCalculationTypeForScenario(scenario, calculationSpecification, selectedProbabilisticType, analysisType); - } - Debug.WriteLine("Location '{0}', scenario '{1}' 20", scenarioName, scenarioId); - calculationresults.AddRange(scenario.CalculationResults); + Debug.WriteLine("Location '{0}', scenario '{1}' 11", scenarioName, scenarioId); + CalculateStabilityBishopUpliftvanForScenario(scenario, calculationSpecification, selectedProbabilisticType, analysisType); } - // Assign the combined results to the scenario - scenario.CalculationResults.Clear(); - scenario.CalculationResults.AddRange(calculationresults); + else + { + Debug.WriteLine("Location '{0}', scenario '{1}' 15", scenarioName, scenarioId); + CalculateOneCalculationTypeForScenario(scenario, calculationSpecification, selectedProbabilisticType, analysisType); + } + Debug.WriteLine("Location '{0}', scenario '{1}' 20", scenarioName, scenarioId); + calculationresults.AddRange(scenario.CalculationResults); } - + // Assign the combined results to the scenario + scenario.CalculationResults.Clear(); + scenario.CalculationResults.AddRange(calculationresults); } - catch (Exception exception) + + } + catch (Exception exception) + { + scenario.Errors.Add(exception.Message); + } + finally + { + if( oldLocation != null) { - scenario.Errors.Add(exception.Message); + scenario.Location = oldLocation; } - finally - { - if( oldLocation != null) - { - scenario.Location = oldLocation; - } - } - }); + } } private void CloneLocationOnScenario(Scenario scenario) { lock (lockObject) { - // TODO missing clone method for Location. This is a dirty way of performing a clone. - var locationUsedInCalculation = new XmlSerializer().SerializeToString(scenario.Location); - var location = new XmlDeserializer().XmlDeserializeFromString(locationUsedInCalculation); - scenario.Location = location; +// // TODO missing clone method for Location. This is a dirty way of performing a clone. +// var locationUsedInCalculation = new XmlSerializer().SerializeToString(scenario.Location); +// var location = new XmlDeserializer().XmlDeserializeFromString(locationUsedInCalculation); +// scenario.Location = location; ##Bka replace with object copier. } } @@ -434,7 +439,7 @@ } foreach (var errorMessage in damFailureMechanismeCalculator.ErrorMessages) { - LogManager.Messages.Add(errorMessage); + //LogManager.Messages.Add(errorMessage);##Bka } var recordIndex = 0; @@ -533,11 +538,11 @@ foreach (var error in scenario.Errors) { var logMessage = new LogMessage(LogMessageType.Error, null, error); - LogManager.Messages.Add(logMessage); + //LogManager.Messages.Add(logMessage);##Bka } foreach (var errorMessage in damFailureMechanismeCalculator.ErrorMessages) { - LogManager.Messages.Add(errorMessage); + // LogManager.Messages.Add(errorMessage);##Bka } foreach (var soilProfileProbability in scenario.Location.Segment.SoilProfileProbabilities) @@ -628,7 +633,7 @@ foreach (var error in scenario.Errors) { var logMessage = new LogMessage(LogMessageType.Error, null, error); - LogManager.Messages.Add(logMessage); + //LogManager.Messages.Add(logMessage); ##Bka } return res; } @@ -854,9 +859,9 @@ case PLLineCreationMethod.ExpertKnowledgeRRD: case PLLineCreationMethod.GaugesWithFallbackToExpertKnowledgeRRD: return CreateAllPLLinesExpertKnowledge(out upliftSituation, waterLevel, waterLevelLow, location, soilProfileProbability, surfaceLine); - case PLLineCreationMethod.DupuitStatic: - string geometryDirectory = DamProject.ProjectWorkingPath; - return CreateAllPLLinesDupuit(out upliftSituation, location, soilProfileProbability, surfaceLine, geometryDirectory, waterLevel); +// case PLLineCreationMethod.DupuitStatic: +// string geometryDirectory = DamProjectData.ProjectWorkingPath; +// return CreateAllPLLinesDupuit(out upliftSituation, location, soilProfileProbability, surfaceLine, geometryDirectory, waterLevel); ##Bka case PLLineCreationMethod.DupuitDynamic: throw new DamCalculationException("PL-Line creation with DupuitDynamic not yet implemented"); default: @@ -875,33 +880,33 @@ /// Create PLLines with Dupuit model /// /// the created pl lines - private PLLines CreateAllPLLinesDupuit(out UpliftSituation upliftSituation, Location location, SoilGeometryProbability soilProfileProbability, - SurfaceLine2 surfaceLine, String geometryDirectory, double waterLevel) - { - var timeSerieIn = new TimeSerie(); - timeSerieIn.Entries.Add(new TimeSerieEntry(DateTime.Now, waterLevel)); - var plLinesCreatorDupuit = new PLLinesCreatorDupuit - { - Geometry2DData = Geometry2DDataCreator.CreateGeometry2DData(location, soilProfileProbability, surfaceLine, geometryDirectory), - SurfaceLine = location.LocalXZSurfaceLine2, - WaterLevelTimeserie = timeSerieIn, - SoilList = location.SoilList, - PolderLevel = location.PolderLevel, - IsReverseLayerOrder = true - }; +// private PLLines CreateAllPLLinesDupuit(out UpliftSituation upliftSituation, Location location, SoilGeometryProbability soilProfileProbability, +// SurfaceLine2 surfaceLine, String geometryDirectory, double waterLevel) +// { +// var timeSerieIn = new TimeSerie(); +// timeSerieIn.Entries.Add(new TimeSerieEntry(DateTime.Now, waterLevel)); +// var plLinesCreatorDupuit = new PLLinesCreatorDupuit +// { +// Geometry2DData = Geometry2DDataCreator.CreateGeometry2DData(location, soilProfileProbability, surfaceLine, geometryDirectory), +// SurfaceLine = location.LocalXZSurfaceLine2, +// WaterLevelTimeserie = timeSerieIn, +// SoilList = location.SoilList, +// PolderLevel = location.PolderLevel, +// IsReverseLayerOrder = true +// }; +// +// upliftSituation.Pl3HeadAdjusted = 0; +// upliftSituation.Pl3LocationXMinUplift = 0; +// upliftSituation.Pl3MinUplift = 0; +// upliftSituation.Pl4HeadAdjusted = 0; +// upliftSituation.Pl4LocationXMinUplift = 0; +// upliftSituation.Pl4MinUplift = 0; +// upliftSituation.IsUplift = false; // must be determined later on; just to avoid compiler error +// plLinesCreatorDupuit.CreateAllPlLines(); +// +// return null; +// } - upliftSituation.Pl3HeadAdjusted = 0; - upliftSituation.Pl3LocationXMinUplift = 0; - upliftSituation.Pl3MinUplift = 0; - upliftSituation.Pl4HeadAdjusted = 0; - upliftSituation.Pl4LocationXMinUplift = 0; - upliftSituation.Pl4MinUplift = 0; - upliftSituation.IsUplift = false; // must be determined later on; just to avoid compiler error - plLinesCreatorDupuit.CreateAllPlLines(); - - return null; - } - /// /// Create PLLines with expert knowledge /// @@ -944,7 +949,6 @@ plLinesCreator.Gauges = location.Gauges; plLinesCreator.GaugeMissVal = location.GaugeMissVal; plLinesCreator.IsAdjustPL3AndPL4SoNoUpliftWillOccurEnabled = true; // for stability this must set to true - plLinesCreator.SoilBaseDB = location.SoilbaseDB; plLinesCreator.SoilList = location.SoilList; plLinesCreator.DikeEmbankmentMaterial = location.SoilList.GetSoilByName(location.DikeEmbankmentMaterial); plLinesCreator.PlLineOffsetBelowDikeTopAtRiver = location.PlLineOffsetBelowDikeTopAtRiver; @@ -957,15 +961,15 @@ plLinesCreator.UsePlLineOffsetFactorBelowShoulderCrest = location.UsePlLineOffsetFactorBelowShoulderCrest; plLinesCreator.XSoilGeometry2DOrigin = location.XSoilGeometry2DOrigin; - PLLines plLines = plLinesCreator.CreateAllPLLines(location); + //PLLines plLines = plLinesCreator.CreateAllPLLines(location); ##Bka upliftSituation.Pl3HeadAdjusted = plLinesCreator.Pl3HeadAdjusted; upliftSituation.Pl3LocationXMinUplift = plLinesCreator.Pl3LocationXMinUplift; upliftSituation.Pl3MinUplift = plLinesCreator.Pl3MinUplift; upliftSituation.Pl4HeadAdjusted = plLinesCreator.Pl4HeadAdjusted; upliftSituation.Pl4LocationXMinUplift = plLinesCreator.Pl4LocationXMinUplift; upliftSituation.Pl4MinUplift = plLinesCreator.Pl4MinUplift; upliftSituation.IsUplift = false; // must be determined later on; just to avoid compiler error - return plLines; + return null; //plLines; ##Bka } } } \ No newline at end of file