Overview
Comment:Corrected the csex and cseo functions
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: fc1fb3618593618f9f91c767378717791035037459606e36b7cac2aaa016acab
User & Date: gawthrop@users.sourceforge.net on 2000-11-10 14:19:50
Other Links: branch diff | manifest | tags
Context
2000-11-10
14:45:16
Finished up changes to incorporate Geraint's cc stuff check-in: 3336b8ec0d user: gawthrop@users.sourceforge.net tags: origin/master, trunk
14:19:50
Corrected the csex and cseo functions check-in: fc1fb36185 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
09:38:30
Got rid of sys_name functions with no () check-in: 413c080bd3 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/make_ode2odes from [d698ae8f48] to [0075b8f053].

1
2
3
4
5
6
7
8
9
10
11



12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21











+
+
+







#! /bin/sh

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

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.41  2000/11/09 17:06:39  peterg
## Now does euler for cc
##
## Revision 1.40  2000/10/17 09:55:00  peterg
## Replaced switchopen by logic
##
## Revision 1.39  2000/10/14 08:04:40  peterg
## Changed arguments to _inout for consistency
##
## Revision 1.38  2000/10/11 09:08:08  peterg
164
165
166
167
168
169
170
171

172
173
174
175

176
177
178
179
180
181
182
167
168
169
170
171
172
173

174
175
176
177

178
179
180
181
182
183
184
185







-
+



-
+







function make_m() {
#lang_header  $1 ode2odes m  'x,par,simpar' '[Y,X,t]' > $filename
mtt_header ${sys} ode2odes m > $filename
cat <<EOF >> $filename 
global MTT_data;

  if nargin<3
    simpar = ${sys}_simpar; 
    simpar = ${sys}_simpar(); 
    [simpar.dt] = mtt_simpar_update;
  endif
  if nargin<2
    par = ${sys}_numpar; 
    par = ${sys}_numpar(); 
    [par] = mtt_numpar_update(par);
  endif
  if nargin<1
    [x]  =  ${sys}_state(par); 
    [x] = mtt_state_update(x);
  endif

239
240
241
242
243
244
245
246

247
248
249
250
251
252
253
254
255


256
257
258
259

260
261

262
263
264
265
266
267
268


269
270
271

272
273

274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
















293
294
295
296
297
298
299
242
243
244
245
246
247
248

249
250
251
252
253
254
255
256


257
258
259
260
261

262
263

264
265
266
267
268



269
270
271
272

273
274

275
276
277
278
279
280
281
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
308
309
310
311
312
313
314
315
316
317







-
+







-
-
+
+



-
+

-
+




-
-
-
+
+


-
+

-
+



















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







#include <octave/LSODE.h>
#include <octave/ov-struct.h>
#include <octave/oct-map.h>

#include "${sys}_def.h"
#include "${sys}_sympar.h"

octave_value_list
ColumnVector
mtt_${ode} (ColumnVector x, ColumnVector u, double t, ColumnVector par)
{
  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, 2);
  return (f);
  f = feval ("${sys}_${ode}", args, 1);
  return f(0).vector_value ();
}

ColumnVector
mtt_cseo (ColumnVector x, ColumnVector u, double t, ColumnVector par)
mtt_${odeo} (ColumnVector x, ColumnVector u, double t, ColumnVector par)
{
  octave_value_list args;
  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);
  ColumnVector f;
  f = feval ("${sys}_cseo", args, 1)(0).vector_value ();
  return (f);
  f = feval ("${sys}_${odeo}", args, 1);
  return f(0).vector_value ();
}

