Overview
Comment:Updated from main branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/optimise-algebraic-equations | trunk
Files: files | file ages | folders
SHA3-256: df5f842a8c3c998308d5e0ff62d94b5f9d9019fd2c867ffc911fdfb02de3baff
User & Date: geraint@users.sourceforge.net on 2002-07-10 15:22:30
Other Links: branch diff | manifest | tags
Context
2002-07-10
15:52:17
Updated from main branch. Leaf check-in: 324f841c3c user: geraint@users.sourceforge.net tags: origin/optimise-algebraic-equations, trunk
15:22:30
Updated from main branch. check-in: df5f842a8c user: geraint@users.sourceforge.net tags: origin/optimise-algebraic-equations, trunk
15:02:33
Updated from main branch. check-in: 4749685170 user: geraint@users.sourceforge.net tags: origin/optimise-algebraic-equations, trunk
Changes

Modified mttroot/mtt/lib/comp/compound/Sensitivity/sEMTF/sEMTF_lbl.txt from [c9d0e3e307] to [9abf0eb7d9].

1
2







3





4
5
6
7
8
9






10
11
12
13
14
15
16
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33


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






+
+
+
+
+
+







%% Label file for system sEMTF (sEMTF_lbl.txt)
%SUMMARY sEMTF Effort modulated TF - sensitivity version
%DESCRIPTION It is assumed that no sensitivity parameter is associated
%DESCRIPTION with this component.
%DESCRIPTION This is a built out of EMTFs and the 4 port AE3 component
%DESCRIPTION There is one argument alias - the transformer (flow) gain 
%DESCRIPTION There are two CR aliases: one for the EMTF and one for
%DESCRIPTION the AE3
%DESCRIPTION Examples:
%DESCRIPTION 
%DESCRIPTION   lin;slin  n
%DESCRIPTION   lsin;slsin l
%DESCRIPTION   lcos;slcos l



% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Version control history
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% $Id$
% %% $Log$
% %% Revision 1.2  2002/06/10 08:27:33  gawthrop
% %% Updated description
% %%
% %% Revision 1.1  2002/04/17 18:50:35  gawthrop
% %% Sensitivity EMTF components
% %%
% %% Revision 1.1  2000/12/28 17:29:10  peterg
% %% To RCS
% %%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% Port aliases

Modified mttroot/mtt/lib/control/PPP/ppp_optimise.m from [d6b999b722] to [32d0c90e52].

25
26
27
28
29
30
31






32
33
34
35
36
37
38
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44







+
+
+
+
+
+







  ######################################
  
  ###############################################################
  ## Version control history
  ###############################################################
  ## $Id$
  ## $Log$
  ## Revision 1.12  2002/06/11 11:25:25  gawthrop
  ## No longer delay the simulated data.
  ##
  ## Revision 1.11  2002/05/20 13:32:36  gawthrop
  ## Sanity check on y_0
  ##
  ## Revision 1.10  2002/05/13 16:01:09  gawthrop
  ## Addes Q weighting matrix
  ##
  ## Revision 1.9  2002/05/08 10:14:21  gawthrop
  ## Idetification now OK (Moved data range in ppp_optimise by one sample interval)
  ##
  ## Revision 1.8  2002/04/23 17:50:39  gawthrop
116
117
118
119
120
121
122
123

124
125
126

127
128
129
130
131
132


133
134
135



136
137
138
139
140


141






142
143
144
145
146
147
148
122
123
124
125
126
127
128

129
130
131

132
133
134
135
136
137
138
139
140



141
142
143
144




145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160







-
+


-
+






+
+
-
-
-
+
+
+

-
-
-
-
+
+

+
+
+
+
+
+







    printf("\n");
  endif
  
  while (abs(reduction)>extras.criterion)&&\
	(abs(err)>extras.criterion)&&\
	(iterations<extras.max_iterations)

    iterations = iterations + 1; # Increment iteration counter
    iterations = iterations + 1 # Increment iteration counter

    [y,y_par,x] = eval(sim_command); # Simulate
    [N_data,N_y] = size(y);
    [N_data,N_y] = size(y)

    if (N_y!=n_y)
      mess = sprintf("n_y (%i) in data not same as n_y (%i) in model", n_y,N_y);
      error(mess);
    endif

    ## Use the last part of the simulation to compare with data
    ## ### Removed #### And shift back by one data point
    if ( (N_data-n_data)<1 )
      error(sprintf("y_0 (%i) must be shorter than y (%i)", n_data, N_data));
    endif
