Overview
Comment:Numerical solution of algebraic equations.
sys_ae.cc written for unsolved inputs.
Solution of equations using hybrd from MINPACK (as used by Octave fsolve).
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/numerical-algebraic-solution | trunk
Files: files | file ages | folders
SHA3-256: 2640c1bcbbfd9eef4f0452891ec3081387b05bc2d018bc0dabde1449926b51a0
User & Date: geraint@users.sourceforge.net on 2001-05-04 04:07:24
Other Links: branch diff | manifest | tags
Context
2001-05-05
20:50:16
Fixed errors when MTTNx=0. check-in: fc9f65477a user: geraint@users.sourceforge.net tags: origin/numerical-algebraic-solution, trunk
2001-05-04
04:07:24
Numerical solution of algebraic equations.
sys_ae.cc written for unsolved inputs.
Solution of equations using hybrd from MINPACK (as used by Octave fsolve).
check-in: 2640c1bcbb user: geraint@users.sourceforge.net tags: origin/numerical-algebraic-solution, trunk
2001-04-30
03:02:53
Created branch numerical-algebraic-solution check-in: e96b3471d0 user: gawthrop@users.sourceforge.net tags: origin/numerical-algebraic-solution, trunk
Changes

Modified mttroot/mtt/bin/mtt from [10150b1995] to [6ea445f6e4].

12
13
14
15
16
17
18



19
20
21
22
23
24
25
# Copyright (C) 2001 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Header$
## $Log$



## Revision 1.308  2001/04/25 22:17:45  geraint
## Fixed icd.txt2 dependency.
##
## Revision 1.307  2001/04/15 21:15:41  geraint
## Added interface definition rep: _ICD.(txt|c|cc|m).
##
## Revision 1.305  2001/04/11 09:44:26  gawthrop







>
>
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Copyright (C) 2001 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Header$
## $Log$
## Revision 1.309  2001/04/28 03:15:03  geraint
## Fixed comment (interfered with "mtt help representations").
##
## Revision 1.308  2001/04/25 22:17:45  geraint
## Fixed icd.txt2 dependency.
##
## Revision 1.307  2001/04/15 21:15:41  geraint
## Added interface definition rep: _ICD.(txt|c|cc|m).
##
## Revision 1.305  2001/04/11 09:44:26  gawthrop
1425
1426
1427
1428
1429
1430
1431

1432
1433
1434
1435
1436
1437
1438
  rm -f *_csex.cc *_numpar.cc *_smxa.cc *_state.cc 
  rm -f *_ode.cc *_odeo.cc
  rm -f *_logic.m *_logic.cc *_logic.oct
  rm -f *_state.m *_state.cc *_state.oct
  rm -f *_ode2odes.* *.dat2 MTT.core
  rm -f *_modpar.txt *_modpar.r
  rm -f *_ICD.txt *_ICD.c *_ICD.cc *_ICD.m

  rm -fR *_rep MTT_work
  exit
fi

# Clean up named system
if [ "$2" = "Clean" ] && [ "$3" = "" ]; then
  echo 'Removing all generated files for system ' $1







>







1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
  rm -f *_csex.cc *_numpar.cc *_smxa.cc *_state.cc 
  rm -f *_ode.cc *_odeo.cc
  rm -f *_logic.m *_logic.cc *_logic.oct
  rm -f *_state.m *_state.cc *_state.oct
  rm -f *_ode2odes.* *.dat2 MTT.core
  rm -f *_modpar.txt *_modpar.r
  rm -f *_ICD.txt *_ICD.c *_ICD.cc *_ICD.m
  rm -f *_ae.r *_ae.m *_ae.cc *_ae.oct
  rm -fR *_rep MTT_work
  exit
fi

# Clean up named system
if [ "$2" = "Clean" ] && [ "$3" = "" ]; then
  echo 'Removing all generated files for system ' $1
1461
1462
1463
1464
1465
1466
1467

