Index: mttroot/mtt/bin/trans/dae_r2m ================================================================== --- mttroot/mtt/bin/trans/dae_r2m +++ mttroot/mtt/bin/trans/dae_r2m @@ -3,19 +3,22 @@ ###################################### ##### Model Transformation Tools ##### ###################################### # Bourne shell script: dae_r2m -# Reduce DAE to simulab DAE -# P.J.Gawthrop 14 June 1991, 12 Jan 1994, April 1994, Jan 95. +# Reduce DAE to OCTAVE (DASSL) DAE +# P.J.Gawthrop 14 June 1991, 12 Jan 1994, April 1994, Jan 95, Aug 97. # Copyright (c) P.J.Gawthrop 1991, 1994, 1995, 1996 ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +# Revision 1.6 1997/08/28 14:07:16 peterg +# Changed MTTDx to MTTDeriv +# # Revision 1.5 1996/08/24 14:27:29 peter # Global parameters. # ## Revision 1.4 1996/08/18 20:02:21 peter ## Include zero outputs. @@ -42,73 +45,75 @@ echo Creating $1_daeo.m # Remove the old log file rm -f dae_r2m.log + +# Remove temp. files +rm -f $1_dae.m? +rm -f $1_daeo.m? # Use reduce to accomplish the transformation -reduce >dae_r2m.log << EOF +$SYMBOLIC >dae_r2m.log << EOF %Read the reduce definitions file in "$1_def.r"; %Read the reduce DAE file in "$1_dae.r"; +% Matrix output function +in"$MTTPATH/trans/matlab_matrix.r"; + %Set up the number of argument variables to zero in case the user has forgotten MTTNVar := 0; %Read the parameter file -in "$1_sympar.r"; +%%in "$1_sympar.r"; -ON NERO; % Suppress zero elements +%% ON NERO; % Suppress zero elements %Define the common part of the functions. PROCEDURE common; BEGIN - IF MTTNvar>0 THEN - BEGIN - write "% Set the parameters"; - write "global ...;;"; - FOR i := 1:MTTNvar DO - BEGIN - IF i0 THEN FOR i := 1:MTTNu DO BEGIN - write "MTTu", i, " = u(", i, ");"; + write "mttu", i, " = u(", i, ");"; END; END; % Firstly do the residual = f(dx,x,t) function. @@ -133,83 +138,167 @@ FOR i := 1:MTTNz DO MTTGu(i,j) := df(MTTZ(i,1), uj, 1); END; END; -OUT "$1_dae.m"; -write "function residual = $1_dae(mttderiv0,mttx,t);"; +IF MTTNz=0 THEN +BEGIN + MTTGx := 0; + MTTGu := 0; + MTTz := 0; +END; + +OUT "$1_dae.m1"; +write "function residual = $1_dae(mttx,deriv0,t);"; write "% residuals = $1_dae(dx,x,t);"; write "%DAE in DASSL $1;;"; write "%File $1_dae.m;;"; write "%Generated by MTT;;"; common(); - write "% Set up the non-state derivatives"; - FOR i := 1:MTTNz DO - BEGIN - write "mttdz", i, " = mttderiv0(", MTTNx+ i, ");"; - END; - - -%Fortran switches - one line expressions -OFF echo; -ON fort$ -cardno!* := 1$ -fortwidth!* := 100$ -OFF period$ - - -Mttderiv := MTTdX; - -IF MTTNz>0 THEN - MTTGx := MTTGx; - -OFF fort; - -write "for i=1:", MTTNx, ";;"; -write " residual(i) = mttderiv(i)-mttderiv0(i);"; -write "end;"; - -IF MTTNz>0 THEN -BEGIN - write "dxz = MTTGx*Mttderiv"; - write "for i=1:", MTTNz, ";;"; - write " residual(i+", MTTNx, ") = dxz(i)-mttderiv0(i+", MTTNx,");"; - write "end;"; -END; - - - -SHUT "$1_dae.m"; - -OFF fort; - -% Now do the y = g(x,t) function. -OUT "$1_daeo.m"; - -write "function MTTy = $1_daeo(MTTx,t);"; -write "% dX = $1_daeo(MTTx,t);"; -write "%DAE in Simulab form for system $1;;"; -write "%File $1_daeo.m;;"; -write "%Generated by MTT;;"; - -common(); - -%Fortran switches - one line expressions -OFF echo; -ON fort$ -cardno!* := 1$ -fortwidth!* := 100$ -OFF period$ - -MTTy := MTTy; - -SHUT "$1_daeo.m"; - +SHUT "$1_dae.m1"; + +GENTRANOUT "$1_dae.m3"; +write "% State derivative"; +IF MTTNX>0 THEN +BEGIN + MTT_Matrix := MTTdX$ + MTT_Matrix_name := "deriv"$ + MTT_Matrix_n := MTTNx$ + MTT_Matrix_m := 1$ + matlab_Matrix()$ + GENTRAN deriv := mtt_matrix$ +END; + +IF MTTNYz>0 THEN +BEGIN + MTT_Matrix := MTTYz$ + MTT_Matrix_name := "MTTYz"$ + MTT_Matrix_n := MTTNYz$ + MTT_Matrix_m := 1$ + matlab_Matrix()$ + GENTRAN MTTYz := mtt_matrix$ +END; + +if MTTNz>0 THEN +BEGIN + MTT_Matrix := MTTz$ + MTT_Matrix_name := "MTTz"$ + MTT_Matrix_n := MTTNz$ + MTT_Matrix_m := 1$ + matlab_Matrix()$ + GENTRAN MTTz := mtt_matrix$ + + MTT_Matrix := MTTGu$ + MTT_Matrix_name := "MTTGu"$ + MTT_Matrix_n := MTTNz$ + MTT_Matrix_m := 1$ + matlab_Matrix()$ + GENTRAN MTTGu := mtt_matrix$ + + MTT_Matrix := MTTGu$ + MTT_Matrix_name := "MTTGx"$ + MTT_Matrix_n := MTTNz$ + MTT_Matrix_m := 1$ + matlab_Matrix()$ + GENTRAN MTTGx := mtt_matrix$ + +END; + + +SHUT "$1_dae.m3"; + +OUT "$1_dae.m4"; +% write "% Set up the non-state derivatives"; +% FOR i := 1:MTTNz DO +% write "mttdz", i, " = mttderiv0(", MTTNx+ i, ");"; +% END; + +write "j = 0;"; + +%Residual has 3 parts as follows: +%Part 1: dx/dt - dx_0/dt +if MTTNx>0 THEN +BEGIN + write "for i=1:", MTTNx, ";;"; + write " j = j+1"; + write " residual(j) = deriv(i)-deriv0(j);"; + write "end;"; +END; + +%Part 2: dz/dt - dz_0/dt +IF MTTNz>0 THEN +BEGIN + if MTTNx>0 THEN + write "mttdzx = mttgx*mttdx" + ELSE + write "mttdzx = zeros(", MTTNz, ",1);"; + + + if MTTNu>0 THEN + write "mttdzu = mttgu*mttdu" + ELSE + write "mttdzu = zeros(", MTTNz, ",1);"; + + write "mttdz = mttdzx + mttdzu"; + + write "for i=1:", MTTNz, ";;"; + write " j = j+1"; + write " residual(j) = mttdz(i)-mttderiv0(j);"; + write "end;"; +END; + +%Part 3: v=0 (the algebraic bits) +IF MTTNyz>0 THEN +BEGIN + write "for i=1:", MTTNyz, ";;"; + write " j = j+1"; + write " residual(j) = mttyz(i)"; + write "end;"; +END; + +SHUT "$1_dae.m4"; + + +% Now do the y = g(x,t) function. +OUT "$1_daeo.m1"; + +write "function mtty = $1_daeo(mttx,t);"; +write "% mtty = $1_daeo(mttx,t);"; +write "%DAE in Simulab form for system $1;;"; +write "%File $1_daeo.m;;"; +write "%Generated by MTT;;"; + +SHUT "$1_daeo.m1"; + +OUT "$1_daeo.m3"; +common(); + + +%Fortran switches - one line expressions +OFF echo; +ON fort$ +cardno!* := 1$ +fortwidth!* := 500$ +OFF period$ + +MTTy := MTTy; + +SHUT "$1_daeo.m3"; + +EOF + +# Create the globals +sympar2global_txt2m $1> $1_dae.m2 +sympar2global_txt2m $1> $1_daeo.m2 + +# Put together the pieces +cat $1_dae.m?>$1_dae.m +cat $1_daeo.m?>$1_daeo.m