Commit d0c7c3dc authored by Grand Francois's avatar Grand Francois
Browse files

Merge branch 'regimeuniforme'

Showing with 481 additions and 130 deletions
+481 -130
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
npm-debug.log npm-debug.log
testem.log testem.log
/typings /typings
Makefile
# e2e # e2e
/e2e/*.js /e2e/*.js
......
Makefile 0 → 100644
SRC_DIR := src
BUILD_DIR := build
NODE_BASE := $(HOME)/Documents/dev/node-v6.10.2-linux-x64
NODE := $(NODE_BASE)/bin/node
JASMINE_CLI := ./node_modules/jasmine-node/lib/jasmine-node/cli.js
#$(error $(NODE))
SOURCE_FILES := $(shell find $(SRC_DIR) -name *.ts)
all : compile
compile : build-dir $(SOURCE_FILES)
npm run build
build-dir :
mkdir -p $(BUILD_DIR)
buildspec :
npm run buildspec
jasmine : buildspec
npm run jasmine
karma :
npm run karma
clean :
rm -rf $(BUILD_DIR)
debug_test 0 → 100755
#!/bin/bash
do_kill()
{
local pid=$1
if [[ -n $pid ]]; then
if [[ -n $(ps -ef|grep $pid|grep -v grep) ]]; then
echo "killing $pid..."
kill $jm_pid
else
echo "no process with pid $pid"
fi
fi
}
do_exit()
{
# echo "exits"
do_kill $jm_pid
}
syntax()
{
echo "syntaxe : $(basename $0) <fichier spec>"
exit 1
}
trap do_exit SIGINT
trap do_exit EXIT
if [[ $# != 1 ]]; then
syntax
fi
ni=$(ps -ef|grep node-inspector|grep -v grep)
if [[ -z $ni ]]; then
echo "starting node-inspector..."
node-inspector &
else
echo "node-inspector already running"
fi
echo
echo "debugging $1..."
node --debug-brk ./node_modules/jasmine-node/bin/jasmine-node $1 &
jm_pid=$!
echo
#ps -ef|grep jasmine-node|grep -v grep
#pid=$(ps -ef|grep jasmine-node|grep -v grep|awk '{print $2}')
#echo $pid $jm_pid
echo "starting Chrome...."
chromium-browser http://127.0.0.1:8080/?port=5858
...@@ -15,9 +15,10 @@ module.exports = function (config) { ...@@ -15,9 +15,10 @@ module.exports = function (config) {
// list of files / patterns to load in the browser // list of files / patterns to load in the browser
files: [ files: [
{ pattern: 'src/**/*.ts', included: false }, { pattern: 'spec/test-main.js', included: true },
{ pattern: 'spec/**/*.ts', included: false }, { pattern: 'spec/**/*.ts', included: false },
'spec/test-main.js' { pattern: 'src/**/*.ts', included: false }
// { pattern: 'build/**/*.js', included: false }
], ],
...@@ -29,17 +30,29 @@ module.exports = function (config) { ...@@ -29,17 +30,29 @@ module.exports = function (config) {
// preprocess matching files before serving them to the browser // preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: { preprocessors: {
'+(src|spec)**/*.ts': ['typescript'] // '+(src|spec)/**/*.ts': ['typescript']
'**/*.ts': ['typescript']
}, },
typescriptPreprocessor: { typescriptPreprocessor: {
// options passed to the typescript compiler
options: { options: {
// https://github.com/Microsoft/TypeScript/blob/b0584b58fa07ee8c06e6d6f0f1bce2d4c37c7640/lib/typescript.d.ts#L1573 sourceMap: true, // (optional) Generates corresponding .map file.
// enum ScriptTarget { ES3 = 0, ES5 = 1, ES6 = 2, ES2015 = 2, Latest = 2 } // enum ScriptTarget { ES3 = 0, ES5 = 1, ES6 = 2, ES2015 = 2, Latest = 2 }
target: 1, target: 'ES5', // (optional) Specify ECMAScript target version: 'ES3' (default), or 'ES5'
// https://github.com/Microsoft/TypeScript/blob/b0584b58fa07ee8c06e6d6f0f1bce2d4c37c7640/lib/typescript.d.ts#L1544
// enum ModuleKind { None = 0, CommonJS = 1, AMD = 2, UMD = 3, System = 4, ES6 = 5, ES2015 = 5 } // enum ModuleKind { None = 0, CommonJS = 1, AMD = 2, UMD = 3, System = 4, ES6 = 5, ES2015 = 5 }
module: 2 module: 'amd', // (optional) Specify module code generation: 'commonjs' or 'amd'
// noImplicitAny: true, // (optional) Warn on expressions and declarations with an implied 'any' type.
// noResolve: true, // (optional) Skip resolution and preprocessing.
// removeComments: true, // (optional) Do not emit comments to output.
// concatenateOutput: false // (optional) Concatenate and emit output to single file. By default true if module option is omited, otherwise false.
},
// transforming the filenames
transformPath: function (path) {
return path.replace(/\.ts$/, '.js');
} }
}, },
...@@ -60,6 +73,7 @@ module.exports = function (config) { ...@@ -60,6 +73,7 @@ module.exports = function (config) {
// level of logging // level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO, logLevel: config.LOG_INFO,
// logLevel: config.LOG_DEBUG,
// enable / disable watching file and executing tests whenever any file changes // enable / disable watching file and executing tests whenever any file changes
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
"devDependencies": { "devDependencies": {
"@types/jasmine": "^2.5.47", "@types/jasmine": "^2.5.47",
"jasmine-core": "^2.5.2", "jasmine-core": "^2.5.2",
"jasmine-node": "^1.14.5",
"karma": "^1.3.0", "karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0", "karma-chrome-launcher": "^2.0.0",
"karma-jasmine": "^1.0.2", "karma-jasmine": "^1.0.2",
...@@ -21,8 +22,9 @@ ...@@ -21,8 +22,9 @@
}, },
"scripts": { "scripts": {
"build": "./node_modules/typescript/bin/tsc --p src/tsconfig.app.json", "build": "./node_modules/typescript/bin/tsc --p src/tsconfig.app.json",
"buildtest": "./node_modules/typescript/bin/tsc --p spec/tsconfig.spec.json", "buildspec": "./node_modules/typescript/bin/tsc --p spec/tsconfig.spec.json",
"test": "./node_modules/typescript/bin/tsc --p spec/tsconfig.spec.json && ./node_modules/karma/bin/karma start", "jasmine": "./node_modules/.bin/jasmine",
"karma": "./node_modules/typescript/bin/tsc --p spec/tsconfig.spec.json && ./node_modules/karma/bin/karma start",
"lint": "./node_modules/tslint/bin/tslint", "lint": "./node_modules/tslint/bin/tslint",
"viz": "tsviz -recursive src/ jalhyd_class_diagram.png" "viz": "tsviz -recursive src/ jalhyd_class_diagram.png"
} }
......
/// <reference path="../node_modules/@types/jasmine/index.d.ts" /> /// <reference path="../node_modules/@types/jasmine/index.d.ts" />
import { nub, res } from "./nubtest"; import { Result } from "../src/base";
import { nub, precDigits } from "./nubtest";
describe('Class Nub: ', () => { describe('Class Nub: ', () => {
beforeEach(() => { // beforeEach(() => {
res.vCalc = 3; // res.vCalc = 3;
}); // });
describe('Calc(): ', () => { describe('Calc(): ', () => {
it('should return a result.vCalc equal to 3', () => { it('should return a result.vCalc equal to 3', () => {
expect(nub.Calc("C")).toEqual(res); let res = new Result(3);
expect(nub.Calc("C").vCalc).toBeCloseTo(res.vCalc, precDigits);
});
it('should return a result.vCalc equal to 1', () => {
let res = new Result(1);
expect(nub.Calc("A").vCalc).toBeCloseTo(res.vCalc, precDigits);
});
it('should return a result.vCalc equal to 2', () => {
let res = new Result(2); precDigits
expect(nub.Calc("B").vCalc).toBeCloseTo(res.vCalc, precDigits);
}); });
}); });
}); });
...@@ -67,9 +67,6 @@ describe('Class ConduiteDistrib: ', () => { ...@@ -67,9 +67,6 @@ describe('Class ConduiteDistrib: ', () => {
nub.v.j = 0.6; nub.v.j = 0.6;
nub.v.nu = 1e-6; nub.v.nu = 1e-6;
let res = new Result;
res.vCalc = 737.0213567924325;
expect(nub.Calc("lg").vCalc).toBeCloseTo(737.021, 3); expect(nub.Calc("lg").vCalc).toBeCloseTo(737.021, 3);
}); });
}); });
...@@ -82,9 +79,6 @@ describe('Class ConduiteDistrib: ', () => { ...@@ -82,9 +79,6 @@ describe('Class ConduiteDistrib: ', () => {
nub.v.j = 0.6; nub.v.j = 0.6;
nub.v.lg = 100; nub.v.lg = 100;
let res = new Result;
res.vCalc = 0.0029506676187219757;
expect(nub.Calc("nu").vCalc).toBeCloseTo(0.00295, 5); expect(nub.Calc("nu").vCalc).toBeCloseTo(0.00295, 5);
}); });
}); });
......
/// <reference path="../node_modules/@types/jasmine/index.d.ts" /> /// <reference path="../node_modules/@types/jasmine/index.d.ts" />
import { nub, res } from "./nubtest"; // import { nub, res } from "./nubtest";
import { nub } from "./nubtest";
import { Dichotomie } from "../src/dichotomie" import { Dichotomie } from "../src/dichotomie"
let dicho: Dichotomie = new Dichotomie(nub, "A"); let dicho: Dichotomie = new Dichotomie(nub, "A");
...@@ -8,7 +9,7 @@ let dicho: Dichotomie = new Dichotomie(nub, "A"); ...@@ -8,7 +9,7 @@ let dicho: Dichotomie = new Dichotomie(nub, "A");
describe('Class Dichotomie: ', () => { describe('Class Dichotomie: ', () => {
describe('Dichotomie(3, 1E-6, 0): ', () => { describe('Dichotomie(3, 1E-6, 0): ', () => {
it('should return a result close to 1', () => { it('should return a result close to 1', () => {
expect(dicho.Dichotomie(3, 1E-6, 0).vCalc).toBeCloseTo(1,1E-6); expect(dicho.Dichotomie(3, 1E-6, 0).vCalc).toBeCloseTo(1, 1E-6);
}); });
}); });
}); });
import { Nub, Result, IParametres } from "../src/base"; import { Result, IParamsEquation } from "../src/base";
import { Nub } from "../src/nub";
export class NubTest extends Nub { export class NubTest extends Nub {
constructor(v: IParametres) { constructor(v: IParamsEquation) {
super(v); super(v);
this.sVarsEq = ["C"]; this.sVarsEq = ["C"];
} }
Equation(): Result { Equation(): Result {
let res: Result = new Result(); return new Result(this.v["A"] + this.v["B"]);
res.vCalc = this.v["A"] + this.v["B"];
return res;
} }
} }
export let nub = new NubTest({ "A": 1, "B": 2, "C": null }); export let nub = new NubTest({ "A": 1, "B": 2, "C": 3 });
export let res = new Result; //export let res = new Result(0);
\ No newline at end of file
/**
* précision de calcul (nombre de décimales)
*/
export let precDigits = 3;
/**
* précision de calcul (max de abs(v-v'))
*/
export let precDist = Math.pow(10, -precDigits);
/// <reference path="../node_modules/@types/jasmine/index.d.ts" />
import { Result } from "../src/base";
import { RegimeUniforme } from "../src/regime_uniforme";
import { cSnRectang } from "../src/section/section_rectang";
import { cParamsCanal } from "../src/section/section_type";
import { precDigits, precDist } from "./nubtest";
describe('Class RegimeUniforme / section rectangulaire : ', () => {
// beforeAll(() => {
// });
describe('Calc(): ', () => {
it('Q should be 1.568', () => {
let sect: cSnRectang;
let prmsCanal: cParamsCanal;
// Ks=Strickler, Q=Débit, If=pente du font, précision, YB=hauteur de berge, YCL=Condition limite en cote à l'amont ou à l'aval
prmsCanal = new cParamsCanal(40, 0, 0.001, precDist, 1)
// largeur de fond
sect = new cSnRectang(false, prmsCanal, 2.5);
// tirant d'eau
sect.v.Y = 0.8;
var ru = new RegimeUniforme(sect);
// nom variable à calculer, valeur de Q
expect(ru.Calc("Q").vCalc).toBeCloseTo(1.568, precDigits);
});
it('Q should be 0.731', () => {
let sect: cSnRectang;
let prmsCanal: cParamsCanal;
// Ks=Strickler, Q=Débit, If=pente du font, précision, YB=hauteur de berge, YCL=Condition limite en cote à l'amont ou à l'aval
prmsCanal = new cParamsCanal(30, 0, 0.0001, precDist, 1.2)
// largeur de fond
sect = new cSnRectang(false, prmsCanal, 3);
// tirant d'eau
sect.v.Y = 1.1;
var ru = new RegimeUniforme(sect);
// nom variable à calculer, valeur de Q
expect(ru.Calc("Q").vCalc).toBeCloseTo(0.731, precDigits);
});
it('Strickler should be 30.618', () => {
let sect: cSnRectang;
let prmsCanal: cParamsCanal;
// Ks=Strickler, Q=Débit, If=pente du font, précision, YB=hauteur de berge, YCL=Condition limite en cote à l'amont ou à l'aval
prmsCanal = new cParamsCanal(40, 1.2, 0.001, precDist, 1)
// largeur de fond
sect = new cSnRectang(false, prmsCanal, 2.5);
// tirant d'eau
sect.v.Y = 0.8;
var ru = new RegimeUniforme(sect);
// nom variable à calculer, valeur de Ks
expect(ru.Calc("Ks").vCalc).toBeCloseTo(30.618, precDigits);
});
});
});
/// <reference path="../node_modules/@types/jasmine/index.d.ts" />
import { Result } from "../src/base";
import { RegimeUniforme } from "../src/regime_uniforme";
import { cSnTrapez } from "../src/section/section_trapez";
import { cParamsCanal } from "../src/section/section_type";
import { precDigits, precDist } from "./nubtest";
describe('Class RegimeUniforme / section trapèze: ', () => {
beforeAll(() => {
});
describe('Calc(): ', () => {
it('Q should be 1.988', () => {
let sect: cSnTrapez;
let paramCnl: cParamsCanal;
// Ks=Strickler, Q=Débit, If=pente du font, précision, YB=hauteur de berge, YCL=Condition limite en cote à l'amont ou à l'aval
paramCnl = new cParamsCanal(40, 0, 0.001, precDist, 1)
// largeur de fond, fruit
sect = new cSnTrapez(false, paramCnl, 2.5, 0.56);
// tirant d'eau
sect.v.Y = 0.8;
var ru: RegimeUniforme;
ru = new RegimeUniforme(sect);
expect(ru.Calc("Q").vCalc).toBeCloseTo(1.988, precDigits);
});
it('LargeurFond should be 1.516', () => {
let sect: cSnTrapez;
let paramCnl: cParamsCanal;
// Ks=Strickler, Q=Débit, If=pente du font, précision, YB=hauteur de berge, YCL=Condition limite en cote à l'amont ou à l'aval
paramCnl = new cParamsCanal(40, 1.2, 0.001, 0.001, 1)
// largeur de fond, fruit
sect = new cSnTrapez(false, paramCnl, 0, 0.56);
// tirant d'eau
sect.v.Y = 0.8;
var ru: RegimeUniforme;
ru = new RegimeUniforme(sect);
expect(ru.Calc("LargeurFond").vCalc).toBeCloseTo(1.516, precDigits);
});
});
});
{
"spec_dir": "build/spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": false
}
\ No newline at end of file
var TEST_REGEXP = /(spec|test)\.js$/i; var TEST_REGEXP = /(spec|test)\.js$/i;
var allTestFiles = []; var allTestFiles = [];
//console.log('files ' + Object.keys(window.__karma__.files));
// Get a list of all the test files to include // Get a list of all the test files to include
Object.keys(window.__karma__.files).forEach(function(file) { Object.keys(window.__karma__.files).forEach(function (file) {
if (TEST_REGEXP.test(file)) { if (TEST_REGEXP.test(file)) {
// Normalize paths to RequireJS module names. // Normalize paths to RequireJS module names.
// If you require sub-dependencies of test files to be loaded as-is (requiring file extension) // If you require sub-dependencies of test files to be loaded as-is (requiring file extension)
......
/** /**
* Résultat de calcul comprenant la valeur du résultat et des calculs annexes (flag, calculs intermédiaires...) * Résultat de calcul comprenant la valeur du résultat et des calculs annexes (flag, calculs intermédiaires...)
*/ */
export class Result { export class Result {
/** Valeur calculée */ /** Valeur calculée */
public vCalc: number; private _vCalc: number;
/** Variables intermédiaires, flags d'erreur */ /** Variables intermédiaires, flags d'erreur */
public extraVar: {}; public extraVar: {};
constructor(v: number) {
this._vCalc = v
this.extraVar = {}
};
get vCalc() { return this._vCalc; }
} }
/** /**
* Série de valeurs à calculer définie par le nom de la variable à sérier et le vecteur de valeur * Série de valeurs à calculer définie par le nom de la variable à sérier et le vecteur de valeur
*/ */
...@@ -23,8 +31,10 @@ export class Serie { ...@@ -23,8 +31,10 @@ export class Serie {
} }
} }
/**
export interface IParametres { * liste des valeurs des variables
*/
export interface IParamsEquation {
[key: string]: number; // map : array of numbers with string keys [key: string]: number; // map : array of numbers with string keys
} }
...@@ -48,69 +58,3 @@ export abstract class Debug { ...@@ -48,69 +58,3 @@ export abstract class Debug {
if (this.DBG) console.log(s); if (this.DBG) console.log(s);
} }
} }
/**
* Classe abstraite de Noeud de calcul : classe de base pour tous les calculs
*/
export abstract class Nub extends Debug {
/// Nom des variables calculées par la méthode Equation
private _varsEq: string[] = [];
public v: IParametres;
constructor(parametres: IParametres) {
super(false);
this.v = parametres;
}
/**
* Formule utilisée pour le calcul analytique (solution directe ou méthode de résolution spécifique)
*/
abstract Equation(sVarCalc: string): Result;
/**
* Calcul d'une équation quelque soit l'inconnue à calculer
*/
Calc(sVarCalc: string): Result {
for (let sVarEq of this._varsEq) {
if (sVarCalc == sVarEq) {
return this.Equation(sVarCalc);
}
}
return this.Solve(sVarCalc);
}
CalcSerie(svarCalc: string, serie: Serie): Result[] {
/** @todo faire une boucle pour appeler this.Calc avec chaque valeur de serie.values
*
*/
let results = [new (Result)];
return results;
}
get sVarsEq(): string[] {
return this._varsEq;
}
set sVarsEq(sVarsEq: string[]) {
this._varsEq = sVarsEq;
}
AddVarEq(sVarEq: string) {
this._varsEq.push(sVarEq);
}
/**
* Résoud l'équation par une méthode numérique
*/
Solve(sVarCalc: string): Result {
let res: Result;
/** @todo Résolution par méthode numérique (dichotomie...) */
return res;
}
}
import { Nub, Result, IParametres } from "./base"; import { Result, IParamsEquation } from "./base";
import { Nub } from "./nub";
// export interface IParamConduiteDistrib extends IParametres { // export interface IParamConduiteDistrib extends IParametres {
export class ParamConduiteDistrib implements IParametres { export class ParamConduiteDistrib implements IParamsEquation {
[key: string]: number; [key: string]: number;
/** Débit */ /** Débit */
...@@ -39,33 +40,34 @@ export class ConduiteDistrib extends Nub { ...@@ -39,33 +40,34 @@ export class ConduiteDistrib extends Nub {
} }
Equation(sVarCalc: string): Result { Equation(sVarCalc: string): Result {
let res: Result = new Result(); let res: Result;
let v: number;
var K = 0.3164 * Math.pow(4, 1.75) / (5.5 * 9.81 * Math.pow(3.1415, 1.75)); // Constante de la formule var K = 0.3164 * Math.pow(4, 1.75) / (5.5 * 9.81 * Math.pow(3.1415, 1.75)); // Constante de la formule
switch (sVarCalc) { switch (sVarCalc) {
case "j": case "j":
res.vCalc = K * Math.pow(this.v.nu, 0.25) * Math.pow(this.v.q, 1.75) * this.v.lg / Math.pow(this.v.d, 4.75); v = K * Math.pow(this.v.nu, 0.25) * Math.pow(this.v.q, 1.75) * this.v.lg / Math.pow(this.v.d, 4.75);
break; break;
case "d": case "d":
res.vCalc = Math.pow(this.v.j / (K * Math.pow(this.v.nu, 0.25) * Math.pow(this.v.q, 1.75) * this.v.lg), 1 / 4.75); v = Math.pow(this.v.j / (K * Math.pow(this.v.nu, 0.25) * Math.pow(this.v.q, 1.75) * this.v.lg), 1 / 4.75);
break; break;
case "q": case "q":
res.vCalc = Math.pow(this.v.j / (K * Math.pow(this.v.nu, 0.25) * this.v.lg / Math.pow(this.v.d, 4.75)), 1 / 1.75) v = Math.pow(this.v.j / (K * Math.pow(this.v.nu, 0.25) * this.v.lg / Math.pow(this.v.d, 4.75)), 1 / 1.75)
break; break;
case "lg": case "lg":
res.vCalc = this.v.j / (K * Math.pow(this.v.nu, 0.25) * Math.pow(this.v.q, 1.75) / Math.pow(this.v.d, 4.75)); v = this.v.j / (K * Math.pow(this.v.nu, 0.25) * Math.pow(this.v.q, 1.75) / Math.pow(this.v.d, 4.75));
break; break;
case "nu": case "nu":
res.vCalc = Math.pow(this.v.j / (K * Math.pow(this.v.q, 1.75) * this.v.lg / Math.pow(this.v.d, 4.75)), 1 / 0.25); v = Math.pow(this.v.j / (K * Math.pow(this.v.q, 1.75) * this.v.lg / Math.pow(this.v.d, 4.75)), 1 / 0.25);
break; break;
} }
return res; return new Result(v);
} }
} }
\ No newline at end of file
import { Debug, Nub, Result } from "./base"; import { Debug, Result } from "./base";
import { Nub } from "./nub";
export class Dichotomie extends Debug { export class Dichotomie extends Debug {
/** Pas de parcours de l'intervalle pour initialisation dichotomie */ /** Pas de parcours de l'intervalle pour initialisation dichotomie */
...@@ -34,7 +35,6 @@ export class Dichotomie extends Debug { ...@@ -34,7 +35,6 @@ export class Dichotomie extends Debug {
return (a || b) && !(a && b); return (a || b) && !(a && b);
} }
/** /**
* Calcul de l'équation analytique. * Calcul de l'équation analytique.
* @note Wrapper vers this.nub.Equation pour simplifier le code. * @note Wrapper vers this.nub.Equation pour simplifier le code.
...@@ -48,10 +48,8 @@ export class Dichotomie extends Debug { ...@@ -48,10 +48,8 @@ export class Dichotomie extends Debug {
return this.nub.Equation(this.nub.sVarsEq[0]); return this.nub.Equation(this.nub.sVarsEq[0]);
} }
/** /**
* Calcul à l'ouvrage * Calcul à l'ouvrage
* @param sVarCalc Nom de la variable à calculer
* @param rTarget Valeur cible * @param rTarget Valeur cible
* @param rtol Précision attendue du résultat * @param rtol Précision attendue du résultat
* @param rInit Valeur initiale de l'inconnue à rechercher * @param rInit Valeur initiale de l'inconnue à rechercher
...@@ -79,7 +77,7 @@ export class Dichotomie extends Debug { ...@@ -79,7 +77,7 @@ export class Dichotomie extends Debug {
v1 = v; v1 = v;
v2 = v; v2 = v;
this.debug(nIterMax);
//** @todo : Chercher en dehors de l'intervalle en le décalant à droite ou à gauche en fonction de la valeur */ //** @todo : Chercher en dehors de l'intervalle en le décalant à droite ou à gauche en fonction de la valeur */
let nIter: number; let nIter: number;
for (nIter = 1; nIter < nIterMax; nIter++) { for (nIter = 1; nIter < nIterMax; nIter++) {
...@@ -113,11 +111,12 @@ export class Dichotomie extends Debug { ...@@ -113,11 +111,12 @@ export class Dichotomie extends Debug {
} }
if (this.XOR(rTarget > v1, rTarget >= v2)) { break; } if (this.XOR(rTarget > v1, rTarget >= v2)) { break; }
} }
this.debug("intervalle initial " + X1 + ", " + X2);
// Gestion de l'absence de solution dans l'intervalle de recherche // Gestion de l'absence de solution dans l'intervalle de recherche
if (nIter >= this.IDEFINT) { if (nIter >= this.IDEFINT) {
this.debug("nIter >= this.IDEFINT"); this.debug("nIter >= this.IDEFINT");
if (v2 < rTarget && v1 < rTarget) { if (v2 < rTarget && v1 < rTarget) {
// Cote de l'eau trop basse pour passer le débit il faut ouvrir un autre ouvrage // Cote de l'eau trop basse pour passer le débit il faut ouvrir un autre ouvrage
this.vX = XmaxInit; this.vX = XmaxInit;
...@@ -154,8 +153,6 @@ export class Dichotomie extends Debug { ...@@ -154,8 +153,6 @@ export class Dichotomie extends Debug {
res.extraVar["flag"] = -1; // la valeur cible n'est pas dans l'intervalle de recherche res.extraVar["flag"] = -1; // la valeur cible n'est pas dans l'intervalle de recherche
return res; return res;
} }
res = new Result(); return new Result(X);
res.vCalc = X;
return res;
} }
} }
import { Nub, Result, IParametres } from "./base"; import { Result, IParamsEquation } from "./base";
import { Nub } from "./nub";
interface IParamLechaptCalmon extends IParamsEquation {
interface IParamLechaptCalmon extends IParametres {
/** Débit */ /** Débit */
Q: number; Q: number;
/** Diamètre */ /** Diamètre */
D: number; D: number;
/** Perte de charge */ /** Perte de charge */
...@@ -32,22 +32,28 @@ class LechaptCalmon extends Nub { ...@@ -32,22 +32,28 @@ class LechaptCalmon extends Nub {
} }
Equation(sVarCalc: string): Result { Equation(sVarCalc: string): Result {
let res: Result; let v: number;
switch (sVarCalc) { switch (sVarCalc) {
case "Q": case "Q":
res.vCalc = Math.pow((((this.v.J * Math.pow(this.v.D, this.v.N)) / this.v.L) * (1000 / this.v.Lg)), 1 / this.v.M); v = Math.pow((((this.v.J * Math.pow(this.v.D, this.v.N)) / this.v.L) * (1000 / this.v.Lg)), 1 / this.v.M);
break; break;
case "D": case "D":
res.vCalc = Math.pow((((this.v.L * Math.pow(this.v.Q, this.v.M)) / this.v.J) * (this.v.Lg / 1000)), 1 / this.v.N); v = Math.pow((((this.v.L * Math.pow(this.v.Q, this.v.M)) / this.v.J) * (this.v.Lg / 1000)), 1 / this.v.N);
break break
case "J": case "J":
res.vCalc = ((this.v.L * Math.pow(this.v.Q, this.v.M)) / Math.pow(this.v.D, this.v.N)) * (this.v.Lg / 1000); v = ((this.v.L * Math.pow(this.v.Q, this.v.M)) / Math.pow(this.v.D, this.v.N)) * (this.v.Lg / 1000);
break; break;
case "Lg": case "Lg":
res.vCalc = ((this.v.J * Math.pow(this.v.D, this.v.N)) / (this.v.L * Math.pow(this.v.Q, this.v.M))) * 1000; v = ((this.v.J * Math.pow(this.v.D, this.v.N)) / (this.v.L * Math.pow(this.v.Q, this.v.M))) * 1000;
default:
throw "invalid variable name " + sVarCalc;
} }
return res; return new Result(v);
} }
} }
\ No newline at end of file
src/nub.ts 0 → 100644
import { Debug, IParamsEquation, Result, Serie } from "./base"
import { Dichotomie } from "./dichotomie"
/**
* Classe abstraite de Noeud de calcul : classe de base pour tous les calculs
*/
export abstract class Nub extends Debug {
/// Nom des variables calculées par la méthode Equation
private _varsEq: string[] = [];
public v: IParamsEquation;
constructor(paramsEq: IParamsEquation, dbg: boolean = false) {
super(dbg);
this.v = paramsEq;
}
/**
* Formule utilisée pour le calcul analytique (solution directe ou méthode de résolution spécifique)
*/
abstract Equation(sVarCalc: string): Result;
/**
* Calcul d'une équation quelque soit l'inconnue à calculer
* @param sVarCalc nom de la variable à calculer
* @param rInit valeur initiale de la variable à calculer dans le cas de la dichotomie
* @param rPrec précision de calcul
*/
Calc(sVarCalc: string, rInit: number = 0, rPrec: number = 0.001): Result {
for (let sVarEq of this._varsEq) {
if (sVarCalc == sVarEq) {
return this.Equation(sVarCalc);
}
}
return this.Solve(sVarCalc, rInit, rPrec);
}
CalcSerie(svarCalc: string, serie: Serie): Result[] {
/** @todo faire une boucle pour appeler this.Calc avec chaque valeur de serie.values
*
*/
// let results = [new (Result)];
let results = [new Result(0)];
return results;
}
get sVarsEq(): string[] {
return this._varsEq;
}
set sVarsEq(sVarsEq: string[]) {
this._varsEq = sVarsEq;
}
AddVarEq(sVarEq: string) {
this._varsEq.push(sVarEq);
}
/**
* Résoud l'équation par une méthode numérique
* @param sVarCalc nom de la variable à calculer
* @param rInit valeur initiale de la variable à calculer dans le cas de la dichotomie
* @param rPrec précision de calcul
*/
Solve(sVarCalc: string, rInit: number, rPrec: number): Result {
let dicho: Dichotomie = new Dichotomie(this, sVarCalc);
var target = this.v[this._varsEq[0]];
return dicho.Dichotomie(target, rPrec, rInit);
}
}
import { Result, IParamsEquation } from "./base";
import { Nub } from "./nub";
import { acSection, cParamsCanal } from "./section/section_type";
export class RegimeUniforme extends Nub {
private Sn: acSection; ///< Objet section
constructor(s: acSection) {
// let paramsEq: { [key: string]: number } = {};
super(s.v, false);
this.debug('constructeur RU');
this.Sn = s;
this.AddVarEq("Q");
this.AddVarEq("Y");
}
/**
* Calcul du débit en régime uniforme.
* @return Débit en régime uniforme
*/
Calc_Qn() {
this.Sn.Reset(true);
if (this.Sn.oP.v.If <= 0) {
var Qn = 0; // ? false bool
//this.oLog.Add('h_normale_pente_neg_nul',true);
} else {
Qn = this.Sn.oP.v.Ks * Math.pow(this.Sn.Calc('R', this.Sn.v.Y), 2 / 3) * this.Sn.Calc('S', this.Sn.v.Y) * Math.sqrt(this.Sn.oP.v.If);
this.debug("RU : Qn=" + Qn);
}
return Qn;
}
Equation(sVarCalc: string): Result {
let v: number;
switch (sVarCalc) {
case 'Y':
v = this.Sn.Calc('Yn');
break;
case 'Q':
v = this.Calc_Qn();
break;
// default:
// var oDicho = new cDichotomie(this.oLog, this, 'Calc_Qn');
// v = oDicho.calculer(this.v['Q'], this.precision, rInit);
// break;
default:
throw "invalid variable name " + sVarCalc;
}
return new Result(v);
}
}
\ No newline at end of file
export class cLog {
public txt;
constructor() {
this.txt = '';
}
Add(sTxt,bErr=false) {
// peut on mettre des balises ?
this.txt += '<li';
if(bErr) {this.txt += ' class="hyd_erreur"';}
this.txt += '>'+sTxt+'</li>';
}
Result() {
if(this.txt!='') {
return this.txt;
} else {
return '';
}
}
}
\ No newline at end of file
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