1468
1469
1470
1471
1472
1473
1474
  rm -f $1_csex.cc $1_numpar.cc $1_smxa.cc $1_state.cc 
  rm -f $1_ode.cc $1_odeo.cc
  rm -f $1_logic.m $1_logic.cc $1_logic.oct 
  rm -f $1_state.m $1_state.cc $1_state.oct
  rm -f $1_ode2odes.* $1.dat2
  rm -f $1_modpar.txt $1_modpar.r
  rm -f $1_ICD.txt $1_ICD.c $1_ICD.cc $1_ICD.m

  rm -fR $1_rep MTT_work
  exit
fi

if [ "$2" = "rep" ]; then
     documenttype=article
      # See if we are making a book -- ie representation rep on a directory







>







1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
  rm -f $1_csex.cc $1_numpar.cc $1_smxa.cc $1_state.cc 
  rm -f $1_ode.cc $1_odeo.cc
  rm -f $1_logic.m $1_logic.cc $1_logic.oct 
  rm -f $1_state.m $1_state.cc $1_state.oct
  rm -f $1_ode2odes.* $1.dat2
  rm -f $1_modpar.txt $1_modpar.r
  rm -f $1_ICD.txt $1_ICD.c $1_ICD.cc $1_ICD.m
  rm -f $1_ae.r $1_ae.m $1_ae.cc $1_ae.oct
  rm -fR $1_rep MTT_work
  exit
fi

if [ "$2" = "rep" ]; then
     documenttype=article
      # See if we are making a book -- ie representation rep on a directory
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
else
	mtt_update $1 logic
endif

# Dummy target
FORCE:

$1_ode2odes_common.m    : $1_input.m   $1_logic.m   $1_numpar.m   $1_simpar.m   $1_state.m
	@echo > /dev/null
$1_ode2odes_common.cc   : $1_input.cc  $1_logic.cc  $1_numpar.cc  $1_simpar.cc  $1_state.cc
	@echo > /dev/null
$1_ode2odes_common.o    : $1_input.o   $1_logic.o   $1_numpar.o   $1_simpar.o   $1_state.o
	@echo "Creating $1_ode2odes_common.o"
	ar -cr \$@ \$^
$1_ode2odes_common.oct  : $1_input.oct $1_logic.oct $1_numpar.oct $1_simpar.oct $1_state.oct
	@echo > /dev/null

$1_ode2odes_euler.m  $1_ode2odes_rk4.m    : $1_ode.m     $1_odeo.m
	@echo > /dev/null
$1_ode2odes_euler.cc $1_ode2odes_rk4.cc   : $1_ode.cc    $1_odeo.cc
	@echo > /dev/null
$1_ode2odes_euler.o  $1_ode2odes_rk4.o    : $1_ode.o     $1_odeo.o   mtt_euler.o







|

|

|


|







2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
else
	mtt_update $1 logic
endif

# Dummy target
FORCE:

$1_ode2odes_common.m    : $1_ae.m   $1_input.m   $1_logic.m   $1_numpar.m   $1_simpar.m   $1_state.m
	@echo > /dev/null
$1_ode2odes_common.cc   : $1_ae.cc  $1_input.cc  $1_logic.cc  $1_numpar.cc  $1_simpar.cc  $1_state.cc
	@echo > /dev/null
$1_ode2odes_common.o    : $1_ae.o   $1_input.o   $1_logic.o   $1_numpar.o   $1_simpar.o   $1_state.o
	@echo "Creating $1_ode2odes_common.o"
	ar -cr \$@ \$^
$1_ode2odes_common.oct  : $1_ae.oct $1_input.oct $1_logic.oct $1_numpar.oct $1_simpar.oct $1_state.oct
	@echo > /dev/null

$1_ode2odes_euler.m  $1_ode2odes_rk4.m    : $1_ode.m     $1_odeo.m
	@echo > /dev/null
$1_ode2odes_euler.cc $1_ode2odes_rk4.cc   : $1_ode.cc    $1_odeo.cc
	@echo > /dev/null
$1_ode2odes_euler.o  $1_ode2odes_rk4.o    : $1_ode.o     $1_odeo.o   mtt_euler.o
2398
2399
2400
2401
2402
2403
2404









2405
2406
2407
2408
2409
2410
2411

$1_dae.m: $1_def.r $1_dae.r  $1_sympars.txt
	dae_r2m $1; matlab_tidy $1_dae.m; matlab_tidy $1_daeo.m
