ADDED mttroot/mtt/bin/trans/m/mtt_zeroswitches.m Index: mttroot/mtt/bin/trans/m/mtt_zeroswitches.m ================================================================== --- mttroot/mtt/bin/trans/m/mtt_zeroswitches.m +++ mttroot/mtt/bin/trans/m/mtt_zeroswitches.m @@ -0,0 +1,4 @@ +function [x] = mtt_zeroswitches(x,Nx,open) + I_open = nozeros(open.*[1:Nx]'); # Indices of open switches + x(I_open) = 0.0; # Open switches have zero states +endfunction; Index: mttroot/mtt/bin/trans/make_ode2odes ================================================================== --- mttroot/mtt/bin/trans/make_ode2odes +++ mttroot/mtt/bin/trans/make_ode2odes @@ -7,10 +7,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.89 2004/08/29 16:04:44 geraint +## Fixed ae for non-sorted code. +## ## Revision 1.88 2004/08/29 13:15:28 geraint ## Uses sys_sae instead of sys_ae if sorted equations are being used. ## ## Revision 1.87 2004/08/29 01:46:56 geraint ## Added rules to create ode2odes for sorted system: sesx and sesy. @@ -510,10 +513,12 @@ fi cat <> $filename [open_switches] = ${sys}_logic(x,u,t,par); # Switch logic [x] = $algorithm; # Integration update + [open_switches] = ${sys}_logic(x,u,t,par); # Switch logic + [x] = mtt_zeroswitches(x,$Nx,open_switches); t = t + ddt; # Time update mttj = mttj+1; # Increment counter if mttj==simpar.stepfactor mttj = 0; # Reset counter endif @@ -808,10 +813,24 @@ args (3) = octave_value (par); f = feval ("${sys}_${odeo}", args, 1); return f(0).${vector_value} (); #endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX)) } + +inline ColumnVector +mtt_zeroswitches (ColumnVector &x, + const int Nx, + const ColumnVector &openx) +{ + for (register int i = 0; i < Nx; i++) { + if (0 != openx (i)) { + x(i) = 0.0; + } + } + return x; +} + EOF case "$method" in "implicit") cat <> $filename @@ -1196,10 +1215,12 @@ ## Common stuff cat <> $filename open_switches = mtt_logic (x, u, t, par); x = $algorithm; + open_switches = mtt_logic (x, u, t, par); + x = mtt_zeroswitches (x, $Nx, open_switches); t += ddt; j++; j = (j == static_cast (stepfactor)) ? 0 : j; }