public static double CalculateEND(DepthFactor depthF, BreathGas gas) { var air = new BreathGas(); var ppN = DivingMath.SeaLevelPreasureBars * BreathGas.GetGasPartialPreasureForDepth(depthF, gas.PpN); var depth = DivingMath.PreasureBarsToDepth(ppN / air.PpN, depthF.WaterDensity); return(Math.Round(depth.Depth, 1)); }
public const double WaterVapourPreasureBars = 0.023; // for t 20C public static double DepthToPreasureBars(DepthFactor depthFactor) { if (depthFactor.Depth <= 0) { return(SeaLevelPreasureBars); } if (depthFactor.WaterDensity == default(double)) { depthFactor.WaterDensity = FreshWaterDensity; } var weightDensity = depthFactor.WaterDensity * GravityG; return(SeaLevelPreasureBars + depthFactor.Depth * weightDensity / PascalsPerBar); }
private void CalculateCompartmentPresures(double time, double depth, BreathGas gas, CompartmentCalculations[] tissues = null) { var depthFact = new DepthFactor(depth, _waterDensity); double ppNitro = gas.PpN * (BreathGas.GetGasPartialPreasureForDepth(depthFact, 1.0) - DivingMath.WaterVapourPreasureBars); double ppHe = gas.PpHe * (BreathGas.GetGasPartialPreasureForDepth(depthFact, 1.0) - DivingMath.WaterVapourPreasureBars); int index = 0; foreach (var cpt in _compartments) { var data = (tissues ?? _compartmentData)[index]; var n2Koef = 1.0 - Math.Pow(2.0, -time / cpt.N2HalfTime); var heKoef = 1.0 - Math.Pow(2.0, -time / cpt.HeHalfTime); data.N2Presure = data.N2Presure + ((ppNitro - data.N2Presure) * n2Koef); data.HePresure = data.HePresure + ((ppHe - data.HePresure) * heKoef); ++index; } }
private BreathGas SelectDecoGas(DepthFactor currDepth, double decoStopDepth) { const double MaxDecoPpO = 1.6; const double OptimalDecoPpO = 1.5; if ((_diveParameters.DecoLevels?.Count() ?? 0) == 0) { return(_diveParameters.Levels.Last().Gas); } var decoPpO = MaxDecoPpO; if ((currDepth.Depth - decoStopDepth) > (DecoStopsStep + double.Epsilon)) { decoPpO = OptimalDecoPpO; } var gasesCanUse = new List <KeyValuePair <double, BreathGas> >(_diveParameters.DecoLevels.Count()); // explicit depth gases go first var explicitDepthGases = _diveParameters.DecoLevels.Where(d => d.Depth > double.Epsilon); if (explicitDepthGases.Any()) { var suitedDecoGases = explicitDepthGases.Where(d => currDepth.Depth <= d.Depth); if (!suitedDecoGases.Any()) { return(_diveParameters.Levels.Last().Gas); } var minDepth = explicitDepthGases.Where(d => currDepth.Depth <= d.Depth).Min(d => d.Depth); var explicitDecoGas = explicitDepthGases.FirstOrDefault(d => DivingMath.CompareDouble(d.Depth, minDepth)); if (explicitDecoGas != null) { return(explicitDecoGas.Gas); } else { return(_diveParameters.Levels.Last().Gas); } } else { foreach (var decoLevel in _diveParameters.DecoLevels) { var currDecoPpO = BreathGas.GetGasPartialPreasureForDepth(currDepth, decoLevel.Gas.PpO); if (currDecoPpO <= decoPpO) { gasesCanUse.Add(new KeyValuePair <double, BreathGas>(currDecoPpO, decoLevel.Gas)); } } if (gasesCanUse.Count == 0) { return(_diveParameters.Levels.Last().Gas); } return(gasesCanUse.First(g => DivingMath.CompareDouble(g.Key, gasesCanUse.Max(k => k.Key))).Value); } }