Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
cassiopee
jalhyd
Commits
2f62c612
Commit
2f62c612
authored
Nov 14, 2019
by
Mathias Chouet
🍝
Browse files
YAXN: calculate X using dichotomy, update specs; SPP: fix calculated parameters
parent
2c96123d
Changes
5
Hide whitespace changes
Inline
Side-by-side
spec/spp.spec.ts
View file @
2f62c612
...
...
@@ -40,13 +40,13 @@ describe("Class SPP: ", () => {
it
(
"
sum([ 3*X^4, 7*1^0 ]) = 55 - X should be 2
"
,
()
=>
{
const
nub
=
new
SPP
(
new
SPPParams
(
55
));
nub
.
addChild
(
new
YAXN
(
new
YAXNParams
(
3
,
666
,
4
)));
nub
.
addChild
(
new
YAXN
(
new
YAXNParams
(
3
,
5
,
4
)));
nub
.
addChild
(
new
YAXN
(
new
YAXNParams
(
7
,
1
,
0
)));
nub
.
operation
=
SPPOperation
.
SUM
;
const
c
=
nub
.
getChildren
()[
0
]
as
YAXN
;
nub
.
calculatedParam
=
c
.
prms
.
X
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBe
(
2
);
expect
(
nub
.
result
.
vCalc
).
toBe
CloseTo
(
2
,
3
);
});
});
...
...
@@ -55,13 +55,13 @@ describe("Class SPP: ", () => {
it
(
"
product([ 3*X^4, 7*1^0 ]) = 336 - X should be 2
"
,
()
=>
{
const
nub
=
new
SPP
(
new
SPPParams
(
336
));
nub
.
addChild
(
new
YAXN
(
new
YAXNParams
(
3
,
666
,
4
)));
nub
.
addChild
(
new
YAXN
(
new
YAXNParams
(
3
,
17
,
4
)));
nub
.
addChild
(
new
YAXN
(
new
YAXNParams
(
7
,
1
,
0
)));
nub
.
operation
=
SPPOperation
.
PRODUCT
;
const
c
=
nub
.
getChildren
()[
0
]
as
YAXN
;
nub
.
calculatedParam
=
c
.
prms
.
X
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBe
(
2
);
expect
(
nub
.
result
.
vCalc
).
toBe
CloseTo
(
2
,
3
);
});
});
...
...
@@ -99,4 +99,12 @@ describe("Class SPP: ", () => {
});
it
(
"
non-integer exponent with negative coefficient
"
,
()
=>
{
const
spp
=
new
SPP
(
new
SPPParams
(
-
27
));
const
c1
=
new
YAXN
(
new
YAXNParams
(
1
,
666
,
3
));
spp
.
addChild
(
c1
);
spp
.
calculatedParam
=
c1
.
prms
.
X
;
expect
(
spp
.
CalcSerie
().
vCalc
).
toBeCloseTo
(
-
3
,
3
);
});
});
spec/yaxn.spec.ts
View file @
2f62c612
...
...
@@ -14,7 +14,7 @@ describe("Class YAXN: ", () => {
const
nub
=
new
YAXN
(
new
YAXNParams
(
4.2
,
666
,
3
,
65.625
));
nub
.
calculatedParam
=
nub
.
prms
.
X
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBe
(
2.5
);
expect
(
nub
.
result
.
vCalc
).
toBe
CloseTo
(
2.5
,
3
);
});
it
(
"
non-integer N should trigger error
"
,
()
=>
{
...
...
src/child_nub.ts
0 → 100644
View file @
2f62c612
import
{
Nub
}
from
"
./nub
"
;
import
{
ParamDefinition
}
from
"
./param/param-definition
"
;
/**
* A Nub that is meant to exist within a parent only
*/
export
abstract
class
ChildNub
extends
Nub
{
/**
* Forwards to parent, that has vsibility over
* all the parameters, including the Structure ones
*/
public
unsetCalculatedParam
(
except
:
ParamDefinition
)
{
if
(
this
.
parent
)
{
this
.
parent
.
unsetCalculatedParam
(
except
);
}
}
/**
* Forwards to parent, that has vsibility over
* all the parameters, including the Structure ones
*/
public
get
calculatedParam
():
ParamDefinition
{
if
(
this
.
parent
)
{
return
this
.
parent
.
calculatedParam
;
}
// For testing purpose without ParallelStructure
return
this
.
_calculatedParam
;
}
/**
* Forwards to parent, that has vsibility over
* all the parameters, including the Structure ones
*/
public
set
calculatedParam
(
p
:
ParamDefinition
)
{
if
(
this
.
parent
)
{
this
.
parent
.
calculatedParam
=
p
;
}
else
{
// For testing purpose without ParallelStructure
this
.
_calculatedParam
=
p
;
}
}
/**
* Forwards to parent, that has vsibility over
* all the parameters, including the Structure ones
*/
public
findFirstCalculableParameter
(
otherThan
?:
ParamDefinition
)
{
if
(
this
.
parent
)
{
return
this
.
parent
.
findFirstCalculableParameter
(
otherThan
);
}
return
undefined
;
}
/**
* Forwards to parent, that has visibility over
* all the parameters, including the Structure ones
*/
public
resetDefaultCalculatedParam
(
requirer
?:
ParamDefinition
)
{
if
(
this
.
parent
)
{
this
.
parent
.
resetDefaultCalculatedParam
(
requirer
);
}
}
}
src/structure/structure.ts
View file @
2f62c612
import
{
ChildNub
}
from
"
../child_nub
"
;
import
{
CalculatorType
}
from
"
../compute-node
"
;
import
{
Nub
}
from
"
../nub
"
;
import
{
ParamCalculability
,
ParamDefinition
}
from
"
../param/param-definition
"
;
import
{
Props
}
from
"
../props
"
;
import
{
Message
,
MessageCode
}
from
"
../util/message
"
;
...
...
@@ -48,7 +48,7 @@ export enum StructureJetType {
/**
* classe de calcul sur la conduite distributrice
*/
export
abstract
class
Structure
extends
Nub
{
export
abstract
class
Structure
extends
Child
Nub
{
/**
* Test générique si VarCalc="Q" pour l'utilisation de Equation
...
...
@@ -125,62 +125,6 @@ export abstract class Structure extends Nub {
return
undefined
;
}
/**
* Forwards to parent, that has vsibility over
* all the parameters, including the Structure ones
*/
public
unsetCalculatedParam
(
except
:
ParamDefinition
)
{
if
(
this
.
parent
)
{
this
.
parent
.
unsetCalculatedParam
(
except
);
}
}
/**
* Forwards to parent, that has vsibility over
* all the parameters, including the Structure ones
*/
public
get
calculatedParam
():
ParamDefinition
{
if
(
this
.
parent
)
{
return
this
.
parent
.
calculatedParam
;
}
// For testing purpose without ParallelStructure
return
this
.
_calculatedParam
;
}
/**
* Forwards to parent, that has vsibility over
* all the parameters, including the Structure ones
*/
public
set
calculatedParam
(
p
:
ParamDefinition
)
{
if
(
this
.
parent
)
{
this
.
parent
.
calculatedParam
=
p
;
}
else
{
// For testing purpose without ParallelStructure
this
.
_calculatedParam
=
p
;
}
}
/**
* Forwards to parent, that has vsibility over
* all the parameters, including the Structure ones
*/
public
findFirstCalculableParameter
(
otherThan
?:
ParamDefinition
)
{
if
(
this
.
parent
)
{
return
this
.
parent
.
findFirstCalculableParameter
(
otherThan
);
}
return
undefined
;
}
/**
* Forwards to parent, that has visibility over
* all the parameters, including the Structure ones
*/
public
resetDefaultCalculatedParam
(
requirer
?:
ParamDefinition
)
{
if
(
this
.
parent
)
{
this
.
parent
.
resetDefaultCalculatedParam
(
requirer
);
}
}
/**
* Calcul de l'aire d'écoulement sur le seuil ou dans l'orifice
*/
...
...
src/yaxn.ts
View file @
2f62c612
import
{
ChildNub
}
from
"
./child_nub
"
;
import
{
CalculatorType
}
from
"
./compute-node
"
;
import
{
Nub
}
from
"
./nub
"
;
import
{
ParamCalculability
}
from
"
./param/param-definition
"
;
import
{
Message
,
MessageCode
}
from
"
./util/message
"
;
import
{
Result
}
from
"
./util/result
"
;
...
...
@@ -8,7 +8,7 @@ import { YAXNParams } from "./yaxn_params";
/**
* Y = A.X^N
*/
export
class
YAXN
extends
Nub
{
export
class
YAXN
extends
Child
Nub
{
constructor
(
prms
:
YAXNParams
,
dbg
:
boolean
=
false
)
{
super
(
prms
,
dbg
);
...
...
@@ -30,7 +30,7 @@ export class YAXN extends Nub {
v
=
this
.
prms
.
A
.
v
*
Math
.
pow
(
this
.
prms
.
X
.
v
,
this
.
prms
.
N
.
v
);
break
;
case
"
X
"
:
/*
case "X":
// X = (Y/A)^(1/N)
if (this.prms.A.v === 0) {
const m = new Message(MessageCode.ERROR_DIVISION_BY_ZERO);
...
...
@@ -44,7 +44,7 @@ export class YAXN extends Nub {
}
v = Math.pow((this.prms.Y.v / this.prms.A.v), (1 / this.prms.N.v));
break;
*/
default
:
throw
new
Error
(
"
YAXN.Equation() : invalid variable name
"
+
sVarCalc
);
}
...
...
@@ -55,7 +55,7 @@ export class YAXN extends Nub {
/** paramétrage de la calculabilité des paramètres */
protected
setParametersCalculability
()
{
this
.
prms
.
Y
.
calculability
=
ParamCalculability
.
EQUATION
;
this
.
prms
.
X
.
calculability
=
ParamCalculability
.
EQUATION
;
this
.
prms
.
X
.
calculability
=
ParamCalculability
.
DICHO
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment