Commit 414dc6b9 authored by Dorchies David's avatar Dorchies David
Browse files

#6 Ajout de l'équation Cunge80

Showing with 307 additions and 51 deletions
+307 -51
......@@ -210,7 +210,7 @@ function [Q,C,w] = Qouvrage(T,h1,h2,w,hv,L,Cd)
end
// Classique - Orifice ========================================
if (T==4)
Q=Cd*min(h1,w)*L*R2G*(h1)^0.5;
Q=Cd*min(h1,w)*L*R2G*(h1 - min(h1,w)/2)^0.5;
if (h1>w)
C=3;
else
......@@ -220,8 +220,12 @@ function [Q,C,w] = Qouvrage(T,h1,h2,w,hv,L,Cd)
// Classique - Noyee ==========================================
if (T==5)
if (h1>h2)
Q=Cd*w*L*R2G*(h1-h2)^0.5;
C=5;
Q=Cd*min(h1,w)*L*R2G*(h1-h2)^0.5;
if (h1>w)
C=5;
else
C=2;
end
else
Q=0;
C=0;
......
......@@ -7,7 +7,7 @@ function TestQOuvrageSuite(T)
//TestQOuvrageLoop(sTest, T, L, Cd, H1, h2, W)
TestQOuvrageLoop("Calcul Q avec W croissant",T, 2, 0.6, 1.2, 1, 0:0.1:1.3);
TestQOuvrageLoop("Calcul Q en charge avec h1 croissant",T, 2, 0.6, [1.05,1.3,1.5], 1, 0.8);
TestQOuvrageLoop("Calcul Q a surface libre avec h1 croissant",T, 2, 0.6, 1.1:0.4:1.5, 1, 2);
TestQOuvrageLoop("Calcul Q a surface libre avec h1 croissant",T, 2, 0.6, [1.1,1.5], 1, 2);
endfunction
describe("CEM88D");
......@@ -22,3 +22,8 @@ TestQOuvrageSuite(3);
describe("Classique - Orifice dénoyé");
TestQOuvrageSuite(4);
describe("Classique - Orifice noyé");
TestQOuvrageSuite(5);
describe("Cunge 80");
TestQOuvrageSuite(6);
......@@ -3,11 +3,10 @@
* @param sTxt Texte de la suite de test
* @param fFun Fonction de la suite de test
*/
export function describe(sTxt: string, fFun: Function) {
//console.group();
export function describe(sTxt: string, fFun: () => void) {
// tslint:disable-next-line:no-console
console.log(sTxt);
fFun();
//console.groupEnd();
}
/**
......@@ -15,7 +14,8 @@ export function describe(sTxt: string, fFun: Function) {
* @param sTxt Texte de la suite de test
* @param fFun Fonction de la suite de test
*/
export function xdescribe(sTxt: string, fFun: Function) {
export function xdescribe(sTxt: string, fFun: () => void) {
// tslint:disable-next-line:no-console
console.log(sTxt + " ignored ***");
}
......@@ -24,42 +24,63 @@ export function xdescribe(sTxt: string, fFun: Function) {
* @param sTxt Texte à afficher pour la spec
* @param fFun Function à lancer pour la spec
*/
export function it(sTxt: string, fFun: Function) {
export function it(sTxt: string, fFun: () => void) {
// tslint:disable-next-line:no-console
console.log(sTxt);
fFun();
}
/**
* Mock expect et toBeCloseTo de Jasmine.
/**
* Mock expect et toBeCloseTo de Jasmine.
* Ne fonctionne pas à cause de this = undefined dans le contexte "use strict"
*/
export function expect(obj: Object) {
export function expect(obj: object) {
this.testResult = obj;
this.toBeCloseTo = function(expected: number, precision: number) {
var pow = Math.pow(10, precision + 1);
var delta = Math.abs(expected - this.testResult);
var maxDelta = Math.pow(10, -precision) / 2;
const pow = Math.pow(10, precision + 1);
const delta = Math.abs(expected - this.testResult);
const maxDelta = Math.pow(10, -precision) / 2;
if (Math.round(delta * pow) / pow > maxDelta) {
console.error("Expected "+this.testResult+" to be close to "+expected+","+precision);
// tslint:disable-next-line:no-console
console.error("Expected " + this.testResult + " to be close to " + expected + "," + precision);
}
return this;
};
return this;
}
/**
/**
* Mock de la function chainée à expect de test d'une valeur à un epsilon près
* @param actual Valeur numérique sortie du test
* @param expected Valeur numérique attendue
* @param precision Précision attendue (nombre de chiffre après la virgule)
*/
export function toBeCloseTo (actual: number, expected: number, precision: number) {
var pow = Math.pow(10, precision + 1);
var delta = Math.abs(expected - actual);
var maxDelta = Math.pow(10, -precision) / 2;
export function toBeCloseTo(actual: number, expected: number, precision: number) {
const pow = Math.pow(10, precision + 1);
const delta = Math.abs(expected - actual);
const maxDelta = Math.pow(10, -precision) / 2;
if (Math.round(delta * pow) / pow > maxDelta) {
console.error("Expected "+actual+" to be close to "+expected+","+precision);
// tslint:disable-next-line:no-console
console.error("Expected " + actual + " to be close to " + expected + "," + precision);
}
return this;
};
}
/**
* Mock de la fonction toBe de Jasmine : the actual value to be `===` to the expected value
* @param actual Objet à tester
* @param expected Objet de référence
*/
export function toBe(actual: any, expected: any) {
return actual === expected;
}
/**
* Mock de la fonction toBe de Jasmine : the actual value to be `===` to the expected value
* @param actual Objet à tester
* @param expected Objet de référence
*/
export function toEqual(actual: any, expected: any) {
return actual === expected;
}
......@@ -6,15 +6,35 @@ import { RectangularStructure } from "../../src/structure/rectangular_structure"
import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure";
import { precDigits } from "../nubtest";
/**
* Récupération du nom de la classe
* https://www.stevefenton.co.uk/2013/04/Obtaining-A-Class-Name-At-Runtime-In-TypeScript/
*/
class Describer {
/**
* Récupère le nom de la classe d'un objet
* @param inputClass Objet à tester
*/
public static getName(inputClass: any) {
const funcNameRegex = /function (.{1,})\(/;
const results = (funcNameRegex).exec((inputClass as any).constructor.toString());
return (results && results.length > 1) ? results[1] : "";
}
}
export function itCalcQ(
struct: RectangularStructure, h1: number, W: number, Q: number,
mode?: StructureFlowMode, regime?: StructureFlowRegime) {
struct.debug("itCalQ " + Describer.getName(struct) + " h1=" + h1 + " W=" + W + " Q=" + Q);
struct.prms.h1.v = h1;
struct.prms.W.v = W;
const res: Result = struct.Calc("Q");
struct.debug("struct.Calc(Q)=" + res.vCalc);
it("Q(h1=" + h1 + ",W=" + W + ") should be " + Q, () => {
struct.debug("struct.Calc(Q)=" + res.vCalc);
expect(res.vCalc).toBeCloseTo(Q, precDigits);
});
if (mode !== undefined) {
......
......@@ -44,7 +44,7 @@ class StructureTest extends Structure {
}
const structTestPrm: StructureParams = new StructureParams(1, 30, 15);
const structTest: StructureTest = new StructureTest(structTestPrm, true);
const structTest: StructureTest = new StructureTest(structTestPrm, false);
describe("Class Structure: ", () => {
......
......@@ -8,7 +8,7 @@ import { StructureCem88d } from "../../src/structure/structure_cem88d";
import { itCalcQ } from "./rectangular_structure";
const structPrm: RectangularStructureParams = new RectangularStructureParams(1, 1, 1, 2, 0.6, 0);
const structTest: StructureCem88d = new StructureCem88d(structPrm, true);
const structTest: StructureCem88d = new StructureCem88d(structPrm, false);
describe("Class StructureCem88d: ", () => {
describe("Calcul Q avec W croissant: ", () => {
......
......@@ -8,7 +8,7 @@ import { StructureCem88v } from "../../src/structure/structure_cem88v";
import { itCalcQ } from "./rectangular_structure";
const structPrm: RectangularStructureParams = new RectangularStructureParams(1, 1, 1, 2, 0.6, 0);
const structTest: StructureCem88v = new StructureCem88v(structPrm, true);
const structTest: StructureCem88v = new StructureCem88v(structPrm, false);
describe("Class StructureCem88v: ", () => {
describe("Calcul Q avec W croissant: ", () => {
......
// tslint:disable-next-line:no-reference
/// <reference path="../../node_modules/@types/jasmine/index.d.ts" />
import { Result } from "../../src/base";
import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params";
import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure";
import { StructureCunge80 } from "../../src/structure/structure_cunge80";
import { itCalcQ } from "./rectangular_structure";
const structPrm: RectangularStructureParams = new RectangularStructureParams(1, 1, 1, 2, 0.6, 0);
const structTest: StructureCunge80 = new StructureCunge80(structPrm, false);
describe("Class StructureCunge80: ", () => {
describe("Calcul Q avec W croissant: ", () => {
const W: number[] = [
0.000000, 0.100000, 0.200000, 0.300000, 0.400000, 0.500000, 0.600000,
0.700000, 0.800000, 0.900000, 1.000000, 1.100000, 1.200000, 1.300000];
const h1: number = 1.200000;
const Q: number[] = [0.000000, 0.237709, 0.475418, 0.713127, 0.950836, 1.188545,
1.426254, 1.663963, 1.901673, 2.139382, 2.377091, 2.377091, 2.377091, 2.377091];
for (let i = 0; i < Q.length; i++ ) {
itCalcQ(structTest, h1, W[i], Q[i]);
}
});
describe("Calcul Q en charge avec h1 croissant: ", () => {
const W: number = 0.8;
const h1: number[] = [1.050000, 1.300000, 1.500000];
const Q: number[] = [0.950836, 2.329064, 3.557704];
const mode: StructureFlowMode[] = [
StructureFlowMode.ORIFICE, StructureFlowMode.ORIFICE, StructureFlowMode.ORIFICE];
const regime: StructureFlowRegime[] = [
StructureFlowRegime.SUBMERGED, StructureFlowRegime.SUBMERGED, StructureFlowRegime.FREE];
for (let i = 0; i < Q.length; i++ ) {
itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]);
}
});
describe("Calcul Q a surface libre avec h1 croissant: ", () => {
const W: number = Infinity;
const h1: number[] = [1.100000, 1.500000];
const Q: number[] = [1.680857, 3.758510];
const mode: StructureFlowMode[] = [
StructureFlowMode.WEIR, StructureFlowMode.WEIR];
const regime: StructureFlowRegime[] = [
StructureFlowRegime.SUBMERGED, StructureFlowRegime.FREE];
for (let i = 0; i < Q.length; i++ ) {
itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]);
}
});
});
......@@ -8,7 +8,7 @@ import { StructureOrificeFree } from "../../src/structure/structure_orifice_free
import { itCalcQ } from "./rectangular_structure";
const structPrm: RectangularStructureParams = new RectangularStructureParams(1, 1, 1, 2, 0.6, 0);
const structTest: StructureOrificeFree = new StructureOrificeFree(structPrm, true);
const structTest: StructureOrificeFree = new StructureOrificeFree(structPrm, false);
describe("Class StructureOrificeFree: ", () => {
describe("Calcul Q avec W croissant: ", () => {
......
......@@ -8,7 +8,7 @@ import { StructureOrificeSubmerged } from "../../src/structure/structure_orifice
import { itCalcQ } from "./rectangular_structure";
const structPrm: RectangularStructureParams = new RectangularStructureParams(1, 1, 1, 2, 0.6, 0);
const structTest: StructureOrificeSubmerged = new StructureOrificeSubmerged(structPrm, true);
const structTest: StructureOrificeSubmerged = new StructureOrificeSubmerged(structPrm, false);
describe("Class StructureOrificeSubmerged: ", () => {
describe("Calcul Q avec W croissant: ", () => {
......
......@@ -8,7 +8,7 @@ import { StructureWeirFree } from "../../src/structure/structure_weir_free";
import { itCalcQ } from "./rectangular_structure";
const structPrm: RectangularStructureParams = new RectangularStructureParams(1, 1, 1, 2, 0.6, 0);
const structTest: StructureWeirFree = new StructureWeirFree(structPrm, true);
const structTest: StructureWeirFree = new StructureWeirFree(structPrm, false);
describe("Class StructureWeirFree: ", () => {
describe("Calcul Q avec W croissant: ", () => {
......
import { Result } from "../../src/base";
import { RectangularStructure } from "../../src/structure/rectangular_structure";
import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure";
import { it, toBe, toBeCloseTo } from "../mock_jasmine";
import { precDigits } from "../nubtest";
/**
* Récupération du nom de la classe
* https://www.stevefenton.co.uk/2013/04/Obtaining-A-Class-Name-At-Runtime-In-TypeScript/
*/
class Describer {
/**
* Récupère le nom de la classe d'un objet
* @param inputClass Objet à tester
*/
public static getName(inputClass: any) {
const funcNameRegex = /function (.{1,})\(/;
const results = (funcNameRegex).exec((inputClass as any).constructor.toString());
return (results && results.length > 1) ? results[1] : "";
}
}
export function itCalcQ(
struct: RectangularStructure, h1: number, W: number, Q: number,
mode?: StructureFlowMode, regime?: StructureFlowRegime) {
struct.debug("itCalQ " + Describer.getName(struct) + " h1=" + h1 + " W=" + W + " Q=" + Q);
struct.prms.h1.v = h1;
struct.prms.W.v = W;
const res: Result = struct.Calc("Q");
struct.debug("struct.Calc(Q)=" + res.vCalc);
it("Q(h1=" + h1 + ",W=" + W + ") should be " + Q, () => {
struct.debug("struct.Calc(Q)=" + res.vCalc);
toBeCloseTo(res.vCalc, Q, precDigits);
});
if (mode !== undefined) {
it("Q(h1=" + h1 + ",W=" + W + ") Mode should be " + mode, () => {
toBe(res.extraVar.Mode, mode);
});
}
if (regime !== undefined) {
it("Q(h1=" + h1 + ",W=" + W + ") Regime should be " + regime, () => {
toBe(res.extraVar.Regime, regime);
});
}
}
import { Result } from "../../src/base";
import { RectangularStructureParams, StructureCem88d } from "../../src/structure/structure_cem88d";
import { describe, it, toBeCloseTo } from "../mock_jasmine";
import { describe, xdescribe } from "../mock_jasmine";
import { precDigits } from "../nubtest";
import { itCalcQ } from "./test_rectangular_structure";
const structPrm: RectangularStructureParams = new RectangularStructureParams(1, 1, 1, 2, 0.6, 0);
const structTest: StructureCem88d = new StructureCem88d(structPrm, true);
const structTest: StructureCem88d = new StructureCem88d(structPrm, false);
describe("Class StructureCem88d: ", () => {
function itCalcQ(struct: StructureCem88d, h1: number, W: number, Q: number) {
it("Q(h1=" + h1 + ",W=" + W + ") should be " + Q, () => {
struct.prms.h1.v = h1;
struct.prms.W.v = W;
toBeCloseTo(struct.Calc("Q").vCalc, Q, precDigits);
});
}
describe("Calcul Q avec W croissant: ", () => {
const W: number[] = [0.000000, 0.100000, 0.200000, 0.300000, 0.400000, 0.500000,
......
import { Result } from "../../src/base";
import { RectangularStructureParams, StructureCem88v } from "../../src/structure/structure_cem88v";
import { describe, it, toBeCloseTo, xdescribe } from "../mock_jasmine"
import { describe, xdescribe } from "../mock_jasmine";
import { precDigits } from "../nubtest";
import { itCalcQ } from "./test_rectangular_structure";
const structPrm: RectangularStructureParams = new RectangularStructureParams(1, 1, 1, 2, 0.6, 0);
const structTest: StructureCem88v = new StructureCem88v(structPrm, true);
const structTest: StructureCem88v = new StructureCem88v(structPrm, false);
describe("Class StructureCem88v: ", () => {
function itCalcQ(struct: StructureCem88v, h1: number, W: number, Q: number) {
it("Q(h1=" + h1 + ",W=" + W + ") should be " + Q, () => {
struct.prms.h1.v = h1;
struct.prms.W.v = W;
toBeCloseTo(struct.Calc("Q").vCalc, Q, precDigits);
});
}
describe("Calcul Q avec W croissant: ", () => {
const W: number[] = [0.000000, 0.100000, 0.200000, 0.300000, 0.400000, 0.500000, 0.600000,
0.700000, 0.800000, 0.900000, 1.000000, 1.100000, 1.200000, 1.300000];
......
import { Result } from "../../src/base";
import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params";
import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure";
import { StructureCunge80 } from "../../src/structure/structure_cunge80";
import { describe, xdescribe } from "../mock_jasmine";
import { itCalcQ } from "./test_rectangular_structure";
const structPrm: RectangularStructureParams = new RectangularStructureParams(1, 1, 1, 2, 0.6, 0);
const structTest: StructureCunge80 = new StructureCunge80(structPrm, true);
describe("Class StructureCunge80: ", () => {
describe("Calcul Q avec W croissant: ", () => {
const W: number[] = [
0.000000, 0.100000, 0.200000, 0.300000, 0.400000, 0.500000, 0.600000,
0.700000, 0.800000, 0.900000, 1.000000, 1.100000, 1.200000, 1.300000];
const h1: number = 1.200000;
const Q: number[] = [0.000000, 0.237709, 0.475418, 0.713127, 0.950836, 1.188545,
1.426254, 1.663963, 1.901673, 2.139382, 2.377091, 2.377091, 2.377091, 2.377091];
for (let i = 0; i < Q.length; i++ ) {
itCalcQ(structTest, h1, W[i], Q[i]);
}
});
describe("Calcul Q en charge avec h1 croissant: ", () => {
const W: number = 0.8;
const h1: number[] = [1.050000, 1.300000, 1.500000];
const Q: number[] = [0.950836, 2.329064, 3.557704];
const mode: StructureFlowMode[] = [
StructureFlowMode.ORIFICE, StructureFlowMode.ORIFICE, StructureFlowMode.ORIFICE];
const regime: StructureFlowRegime[] = [
StructureFlowRegime.SUBMERGED, StructureFlowRegime.SUBMERGED, StructureFlowRegime.FREE];
for (let i = 0; i < Q.length; i++ ) {
itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]);
}
});
describe("Calcul Q a surface libre avec h1 croissant: ", () => {
const W: number = Infinity;
const h1: number[] = [1.100000, 1.500000];
const Q: number[] = [1.680857, 3.758510];
const mode: StructureFlowMode[] = [
StructureFlowMode.WEIR, StructureFlowMode.WEIR];
const regime: StructureFlowRegime[] = [
StructureFlowRegime.SUBMERGED, StructureFlowRegime.FREE];
for (let i = 0; i < Q.length; i++ ) {
itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]);
}
});
});
......@@ -62,7 +62,7 @@ export abstract class Debug {
* Affiche un message dans la console si le flag this.DBG est à true
* @param s Message à afficher dans la console
*/
protected debug(s: any) {
public debug(s: any) {
if (this._DBG) console.log(s);
}
......
import { Result } from "../base";
import { RectangularStructure } from "./rectangular_structure";
import { RectangularStructureParams } from "./rectangular_structure_params";
import { Structure, StructureFlowMode, StructureFlowRegime } from "./structure";
export { RectangularStructureParams };
/**
* Equation classique orifice noyé
*/
export class StructureCunge80 extends RectangularStructure {
/**
* Calcul du débit avec l'équation classique d'un orifice noyé
* @param sVarCalc Variable à calculer (doit être égale à Q ici)
*/
public Equation(sVarCalc: string): Result {
const res: Result = super.Equation(sVarCalc);
switch (res.extraVar.Regime) {
case StructureFlowRegime.FREE:
if (res.extraVar.Mode === StructureFlowMode.WEIR) {
const R32: number = 3 * Math.sqrt(3) / 2;
res.vCalc = this.prms.Cd.v * this.prms.L.v * Structure.R2G / R32 * Math.pow(this.prms.h1.v, 1.5);
this.debug("StructureCunge80.Equation WEIR FREE Q=" + res.vCalc);
} else {
res.vCalc = this.prms.Cd.v * this.prms.L.v * Structure.R2G
* this.prms.W.v * Math.pow(this.prms.h1.v - this.prms.W.v, 0.5);
this.debug("StructureCunge80.Equation ORIFICE FREE Q=" + res.vCalc);
}
break;
case StructureFlowRegime.SUBMERGED:
if (res.extraVar.Mode === StructureFlowMode.WEIR) {
res.vCalc = this.prms.Cd.v * this.prms.L.v * Structure.R2G * this.prms.h2.v
* Math.sqrt(this.prms.h1.v - this.prms.h2.v);
this.debug("StructureCunge80.Equation WEIR SUBMERGED Q=" + res.vCalc);
} else {
res.vCalc = this.prms.Cd.v * this.prms.L.v * Structure.R2G
* this.prms.W.v * Math.sqrt(this.prms.h1.v - this.prms.h2.v);
this.debug("StructureCunge80.Equation ORIFICE SUBMERGED Q=" + res.vCalc);
}
}
return res;
}
protected getFlowRegime() {
if (this.prms.h1.v >= 1.5 * this.prms.h2.v) {
return StructureFlowRegime.FREE;
} else {
return StructureFlowRegime.SUBMERGED;
}
}
protected getFlowMode() {
const regime: StructureFlowRegime = this.getFlowRegime();
switch (regime) {
case StructureFlowRegime.FREE:
if (this.prms.W.v <= 2 / 3 * this.prms.h1.v) {
return StructureFlowMode.ORIFICE;
} else {
return StructureFlowMode.WEIR;
}
case StructureFlowRegime.SUBMERGED:
if (this.prms.W.v <= this.prms.h2.v) {
return StructureFlowMode.ORIFICE;
} else {
return StructureFlowMode.WEIR;
}
}
}
}
Supports Markdown
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