forked from MarekMatejak/Physiolibrary
/
Blocks.mo
841 lines (761 loc) · 33.8 KB
/
Blocks.mo
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
within Physiolibrary;
package Blocks "Base Signal Blocks Library"
extends Modelica.Icons.Package;
package Math "Modelica.Math extension"
extends Modelica.Icons.Package;
model Integrator "Integrator with support of steady state calculation."
extends SteadyStates.Interfaces.SteadyState(
state_start=y_start, state(nominal=NominalValue));
parameter Real k=1 "Integrator gain";
parameter Real y_start=0 "Initial or guess value of output (= state)"
annotation (Dialog(group="Initialization"));
extends Modelica.Blocks.Interfaces.SISO(u(nominal=NominalValue/k),y(nominal=NominalValue));
parameter Real NominalValue = 1
"Numerical scale. For some substances such as hormones, hydronium or hydroxide ions should be set."
annotation ( HideResult=true, Dialog(tab="Solver",group="Numerical support of very small concentrations"));
equation
state = y; //der(y) = k*u
change = k*u;
annotation (defaultComponentName="int",
Documentation(info="<html>
<p>
This blocks computes output <b>y</b> (element-wise) as
<i>integral</i> of the input <b>u</b> multiplied with
the gain <i>k</i>:
</p>
<pre>
k
y = - u
s
</pre>
<p>
It might be difficult to initialize the integrator in steady state.
This is discussed in the description of package
<a href=\"Modelica://Modelica.Blocks.Continuous#info\">Continuous</a>.
</p>
</html>
"), Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={
Line(points={{-80,78},{-80,-90}}, color={192,192,192}),
Polygon(
points={{-80,90},{-88,68},{-72,68},{-80,90}},
lineColor={192,192,192},
fillColor={192,192,192},
fillPattern=FillPattern.Solid),
Line(points={{-90,-80},{82,-80}}, color={192,192,192}),
Polygon(
points={{90,-80},{68,-72},{68,-88},{90,-80}},
lineColor={192,192,192},
fillColor={192,192,192},
fillPattern=FillPattern.Solid),
Text(
extent={{0,-10},{60,-70}},
lineColor={192,192,192},
textString="I"),
Text(
extent={{-150,-150},{150,-110}},
lineColor={0,0,0},
textString="k=%k"),
Line(points={{-80,-80},{80,80}}, color={0,0,127})}),
Diagram(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={
Rectangle(extent={{-60,60},{60,-60}}, lineColor={0,0,255}),
Line(points={{-100,0},{-60,0}}, color={0,0,255}),
Line(points={{60,0},{100,0}}, color={0,0,255}),
Text(
extent={{-36,60},{32,2}},
lineColor={0,0,0},
textString="k"),
Text(
extent={{-32,0},{36,-58}},
lineColor={0,0,0},
textString="s"),
Line(points={{-46,0},{46,0}}, color={0,0,0})}));
end Integrator;
block Add "u + parameter"
parameter Real k(start=1) "value added to input signal";
public
Modelica.Blocks.Interfaces.RealInput u "Input signal connector"
annotation (Placement(transformation(extent={{-140,-20},{-100,20}})));
Modelica.Blocks.Interfaces.RealOutput y "Output signal connector"
annotation (Placement(transformation(extent={{100,-10},{120,10}})));
equation
y = k+u;
annotation (defaultComponentName="add",
Documentation(info="<html>
<p>This block computes output <i>y</i> as <i>sum</i> of offset <i>k</i> with the input <i>u</i>: </p>
<p><code> y = k + u;</code> </p>
</html>"), Icon(coordinateSystem(
preserveAspectRatio=false,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={
Polygon(
points={{-100,100},{100,40},{100,-40},{-100,-100},{-100,100}},
lineColor={0,0,127},
smooth=Smooth.None,
fillColor={255,255,255},
fillPattern=FillPattern.Solid),
Text(
extent={{-100,-42},{100,40}},
lineColor={0,0,0},
textString="u+%k"),
Text(
extent={{-150,140},{150,100}},
textString="%name",
lineColor={0,0,255})}),
Diagram(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={Polygon(
points={{-100,-100},{-100,100},{100,0},{-100,-100}},
lineColor={0,0,127},
fillColor={255,255,255},
fillPattern=FillPattern.Solid), Text(
extent={{-76,38},{0,-34}},
lineColor={0,0,255},
textString="k")}));
end Add;
block Reciprocal "1 / u"
extends Modelica.Blocks.Interfaces.SISO;
equation
y = 1/u;
annotation (defaultComponentName="rec",
Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={Text(
extent={{-100,100},{100,-100}},
lineColor={0,0,0},
textString="1/u")}),
Documentation(info="<html>
<p>This blocks computes the output <b>y</b> as <i>reciprocal value</i> of the input <b>u</b>: </p>
<p><code> y = 1 / u ;</code> </p>
</html>"));
end Reciprocal;
block Power "b ^ u"
parameter Boolean useBaseInput = false
"=true, if exponential base input is used instead of parameter Base"
annotation(Evaluate=true, HideResult=true, choices(__Dymola_checkBox=true),Dialog(group="External inputs/outputs"));
parameter Real Base=10 "exponential base if useBaseInput=false"
annotation (Dialog(enable=not useBaseInput));
Modelica.Blocks.Interfaces.RealOutput y
annotation (Placement(transformation(extent={{100,-10},{120,10}})));
Modelica.Blocks.Interfaces.RealInput base(start=Base) = b if useBaseInput annotation (Placement(
transformation(extent={{-120,40},{-80,80}})));
Modelica.Blocks.Interfaces.RealInput exponent annotation (Placement(
transformation(extent={{-120,-80},{-80,-40}})));
protected
Real b "Current exponential base";
equation
if not useBaseInput then
b = Base;
end if;
y = b^exponent;
annotation (defaultComponentName="pow",
Documentation(info="<html>
<p>y = base^exponent</p>
</html>"), Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2},
initialScale=0.04), graphics={Rectangle(
extent={{-100,-100},{100,100}},
lineColor={0,0,127},
fillColor={255,255,255},
fillPattern=FillPattern.Solid), Text(
extent={{-100,-40},{100,40}},
lineColor={0,0,0},
textString="b^u")}));
end Power;
block Min "Pass through the smallest signal"
extends Modelica.Blocks.Interfaces.MISO;
equation
y = min(u);
annotation (defaultComponentName="min", Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics={Text(
extent={{-90,36},{90,-36}},
lineColor={160,160,164},
textString="min()")}),
Documentation(info="<html>
<p>
This block computes the output <b>y</b> as <i>minimum</i> of
the Real inputs <b>u[1]</b>,<b>u[2]</b> .. <b>u[nin]</b>:
</p>
<pre> y = <b>min</b> ( u );
</pre>
</html>
"));
end Min;
block Log10AsEffect "min( 0, log10(u) )"
extends Modelica.Blocks.Interfaces.SISO;
equation
y = if u>1 then Modelica.Math.log10(u) else 0;
annotation (defaultComponentName="logEffect",
Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={
Polygon(
points={{90,0},{68,8},{68,-8},{90,0}},
lineColor={192,192,192},
fillColor={192,192,192},
fillPattern=FillPattern.Solid),
Line(points={{-90,0},{68,0}}, color={192,192,192}),
Polygon(
points={{-80,90},{-88,68},{-72,68},{-80,90}},
lineColor={192,192,192},
fillColor={192,192,192},
fillPattern=FillPattern.Solid),
Line(points={{-80,-80},{-80,68}}, color={192,192,192}),
Text(
extent={{-44,-56},{94,-80}},
lineColor={192,192,192},
textString="max(log10,0)"),
Line(points={{-100,0},{-80,0},{-78,0},{-74,0},{-76,0},{-74,0},{-72,
0},{-69.5,6.08},{-64.7,15.9},{-57.5,26},{-47,36.1},{-31.8,
46.1},{-10.1,56},{22.1,66},{68.7,76.1},{80,78}}, color={0,0,
0})}),
Diagram(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={
Line(points={{-80,80},{-88,80}}, color={192,192,192}),
Line(points={{-80,-80},{-88,-80}}, color={192,192,192}),
Line(points={{-80,-90},{-80,84}}, color={192,192,192}),
Text(
extent={{-65,96},{-38,78}},
lineColor={160,160,164},
textString="y"),
Polygon(
points={{-80,100},{-86,84},{-74,84},{-80,100}},
lineColor={192,192,192},
fillColor={192,192,192},
fillPattern=FillPattern.Solid),
Line(points={{-100,0},{84,0}}, color={192,192,192}),
Polygon(
points={{100,0},{84,6},{84,-6},{100,0}},
lineColor={192,192,192},
fillColor={192,192,192},
fillPattern=FillPattern.Solid),
Line(points={{-100,0},{-80,0},{-78,0},{-74,0},{-76,0},{-74,0},{-72,
0},{-69.5,6.08},{-64.7,15.9},{-57.5,26},{-47,36.1},{-31.8,
46.1},{-10.1,56},{22.1,66},{68.7,76.1},{80,78}}, color={0,0,
0}),
Text(
extent={{70,-3},{90,-23}},
textString="20",
lineColor={0,0,255}),
Text(
extent={{-78,-1},{-58,-21}},
textString="1",
lineColor={0,0,255}),
Text(
extent={{-109,72},{-89,88}},
textString=" 1.3",
lineColor={0,0,255}),
Text(
extent={{-109,-88},{-89,-72}},
textString="-1.3",
lineColor={0,0,255}),
Text(
extent={{62,30},{90,10}},
lineColor={160,160,164},
textString="u")}),
Documentation(info="<html>
<p>This blocks computes the output <b>y</b> as the <i>base 10 logarithm</i> of the input <b>u </b>if <b>u>1</b> or 0 otherwise </p>
<p><code> y = if(u>1) <b>log10</b>( u ) else 0;</code></p>
</html>"));
end Log10AsEffect;
block Parts "Divide the input value by weights"
extends Modelica.Blocks.Interfaces.SIMO;
parameter Real w[nout]=ones(nout) "Optional: weight coefficients";
protected
Real coef;
Real weight[nout];
equation
ones(nout)*weight = 1;
for i in 1:nout loop
weight[i] = w[i] * coef;
y[i] = u * weight[i];
end for;
annotation (defaultComponentName="parts",
Documentation(info="<html>
<p>This blocks divide input value u to output array y by weights. The sum of output values is equal to input value <b>u</b>: </p>
<p><code> u = (w[1]*y[1] + w[2]*y[2] + ... + w[n]*y[n]) / (w[1] + w[2] + ... + w[n]);</code></p>
<p>Example: </p>
<pre> parameter: nin = 3; w=ones(3);
results in the following equations:
<p><code> y[1]=u/3, y[2]=u/3, y[3]=u/3;</code> </p>
</html>"), Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={Text(
extent={{-100,-100},{100,100}},
lineColor={0,0,0},
textString="Parts")}));
end Parts;
block HomotopyStrongComponentBreaker
"Break the strong component in normalized signal with independent default constant value"
extends Modelica.Blocks.Interfaces.SISO;
parameter Real defaultValue=1;
parameter Real defaultSlope=0;
equation
y = homotopy(u,defaultValue + defaultSlope*(u-defaultValue));
//y = homotopy(u,defaultValue);
annotation (defaultComponentName="homotopy",
Documentation(info="<html>
<p>This blocks should solve the initial strong component problem. In the non-linear-strong-component-cycled place, where the default or mean value of variable is known.</p>
<p>For example the regulation loop L driven by loop-dependent effect E with default value 1:</p>
<p> </p>
<p>E=f(L(E)) can be rewritten to E=f(L( H )), where H is output from this block with input E. </p>
</html>"), Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2},
initialScale=0.04), graphics={Text(
extent={{-100,-24},{96,20}},
lineColor={0,0,255},
textString="Homotopy")}),
Diagram(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2},
initialScale=0.04), graphics={Rectangle(
extent={{-100,-100},{100,100}},
lineColor={0,0,255},
fillColor={255,255,255},
fillPattern=FillPattern.Solid), Text(
extent={{-98,-18},{98,26}},
lineColor={0,0,255},
textString="Homotopy")}));
end HomotopyStrongComponentBreaker;
end Math;
package Interpolation "Empirical Dependence of Two Variables"
extends Modelica.Icons.Package;
function Spline "Cubic spline interpolation function"
input Real[:] x "x coordinations of interpolating points"; //souradnice x souradnice uzlovych bodu
input Real[:,4] a
"cubic polynom coefficients of curve segments between interpolating points"; //parametry kubiky
input Real xVal "input value of x to calculate y value"; //vstupni hodnota
output Real yVal "y value at xVal";
// output Real outExtra;
protected
Integer index "index of segment";
Integer n "number of interpolating points";
algorithm
// Najdi interval, ve kterem se nachazi xVal
if (xVal <= x[1]) then //kdyz je hodnota xVal pred prvnim uzlovym bodem
yVal := xVal * a[1,3] + a[1,4]; //pocitam primku
else
n := size(x,1); //pocet uzlovych bodu
if (xVal>=x[n]) then //kdyz je hodnota xVal za poslednim uzlovym bodem
yVal := xVal * a[n+1,3] + a[n+1,4]; //pocitam primku
else
index := 2;
while xVal > x[index] and index < n loop
index:=index+1;
end while;
yVal := ((a[index,1]*xVal + a[index,2])*xVal + a[index,3])*xVal + a[index,4];
/*
x1:=x[index-1];
x2:=x[index];
y1:=y[index-1];
y2:=y[index];
slope1:=slope[index-1];
slope2:=slope[index];
a1:=-(-x2*slope2 - x2*slope1 + slope2*x1 + slope1*x1 + 2*y2 - 2*y1)/(x2 - x1)^3;
a2:=(-x2^2*slope2-2*x2^2*slope1-3*x2*y1+x2*slope1*x1+3*x2*y2-x2*slope2*x1-3*y1*x1+slope1*x1^2+3*y2*x1+2*slope2*x1^2)/(x2-x1)^3;
a3:=-(-slope1*x2^3-2*x2^2*slope2*x1-x2^2*slope1*x1+x2*slope2*x1^2+2*x2*slope1*x1^2+6*x2*x1*y2-6*x2*x1*y1+slope2*x1^3)/(x2-x1)^3;
a4:=(-slope1*x2^3*x1+y1*x2^3-slope2*x1^2*x2^2+slope1*x1^2*x2^2-3*y1*x2^2*x1+3*y2*x1^2*x2+slope2*x1^3*x2-y2*x1^3)/(x2-x1)^3;
yVal :=a1*(xVal)^3 + a2*(xVal)^2 + a3*(xVal) + a4;
*/
end if;
end if;
// outExtra := xVal + yVal;
annotation (Documentation(revisions="<html>
<p>author: Ondrej Vacek</p>
</html>"));
end Spline;
function SplineCoefficients "Cubic spline interpolation coefficients"
input Real[:] x "x coordinations of interpolating points";
input Real[:] y "y coordinations of interpolating points";
input Real[:] slope "slopes at interpolating points";
output Real[size(x,1)+1,4] a
"cubic polynom coefficients of curve segments between interpolating points"; //pocet hodnot ctyrech parametru kubiky je o jeden vic nez pocet bodu
protected
Integer n "number of interpolating points";
Integer i "index of segment";
Real x1 "previos point";
Real x2 "current point";
Real y1 "previous point";
Real y2 "current point";
Real slope1 "previous point";
Real slope2 "current point";
algorithm
n := size(x,1);//pocet uzlovych bodu
for i in 2:n loop //cyklus od 2 do n
x1:=x[i-1]; //predchozi bod
x2:=x[i]; //soucasny bod
y1:=y[i-1]; //predchozi bod
y2:=y[i]; //soucasny bod
slope1:=slope[i-1]; //predchozi bod
slope2:=slope[i]; //soucasny bod
//vypocty parametru kubiky (od 2 do n) podle souradnic a smernic dvou bodu : y=a[i,4]+a[i,3]*x+a[i,2]*x^2+a[i,1]*x^3
a[i,1]:=-(-x2*slope2 - x2*slope1 + x1*slope2 + x1*slope1 + 2*y2 - 2*y1)/(x2 - x1)^3;
a[i,2]:=(-x2^2*slope2-2*x2^2*slope1-3*x2*y1+x2*slope1*x1+3*x2*y2-x2*slope2*x1-3*y1*x1+slope1*x1^2+3*y2*x1+2*slope2*x1^2)/(x2-x1)^3;
a[i,3]:=-(-slope1*x2^3-2*x2^2*slope2*x1-x2^2*slope1*x1+x2*slope2*x1^2+2*x2*slope1*x1^2+6*x2*x1*y2-6*x2*x1*y1+slope2*x1^3)/(x2-x1)^3;
a[i,4]:=(-slope1*x2^3*x1+y1*x2^3-slope2*x1^2*x2^2+slope1*x1^2*x2^2-3*y1*x2^2*x1+3*y2*x1^2*x2+slope2*x1^3*x2-y2*x1^3)/(x2-x1)^3;
end for;
a[1, :] := { 0, 0, slope[1], y[1] - x[1]*slope[1]}; //vypocet prvni sady parametru kubiky - primky
a[n+1,:] := { 0, 0, slope[n], y[n] - x[n]*slope[n]}; //vypocet posledni sady parametru kubiky - primky
annotation (Documentation(revisions="<html>
<p>author: Ondrej Vacek</p>
</html>"));
end SplineCoefficients;
model Curve
"2D natural cubic interpolation spline defined with (x,y,slope) points"
parameter Real x[:] = fill(Modelica.Constants.N_A,1)
"x coordinations of interpolating points";
parameter Real y[:] = fill(Modelica.Constants.N_A,1)
"y coordinations of interpolating points";
parameter Real slope[:] = fill(Modelica.Constants.N_A,1)
"slopes at interpolating points";
parameter Real[:,3] data = transpose({x,y,slope})
"Array of interpolating points as {x,y,slope}";
parameter Real Xscale = 1 "conversion scale to SI unit of x values";
parameter Real Yscale = 1 "conversion scale to SI unit of y values";
Modelica.Blocks.Interfaces.RealInput u
annotation (Placement(transformation(extent={{-120,
-20},{-80,20}})));
Modelica.Blocks.Interfaces.RealOutput val
annotation (Placement(transformation(extent={{80,-20},
{120,20}})));
protected
parameter Real a[:,:] = SplineCoefficients( data[:, 1]*Xscale,data[:, 2]*Yscale,data[:, 3]*Yscale/Xscale)
"cubic polynom coefficients of curve segments between interpolating points";
equation
val = Spline(
data[:, 1]*Xscale,
a,
u);
annotation ( Icon(coordinateSystem(
preserveAspectRatio=false, extent={{-100,-100},{100,100}}),
graphics={
Rectangle(
extent={{-100,100},{100,-100}},
lineColor={0,0,127},
fillColor={255,255,255},
fillPattern=FillPattern.Solid),
Line(
points={{-70,-76},{-20,-48},{0,12},{34,62},{76,72}},
color={0,0,127},
smooth=Smooth.Bezier),
Line(
points={{-48,-82},{-48,90},{-48,90}},
color={0,0,127},
smooth=Smooth.Bezier,
arrow={Arrow.None,Arrow.Filled}),
Line(
points={{-72,-74},{68,-74},{68,-74}},
color={0,0,127},
smooth=Smooth.Bezier,
arrow={Arrow.None,Arrow.Filled})}));
end Curve;
end Interpolation;
package Factors "Multiplication Effects"
extends Modelica.Icons.Package;
model Normalization "effect = u/NormalValue"
extends Icons.BaseFactorIcon;
parameter Real NormalValue=1
"Normal value of u, because y=(u/NormalValue)*yBase.";
Modelica.Blocks.Interfaces.RealInput u
annotation (Placement(transformation(extent={{-100,-20},{-60,
20}})));
Types.Fraction effect;
equation
effect = u/NormalValue;
y=effect*yBase;
annotation ( Documentation(revisions="<html>
<p><i>2009-2010</i></p>
<p>Marek Matejak, Charles University, Prague, Czech Republic </p>
</html>",
info="<html>
<p><h4>y = yBase * u</h4></p>
</html>"));
end Normalization;
model DamagedFraction "effect = 1 - DamagedAreaFraction"
extends Icons.BaseFactorIcon;
parameter Types.Fraction DamagedAreaFraction = 0;
Types.Fraction effect;
equation
effect = 1-DamagedAreaFraction;
y=yBase*effect;
end DamagedFraction;
model Spline "effect = spline(data,u)"
extends Icons.BaseFactorIcon4;
Modelica.Blocks.Interfaces.RealInput u
annotation (Placement(transformation(extent={{-100,-20},{-60,
20}})));
parameter Real[:,3] data "Array of interpolating points as {x,y,slope}";
parameter Real Xscale = 1 "conversion scale to SI unit of x values";
parameter Real Yscale = 1 "conversion scale to SI unit of y values";
parameter Boolean UsePositiveLog10 = false
"x = if u/scaleX <=1 then 0 else log10(u/scaleX)";
Types.Fraction effect "Multiplication coeffecient for yBase to reach y";
protected
parameter Real a[:,:] = Interpolation.SplineCoefficients(
data[:, 1],data[:, 2]*Yscale,data[:, 3]*Yscale)
"Cubic polynom coefficients of curve segments between interpolating points";
equation
effect = if UsePositiveLog10 then Interpolation.Spline(data[:, 1],a,if u/Xscale <= 1 then 0 else log10(u/Xscale))
else Interpolation.Spline(data[:, 1],a,u/Xscale);
y=effect*yBase;
annotation ( Documentation(revisions="<html>
<p><i>2009-2010</i></p>
<p>Marek Matejak, Charles University, Prague, Czech Republic </p>
</html>"));
end Spline;
model LagSpline "Adapt the input signal before interpolation"
extends Icons.BaseFactorIcon5;
Modelica.Blocks.Interfaces.RealInput u
annotation (Placement(transformation(extent={{-100,-20},{-60,
20}})));
parameter Types.Time HalfTime(displayUnit="min"); //=3462.468;
parameter Real initialValue = 1 "as u/Xscale";
parameter Real Xscale = 1 "conversion scale to SI unit of x values";
parameter Real Yscale = 1 "conversion scale to SI unit of y values";
parameter Boolean UsePositiveLog10 = false
"x = if u_delayed/scaleX <=1 then 0 else log10(u_delayed/scaleX)";
parameter Real[:,3] data;
Blocks.Math.Integrator integrator(k=(Modelica.Math.log(2)/
HalfTime), y_start=initialValue*Xscale)
annotation (Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={-38,38})));
Modelica.Blocks.Math.Feedback feedback annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={-38,68})));
Types.Fraction effect;
Spline spline(
data=data,
Xscale=Xscale,
Yscale=Yscale,
UsePositiveLog10=UsePositiveLog10)
annotation (Placement(transformation(extent={{-10,-18},{10,2}})));
equation
effect = spline.effect;
connect(feedback.y, integrator.u) annotation (Line(
points={{-38,59},{-38,50}},
color={0,0,127},
smooth=Smooth.None));
connect(integrator.y, feedback.u2) annotation (Line(
points={{-38,27},{-38,16},{-62,16},{-62,68},{-46,68}},
color={0,0,127},
smooth=Smooth.None));
connect(feedback.u1, u) annotation (Line(
points={{-38,76},{-38,94},{-88,94},{-88,0},{-80,0}},
color={0,0,127},
smooth=Smooth.None));
connect(integrator.y, spline.u) annotation (Line(
points={{-38,27},{-38,-8},{-8,-8}},
color={0,0,127},
smooth=Smooth.None));
connect(yBase, spline.yBase) annotation (Line(
points={{0,20},{0,-6}},
color={0,0,127},
smooth=Smooth.None));
connect(spline.y, y) annotation (Line(
points={{0,-12},{0,-40}},
color={0,0,127},
smooth=Smooth.None));
annotation ( Documentation(revisions="<html>
<p><i>2009-2010</i></p>
<p>Marek Matejak, Charles University, Prague, Czech Republic </p>
</html>", info="<html>
<p>If the input signal u is constant and it is different from starting delayed input d, the middle value between u and d will be reached after HalfTime.</p>
<p>The mathematical background:</p>
<p>d'(t) = k*(u(t) - d(t)) => The solution of d(t) in special case, if u(t) is constant at each time t: d(t)=u+(d(0)-u)*e^(-k*t), where the definition of HalfTime is d(HalfTime) = d(0) + (d(0)-u)/2.</p>
</html>"), Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},
{100,100}}), graphics));
end LagSpline;
model SplineLag "Adapt the effect after interpolation"
extends Icons.BaseFactorIcon3;
Modelica.Blocks.Interfaces.RealInput u
annotation (Placement(transformation(extent={{-100,-20},{-60,
20}})));
parameter Types.Time HalfTime(displayUnit="d");
//Tau(unit="day");
parameter String stateName=getInstanceName()
"Name in Utilities input/output function"
annotation (Evaluate=true, HideResult=true, Dialog(group="Value I/O",tab="IO"));
parameter Real Xscale = 1 "conversion scale to SI unit of x values";
parameter Boolean UsePositiveLog10 = false
"x = if u/scaleX <=1 then 0 else log10(u/scaleX)";
parameter Real[:,3] data;
Modelica.Blocks.Math.Product product annotation (Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={0,-32})));
Blocks.Math.Integrator integrator(y_start=1, k=(
Modelica.Math.log(2)/HalfTime),
stateName=stateName)
annotation (Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={-26,12})));
Modelica.Blocks.Math.Feedback feedback annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={-26,44})));
Types.Fraction effect;
Spline spline(
data=data,
Xscale=Xscale,
UsePositiveLog10=UsePositiveLog10)
annotation (Placement(transformation(extent={{-36,56},{-16,76}})));
Types.Constants.FractionConst fraction(k(displayUnit="1") = 1)
annotation (Placement(transformation(extent={{-44,82},{-36,90}})));
equation
//der(effect) = (ln(2)/HalfTime)*(spline(data,u)-effect)
effect = integrator.y;
connect(yBase, product.u1) annotation (Line(
points={{0,20},{0,30},{0,-20},{6,-20}},
color={0,0,127},
smooth=Smooth.None));
connect(product.y, y) annotation (Line(
points={{-2.02067e-015,-43},{-2.02067e-015,-55.5},{0,-55.5},{0,-40}},
color={0,0,127},
smooth=Smooth.None));
connect(feedback.y, integrator.u) annotation (Line(
points={{-26,35},{-26,24}},
color={0,0,127},
smooth=Smooth.None));
connect(integrator.y, feedback.u2) annotation (Line(
points={{-26,1},{-26,-8},{-50,-8},{-50,44},{-34,44}},
color={0,0,127},
smooth=Smooth.None));
connect(integrator.y, product.u2) annotation (Line(
points={{-26,1},{-26,-8},{-6,-8},{-6,-20}},
color={0,0,127},
smooth=Smooth.None));
connect(feedback.u1, spline.y) annotation (Line(
points={{-26,52},{-26,62}},
color={0,0,127},
smooth=Smooth.None));
connect(u, spline.u) annotation (Line(
points={{-80,0},{-82,0},{-82,66},{-34,66}},
color={0,0,127},
smooth=Smooth.None));
connect(fraction.y, spline.yBase) annotation (Line(
points={{-35,86},{-26,86},{-26,68}},
color={0,0,127},
smooth=Smooth.None));
annotation ( Documentation(revisions="<html>
<p><i>2009-2010</i></p>
<p>Marek Matejak, Charles University, Prague, Czech Republic </p>
</html>"), Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},
{100,100}}), graphics));
end SplineLag;
model SplineLagOrZero "LagSpline if not Failed"
extends Icons.BaseFactorIcon2;
Modelica.Blocks.Interfaces.RealInput u
annotation (Placement(transformation(extent={{-120,-20},{-80,20}})));
parameter Types.Time HalfTime(displayUnit="d");
parameter Real[:,3] data;
parameter String stateName=getInstanceName()
"Name in Utilities input/output function"
annotation (Evaluate=true, HideResult=true, Dialog(group="Value I/O",tab="IO"));
parameter Real Xscale = 1 "conversion scale to SI unit of x values";
Interpolation.Curve
curve(
x=data[:, 1],
y=data[:, 2],
slope=data[:, 3],
Xscale=Xscale)
annotation (Placement(transformation(extent={{-76,20},{-56,40}})));
Modelica.Blocks.Math.Product product annotation (Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={0,-50})));
Blocks.Math.Integrator integrator(y_start=1, k=(
Modelica.Math.log(2)/HalfTime),
stateName=stateName)
annotation (Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={-14,-6})));
Modelica.Blocks.Math.Feedback feedback annotation (Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={-14,26})));
Modelica.Blocks.Logical.Switch switch1
annotation (Placement(transformation(extent={{-36,40},{-16,60}})));
Modelica.Blocks.Sources.Constant Constant1(k=0)
annotation (Placement(transformation(extent={{-82,62},{-62,82}})));
Modelica.Blocks.Interfaces.BooleanInput
Failed
annotation (Placement(transformation(extent={{-120,20},{-80,
60}})));
Types.Fraction effect;
equation
effect = integrator.y;
connect(curve.u, u) annotation (Line(
points={{-76,30},{-87,30},{-87,0},{-100,0}},
color={0,0,127},
smooth=Smooth.None));
connect(yBase, product.u1) annotation (Line(
points={{0,60},{0,31},{0,-38},{6,-38}},
color={0,0,127},
smooth=Smooth.None));
connect(product.y, y) annotation (Line(
points={{-2.02067e-015,-61},{-2.02067e-015,-55.5},{0,-55.5},{0,-60}},
color={0,0,127},
smooth=Smooth.None));
connect(feedback.y, integrator.u) annotation (Line(
points={{-14,17},{-14,6}},
color={0,0,127},
smooth=Smooth.None));
connect(integrator.y, feedback.u2) annotation (Line(
points={{-14,-17},{-14,-26},{-38,-26},{-38,26},{-22,26}},
color={0,0,127},
smooth=Smooth.None));
connect(integrator.y, product.u2) annotation (Line(
points={{-14,-17},{-14,-26},{-6,-26},{-6,-38}},
color={0,0,127},
smooth=Smooth.None));
connect(switch1.y, feedback.u1) annotation (Line(
points={{-15,50},{-14,50},{-14,34}},
color={0,0,127},
smooth=Smooth.None));
connect(curve.val, switch1.u3) annotation (Line(
points={{-56,30},{-54,30},{-54,42},{-38,42}},
color={0,0,127},
smooth=Smooth.None));
connect(Constant1.y, switch1.u1) annotation (Line(
points={{-61,72},{-58,72},{-58,58},{-38,58}},
color={0,0,127},
smooth=Smooth.None));
connect(switch1.u2, Failed) annotation (Line(
points={{-38,50},{-78,50},{-78,40},{-100,40}},
color={255,0,255},
smooth=Smooth.None));
annotation ( Documentation(revisions="<html>
<p><i>2009-2010</i></p>
<p>Marek Matejak, Charles University, Prague, Czech Republic </p>
</html>"));
end SplineLagOrZero;
end Factors;
annotation (Documentation(revisions="<html>
<p>Licensed by Marek Matejak under the Modelica License 2</p>
<p>Copyright © 2008-2014, Marek Matejak, Charles University in Prague.</p>
<p><br><i>This Modelica package is <u>free</u> software and the use is completely at <u>your own risk</u>; it can be redistributed and/or modified under the terms of the Modelica License 2. For license conditions (including the disclaimer of warranty) see <a href=\"modelica://Physiolibrary.UsersGuide.ModelicaLicense2\">UsersGuide.ModelicaLicense2</a> or visit <a href=\"http://www.modelica.org/licenses/ModelicaLicense2\">http://www.modelica.org/licenses/ModelicaLicense2</a>.</i></p>
</html>"));
end Blocks;