-
Notifications
You must be signed in to change notification settings - Fork 298
/
Obfuscation2.mos
8095 lines (8093 loc) · 786 KB
/
Obfuscation2.mos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// name: Obfuscation2
// keywords:
// status: correct
// cflags: -d=newInst
//
setCommandLineOptions("--obfuscate=protected");
loadModel(Modelica, {"3.2.3"}); getErrorString();
instantiateModel(Modelica.Fluid.Examples.BranchingDynamicPipes); getErrorString();
// Result:
// true
// true
// ""
// "function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX \"Return temperature as a function of pressure p, specific enthalpy h and composition X\"
// input Real p(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, max = 100000000.0, start = 100000.0, nominal = 100000.0) \"Pressure\";
// input Real h(quantity = \"SpecificEnergy\", unit = \"J/kg\", min = -10000000000.0, max = 10000000000.0, nominal = 1000000.0) \"Specific enthalpy\";
// input Real[:] X(quantity = fill(\"MassFraction\", size(X, 1)), unit = fill(\"kg/kg\", size(X, 1)), min = fill(0.0, size(X, 1)), max = fill(1.0, size(X, 1)), nominal = fill(0.1, size(X, 1))) \"Mass fractions of composition\";
// output Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 190.0, max = 647.0, start = 288.15, nominal = 300.0) \"Temperature\";
// algorithm
// T := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX.Internal.solve(h, 190.0, 647.0, p, X[1:1], Modelica.Media.IdealGases.Common.DataRecord(\"H2O\", 0.01801528, -13423382.81725291, 549760.6476280135, 1000.0, {-39479.6083, 575.5731019999999, 0.931782653, 0.00722271286, -7.34255737e-06, 4.95504349e-09, -1.336933246e-12}, {-33039.7431, 17.24205775}, {1034972.096, -2412.698562, 4.64611078, 0.002291998307, -6.836830479999999e-07, 9.426468930000001e-11, -4.82238053e-15}, {-13842.86509, -7.97814851}, 461.5233290850878), 1e-13);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX.Internal.f_nonlinear
// input Real x \"Independent variable of function\";
// input Real p = 0.0 \"Disregarded variables (here always used for pressure)\";
// input Real[:] X = {} \"Disregarded variables (her always used for composition)\";
// input Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX.Internal.f_nonlinear_Data f_nonlinear_data \"Additional data for the function\";
// output Real y \"= f_nonlinear(x)\";
// algorithm
// y := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.h_pTX(p, x, X);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX.Internal.f_nonlinear;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX.Internal.f_nonlinear_Data \"Automatically generated record constructor for Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX.Internal.f_nonlinear_Data\"
// input String name;
// input Real MM;
// input Real Hf;
// input Real H0;
// input Real Tlimit;
// input Real[7] alow;
// input Real[2] blow;
// input Real[7] ahigh;
// input Real[2] bhigh;
// input Real R;
// output f_nonlinear_Data res;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX.Internal.f_nonlinear_Data;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX.Internal.solve
// input Real y_zero \"Determine x_zero, such that f_nonlinear(x_zero) = y_zero\";
// input Real x_min \"Minimum value of x\";
// input Real x_max \"Maximum value of x\";
// input Real pressure = 0.0 \"Disregarded variables (here always used for pressure)\";
// input Real[:] X = {} \"Disregarded variables (here always used for composition)\";
// input Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX.Internal.f_nonlinear_Data f_nonlinear_data \"Additional data for function f_nonlinear\";
// input Real x_tol = 1e-13 \"Relative tolerance of the result\";
// output Real x_zero \"f_nonlinear(x_zero) = y_zero\";
// protected constant Real eps = 1e-15 \"Machine epsilon\";
// protected constant Real x_eps = 1e-10 \"Slight modification of x_min, x_max, since x_min, x_max are usually exactly at the borders T_min/h_min and then small numeric noise may make the interval invalid\";
// protected Real c \"Intermediate point a <= c <= b\";
// protected Real d;
// protected Real e \"b - a\";
// protected Real m;
// protected Real s;
// protected Real p;
// protected Real q;
// protected Real r;
// protected Real tol;
// protected Real fa \"= f_nonlinear(a) - y_zero\";
// protected Real fb \"= f_nonlinear(b) - y_zero\";
// protected Real fc;
// protected Boolean found = false;
// protected Real x_min2 = x_min - x_eps;
// protected Real x_max2 = x_max + x_eps;
// protected Real a = x_min2 \"Current best minimum interval value\";
// protected Real b = x_max2 \"Current best maximum interval value\";
// algorithm
// fa := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX.Internal.f_nonlinear(x_min2, pressure, X, f_nonlinear_data) - y_zero;
// fb := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX.Internal.f_nonlinear(x_max2, pressure, X, f_nonlinear_data) - y_zero;
// fc := fb;
// if fa > 0.0 and fb > 0.0 or fa < 0.0 and fb < 0.0 then
// Modelica.Utilities.Streams.error(\"The arguments x_min and x_max to OneNonLinearEquation.solve(..)
// do not bracket the root of the single non-linear equation:
// x_min = \" + String(x_min2, 6, 0, true) + \"
// \" + \" x_max = \" + String(x_max2, 6, 0, true) + \"
// \" + \" y_zero = \" + String(y_zero, 6, 0, true) + \"
// \" + \" fa = f(x_min) - y_zero = \" + String(fa, 6, 0, true) + \"
// \" + \" fb = f(x_max) - y_zero = \" + String(fb, 6, 0, true) + \"
// \" + \"fa and fb must have opposite sign which is not the case\");
// end if;
// c := a;
// fc := fa;
// e := b - a;
// d := e;
// while not found loop
// if abs(fc) < abs(fb) then
// a := b;
// b := c;
// c := a;
// fa := fb;
// fb := fc;
// fc := fa;
// end if;
// tol := 2.0 * eps * abs(b) + x_tol;
// m := (c - b) / 2.0;
// if abs(m) <= tol or fb == 0.0 then
// found := true;
// x_zero := b;
// else
// if abs(e) < tol or abs(fa) <= abs(fb) then
// e := m;
// d := e;
// else
// s := fb / fa;
// if a == c then
// p := 2.0 * m * s;
// q := 1.0 - s;
// else
// q := fa / fc;
// r := fb / fc;
// p := s * (2.0 * m * q * (q - r) - (b - a) * (r - 1.0));
// q := (q - 1.0) * (r - 1.0) * (s - 1.0);
// end if;
// if p > 0.0 then
// q := -q;
// else
// p := -p;
// end if;
// s := e;
// e := d;
// if 2.0 * p < 3.0 * m * q - abs(tol * q) and p < abs(0.5 * s * q) then
// d := p / q;
// else
// e := m;
// d := e;
// end if;
// end if;
// a := b;
// fa := fb;
// b := b + (if abs(d) > tol then d else if m > 0.0 then tol else -tol);
// fb := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX.Internal.f_nonlinear(b, pressure, X, f_nonlinear_data) - y_zero;
// if fb > 0.0 and fc > 0.0 or fb < 0.0 and fc < 0.0 then
// c := a;
// fc := fa;
// e := b - a;
// d := e;
// end if;
// end if;
// end while;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX.Internal.solve;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.ThermodynamicState \"Automatically generated record constructor for Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.ThermodynamicState\"
// input Real p;
// input Real T;
// input Real[2] X;
// output ThermodynamicState res;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.ThermodynamicState;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.Utilities.smoothMax
// input Real x1 \"First argument of smooth max operator\";
// input Real x2 \"Second argument of smooth max operator\";
// input Real dx \"Approximate difference between x1 and x2, below which regularization starts\";
// output Real y \"Result of smooth max operator\";
// algorithm
// y := max(x1, x2) + log(exp(4.0 / dx * (x1 - max(x1, x2))) + exp(4.0 / dx * (x2 - max(x1, x2)))) / (4.0 / dx);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.Utilities.smoothMax;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.Utilities.smoothMax_der
// input Real x1 \"First argument of smooth max operator\";
// input Real x2 \"Second argument of smooth max operator\";
// input Real dx \"Approximate difference between x1 and x2, below which regularization starts\";
// input Real dx1;
// input Real dx2;
// input Real ddx;
// output Real dy \"Derivative of smooth max operator\";
// algorithm
// dy := (if x1 > x2 then dx1 else dx2) + 0.25 * (((4.0 * (dx1 - (if x1 > x2 then dx1 else dx2)) / dx - 4.0 * (x1 - max(x1, x2)) * ddx / dx ^ 2.0) * exp(4.0 * (x1 - max(x1, x2)) / dx) + (4.0 * (dx2 - (if x1 > x2 then dx1 else dx2)) / dx - 4.0 * (x2 - max(x1, x2)) * ddx / dx ^ 2.0) * exp(4.0 * (x2 - max(x1, x2)) / dx)) * dx / (exp(4.0 * (x1 - max(x1, x2)) / dx) + exp(4.0 * (x2 - max(x1, x2)) / dx)) + log(exp(4.0 * (x1 - max(x1, x2)) / dx) + exp(4.0 * (x2 - max(x1, x2)) / dx)) * ddx);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.Utilities.smoothMax_der;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.Utilities.spliceFunction \"Spline interpolation of two functions\"
// input Real pos \"Returned value for x-deltax >= 0\";
// input Real neg \"Returned value for x+deltax <= 0\";
// input Real x \"Function argument\";
// input Real deltax = 1.0 \"Region around x with spline interpolation\";
// output Real out;
// protected Real scaledX;
// protected Real scaledX1;
// protected Real y;
// algorithm
// scaledX1 := x / deltax;
// scaledX := scaledX1 * 1.570796326794897;
// if scaledX1 <= -0.999999999 then
// y := 0.0;
// elseif scaledX1 >= 0.999999999 then
// y := 1.0;
// else
// y := (tanh(tan(scaledX)) + 1.0) / 2.0;
// end if;
// out := pos * y + (1.0 - y) * neg;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.Utilities.spliceFunction;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.Utilities.spliceFunction_der \"Derivative of spliceFunction\"
// input Real pos;
// input Real neg;
// input Real x;
// input Real deltax = 1.0;
// input Real dpos;
// input Real dneg;
// input Real dx;
// input Real ddeltax = 0.0;
// output Real out;
// protected Real scaledX;
// protected Real scaledX1;
// protected Real dscaledX1;
// protected Real y;
// algorithm
// scaledX1 := x / deltax;
// scaledX := scaledX1 * 1.570796326794897;
// dscaledX1 := (dx - scaledX1 * ddeltax) / deltax;
// if scaledX1 <= -0.99999999999 then
// y := 0.0;
// elseif scaledX1 >= 0.9999999999 then
// y := 1.0;
// else
// y := (tanh(tan(scaledX)) + 1.0) / 2.0;
// end if;
// out := dpos * y + (1.0 - y) * dneg;
// if abs(scaledX1) < 1.0 then
// out := out + (pos - neg) * dscaledX1 * 1.570796326794897 / 2.0 / (cosh(tan(scaledX)) * cos(scaledX)) ^ 2.0;
// end if;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.Utilities.spliceFunction_der;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.enthalpyOfWater \"Computes specific enthalpy of water (solid/liquid) near atmospheric pressure from temperature T\"
// input Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) \"Temperature\";
// output Real h(quantity = \"SpecificEnergy\", unit = \"J/kg\") \"Specific enthalpy of water\";
// algorithm
// h := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.Utilities.spliceFunction(4200.0 * (T - 273.15), 2050.0 * (T - 273.15) - 333000.0, T - 273.16, 0.1);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.enthalpyOfWater;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.enthalpyOfWater_der \"Derivative function of enthalpyOfWater\"
// input Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) \"Temperature\";
// input Real dT(unit = \"K/s\") \"Time derivative of temperature\";
// output Real dh(unit = \"J/(kg.s)\") \"Time derivative of specific enthalpy\";
// algorithm
// dh := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.Utilities.spliceFunction_der(4200.0 * (T - 273.15), 2050.0 * (T - 273.15) - 333000.0, T - 273.16, 0.1, 4200.0 * dT, 2050.0 * dT, dT, 0.0);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.enthalpyOfWater_der;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.h_pTX \"Return specific enthalpy of moist air as a function of pressure p, temperature T and composition X\"
// input Real p(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\") \"Pressure\";
// input Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) \"Temperature\";
// input Real[:] X(quantity = fill(\"MassFraction\", size(X, 1)), unit = fill(\"1\", size(X, 1)), min = fill(0.0, size(X, 1)), max = fill(1.0, size(X, 1))) \"Mass fractions of moist air\";
// output Real h(quantity = \"SpecificEnergy\", unit = \"J/kg\") \"Specific enthalpy at p, T, X\";
// protected Real p_steam_sat(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, nominal = 100000.0) \"partial saturation pressure of steam\";
// protected Real X_sat(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Absolute humidity per unit mass of moist air\";
// protected Real X_liquid(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Mass fraction of liquid water\";
// protected Real X_steam(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Mass fraction of steam water\";
// protected Real X_air(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Mass fraction of air\";
// algorithm
// p_steam_sat := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.saturationPressure(T);
// X_sat := min(p_steam_sat * 0.6219647130774989 / max(1e-13, p - p_steam_sat) * (1.0 - X[1]), 1.0);
// X_liquid := max(X[1] - X_sat, 0.0);
// X_steam := X[1] - X_liquid;
// X_air := 1.0 - X[1];
// h := Modelica.Media.IdealGases.Common.Functions.h_Tlow(Modelica.Media.IdealGases.Common.DataRecord(\"H2O\", 0.01801528, -13423382.81725291, 549760.6476280135, 1000.0, {-39479.6083, 575.5731019999999, 0.931782653, 0.00722271286, -7.34255737e-06, 4.95504349e-09, -1.336933246e-12}, {-33039.7431, 17.24205775}, {1034972.096, -2412.698562, 4.64611078, 0.002291998307, -6.836830479999999e-07, 9.426468930000001e-11, -4.82238053e-15}, {-13842.86509, -7.97814851}, 461.5233290850878), T, true, Modelica.Media.Interfaces.Choices.ReferenceEnthalpy.UserDefined, 2547494.319) * X_steam + Modelica.Media.IdealGases.Common.Functions.h_Tlow(Modelica.Media.IdealGases.Common.DataRecord(\"Air\", 0.0289651159, -4333.833858403446, 298609.6803431054, 1000.0, {10099.5016, -196.827561, 5.00915511, -0.00576101373, 1.06685993e-05, -7.94029797e-09, 2.18523191e-12}, {-176.796731, -3.921504225}, {241521.443, -1257.8746, 5.14455867, -0.000213854179, 7.06522784e-08, -1.07148349e-11, 6.57780015e-16}, {6462.26319, -8.147411905}, 287.0512249529787), T, true, Modelica.Media.Interfaces.Choices.ReferenceEnthalpy.UserDefined, 25104.684) * X_air + Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.enthalpyOfWater(T) * X_liquid;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.h_pTX;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.h_pTX_der \"Derivative function of h_pTX\"
// input Real p(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\") \"Pressure\";
// input Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) \"Temperature\";
// input Real[:] X(quantity = fill(\"MassFraction\", size(X, 1)), unit = fill(\"1\", size(X, 1)), min = fill(0.0, size(X, 1)), max = fill(1.0, size(X, 1))) \"Mass fractions of moist air\";
// input Real dp(unit = \"Pa/s\") \"Pressure derivative\";
// input Real dT(unit = \"K/s\") \"Temperature derivative\";
// input Real[:] dX(unit = \"1/s\") \"Composition derivative\";
// output Real h_der(unit = \"J/(kg.s)\") \"Time derivative of specific enthalpy\";
// protected Real p_steam_sat(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, nominal = 100000.0) \"partial saturation pressure of steam\";
// protected Real X_sat(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Absolute humidity per unit mass of moist air\";
// protected Real X_liquid(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Mass fraction of liquid water\";
// protected Real X_steam(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Mass fraction of steam water\";
// protected Real X_air(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Mass fraction of air\";
// protected Real x_sat(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Absolute humidity per unit mass of dry air at saturation\";
// protected Real dX_steam(unit = \"1/s\") \"Time derivative of steam mass fraction\";
// protected Real dX_air(unit = \"1/s\") \"Time derivative of dry air mass fraction\";
// protected Real dX_liq(unit = \"1/s\") \"Time derivative of liquid/solid water mass fraction\";
// protected Real dps(unit = \"Pa/s\") \"Time derivative of saturation pressure\";
// protected Real dx_sat(unit = \"1/s\") \"Time derivative of absolute humidity per unit mass of dry air\";
// algorithm
// p_steam_sat := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.saturationPressure(T);
// x_sat := p_steam_sat * 0.6219647130774989 / max(1e-13, p - p_steam_sat);
// X_sat := min(x_sat * (1.0 - X[1]), 1.0);
// X_liquid := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.Utilities.smoothMax(X[1] - X_sat, 0.0, 1e-05);
// X_steam := X[1] - X_liquid;
// X_air := 1.0 - X[1];
// dX_air := -dX[1];
// dps := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.saturationPressure_der(T, dT);
// dx_sat := 0.6219647130774989 * (dps * (p - p_steam_sat) - p_steam_sat * (dp - dps)) / (p - p_steam_sat) / (p - p_steam_sat);
// dX_liq := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.Utilities.smoothMax_der(X[1] - X_sat, 0.0, 1e-05, (1.0 + x_sat) * dX[1] - (1.0 - X[1]) * dx_sat, 0.0, 0.0);
// dX_steam := dX[1] - dX_liq;
// h_der := X_steam * Modelica.Media.IdealGases.Common.Functions.h_Tlow_der(Modelica.Media.IdealGases.Common.DataRecord(\"H2O\", 0.01801528, -13423382.81725291, 549760.6476280135, 1000.0, {-39479.6083, 575.5731019999999, 0.931782653, 0.00722271286, -7.34255737e-06, 4.95504349e-09, -1.336933246e-12}, {-33039.7431, 17.24205775}, {1034972.096, -2412.698562, 4.64611078, 0.002291998307, -6.836830479999999e-07, 9.426468930000001e-11, -4.82238053e-15}, {-13842.86509, -7.97814851}, 461.5233290850878), T, true, Modelica.Media.Interfaces.Choices.ReferenceEnthalpy.UserDefined, 2547494.319, dT) + dX_steam * Modelica.Media.IdealGases.Common.Functions.h_Tlow(Modelica.Media.IdealGases.Common.DataRecord(\"H2O\", 0.01801528, -13423382.81725291, 549760.6476280135, 1000.0, {-39479.6083, 575.5731019999999, 0.931782653, 0.00722271286, -7.34255737e-06, 4.95504349e-09, -1.336933246e-12}, {-33039.7431, 17.24205775}, {1034972.096, -2412.698562, 4.64611078, 0.002291998307, -6.836830479999999e-07, 9.426468930000001e-11, -4.82238053e-15}, {-13842.86509, -7.97814851}, 461.5233290850878), T, true, Modelica.Media.Interfaces.Choices.ReferenceEnthalpy.UserDefined, 2547494.319) + X_air * Modelica.Media.IdealGases.Common.Functions.h_Tlow_der(Modelica.Media.IdealGases.Common.DataRecord(\"Air\", 0.0289651159, -4333.833858403446, 298609.6803431054, 1000.0, {10099.5016, -196.827561, 5.00915511, -0.00576101373, 1.06685993e-05, -7.94029797e-09, 2.18523191e-12}, {-176.796731, -3.921504225}, {241521.443, -1257.8746, 5.14455867, -0.000213854179, 7.06522784e-08, -1.07148349e-11, 6.57780015e-16}, {6462.26319, -8.147411905}, 287.0512249529787), T, true, Modelica.Media.Interfaces.Choices.ReferenceEnthalpy.UserDefined, 25104.684, dT) + dX_air * Modelica.Media.IdealGases.Common.Functions.h_Tlow(Modelica.Media.IdealGases.Common.DataRecord(\"Air\", 0.0289651159, -4333.833858403446, 298609.6803431054, 1000.0, {10099.5016, -196.827561, 5.00915511, -0.00576101373, 1.06685993e-05, -7.94029797e-09, 2.18523191e-12}, {-176.796731, -3.921504225}, {241521.443, -1257.8746, 5.14455867, -0.000213854179, 7.06522784e-08, -1.07148349e-11, 6.57780015e-16}, {6462.26319, -8.147411905}, 287.0512249529787), T, true, Modelica.Media.Interfaces.Choices.ReferenceEnthalpy.UserDefined, 25104.684) + X_liquid * Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.enthalpyOfWater_der(T, dT) + dX_liq * Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.enthalpyOfWater(T);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.h_pTX_der;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.saturationPressure \"Return saturation pressure of water as a function of temperature T between 190 and 647.096 K\"
// input Real Tsat(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 190.0, max = 647.0, start = 288.15, nominal = 300.0) \"Saturation temperature\";
// output Real psat(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, max = 100000000.0, start = 100000.0, nominal = 100000.0) \"Saturation pressure\";
// algorithm
// psat := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.Utilities.spliceFunction(Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.saturationPressureLiquid(Tsat), Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.sublimationPressureIce(Tsat), Tsat - 273.16, 1.0);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.saturationPressure;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.saturationPressureLiquid \"Return saturation pressure of water as a function of temperature T in the range of 273.16 to 647.096 K\"
// input Real Tsat(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) \"Saturation temperature\";
// output Real psat(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, nominal = 100000.0) \"Saturation pressure\";
// protected Real Tcritical(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) = 647.096 \"Critical temperature\";
// protected Real pcritical(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, nominal = 100000.0) = 22064000.0 \"Critical pressure\";
// protected Real[:] a = {-7.85951783, 1.84408259, -11.7866497, 22.6807411, -15.9618719, 1.80122502} \"Coefficients a[:]\";
// protected Real[:] n = {1.0, 1.5, 3.0, 3.5, 4.0, 7.5} \"Coefficients n[:]\";
// protected Real r1 = 1.0 - Tsat / Tcritical \"Common subexpression\";
// algorithm
// psat := exp((a[1] * r1 ^ n[1] + a[2] * r1 ^ n[2] + a[3] * r1 ^ n[3] + a[4] * r1 ^ n[4] + a[5] * r1 ^ n[5] + a[6] * r1 ^ n[6]) * Tcritical / Tsat) * pcritical;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.saturationPressureLiquid;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.saturationPressureLiquid_der \"Derivative function for 'saturationPressureLiquid'\"
// input Real Tsat(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) \"Saturation temperature\";
// input Real dTsat(unit = \"K/s\") \"Saturation temperature derivative\";
// output Real psat_der(unit = \"Pa/s\") \"Saturation pressure derivative\";
// protected Real Tcritical(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) = 647.096 \"Critical temperature\";
// protected Real pcritical(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, nominal = 100000.0) = 22064000.0 \"Critical pressure\";
// protected Real[:] a = {-7.85951783, 1.84408259, -11.7866497, 22.6807411, -15.9618719, 1.80122502} \"Coefficients a[:]\";
// protected Real[:] n = {1.0, 1.5, 3.0, 3.5, 4.0, 7.5} \"Coefficients n[:]\";
// protected Real r1 = 1.0 - Tsat / Tcritical \"Common subexpression 1\";
// protected Real r1_der = -1.0 / Tcritical * dTsat \"Derivative of common subexpression 1\";
// protected Real r2 = a[1] * r1 ^ n[1] + a[2] * r1 ^ n[2] + a[3] * r1 ^ n[3] + a[4] * r1 ^ n[4] + a[5] * r1 ^ n[5] + a[6] * r1 ^ n[6] \"Common subexpression 2\";
// algorithm
// psat_der := exp(r2 * Tcritical / Tsat) * pcritical * ((a[1] * r1 ^ (n[1] - 1.0) * n[1] * r1_der + a[2] * r1 ^ (n[2] - 1.0) * n[2] * r1_der + a[3] * r1 ^ (n[3] - 1.0) * n[3] * r1_der + a[4] * r1 ^ (n[4] - 1.0) * n[4] * r1_der + a[5] * r1 ^ (n[5] - 1.0) * n[5] * r1_der + a[6] * r1 ^ (n[6] - 1.0) * n[6] * r1_der) * Tcritical / Tsat - r2 * Tcritical * dTsat / Tsat ^ 2.0);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.saturationPressureLiquid_der;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.saturationPressure_der \"Derivative function for 'saturationPressure'\"
// input Real Tsat(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 190.0, max = 647.0, start = 288.15, nominal = 300.0) \"Saturation temperature\";
// input Real dTsat(unit = \"K/s\") \"Time derivative of saturation temperature\";
// output Real psat_der(unit = \"Pa/s\") \"Saturation pressure\";
// algorithm
// psat_der := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.Utilities.spliceFunction_der(Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.saturationPressureLiquid(Tsat), Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.sublimationPressureIce(Tsat), Tsat - 273.16, 1.0, Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.saturationPressureLiquid_der(Tsat, dTsat), Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.sublimationPressureIce_der(Tsat, dTsat), dTsat, 0.0);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.saturationPressure_der;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.setState_pTX \"Return thermodynamic state as function of pressure p, temperature T and composition X\"
// input Real p(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, max = 100000000.0, start = 100000.0, nominal = 100000.0) \"Pressure\";
// input Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 190.0, max = 647.0, start = 288.15, nominal = 300.0) \"Temperature\";
// input Real[:] X(quantity = fill(\"MassFraction\", size(X, 1)), unit = fill(\"kg/kg\", size(X, 1)), min = fill(0.0, size(X, 1)), max = fill(1.0, size(X, 1)), nominal = fill(0.1, size(X, 1))) = {0.01, 0.99} \"Mass fractions\";
// output Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.ThermodynamicState state \"Thermodynamic state\";
// algorithm
// state := if size(X, 1) == 2 then Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.ThermodynamicState(p, T, X) else Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.ThermodynamicState(p, T, cat(1, X, {1.0 - sum(X)}));
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.setState_pTX;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.setState_phX \"Return thermodynamic state as function of pressure p, specific enthalpy h and composition X\"
// input Real p(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, max = 100000000.0, start = 100000.0, nominal = 100000.0) \"Pressure\";
// input Real h(quantity = \"SpecificEnergy\", unit = \"J/kg\", min = -10000000000.0, max = 10000000000.0, nominal = 1000000.0) \"Specific enthalpy\";
// input Real[:] X(quantity = fill(\"MassFraction\", size(X, 1)), unit = fill(\"kg/kg\", size(X, 1)), min = fill(0.0, size(X, 1)), max = fill(1.0, size(X, 1)), nominal = fill(0.1, size(X, 1))) = {0.01, 0.99} \"Mass fractions\";
// output Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.ThermodynamicState state \"Thermodynamic state\";
// algorithm
// state := if size(X, 1) == 2 then Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.ThermodynamicState(p, Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX(p, h, X), X) else Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.ThermodynamicState(p, Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.T_phX(p, h, X), cat(1, X, {1.0 - sum(X)}));
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.setState_phX;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.specificEnthalpy \"Return specific enthalpy of moist air as a function of the thermodynamic state record\"
// input Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.ThermodynamicState state \"Thermodynamic state record\";
// output Real h(quantity = \"SpecificEnergy\", unit = \"J/kg\", min = -10000000000.0, max = 10000000000.0, nominal = 1000000.0) \"Specific enthalpy\";
// algorithm
// h := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.h_pTX(state.p, state.T, state.X);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.specificEnthalpy;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.specificEnthalpy_pTX \"Return specific enthalpy from p, T, and X or Xi\"
// input Real p(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, max = 100000000.0, start = 100000.0, nominal = 100000.0) \"Pressure\";
// input Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 190.0, max = 647.0, start = 288.15, nominal = 300.0) \"Temperature\";
// input Real[:] X(quantity = fill(\"MassFraction\", size(X, 1)), unit = fill(\"kg/kg\", size(X, 1)), min = fill(0.0, size(X, 1)), max = fill(1.0, size(X, 1)), nominal = fill(0.1, size(X, 1))) = {0.01, 0.99} \"Mass fractions\";
// output Real h(quantity = \"SpecificEnergy\", unit = \"J/kg\", min = -10000000000.0, max = 10000000000.0, nominal = 1000000.0) \"Specific enthalpy\";
// algorithm
// h := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.specificEnthalpy(Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.setState_pTX(p, T, X));
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.specificEnthalpy_pTX;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.sublimationPressureIce \"Return sublimation pressure of water as a function of temperature T between 190 and 273.16 K\"
// input Real Tsat(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) \"Sublimation temperature\";
// output Real psat(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, nominal = 100000.0) \"Sublimation pressure\";
// protected Real Ttriple(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) = 273.16 \"Triple point temperature\";
// protected Real ptriple(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, nominal = 100000.0) = 611.657 \"Triple point pressure\";
// protected Real[:] a = {-13.928169, 34.7078238} \"Coefficients a[:]\";
// protected Real[:] n = {-1.5, -1.25} \"Coefficients n[:]\";
// protected Real r1 = Tsat / Ttriple \"Common subexpression\";
// algorithm
// psat := exp(a[1] - a[1] * r1 ^ n[1] + a[2] - a[2] * r1 ^ n[2]) * ptriple;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.sublimationPressureIce;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.sublimationPressureIce_der \"Derivative function for 'sublimationPressureIce'\"
// input Real Tsat(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) \"Sublimation temperature\";
// input Real dTsat(unit = \"K/s\") \"Sublimation temperature derivative\";
// output Real psat_der(unit = \"Pa/s\") \"Sublimation pressure derivative\";
// protected Real Ttriple(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) = 273.16 \"Triple point temperature\";
// protected Real ptriple(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, nominal = 100000.0) = 611.657 \"Triple point pressure\";
// protected Real[:] a = {-13.928169, 34.7078238} \"Coefficients a[:]\";
// protected Real[:] n = {-1.5, -1.25} \"Coefficients n[:]\";
// protected Real r1 = Tsat / Ttriple \"Common subexpression 1\";
// protected Real r1_der = dTsat / Ttriple \"Derivative of common subexpression 1\";
// algorithm
// psat_der := exp(a[1] - a[1] * r1 ^ n[1] + a[2] - a[2] * r1 ^ n[2]) * ptriple * ((-a[1] * r1 ^ (n[1] - 1.0) * n[1] * r1_der) - a[2] * r1 ^ (n[2] - 1.0) * n[2] * r1_der);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.sublimationPressureIce_der;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.temperature \"Return temperature of ideal gas as a function of the thermodynamic state record\"
// input Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.ThermodynamicState state \"Thermodynamic state record\";
// output Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 190.0, max = 647.0, start = 288.15, nominal = 300.0) \"Temperature\";
// algorithm
// T := state.T;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.temperature;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.temperature_phX \"Return temperature from p, h, and X or Xi\"
// input Real p(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, max = 100000000.0, start = 100000.0, nominal = 100000.0) \"Pressure\";
// input Real h(quantity = \"SpecificEnergy\", unit = \"J/kg\", min = -10000000000.0, max = 10000000000.0, nominal = 1000000.0) \"Specific enthalpy\";
// input Real[:] X(quantity = fill(\"MassFraction\", size(X, 1)), unit = fill(\"kg/kg\", size(X, 1)), min = fill(0.0, size(X, 1)), max = fill(1.0, size(X, 1)), nominal = fill(0.1, size(X, 1))) = {0.01, 0.99} \"Mass fractions\";
// output Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 190.0, max = 647.0, start = 288.15, nominal = 300.0) \"Temperature\";
// algorithm
// T := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.temperature(Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.setState_phX(p, h, X));
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary1.Medium.temperature_phX;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX \"Return temperature as a function of pressure p, specific enthalpy h and composition X\"
// input Real p(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, max = 100000000.0, start = 100000.0, nominal = 100000.0) \"Pressure\";
// input Real h(quantity = \"SpecificEnergy\", unit = \"J/kg\", min = -10000000000.0, max = 10000000000.0, nominal = 1000000.0) \"Specific enthalpy\";
// input Real[:] X(quantity = fill(\"MassFraction\", size(X, 1)), unit = fill(\"kg/kg\", size(X, 1)), min = fill(0.0, size(X, 1)), max = fill(1.0, size(X, 1)), nominal = fill(0.1, size(X, 1))) \"Mass fractions of composition\";
// output Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 190.0, max = 647.0, start = 288.15, nominal = 300.0) \"Temperature\";
// algorithm
// T := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX.Internal.solve(h, 190.0, 647.0, p, X[1:1], Modelica.Media.IdealGases.Common.DataRecord(\"H2O\", 0.01801528, -13423382.81725291, 549760.6476280135, 1000.0, {-39479.6083, 575.5731019999999, 0.931782653, 0.00722271286, -7.34255737e-06, 4.95504349e-09, -1.336933246e-12}, {-33039.7431, 17.24205775}, {1034972.096, -2412.698562, 4.64611078, 0.002291998307, -6.836830479999999e-07, 9.426468930000001e-11, -4.82238053e-15}, {-13842.86509, -7.97814851}, 461.5233290850878), 1e-13);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX.Internal.f_nonlinear
// input Real x \"Independent variable of function\";
// input Real p = 0.0 \"Disregarded variables (here always used for pressure)\";
// input Real[:] X = {} \"Disregarded variables (her always used for composition)\";
// input Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX.Internal.f_nonlinear_Data f_nonlinear_data \"Additional data for the function\";
// output Real y \"= f_nonlinear(x)\";
// algorithm
// y := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.h_pTX(p, x, X);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX.Internal.f_nonlinear;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX.Internal.f_nonlinear_Data \"Automatically generated record constructor for Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX.Internal.f_nonlinear_Data\"
// input String name;
// input Real MM;
// input Real Hf;
// input Real H0;
// input Real Tlimit;
// input Real[7] alow;
// input Real[2] blow;
// input Real[7] ahigh;
// input Real[2] bhigh;
// input Real R;
// output f_nonlinear_Data res;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX.Internal.f_nonlinear_Data;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX.Internal.solve
// input Real y_zero \"Determine x_zero, such that f_nonlinear(x_zero) = y_zero\";
// input Real x_min \"Minimum value of x\";
// input Real x_max \"Maximum value of x\";
// input Real pressure = 0.0 \"Disregarded variables (here always used for pressure)\";
// input Real[:] X = {} \"Disregarded variables (here always used for composition)\";
// input Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX.Internal.f_nonlinear_Data f_nonlinear_data \"Additional data for function f_nonlinear\";
// input Real x_tol = 1e-13 \"Relative tolerance of the result\";
// output Real x_zero \"f_nonlinear(x_zero) = y_zero\";
// protected constant Real eps = 1e-15 \"Machine epsilon\";
// protected constant Real x_eps = 1e-10 \"Slight modification of x_min, x_max, since x_min, x_max are usually exactly at the borders T_min/h_min and then small numeric noise may make the interval invalid\";
// protected Real c \"Intermediate point a <= c <= b\";
// protected Real d;
// protected Real e \"b - a\";
// protected Real m;
// protected Real s;
// protected Real p;
// protected Real q;
// protected Real r;
// protected Real tol;
// protected Real fa \"= f_nonlinear(a) - y_zero\";
// protected Real fb \"= f_nonlinear(b) - y_zero\";
// protected Real fc;
// protected Boolean found = false;
// protected Real x_min2 = x_min - x_eps;
// protected Real x_max2 = x_max + x_eps;
// protected Real a = x_min2 \"Current best minimum interval value\";
// protected Real b = x_max2 \"Current best maximum interval value\";
// algorithm
// fa := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX.Internal.f_nonlinear(x_min2, pressure, X, f_nonlinear_data) - y_zero;
// fb := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX.Internal.f_nonlinear(x_max2, pressure, X, f_nonlinear_data) - y_zero;
// fc := fb;
// if fa > 0.0 and fb > 0.0 or fa < 0.0 and fb < 0.0 then
// Modelica.Utilities.Streams.error(\"The arguments x_min and x_max to OneNonLinearEquation.solve(..)
// do not bracket the root of the single non-linear equation:
// x_min = \" + String(x_min2, 6, 0, true) + \"
// \" + \" x_max = \" + String(x_max2, 6, 0, true) + \"
// \" + \" y_zero = \" + String(y_zero, 6, 0, true) + \"
// \" + \" fa = f(x_min) - y_zero = \" + String(fa, 6, 0, true) + \"
// \" + \" fb = f(x_max) - y_zero = \" + String(fb, 6, 0, true) + \"
// \" + \"fa and fb must have opposite sign which is not the case\");
// end if;
// c := a;
// fc := fa;
// e := b - a;
// d := e;
// while not found loop
// if abs(fc) < abs(fb) then
// a := b;
// b := c;
// c := a;
// fa := fb;
// fb := fc;
// fc := fa;
// end if;
// tol := 2.0 * eps * abs(b) + x_tol;
// m := (c - b) / 2.0;
// if abs(m) <= tol or fb == 0.0 then
// found := true;
// x_zero := b;
// else
// if abs(e) < tol or abs(fa) <= abs(fb) then
// e := m;
// d := e;
// else
// s := fb / fa;
// if a == c then
// p := 2.0 * m * s;
// q := 1.0 - s;
// else
// q := fa / fc;
// r := fb / fc;
// p := s * (2.0 * m * q * (q - r) - (b - a) * (r - 1.0));
// q := (q - 1.0) * (r - 1.0) * (s - 1.0);
// end if;
// if p > 0.0 then
// q := -q;
// else
// p := -p;
// end if;
// s := e;
// e := d;
// if 2.0 * p < 3.0 * m * q - abs(tol * q) and p < abs(0.5 * s * q) then
// d := p / q;
// else
// e := m;
// d := e;
// end if;
// end if;
// a := b;
// fa := fb;
// b := b + (if abs(d) > tol then d else if m > 0.0 then tol else -tol);
// fb := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX.Internal.f_nonlinear(b, pressure, X, f_nonlinear_data) - y_zero;
// if fb > 0.0 and fc > 0.0 or fb < 0.0 and fc < 0.0 then
// c := a;
// fc := fa;
// e := b - a;
// d := e;
// end if;
// end if;
// end while;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX.Internal.solve;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.ThermodynamicState \"Automatically generated record constructor for Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.ThermodynamicState\"
// input Real p;
// input Real T;
// input Real[2] X;
// output ThermodynamicState res;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.ThermodynamicState;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.Utilities.smoothMax
// input Real x1 \"First argument of smooth max operator\";
// input Real x2 \"Second argument of smooth max operator\";
// input Real dx \"Approximate difference between x1 and x2, below which regularization starts\";
// output Real y \"Result of smooth max operator\";
// algorithm
// y := max(x1, x2) + log(exp(4.0 / dx * (x1 - max(x1, x2))) + exp(4.0 / dx * (x2 - max(x1, x2)))) / (4.0 / dx);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.Utilities.smoothMax;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.Utilities.smoothMax_der
// input Real x1 \"First argument of smooth max operator\";
// input Real x2 \"Second argument of smooth max operator\";
// input Real dx \"Approximate difference between x1 and x2, below which regularization starts\";
// input Real dx1;
// input Real dx2;
// input Real ddx;
// output Real dy \"Derivative of smooth max operator\";
// algorithm
// dy := (if x1 > x2 then dx1 else dx2) + 0.25 * (((4.0 * (dx1 - (if x1 > x2 then dx1 else dx2)) / dx - 4.0 * (x1 - max(x1, x2)) * ddx / dx ^ 2.0) * exp(4.0 * (x1 - max(x1, x2)) / dx) + (4.0 * (dx2 - (if x1 > x2 then dx1 else dx2)) / dx - 4.0 * (x2 - max(x1, x2)) * ddx / dx ^ 2.0) * exp(4.0 * (x2 - max(x1, x2)) / dx)) * dx / (exp(4.0 * (x1 - max(x1, x2)) / dx) + exp(4.0 * (x2 - max(x1, x2)) / dx)) + log(exp(4.0 * (x1 - max(x1, x2)) / dx) + exp(4.0 * (x2 - max(x1, x2)) / dx)) * ddx);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.Utilities.smoothMax_der;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.Utilities.spliceFunction \"Spline interpolation of two functions\"
// input Real pos \"Returned value for x-deltax >= 0\";
// input Real neg \"Returned value for x+deltax <= 0\";
// input Real x \"Function argument\";
// input Real deltax = 1.0 \"Region around x with spline interpolation\";
// output Real out;
// protected Real scaledX;
// protected Real scaledX1;
// protected Real y;
// algorithm
// scaledX1 := x / deltax;
// scaledX := scaledX1 * 1.570796326794897;
// if scaledX1 <= -0.999999999 then
// y := 0.0;
// elseif scaledX1 >= 0.999999999 then
// y := 1.0;
// else
// y := (tanh(tan(scaledX)) + 1.0) / 2.0;
// end if;
// out := pos * y + (1.0 - y) * neg;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.Utilities.spliceFunction;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.Utilities.spliceFunction_der \"Derivative of spliceFunction\"
// input Real pos;
// input Real neg;
// input Real x;
// input Real deltax = 1.0;
// input Real dpos;
// input Real dneg;
// input Real dx;
// input Real ddeltax = 0.0;
// output Real out;
// protected Real scaledX;
// protected Real scaledX1;
// protected Real dscaledX1;
// protected Real y;
// algorithm
// scaledX1 := x / deltax;
// scaledX := scaledX1 * 1.570796326794897;
// dscaledX1 := (dx - scaledX1 * ddeltax) / deltax;
// if scaledX1 <= -0.99999999999 then
// y := 0.0;
// elseif scaledX1 >= 0.9999999999 then
// y := 1.0;
// else
// y := (tanh(tan(scaledX)) + 1.0) / 2.0;
// end if;
// out := dpos * y + (1.0 - y) * dneg;
// if abs(scaledX1) < 1.0 then
// out := out + (pos - neg) * dscaledX1 * 1.570796326794897 / 2.0 / (cosh(tan(scaledX)) * cos(scaledX)) ^ 2.0;
// end if;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.Utilities.spliceFunction_der;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.enthalpyOfWater \"Computes specific enthalpy of water (solid/liquid) near atmospheric pressure from temperature T\"
// input Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) \"Temperature\";
// output Real h(quantity = \"SpecificEnergy\", unit = \"J/kg\") \"Specific enthalpy of water\";
// algorithm
// h := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.Utilities.spliceFunction(4200.0 * (T - 273.15), 2050.0 * (T - 273.15) - 333000.0, T - 273.16, 0.1);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.enthalpyOfWater;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.enthalpyOfWater_der \"Derivative function of enthalpyOfWater\"
// input Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) \"Temperature\";
// input Real dT(unit = \"K/s\") \"Time derivative of temperature\";
// output Real dh(unit = \"J/(kg.s)\") \"Time derivative of specific enthalpy\";
// algorithm
// dh := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.Utilities.spliceFunction_der(4200.0 * (T - 273.15), 2050.0 * (T - 273.15) - 333000.0, T - 273.16, 0.1, 4200.0 * dT, 2050.0 * dT, dT, 0.0);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.enthalpyOfWater_der;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.h_pTX \"Return specific enthalpy of moist air as a function of pressure p, temperature T and composition X\"
// input Real p(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\") \"Pressure\";
// input Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) \"Temperature\";
// input Real[:] X(quantity = fill(\"MassFraction\", size(X, 1)), unit = fill(\"1\", size(X, 1)), min = fill(0.0, size(X, 1)), max = fill(1.0, size(X, 1))) \"Mass fractions of moist air\";
// output Real h(quantity = \"SpecificEnergy\", unit = \"J/kg\") \"Specific enthalpy at p, T, X\";
// protected Real p_steam_sat(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, nominal = 100000.0) \"partial saturation pressure of steam\";
// protected Real X_sat(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Absolute humidity per unit mass of moist air\";
// protected Real X_liquid(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Mass fraction of liquid water\";
// protected Real X_steam(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Mass fraction of steam water\";
// protected Real X_air(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Mass fraction of air\";
// algorithm
// p_steam_sat := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.saturationPressure(T);
// X_sat := min(p_steam_sat * 0.6219647130774989 / max(1e-13, p - p_steam_sat) * (1.0 - X[1]), 1.0);
// X_liquid := max(X[1] - X_sat, 0.0);
// X_steam := X[1] - X_liquid;
// X_air := 1.0 - X[1];
// h := Modelica.Media.IdealGases.Common.Functions.h_Tlow(Modelica.Media.IdealGases.Common.DataRecord(\"H2O\", 0.01801528, -13423382.81725291, 549760.6476280135, 1000.0, {-39479.6083, 575.5731019999999, 0.931782653, 0.00722271286, -7.34255737e-06, 4.95504349e-09, -1.336933246e-12}, {-33039.7431, 17.24205775}, {1034972.096, -2412.698562, 4.64611078, 0.002291998307, -6.836830479999999e-07, 9.426468930000001e-11, -4.82238053e-15}, {-13842.86509, -7.97814851}, 461.5233290850878), T, true, Modelica.Media.Interfaces.Choices.ReferenceEnthalpy.UserDefined, 2547494.319) * X_steam + Modelica.Media.IdealGases.Common.Functions.h_Tlow(Modelica.Media.IdealGases.Common.DataRecord(\"Air\", 0.0289651159, -4333.833858403446, 298609.6803431054, 1000.0, {10099.5016, -196.827561, 5.00915511, -0.00576101373, 1.06685993e-05, -7.94029797e-09, 2.18523191e-12}, {-176.796731, -3.921504225}, {241521.443, -1257.8746, 5.14455867, -0.000213854179, 7.06522784e-08, -1.07148349e-11, 6.57780015e-16}, {6462.26319, -8.147411905}, 287.0512249529787), T, true, Modelica.Media.Interfaces.Choices.ReferenceEnthalpy.UserDefined, 25104.684) * X_air + Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.enthalpyOfWater(T) * X_liquid;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.h_pTX;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.h_pTX_der \"Derivative function of h_pTX\"
// input Real p(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\") \"Pressure\";
// input Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) \"Temperature\";
// input Real[:] X(quantity = fill(\"MassFraction\", size(X, 1)), unit = fill(\"1\", size(X, 1)), min = fill(0.0, size(X, 1)), max = fill(1.0, size(X, 1))) \"Mass fractions of moist air\";
// input Real dp(unit = \"Pa/s\") \"Pressure derivative\";
// input Real dT(unit = \"K/s\") \"Temperature derivative\";
// input Real[:] dX(unit = \"1/s\") \"Composition derivative\";
// output Real h_der(unit = \"J/(kg.s)\") \"Time derivative of specific enthalpy\";
// protected Real p_steam_sat(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, nominal = 100000.0) \"partial saturation pressure of steam\";
// protected Real X_sat(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Absolute humidity per unit mass of moist air\";
// protected Real X_liquid(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Mass fraction of liquid water\";
// protected Real X_steam(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Mass fraction of steam water\";
// protected Real X_air(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Mass fraction of air\";
// protected Real x_sat(quantity = \"MassFraction\", unit = \"1\", min = 0.0, max = 1.0) \"Absolute humidity per unit mass of dry air at saturation\";
// protected Real dX_steam(unit = \"1/s\") \"Time derivative of steam mass fraction\";
// protected Real dX_air(unit = \"1/s\") \"Time derivative of dry air mass fraction\";
// protected Real dX_liq(unit = \"1/s\") \"Time derivative of liquid/solid water mass fraction\";
// protected Real dps(unit = \"Pa/s\") \"Time derivative of saturation pressure\";
// protected Real dx_sat(unit = \"1/s\") \"Time derivative of absolute humidity per unit mass of dry air\";
// algorithm
// p_steam_sat := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.saturationPressure(T);
// x_sat := p_steam_sat * 0.6219647130774989 / max(1e-13, p - p_steam_sat);
// X_sat := min(x_sat * (1.0 - X[1]), 1.0);
// X_liquid := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.Utilities.smoothMax(X[1] - X_sat, 0.0, 1e-05);
// X_steam := X[1] - X_liquid;
// X_air := 1.0 - X[1];
// dX_air := -dX[1];
// dps := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.saturationPressure_der(T, dT);
// dx_sat := 0.6219647130774989 * (dps * (p - p_steam_sat) - p_steam_sat * (dp - dps)) / (p - p_steam_sat) / (p - p_steam_sat);
// dX_liq := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.Utilities.smoothMax_der(X[1] - X_sat, 0.0, 1e-05, (1.0 + x_sat) * dX[1] - (1.0 - X[1]) * dx_sat, 0.0, 0.0);
// dX_steam := dX[1] - dX_liq;
// h_der := X_steam * Modelica.Media.IdealGases.Common.Functions.h_Tlow_der(Modelica.Media.IdealGases.Common.DataRecord(\"H2O\", 0.01801528, -13423382.81725291, 549760.6476280135, 1000.0, {-39479.6083, 575.5731019999999, 0.931782653, 0.00722271286, -7.34255737e-06, 4.95504349e-09, -1.336933246e-12}, {-33039.7431, 17.24205775}, {1034972.096, -2412.698562, 4.64611078, 0.002291998307, -6.836830479999999e-07, 9.426468930000001e-11, -4.82238053e-15}, {-13842.86509, -7.97814851}, 461.5233290850878), T, true, Modelica.Media.Interfaces.Choices.ReferenceEnthalpy.UserDefined, 2547494.319, dT) + dX_steam * Modelica.Media.IdealGases.Common.Functions.h_Tlow(Modelica.Media.IdealGases.Common.DataRecord(\"H2O\", 0.01801528, -13423382.81725291, 549760.6476280135, 1000.0, {-39479.6083, 575.5731019999999, 0.931782653, 0.00722271286, -7.34255737e-06, 4.95504349e-09, -1.336933246e-12}, {-33039.7431, 17.24205775}, {1034972.096, -2412.698562, 4.64611078, 0.002291998307, -6.836830479999999e-07, 9.426468930000001e-11, -4.82238053e-15}, {-13842.86509, -7.97814851}, 461.5233290850878), T, true, Modelica.Media.Interfaces.Choices.ReferenceEnthalpy.UserDefined, 2547494.319) + X_air * Modelica.Media.IdealGases.Common.Functions.h_Tlow_der(Modelica.Media.IdealGases.Common.DataRecord(\"Air\", 0.0289651159, -4333.833858403446, 298609.6803431054, 1000.0, {10099.5016, -196.827561, 5.00915511, -0.00576101373, 1.06685993e-05, -7.94029797e-09, 2.18523191e-12}, {-176.796731, -3.921504225}, {241521.443, -1257.8746, 5.14455867, -0.000213854179, 7.06522784e-08, -1.07148349e-11, 6.57780015e-16}, {6462.26319, -8.147411905}, 287.0512249529787), T, true, Modelica.Media.Interfaces.Choices.ReferenceEnthalpy.UserDefined, 25104.684, dT) + dX_air * Modelica.Media.IdealGases.Common.Functions.h_Tlow(Modelica.Media.IdealGases.Common.DataRecord(\"Air\", 0.0289651159, -4333.833858403446, 298609.6803431054, 1000.0, {10099.5016, -196.827561, 5.00915511, -0.00576101373, 1.06685993e-05, -7.94029797e-09, 2.18523191e-12}, {-176.796731, -3.921504225}, {241521.443, -1257.8746, 5.14455867, -0.000213854179, 7.06522784e-08, -1.07148349e-11, 6.57780015e-16}, {6462.26319, -8.147411905}, 287.0512249529787), T, true, Modelica.Media.Interfaces.Choices.ReferenceEnthalpy.UserDefined, 25104.684) + X_liquid * Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.enthalpyOfWater_der(T, dT) + dX_liq * Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.enthalpyOfWater(T);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.h_pTX_der;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.saturationPressure \"Return saturation pressure of water as a function of temperature T between 190 and 647.096 K\"
// input Real Tsat(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 190.0, max = 647.0, start = 288.15, nominal = 300.0) \"Saturation temperature\";
// output Real psat(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, max = 100000000.0, start = 100000.0, nominal = 100000.0) \"Saturation pressure\";
// algorithm
// psat := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.Utilities.spliceFunction(Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.saturationPressureLiquid(Tsat), Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.sublimationPressureIce(Tsat), Tsat - 273.16, 1.0);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.saturationPressure;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.saturationPressureLiquid \"Return saturation pressure of water as a function of temperature T in the range of 273.16 to 647.096 K\"
// input Real Tsat(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) \"Saturation temperature\";
// output Real psat(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, nominal = 100000.0) \"Saturation pressure\";
// protected Real Tcritical(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) = 647.096 \"Critical temperature\";
// protected Real pcritical(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, nominal = 100000.0) = 22064000.0 \"Critical pressure\";
// protected Real[:] a = {-7.85951783, 1.84408259, -11.7866497, 22.6807411, -15.9618719, 1.80122502} \"Coefficients a[:]\";
// protected Real[:] n = {1.0, 1.5, 3.0, 3.5, 4.0, 7.5} \"Coefficients n[:]\";
// protected Real r1 = 1.0 - Tsat / Tcritical \"Common subexpression\";
// algorithm
// psat := exp((a[1] * r1 ^ n[1] + a[2] * r1 ^ n[2] + a[3] * r1 ^ n[3] + a[4] * r1 ^ n[4] + a[5] * r1 ^ n[5] + a[6] * r1 ^ n[6]) * Tcritical / Tsat) * pcritical;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.saturationPressureLiquid;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.saturationPressureLiquid_der \"Derivative function for 'saturationPressureLiquid'\"
// input Real Tsat(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) \"Saturation temperature\";
// input Real dTsat(unit = \"K/s\") \"Saturation temperature derivative\";
// output Real psat_der(unit = \"Pa/s\") \"Saturation pressure derivative\";
// protected Real Tcritical(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) = 647.096 \"Critical temperature\";
// protected Real pcritical(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, nominal = 100000.0) = 22064000.0 \"Critical pressure\";
// protected Real[:] a = {-7.85951783, 1.84408259, -11.7866497, 22.6807411, -15.9618719, 1.80122502} \"Coefficients a[:]\";
// protected Real[:] n = {1.0, 1.5, 3.0, 3.5, 4.0, 7.5} \"Coefficients n[:]\";
// protected Real r1 = 1.0 - Tsat / Tcritical \"Common subexpression 1\";
// protected Real r1_der = -1.0 / Tcritical * dTsat \"Derivative of common subexpression 1\";
// protected Real r2 = a[1] * r1 ^ n[1] + a[2] * r1 ^ n[2] + a[3] * r1 ^ n[3] + a[4] * r1 ^ n[4] + a[5] * r1 ^ n[5] + a[6] * r1 ^ n[6] \"Common subexpression 2\";
// algorithm
// psat_der := exp(r2 * Tcritical / Tsat) * pcritical * ((a[1] * r1 ^ (n[1] - 1.0) * n[1] * r1_der + a[2] * r1 ^ (n[2] - 1.0) * n[2] * r1_der + a[3] * r1 ^ (n[3] - 1.0) * n[3] * r1_der + a[4] * r1 ^ (n[4] - 1.0) * n[4] * r1_der + a[5] * r1 ^ (n[5] - 1.0) * n[5] * r1_der + a[6] * r1 ^ (n[6] - 1.0) * n[6] * r1_der) * Tcritical / Tsat - r2 * Tcritical * dTsat / Tsat ^ 2.0);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.saturationPressureLiquid_der;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.saturationPressure_der \"Derivative function for 'saturationPressure'\"
// input Real Tsat(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 190.0, max = 647.0, start = 288.15, nominal = 300.0) \"Saturation temperature\";
// input Real dTsat(unit = \"K/s\") \"Time derivative of saturation temperature\";
// output Real psat_der(unit = \"Pa/s\") \"Saturation pressure\";
// algorithm
// psat_der := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.Utilities.spliceFunction_der(Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.saturationPressureLiquid(Tsat), Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.sublimationPressureIce(Tsat), Tsat - 273.16, 1.0, Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.saturationPressureLiquid_der(Tsat, dTsat), Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.sublimationPressureIce_der(Tsat, dTsat), dTsat, 0.0);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.saturationPressure_der;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.setState_pTX \"Return thermodynamic state as function of pressure p, temperature T and composition X\"
// input Real p(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, max = 100000000.0, start = 100000.0, nominal = 100000.0) \"Pressure\";
// input Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 190.0, max = 647.0, start = 288.15, nominal = 300.0) \"Temperature\";
// input Real[:] X(quantity = fill(\"MassFraction\", size(X, 1)), unit = fill(\"kg/kg\", size(X, 1)), min = fill(0.0, size(X, 1)), max = fill(1.0, size(X, 1)), nominal = fill(0.1, size(X, 1))) = {0.01, 0.99} \"Mass fractions\";
// output Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.ThermodynamicState state \"Thermodynamic state\";
// algorithm
// state := if size(X, 1) == 2 then Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.ThermodynamicState(p, T, X) else Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.ThermodynamicState(p, T, cat(1, X, {1.0 - sum(X)}));
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.setState_pTX;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.setState_phX \"Return thermodynamic state as function of pressure p, specific enthalpy h and composition X\"
// input Real p(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, max = 100000000.0, start = 100000.0, nominal = 100000.0) \"Pressure\";
// input Real h(quantity = \"SpecificEnergy\", unit = \"J/kg\", min = -10000000000.0, max = 10000000000.0, nominal = 1000000.0) \"Specific enthalpy\";
// input Real[:] X(quantity = fill(\"MassFraction\", size(X, 1)), unit = fill(\"kg/kg\", size(X, 1)), min = fill(0.0, size(X, 1)), max = fill(1.0, size(X, 1)), nominal = fill(0.1, size(X, 1))) = {0.01, 0.99} \"Mass fractions\";
// output Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.ThermodynamicState state \"Thermodynamic state\";
// algorithm
// state := if size(X, 1) == 2 then Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.ThermodynamicState(p, Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX(p, h, X), X) else Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.ThermodynamicState(p, Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.T_phX(p, h, X), cat(1, X, {1.0 - sum(X)}));
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.setState_phX;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.specificEnthalpy \"Return specific enthalpy of moist air as a function of the thermodynamic state record\"
// input Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.ThermodynamicState state \"Thermodynamic state record\";
// output Real h(quantity = \"SpecificEnergy\", unit = \"J/kg\", min = -10000000000.0, max = 10000000000.0, nominal = 1000000.0) \"Specific enthalpy\";
// algorithm
// h := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.h_pTX(state.p, state.T, state.X);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.specificEnthalpy;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.specificEnthalpy_pTX \"Return specific enthalpy from p, T, and X or Xi\"
// input Real p(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, max = 100000000.0, start = 100000.0, nominal = 100000.0) \"Pressure\";
// input Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 190.0, max = 647.0, start = 288.15, nominal = 300.0) \"Temperature\";
// input Real[:] X(quantity = fill(\"MassFraction\", size(X, 1)), unit = fill(\"kg/kg\", size(X, 1)), min = fill(0.0, size(X, 1)), max = fill(1.0, size(X, 1)), nominal = fill(0.1, size(X, 1))) = {0.01, 0.99} \"Mass fractions\";
// output Real h(quantity = \"SpecificEnergy\", unit = \"J/kg\", min = -10000000000.0, max = 10000000000.0, nominal = 1000000.0) \"Specific enthalpy\";
// algorithm
// h := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.specificEnthalpy(Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.setState_pTX(p, T, X));
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.specificEnthalpy_pTX;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.sublimationPressureIce \"Return sublimation pressure of water as a function of temperature T between 190 and 273.16 K\"
// input Real Tsat(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) \"Sublimation temperature\";
// output Real psat(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, nominal = 100000.0) \"Sublimation pressure\";
// protected Real Ttriple(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) = 273.16 \"Triple point temperature\";
// protected Real ptriple(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, nominal = 100000.0) = 611.657 \"Triple point pressure\";
// protected Real[:] a = {-13.928169, 34.7078238} \"Coefficients a[:]\";
// protected Real[:] n = {-1.5, -1.25} \"Coefficients n[:]\";
// protected Real r1 = Tsat / Ttriple \"Common subexpression\";
// algorithm
// psat := exp(a[1] - a[1] * r1 ^ n[1] + a[2] - a[2] * r1 ^ n[2]) * ptriple;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.sublimationPressureIce;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.sublimationPressureIce_der \"Derivative function for 'sublimationPressureIce'\"
// input Real Tsat(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) \"Sublimation temperature\";
// input Real dTsat(unit = \"K/s\") \"Sublimation temperature derivative\";
// output Real psat_der(unit = \"Pa/s\") \"Sublimation pressure derivative\";
// protected Real Ttriple(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 0.0, start = 288.15, nominal = 300.0) = 273.16 \"Triple point temperature\";
// protected Real ptriple(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, nominal = 100000.0) = 611.657 \"Triple point pressure\";
// protected Real[:] a = {-13.928169, 34.7078238} \"Coefficients a[:]\";
// protected Real[:] n = {-1.5, -1.25} \"Coefficients n[:]\";
// protected Real r1 = Tsat / Ttriple \"Common subexpression 1\";
// protected Real r1_der = dTsat / Ttriple \"Derivative of common subexpression 1\";
// algorithm
// psat_der := exp(a[1] - a[1] * r1 ^ n[1] + a[2] - a[2] * r1 ^ n[2]) * ptriple * ((-a[1] * r1 ^ (n[1] - 1.0) * n[1] * r1_der) - a[2] * r1 ^ (n[2] - 1.0) * n[2] * r1_der);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.sublimationPressureIce_der;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.temperature \"Return temperature of ideal gas as a function of the thermodynamic state record\"
// input Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.ThermodynamicState state \"Thermodynamic state record\";
// output Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 190.0, max = 647.0, start = 288.15, nominal = 300.0) \"Temperature\";
// algorithm
// T := state.T;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.temperature;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.temperature_phX \"Return temperature from p, h, and X or Xi\"
// input Real p(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, max = 100000000.0, start = 100000.0, nominal = 100000.0) \"Pressure\";
// input Real h(quantity = \"SpecificEnergy\", unit = \"J/kg\", min = -10000000000.0, max = 10000000000.0, nominal = 1000000.0) \"Specific enthalpy\";
// input Real[:] X(quantity = fill(\"MassFraction\", size(X, 1)), unit = fill(\"kg/kg\", size(X, 1)), min = fill(0.0, size(X, 1)), max = fill(1.0, size(X, 1)), nominal = fill(0.1, size(X, 1))) = {0.01, 0.99} \"Mass fractions\";
// output Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 190.0, max = 647.0, start = 288.15, nominal = 300.0) \"Temperature\";
// algorithm
// T := Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.temperature(Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.setState_phX(p, h, X));
// end Modelica.Fluid.Examples.BranchingDynamicPipes.boundary4.Medium.temperature_phX;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.T_phX \"Return temperature as a function of pressure p, specific enthalpy h and composition X\"
// input Real p(quantity = \"Pressure\", unit = \"Pa\", displayUnit = \"bar\", min = 0.0, max = 100000000.0, start = 100000.0, nominal = 100000.0) \"Pressure\";
// input Real h(quantity = \"SpecificEnergy\", unit = \"J/kg\", min = -10000000000.0, max = 10000000000.0, nominal = 1000000.0) \"Specific enthalpy\";
// input Real[:] X(quantity = fill(\"MassFraction\", size(X, 1)), unit = fill(\"kg/kg\", size(X, 1)), min = fill(0.0, size(X, 1)), max = fill(1.0, size(X, 1)), nominal = fill(0.1, size(X, 1))) \"Mass fractions of composition\";
// output Real T(quantity = \"ThermodynamicTemperature\", unit = \"K\", displayUnit = \"degC\", min = 190.0, max = 647.0, start = 288.15, nominal = 300.0) \"Temperature\";
// algorithm
// T := Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.T_phX.Internal.solve(h, 190.0, 647.0, p, X[1:1], Modelica.Media.IdealGases.Common.DataRecord(\"H2O\", 0.01801528, -13423382.81725291, 549760.6476280135, 1000.0, {-39479.6083, 575.5731019999999, 0.931782653, 0.00722271286, -7.34255737e-06, 4.95504349e-09, -1.336933246e-12}, {-33039.7431, 17.24205775}, {1034972.096, -2412.698562, 4.64611078, 0.002291998307, -6.836830479999999e-07, 9.426468930000001e-11, -4.82238053e-15}, {-13842.86509, -7.97814851}, 461.5233290850878), 1e-13);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.T_phX;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.T_phX.Internal.f_nonlinear
// input Real x \"Independent variable of function\";
// input Real p = 0.0 \"Disregarded variables (here always used for pressure)\";
// input Real[:] X = {} \"Disregarded variables (her always used for composition)\";
// input Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.T_phX.Internal.f_nonlinear_Data f_nonlinear_data \"Additional data for the function\";
// output Real y \"= f_nonlinear(x)\";
// algorithm
// y := Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.h_pTX(p, x, X);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.T_phX.Internal.f_nonlinear;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.T_phX.Internal.f_nonlinear_Data \"Automatically generated record constructor for Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.T_phX.Internal.f_nonlinear_Data\"
// input String name;
// input Real MM;
// input Real Hf;
// input Real H0;
// input Real Tlimit;
// input Real[7] alow;
// input Real[2] blow;
// input Real[7] ahigh;
// input Real[2] bhigh;
// input Real R;
// output f_nonlinear_Data res;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.T_phX.Internal.f_nonlinear_Data;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.T_phX.Internal.solve
// input Real y_zero \"Determine x_zero, such that f_nonlinear(x_zero) = y_zero\";
// input Real x_min \"Minimum value of x\";
// input Real x_max \"Maximum value of x\";
// input Real pressure = 0.0 \"Disregarded variables (here always used for pressure)\";
// input Real[:] X = {} \"Disregarded variables (here always used for composition)\";
// input Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.T_phX.Internal.f_nonlinear_Data f_nonlinear_data \"Additional data for function f_nonlinear\";
// input Real x_tol = 1e-13 \"Relative tolerance of the result\";
// output Real x_zero \"f_nonlinear(x_zero) = y_zero\";
// protected constant Real eps = 1e-15 \"Machine epsilon\";
// protected constant Real x_eps = 1e-10 \"Slight modification of x_min, x_max, since x_min, x_max are usually exactly at the borders T_min/h_min and then small numeric noise may make the interval invalid\";
// protected Real c \"Intermediate point a <= c <= b\";
// protected Real d;
// protected Real e \"b - a\";
// protected Real m;
// protected Real s;
// protected Real p;
// protected Real q;
// protected Real r;
// protected Real tol;
// protected Real fa \"= f_nonlinear(a) - y_zero\";
// protected Real fb \"= f_nonlinear(b) - y_zero\";
// protected Real fc;
// protected Boolean found = false;
// protected Real x_min2 = x_min - x_eps;
// protected Real x_max2 = x_max + x_eps;
// protected Real a = x_min2 \"Current best minimum interval value\";
// protected Real b = x_max2 \"Current best maximum interval value\";
// algorithm
// fa := Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.T_phX.Internal.f_nonlinear(x_min2, pressure, X, f_nonlinear_data) - y_zero;
// fb := Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.T_phX.Internal.f_nonlinear(x_max2, pressure, X, f_nonlinear_data) - y_zero;
// fc := fb;
// if fa > 0.0 and fb > 0.0 or fa < 0.0 and fb < 0.0 then
// Modelica.Utilities.Streams.error(\"The arguments x_min and x_max to OneNonLinearEquation.solve(..)
// do not bracket the root of the single non-linear equation:
// x_min = \" + String(x_min2, 6, 0, true) + \"
// \" + \" x_max = \" + String(x_max2, 6, 0, true) + \"
// \" + \" y_zero = \" + String(y_zero, 6, 0, true) + \"
// \" + \" fa = f(x_min) - y_zero = \" + String(fa, 6, 0, true) + \"
// \" + \" fb = f(x_max) - y_zero = \" + String(fb, 6, 0, true) + \"
// \" + \"fa and fb must have opposite sign which is not the case\");
// end if;
// c := a;
// fc := fa;
// e := b - a;
// d := e;
// while not found loop
// if abs(fc) < abs(fb) then
// a := b;
// b := c;
// c := a;
// fa := fb;
// fb := fc;
// fc := fa;
// end if;
// tol := 2.0 * eps * abs(b) + x_tol;
// m := (c - b) / 2.0;
// if abs(m) <= tol or fb == 0.0 then
// found := true;
// x_zero := b;
// else
// if abs(e) < tol or abs(fa) <= abs(fb) then
// e := m;
// d := e;
// else
// s := fb / fa;
// if a == c then
// p := 2.0 * m * s;
// q := 1.0 - s;
// else
// q := fa / fc;
// r := fb / fc;
// p := s * (2.0 * m * q * (q - r) - (b - a) * (r - 1.0));
// q := (q - 1.0) * (r - 1.0) * (s - 1.0);
// end if;
// if p > 0.0 then
// q := -q;
// else
// p := -p;
// end if;
// s := e;
// e := d;
// if 2.0 * p < 3.0 * m * q - abs(tol * q) and p < abs(0.5 * s * q) then
// d := p / q;
// else
// e := m;
// d := e;
// end if;
// end if;
// a := b;
// fa := fb;
// b := b + (if abs(d) > tol then d else if m > 0.0 then tol else -tol);
// fb := Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.T_phX.Internal.f_nonlinear(b, pressure, X, f_nonlinear_data) - y_zero;
// if fb > 0.0 and fc > 0.0 or fb < 0.0 and fc < 0.0 then
// c := a;
// fc := fa;
// e := b - a;
// d := e;
// end if;
// end if;
// end while;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.T_phX.Internal.solve;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.ThermodynamicState \"Automatically generated record constructor for Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.ThermodynamicState\"
// input Real p;
// input Real T;
// input Real[2] X;
// output ThermodynamicState res;
// end Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.ThermodynamicState;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.Utilities.smoothMax
// input Real x1 \"First argument of smooth max operator\";
// input Real x2 \"Second argument of smooth max operator\";
// input Real dx \"Approximate difference between x1 and x2, below which regularization starts\";
// output Real y \"Result of smooth max operator\";
// algorithm
// y := max(x1, x2) + log(exp(4.0 / dx * (x1 - max(x1, x2))) + exp(4.0 / dx * (x2 - max(x1, x2)))) / (4.0 / dx);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.Utilities.smoothMax;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.Utilities.smoothMax_der
// input Real x1 \"First argument of smooth max operator\";
// input Real x2 \"Second argument of smooth max operator\";
// input Real dx \"Approximate difference between x1 and x2, below which regularization starts\";
// input Real dx1;
// input Real dx2;
// input Real ddx;
// output Real dy \"Derivative of smooth max operator\";
// algorithm
// dy := (if x1 > x2 then dx1 else dx2) + 0.25 * (((4.0 * (dx1 - (if x1 > x2 then dx1 else dx2)) / dx - 4.0 * (x1 - max(x1, x2)) * ddx / dx ^ 2.0) * exp(4.0 * (x1 - max(x1, x2)) / dx) + (4.0 * (dx2 - (if x1 > x2 then dx1 else dx2)) / dx - 4.0 * (x2 - max(x1, x2)) * ddx / dx ^ 2.0) * exp(4.0 * (x2 - max(x1, x2)) / dx)) * dx / (exp(4.0 * (x1 - max(x1, x2)) / dx) + exp(4.0 * (x2 - max(x1, x2)) / dx)) + log(exp(4.0 * (x1 - max(x1, x2)) / dx) + exp(4.0 * (x2 - max(x1, x2)) / dx)) * ddx);
// end Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.Utilities.smoothMax_der;
//
// function Modelica.Fluid.Examples.BranchingDynamicPipes.pipe1.Medium.Utilities.spliceFunction \"Spline interpolation of two functions\"
// input Real pos \"Returned value for x-deltax >= 0\";
// input Real neg \"Returned value for x+deltax <= 0\";
// input Real x \"Function argument\";
// input Real deltax = 1.0 \"Region around x with spline interpolation\";
// output Real out;
// protected Real scaledX;
// protected Real scaledX1;
// protected Real y;
// algorithm
// scaledX1 := x / deltax;
// scaledX := scaledX1 * 1.570796326794897;
// if scaledX1 <= -0.999999999 then
// y := 0.0;
// elseif scaledX1 >= 0.999999999 then
// y := 1.0;