File mttroot/mtt/bin/trans/cse2ode_r artifact 280cac859b part of check-in be739f082c


#! /bin/sh

     ###################################### 
     ##### Model Transformation Tools #####
     ######################################

# Bourne shell script: cse2ode_r
# Reduce constrained-state equations to ode.
# P.J.Gawthrop 10th May 199, 8th August 1991, April 1994, Dec 1994
# Copyright (c) P.J.Gawthrop, 1991, 1994.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.3.4.2  2002/09/10 23:24:19  geraint
## Rationalised local and global optimisations.
## Fixes presentation of locally optimised code (ode view).
## Much more elegant :-)
##
## Revision 1.3.4.1  2002/09/03 23:44:43  geraint
## adding global optimisation (-optg).
##
## Revision 1.3  2001/07/27 23:29:10  geraint
## Optimises only when requested (-opt).
##
## Revision 1.2  2001/07/13 04:54:04  geraint
## Branch merge: numerical-algebraic-solution back to main.
##
## Revision 1.1.4.1  2001/05/04 04:07:24  geraint
## Numerical solution of algebraic equations.
## sys_ae.cc written for unsolved inputs.
## Solution of equations using hybrd from MINPACK (as used by Octave fsolve).
##
## Revision 1.1  2000/12/28 12:21:31  peterg
## Put under RCS
##
## Revision 1.2  1997/01/06 21:17:10  peterg
## Removed:  OFF Exp; OFF GCD;
##
## Revision 1.1  1996/08/25 10:05:45  peter
## Initial revision
##
###############################################################

optimise=''; optimise_msg=''
while [ -n "`echo $1 | grep '^-'`" ]; do
    case $1 in
	-optimise_global )
	    optimise='-optimise_global'
	    optimise_msg=' with global optimisation' ;;
	-optimise_local )
	    optimise='-optimise_local'
	    optimise_msg=' with local optimisation' ;;
	*)
	    echo "$1 is an invalid argument - ignoring" ;;
    esac
    shift
done

# Create the reduce output code
def2write_r $1 ode
def2write_r $1 odeo

#Inform user
echo Creating $1_ode.r $optimise_msg
echo Creating $1_odeo.r $optimise_msg

# Remove the old log file
rm -f cse2ode_r.log

# Use reduce to accomplish the transformation
$SYMBOLIC >cse2ode_r.log << EOF

%Read the formatting function
in "$MTTPATH/trans/reduce_matrix.r";

%Read the definitions file
in "$1_def.r";

%Read the substitution file
in "$1_subs.r";

%Read the constrained-state equations file
in "$1_cse.r";

%Read the algebraic equations file
in "$1_ae.r";

IF MTTNx>0 THEN
 IF MTTNz>0 THEN
   MTTdXX := MTTE^(-1)*MTTEdX
 ELSE
   MTTdXX := MTTEdX;

%Remove all dX terms from y - a rather nasty method, sorry!
  MTTdX1 := 0;
  MTTdX2 := 0;
  MTTdX3 := 0;
  MTTdX4 := 0;
  MTTdX5 := 0;
  MTTdX6 := 0;
  MTTdX7 := 0;
  MTTdX8 := 0;
  MTTdX9 := 0;
  MTTdX10 := 0;
  MTTdX11 := 0;
  MTTdX12 := 0;
  MTTdX13 := 0;
  MTTdX14 := 0;
  MTTdX15 := 0;
  MTTdX16 := 0;
  MTTdX17 := 0;
  MTTdX18 := 0;
  MTTdX19 := 0;
  MTTdX20 := 0;

%Substitute  dX into y;
IF MTTNz>0 THEN
  IF MTTNx>0 THEN
    MTTY := MTTY + MTTEyx*MTTdX;

OFF Echo;
OFF Nat;

MTTdX := MTTdXX;

%Write out the  ordinary differential equations.
OUT "$1_ode.r";
write "%File: $1_ode.r";
in ("$1_ode_write.r");
write "in ""$1_odeo.r"";";
write "END;";
SHUT "$1_ode.r";

%Write out the  output equations
OUT "$1_odeo.r";
write "%File: $1_odeo.r";
in ("$1_odeo_write.r");
write "END;";
SHUT "$1_odeo.r";
quit;
EOF

if [ ${optimise:-""} = "-optimise_global" ]; then
    mtt_optimise global $1 ode
    mtt_optimise global $1 odeo
elif [ ${optimise:-""} = "-optimise_local" ]; then
    mtt_optimise local $1 ode
    mtt_optimise local $1 odeo
fi

# Now invoke the standard error handling.
mtt_error_r cse2ode_r.log


MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]