$1_dae.c: $1_def.r $1_dae.r  $1_sympar.r
	dae_r2c $1; c_tidy $1_dae.c
$1_dae.tex: $1_dae.r $1_simp.r
	dae_r2tex $partition $1; latex_tidy $1_dae.tex










#SUMMARY cse	constrained-state equations (r)
#SUMMARY cse*	constrained-state equations (m)
#SUMMARY cse*	constrained-state equations (oct)
#SUMMARY cse	constrained-state equations (tex)
#SUMMARY cse*	constrained-state equations (view)
#SUMMARY cse	constrained-state equations (ps)







>
>
>
>
>
>
>
>
>







2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425

$1_dae.m: $1_def.r $1_dae.r  $1_sympars.txt
	dae_r2m $1; matlab_tidy $1_dae.m; matlab_tidy $1_daeo.m
$1_dae.c: $1_def.r $1_dae.r  $1_sympar.r
	dae_r2c $1; c_tidy $1_dae.c
$1_dae.tex: $1_dae.r $1_simp.r
	dae_r2tex $partition $1; latex_tidy $1_dae.tex

#SUMMARY ae	algebraic equations - unknown inputs (r)
#SUMMARY ae	algebraic equations - unknown inputs (m)
#SUMMARY ae	algebraic equations - unknown inputs (cc)

$1_ae.r: $1_cse.r
	touch $1_ae.r
$1_ae.m: $1_ae.r
	mtt_r2m $1 ae

#SUMMARY cse	constrained-state equations (r)
#SUMMARY cse*	constrained-state equations (m)
#SUMMARY cse*	constrained-state equations (oct)
#SUMMARY cse	constrained-state equations (tex)
#SUMMARY cse*	constrained-state equations (view)
#SUMMARY cse	constrained-state equations (ps)

Modified mttroot/mtt/bin/trans/cse2ode_r from [b0e0e060b2] to [6fa8ee5ed3].

10
11
12
13
14
15
16



17
18
19
20
21
22
23
# Copyright (c) P.J.Gawthrop, 1991, 1994.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$



## 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
##
###############################################################







>
>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Copyright (c) P.J.Gawthrop, 1991, 1994.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## 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
##
###############################################################
43
44
45
46
47
48
49



50
51
52
53
54
55
56
in "$1_def.r";

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

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




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








>
>
>







46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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;

Modified mttroot/mtt/bin/trans/dae2cse_r from [2f584317f5] to [c759129236].

11
12
13
14
15
16
17



18
19
20
21
22
23
24
# Copyright (c) P.J.Gawthrop 1991, 1992, 1994.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$



## Revision 1.14.2.1  2001/03/19 00:29:08  geraint
## Parse switches (-A) before calling def2write_r.
## Update $1_def.* instead of removing.
##
## Revision 1.14  2000/12/28 12:24:35  peterg
## *** empty log message ***
##







>
>
>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Copyright (c) P.J.Gawthrop 1991, 1992, 1994.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.15  2001/03/19 02:28:52  geraint
## Branch merge: merging-ode2odes-exe back to MAIN.
##
## Revision 1.14.2.1  2001/03/19 00:29:08  geraint
## Parse switches (-A) before calling def2write_r.
## Update $1_def.* instead of removing.
##
## Revision 1.14  2000/12/28 12:24:35  peterg
## *** empty log message ***
##
279
280
281
282
283
284
285
286
287










288
289
290
291
292
293
294
  BEGIN
    MTT_sol_i := first(MTT_sol); MTT_sol := rest(MTT_sol);
    set(lhs(MTT_sol_i),rhs(MTT_sol_i));
  END;

  % No algebraic variables left!
  MTTNYz := 0;
END; % IF MTTNyz>0












% Create the matrix declarations
OUT "$1_cse.r1";
write "MATRIX MTTEdx(", MTTNx, ",", 1, ")$"; 
write "MATRIX MTTE(", MTTNx, ",", MTTNx, ")$"; 
SHUT "$1_cse.r1";








|

>
>
>
>
>
>
>
>
>
>







282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
  BEGIN
    MTT_sol_i := first(MTT_sol); MTT_sol := rest(MTT_sol);
    set(lhs(MTT_sol_i),rhs(MTT_sol_i));
  END;

  % No algebraic variables left!
  MTTNYz := 0;