#define mtt_implicit(x,dx,AA,AAx,ddt,nx,open) call_mtt_implicit((x),(dx),(AA),(AAx),(ddt),(nx),(open))
// #define mtt_implicit(x,dx,AA,AAx,ddt,nx,open) call_mtt_implicit((x),(dx),(AA),(AAx),(ddt),(nx),(open))
ColumnVector
call_mtt_implicit (ColumnVector x,
mtt_implicit (ColumnVector x,
		   ColumnVector dx,
		   Matrix AA,
		   ColumnVector AAx,
		   double ddt,
		   int nx,
		   ColumnVector open_switches)
{
  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 ();
}

ColumnVector
mtt_euler (ColumnVector x,
		   ColumnVector dx,
		   double ddt,
		   int nx,
		   ColumnVector open_switches)
{
  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 ();
}

ColumnVector
mtt_input (ColumnVector x, ColumnVector y, const double t, ColumnVector par)
{
  octave_value_list args;
  args (0) = octave_value (x);
  args (1) = octave_value (y);
374
375
376
377
378
379
380
381

382
383
384
385
386
387
388
389


















390
391
392



393
394
395
396




397
398
399



400
401


402

403
404
405
406
407
408
409
392
393
394
395
396
397
398
399
400
401







402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419



420
421
422




423
424
425
426



427
428
429


430
431

432
433
434
435
436
437
438
439








+

-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
-
-
+
+
+
-
-
+
+
-
+







  args (2) = octave_value (t);
  args (3) = octave_value (par);

  ColumnVector f;
  f = feval ("${sys}_logic", args, 1)(0).vector_value ();
  return (f);
}


void
mtt_write (double t, ColumnVector x, ColumnVector y, int nx, int ny)
{
  register int i;
  cout.precision (5);		// this should be passed in as an argument
  cout.width (12);		// as should this (instead of nx, ny)
  cout << t;
  for (i = 0; i < y.length (); i++)
mtt_write (double t, ColumnVector x, ColumnVector y){
  octave_value_list args;
  args (0) = octave_value (t);
  args (1) = octave_value (x);
  args (2) = octave_value (y);
  ColumnVector f;
  feval ("mtt_write", args, 1);

}

//void
//mtt_write (double t, ColumnVector x, ColumnVector y, int nx, int ny)
//{
//  register int i;
//  cout.precision (5);		// this should be passed in as an argument
//  cout.width (12);		// as should this (instead of nx, ny)
//  cout << t;
//  for (i = 0; i < y.length (); i++)
    {
      cout.width (12);
      cout << '\t' << y (i);
//    {
//      cout.width (12);
//      cout << '\t' << y (i);
    }
  cout.width (12);
  cout << "\t\t" << t;
  for (i = 0; i < x.length (); i++)
//    }
//  cout.width (12);
//  cout << "\t\t" << t;
//  for (i = 0; i < x.length (); i++)
    {
      cout.width (12);
      cout << '\t' << x (i);
//    {
//      cout.width (12);
//      cout << '\t' << x (i);
    }
  cout << endl;
//    }
//  cout << endl;
}
//}

ColumnVector nozeros (const ColumnVector v0, const double tol = 0.0)
{
  ColumnVector v (v0.length ());
  register int j;
  for (register int i = j = 0; i < v.length (); i++)
    {
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
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







-
+



-
+
+

-
+



-










-
+







  const int	ilast	= (int)round (simpar ["last"].double_value () / ddt);

  // cse translation
  // LSODE will need ODEFUNC

  for (register int j = 0, i = 1; i <= ilast; i++)
    {
      y	= mtt_cseo (x, u, t, par);
      y	= mtt_${odeo} (x, u, t, par);
      u	= mtt_input (x, y, t, par);
      if (0 == j)
	{
	  mtt_write (t, x, y, MTTNX, MTTNY);
	  //mtt_write (t, x, y, MTTNX, MTTNY);
           mtt_write (t, x, y);
	}
      dx = mtt_${ode} (x, u, t, par)(0).vector_value ();
      dx = mtt_${ode} (x, u, t, par);
EOF

if [ "$method" = "implicit" ]; then
echo Hi $filename
cat <<EOF >> $filename

      AA = mtt_smxa (x, u, ddt, par);
      AAx = mtt_smxax (x, u, ddt, par);
EOF
fi

## Common stuff
cat <<EOF >> $filename
      open_switches = mtt_logic (x, u, t, par);
      x = mtt_implicit (x, dx, AA, AAx, ddt, 1, open_switches);
      x =  $algorithm; 
      t += ddt;
      j++;
      j = (j == (int)simpar ["stepfactor"].double_value ()) ? j : 0;
    }

  retval (0) = octave_value (y);
  retval (1) = octave_value (x);


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