#     if ( (N_data-n_data)<1 )
#       error(sprintf("y_0 (%i) must be shorter than y (%i)", n_data, N_data));
#     endif
    
    ## Use the last part of the simulation to compare with data
    ## And shift back by one data point
    y = y(N_data-n_data:N_data-1,:);
    y_par = y_par(N_data-n_data:N_data-1,:);
    y = y(N_data-n_data+1:N_data,:);
    y_par = y_par(N_data-n_data+1:N_data,:);

    if extras.visual==1
      ## Plot
      title("Optimisation data");
      plot([y y_0])
    endif
    
    ##Evaluate error, cost derivative J and cost second derivative JJ
    err = 0; 
    J = zeros(n_th,1);
    JJ = zeros(n_th,n_th);
   
    for i = 1:n_y
      E = y(:,i) - y_0(:,i);	#  Error in ith output

Modified mttroot/mtt/lib/cr/r/slin.cr from [5d71e66c46] to [ac0389ce2b].

36
37
38
39
40
41
42






















43





44
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71







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

+
+
+
+
+

SUCH THAT sgain EQ 0
LET slin(gain_causality, gain, sgain, other_causality, 2, 
       input, causality, 1,
       sinput, causality, 2)
         = lin(gain_causality, gain, other_causality, 1, 
               sinput, causality, 1);
         

%% This is the version to go with sEMTF
%% It is the CR passed to the AE3 components

%DESCRIPTION four port component - effort i/o
FOR ALL gain, input, junk, m_input, dm_input
LET slin(gain, effort, 2, 
	input, effort, 1,
	junk, flow, 2,
	m_input, effort, 3,
        dm_input,effort, 4)
	 = gain*dm_input*input;

%DESCRIPTION four port component - flow i/o
FOR ALL gain, input, junk, m_input, dm_input
LET slin(gain, flow, 2, 
	input, flow, 1,
	junk, effort, 2,
	m_input, effort, 3,
        dm_input,effort, 4)
	 = gain*dm_input*input;

END;;






Modified mttroot/mtt/lib/rep/sfun_rep.sh from [63c5879b48] to [fe83bc4dd5].

1
2
3
4
5
6
7
8
9
10
11
12
13

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

13
14
15
16
17
18
19
20












-
+







#! /bin/sh

set -e

#
# function definitions
#


set_debug ()
{
    debug=$1
    if [ $debug -eq 1 ]; then
    if ( $debug ); then
	set -x
	make_debug='--debug=a'
    else
	set +x
	make_debug=''
    fi
}
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
29
30
31
32
33
34
35

36



37
38
39
40
41
42
43







-
+
-
-
-







    esac
    echo "#Error: " $message
    exit errno;
}       

