public Result.PPraeasureForCompartment GetMaxValues(bool tmx) { int compNo = compartments.compartment.Count(); Result.PPraeasureForCompartment res = new Result.PPraeasureForCompartment(compNo, tmx); foreach (Result.PPraeasureForCompartment ppfc in result) { res.AmbientPreasure = Math.Max(res.AmbientPreasure, ppfc.AmbientPreasure); res.Depth = Math.Max(res.Depth, ppfc.Depth); res.PreasureN2 = Math.Max(res.PreasureN2, ppfc.PreasureN2); if (tmx) { res.PreasureHe = Math.Max(res.PreasureHe, ppfc.PreasureHe); } res.Time = Math.Max(res.Time, ppfc.Time); int count = ppfc.Count(); for (int i = 0; i < count; i++) { res.setN2(i, Math.Max(res.getN2(i), ppfc.getN2(i))); if (tmx) { res.setHe(i, Math.Max(res.getHe(i), ppfc.getHe(i))); } } } return(res); }
public Result.PPraeasureForCompartment GetValusAtTime(double time, bool tmx) { int compNo = compartments.compartment.Count(); Result.PPraeasureForCompartment res = new Result.PPraeasureForCompartment(compNo, tmx); if (result[upperResultSerch].Time < time) { lowerResultSerch = upperResultSerch; upperResultSerch = result.Count() - 1; if (result[upperResultSerch].Time < time) { throw new Exception("GetValusAtTime. Invalid time, over maximum value"); } } if (result[lowerResultSerch].Time > time) { upperResultSerch = lowerResultSerch; lowerResultSerch = 0; if (result[lowerResultSerch].Time > time) { throw new Exception("GetValusAtTime. Invalid time, under minimum value"); } } if (lowerResultSerch > upperResultSerch) { throw new Exception("GetValusAtTime. Invalid range"); } bool notFound = true; int curentIndex = 0; while (notFound) { if (Math.Abs(result[lowerResultSerch].Time - time) < Double.Epsilon) { upperResultSerch = lowerResultSerch; } else if (Math.Abs(result[upperResultSerch].Time - time) < Double.Epsilon) { lowerResultSerch = upperResultSerch; } else { curentIndex = (int)(0.5 * (upperResultSerch + lowerResultSerch)); if (result[curentIndex].Time < time) { lowerResultSerch = curentIndex; } else { upperResultSerch = curentIndex; } } notFound = (upperResultSerch - lowerResultSerch) > 1; } if (upperResultSerch == lowerResultSerch) { res = result[upperResultSerch]; } else { double delta = (time - result[lowerResultSerch].Time) / (result[upperResultSerch].Time - result[lowerResultSerch].Time); res.Time = time; res.AmbientPreasure = result[lowerResultSerch].AmbientPreasure + delta * (result[upperResultSerch].AmbientPreasure - result[lowerResultSerch].AmbientPreasure); res.Depth = result[lowerResultSerch].Depth + delta * (result[upperResultSerch].Depth - result[lowerResultSerch].Depth); for (int i = 0; i < compNo; i++) { res.setN2(i, (result[lowerResultSerch].getN2(i) + delta * (result[upperResultSerch].getN2(i) - result[lowerResultSerch].getN2(i)))); if (tmx) { res.setHe(i, (result[lowerResultSerch].getHe(i) + delta * (result[upperResultSerch].getHe(i) - result[lowerResultSerch].getHe(i)))); } } } return(res); }