#*------------------------------------------------------------------- * EMSO Model Library (EML) Copyright (C) 2004 - 2007 ALSOC. * * This LIBRARY is free software; you can distribute it and/or modify * it under the therms of the ALSOC FREE LICENSE as available at * http://www.enq.ufrgs.br/alsoc. * * EMSO is distributed under the terms of the ALSOC LICENSE as * available at http://www.enq.ufrgs.br/alsoc. *----------------------------------------------------------------------- * Adapted by: Jonathan Ospino P. * $Id: TimeDelay.mso 2012$ *---------------------------------------------------------------------*# using "types"; Model TimeDelay ATTRIBUTES Pallete=true; Icon="icon/TimeDelay"; Info="== Time Delay block == It delays the value of the input signal t0 units to the right with respect to the time. The resulting value is assigned to the output variable. ****************** How does it work? *********************** The model uses the <> and <> cases (see Quinto et. al,2009) and it solves them simultaneously. Finally, the output value is seleceted depending on whether or not the user specified a filter. ***************************************************************"; PARAMETERS t0 as Real(Brief="Time Delay value",Default=0,Unit='s'); N as Integer(Brief="Number of elements (1<=N<=100)", Lower=1, Upper=100, Default=100); Ntank as Integer(Brief="Number of tanks to be Used with the series of tanks (1<=N<=2000)", Lower=1, Upper=2000, Default=2000); Approach as Switcher(Brief="HINT: Use a filter just when...",Valid=["Tank series","Discretized","Discretized+filter","Capacitive series"],Default="Discretized"); alfa as Real(Brief="Unfiltered fraction",Default=0.94); a(3,3) as Real(Brief="Parameters used on the 2nd-Order approaches",Hidden=true); VARIABLES in In as Real(PosX=0,PosY=0.5,Protected=true); out Out as Real(PosX=1,PosY=0.5,Protected=true); x1(2*N+1) as Real(Hidden=true); # States for the 2nd-Order + FE approach(Discretized Model) x2(2*N+2) as Real(Hidden=true); # States for the 2nd-Order + FE + Filter approach (Discretized Model + Filter) x3(Ntank) as Real(Hidden=true); # States for the tank delay approach x4(3*N+1) as Real(Hidden=true); # States for the 2nd-Order + Filters + FE approach (Capacitive series) y1 as Real(Hidden=true); # Tentative store for the Output variable when 2nd-Order + FE approach y2 as Real(Hidden=true); # Tentative store for the Output variable when 2nd-Order + FE + Filter approach y3 as Real(Hidden=true); # Tentative store for the Output variable when tank delay approach y4 as Real(Hidden=true); # Tentative store for the Output variable when 2nd-Order + Filters + FE approach SET a(1,1:3)=[2, -1.5, -0.5]; a(2,1:3)=[-2, 4.5, -2.5]; a(3,1:3)=[0, 1, -1]; EQUATIONS #* The following IF-ELSE sentence assures that user can deactivate the action of the time delay block over its input signal by just setting t0 to 0. So, there are two posibilities: t>0 and t0=0. (1) t0>0 -> The block applies the time delay approach developed by (Quinto et al.,2009) considering the application or not of a capacitive filter. (2) t0=0 -> Since the previous case produces singularity problems when applied with t0=0, then an alternative path must be set in the current algorithm to success. *# if t0>0*'s' then # 2nd-Order + FE approach (Discretized Model) x1(1)=In; for i in [2:2:2*N] do t0*diff(x1(i))=N*(a(1,1)*x1(i-1)+a(1,2)*x1(i)+a(1,3)*x1(i+1)); t0*diff(x1(i+1))=N*(a(2,1)*x1(i-1)+a(2,2)*x1(i)+a(2,3)*x1(i+1)); end y1=x1(2*N+1); # 2nd-Order + FE + Filter approach (Discretized Model+Filter) x2(1)=In; for i in [2:2:2*N] do alfa*t0*diff(x2(i))=N*(a(1,1)*x2(i-1)+a(1,2)*x2(i)+a(1,3)*x2(i+1)); alfa*t0*diff(x2(i+1))=N*(a(2,1)*x2(i-1)+a(2,2)*x2(i)+a(2,3)*x2(i+1)); end (1-alfa)*t0*diff(x2(2*N+2)) = N*(x2(2*N+1)-x2(2*N+2)); y2=x2(2*N+2); # Tank series approach (t0/Ntank)*diff(x3(1))=In-x3(1); for i in [2:Ntank] do (t0/Ntank)*diff(x3(i))=x3(i-1)-x3(i); end y3=x3(Ntank); # 2nd-Order + Filters +FE approach (Capacitive series) x4(1) = In; for i in [2:3:3*N-1] do t0*diff(x4(i)) = 2*N*(a(1,1)*x4(i-1)+a(1,2)*x4(i)+a(1,3)*x4(i+1)); t0*diff(x4(i+1)) = 2*N*(a(2,1)*x4(i-1)+a(2,2)*x4(i)+a(2,3)*x4(i+1)); t0*diff(x4(i+2)) = 2*N*(a(3,2)*x4(i+1)+a(3,3)*x4(i+2)); end y4 = x4(3*N+1); else # 2nd-Order + FE approach (Discretized Model) x1(1)=In; for i in [2:2:2*N] do diff(x1(i))=0*'1/s'; diff(x1(i+1))=0*'1/s'; end y1=0; # 2nd-Order + FE + Filter approach (Discretized Model + Filter) x2(1)=In; for i in [2:2:2*N] do alfa*diff(x2(i))=0*'1/s'; alfa*diff(x2(i+1))=0*'1/s'; end (1-alfa)*diff(x2(2*N+2))=0*'1/s'; y2=0; # Tank series approach (t0/Ntank)*diff(x3(1))=0; for i in [2:Ntank] do (t0/Ntank)*diff(x3(i))=0; end y3=0; # 2nd-Order + Filters +FE approach (Capacitive series) x4(1) = In; for i in [2:3:3*N-1] do t0*diff(x4(i)) = 0; t0*diff(x4(i+1)) = 0; t0*diff(x4(i+2)) = 0; end y4 = 0; end if t0>0*'s' then switch Approach case "Discretized": Out=y1; case "Discretized+filter": Out=y2; case "Tank series": Out=y3; case "Capacitive series": Out=y4; end else switch Approach case "Discretized": Out=In; case "Discretized+filter": Out=In; case "Tank series": Out=In; case "Capacitive series": Out=In; end end INITIAL x1(2:2*N+1) = 0; x2(2:2*N+2) = 0; x3=0; x4(2:3*N+1) = 0; end #* FINAL REMARKS ------------- The following paragraphs show some remarks about the implementation of the the models included in the Quinto et al.'s file, so: A. Higher-Order Padé -------------------- This model was not implemented because it show many oscillations, even for the higher possible value. B. 2nd-Order Finite-Elements Approximation (2nd-Order + FE) ----------------------------------------------------------- This model did show very good results for N near to 100. C. 2nd-Order Finite-Elements Approximation with Filter (2nd-Order + FE + Filter) -------------------------------------------------------------------------------- This model did show very good results for N near to 100. D. 2nd-Order plus Filters Finite-Elements Approximation (2nd-Order + Filters + FE) ---------------------------------------------------------------------------------- This model did show very good results for N near to 100. E. Series of tanks Approximation (Tanks series) ----------------------------------------------- This model did show very good results for N near to 100. *#