jalhyd
Version:
JaLHyd, a Javascript Library for Hydraulics
268 lines • 11 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Jet = void 0;
const internal_modules_1 = require("../internal_modules");
const internal_modules_2 = require("../internal_modules");
const internal_modules_3 = require("../internal_modules");
const internal_modules_4 = require("../internal_modules");
const internal_modules_5 = require("../internal_modules");
const internal_modules_6 = require("../internal_modules");
class Jet extends internal_modules_2.Nub {
constructor(prms, dbg = false) {
super(prms, dbg);
/** steps for generating the trajectory */
this.precision = 50;
this.setCalculatorType(internal_modules_1.CalculatorType.Jet);
this._defaultCalculatedParam = prms.D;
this.resetDefaultCalculatedParam();
}
/** paramètres castés au bon type */
get prms() {
return this._prms;
}
Calc(sVarCalc, rInit) {
this.currentResultElement = super.Calc(sVarCalc, rInit);
// omit extra results if calculation failed
if (this.result.vCalc !== undefined) {
// H: chute
this.result.resultElement.values.H = this.prms.ZJ.v - this.prms.ZW.v;
// Y: profondeur
this.result.resultElement.values.Y = this.prms.ZW.v - this.prms.ZF.v;
// YH: rapport profondeur/chute
this.result.resultElement.values.YH = this.result.resultElement.values.Y / this.result.resultElement.values.H;
// t: temps de vol
this.result.resultElement.values.t = this.prms.D.V / Math.cos(this.alpha) / this.prms.V0.V;
// Vx: vitesse horizontale à l'impact
this.result.resultElement.values.Vx = this.prms.V0.V * Math.cos(this.alpha);
// Vz: vitesse verticale à l'impact
this.result.resultElement.values.Vz =
this.prms.V0.V * Math.sin(this.alpha) - this.result.resultElement.values.t * 9.81;
// Vt: vitesse à l'impact
this.result.resultElement.values.Vt = Math.sqrt(Math.pow(this.result.resultElement.values.Vx, 2)
+ Math.pow(this.result.resultElement.values.Vz, 2));
}
let ZF = this.prms.ZF.v;
let ZW = this.prms.ZW.v;
let ZJ = this.prms.ZJ.v;
if (this.calculatedParam === this.prms.ZF) {
ZF = this.result.resultElement.vCalc;
}
if (this.calculatedParam === this.prms.ZW) {
ZW = this.result.resultElement.vCalc;
}
if (this.calculatedParam === this.prms.ZJ) {
ZJ = this.result.resultElement.vCalc;
}
// y a-t-il de l'eau au dessus du sol ?
if (ZF > ZW) {
this.result.resultElement.log.add(new internal_modules_5.Message(internal_modules_5.MessageCode.WARNING_JET_WATER_ELEVATION_UNDERGROUND));
}
// le jet est-il bien au dessus du sol ?
if (ZF > ZJ) {
this.result.resultElement.log.add(new internal_modules_5.Message(internal_modules_5.MessageCode.WARNING_JET_START_ELEVATION_UNDERGROUND));
}
// le jet est-il bien émergé ?
if (ZW > ZJ) {
this.result.resultElement.log.add(new internal_modules_5.Message(internal_modules_5.MessageCode.WARNING_JET_START_SUBMERGED));
}
return this.result;
}
Equation(sVarCalc) {
const g = 9.81;
let v;
let h;
switch (sVarCalc) {
case ("ZJ"):
h = this.CalcH();
v = h + this.prms.ZW.v;
break;
case ("ZW"):
h = this.CalcH();
v = this.prms.ZJ.v - h;
break;
case ("D"):
h = (this.prms.ZJ.v - this.prms.ZW.v);
const sqrtArg = Math.pow(this.prms.V0.v * Math.sin(this.alpha), 2) + 2 * g * h;
if (sqrtArg < 0) {
return new internal_modules_6.Result(new internal_modules_5.Message(internal_modules_5.MessageCode.ERROR_JET_SUBMERGED_NO_SOLUTION), this);
}
v = this.prms.V0.v / g * Math.cos(this.alpha)
* (this.prms.V0.v * Math.sin(this.alpha)
+ Math.sqrt(sqrtArg));
break;
default:
throw new Error("Jet.Equation() : invalid variable name " + sVarCalc);
}
return new internal_modules_6.Result(v);
}
/** clone casting */
clone() {
return super.clone();
}
/**
* Returns an array of trajectories built from the current Nub state.
* A trajectory is a list of coordinate pairs representing the fall height (y),
* for each abscissa (x) between 0 and the impact abscissa (D).
* A coordinate pair is a list of 2 numbers [ x, y ].
* If no parameter is varying, result will contain only 1 element.
* Trajectory calculation uses a copy of the current Nub to calculate ZW from D.
*/
generateTrajectories() {
const trajectories = [];
// clone Nub so that ZW calculation will not impact current state
const nub = this.clone();
// is anything varying ?
if (this.resultHasMultipleValues()) {
const valuesLists = {};
const length = this.variatingLength();
// reset clone params to SINGLE mode
nub.prms.V0.valueMode = internal_modules_4.ParamValueMode.SINGLE;
nub.prms.S.valueMode = internal_modules_4.ParamValueMode.SINGLE;
nub.prms.D.valueMode = internal_modules_4.ParamValueMode.SINGLE;
// H will be calculated
// 1. find all extended values lists; ignore ZW (will be calculated) and D (will be reaffected)
for (const symbol of ["S", "V0", "ZJ"]) {
const p = this.getParameter(symbol);
valuesLists[symbol] = [];
if (this.calculatedParam.symbol === symbol) { // calculated
for (let i = 0; i < length; i++) {
valuesLists[symbol].push(this.result.resultElements[i].vCalc);
}
}
else if (p.hasMultipleValues) { // variating
const iter = p.getExtendedValuesIterator(length);
while (iter.hasNext) {
const nv = iter.next();
valuesLists[symbol].push(nv.value);
}
}
else { // single
for (let i = 0; i < length; i++) {
valuesLists[symbol].push(p.singleValue);
}
}
}
// 2. build one series for each variating step
for (let i = 0; i < length; i++) {
// exclude iteration if calculation has failed
if (this.result.resultElements[i].ok) {
// set clone params values; ignore ZW (will be calculated)
// and D (will be reaffected by getDAbscissae)
for (const symbol of ["S", "V0", "ZJ"]) {
const val = valuesLists[symbol][i];
nub.getParameter(symbol).v = val;
}
// compute series
trajectories.push(this.buildSeriesForIteration(nub, i));
}
else {
// mark failed calculation using empty list
trajectories.push([]);
}
}
}
else { // nothing is varying
for (const symbol of ["S", "V0", "ZJ"]) {
// init .v of clone
nub.getParameter(symbol).v = nub.getParameter(symbol).singleValue;
}
trajectories.push(this.buildSeriesForIteration(nub, 0));
}
return trajectories;
}
CalcH() {
const g = 9.81;
return (0.5 * g * Math.pow(this.prms.D.v, 2)
/ (Math.pow(Math.cos(this.alpha), 2) * Math.pow(this.prms.V0.v, 2)) - Math.tan(this.alpha) * this.prms.D.v);
}
/**
* Build a trajectory data series for a calculation iteration
*/
buildSeriesForIteration(nub, i) {
const traj = [];
const xs = this.getDAbscissae(i);
for (const x of xs) {
// compute H for D = x
nub.prms.D.v = x;
// console.log("__computing H for x =", x, nub.prms.D.v);
const h = nub.Calc("ZW");
traj.push([x, h.vCalc]);
}
return traj;
}
/**
* Returns a list of abscissae from 0 to D (number of steps is this.precision)
* @param variatingIndex if D is variating, index of the D value to fetch
*/
getDAbscissae(variatingIndex = 0) {
const abs = [];
// divide impact abscissa into steps
let D;
if (this.calculatedParam.symbol === "D") {
D = this.result.resultElements[variatingIndex].vCalc;
}
else if (this.prms.D.hasMultipleValues) {
const length = this.variatingLength();
const valsD = [];
const iter = this.prms.D.getExtendedValuesIterator(length);
while (iter.hasNext) {
const nv = iter.next();
valsD.push(nv.value);
}
D = valsD[variatingIndex];
}
else {
D = this.prms.D.V;
}
const step = D / this.precision;
// zero-abscissa
let x = 0;
abs.push(x);
// abscissae in ]0,D[
for (let i = 0; i < this.precision - 1; i++) {
x += step;
abs.push(x);
}
// D-abscissa
abs.push(D);
return abs;
}
setParametersCalculability() {
this.prms.V0.calculability = internal_modules_3.ParamCalculability.DICHO;
this.prms.S.calculability = internal_modules_3.ParamCalculability.DICHO;
this.prms.ZJ.calculability = internal_modules_3.ParamCalculability.EQUATION;
this.prms.ZW.calculability = internal_modules_3.ParamCalculability.EQUATION;
this.prms.ZF.calculability = internal_modules_3.ParamCalculability.FIXED;
this.prms.D.calculability = internal_modules_3.ParamCalculability.EQUATION;
}
static resultsUnits() {
return Jet._resultsUnits;
}
exposeResults() {
this._resultsFamilies = {
H: internal_modules_3.ParamFamily.TOTALFALLS,
Y: internal_modules_3.ParamFamily.HEIGHTS,
YH: undefined,
t: undefined,
Vx: undefined,
Vz: undefined,
Vt: undefined
};
}
get alpha() {
return Math.atan(this.prms.S.v);
}
}
exports.Jet = Jet;
/**
* { symbol => string } map that defines units for extra results
*/
Jet._resultsUnits = {
H: "m",
Y: "m",
t: "s",
Vx: "m/s",
Vz: "m/s",
Vt: "m/s"
};
//# sourceMappingURL=jet.js.map