Commit 6ffa7818 authored by Dorchies David's avatar Dorchies David
Browse files

Fix #154

parent d184d130
......@@ -201,6 +201,14 @@ function testMacroRugoConfig(sInstance: string, Q0: number, fVal0: number, mrExt
});
}
function macroRugoInstanceJalHyd85(): MacroRugo {
const nubMR = macroRugoInstanceEmergentCd15();
nubMR.prms.C.singleValue = 0.2;
nubMR.prms.PBH.singleValue = 0.8;
nubMR.calculatedParam = nubMR.prms.Q;
return nubMR;
}
describe("Class MacroRugo: ", () => {
testMacroRugoConfig("EmergentCd15", 0.901710, 0.679969, macroRugoExtraResultEmergentCd15);
......@@ -216,10 +224,8 @@ describe("Class MacroRugo: ", () => {
describe("JalHyd #85", () => {
it("CalcSerie Q should return the good result :)", () => {
const nubMR = macroRugoInstanceEmergentCd2();
nubMR.prms.C.singleValue = 0.2;
nubMR.prms.PBH.singleValue = 0.8;
nubMR.calculatedParam = nubMR.prms.Q;
const nubMR = macroRugoInstanceJalHyd85();
const nubMR2 = macroRugoInstanceJalHyd85();
nubMR.prms.Y.setValues(0.7, 1.2, 0.1);
const aQ: number[] = [ 0.484255, 0.578363, 1.004229, 1.280269, 1.618937, 2.018687 ];
......@@ -227,6 +233,8 @@ describe("Class MacroRugo: ", () => {
nubMR.CalcSerie();
for (let i = 0; i < aQ.length; i++) {
expect(nubMR.result.resultElements[i].vCalc).toBeCloseTo(aQ[i], 4);
nubMR2.prms.Y.setValue(0.7 + i * 0.1);
expect(nubMR2.CalcSerie().vCalc).toBeCloseTo(aQ[i], 4);
}
});
});
......
......@@ -56,7 +56,7 @@ describe("MacroRugoCompound", () => {
beforeEach(() => {
BR += 1;
});
for (let i = 1; i < 10; i += 1) {
for (let i = 1; i <= 10; i += 1) {
it(`B = ${i} should return same result as Macrorugo`, () => {
const mrc = Session.getInstance().createNub(
new Props({ calcType: CalculatorType.MacroRugoCompound })
......@@ -65,7 +65,7 @@ describe("MacroRugoCompound", () => {
mrc.prms.BR.singleValue = BR;
const mr = getMacroRugoRef();
expect(mrc.CalcSerie().vCalc)
.toBeCloseTo(mr.result.vCalc * mrc.prms.BR.currentValue / mr.prms.B.currentValue, 3);
.toBeCloseTo(mr.result.vCalc * mrc.prms.BR.currentValue / mr.prms.B.currentValue, 2);
const ax = mrc.prms.PBD.v / Math.sqrt(mrc.prms.C.v);
let B: number = 0;
for (const child of mrc.children) {
......@@ -74,7 +74,7 @@ describe("MacroRugoCompound", () => {
B += child.prms.B.v;
expect(child.prms.B.v).toBeGreaterThanOrEqual(ax / 4);
}
expect(B).toBeCloseTo(mrc.prms.BR.currentValue, 6);
expect(B).toBeCloseTo(mrc.prms.BR.currentValue, 2);
});
}
});
......
......@@ -26,7 +26,7 @@ export class MacroRugo extends Nub {
private static readonly fracAxAy = 1;
/** Limit between emergent and submerged flow */
private static readonly limitSubmerg = 1.1;
private static readonly limitSubmerg = 1;
/** Averaged velocity (m.s-1) */
......@@ -83,8 +83,8 @@ export class MacroRugo extends Nub {
// Vitesse maximale
const cc = 0.4 * this.prms.Cd0.v + 0.7;
let resVmax = vg * Math.min(
cc / (1 - Math.pow(r.resultElement.values.Fr, 2) / 4),
Math.pow(r.resultElement.values.Fr, -2 / 3)
cc / (1 - Math.pow(resFr, 2) / 4),
Math.pow(resFr, -2 / 3)
);
if (isNaN(resVmax)) { // if Y == 0
resVmax = 0;
......@@ -124,18 +124,24 @@ export class MacroRugo extends Nub {
r.resultElement.values.V_GuideTech = cV[0] * Math.pow(this.prms.Y.v / this.prms.PBD.v, cV[1]) *
Math.pow(this.prms.If.v, cV[2]) * Math.sqrt(MacroRugo.g * this.prms.PBD.v);
}
if (this.prms.Y.v > 0 && this.prms.If.v > 0) {
r.resultElement.values.Strickler =
this.prms.Q.V / (Math.pow(this.prms.Y.v, 5 / 3) * this.prms.B.v * Math.pow(this.prms.If.v, 0.5));
} else {
r.resultElement.values.Strickler = 0;
}
return r;
}
public Equation(sVarCalc: string): Result {
this.Q = this.prms.Q.v;
const q0 = Math.sqrt(2 * MacroRugo.g * this.prms.If.v * this.prms.PBD.v * ( 1 - (this.sigma * this.prms.C.v)) /
const q0 = Math.sqrt(2 * MacroRugo.g * this.prms.If.v * this.prms.PBD.v * (1 - (this.sigma * this.prms.C.v)) /
(this.prms.Cd0.v * this.prms.C.v)) * this.prms.Y.v * this.prms.B.v;
let r: Result;
if (q0 > 0) {
const dicho = new Dichotomie(this, "Q", false, this.resolveQ);
r = dicho.Dichotomie(0, SessionSettings.precision, q0);
// r = dicho.Dichotomie(0, SessionSettings.precision, q0);
r = dicho.Dichotomie(0, 1E-10, q0);
} else {
r = new Result(0);
}
......@@ -208,7 +214,7 @@ export class MacroRugo extends Nub {
this.u0 = Math.sqrt(k * 2 * g * S * this.R
/ (this.Cd * C * k / D + this.calcCf(k) * this.R));
/** turbulent length scale (m) within the blocks layer (alpha_t) */
const alpha = uniroot(this.resolveAlpha_t, this, 1E-6, 100);
const alpha = uniroot(this.resolveAlpha_t, this, 1E-3, 10);
/** averaged velocity at the top of blocks (m.s-1) */
const uk = this.calcUz(alpha);
/** Equation (13) Cassan et al., 2016 */
......@@ -232,7 +238,7 @@ export class MacroRugo extends Nub {
for (let z = step; z < zMax; z += step) {
uOld = u;
u = this.calcUz(alpha, z);
Qinf += (uOld + u) ;
Qinf += (uOld + u);
}
Qinf = Qinf / 2 * step * k;
......@@ -243,7 +249,7 @@ export class MacroRugo extends Nub {
// Emergent conditions
// Resolve equation (4) Cassan et al., 2016
return this.resolveEmergent();
return this.resolveQEmergent();
}
}
......@@ -305,7 +311,10 @@ export class MacroRugo extends Nub {
* Calculation of Cd : drag coefficient of a block under the actual flow conditions
*/
private get Cd(): number {
return this.prms.Cd0.v * (1 + 0.4 / Math.pow(this.prms.Y.v / this.prms.PBD.v, 2)) * this.fFr;
if (this._cache.Cd === undefined) {
this._cache.Cd = this.prms.Cd0.v * (1 + 1 / Math.pow(this.prms.Y.v / this.prms.PBD.v, 2));
}
return this._cache.Cd;
}
/**
......@@ -346,40 +355,59 @@ export class MacroRugo extends Nub {
return alpha * this.calcUz(alpha) - l0 * this.ustar;
}
private resolveEmergent(): number {
private resolveQEmergent(): number {
// tslint:disable-next-line: variable-name
const Cd = this.Cd * this.fFr;
/** N from Cassan 2016 eq(2) et Cassan 2014 eq(12) */
const N = (1 * this.calcCf(this.prms.Y.v)) / (this.prms.Y.v / this.prms.PBD.v * Cd * this.prms.C.v);
// const U0i = Math.sqrt(
// 2 * MacroRugo.g * this.prms.If.v * this.prms.PBD.v *
// (1 - this.sigma * this.prms.C.v) / (Cd * this.prms.C.v * (1 + N))
// );
return this.U0 - uniroot(this.resolveU0Complete, this, 1E-6, 100);
}
private resolveU0Complete(U0: number): number {
const fFr = this.CalcfFr(U0);
const alpha = 1 - Math.pow(1 * this.prms.C.v, 0.5) - 0.5 * this.sigma * this.prms.C.v;
// tslint:disable-next-line:variable-name
const Cd = this.prms.Cd0.v * (1 + 1 / Math.pow(this.prms.Y.v / this.prms.PBD.v, 2)) * this.fFr;
/** N from Cassan 2016 eq(2) et Cassan 2014 eq(12) */
const N = (alpha * this.calcCf(this.prms.Y.v)) / (this.prms.Y.v / this.prms.PBD.v * Cd * this.prms.C.v);
const N = (alpha * this.calcCf(this.prms.Y.v)) /
(this.prms.Y.v / this.prms.PBD.v * this.Cd * fFr * this.prms.C.v);
return this.U0 - Math.sqrt(
return U0 - Math.sqrt(
2 * MacroRugo.g * this.prms.If.v * this.prms.PBD.v *
(1 - this.sigma * this.prms.C.v) / (Cd * this.prms.C.v * (1 + N))
(1 - this.sigma * this.prms.C.v) / (this.Cd * fFr * this.prms.C.v * (1 + N))
);
}
private get fFr(): number {
if (this._cache.fFr === undefined) {
this._cache.fFr = this.CalcfFr(this.U0);
}
return this._cache.fFr;
}
/**
* Froude correction function
*/
private get fFr(): number {
if (this._cache.fFr === undefined) {
// tslint:disable-next-line:variable-name
const Fr = this.U0 /
(1 - Math.sqrt(MacroRugo.fracAxAy * this.prms.C.v)) /
Math.sqrt(MacroRugo.g * this.prms.Y.v);
private CalcfFr(U0: number): number {
// tslint:disable-next-line:variable-name
const Fr = U0 /
(1 - Math.sqrt(MacroRugo.fracAxAy * this.prms.C.v)) /
Math.sqrt(MacroRugo.g * this.prms.Y.v);
/** Interpolation linéaire entre le bloc rond (Cd0=1) et le carré (Cd0=2) */
const r = 0.4 * this.prms.Cd0.v + 0.7;
/** Interpolation linéaire entre le bloc rond (Cd0=1) et le carré (Cd0=2) */
const r = 0.4 * this.prms.Cd0.v + 0.7;
if (Fr < 1.3) {
this._cache.fFr = Math.pow(Math.min(r / (1 - Math.pow(Fr, 2) / 4), Math.pow(Fr, -2 / 3)), 2);
} else {
this._cache.fFr = Math.pow(Fr, -4 / 3);
}
if (Fr < 1.3) {
return Math.pow(Math.min(r / (1 - Math.pow(Fr, 2) / 4), Math.pow(Fr, -2 / 3)), 2);
} else {
return Math.pow(Fr, -4 / 3);
}
return this._cache.fFr;
}
}
......
......@@ -429,7 +429,7 @@ export class Session {
1.57, // Q
0.6, // h
0.01, // Ks
0.05, // C
0.13, // C
0.5, // D
0.8, // k
1.5 // Cd0
......@@ -493,7 +493,7 @@ export class Session {
3, // DH
0.05, // If
0.01, // Ks
0.05, // C
0.13, // C
0.5, // D
0.8, // k
1.5 // Cd0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment