using System.Collections.Generic; using System.Linq; using Deltares.WTIPiping; using Wti.Calculation.Properties; namespace Wti.Calculation.Piping { /// /// This class represents a combination of piping sub-calculations, which together can be used /// to assess based on piping. /// public class PipingCalculation { private readonly PipingCalculationInput input; /// /// Constructs a new . The is used to /// obtain the parameters used in the different sub calculations. /// /// The containing all the values required /// for performing a piping calculation. public PipingCalculation(PipingCalculationInput input) { this.input = input; } /// /// Performs the actual sub calculations and returns a , which /// contains the results of all sub calculations. /// /// A containing the results of the sub calculations. /// Thrown when any of the invocations of the sub-calculations from the kernel throws an Exception. public PipingCalculationResult Calculate() { var upliftResult = CalculateUplift(); var heaveResult = CalculateHeave(); var sellmeijerResult = CalculateSellmeijer(); return new PipingCalculationResult( upliftResult.Zu, upliftResult.FoSu, heaveResult.Zh, heaveResult.FoSh, sellmeijerResult.Zp, sellmeijerResult.FoSp ); } /// /// Returns a list of validation messages. The validation messages are based on the values of the /// which was provided to this and are determined by the Piping kernel. /// public List Validate() { List upliftCalculatorValidationResults = input.SurfaceLine != null ? CreateUpliftCalculator().Validate() : new List(new[] { Resources.PipingCalculation_Validate_Lacks_surfaceline_uplift }); List heaveCalculatorValidationResults = CreateHeaveCalculator().Validate(); List sellmeijerCalculatorValidationResults = CreateSellmeijerCalculator().Validate(); return upliftCalculatorValidationResults.Concat(heaveCalculatorValidationResults).Concat(sellmeijerCalculatorValidationResults).ToList(); } private Sellmeijer2011Calculator CalculateSellmeijer() { Sellmeijer2011Calculator sellmeijerCalculator = CreateSellmeijerCalculator(); try { sellmeijerCalculator.Calculate(); } catch (PipingException e) { throw new PipingCalculationException(e.Message, e); } catch (PipingException e) { throw new PipingCalculationException(e.Message, e); } return sellmeijerCalculator; } private HeaveCalculator CalculateHeave() { var heaveCalculator = CreateHeaveCalculator(); try { heaveCalculator.Calculate(); } catch (PipingException e) { throw new PipingCalculationException(e.Message, e); } return heaveCalculator; } private WTIUpliftCalculator CalculateUplift() { WTIUpliftCalculator upliftCalculator = CreateUpliftCalculator(); try { upliftCalculator.Calculate(); } catch (WTIUpliftCalculatorException e) { throw new PipingCalculationException(e.Message, e); } catch (PipingException e) { throw new PipingCalculationException(e.Message, e); } return upliftCalculator; } private HeaveCalculator CreateHeaveCalculator() { var calculator = new HeaveCalculator { Ich = input.CriticalHeaveGradient, PhiExit = input.PiezometricHeadExit, DTotal = input.ThicknessCoverageLayer, PhiPolder = input.PiezometricHeadPolder, RExit = input.DampingFactorExit, HExit = input.PhreaticLevelExit }; return calculator; } private WTIUpliftCalculator CreateUpliftCalculator() { var effectiveStressResult = CalculateEffectiveThickness(); var calculator = new WTIUpliftCalculator { VolumetricWeightOfWater = input.WaterVolumetricWeight, ModelFactorUplift = input.UpliftModelFactor, EffectiveStress = effectiveStressResult.EffectiveStress, HRiver = input.AssessmentLevel, PhiExit = input.PiezometricHeadExit, RExit = input.DampingFactorExit, HExit = input.PhreaticLevelExit, PhiPolder = input.PiezometricHeadPolder }; return calculator; } private Sellmeijer2011Calculator CreateSellmeijerCalculator() { var calculator = new Sellmeijer2011Calculator { ModelFactorPiping = input.SellmeijerModelFactor, HRiver = input.AssessmentLevel, HExit = input.PhreaticLevelExit, Rc = input.SellmeijerReductionFactor, DTotal = input.ThicknessCoverageLayer, SeepageLength = input.SeepageLength, GammaSubParticles = input.SandParticlesVolumicWeight, WhitesDragCoefficient = input.WhitesDragCoefficient, D70 = input.Diameter70, VolumetricWeightOfWater = input.WaterVolumetricWeight, DarcyPermeability = input.DarcyPermeability, KinematicViscosityWater = input.WaterKinematicViscosity, Gravity = input.Gravity, DAquifer = input.ThicknessAquiferLayer, D70Mean = input.MeanDiameter70, BeddingAngle = input.BeddingAngle }; return calculator; } private EffectiveThicknessCalculator CalculateEffectiveThickness() { var calculator = new EffectiveThicknessCalculator { ExitPointXCoordinate = input.ExitPointXCoordinate, PhreaticLevel = input.PhreaticLevelExit, SoilProfile = PipingProfileCreator.Create(), SurfaceLine = PipingSurfaceLineCreator.Create(input.SurfaceLine), VolumicWeightOfWater = input.WaterVolumetricWeight }; calculator.Calculate(); return calculator; } } }