jalhyd
Version:
JaLHyd, a Javascript Library for Hydraulics
504 lines • 20.2 kB
TypeScript
import { CalculatorType, ComputeNode, IProperties } from "./internal_modules";
import { ParamDefinition, ParamsEquation } from "./internal_modules";
import { LinkedValue } from "./internal_modules";
import { ParamFamily } from "./internal_modules";
import { IParamDefinitionIterator } from "./internal_modules";
import { Props } from "./internal_modules";
import { Message, MessageCode } from "./internal_modules";
import { Observer } from "./internal_modules";
import { Result } from "./internal_modules";
import { VariatedDetails } from "./internal_modules";
declare class NubIterator implements IterableIterator<Nub> {
private _nubs;
private _index;
constructor(n: Nub);
private fill;
next(): IteratorResult<Nub>;
[Symbol.iterator](): IterableIterator<Nub>;
}
/**
* Classe abstraite de Noeud de calcul dans une session :
* classe de base pour tous les calculs
*/
export declare abstract class Nub extends ComputeNode implements IProperties {
/**
* Find longest series, BUT: if any varying parameter is a calculation result,
* its values can't be extended (could be, but not at the moment), so
* the global size in this case will be the min of sizes of linked variated results
* @param variated list of variated parameter/valuesList pairs to examinate
*/
static findVariatedSize(variated: VariatedDetails[]): {
size: number;
longest: number;
minLinkedResultParam: VariatedDetails;
};
protected static concatPrms(p1: ParamsEquation[], p2: ParamsEquation[]): ParamsEquation[];
private static progressPercentageAccordedToChainCalculation;
/** paramétrage de la dichotomie */
dichoStartIntervalMaxSteps: number;
/** pointer to parent Nub */
private _parent;
get parent(): Nub;
setParent(p: Nub): void;
/**
* Used by GUI for translation of the nub type in ngHyd (snackbar, ...).
* Formely childrenType, this was indicating type of children nubs.
* Now the child nub itself declares its type.
* Related to CalculatorType and INFO_CHILD_TYPE_* messages.
*/
protected _intlType: string;
get intlType(): string;
get result(): Result;
/**
* Local setter to set result element of Equation() / Solve() / … as current
* ResultElement, instead of overwriting the whole Result object
* (used by CalcSerie with varying parameters)
*/
protected set currentResultElement(r: Result);
set properties(props: Props);
/**
* return ParamsEquation of all children recursively
*/
get childrenPrms(): ParamsEquation[];
/**
* Returns an array with the calculable parameters
*/
get calculableParameters(): ParamDefinition[];
/**
* Returns an iterator over :
* - own parameters (this._prms)
* - children parameters (this._children[*]._prms)
*/
get parameterIterator(): IParamDefinitionIterator;
protected get progress(): number;
/**
* Updates the progress percentage and notifies observers,
* at most once per 300ms
*/
protected set progress(v: number);
get calcType(): CalculatorType;
/**
* set Nub calculator type.
* give children the opportunity to react to assignment
* @see Structure
*/
protected setCalculatorType(ct: CalculatorType): void;
get calculatedParam(): ParamDefinition;
/**
* Sets p as the parameter to be computed; sets it to CALC mode
*/
set calculatedParam(p: ParamDefinition);
/**
* Returns a parameter descriptor compatible with Calc() methods,
* ie. a symbol string for a Nub's main parameter, or an object
* of the form { uid: , symbol: } for a Nub's sub-Nub parameter
* (ex: Structure parameter in ParallelStructure)
*/
get calculatedParamDescriptor(): string | {
uid: string;
symbol: string;
};
/** parameter that is to be computed by default - to be overloaded by child classes */
protected _defaultCalculatedParam: ParamDefinition;
/** parameter that is to be computed */
protected _calculatedParam: ParamDefinition;
/**
* List of children Nubs; browsed by parameters iterator.
* - for ParallelStructures: contains 0 or more Structures
* - for SectionNub : contains exactly 1 acSection
*/
protected _children: Nub[];
/** properties describing the Nub type */
protected _props: Props;
/** résultat de Calc()/CalcSerie() */
protected _result: Result;
/** implémentation par délégation de IObservable */
private _observable;
/** a rough indication of calculation progress, between 0 and 100 */
private _progress;
/** allows notifying of progress every X milliseconds only */
private previousNotificationTimestamp;
private _firstAnalyticalPrmSymbol;
constructor(prms: ParamsEquation, dbg?: boolean);
setProperties(props: IProperties, resetProps?: boolean): void;
/**
* Finds the previous calculated parameter and sets its mode to SINGLE
*/
unsetCalculatedParam(except: ParamDefinition): void;
/**
* @param excluded parameter to exclude from search
* @returns true if one of the parameters (other than excluded if provided) is in calculated mode
*/
private hasCalculedParam;
/**
* Tries to reset the calculated parameter, successively, to :
* - the default one if it is in SINGLE mode
* - the first SINGLE calculable parameter other than requirer
* - the first MINMAX/LISTE calculable parameter other than requirer
*
* If no default calculated parameter is defined, does nothing.
*
* @param force checking of non pre-existing calculated parameter
*/
resetDefaultCalculatedParam(requirer?: ParamDefinition, force?: boolean): void;
/**
* Returns the first visible calculable parameter other than otherThan,
* that is set to SINGLE, MINMAX or LISTE mode (there might be none)
*/
findFirstCalculableParameter(otherThan?: ParamDefinition): ParamDefinition;
/**
* Formule utilisée pour le calcul analytique (solution directe ou méthode de résolution spécifique)
*/
abstract Equation(sVarCalc: string): Result;
/**
* Calculate and put in cache the symbol of first parameter calculable analytically
*/
get firstAnalyticalPrmSymbol(): string;
/**
* Run Equation with first analytical parameter to compute
* Returns the result in number form
*/
EquationFirstAnalyticalParameter(): number;
/**
* Calcul d'une équation quelle que soit l'inconnue à calculer; déclenche le calcul en
* chaîne des modules en amont si nécessaire
* @param sVarCalc nom de la variable à calculer
* @param rInit valeur initiale de la variable à calculer dans le cas de la dichotomie
*/
Calc(sVarCalc?: string, rInit?: number): Result;
/**
* Calculates required Nubs so that all input data is available;
* uses 50% of the progress
* @returns true if everything went OK, false otherwise
*/
triggerChainCalculation(): {
ok: boolean;
message: Message;
};
/**
* Returns a list of parameters that are fixed, either because their valueMode
* is SINGLE, or because their valueMode is LINK and the reference is
* defined and fixed. Does not take calculated parameters into account.
*/
findFixedParams(): ParamDefinition[];
/**
* Returns a list of parameters that are variating, either because their valueMode
* is LISTE or MINMAX, or because their valueMode is LINK and the reference is
* defined and variated. Does not take calculated parameters into account.
*/
findVariatedParams(): VariatedDetails[];
/**
* compute log stats (# of error, warning, info) on all result elements for all nub (source and source's children)
*/
resultElementsLogStats(stats?: any): any;
/**
* abstract of iterations logs
*/
private generateAbstractLogMessages;
/**
* Effectue une série de calculs sur un paramètre; déclenche le calcul en chaîne
* des modules en amont si nécessaire
* @param rInit solution approximative du paramètre
* @param resetDepending true pour resetResult() sur les Nubs dépendants également
*/
CalcSerie(rInit?: number, resetDepending?: boolean): Result;
addChild(child: Nub, after?: number): void;
getChildren(): Nub[];
/**
* @returns iterator on direct child nubs (may include extra nubs, see Pab nub)
*/
directChildNubIterator(): IterableIterator<Nub>;
/**
* @returns iterator on all child nubs (recursively)
*/
get allChildNubIterator(): NubIterator;
/**
* Returns true if all parameters are valid; used to check validity of
* parameters linked to Nub results
*/
isComputable(): boolean;
/**
* @returns true if nub is an orifice structure
*/
get isOrifice(): boolean;
/**
* Liste des valeurs (paramètre, résultat, résultat complémentaire) liables à un paramètre
* @param src paramètre auquel lier d'autres valeurs
*/
getLinkableValues(src: ParamDefinition): LinkedValue[];
/**
* Returns true if the given Nub UID is either of :
* - the current Nub UID
* - the current Nub's parent Nub UID
* - the UID of any of the current Nub's children
*/
isParentOrChildOf(uid: string): boolean;
/**
* Returns true if the given Nub UID :
* - is the current Nub UID
* - is the UID of any of the current Nub's siblings (children of the same parent)
*/
isSiblingOf(uid: string): boolean;
/**
* Returns all Nubs whose results are required by the given one,
* without following links (stops when it finds a Nub that has to
* be calculated). Used to trigger chain calculation.
*/
getRequiredNubs(visited?: string[]): Nub[];
/**
* Returns all Nubs whose results are required by the given one,
* following links. Used by Solveur.
*/
getRequiredNubsDeep(visited?: string[]): Nub[];
/**
* Returns all Nubs whose parameters or results are targetted
* by the given one.
* (used for dependencies checking at session saving time)
*/
getTargettedNubs(visited?: string[]): Nub[];
/**
* Returns true if
* - this Nub
* - any of this Nub's children
* - this Nub's parent
* depends on
* - the result of the given Nub
* - the result of any of the given Nub's children
* [ note: but NOT the result of the given Nub's parent, or the given Nub might
* be recalculated independently, which is not wanted ]
*
* (ie. "my family depends on the result of your family")
*
* If followLinksChain is false, will limit the exploration to the first target level only
*/
dependsOnNubResult(nub: Nub, followLinksChain?: boolean): boolean;
/**
* Returns true if this nub (parent and children included)
* directly requires (1st level only)
* the given parameter
*/
dependsOnParameter(src: ParamDefinition): boolean;
/**
* Returns true if the computation of the current Nub (parent and children
* included) directly requires (1st level only), anything (parameter or result)
* from the given Nub UID "uid", its parent or any of its children
* @param uid
* @param symbol symbol of the target parameter whose value change triggered this method;
* if current Nub targets this symbol, it will be considered dependent
* @param includeValuesLinks if true, even if this Nub targets only non-calculated non-modified
* parameters, it will be considered dependent @see jalhyd#98
* @param includeOtherDependencies if true, then:
* - if this Nub is a Solveur, also returns true if ${uid} is either the X or the Ytarget's parent
* Nub of this Solveur
* - if this Nub is a Verificateur, also returns true if ${uid} is either a selected Custom
* Species or the Pass to check of this Verificateur
*/
resultDependsOnNub(uid: string, visited?: string[], symbol?: string, includeValuesLinks?: boolean, includeOtherDependencies?: boolean): boolean;
/**
* Returns true if the computation of the current Nub has multiple values
* (whether it is already computed or not), by detecting if any parameter,
* linked or not, is variated
*/
resultHasMultipleValues(): boolean;
/**
* Sets the current result to undefined, as well as the results
* of all depending Nubs; also invalidates all fake ParamValues
* held by LinkedValues pointing to this result
* @param resetDepending true pour resetResult() sur les Nubs dépendants également
*/
resetResult(visited?: string[], resetDepending?: boolean): void;
/**
* For all parameters pointing to the result of the given Nub,
* invalidates fake ParamValues held by pointed LinkedValue
*/
private resetLinkedParamValues;
/**
* Duplicates the current Nub, but does not register it in the session
*/
clone(): Nub;
/**
* Returns a JSON representation of the Nub's current state
* @param extra extra key-value pairs, for ex. calculator title in GUI
* @param nubUidsInSession UIDs of Nubs that will be saved in session along with this one;
* useful to determine if linked parameters must be kept as links
* or have their value copied (if target is not in UIDs list)
*/
serialise(extra?: object, nubUidsInSession?: string[]): string;
/**
* Returns an object representation of the Nub's current state
* @param extra extra key-value pairs, for ex. calculator title in GUI
* @param nubUidsInSession UIDs of Nubs that will be saved in session along with this one;
* useful to determine if linked parameters must be kept as links
* or have their value copied (if target is not in UIDs list)
*/
objectRepresentation(extra?: object, nubUidsInSession?: string[]): object;
/**
* Fills the current Nub with parameter values, provided an object representation
* @param obj object representation of a Nub content (parameters)
* @returns the calculated parameter found, if any - used by child Nub to notify
* its parent of the calculated parameter to set
*/
loadObjectRepresentation(obj: any): {
p: ParamDefinition;
hasErrors: boolean;
changedUids: {
[key: string]: string;
};
};
/**
* Load parameter state from JSON and amend "ret" status variable;
* to be used by loadObjectRepresentation() only
*/
protected loadParam(p: any, ret: {
p: ParamDefinition;
hasErrors: boolean;
}): void;
/**
* Once session is loaded, run a second pass on all linked parameters to
* reset their target if needed
*/
fixLinks(obj: any): {
hasErrors: boolean;
};
/**
* Replaces a child Nub
* @param index index of child in _children array
* @param child new child
* @param resetCalcParam if true, resets default calculated parameter after replacing child
* @param keepParametersState if true, mode and value of parameters will be kept between old and new section
*/
replaceChild(index: number, child: Nub, resetCalcParam?: boolean, keepParametersState?: boolean): void;
/**
* Finds oldChild in the list, and replaces it at the same index with newChild;
* if the current calculated parameter belonged to the old child, resets a default one
* @param oldChild child to get the index for
* @param newChild child to set at this index
*/
replaceChildInplace(oldChild: Nub, newChild: Nub): void;
/**
* Returns the current index of the given child if any,
* or else returns -1
* @param child child or child UID to look for
*/
getIndexForChild(child: Nub | string): number;
/**
* @return true if given Nub id a child of current Nub
*/
hasChild(child: Nub): boolean;
/**
* @return true if given Nub uid id a child of current Nub
*/
hasChildUid(childUid: string): boolean;
/**
* @return child having the given UID
*/
getChild(uid: string): Nub;
/** Moves a child up (1 step) */
moveChildUp(child: Nub): void;
/** Moves a child down (1 step) */
moveChildDown(child: Nub): void;
/**
* Removes a child
* @param index
*/
deleteChild(index: number): void;
/** Removes all children */
deleteAllChildren(): void;
/**
* Returns the position or the current structure (starting at 0)
* in the parent Nub
*/
findPositionInParent(): number;
/**
* Adds a new empty ResultElement to the current Result object, so that
* computation result is stored into it, via set currentResult(); does
* the same for all children
*/
initNewResultElement(): void;
/**
* Sets this._result to a new empty Result, before starting a new CalcSerie();
* does the same for all children
*/
reinitResult(): void;
/**
* @returns true if results for this nub and all its children do not contain errors
*/
get allResultsOk(): boolean;
/**
* @returns true if all messages in nub hierarchy have the same code
*/
hasOnlyMessage(code: MessageCode): boolean;
get uniqueMessageCodes(): MessageCode[];
/**
* ajoute un observateur à la liste
*/
addObserver(o: Observer): void;
/**
* supprime un observateur de la liste
*/
removeObserver(o: Observer): void;
/**
* notifie un événement aux observateurs
*/
notifyObservers(data: any, sender?: any): void;
/**
* Retrieves the ParamFamily associated to the given symbol, whether it is a
* parameter or a result
*/
getFamily(symbol: string): ParamFamily;
/**
* Retrieves the unit (string) associated to the given symbol, whether it is a
* parameter or a result
*/
getUnit(symbol: string): string;
/**
* Find the longest variating parameter, which will also be the Nub's result length
*/
variatingLength(): number;
/**
* For all SINGLE, LINK and CALC parameters, copies singleValue to
* sandbox value (.v) before calculation
*/
copySingleValuesToSandboxValues(): void;
protected findCalculatedParameter(): any;
protected doCalc(computedSymbol?: any, rInit?: number): Result;
/**
* Returns values of parameters and the result of the calculation for the calculated parameter
* @param sVarCalc Symbol of the calculated param
* @param result Result object of the calculation
*/
protected getParamValuesAfterCalc(sVarCalc: string, result: Result): {
[key: string]: number;
};
/**
* To call Nub.calc(…) from indirect child
*/
protected nubCalc(sVarCalc: string, rInit?: number): Result;
/**
* Used by GUI to update results display
*/
protected notifyResultUpdated(): void;
/**
* Used by GUI to update progress bar
*/
protected notifyProgressUpdated(): void;
/**
* Optional postprocessing after adding / replacing a child
*/
protected adjustChildParameters(child: Nub): void;
/**
* 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
*/
protected Solve(sVarCalc: string, rInit: number): Result;
invertedPropertiesEnumAndValues(forceNumbers?: boolean): any;
addPropertiesObserver(o: Observer): void;
protected childHasProperty(key: string, nth?: number): boolean;
hasProperty(key: string): boolean;
get keys(): string[];
getPropValue(key: string): any;
setPropValue(key: string, val: any, sender?: any): boolean;
}
export {};
//# sourceMappingURL=nub.d.ts.map