Giter Club home page Giter Club logo

dive's Introduction

dive

Various standard scuba diving algorithms, formulas, calculations and device management.

Getting Started

Install the module with: npm install scuba-dive

var dive = require('scuba-dive');
// or <script type="text/javascript" src="scuba-dive.js"></script>
dive.feetToMeters(); // 0.3048
dive.feetToMeters(33); // 10.0584
dive.metersToFeet(10); // 3.28084

// check defaults or change them
dive.gravitySamples.current(); // 9.80665 m/s2
dive.gravitySamples.current(9.8);
dive.gravitySamples.current(); // 9.8 m/s2
dive.surfacePressureSamples.current(); // 1 bar
dive.surfacePressureSamples.current(1);
dive.liquidSamples.fresh.density(); // 1000 kg/m3 (1 ton of a m^3)
dive.liquidSamples.salt.density(); // 1030 kg/m3
dive.liquidSamples.mercury.density(); // 13595.1 kg/m3
dive.constants.vapourPressure.lungsBreathing.current(); // 0.056713577314554675 bars (commonly seen in buhlmann deco)
dive.constants.altitudePressure.current(); // 1 bar (for sea level)
dive.constants.altitudePressure.current(0.6600); // (approx. 3000 meters above sea level)
dive.constants.altitudePressure.current(1); // change back to default at sea-level

// calculate dac, sac and rmv rate
dive.dac(2500, 1300, 50); // 24 psi/min
dive.sac(24, 10); // 12.022841322028032 psi/min given 24 psi/min dac rate
dive.rmv(25, 80, 3000); // 0.67 cuft/min given 25 psi/min sac rate

// calculate various depth of 1 cubic meter volume of liquid in atm or bars
dive.depthInMetersToBars(10); // 2.0094000000000003 bar absolute
dive.depthInMetersToAtm(10); // 1.9962003454231434 atm
dive.atmToDepthInMeters(1); // 10.038141470180305 meters
dive.barToDepthInMeters(1); // 9.906875371507827 meters

// calculate depth meters for all calculations above but in fresh water
dive.depthInMetersToBars(10, true); // 1.98 bar absolute (1 above)
dive.depthInMetersToAtm(10, true); // 1.9671848013816926 atm absolute (1 above)
dive.atmToDepthInMeters(1, true); // 10.339285714285714 meters
dive.barToDepthInMeters(1, true); // 10.204081632653061 meters

// calculating partial pressure of a particular gas component mixture
// calculate partial pressure for gas mixture that is 79% nitrogen (N2) and 21% oxygen (O2)
// at 10 meters below sea level, what is partial pressure of each gas?
var p = dive.depthInMetersToBars(10); // 2.0094000000000003 bar absolute
dive.partialPressure(p, 0.79); // 1.5874260000000002 bar absolute
dive.partialPressure(p, 0.21); // 0.42197400000000007 bar absolute

// you can also use the helper function to calculate from depth in meters
dive.partialPressureAtDepth(10, 0.79); // 1.5874260000000002 bar absolute
dive.partialPressureAtDepth(10, 0.21); // 0.42197400000000007 bar absolute

// calculate partial pressures for above but in fresh water
dive.partialPressureAtDepth(10, 0.79, true); // 1.5642 bar absolute
dive.partialPressureAtDepth(10, 0.21, true); // 0.4158 bar absolute

// calculate water vapour pressure at a given temperature (degrees celcius)
// use the conversion tools to calculate in terms of bars
var mmHg = dive.waterVapourPressure(35.2); // 42.538675172399344 mmHg
var pascals = dive.mmHgToPascal(mmHg); // 5671.357731455468 Pascal
dive.pascalToBar(pascals); // 0.056713577314554675 bar
dive.waterVapourPressureInBars(35.2); // 0.056713577314554675 bar
// notice the 0.0567 bar above? we can plug that into the Buhlmann Decompression Algorithm

// calculate maximum operating depth using AIR (21% Oxygen) at 1.4 bars
dive.maxOperatingDepth(1.4, 0.21); // 56.10089197613197 meters
// calculate maximum operating depth using AIR (21% Oxygen) at 1.4 bars in fresh water
dive.maxOperatingDepth(1.4, 0.21, true); // 57.78391873541593 meters

// calculate the narcotic equivalent depth for breathing a gas mixture
// that is 12% Oxygen, 38% Nitrogen and 50% Helium at 100m
dive.equivNarcoticDepth(0.12, 0.38, 0.50, 100); // 56.882888936481194 meters air
dive.equivNarcoticDepth(0.12, 0.38, 0.50, 100, true); // 56.766365121623096 meters air (in fresh water)

// depth change in bars per minute (e.g. 0 to 10 meters in 30 seconds)
dive.depthChangeInBarsPerMinute(0, 10, 0.5); // 2.0201699 bars per minute (in salt water)
dive.depthChangeInBarsPerMinute(0, 10, 0.5, true); // 1.9613300000000002 bars per minute (in fresh water)