check_for_valid_input ()
{
    args="$*"
    return 0;
    if [ $# -neq 4 ]; then
	exit_error "Invalid Input"
    fi
}

#
# file templates
#

# template_README      	compilation instructions
1375
1376
1377
1378
1379
1380
1381
1382
1383


1384
1385
1386
1372
1373
1374
1375
1376
1377
1378


1379
1380
1381
1382
1383







-
-
+
+








### main program

#set_debug 0
#check_for_valid_input "$*"
set_debug false
check_for_valid_input "$*"

OPTS="$1" SYS="$2" REP="$3" LANG="$4" make $make_debug -f ${MTT_REP}/sfun_rep/Makefile ${2}_${3}.${4}
exit 0

Modified mttroot/mtt/lib/rep/sfun_rep/Makefile from [144656f589] to [9de61fb76d].

1
2
3
4
5

6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

42
43
44
45
46
47
48
1
2
3
4

5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48




-
+








-
+







-
+


















-
+







#! /usr/bin/make -f

all: $(SYS)_sfun.mexglx

$(SYS)_sfun.mexglx: $(SYS)_sfun.c sfun_debug.h useful-functions.hh $(SYS)_def.h $(SYS)_sympar.h $(SYS)_numpar.c $(SYS)_ode.c $(SYS)_odeo.c $(SYS)_state.c $(SYS)_sfun_ae.mexglx $(SYS)_sfun_input.mexglx $(SYS)_sfun_interface.mexglx $(SYS).mdl
$(SYS)_sfun.mexglx: $(SYS)_sfun.c sfun_debug.h useful-functions.hh $(SYS)_def.h $(SYS)_sympar.h $(SYS)_cr.h $(SYS)_numpar.c $(SYS)_ode.c $(SYS)_odeo.c $(SYS)_state.c $(SYS)_sfun_ae.mexglx $(SYS)_sfun_input.mexglx $(SYS)_sfun_interface.mexglx $(SYS).mdl
	echo Creating $@
	mex $(SYS)_sfun.c
	cp *_sfun*mexglx $(SYS).mdl ..

$(SYS)_sfun.c:: ${MTT_REP}/sfun_rep/sfun.c.tmpl
	echo Creating $@
	cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@

$(SYS)_sfun_ae.mexglx: $(SYS)_sfun_ae.c sfun-debug.h useful-functions.hh $(SYS)_def.h $(SYS)_sympar.h $(SYS)_ae.c
$(SYS)_sfun_ae.mexglx: $(SYS)_sfun_ae.c sfun_debug.h useful-functions.hh $(SYS)_def.h $(SYS)_sympar.h $(SYS)_cr.h $(SYS)_ae.c
	echo Creating $@
	mex $(SYS)_sfun_ae.c

$(SYS)_sfun_ae.c:: ${MTT_REP}/sfun_rep/mex_ae.c.tmpl
	echo Creating $@
	cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@

$(SYS)_sfun_input.mexglx: $(SYS)_sfun_input.c sfun_debug.h useful-functions.hh $(SYS)_def.h $(SYS)_sympar.h $(SYS)_input.c $(SYS)_numpar.c
$(SYS)_sfun_input.mexglx: $(SYS)_sfun_input.c sfun_debug.h useful-functions.hh $(SYS)_def.h $(SYS)_sympar.h $(SYS)_cr.h $(SYS)_input.c $(SYS)_numpar.c
	echo Creating $@
	mex $(SYS)_sfun_input.c

$(SYS)_sfun_input.c:: ${MTT_REP}/sfun_rep/sfun_input.c.tmpl
	echo Creating $@
	cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@

$(SYS)_sfun_interface.mexglx: $(SYS)_sfun_interface.c sfun_debug.h useful-functions.hh $(SYS)_def.h $(SYS)_sympar.h $(SYS)_numpar.c
	echo Creating $@
	mex $(SYS)_sfun_interface.c

$(SYS)_sfun_interface.c: ${MTT_REP}/sfun_rep/sfun_interface.c.tmpl $(SYS)_struc.c
	echo Creating $@
	cat ${MTT_REP}/sfun_rep/sfun_interface.c.tmpl	|\
	 sed 's/<mtt_model_name>/$(SYS)/g'		|\
	 ${MTT_REP}/sfun_rep/insert_file.sh > $@

$(SYS)_sfun.zip: $(SYS)_sfun.c sfun_debug.h useful-functions.hh $(SYS)_sfun_ae.c $(SYS)_sfun_input.c $(SYS)_sfun_interface.c \
	 $(SYS)_def.h $(SYS)_sympar.h \
	 $(SYS)_def.h $(SYS)_sympar.h $(SYS)_cr.h\
	 $(SYS)_ae.c $(SYS)_input.c $(SYS)_numpar.c $(SYS)_ode.c $(SYS)_odeo.c $(SYS)_state.c \
	 $(SYS).mdl README
	echo Creating $@
	zip $@ $^

$(SYS).mdl: ${MTT_REP}/sfun_rep/mdl.tmpl
	echo Creating $@

Modified mttroot/mtt/lib/rep/sfun_rep/mdl.tmpl from [16ba1b6745] to [97145b618f].

1
2

3
4
5
6
7
8
9
1

2
3
4
5
6
7
8
9

-
+







Model {
  Name			  "<mtt_model_name>"
  Name			  "mdl"
  Version		  4.00
  SampleTimeColors	  off
  LibraryLinkDisplay	  "all"
  WideLines		  off
  ShowLineDimensions	  on
  ShowPortDataTypes	  off
  ShowStorageClass	  off
23
24
25
26
27
28
29
30
31


32
33
34
35
36
37
38
23
24
25
26
27
28
29


30
31
32
33
34
35
36
37
38







-
-
+
+







  BrowserLookUnderMasks	  off
  Created		  "Mon May 20 13:21:21 2002"
  Creator		  "geraint"
  UpdateHistory		  "UpdateHistoryNever"
  ModifiedByFormat	  "%<Auto>"
  LastModifiedBy	  "geraint"
  ModifiedDateFormat	  "%<Auto>"
  LastModifiedDate	  "Thu May 23 16:35:42 2002"
  ModelVersionFormat	  "1.%<AutoIncrement:13>"
  LastModifiedDate	  "Tue Jun 18 18:49:28 2002"
  ModelVersionFormat	  "1.%<AutoIncrement:14>"
  ConfigurationManager	  "None"
  SimParamPage		  "Solver"
  StartTime		  "0.0"
  StopTime		  "10.0"
  SolverMode		  "Auto"
  Solver		  "ode45"
  RelTol		  "1e-3"
150
151
152
153
154
155
156
157
158


159
160
161
162
163
164
165
150
151
152
153
154
155
156


157
158
159
160
161
162
163
164
165







-
-
+
+







  LineDefaults {
    FontName		    "Helvetica"
    FontSize		    9
    FontWeight		    "normal"
    FontAngle		    "normal"
  }
  System {
    Name		    "<mtt_model_name>"
    Location		    [51, 441, 346, 574]
    Name		    "mdl"
    Location		    [61, 487, 356, 620]
    Open		    on
    ModelBrowserVisibility  off
    ModelBrowserWidth	    200
    ScreenColor		    "white"
    PaperOrientation	    "landscape"
    PaperPositionMode	    "auto"
    PaperType		    "usletter"
186
187
188
189
190
191
192
193

194
195
196
197
198
199
200
186
187
188
189
190
191
192

193
194
195
196
197
198
199
200







-
+







      ShowPortLabels	      on
      TreatAsAtomicUnit	      off
      RTWSystemCode	      "Auto"
      RTWFcnNameOpts	      "Auto"
      RTWFileNameOpts	      "Auto"
      System {
	Name			"MTT Model\n<mtt_model_name>"
	Location		[45, 448, 1008, 720]
	Location		[55, 494, 1018, 766]
	Open			off
	ModelBrowserVisibility	off
	ModelBrowserWidth	200
	ScreenColor		"white"
	PaperOrientation	"landscape"
	PaperPositionMode	"auto"
	PaperType		"usletter"
252
253
254
255
256
257
258
















259
260
261
262
263
264
265
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







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







	    Name		    "MTT Model Outputs: MTTY"
	    TestPoint		    off
	    LinearAnalysisOutput    off
	    LinearAnalysisInput	    off
	    RTWStorageClass	    "Auto"
	  }
	}
	Block {
	  BlockType		  Memory
	  Name			  "Memory"
	  Position		  [870, 80, 900, 110]
	  X0			  "0"
	  InheritSampleTime	  off
	  RTWStateStorageClass	  "Auto"
	}
	Block {
	  BlockType		  Memory
	  Name			  "Memory1"
	  Position		  [860, 175, 890, 205]
	  X0			  "0"
	  InheritSampleTime	  off
	  RTWStateStorageClass	  "Auto"
	}
	Block {
	  BlockType		  "S-Function"
	  Name			  "S-Function"
	  Ports			  [4, 2]
	  Position		  [710, 47, 840, 238]
	  BackgroundColor	  "lightBlue"
	  DropShadow		  on
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326














327
328
329






330
331
332
333
334
335
336
320
321
322
323
324
325
326







327
328
329
330
331
332
333
334

335
336
337
338
339
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







-
-
-
-
-
-
-








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



+
+
+
+
+
+







	  Name			  "MTT  Model Inputs: MTTU"
	  Labels		  [1, 0]
	  SrcBlock		  "MTT Model Inputs"
	  SrcPort		  1
	  DstBlock		  "S-Function"
	  DstPort		  1
	}
	Line {
	  SrcBlock		  "S-Function"
	  SrcPort		  1
	  Points		  [30, 0; 0, -70; -850, 0; 0, 105]
	  DstBlock		  "MTT Plant Model"
	  DstPort		  1
	}
	Line {
	  SrcBlock		  "In1"
	  SrcPort		  1
	  DstBlock		  "S-Function"
	  DstPort		  4
	}
	Line {
	  SrcBlock		  "S-Function"
	  SrcPort		  2
	  SrcPort		  1
	  DstBlock		  "Memory"
	  DstPort		  1
	}
	Line {
	  SrcBlock		  "Memory"
	  SrcPort		  1
	  Points		  [0, -55; -855, 0]
	  DstBlock		  "MTT Plant Model"
	  DstPort		  1
	}
	Line {
	  SrcBlock		  "Memory1"
	  SrcPort		  1
	  DstBlock		  "Out1"
	  DstPort		  1
	}
	Line {
	  SrcBlock		  "S-Function"
	  SrcPort		  2
	  DstBlock		  "Memory1"
	  DstPort		  1
	}
      }
    }
    Block {
      BlockType		      Outport
      Name		      "Out1"
      Position		      [185, 43, 215, 57]
      Port		      "1"

Modified mttroot/mtt/lib/rep/sfun_rep/mex_ae.c.tmpl from [4178a7adf7] to [797312fca9].

1
2
3
4
5
6
7
8
9
10
11
12
13

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













+







/* -*-c-*-	Put emacs into c-mode
 * <mtt_model_name>_sfun_ae.c:
 * Matlab mex algebraic equations for <mtt_model_name>
 */

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <mex.h>
#include "sfun_debug.h"
#include "useful-functions.hh"
#include "<mtt_model_name>_def.h"
#include "<mtt_model_name>_sympar.h"
#include "<mtt_model_name>_cr.h"

/* utility procedures */

double *
array_of_double (size_t n)
{
  void *p = calloc (n, sizeof (double));

Modified mttroot/mtt/lib/rep/sfun_rep/sfun.c.tmpl from [e8393fa8d4] to [79b281c10a].

10
11
12
13
14
15
16

17
18
19
20
21
22
23
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24







+







#include <stdio.h>
#include <stdlib.h>
#include "simstruc.h"
#include "sfun_debug.h"
#include "useful-functions.hh"
#include "<mtt_model_name>_def.h"
#include "<mtt_model_name>_sympar.h"
#include "<mtt_model_name>_cr.h"

static double *mttdx;		/* pointer to rates */
static double *mttu;		/* pointer to inputs */
static double *mttpar;		/* pointer to parameters */
static double *mttx;		/* pointer to states */
static double *mtty;		/* pointer to outputs */
static double *mttyz;		/* pointer to residuals */
160
161
162
163
164
165
166
167
168


169
170
171
172
173
174
175
161
162
163
164
165
166
167


168
169
170
171
172
173
174
175
176







-
-
+
+







  mxSetName (MTT_MATLAB_P, "MTT_P");
  p = mxGetPr (MTT_MATLAB_P);
  for (i = 0; i < MTTNPAR; i++) {
    p[i] = mttpar[i];
  }
  mexPutArray (MTT_MATLAB_P, "base");

  /* call fsolve */
  mexEvalString ("MTT_Ui = fsolve (@<mtt_model_name>_sfun_ae, MTT_Ui, optimset('display','off'), MTT_X, MTT_U, MTT_T, MTT_P);");
  /* call solver */
  mexEvalString ("MTT_Ui = lsqnonlin (@<mtt_model_name>_sfun_ae, MTT_Ui, [], [], optimset('display','off','diagnostics','off','TolX',1e-2,'TolFun',1e-2), MTT_X, MTT_U, MTT_T, MTT_P);");

  /* retrieve result */
  MTT_MATLAB_Ui = mexGetArray ("MTT_Ui", "base");
  p = mxGetPr (MTT_MATLAB_Ui);
  for (i = 0; i < MTTNYZ; i++) {
    mttu[MTTNU + i] = p[i];
  }

Modified mttroot/mtt/lib/rep/sfun_rep/sfun_input.c.tmpl from [1b479e7eb4] to [37d9259f60].

10
11
12
13
14
15
16

17
18
19
20
21
22
23
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24







+







#include <stdio.h>
#include <stdlib.h>
#include "simstruc.h"
#include "sfun_debug.h"
#include "useful-functions.hh"
#include "<mtt_model_name>_def.h"
#include "<mtt_model_name>_sympar.h"
#include "<mtt_model_name>_cr.h"

static double *mttu;		/* pointer to inputs */
static double *mttpar;		/* pointer to parameters */
static double *mttx;		/* pointer to states */
static double *mtty;		/* pointer to outputs */
static double  mttt;		/* time */


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