︙ | | | ︙ | |
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
@comment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@comment Version control history
@comment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@comment $Id$
@comment $Log$
@comment Revision 1.6 2001/10/15 14:29:50 gawthrop
@comment Added documentaton on [1:N] style port labels
@comment
@comment Revision 1.5 2001/07/23 03:35:29 geraint
@comment Updated file structure (mtt/bin).
@comment
@comment Revision 1.4 2001/07/23 03:25:02 geraint
|
>
>
>
>
>
>
>
>
>
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
@comment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@comment Version control history
@comment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@comment $Id$
@comment $Log$
@comment Revision 1.9 2002/07/05 13:29:34 geraint
@comment Added notes about generating dynamically linked functions for Octave and Matlab.
@comment
@comment Revision 1.8 2002/07/04 21:34:12 geraint
@comment Updated gnuplot view description to describe Tcl/Tk interface instead of obsolete txt method.
@comment
@comment Revision 1.7 2002/04/23 09:51:54 gawthrop
@comment Changed incorrect statement about searching for components.
@comment
@comment Revision 1.6 2001/10/15 14:29:50 gawthrop
@comment Added documentaton on [1:N] style port labels
@comment
@comment Revision 1.5 2001/07/23 03:35:29 geraint
@comment Updated file structure (mtt/bin).
@comment
@comment Revision 1.4 2001/07/23 03:25:02 geraint
|
︙ | | | ︙ | |
431
432
433
434
435
436
437
438
439
440
441
442
443
444
|
Simulation parameters
* Euler integration::
* Implicit integration::
* Runge Kutta IV integration::
* Hybrd algebraic solver::
Simulation output
* Viewing results with gnuplot::
* Exporting results to SciGraphica::
Representations
|
>
>
>
>
|
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
|
Simulation parameters
* Euler integration::
* Implicit integration::
* Runge Kutta IV integration::
* Hybrd algebraic solver::
Simulation code
* Dynamically linked functions::
Simulation output
* Viewing results with gnuplot::
* Exporting results to SciGraphica::
Representations
|
︙ | | | ︙ | |
658
659
660
661
662
663
664
665
666
667
668
669
670
671
|
* Text editors::
* Octave::
* LaTeX::
Octave
* Octave control system toolbox (OCST)::
Administration
* Software components::
* REDUCE setup::
* Octave setup::
* Paths::
|
>
>
>
|
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
|
* Text editors::
* Octave::
* LaTeX::
Octave
* Octave control system toolbox (OCST)::
* Creating GNU Octave .oct files::
* Creating Matlab .mex files::
* Embedding MTT models in Simulink::
Administration
* Software components::
* REDUCE setup::
* Octave setup::
* Paths::
|
︙ | | | ︙ | |
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
|
@end example
To generate an executable based on the C++ representation:
@example
mtt -cc [options] sys ode2odes exe
@end example
@node Simulation output, , Simulation code, Simulation
@comment node-name, next, previous, up
@section Simulation output
@cindex Simulation output
The view (@pxref{Views}) representation provides a graphical
representation of the results of a simulation; the postscript language
provides the same thing in a form that can be included in a document.
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
|
@end example
To generate an executable based on the C++ representation:
@example
mtt -cc [options] sys ode2odes exe
@end example
@menu
* Dynamically linked functions::
@end menu
@node Dynamically linked functions, , Simulation code, Simulation code
@comment node-name, next, previous, up
@subsection Dynamically linked functions
Some model representations can be compiled into dynamically loaded
code (shared objects) which are compiled prior to use in other
modelling and simulation environments; in particular, .oct files can
be generated for use in GNU Octave (@pxref{Creating GNU Octave .oct
files}) and .mex files can be generated for use in Matlab
(@pxref{Creating Matlab .mex files}) or Simulink (@pxref{Embedding MTT
models in Simulink}). The use of compiled (and possibly
compiler-optimised) code can offer significant processing speed
advantages over equivalent interpreted functions (e.g. .m files) for
computationally intensive procedures.
The C++ code generated by @strong{MTT} allows the same code to be
generated as standalone code, Octave .oct files or Matlab .mexglx
files. Although @strong{MTT} usually takes care of the compilation
options, if it is necessary to compile the code on a machine on which
@strong{MTT} is not installed, the appropriate flag should be passed
to the compiler pre-processor:
@itemize @bullet
@item
@code{-DCODEGENTARGET=STANDALONE}
@item
@code{-DCODEGENTARGET=OCTAVEDLD}
@item
@code{-DCODEGENTARGET=MATLABMEX}
@end itemize
@node Simulation output, , Simulation code, Simulation
@comment node-name, next, previous, up
@section Simulation output
@cindex Simulation output
The view (@pxref{Views}) representation provides a graphical
representation of the results of a simulation; the postscript language
provides the same thing in a form that can be included in a document.
|
︙ | | | ︙ | |
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
|
@end menu
@node Viewing results with gnuplot, Exporting results to SciGraphica, Simulation output, Simulation output
@comment node-name, next, previous, up@subsection
@subsection Viewing results with gnuplot
@cindex gnuplot
Simulation results may be viewed in
@uref{http://www.gnuplot.org,gnuplot} with the command
@example
mtt [options] rc gnuplot view
@end example
The plot format is controlled by the file @emph{sys_gnuplot.txt}. A default version
of this file, which will cause gnuplot to plot the time-history of each state
and each output individually, may be created with the command
@example
mtt rc gnuplot txt
@end example
resulting in
@example
wait=-1
set data style lines
set xlabel "time"
set grid
set term X11
plot "rc_odes.dat2" using 1:4 axes x1y1 title "rc_c_c;
pause(wait);
plot "rc_odes.dat2" using 1:2 axes x1y1 title "rc_e2_e2
; pause(wait);
@end example
The file is used as an input to the gnuplot program and may therefore be
edited to contain any valid gnuplot commands.
@node Exporting results to SciGraphica, , Viewing results with gnuplot, Simulation output
@comment node-name, next, previous, up
@subsection Exporting results to SciGraphica
@cindex SciGraphica
Simulation results can be converted into an XML-format
|
|
|
>
<
|
<
<
<
<
>
<
>
<
<
<
<
<
|
<
<
<
<
<
<
>
|
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
|
@end menu
@node Viewing results with gnuplot, Exporting results to SciGraphica, Simulation output, Simulation output
@comment node-name, next, previous, up@subsection
@subsection Viewing results with gnuplot
@cindex gnuplot
Simulation plots may be conveniently selected, viewed with
@uref{http://www.gnuplot.org,gnuplot}
and saved to file (in PostScript format) using the command
@example
mtt [options] rc gnuplot view
@end example
This will cause a menu to be displayed, from which states and outputs may be selected for viewing. Clicking on a @emph{parameter name} will cause a new window to be opened displaying the time history of the selected parameter. Selecting the @emph{print} option in the main window provides the option of saving to file a plot of the last selected parameter. Clicking on the @emph{title bar} of the main window (``Outputs'' or ``States'') will alter the order in which the parameter names are displayed.
It should be noted that unlike other representations, if a simulation has been previously run in a directory, this command will @emph{not} cause @strong{MTT} to re-run a simulation, even if any of the input files have been changed.
If it is desired to re-run a simulation, it is advisable to run the command
@example
mtt [options] rc odeso view ; mtt [options] rc gnuplot view
@end example
As with @strong{xMTT} (@pxref{Menu-driven interface}), the Wish Tcl/Tk interpreter must be installed to make use of this feature.
@node Exporting results to SciGraphica, , Viewing results with gnuplot, Simulation output
@comment node-name, next, previous, up
@subsection Exporting results to SciGraphica
@cindex SciGraphica
Simulation results can be converted into an XML-format
|
︙ | | | ︙ | |
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
|
%% ss1 is both a source and sensor
ss1 SS external,external
%% ss1 acts as a flow sensor - it imposes zero effort.
ss2 SS 0,external
@end example
@node Other component labels , Component names, SS component labels , Labels (lbl)
@comment node-name, next, previous, up
@subsection Other component labels
@cindex Other component labels
In addition to the label there are two information fields,
@pxref{Labels (lbl)}.
They correspond to the constitutive relationship
|
|
|
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
|
%% ss1 is both a source and sensor
ss1 SS external,external
%% ss1 acts as a flow sensor - it imposes zero effort.
ss2 SS 0,external
@end example
@node Other component labels, Component names, SS component labels , Labels (lbl)
@comment node-name, next, previous, up
@subsection Other component labels
@cindex Other component labels
In addition to the label there are two information fields,
@pxref{Labels (lbl)}.
They correspond to the constitutive relationship
|
︙ | | | ︙ | |
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
|
# Generated by MTT at Mon Jun 16 15:10:17 BST 1997
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %% Version control history
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %% $Id$
# %% $Log$
# %% Revision 1.6 2001/10/15 14:29:50 gawthrop
# %% Added documentaton on [1:N] style port labels
# %%
# %% Revision 1.5 2001/07/23 03:35:29 geraint
# %% Updated file structure (mtt/bin).
# %%
# %% Revision 1.4 2001/07/23 03:25:02 geraint
|
>
>
>
>
>
>
>
>
>
|
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
|
# Generated by MTT at Mon Jun 16 15:10:17 BST 1997
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %% Version control history
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %% $Id$
# %% $Log$
# %% Revision 1.9 2002/07/05 13:29:34 geraint
# %% Added notes about generating dynamically linked functions for Octave and Matlab.
# %%
# %% Revision 1.8 2002/07/04 21:34:12 geraint
# %% Updated gnuplot view description to describe Tcl/Tk interface instead of obsolete txt method.
# %%
# %% Revision 1.7 2002/04/23 09:51:54 gawthrop
# %% Changed incorrect statement about searching for components.
# %%
# %% Revision 1.6 2001/10/15 14:29:50 gawthrop
# %% Added documentaton on [1:N] style port labels
# %%
# %% Revision 1.5 2001/07/23 03:35:29 geraint
# %% Updated file structure (mtt/bin).
# %%
# %% Revision 1.4 2001/07/23 03:25:02 geraint
|
︙ | | | ︙ | |
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
|
step(rc);
bode(rc);
@end example
@menu
* Octave control system toolbox (OCST)::
@end menu
@node Octave control system toolbox (OCST), , Octave, Octave
@comment node-name, next, previous, up
@subsection Octave control system toolbox (OCST)
@cindex Octave
@cindex toolbox
@cindex OCST
@cindex control systems
@cindex mtt2sys
|
>
>
>
|
|
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
|
step(rc);
bode(rc);
@end example
@menu
* Octave control system toolbox (OCST)::
* Creating GNU Octave .oct files::
* Creating Matlab .mex files::
* Embedding MTT models in Simulink::
@end menu
@node Octave control system toolbox (OCST), Creating GNU Octave .oct files, Octave, Octave
@comment node-name, next, previous, up
@subsection Octave control system toolbox (OCST)
@cindex Octave
@cindex toolbox
@cindex OCST
@cindex control systems
@cindex mtt2sys
|
︙ | | | ︙ | |
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
|
The following octave commands then generate the step reponse and bode
diagram respectively:
@example
step(rc);
bode(rc);
@end example
@node LaTeX, , Octave, Language tools
@comment node-name, next, previous, up
@section LaTeX
@cindex LaTeX
LaTeX is a powerful text processor which @strong{MTT} uses to provide
|
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
|
The following octave commands then generate the step reponse and bode
diagram respectively:
@example
step(rc);
bode(rc);
@end example
@node Creating GNU Octave .oct files, Creating Matlab .mex files, Octave control system toolbox (OCST), Octave
@comment node-name, next, previous, up
@subsection Creating GNU Octave .oct files
@cindex Creating GNU Octave .oct files
GNU Octave dynamically loaded functions (.oct files) can be created by
instructing @strong{MTT} to create the ``oct'' representation:
@example
mtt [options] sys ode oct
@end example
This will cause @strong{MTT} to create the C++ representation of the system
(sys_ode.cc) and to then compile it as a shared object suitable for
use within Octave. The resultant file may be used in an identical
manner to the equivalent, but generally slower, interpreted .m file.
Usage information for the function may be obtained within Octave in the usual manner:
@example
octave:1> help rc_ode
rc_ode is the dynamically-linked function from the file
/home/mttuser/rc/rc_ode.oct
Usage: [mttdx] = rc_ode(mttx,mttu,mttt,mttpar)
Octave ode representation of system rc
Generated by MTT on Fri Jul 5 11:23:08 BST 2002
@end example
Note that the first line of output from Octave identifies whether the
compiled or interpreted function is being used.
Alternatively, standard representations may be generated using the
Octave DLDs by use of the ``-oct'' switch:
@example
mtt -oct rc odeso view
@end example
In order to successfully generate .oct files, Octave must be correctly
configured prior to compilation and certain headers and libraries must
be correctly installed on the system (@pxref{.oct file dependencies}).
@node Creating Matlab .mex files, Embedding MTT models in Simulink, Creating GNU Octave .oct files, Octave
@comment node-name, next, previous, up
@subsection Creating Matlab .mex files
@cindex Creating Matlab .mex files
On GNU/Linux systems, Matlab dynamically linked executables (.mexglx
files) can created by instructing @strong{MTT} to create the
``mexglx'' representation:
@example
mtt [options] sys ode mexglx
@end example
This will cause @strong{MTT} to create the C++ representation of the
system (sys_ode.cc) and to then compile it as a shared object suitable
for use within Matlab.
If it is necessary to compile mex files for another platform, then the
usual C++ representation (generated with the -cc flag) can be created
and the resultant file compiled with the -DCODEGENTARGET=MATLABMEX
flag on the target platform.
@example
mtt_machine:
mtt -cc rc ode cc
matlab_machine:
matlab> mex -DCODEGENTARGET=MATLABMEX rc_ode.cc
@end example
@node Embedding MTT models in Simulink, , Creating Matlab .mex files, Octave
@comment node-name, next, previous, up
@subsection Embedding MTT models in Simulink
@cindex Embedding MTT models in Simulink
It is possible to embed @strong{MTT} functions or entire @strong{MTT}
models within Simulink simulations as Sfun blocks. If the zip package
is installed on the system, the command
@example
mtt sys sfun zip
@end example
will create a compressed archive containing sys.mdl, which may be
embedded into a larger Simulink model. Also contained within the
archive will be four sys_sfun*.c files,
@itemize @bullet
@item
sys_sfun.c
model state and output equations
@item
sys_sfun_ae.c
model algebraic equations
@item
sys_sfun_input.c
model inputs
@item
sys_sfun_interface.c
interface between MTT model and Simulink
@end itemize
The last of these files must be edited to correctly map the inputs and
outputs between the @strong{MTT} and Simulink models. The two sections
to edit are clearly marked with
@example
@code{/* Start EDIT */}
@code{....}
@code{/* End EDIT */}
@end example
These four files should then be compiled with the Matlab ``mex''
compiler as described in the @emph{README} file in the archive.
If it is desired to compile the .mex files directly from within
@strong{MTT} on a machine which has the Matlab header files installed,
this may be done with the command
@example
mtt sys sfun mexglx
@end example
which will generated the four .mex files and the .mdl file. In this
case, the user must ensure that @emph{sys_sfun_interface.c} has been
correctly edited prior to compilation.
Note that solution of algebraic equations within Simulink is not
possible unless the @emph{Matlab Optimisation Toolbox} is installed.
@node LaTeX, , Octave, Language tools
@comment node-name, next, previous, up
@section LaTeX
@cindex LaTeX
LaTeX is a powerful text processor which @strong{MTT} uses to provide
|
︙ | | | ︙ | |
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
|
empty_list_elements_ok = 1;
@end example
@node .oct file dependencies, , .octaverc, Octave setup
@comment node-name, next, previous, up Additionally, it is necessary to
@subsection .oct file dependencies
Successful compilation of .oct code requires that Octave has been configured
to use dynamically linked libraries and that the Octave library @code{liboctave}
and the Octave modified version of @code{libkpathsea} are available on the
system.
This can be acheived by compiling Octave from the source code, configured
with the options @code{--enable-shared} and @code{--enable-dl}.
Further information on configuring and installing Octave to handle dynamic
libraries (DLDs) can be found in the
@uref{http://www.octave.org/docs.html,Octave documentation}.
@node Paths, File structure, Octave setup, Administration
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
|
empty_list_elements_ok = 1;
@end example
@node .oct file dependencies, , .octaverc, Octave setup
@comment node-name, next, previous, up Additionally, it is necessary to
@subsection .oct file dependencies
Successful compilation of .oct code requires that Octave has been
configured to use dynamically linked libraries and that the Octave
libraries @code{liboctave}, @code{libcruft} and @code{liboctinterp}
are available on the system.
This can be acheived by compiling Octave from the source code, configured
with the options @code{--enable-shared} and @code{--enable-dl}.
A number of additional libraries and headers are also required to be
installed on a system. These include,
@itemize @bullet
@item
@emph{ncurses} and @emph{readline}
terminal control routines
@item
@emph{blas} or @emph{altas}
basic linear algebra subprograms, usually optimised for the specific processor
@item
@emph{fftw}
fast Fourier transform routines
@item
@emph{g2c}
GNU Fortran to C conversion routines
@item
@emph{kpathsea}
TeX path search routines
@end itemize
Note that on many GNU/Linux distributions, the necessary headers are
contained in development packages which must be installed in addition
to the standard library package.
Further information on configuring and installing Octave to handle dynamic
libraries (DLDs) can be found in the
@uref{http://www.octave.org/docs.html,Octave documentation}.
@node Paths, File structure, Octave setup, Administration
|
︙ | | | ︙ | |