Skip to content

Commit

Permalink
extracted gas properties to library
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiri Pokorny committed Oct 3, 2023
1 parent 0e6d060 commit d212d51
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 164 deletions.
92 changes: 1 addition & 91 deletions projects/planner/src/app/shared/gas.properties.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UnitConversion } from './UnitConversion';
import { BoundGasProperties, GasProperties } from './gas.properties';
import { BoundGasProperties } from './gas.properties';

describe('Gas properties bound', () => {
const units: UnitConversion = new UnitConversion();
Expand Down Expand Up @@ -35,93 +35,3 @@ describe('Gas properties bound', () => {
});
});
});

describe('Gas properties calculator', () => {
let sut: GasProperties;

beforeEach(() => {
sut = new GasProperties();
sut.depth = 30;
});

describe('Air at 30 m', () => {
beforeEach(() => {
sut.tank.o2 = 21;
});

it('MND is 30 m', () => {
expect(sut.mnd).toBeCloseTo(30, 3);
});

it('END is 30 m', () => {
expect(sut.end).toBeCloseTo(30, 3);
});

it('Minimum depth is 0 m', () => {
expect(sut.minDepth).toBeCloseTo(0, 3);
});

it('Maximum depth (MOD) is 57 m', () => {
expect(sut.maxDepth).toBeCloseTo(56.986, 3);
});

it('Total partial pressure is depth (4 b)', () => {
expect(sut.totalPp).toBeCloseTo(4, 3);
});

it('ppO2 is 0.836', () => {
expect(sut.ppO2).toBeCloseTo(0.836, 3);
});

it('ppHe is 0', () => {
expect(sut.ppHe).toBeCloseTo(0, 3);
});

it('ppN2 is 3.164', () => {
expect(sut.ppN2).toBeCloseTo(3.164, 3);
});

it('Density is 5.15 g/l', () => {
expect(sut.density).toBeCloseTo(5.151972, 6);
});
});

describe('Trimix 10/70 at 30 m', () => {
beforeEach(() => {
sut.tank.o2 = 10;
sut.tank.he = 70;
});

it('MND is 123.3 m', () => {
expect(sut.mnd).toBeCloseTo(123.333, 3);
});

it('END is 2 m', () => {
expect(sut.end).toBeCloseTo(2, 3);
});

it('Minimum depth is 8 m', () => {
expect(sut.minDepth).toBeCloseTo(8, 3);
});

it('Maximum depth (MOD) is 130 m', () => {
expect(sut.maxDepth).toBeCloseTo(130, 3);
});

it('ppO2 is 0.4', () => {
expect(sut.ppO2).toBeCloseTo(0.4, 3);
});

it('ppHe is 2.8', () => {
expect(sut.ppHe).toBeCloseTo(2.8, 3);
});

it('ppN2 is 0.8', () => {
expect(sut.ppN2).toBeCloseTo(0.8, 3);
});

it('Density is 2 g/l', () => {
expect(sut.density).toBeCloseTo(2.0732, 6);
});
});
});
74 changes: 1 addition & 73 deletions projects/planner/src/app/shared/gas.properties.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
DensityAtDepth,
DepthConverter,
Gas,
GasMixtures,
Tank
GasProperties
} from 'scuba-physics';
import { TankBound } from './models';
import { UnitConversion } from './UnitConversion';
Expand Down Expand Up @@ -69,71 +65,3 @@ export class BoundGasProperties {
this.calc.depth = newValue;
}
}


export class GasProperties {
/** in meters */
public depth = 0;
private readonly _tank = Tank.createDefault();
private readonly depthConverter = DepthConverter.simple();
private readonly densityCalc = new DensityAtDepth(this.depthConverter);

public get tank(): Tank {
return this._tank;
}

public get ppO2(): number {
const result = GasMixtures.partialPressure(this.depthPressure, this.gas.fO2);
return result;
}

public get ppHe(): number {
const result = GasMixtures.partialPressure(this.depthPressure, this.gas.fHe);
return result;
}

public get ppN2(): number {
const result = GasMixtures.partialPressure(this.depthPressure, this.gas.fN2);
return result;
}

public get totalPp(): number {
return this.depthPressure;
}

public get minDepth(): number {
const surface = this.depthConverter.surfacePressure;
const minDepthPressure = GasMixtures.ceiling(this.gas.fO2, surface);
return this.depthConverter.fromBar(minDepthPressure);
}

public get maxDepth(): number {
const maxppO2 = 1.4; // TODO add to UI
const maxDepthPressure = GasMixtures.mod(1.4, this.gas.fO2);
return this.depthConverter.fromBar(maxDepthPressure);
}

public get end(): number {
const endDepthPressure = GasMixtures.end(this.depthPressure, this.gas.fN2, this.gas.fO2);
return this.depthConverter.fromBar(endDepthPressure);
}

public get mnd(): number {
const narcDepthBars = 4; // TODO add to UI
const endDepthPressure = GasMixtures.mnd(narcDepthBars, this.gas.fN2, this.gas.fO2);
return this.depthConverter.fromBar(endDepthPressure);
}

public get density(): number {
const density = this.densityCalc.atDepth(this.gas, this.depth);
return density;
}

private get gas(): Gas {
return this.tank.gas;
}

private get depthPressure(): number {
return this.depthConverter.toBar(this.depth);
}
}
91 changes: 91 additions & 0 deletions projects/scuba-physics/src/lib/gas.properties.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { GasProperties } from './gas.properties';

