2016-05-24 4 views
1

Dans un modèle continu, comment sauvegarder la valeur minimale d'une variable pendant la simulation?Valeur minimale sur toute la simulation

Quand une simulation est terminée, je veux afficher une variable T_min avec une annotation graphique qui me montre la valeur la plus basse d'une température T pendant la simulation.

Par exemple, si la température simulée T était une fonction sinusoïdale, le résultat souhaité pour la valeur de T_min serait:

enter image description here

Dans le code discret cela ressemblerait à quelque chose comme ceci:

T_min := Modelica.Constants.inf "Start value"; 
if T < T_min then 
    T_min := T; 
else 
    T_min := T_min; 
end if; 

... mais je voudrais une mise en œuvre continue pour éviter l'échantillonnage, le nombre élevé d'événements, etc.

Merci d'avance.

Rene Juste Nielsen

+1

connexes: http://stackoverflow.com/questions/30732774/modelica-compute-minimum-maximum-of-continuous-variable-over-time – matth

Répondre

0

Il semble que j'ai pu finde une réponse à ma propre question simplement en regardant la figure ci-dessus

Le code est assez simple:

model globalMinimum 
    Modelica.SIunits.Temperature T, T_min; 
initial equation 
    T_min = T; 
equation 
    // if statement ensures that 'T_min' doesn't integrate downwards... 
    // ... whenever der(T) is negative; 
    der(T_min) = if T < T_min then min(0, der(T)) else 0; 
end globalMinimum; 
+0

L'équation 'T_min = min (T, T_min)' ne serait-elle pas aussi travail? – Christoph

+0

@Christoph: Merci pour votre suggestion. Cependant, 'T_min' ne conserve pas la valeur minimale de' T', il suit plutôt la 'partie inférieure' de la courbe sinusoïdale (entre -amplitude et 0). –

+0

huh, curieux. Quoi qu'il en soit, un 'T_min = min (T, pre (T_min));' le fait, au moins sur ma machine avec OpenModelica. – Christoph

1

Je Je ne sais pas si la solution de Renes est optimale. La solution génère de nombreux événements d'état générés par les deux si les conditions. Intégré dans le modèle suivant:

model globalMinimum2 
Real T, T_min; 
Boolean is_true; 
initial equation 
T_min = T; 
equation 
T =time/10*sin(time); 
// if statement ensures that 'T_min' doesn't integrate downwards... 
// ... whenever der(T) is negative; 
if T < T_min then 
    der(T_min) = min(0, der(T)); 
    is_true=true; 
else 
    der(T_min) = 0; 
    is_true=false; 
end if; 
end globalMinimum2; 

Le journal de simulation est la suivante:

Integration started at T = 0 using integration method DASSL 
(DAE multi-step solver (dassl/dasslrt of Petzold modified by Dynasim)) 
Integration terminated successfully at T = 50 
    WARNING: You have many state events. It might be due to chattering. 
    Enable logging of event in Simulation/Setup/Debug/Events during simulation 
    CPU-time for integration  : 0.077 seconds 
    CPU-time for one GRID interval: 0.154 milli-seconds 
    Number of result points  : 3801 
    Number of GRID points  : 501 
    Number of (successful) steps : 2519 
    Number of F-evaluations  : 4799 
    Number of H-evaluations  : 18822 
    Number of Jacobian-evaluations: 2121 
    Number of (model) time events : 0 
    Number of (U) time events  : 0 
    Number of state events  : 1650 
    Number of step  events  : 0 
    Minimum integration stepsize : 1.44e-005 
    Maximum integration stepsize : 5.61 
    Maximum integration order  : 3 

Peut-être qu'il est préférable de détecter deux comme indiqué dans l'exemple suivant:

model unnamed_2 
    Real T; 
    Real hold; 
    Real T_min; 
    Boolean take_signal; 

initial equation 
    hold=T; 
equation 
    T = time/10*sin(time); 

    when (T < pre(hold)) then 
    take_signal = true; 
    hold = T; 
    elsewhen (der(T) >=0) then 
    take_signal = false; 
    hold = T; 
    end when; 

    if (take_signal) then 
    T_min = T; 
    else 
    T_min = hold; 
    end if; 

end unnamed_2; 

Le journal de simulation montre que cette solution est plus efficace:

Log-file of program ./dymosim 
(generated: Tue May 24 14:13:38 2016) 

dymosim started 
... "dsin.txt" loading (dymosim input file) 
... "unnamed_2.mat" creating (simulation result file) 

Integration started at T = 0 using integration method DASSL 
(DAE multi-step solver (dassl/dasslrt of Petzold modified by Dynasim)) 
Integration terminated successfully at T = 50 
    CPU-time for integration  : 0.011 seconds 
    CPU-time for one GRID interval: 0.022 milli-seconds 
    Number of result points  : 549 
    Number of GRID points  : 501 
    Number of (successful) steps : 398 
    Number of F-evaluations  : 771 
    Number of H-evaluations  : 1238 
    Number of Jacobian-evaluations: 373 
    Number of (model) time events : 0 
    Number of (U) time events  : 0 
    Number of state events  : 32 
    Number of step  events  : 0 
    Minimum integration stepsize : 4.65e-006 
    Maximum integration stepsize : 3.14 
    Maximum integration order  : 1 
Calling terminal section 
... "dsfinal.txt" creating (final states) 
+0

Merci beaucoup, Lukas. Votre code est certainement plus efficace que le mien et fonctionne très bien. Cordialement, René Just Nielsen. –