END; % IF MTTNyz>0 and $solve

IF (MTTNyz>0) THEN % not $solve (or perhaps solution failed?)
BEGIN
    OUT "$1_ae.r";
    WRITE "MATRIX MTTyz(",MTTNyz,",1)";
    WRITE "%file $1_ae.r";
    FOR i := 1:MTTNyz DO
	WRITE "MTTyz(",i,",1) := ",MTTyz(i,1);
    WRITE ";END;";
    SHUT "$1_ae.r";
END; % if MTTNyz>0 (and !$solve)

% Create the matrix declarations
OUT "$1_cse.r1";
write "MATRIX MTTEdx(", MTTNx, ",", 1, ")$"; 
write "MATRIX MTTE(", MTTNx, ",", MTTNx, ")$"; 
SHUT "$1_cse.r1";

Modified mttroot/mtt/bin/trans/def2write_r from [7008801453] to [9917137f0f].

9
10
11
12
13
14
15





16
17
18
19
20
21
22
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$





## Revision 1.6  2000/11/29 20:48:53  peterg
## Zapped unnecessary Npar creation
##
## Revision 1.5  2000/11/09 10:12:24  peterg
## Removed debugging line
##
## Revision 1.4  2000/10/14 16:19:54  peterg







>
>
>
>
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.7  2001/04/11 09:44:26  gawthrop
## Fixed cc and c problems to do with pow(x,y) and integers
## mtt/lib/reduce/fix_c.r is included in rdae2dae and cse2smx_lang for
## -c, -cc and -oct options
##
## Revision 1.6  2000/11/29 20:48:53  peterg
## Zapped unnecessary Npar creation
##
## Revision 1.5  2000/11/09 10:12:24  peterg
## Removed debugging line
##
## Revision 1.4  2000/10/14 16:19:54  peterg
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
	;;
    ode)
        matrices='dX'
        ns="$Nx"
        ms="1"
	;;
    odeo)
        matrices='Y Yz'
        ns="$Ny $Nyz"
        ms="1 1"
	;;
    sm)
        matrices='A B C D'
        ns="$Nx $Nx $Ny $Ny"
        ms="$Nx $Nu $Nx $Nu"
	;;







|
|







81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
	;;
    ode)
        matrices='dX'
        ns="$Nx"
        ms="1"
	;;
    odeo)
        matrices='Y'
        ns="$Ny"
        ms="1 1"
	;;
    sm)
        matrices='A B C D'
        ns="$Nx $Nx $Ny $Ny"
        ms="$Nx $Nu $Nx $Nu"
	;;

Modified mttroot/mtt/bin/trans/make_ode2odes from [a0ec3f6c8d] to [afde7a9c2a].

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;

Modified mttroot/mtt/bin/trans/mtt_header from [6a295989c6] to [c460ed9eaf].

8
9
10
11
12
13
14




15
16
17
18
19
20
21
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$




## Revision 1.30  2001/03/30 15:13:58  gawthrop
## Rationalised simulation modes to each return mtt_data
##
## Revision 1.29  2001/03/27 13:10:23  geraint
## Improved determination of Octave version.
##
## Revision 1.28  2001/02/17 03:48:17  geraint







>
>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.31  2001/04/03 14:49:42  gawthrop
## Revised to incorporate new ssim (sensitivity simulation)
## representation (m only just now).
##
## Revision 1.30  2001/03/30 15:13:58  gawthrop
## Rationalised simulation modes to each return mtt_data
##
## Revision 1.29  2001/03/27 13:10:23  geraint
## Improved determination of Octave version.
##
## Revision 1.28  2001/02/17 03:48:17  geraint
160
161
162
163
164
165
166







167
168
169
170
171
172
173


# Representation-specific stuff

eqnargs='mttx,mttu,mttt,mttpar'
inputeqnargs='mttx,mtty,mttt,mttpar'
case $rep in







    cse)
	states=yes;
        inputs=yes;
	parameters=yes;
        output='mttdx,mtte'
        args=$eqnargs
	;;







>
>
>
>
>
>
>







164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184


# Representation-specific stuff