describe('Gas properties calculator', () => {
let sut: GasProperties;

beforeEach(() => {
sut = new GasProperties();
sut.depth = 30;
});

describe('Air at 30 m', () => {
beforeEach(() => {
sut.tank.o2 = 21;
});

it('MND is 30 m', () => {
expect(sut.mnd).toBeCloseTo(30, 3);
});

it('END is 30 m', () => {
expect(sut.end).toBeCloseTo(30, 3);
});

it('Minimum depth is 0 m', () => {
expect(sut.minDepth).toBeCloseTo(0, 3);
});

it('Maximum depth (MOD) is 57 m', () => {
expect(sut.maxDepth).toBeCloseTo(56.986, 3);
});

it('Total partial pressure is depth (4 b)', () => {
expect(sut.totalPp).toBeCloseTo(4, 3);
});

it('ppO2 is 0.836', () => {
expect(sut.ppO2).toBeCloseTo(0.836, 3);
});

it('ppHe is 0', () => {
expect(sut.ppHe).toBeCloseTo(0, 3);
});

it('ppN2 is 3.164', () => {
expect(sut.ppN2).toBeCloseTo(3.164, 3);
});

it('Density is 5.15 g/l', () => {
expect(sut.density).toBeCloseTo(5.151972, 6);
});
});

describe('Trimix 10/70 at 30 m', () => {
beforeEach(() => {
sut.tank.o2 = 10;
sut.tank.he = 70;
});

it('MND is 123.3 m', () => {
expect(sut.mnd).toBeCloseTo(123.333, 3);
});

it('END is 2 m', () => {
expect(sut.end).toBeCloseTo(2, 3);
});

it('Minimum depth is 8 m', () => {
expect(sut.minDepth).toBeCloseTo(8, 3);
});

it('Maximum depth (MOD) is 130 m', () => {
expect(sut.maxDepth).toBeCloseTo(130, 3);
});

it('ppO2 is 0.4', () => {
expect(sut.ppO2).toBeCloseTo(0.4, 3);
});

it('ppHe is 2.8', () => {
expect(sut.ppHe).toBeCloseTo(2.8, 3);
});

it('ppN2 is 0.8', () => {
expect(sut.ppN2).toBeCloseTo(0.8, 3);
});

it('Density is 2 g/l', () => {
expect(sut.density).toBeCloseTo(2.0732, 6);
});
});
});
71 changes: 71 additions & 0 deletions projects/scuba-physics/src/lib/gas.properties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { DensityAtDepth } from './GasDensity';
import { Gas, GasMixtures } from './Gases';
import { Tank } from './Tanks';
import { DepthConverter } from './depth-converter';

export class GasProperties {
/** in meters */
public depth = 0;
private readonly _tank = Tank.createDefault();
private readonly depthConverter = DepthConverter.simple();
private readonly densityCalc = new DensityAtDepth(this.depthConverter);

public get tank(): Tank {
return this._tank;
}

public get ppO2(): number {
const result = GasMixtures.partialPressure(this.depthPressure, this.gas.fO2);
return result;
}

public get ppHe(): number {
const result = GasMixtures.partialPressure(this.depthPressure, this.gas.fHe);
return result;
}

public get ppN2(): number {
const result = GasMixtures.partialPressure(this.depthPressure, this.gas.fN2);
return result;
}

public get totalPp(): number {
return this.depthPressure;
}

public get minDepth(): number {
const surface = this.depthConverter.surfacePressure;
const minDepthPressure = GasMixtures.ceiling(this.gas.fO2, surface);
return this.depthConverter.fromBar(minDepthPressure);
}

public get maxDepth(): number {
const maxppO2 = 1.4; // TODO add to UI
const maxDepthPressure = GasMixtures.mod(1.4, this.gas.fO2);
return this.depthConverter.fromBar(maxDepthPressure);
}

public get end(): number {
const endDepthPressure = GasMixtures.end(this.depthPressure, this.gas.fN2, this.gas.fO2);
return this.depthConverter.fromBar(endDepthPressure);
}

public get mnd(): number {
const narcDepthBars = 4; // TODO add to UI
const endDepthPressure = GasMixtures.mnd(narcDepthBars, this.gas.fN2, this.gas.fO2);
return this.depthConverter.fromBar(endDepthPressure);
}

public get density(): number {
const density = this.densityCalc.atDepth(this.gas, this.depth);
return density;
}

private get gas(): Gas {
return this.tank.gas;
}

private get depthPressure(): number {
return this.depthConverter.toBar(this.depth);
}
}
1 change: 1 addition & 0 deletions projects/scuba-physics/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export * from './lib/DepthLevels';
export * from './lib/Diver';
export * from './lib/Gases';
export * from './lib/GasDensity';
export * from './lib/gas.properties';
export * from './lib/NitroxCalculator';
export * from './lib/Options';
export * from './lib/OtuCalculator';
Expand Down

0 comments on commit d212d51

Please sign in to comment.