// gas rate in bars per minute (e.g. 0 to 10 meters in 30 seconds with 79% Nitrogen)
dive.gasRateInBarsPerMinute(0, 10, 0.5, 0.79); // 1.595934221 bars per minute (in salt water)
dive.gasRateInBarsPerMinute(0, 10, 0.5, 0.79,, true); // 1.5494507 bars per minute (in fresh water)

// gas breathing pressure in bars accounting for water vapour pressure in the lungs
// calculate the pressure at 10 meters breathing 79% N2
dive.gasPressureBreathingInBars(10, 0.79); // 0.7531633844215019 bars (in salt water)
dive.gasPressureBreathingInBars(10, 0.79, true); // 0.729921623921502 bars (in fresh water)

// instantaneous equation (exposed at 20 meters with AIR for 40 minutes)
var pGas = dive.gasPressureBreathingInBars(20, 0.79);
dive.instantaneousEquation(0.79, pGas, 40, 4.0); // 1.5940936555866738 bar

// buhlmann deco algorithm (*this needs review*)
var buhlmannDeco = dive.deco.buhlmann();
var newPlan = new buhlmannDeco.plan(buhlmannDeco.ZH16ATissues); // 1 abs pressure in fresh water
newPlan.addBottomGas("2135", 0.21, 0.35);
newPlan.addDecoGas("50%", 0.5, 0.0);
newPlan.addDepthChange(0, 50, "2135", 5);
newPlan.addFlat(50, "2135", 25);
var decoPlan = newPlan.calculateDecompression(false, 0.2, 0.8, 1.6, 30); //gradientFactorLow = 0.2, gradientFactorHigh=0.8, deco ppO2 = 1.6, and max END allowed: 30 meters.

//No-Deco limit for a gas at a depth
var buhlmann = dive.deco.buhlmann();
var newPlan = new buhlmann.plan(buhlmann.ZH16BTissues);
newPlan.addBottomGas("air", 0.21, 0.0);
var gradientFactor = 1.5; //This was choosen to closely match PADI dive tables.
newPlan.ndl(dive.feetToMeters(140), "air", gradientFactor), "NDL for 140 feet should be close to 7 minutes");

TODO

  • Need better test cases and validation for buhlmann implementation (needs review)

Notice of Use

This library was built for pure research and educational purposes only. Use at your own risk. I am not responsible for any injuries that may occur as a result of experimenting with this software. Always use a backup dive computer when experimenting with educational tools like this and others that may implement various diving algorithms. It would be nice if other dive companies followed by publishing their implementations so the research and dive community could improve on it and ultimately protect more people.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

License

Copyright (c) 2013 Thomas Holloway
Licensed under the MIT license.

dive's People

Contributors

archis-polyverse avatar jirkapok avatar nyxtom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dive's Issues

Problems calculating NDL

Firstly, thanks for all the work that has gone into this so far!

It appears that there's an issue in the NDL calculation relating to the ceiling. Where the ceiling starts as a negative integer and should progressively increase until > 0 (through the addition of 1min increments at depths increasing by 3m at each iteration) I'm seeing the reverse: the ceiling becomes more negative with each iteration eg. from -3 up until -24 where it gets stuck in an infinite loop. This is mirrored when running grunt test.

The readme seems to indicate that this particular portion may still be work-in-progress, I'd very much like to help get it back on track if possible, but could do with an initial discussion (assuming this is a somewhat known issue).

Wrong calculation of dive plan with deco gas

I tried creating a pretty straight forward 55m dive with 20 mins bottom time, 18/45 as the back gas and 50% o2 as deco gas. But I think something wrong, because I should clearly have more deco than three minutes

Here it is:

var dive = require('scuba-dive');
var buhlmannDeco = dive.deco.buhlmann();
var newPlan = new buhlmannDeco.plan(buhlmannDeco.ZH16ATissues);

var he = 0.45;
var o2 = 0.18;
var n2 = 1 - he - o2;

newPlan.addDepthChange(0, 55, n2, he, 2);
newPlan.addFlat(55, n2, he, 20);
var result = newPlan.calculateDecompression(0.5, 0.0);

console.log(result);// [{'depth':3,'time':3}] 

Ensure pressure conversions

I have two questions regarding pressure conversions:

  1. https://github.com/nyxtom/dive/blob/master/lib/core.js#L386
    contains temperature checks, which for 100°C use the lower range constants. Shouldn't they use the higher range constants?
  2. For all the depth to pressure conversions the altitudePressure.current constant is used except https://github.com/nyxtom/dive/blob/master/lib/core.js#L322
    Shouldn't be used everywhere?
  3. And also the constant is in bars (i guess), but is used in addition to pascals or Atm which looks like a unit mismatch. (e.g. https://github.com/nyxtom/dive/blob/master/lib/core.js#L244)

Arent these mistakes in calculations?

Implement VPM

I'll do this tonight. This task is to implement Variable Permeability Model.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.