1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#! /bin/sh
######################################
##### Model Transformation Tools #####
######################################
###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.73 2002/05/01 12:24:41 geraint
## Removed unnecessary inclusion of load-save.h.
##
## Revision 1.72 2002/05/01 12:21:29 geraint
## No longer uses save_ascii_data_for_plotting function to write data
## - eliminates dependence on liboctinterp (and libncurses) for .cc.
##
|
>
>
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#! /bin/sh
######################################
##### Model Transformation Tools #####
######################################
###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.74 2002/05/01 17:30:56 geraint
## Improved pre-processor directives to better accommodate future alternatives (matlab)
## if necessary.
##
## Revision 1.73 2002/05/01 12:24:41 geraint
## Removed unnecessary inclusion of load-save.h.
##
## Revision 1.72 2002/05/01 12:21:29 geraint
## No longer uses save_ascii_data_for_plotting function to write data
## - eliminates dependence on liboctinterp (and libncurses) for .cc.
##
|
︙ | | | ︙ | |
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
#include "mtt_${algebraic_solver}.hh"
#include <fstream>
#if (CODEGENTARGET == STANDALONE)
#include <csignal>
extern ColumnVector F${sys}_ae (
ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par);
extern ColumnVector F${sys}_input (
ColumnVector &x,
ColumnVector &y,
const double &t,
ColumnVector &par);
extern ColumnVector F${sys}_logic (
ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par);
extern ColumnVector F${sys}_numpar (
void);
extern ColumnVector F${sys}_simpar (
void);
extern ColumnVector F${sys}_state (
ColumnVector &par);
extern ColumnVector F${sys}_${ode} (
ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par);
extern ColumnVector F${sys}_${odeo} (
ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par);
EOF
case "$method" in
"implicit")
cat <<EOF >> $filename
extern ColumnVector Fmtt_implicit (
ColumnVector &x,
ColumnVector &dx,
Matrix &AA,
ColumnVector &AAx,
const double &ddt,
const int &nx,
const ColumnVector &open_switches);
extern Matrix F${sys}_smxa (
ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par);
extern ColumnVector F${sys}_smxax (
ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par);
EOF
;;
|
|
|
|
|
|
|
|
|
|
|
|
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
|
#include "mtt_${algebraic_solver}.hh"
#include <fstream>
#if (CODEGENTARGET == STANDALONE)
#include <csignal>
extern ColumnVector ${sys}_ae (
ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par);
extern ColumnVector ${sys}_input (
ColumnVector &x,
ColumnVector &y,
const double &t,
ColumnVector &par);
extern ColumnVector ${sys}_logic (
ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par);
extern ColumnVector ${sys}_numpar (
void);
extern ColumnVector ${sys}_simpar (
void);
extern ColumnVector ${sys}_state (
ColumnVector &par);
extern ColumnVector ${sys}_${ode} (
ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par);
extern ColumnVector ${sys}_${odeo} (
ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par);
EOF
case "$method" in
"implicit")
cat <<EOF >> $filename
extern ColumnVector Fmtt_implicit (
ColumnVector &x,
ColumnVector &dx,
Matrix &AA,
ColumnVector &AAx,
const double &ddt,
const int &nx,
const ColumnVector &open_switches);
extern Matrix ${sys}_smxa (
ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par);
extern ColumnVector ${sys}_smxax (
ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par);
EOF
;;
|
︙ | | | ︙ | |
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
|
ColumnVector
mtt_ae (ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par)
{
#if (CODEGENTARGET == STANDALONE)
return F${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);
|
|
|
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
|
ColumnVector
mtt_ae (ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par)
{
#if (CODEGENTARGET == STANDALONE)
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);
|
︙ | | | ︙ | |
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
|
const double &t,
ColumnVector &par)
{
static MTT::${algebraic_solver} ae(MTTNPAR,MTTNU,MTTNX,MTTNY,MTTNYZ);
static ColumnVector u (MTTNU);
#if (CODEGENTARGET == STANDALONE)
u = F${sys}_input (x, y, t, par);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (y);
args (2) = octave_value (t);
args (3) = octave_value (par);
f = feval ("${sys}_input", args, 1);
|
|
|
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
|
const double &t,
ColumnVector &par)
{
static MTT::${algebraic_solver} ae(MTTNPAR,MTTNU,MTTNX,MTTNY,MTTNYZ);
static ColumnVector u (MTTNU);
#if (CODEGENTARGET == STANDALONE)
u = ${sys}_input (x, y, t, par);
#elif (CODEGENTARGET == OCTAVEDLD)
static octave_value_list args, f;
args (0) = octave_value (x);
args (1) = octave_value (y);
args (2) = octave_value (t);
args (3) = octave_value (par);
f = feval ("${sys}_input", args, 1);
|
︙ | | | ︙ | |
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
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
|
inline ColumnVector
mtt_logic (ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par)
{
#if (CODEGENTARGET == STANDALONE)
return F${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)
}
inline ColumnVector
mtt_numpar (void)
{
#if (CODEGENTARGET == STANDALONE)
return F${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)
}
inline ColumnVector
mtt_simpar (void)
{
#if (CODEGENTARGET == STANDALONE)
return F${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)
}
inline ColumnVector
mtt_state (ColumnVector &par)
{
#if (CODEGENTARGET == STANDALONE)
return F${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)
}
inline ColumnVector
mtt_rate (ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par)
{
#if (CODEGENTARGET == STANDALONE)
return F${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)
}
inline ColumnVector
mtt_output (ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par)
{
#if (CODEGENTARGET == STANDALONE)
return F${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);
|
|
|
|
|
|
|
|
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
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
|
inline ColumnVector
mtt_logic (ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par)
{
#if (CODEGENTARGET == STANDALONE)
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)
}
inline ColumnVector
mtt_numpar (void)
{
#if (CODEGENTARGET == STANDALONE)
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)
}
inline ColumnVector
mtt_simpar (void)
{
#if (CODEGENTARGET == STANDALONE)
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)
}
inline ColumnVector
mtt_state (ColumnVector &par)
{
#if (CODEGENTARGET == STANDALONE)
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)
}
inline ColumnVector
mtt_rate (ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par)
{
#if (CODEGENTARGET == STANDALONE)
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)
}
inline ColumnVector
mtt_output (ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par)
{
#if (CODEGENTARGET == STANDALONE)
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);
|
︙ | | | ︙ | |
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
|
inline Matrix
mtt_smxa (ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par)
{
#if (CODEGENTARGET == STANDALONE)
return F${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)
}
inline ColumnVector
mtt_smxax (ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par)
{
#if (CODEGENTARGET == STANDALONE)
return F${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);
|
|
|
|
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
|
inline Matrix
mtt_smxa (ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par)
{
#if (CODEGENTARGET == STANDALONE)
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)
}
inline ColumnVector
mtt_smxax (ColumnVector &x,
ColumnVector &u,
const double &t,
ColumnVector &par)
{
#if (CODEGENTARGET == STANDALONE)
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);
|
︙ | | | ︙ | |
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
|
f = feval ("mtt_dassl", args, 1);
return f(0).${vector_value} ();
#endif // (CODEGENTARGET == STANDALONE)
}
#if (CODEGENTARGET == STANDALONE)
ColumnVector
Fmtt_residual (const ColumnVector &X,
const ColumnVector &DX,
double t,
int &ires)
{
#elif (CODEGENTARGET == OCTAVEDLD)
DEFUN_DLD (mtt_residual, args, , "mtt_residual")
{
|
|
|
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
|
f = feval ("mtt_dassl", args, 1);
return f(0).${vector_value} ();
#endif // (CODEGENTARGET == STANDALONE)
}
#if (CODEGENTARGET == STANDALONE)
ColumnVector
mtt_residual (const ColumnVector &X,
const ColumnVector &DX,
double t,
int &ires)
{
#elif (CODEGENTARGET == OCTAVEDLD)
DEFUN_DLD (mtt_residual, args, , "mtt_residual")
{
|
︙ | | | ︙ | |
832
833
834
835
836
837
838
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
|
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)
par = F${sys}_numpar();
u = F${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)
U.insert (u,0);
if (MTTNYZ > 0)
U.insert (ui,MTTNU);
#if (CODEGENTARGET == STANDALONE)
dx = F${sys}_${ode} (x,U,t,par);
yz = F${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)
for (register int i = 0; i < MTTNX; i++)
|
|
|
|
|
|
836
837
838
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
|
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)
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)
U.insert (u,0);
if (MTTNYZ > 0)
U.insert (ui,MTTNU);
#if (CODEGENTARGET == STANDALONE)
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)
for (register int i = 0; i < MTTNX; i++)
|
︙ | | | ︙ | |