1 ## Model fitting solution
\r
3 The original loss coefficints are (although the optimizer will not find exact values)
\r
5 amodi "PI1" "PI12_LOSS_COEFF" 1.2
\r
6 amodi "PI2" "PI12_LOSS_COEFF" 4.6
\r
7 amodi "PI3" "PI12_LOSS_COEFF" 2.2
\r
9 Here is one possible solution:
\r
12 import "Apros/Sequences"
\r
13 import "Apros/InitialCondition"
\r
14 import "Simantics/DB"
\r
15 import "Simantics/Model"
\r
17 objFun (p :: [Double]) = do
\r
19 loadInitialCondition (syncRead $ \_ -> fromResource $ relativeResource currentModel "/Initial%20Condition")
\r
21 sqSum = ref (0 :: Double)
\r
24 setVar "PO1#PO11_PRESSURE" 1.1
\r
25 setVar "PI1#PI12_LOSS_COEFF" (p!0)
\r
26 setVar "PI2#PI12_LOSS_COEFF" (p!1)
\r
27 setVar "PI3#PI12_LOSS_COEFF" (p!2)
\r
28 fork (wait 1 >> stop)
\r
29 fork $ repeatForever mdo
\r
34 row = measurements!i
\r
35 a = getVar "PI1#PI12_MIX_MASS_FLOW" - row!1 :: Double
\r
36 b = getVar "PI2#PI12_MIX_MASS_FLOW" - row!2 :: Double
\r
37 c = getVar "PI3#PI12_MIX_MASS_FLOW" - row!3 :: Double
\r
38 sqSum := getRef sqSum + a*a + b*b + c*c
\r
42 with this definition call
\r
44 newuoa 1.0 1e-4 100 objFun [1,1,1]
\r