Differences From Artifact [afde7a9c2a]:

To Artifact [a0a317a4de]:


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











>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#! /bin/sh

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

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.57.2.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.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
##
221
222
223
224
225
226
227






228
229
230
231
232
233
234
filename=${sys}_ode2odes.${lang}

if [ -n "$3" ]; then
  method=$3    
else
  method=implicit  
fi







echo Creating $filename with $method integration method

# Find system constants
Nx=`mtt_getsize $sys x` # States
Nu=`mtt_getsize $sys u` # Inputs 
Ny=`mtt_getsize $sys y` # Inputs  







>
>
>
>
>
>







226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
filename=${sys}_ode2odes.${lang}

if [ -n "$3" ]; then
  method=$3    
else
  method=implicit  
fi

if [ -n "$4" ]; then
    algebraic_solver=$4
else
  algebraic_solver="Reduce_Solver"
fi

echo Creating $filename with $method integration method

# Find system constants
Nx=`mtt_getsize $sys x` # States
Nu=`mtt_getsize $sys u` # Inputs 
Ny=`mtt_getsize $sys y` # Inputs  
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
	;;
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);








<













>
>







357
358
359
360
361
362
363

364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
	;;
esac

cat <<EOF  > $filename
#include <octave/oct.h>
#include <octave/load-save.h>
#include <octave/lo-mappers.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>

#include "mtt_${algebraic_solver}.hh"

extern ColumnVector F${sys}_ae (
	ColumnVector &x,
	ColumnVector &u,
	const double &t,
	ColumnVector &par);

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







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<










|
>







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
fi
cat <<EOF >> $filename

void set_signal_handlers (void);

#endif // STANDALONE



































































































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 ${algebraic_solver} ae(F${sys}_ae,MTTNPAR,MTTNU,MTTNX,MTTNY,MTTNYZ);

  u = F${sys}_input (x, y, t, par);
  if (MTTNYZ == 0)
    {
      return u;
    }
  else

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