667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
|
const ColumnVector &open_switches);
EOF
;;
esac
cat <<EOF >> $filename
#endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
ColumnVector
mtt_ae (const ColumnVector &x,
const ColumnVector &u,
const double &t,
const ColumnVector &par)
{
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
return ${sys}_${ae}(x,u,t,par);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (u);
args (2) = octave_value (t);
args (3) = octave_value (par);
f = feval ("${sys}_${ae}", args, 1);
return f(0).${vector_value} ();
#endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
}
inline ColumnVector
mtt_input (const ColumnVector &x,
const ColumnVector &y,
const double &t,
const ColumnVector &par)
|
|
|
|
|
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
|
const ColumnVector &open_switches);
EOF
;;
esac
cat <<EOF >> $filename
#endif // (CODEGENTARGET != OCTAVEDLD)
ColumnVector
mtt_ae (const ColumnVector &x,
const ColumnVector &u,
const double &t,
const ColumnVector &par)
{
#if (CODEGENTARGET != OCTAVEDLD)
return ${sys}_${ae}(x,u,t,par);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (u);
args (2) = octave_value (t);
args (3) = octave_value (par);
f = feval ("${sys}_${ae}", args, 1);
return f(0).${vector_value} ();
#endif // (CODEGENTARGET != OCTAVEDLD)
}
inline ColumnVector
mtt_input (const ColumnVector &x,
const ColumnVector &y,
const double &t,
const ColumnVector &par)
|
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
|
inline ColumnVector
mtt_logic (const ColumnVector &x,
const ColumnVector &u,
const double &t,
const ColumnVector &par)
{
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
return ${sys}_logic (x, u, t, par);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (u);
args (2) = octave_value (t);
args (3) = octave_value (par);
f = feval ("${sys}_logic", args, 1);
return f(0).${vector_value} ();
#endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
}
inline ColumnVector
mtt_numpar (void)
{
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
return ${sys}_numpar ();
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
f = feval ("${sys}_numpar", args, 1);
return f(0).${vector_value} ();
#endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
}
inline ColumnVector
mtt_simpar (void)
{
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
return ${sys}_simpar ();
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
f = feval ("${sys}_simpar", args, 1);
return f(0).${vector_value} ();
#endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
}
inline ColumnVector
mtt_state (const ColumnVector &par)
{
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
return ${sys}_state (par);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (par);
f = feval ("${sys}_state", args, 1);
return f(0).${vector_value} ();
#endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
}
inline ColumnVector
mtt_rate (const ColumnVector &x,
const ColumnVector &u,
const double &t,
const ColumnVector &par)
{
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
return ${sys}_${ode} (x, u, t, par);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (u);
args (2) = octave_value (t);
args (3) = octave_value (par);
f = feval ("${sys}_${ode}", args, 1);
return f(0).${vector_value} ();
#endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
}
inline ColumnVector
mtt_output (const ColumnVector &x,
const ColumnVector &u,
const double &t,
const ColumnVector &par)
{
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
return ${sys}_${odeo} (x, u, t, par);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (u);
args (2) = octave_value (t);
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)
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
|
inline ColumnVector
mtt_logic (const ColumnVector &x,
const ColumnVector &u,
const double &t,
const ColumnVector &par)
{
#if (CODEGENTARGET != OCTAVEDLD)
return ${sys}_logic (x, u, t, par);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (u);
args (2) = octave_value (t);
args (3) = octave_value (par);
f = feval ("${sys}_logic", args, 1);
return f(0).${vector_value} ();
#endif // (CODEGENTARGET != OCTAVEDLD)
}
inline ColumnVector
mtt_numpar (void)
{
#if (CODEGENTARGET != OCTAVEDLD)
return ${sys}_numpar ();
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
f = feval ("${sys}_numpar", args, 1);
return f(0).${vector_value} ();
#endif // (CODEGENTARGET != OCTAVEDLD)
}
inline ColumnVector
mtt_simpar (void)
{
#if (CODEGENTARGET != OCTAVEDLD)
return ${sys}_simpar ();
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
f = feval ("${sys}_simpar", args, 1);
return f(0).${vector_value} ();
#endif // (CODEGENTARGET != OCTAVEDLD)
}
inline ColumnVector
mtt_state (const ColumnVector &par)
{
#if (CODEGENTARGET != OCTAVEDLD)
return ${sys}_state (par);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (par);
f = feval ("${sys}_state", args, 1);
return f(0).${vector_value} ();
#endif // (CODEGENTARGET != OCTAVEDLD)
}
inline ColumnVector
mtt_rate (const ColumnVector &x,
const ColumnVector &u,
const double &t,
const ColumnVector &par)
{
#if (CODEGENTARGET != OCTAVEDLD)
return ${sys}_${ode} (x, u, t, par);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (u);
args (2) = octave_value (t);
args (3) = octave_value (par);
f = feval ("${sys}_${ode}", args, 1);
return f(0).${vector_value} ();
#endif // (CODEGENTARGET != OCTAVEDLD)
}
inline ColumnVector
mtt_output (const ColumnVector &x,
const ColumnVector &u,
const double &t,
const ColumnVector &par)
{
#if (CODEGENTARGET != OCTAVEDLD)
return ${sys}_${odeo} (x, u, t, par);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (u);
args (2) = octave_value (t);
args (3) = octave_value (par);
f = feval ("${sys}_${odeo}", args, 1);
return f(0).${vector_value} ();
#endif // (CODEGENTARGET != OCTAVEDLD)
}
inline ColumnVector
mtt_zeroswitches (ColumnVector &x,
const int Nx,
const ColumnVector &openx)
{
|
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
|
ColumnVector &dx,
Matrix &AA,
ColumnVector &AAx,
const double &ddt,
const int &nx,
const ColumnVector &open_switches)
{
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
return Fmtt_implicit (x, dx, AA, AAx, ddt, nx, open_switches);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (dx);
args (2) = octave_value (AA);
args (3) = octave_value (AAx);
args (4) = octave_value (ddt);
args (5) = octave_value ((double)nx);
args (6) = octave_value (open_switches);
f = feval ("mtt_implicit", args, 1);
return f(0).${vector_value} ();
#endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
}
inline Matrix
mtt_smxa (const ColumnVector &x,
const ColumnVector &u,
const double &t,
const ColumnVector &par)
{
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
return ${sys}_smxa (x, u, t, par);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (u);
args (2) = octave_value (t);
args (3) = octave_value (par);
f = feval ("${sys}_smxa", args, 1);
return f(0).matrix_value ();
#endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
}
inline ColumnVector
mtt_smxax (const ColumnVector &x,
const ColumnVector &u,
const double &t,
const ColumnVector &par)
{
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
return ${sys}_smxax (x, u, t, par);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (u);
args (2) = octave_value (t);
args (3) = octave_value (par);
f = feval ("${sys}_smxax", args, 1);
return f(0).${vector_value} ();
#endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
}
EOF
;;
"dassl")
cat <<EOF >> $filename
inline ColumnVector
mtt_dassl (ColumnVector &x,
const ColumnVector &u,
const double &t,
const ColumnVector &par,
const ColumnVector &dx,
const double &ddt,
const int &nx,
const int &nyz,
const ColumnVector &open_switches)
{
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
return Fmtt_dassl (x, u, t, par, dx, ddt, nx, nyz, open_switches);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (u);
args (2) = octave_value (t);
args (3) = octave_value (par);
args (4) = octave_value (dx);
args (5) = octave_value (ddt);
args (6) = octave_value (static_cast<double> (nx));
args (7) = octave_value (static_cast<double> (nyz));
args (8) = octave_value (open_switches);
f = feval ("mtt_dassl", args, 1);
return f(0).${vector_value} ();
#endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
}
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
ColumnVector
Fmtt_residual (const ColumnVector &X,
const ColumnVector &DX,
double t,
int &ires)
{
#elif (CODEGENTARGET == OCTAVEDLD)
DEFUN_DLD (mtt_residual, args, , "mtt_residual")
{
static ColumnVector X (MTTNX+MTTNYZ);
static ColumnVector DX (MTTNX+MTTNYZ);
static double t;
static int ires;
X = args(0).${vector_value} ();
DX = args(1).${vector_value} ();
t = args(2).double_value ();
ires = static_cast<int>(args(3).double_value ());
#endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
static ColumnVector residual (MTTNX+MTTNYZ);
static ColumnVector U (MTTNU+MTTNYZ);
static ColumnVector u (MTTNU);
static ColumnVector y (MTTNY,0.0);
static ColumnVector par (MTTNPAR);
static ColumnVector dx(MTTNX);
static ColumnVector yz(MTTNYZ);
static ColumnVector x (MTTNX);
static ColumnVector ui (MTTNYZ);
static octave_value_list new_args;
x = X.extract (0,MTTNX-1);
if (MTTNYZ > 0)
ui = X.extract (MTTNX,MTTNX+MTTNYZ-1);
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
par = ${sys}_numpar();
u = ${sys}_input(x,y,t,par);
#elif (CODEGENTARGET == OCTAVEDLD)
par = feval ("${sys}_numpar", new_args, 1)(0).${vector_value} ();
new_args(0) = octave_value (x);
new_args(1) = octave_value (u);
new_args(2) = octave_value (t);
new_args(3) = octave_value (par);
u = feval ("${sys}_input", new_args, 1)(0).${vector_value} ();
#endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
U.insert (u,0);
if (MTTNYZ > 0)
U.insert (ui,MTTNU);
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
dx = ${sys}_${ode} (x,U,t,par);
yz = ${sys}_${ae} (x,U,t,par);
#elif (CODEGENTARGET == OCTAVEDLD)
new_args(1) = octave_value (U);
dx = feval ("${sys}_${ode}", new_args, 1)(0).${vector_value} ();
yz = feval ("${sys}_${ae}", new_args, 1)(0).${vector_value} ();
#endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
for (register int i = 0; i < MTTNX; i++)
residual (i) = dx(i) - DX(i);
if (MTTNYZ > 0)
{
residual.insert (yz,MTTNX);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
|
ColumnVector &dx,
Matrix &AA,
ColumnVector &AAx,
const double &ddt,
const int &nx,
const ColumnVector &open_switches)
{
#if (CODEGENTARGET != OCTAVEDLD)
return Fmtt_implicit (x, dx, AA, AAx, ddt, nx, open_switches);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (dx);
args (2) = octave_value (AA);
args (3) = octave_value (AAx);
args (4) = octave_value (ddt);
args (5) = octave_value ((double)nx);
args (6) = octave_value (open_switches);
f = feval ("mtt_implicit", args, 1);
return f(0).${vector_value} ();
#endif // (CODEGENTARGET != OCTAVEDLD)
}
inline Matrix
mtt_smxa (const ColumnVector &x,
const ColumnVector &u,
const double &t,
const ColumnVector &par)
{
#if (CODEGENTARGET != OCTAVEDLD)
return ${sys}_smxa (x, u, t, par);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (u);
args (2) = octave_value (t);
args (3) = octave_value (par);
f = feval ("${sys}_smxa", args, 1);
return f(0).matrix_value ();
#endif // (CODEGENTARGET != OCTAVEDLD)
}
inline ColumnVector
mtt_smxax (const ColumnVector &x,
const ColumnVector &u,
const double &t,
const ColumnVector &par)
{
#if (CODEGENTARGET != OCTAVEDLD)
return ${sys}_smxax (x, u, t, par);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (u);
args (2) = octave_value (t);
args (3) = octave_value (par);
f = feval ("${sys}_smxax", args, 1);
return f(0).${vector_value} ();
#endif // (CODEGENTARGET != OCTAVEDLD)
}
EOF
;;
"dassl")
cat <<EOF >> $filename
inline ColumnVector
mtt_dassl (ColumnVector &x,
const ColumnVector &u,
const double &t,
const ColumnVector &par,
const ColumnVector &dx,
const double &ddt,
const int &nx,
const int &nyz,
const ColumnVector &open_switches)
{
#if (CODEGENTARGET != OCTAVEDLD)
return Fmtt_dassl (x, u, t, par, dx, ddt, nx, nyz, open_switches);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (u);
args (2) = octave_value (t);
args (3) = octave_value (par);
args (4) = octave_value (dx);
args (5) = octave_value (ddt);
args (6) = octave_value (static_cast<double> (nx));
args (7) = octave_value (static_cast<double> (nyz));
args (8) = octave_value (open_switches);
f = feval ("mtt_dassl", args, 1);
return f(0).${vector_value} ();
#endif // (CODEGENTARGET != OCTAVEDLD)
}
#if (CODEGENTARGET != OCTAVEDLD)
ColumnVector
Fmtt_residual (const ColumnVector &X,
const ColumnVector &DX,
double t,
int &ires)
{
#elif (CODEGENTARGET == OCTAVEDLD)
DEFUN_DLD (mtt_residual, args, , "mtt_residual")
{
static ColumnVector X (MTTNX+MTTNYZ);
static ColumnVector DX (MTTNX+MTTNYZ);
static double t;
static int ires;
X = args(0).${vector_value} ();
DX = args(1).${vector_value} ();
t = args(2).double_value ();
ires = static_cast<int>(args(3).double_value ());
#endif // (CODEGENTARGET != OCTAVEDLD)
static ColumnVector residual (MTTNX+MTTNYZ);
static ColumnVector U (MTTNU+MTTNYZ);
static ColumnVector u (MTTNU);
static ColumnVector y (MTTNY,0.0);
static ColumnVector par (MTTNPAR);
static ColumnVector dx(MTTNX);
static ColumnVector yz(MTTNYZ);
static ColumnVector x (MTTNX);
static ColumnVector ui (MTTNYZ);
static octave_value_list new_args;
x = X.extract (0,MTTNX-1);
if (MTTNYZ > 0)
ui = X.extract (MTTNX,MTTNX+MTTNYZ-1);
#if (CODEGENTARGET != OCTAVEDLD)
par = ${sys}_numpar();
u = ${sys}_input(x,y,t,par);
#elif (CODEGENTARGET == OCTAVEDLD)
par = feval ("${sys}_numpar", new_args, 1)(0).${vector_value} ();
new_args(0) = octave_value (x);
new_args(1) = octave_value (u);
new_args(2) = octave_value (t);
new_args(3) = octave_value (par);
u = feval ("${sys}_input", new_args, 1)(0).${vector_value} ();
#endif // (CODEGENTARGET != OCTAVEDLD)
U.insert (u,0);
if (MTTNYZ > 0)
U.insert (ui,MTTNU);
#if (CODEGENTARGET != OCTAVEDLD)
dx = ${sys}_${ode} (x,U,t,par);
yz = ${sys}_${ae} (x,U,t,par);
#elif (CODEGENTARGET == OCTAVEDLD)
new_args(1) = octave_value (U);
dx = feval ("${sys}_${ode}", new_args, 1)(0).${vector_value} ();
yz = feval ("${sys}_${ae}", new_args, 1)(0).${vector_value} ();
#endif // (CODEGENTARGET != OCTAVEDLD)
for (register int i = 0; i < MTTNX; i++)
residual (i) = dx(i) - DX(i);
if (MTTNYZ > 0)
{
residual.insert (yz,MTTNX);
|
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
|
}
else
step = t;
for (register int i = MTTNX; i < MTTNX+MTTNYZ; i++)
residual(i) += X(i) - DX(i)*step;
}
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
return residual;
#elif (CODEGENTARGET == OCTAVEDLD)
return octave_value (residual);
#endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
}
EOF
;;
"euler" | "rk4" | *)
cat <<EOF >> $filename
inline ColumnVector
mtt_euler (ColumnVector &x,
const ColumnVector &dx,
const double &ddt,
const int &nx,
const ColumnVector &open_switches)
{
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
return Fmtt_euler (x, dx, ddt, nx, open_switches);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (dx);
args (2) = octave_value (ddt);
args (3) = octave_value ((double)nx);
args (4) = octave_value (open_switches);
f = feval ("mtt_euler", args, 1);
return f(0).${vector_value} ();
#endif // ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == MATLABMEX))
}
EOF
;;
esac
cat <<EOF >> $filename
|
|
|
|
|
|
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
|
}
else
step = t;
for (register int i = MTTNX; i < MTTNX+MTTNYZ; i++)
residual(i) += X(i) - DX(i)*step;
}
#if (CODEGENTARGET != OCTAVEDLD)
return residual;
#elif (CODEGENTARGET == OCTAVEDLD)
return octave_value (residual);
#endif // (CODEGENTARGET != OCTAVEDLD)
}
EOF
;;
"euler" | "rk4" | *)
cat <<EOF >> $filename
inline ColumnVector
mtt_euler (ColumnVector &x,
const ColumnVector &dx,
const double &ddt,
const int &nx,
const ColumnVector &open_switches)
{
#if (CODEGENTARGET != OCTAVEDLD)
return Fmtt_euler (x, dx, ddt, nx, open_switches);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (dx);
args (2) = octave_value (ddt);
args (3) = octave_value ((double)nx);
args (4) = octave_value (open_switches);
f = feval ("mtt_euler", args, 1);
return f(0).${vector_value} ();
#endif // (CODEGENTARGET != OCTAVEDLD)
}
EOF
;;
esac
cat <<EOF >> $filename
|
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
|
const double ddt = dt / stepfactor;
const int ilast = static_cast<int> (round ( last / ddt)) + 1;
const int nrows = static_cast<int> (round ((last - first) / dt)) + 1;
for (register int i = 0; i < MTTNY; i++)
{
y (i) = 0.0;
}
for (register int i = 0; i < MTTNX; i++)
{
x (i) = state0 (i);
}
for (register int j = 0, i = 1; i <= ilast; i++)
{
u = mtt_input (x, y, t, par);
y = mtt_output (x, u, t, par);
if (0 == j)
{
mtt_write (t, x, y, first, nrows);
}
EOF
case "$method" in
"rk4")
cat << EOF >> $filename
{
static ColumnVector
|
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
|
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
|
const double ddt = dt / stepfactor;
const int ilast = static_cast<int> (round ( last / ddt)) + 1;
const int nrows = static_cast<int> (round ((last - first) / dt)) + 1;
for (register int i = 0; i < MTTNY; i++)
{
y (i) = 0.0;
#if (CODEGENTARGET == RTXI)
output(i) = y(i);
#endif // (CODEGENTARGET == RTXI)
}
for (register int i = 0; i < MTTNX; i++)
{
x (i) = state0 (i);
}
for (register int j = 0, i = 1; i <= ilast; i++)
{
#if (CODEGENTARGET != RTXI)
u = mtt_input (x, y, t, par);
#else
for (register int i = 0; i < MTTNU; i++) {
u(i) = input(i);
}
#endif // (CODEGENTARGET != RTXI)
y = mtt_output (x, u, t, par);
if (0 == j)
{
#if (CODEGENTARGET != RTXI)
mtt_write (t, x, y, first, nrows);
#else
for (register int i = 0; i < MTTNU; i++) {
output(i) = y(i);
}
#endif // (CODEGENTARGET != RTXI)
}
EOF
case "$method" in
"rk4")
cat << EOF >> $filename
{
static ColumnVector
|