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.56 2001/03/30 15:13:58 gawthrop
## Rationalised simulation modes to each return mtt_data
##
## Revision 1.55 2001/03/27 13:21:59 geraint
## Octave version compatibility for save_ascii_data(_for_plotting).
##
## Revision 1.54 2001/03/27 01:14:27 geraint
|
>
>
>
>
|
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.57 2001/04/01 03:38:54 geraint
## Reset row to zero after write to file, ready for subsequent runs.
## Eliminates SIGSEGV in Octave when _ode2odes called multiple times.
##
## Revision 1.56 2001/03/30 15:13:58 gawthrop
## Rationalised simulation modes to each return mtt_data
##
## Revision 1.55 2001/03/27 13:21:59 geraint
## Octave version compatibility for save_ascii_data(_for_plotting).
##
## Revision 1.54 2001/03/27 01:14:27 geraint
|
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
feval_header=parse.h
save_ascii_data_function=save_ascii_data_for_plotting
;;
esac
cat <<EOF > $filename
#include <octave/oct.h>
#include <octave/ov-struct.h>
#include <octave/load-save.h>
#include <octave/lo-mappers.h>
#include <octave/variables.h>
#ifndef STANDALONE
#include <octave/${feval_header}>
#endif
#include "${sys}_def.h"
#include "${sys}_sympar.h"
#ifdef STANDALONE
#include <csignal>
#include <fstream>
extern ColumnVector F${sys}_input (
ColumnVector &x,
ColumnVector &y,
const double &t,
ColumnVector &par);
|
|
|
|
>
>
>
>
>
>
>
|
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
feval_header=parse.h
save_ascii_data_function=save_ascii_data_for_plotting
;;
esac
cat <<EOF > $filename
#include <octave/oct.h>
#include <octave/load-save.h>
#include <octave/lo-mappers.h>
#include <octave/NLEqn.h>
#include <octave/ov-struct.h>
#include <octave/variables.h>
#ifndef STANDALONE
#include <octave/${feval_header}>
#endif
#include "${sys}_def.h"
#include "${sys}_sympar.h"
#ifdef STANDALONE
#include <csignal>
#include <fstream>
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);
|
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
ColumnVector &u,
const double &t,
ColumnVector &par);
EOF
fi
cat <<EOF >> $filename
#endif // STANDALONE
inline ColumnVector
mtt_input (ColumnVector &x,
ColumnVector &y,
const double &t,
ColumnVector &par)
{
#ifdef STANDALONE
return F${sys}_input (x, y, t, par);
#else
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);
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
|
437
438
439
440
441
442
443
444
445
446
447
448
449
450
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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
|
ColumnVector &u,
const double &t,
ColumnVector &par);
EOF
fi
cat <<EOF >> $filename
void set_signal_handlers (void);
#endif // STANDALONE
class Solver
{
public:
Solver (void) {
solve_errors.input = 0;
solve_errors.user = 0;
solve_errors.converge = 0;
solve_errors.progress = 0;
solve_errors.limit = 0;
solve_errors.unknown = 0;
}
ColumnVector solve (const ColumnVector &x,
const ColumnVector &u,
const double &t,
const ColumnVector &par)
{
initialise(x,u,t,par);
NLFunc fcn(&Solver::evaluate);
NLEqn eqn(Ui,fcn);
Ui = eqn.solve(info);
switch (info)
{
case -2:
solve_errors.input++;
write_stats();
break;
case -1:
solve_errors.user++;
write_stats();
break;
case 1:
solve_errors.converge++;
break;
case 3:
solve_errors.progress++;
write_stats();
break;
case 4:
solve_errors.limit++;
write_stats();
break;
default:
solve_errors.unknown++;
write_stats();
break;;
}
U.insert (Ui,MTTNU);
return U;
}
void write_stats (void)
{
cerr << "input error (" << solve_errors.input << ") "
<< ", user (" << solve_errors.user << ") "
<< ", converge (" << solve_errors.converge << ") "
<< ", progress (" << solve_errors.progress << ") "
<< ", limit (" << solve_errors.limit << ") "
<< ", unknown (" << solve_errors.unknown << ") "
<< endl;
}
private:
static ColumnVector evaluate (const ColumnVector &tryUi)
{
U.insert(tryUi,MTTNU);
return F${sys}_ae(X,U,T,P);
}
void initialise (const ColumnVector &x,
const ColumnVector &u,
const double &t,
const ColumnVector &par)
{
X = x;
T = t;
P = par;
U.insert(u,0);
Ui = ColumnVector(MTTNYZ,0.0);
}
private:
struct {
long int input;
long int user;
long int converge;
long int progress;
long int limit;
long int unknown;
} solve_errors;
static double T;
static ColumnVector X;
static ColumnVector P;
static ColumnVector U;
static ColumnVector Ui;
int info;
};
double Solver::T = 0.0;
ColumnVector Solver::U(MTTNU+MTTNYZ,0.0);
ColumnVector Solver::X(MTTNX,0.0);
ColumnVector Solver::P(MTTNPAR,0.0);
ColumnVector Solver::Ui(MTTNYZ,0.0);
inline ColumnVector
mtt_input (ColumnVector &x,
ColumnVector &y,
const double &t,
ColumnVector &par)
{
#ifdef STANDALONE
static ColumnVector u (MTTNU);
static ColumnVector ui (MTTNYZ);
static ColumnVector U (MTTNU+MTTNYZ);
static Solver ae;
u = F${sys}_input (x, y, t, par);
if (MTTNYZ == 0)
{
return u;
}
else
{
return ae.solve(x,u,t,par);
}
#else
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);
|
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
|
ostream &file = cout)
{
static Matrix data;
static int row;
if (dump_data)
{
Matrix written_data = data.extract (0, 0, row-1, data.cols ()-1);
$save_ascii_data_function (file, written_data, "MTT_data");
return;
}
const int nx = x.length (), ny = y.length ();
register int col = 0;
if (0 == row)
|
>
>
|
|
>
|
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
|
ostream &file = cout)
{
static Matrix data;
static int row;
if (dump_data)
{
if (row > 0)
{
Matrix written_data = data.extract (0, 0, row-1, data.cols ()-1);
$save_ascii_data_function (file, written_data, "MTT_data");
}
return;
}
const int nx = x.length (), ny = y.length ();
register int col = 0;
if (0 == row)
|
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
|
#ifdef STANDALONE
void dump_data (ostream &file)
{
ColumnVector null (0.0);
mtt_write (0.0, null, null, 0, true, file);
}
void set_signal_handlers (void);
void handle_signal (int signum)
{
// handle some signals to ensure data is written.
cerr << "# Writing data to MTT.core (signal " << signum << ")" << endl;
ofstream corefile ("MTT.core");
dump_data (corefile);
switch (signum)
{
case SIGFPE:
// Intel chips do not raise SIGFPE for DIVZERO :-(
raise (SIGABRT);
break;
case SIGINT:
break;
case SIGQUIT:
signal (SIGQUIT, SIG_DFL);
raise (SIGQUIT);
break;
|
<
<
|
|
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
|
#ifdef STANDALONE
void dump_data (ostream &file)
{
ColumnVector null (0.0);
mtt_write (0.0, null, null, 0, true, file);
}
void handle_signal (int signum)
{
// handle some signals to ensure data is written.
cerr << "# Writing data to MTT.core (signal " << signum << ")" << endl;
ofstream corefile ("MTT.core");
dump_data (corefile);
switch (signum)
{
case SIGFPE:
// Intel chips do not raise SIGFPE for DIVZERO :-(
// raise (SIGABRT);
break;
case SIGINT:
break;
case SIGQUIT:
signal (SIGQUIT, SIG_DFL);
raise (SIGQUIT);
break;
|