eqnargs='mttx,mttu,mttt,mttpar'
inputeqnargs='mttx,mtty,mttt,mttpar'
case $rep in
    ae)
	states=yes;
	inputs=yes;
	parameters=yes;
	output=mttyz;
	args=$eqnargs;
	;;
    cse)
	states=yes;
        inputs=yes;
	parameters=yes;
        output='mttdx,mtte'
        args=$eqnargs
	;;
201
202
203
204
205
206
207

208
209
210
211
212
213
214
	  states=no;
	  parameters=no;
          declareinputs=no;
        else
	  states=yes;
	  parameters=yes;
          declareinputs=yes

        fi
	;;
    logic)
	states=no;
	inputs=no;
	parameters=yes;
        output=mttopen







>







212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
	  states=no;
	  parameters=no;
          declareinputs=no;
        else
	  states=yes;
	  parameters=yes;
          declareinputs=yes
	  declarestates=yes
        fi
	;;
    logic)
	states=no;
	inputs=no;
	parameters=yes;
        output=mttopen
469
470
471
472
473
474
475









476
477
478
479
480
481
482
$Lc Inputs $Rc
EOF

N=`n2m 1 $Nu`
for i in $N; do
  echo $constant_declaration 'mttu'$i' = mttu('$i$minusone');'
done









fi

if [ "$declareinputs" = "yes" ]; then
  declare_vars input
fi

if [ "$declaredummies" = "yes" ]; then







>
>
>
>
>
>
>
>
>







481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
$Lc Inputs $Rc
EOF

N=`n2m 1 $Nu`
for i in $N; do
  echo $constant_declaration 'mttu'$i' = mttu('$i$minusone');'
done
cat <<EOF

$Lc Unknown Inputs $Rc
EOF

Ni=`n2m 1 $Nyz`
for i in $Ni; do
  echo $constant_declaration 'mttui'$i' = mttu('$Nu+$i$minusone');'
done
fi

if [ "$declareinputs" = "yes" ]; then
  declare_vars input
fi

if [ "$declaredummies" = "yes" ]; then
525
526
527
528
529
530
531




532
533
534
535
536
537
538
	    arg_type="Octave_map"
	    arg_size="";
	    ;;
	mttu)
	    arg_type="ColumnVector"
	    arg_size="(MTTNU)"
	    ;;




	mtty)
	    arg_type="ColumnVector"
	    arg_size="(MTTNY)"
	    ;;
	mttt)
	    arg_type="const double"
	    arg_size=""







>
>
>
>







546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
	    arg_type="Octave_map"
	    arg_size="";
	    ;;
	mttu)
	    arg_type="ColumnVector"
	    arg_size="(MTTNU)"
	    ;;
	mttyz)
	    arg_type="ColumnVector"
	    arg_size="(MTTNYZ)"
	    ;;
	mtty)
	    arg_type="ColumnVector"
	    arg_size="(MTTNY)"
	    ;;
	mttt)
	    arg_type="const double"
	    arg_size=""

Modified mttroot/mtt/bin/trans/mtt_r2m from [2c1a02abfa] to [41d69599dd].

14
15
16
17
18
19
20



21
22
23
24
25
26
27
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$



## Revision 1.26  2000/11/27 11:52:10  peterg
## Changed some greps to be case insensitive
##
## Revision 1.25  2000/10/14 08:50:07  peterg
## Use new mtt_header
##
## Revision 1.24  2000/10/11 09:07:53  peterg







>
>
>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.27  2001/02/08 00:39:56  geraint
## Removed clear from code generated by: mtt -c -i euler -o
##
## Revision 1.26  2000/11/27 11:52:10  peterg
## Changed some greps to be case insensitive
##
## Revision 1.25  2000/10/14 08:50:07  peterg
## Use new mtt_header
##
## Revision 1.24  2000/10/11 09:07:53  peterg
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
echo Creating $out

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

#Header
case $rep in
    csex|cseo|ode|odeo)
    vectorise=yes
       ;;
    *)
esac

    mtt_header  $1 $rep $ext  > mtt_junk








|







133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
echo Creating $out

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

#Header
case $rep in
    ae|csex|cseo|ode|odeo)
    vectorise=yes
       ;;
    *)
esac

    mtt_header  $1 $rep $ext  > mtt_junk


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