Commit 802242fd authored by Grand Francois's avatar Grand Francois
Browse files

#46 : ajout du Nub pour les sections paramétrées

- Nub.CalcSerie() : ajout d'un paramètre précisant la variable à calculer (nécessaire car les variables à calculer pour les sections paramétrées ne font pas partie des paramètres du Nub)
Showing with 156 additions and 185 deletions
+156 -185
...@@ -44,6 +44,10 @@ export abstract class ComputeNode extends Debug { ...@@ -44,6 +44,10 @@ export abstract class ComputeNode extends Debug {
this._prms.DefineCalculability(); this._prms.DefineCalculability();
} }
public get parameters(): ParamsEquation {
return this._prms;
}
public getParameter(name: string): ParamDefinition { public getParameter(name: string): ParamDefinition {
return this._prms.getParameter(name); return this._prms.getParameter(name);
} }
......
...@@ -12,6 +12,7 @@ export * from "./dichotomie"; ...@@ -12,6 +12,7 @@ export * from "./dichotomie";
export * from "./lechaptcalmon"; export * from "./lechaptcalmon";
export * from "./regime_uniforme"; export * from "./regime_uniforme";
export * from "./remous"; export * from "./remous";
export * from "./section/section_nub";
export * from "./section/section_type"; export * from "./section/section_type";
export * from "./section/section_trapez"; export * from "./section/section_trapez";
export * from "./section/section_rectang"; export * from "./section/section_rectang";
......
...@@ -39,10 +39,12 @@ export abstract class Nub extends ComputeNode { ...@@ -39,10 +39,12 @@ export abstract class Nub extends ComputeNode {
* @param rPrec précision de calcul * @param rPrec précision de calcul
*/ */
public Calc(sVarCalc: string, rInit?: number, rPrec: number = 0.001): Result { public Calc(sVarCalc: string, rInit?: number, rPrec: number = 0.001): Result {
const computedVar = this.getParameter(sVarCalc);
if (rInit === undefined) { if (rInit === undefined) {
rInit = this._prms.map[sVarCalc].v; rInit = computedVar.v;
} }
if (this._prms.map[sVarCalc].isAnalytical()) { if (computedVar.isAnalytical()) {
this._result = this.Equation(sVarCalc); this._result = this.Equation(sVarCalc);
return this._result; return this._result;
} }
...@@ -53,14 +55,20 @@ export abstract class Nub extends ComputeNode { ...@@ -53,14 +55,20 @@ export abstract class Nub extends ComputeNode {
return this._result; return this._result;
} }
const sAnalyticalPrm: string = this.getFirstAnalyticalParameter().symbol; const sAnalyticalPrm: string = this.getFirstAnalyticalParameter().symbol;
this._prms.map[sVarCalc].v = resSolve.vCalc; computedVar.v = resSolve.vCalc;
const res: Result = this.Equation(sAnalyticalPrm); const res: Result = this.Equation(sAnalyticalPrm);
res.vCalc = resSolve.vCalc; res.vCalc = resSolve.vCalc;
this._result = res; this._result = res;
return res; return res;
} }
public CalcSerie(rPrec: number = 0.001, rInit?: number): Result { /**
* effectue une série de calculs sur un paramètre
* @param rPrec précision de calcul
* @param rInit solution approximative du paramètre
* @param sDonnee éventuel symbole du paramètre à calculer
*/
public CalcSerie(rPrec: number = 0.001, rInit?: number, sDonnee?: string): Result {
const res = new Result(); const res = new Result();
this._result = res; this._result = res;
...@@ -79,28 +87,35 @@ export abstract class Nub extends ComputeNode { ...@@ -79,28 +87,35 @@ export abstract class Nub extends ComputeNode {
break; break;
case ParamValueMode.CALCUL: case ParamValueMode.CALCUL:
if (computedParam == undefined) if (sDonnee == undefined) {
computedParam = p; if (computedParam == undefined)
else computedParam = p;
throw new Error(`CalcSerie() : il y plusieurs paramètres à calculer (au moins ${computedParam.symbol} et ${p.symbol})`); else
throw new Error(`CalcSerie() : il y plusieurs paramètres à calculer (au moins ${computedParam.symbol} et ${p.symbol})`);
}
break; break;
} }
} }
if (computedParam == undefined) if (sDonnee)
throw new Error(`CalcSerie() : aucun paramètre à calculer`); var computedSymbol: string = sDonnee;
else {
if (computedParam == undefined)
throw new Error(`CalcSerie() : aucun paramètre à calculer`);
computedSymbol = computedParam.symbol;
}
if (rInit === undefined) if (rInit === undefined)
rInit = this._prms.map[computedParam.symbol].v; rInit = this._prms.map[computedSymbol].v;
if (variatedParam == undefined) if (variatedParam == undefined)
this.Calc(computedParam.symbol, rInit, rPrec); // résultat dans this._result this.Calc(computedSymbol, rInit, rPrec); // résultat dans this._result
else { else {
const res = new Result(); const res = new Result();
variatedParam.paramValues.initIterator(); variatedParam.paramValues.initIterator();
while (variatedParam.paramValues.hasNext) { while (variatedParam.paramValues.hasNext) {
variatedParam.paramValues.next; variatedParam.paramValues.next;
this.Calc(computedParam.symbol, rInit, rPrec); // résultat dans this._result this.Calc(computedSymbol, rInit, rPrec); // résultat dans this._result
res.addResultElement(this._result.resultElement); res.addResultElement(this._result.resultElement);
res.addLog(this._result.log); res.addLog(this._result.log);
if (this._result.ok) if (this._result.ok)
...@@ -121,7 +136,7 @@ export abstract class Nub extends ComputeNode { ...@@ -121,7 +136,7 @@ export abstract class Nub extends ComputeNode {
private Solve(sVarCalc: string, rInit: number, rPrec: number): Result { private Solve(sVarCalc: string, rInit: number, rPrec: number): Result {
const dicho: Dichotomie = new Dichotomie(this, sVarCalc, this.DBG); const dicho: Dichotomie = new Dichotomie(this, sVarCalc, this.DBG);
dicho.startIntervalMaxSteps = this._dichoStartIntervalMaxSteps; dicho.startIntervalMaxSteps = this._dichoStartIntervalMaxSteps;
const target = this._prms.getFirstAnalyticalParameter(); const target = this.getFirstAnalyticalParameter();
return dicho.Dichotomie(target.v, rPrec, rInit); return dicho.Dichotomie(target.v, rPrec, rInit);
} }
......
import { ComputeNodeType, CalculatorType } from "./compute-node"
import { ParamsEquation } from "./param/params-equation";
import { ParamDefinition } from "./param/param-definition";
import { ConduiteDistribParams, ConduiteDistrib } from "./cond_distri";
import { LechaptCalmonParams, LechaptCalmon } from "./lechaptcalmon";
import { acSection } from "./section/section_type";
import { ParamsSectionTrapez, cSnTrapez } from "./section/section_trapez";
import { ParamsSectionRectang, cSnRectang } from "./section/section_rectang";
import { ParamsSectionCirc, cSnCirc } from "./section/section_circulaire";
import { ParamsSectionPuiss, cSnPuiss } from "./section/section_puissance";
import { RegimeUniforme } from "./regime_uniforme";
import { CourbeRemous, CourbeRemousParams } from "./remous";
import { PabDimensionParams, PabDimension } from "./pab/pab_dimension";
import { PabPuissanceParams, PabPuissance } from "./pab/pab_puissance";
import { HashTable } from "./util/hashtable";
import { ParallelStructureParams } from "./structure/parallel_structure_params";
import { ParallelStructure } from "./structure/parallel_structure";
import { RectangularStructureParams } from "./structure/rectangular_structure_params";
import { StructureCem88d } from "./structure/structure_cem88d";
import { StructureKiviParams } from "./structure/structure_kivi_params";
import { StructureKivi } from "./structure/structure_kivi";
export class ComputeNodeParameters {
private static _instance: ComputeNodeParameters;
private _nodes: HashTable;
private constructor() {
this._nodes = new HashTable();
}
public static getInstance() {
if (ComputeNodeParameters._instance == undefined)
ComputeNodeParameters._instance = new ComputeNodeParameters();
return ComputeNodeParameters._instance;
}
private createSection(nt: ComputeNodeType): acSection {
switch (nt) {
case ComputeNodeType.None: // pour les paramètres communs, n'importe quelle section convient
case ComputeNodeType.SectionTrapeze:
{
let cn = new ParamsSectionTrapez(1, 0.5, undefined, undefined,
1, undefined, 0.1, 1);
let n = new cSnTrapez(cn); // pour initialiser la calculabilité des paramètres
return n;
}
case ComputeNodeType.SectionRectangle:
{
let cn = new ParamsSectionRectang(undefined, 1, undefined, 1,
undefined, 0.1, 1);
let n = new cSnRectang(cn); // pour initialiser la calculabilité des paramètres
return n;
}
case ComputeNodeType.SectionCercle:
{
let cn = new ParamsSectionCirc(1, undefined, undefined, 1,
undefined, 0.1, 1);
let n = new cSnCirc(cn); // pour initialiser la calculabilité des paramètres
return n;
}
case ComputeNodeType.SectionPuissance:
{
let cn = new ParamsSectionPuiss(0.5, undefined, 1, undefined,
1, undefined, 0.1, 1);
let n = new cSnPuiss(cn); // pour initialiser la calculabilité des paramètres
return n;
}
default:
throw new Error(`type de section ${ComputeNodeType[nt]} non pris en charge`);
}
}
private createComputeNodeParameters(calcType: CalculatorType, nodeType: ComputeNodeType): ParamsEquation {
switch (calcType) {
case CalculatorType.ConduiteDistributrice:
{
const cn = new ConduiteDistribParams(undefined, undefined, undefined, undefined, undefined);
const n = new ConduiteDistrib(cn); // pour initialiser la calculabilité des paramètres
return cn;
}
case CalculatorType.LechaptCalmon:
{
const cn = new LechaptCalmonParams(undefined, undefined, undefined, undefined, undefined, undefined, undefined);
const n = new LechaptCalmon(cn); // pour initialiser la calculabilité des paramètres
return cn;
}
case CalculatorType.SectionParametree:
{
const sect: acSection = this.createSection(nodeType);
return sect.prms;
}
case CalculatorType.RegimeUniforme:
const sect: acSection = this.createSection(nodeType);
const ru = new RegimeUniforme(sect); // pour initialiser la calculabilité des paramètres
return sect.prms;
case CalculatorType.CourbeRemous:
{
const sect: acSection = this.createSection(nodeType);
const crp = new CourbeRemousParams(sect, undefined, undefined, undefined, undefined, undefined);
const ru = new CourbeRemous(crp); // pour initialiser la calculabilité des paramètres
return crp;
}
case CalculatorType.PabDimensions:
{
let cn = new PabDimensionParams(undefined, undefined, undefined);
let n = new PabDimension(cn); // pour initialiser la calculabilité des paramètres
return cn;
}
case CalculatorType.PabPuissance:
{
let cn = new PabPuissanceParams(undefined, undefined, undefined);
let n = new PabPuissance(cn); // pour initialiser la calculabilité des paramètres
return cn;
}
case CalculatorType.Structure:
switch (nodeType) {
case ComputeNodeType.None: // pour les paramètres communs, n'importe quelle structure convient
case ComputeNodeType.StructureRectangle:
let cn = new RectangularStructureParams(undefined, 0.5, 2, 1, undefined, undefined);
let n = new StructureCem88d(cn);
return cn;
case ComputeNodeType.StructureKIVI:
{
let cn = new StructureKiviParams(undefined, 1, 2, 1, undefined, undefined, undefined, undefined);
let n = new StructureKivi(cn);
return cn;
}
default:
throw new Error(`ComputeNodeParameters.createComputeNodeParameters() : calculatrice '${CalculatorType[calcType]}' / noeud de calcul '${ComputeNodeType[nodeType]}' non pris en charge`);
}
case CalculatorType.ParallelStructure:
{
let cn = new ParallelStructureParams(undefined, undefined, undefined);
let n = new ParallelStructure(cn);
return cn;
}
default:
throw new Error(`ComputeNodeParameters.createComputeNodeParameters() : calculatrice '${CalculatorType[calcType]}' / noeud de calcul '${ComputeNodeType[nodeType]}' non pris en charge`);
}
}
public getComputeNodeParameter(calcType: CalculatorType, nodeType: ComputeNodeType, symbol: string): ParamDefinition {
const key = { calcType, nodeType };
let params = this._nodes.get(key);
if (params == undefined) {
params = this.createComputeNodeParameters(calcType, nodeType);
this._nodes.put(key, params);
}
return params.map[symbol];
}
}
import { Nub } from "../nub"; import { Nub } from "../nub";
import { acSection } from "./section_type"; import { acSection } from "./section_type";
import { Result } from "../util/result"; import { Result } from "../util/result";
import { ParamDefinition, ParamCalculability } from "../param/param-definition";
import { ParamDomain, ParamDomainValue } from "../param/param-domain";
/** /**
* Nub sur les sections paramétrées * Nub sur les sections paramétrées
*/ */
export class SectionParametree extends Nub { export class SectionParametree extends Nub {
private _section: acSection;
private _sectionVars: { [key: string]: ParamDefinition };
constructor(sect: acSection, dbg: boolean = false) { constructor(sect: acSection, dbg: boolean = false) {
super(sect.prms, dbg); super(sect.prms, dbg);
this._section = sect;
this.initSectionVars();
}
private initSectionVars() {
this._sectionVars = {};
this.initSectionVar("Hs");
this.initSectionVar("Hsc");
this.initSectionVar("B");
this.initSectionVar("P");
this.initSectionVar("S");
this.initSectionVar("R");
this.initSectionVar("V");
this.initSectionVar("Fr");
this.initSectionVar("Yc");
this.initSectionVar("Yn");
this.initSectionVar("Yf");
this.initSectionVar("Yt");
this.initSectionVar("Yco");
this.initSectionVar("J");
this.initSectionVar("Imp");
this.initSectionVar("Tau0");
this.initSectionVar("I-J");
}
private initSectionVar(symbol: string) {
this._sectionVars[symbol] = this.createSectionVar(symbol);
}
private createSectionVar(symbol: string): ParamDefinition {
switch (symbol) {
case "Hs":
case "Hsc":
case "B":
case "P":
case "S":
case "R":
case "V":
case "Fr":
case "Yc":
case "Yn":
case "Yf":
case "Yt":
case "Yco":
case "J":
case "Imp":
case "Tau0":
var dom = new ParamDomain(ParamDomainValue.POS_NULL);
break;
case "I-J":
var dom = new ParamDomain(ParamDomainValue.ANY);
break;
default:
throw new Error(`SectionParametree.createSectionVar() : symbole ${symbol} non pris en charge`);
}
const res = new ParamDefinition(symbol, dom);
res.calculability = ParamCalculability.EQUATION;
return res;
}
public get section(): acSection {
return this._section;
}
public getParameter(name: string): ParamDefinition {
try {
return super.getParameter(name);
}
catch (e) {
// pas trouvé -> il s'agit peut être d'une variable dans le genre Hs, B, P, ...
const res = this._sectionVars[name];
if (!res)
throw new Error(`SectionParametree.getParameter() : nom de paramètre ${name} incorrect`);
return res;
}
}
public getFirstAnalyticalParameter(): ParamDefinition {
let res = super.getFirstAnalyticalParameter();
if (res)
return res;
for (const k in this._sectionVars) {
const p = this._sectionVars[k];
if (p.isAnalytical)
return p;
}
return undefined;
} }
/** /**
...@@ -17,6 +116,28 @@ export class SectionParametree extends Nub { ...@@ -17,6 +116,28 @@ export class SectionParametree extends Nub {
} }
Equation(sVarCalc: string): Result { Equation(sVarCalc: string): Result {
throw new Error(`SectionParam.Equation() : calcul sur ${sVarCalc} non implémenté`); switch (sVarCalc) {
case "Hs":
case "Hsc":
case "B":
case "P":
case "S":
case "R":
case "V":
case "Fr":
case "Yc":
case "Yn":
case "Yf":
case "Yt":
case "Yco":
case "J":
case "Imp":
case "Tau0":
case "I-J":
return this._section.Calc(sVarCalc, this.getParameter("Y").v);
default:
throw new Error(`SectionParam.Equation() : calcul sur ${sVarCalc} non implémenté`);
}
} }
} }
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