1
2
3
4
5
6
7
8
|
function [known] = mtt_component_eqn (fullname, port, causality, \
known, Cbg)
## function [known] = mtt_component_eqn (fullname, port, causality, known)
##
## Recursively finds the equations giving the signal of specified
## causality on the specified port of component named "name" within
## subsystem Name
|
|
|
1
2
3
4
5
6
7
8
|
function [known] = mtt_component_eqn (fullname, port, causality, ...
known, Cbg)
## function [known] = mtt_component_eqn (fullname, port, causality, known)
##
## Recursively finds the equations giving the signal of specified
## causality on the specified port of component named "name" within
## subsystem Name
|
︙ | | | ︙ | |
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
if port>N_ports
error(sprintf("port (%i) > N_ports (%i)", port, N_ports));
else # Get name and find equation
name = deblank(cbg.portlist(port,:));
if DEBUG
disp("----> lower-level system")
endif
known = mtt_component_eqn (mtt_fullname(Name,name), 1, \
causality, known, cbg);
return
endif
endif
## Other causality representations
|
|
|
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
if port>N_ports
error(sprintf("port (%i) > N_ports (%i)", port, N_ports));
else # Get name and find equation
name = deblank(cbg.portlist(port,:));
if DEBUG
disp("----> lower-level system")
endif
known = mtt_component_eqn (mtt_fullname(Name,name), 1, ...
causality, known, cbg);
return
endif
endif
## Other causality representations
|
︙ | | | ︙ | |
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
## A useful composite name
name_port_cause = sprintf("%s_%i_%s",name, port, cause);
full_name_port_cause = mtt_fullname(Name,name_port_cause);
## If value is known, don't do anything.
if findstr(sprintf(" %s ", full_name_port_cause), known)>0
eqn = sprintf("%s The %s signal on port %i of %s is known already", \
CD, causality, port, name);
return
else # Add to list
known = sprintf("%s %s", known, full_name_port_cause);
endif
|
|
|
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
## A useful composite name
name_port_cause = sprintf("%s_%i_%s",name, port, cause);
full_name_port_cause = mtt_fullname(Name,name_port_cause);
## If value is known, don't do anything.
if findstr(sprintf(" %s ", full_name_port_cause), known)>0
eqn = sprintf("%s The %s signal on port %i of %s is known already", ...
CD, causality, port, name);
return
else # Add to list
known = sprintf("%s %s", known, full_name_port_cause);
endif
|
︙ | | | ︙ | |
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
bonds = cbg.bonds;
## List of component bond causality (component-orientated causality)
comp_bonds = bonds(bond_list,:).*directions; # Component bonds
## What components are at the other ends of the in bonds?
## Effort
[in_e_bonds,in_e_components,in_e_ports,N_e] = mtt_component_inputs \
(name,comp_type,causality,"effort",comp_bonds,connections,cbg);
## Flow
[in_f_bonds,in_f_components,in_f_ports,N_f] = mtt_component_inputs \
(name,comp_type,causality,"flow",comp_bonds,connections,cbg);
##Composite values
N_ef = N_e + N_f;
in_ef_bonds = [in_e_bonds; in_f_bonds];
in_ef_components = [in_e_components; in_f_components];
|
|
|
|
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
bonds = cbg.bonds;
## List of component bond causality (component-orientated causality)
comp_bonds = bonds(bond_list,:).*directions; # Component bonds
## What components are at the other ends of the in bonds?
## Effort
[in_e_bonds,in_e_components,in_e_ports,N_e] = mtt_component_inputs ...
(name,comp_type,causality,"effort",comp_bonds,connections,cbg);
## Flow
[in_f_bonds,in_f_components,in_f_ports,N_f] = mtt_component_inputs ...
(name,comp_type,causality,"flow",comp_bonds,connections,cbg);
##Composite values
N_ef = N_e + N_f;
in_ef_bonds = [in_e_bonds; in_f_bonds];
in_ef_components = [in_e_components; in_f_components];
|
︙ | | | ︙ | |
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
## Find its equation
if DEBUG
disp("----> higher level system")
endif
known = mtt_component_eqn (mtt_fullname(new_Name,in_name), \
in_port, causality, known, cbg);
LHS = Source_seqn ("external",Name);
RHS = varname(NAME, abs(in_bond), i_cause);
eqn = sprintf("%s%s%s := %s;", LHS, SD, name, RHS);
if !DEBUG
comment = sprintf("%s PORT", CD);
disp(sprintf("%s\n%s",comment, eqn));
endif
endif
## Handle special components
if strcmp(comp_type,"0")||strcmp(comp_type,"1") # Junctions
[eqn,insigs,innames] = junction_seqn (comp_type,Name, outsig, \
insigs, innames);
else # Everything else
if exist(sprintf("%s_cause", comp_type)) # Simple component
## Do the equations
[eqn,insigs,innames] = eval(sprintf("%s_seqn (Name, name, cr, \
arg, outsig, \
insigs, \
innames, is_port_output);", \
comp_type));
## Resolve CR
eqn = mtt_resolve_cr(eqn);
else # Compound component
new_NAME = Name;
new_Name = mtt_fullname(Name,name);
|
|
|
|
|
|
|
|
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
## Find its equation
if DEBUG
disp("----> higher level system")
endif
known = mtt_component_eqn (mtt_fullname(new_Name,in_name), ...
in_port, causality, known, cbg);
LHS = Source_seqn ("external",Name);
RHS = varname(NAME, abs(in_bond), i_cause);
eqn = sprintf("%s%s%s := %s;", LHS, SD, name, RHS);
if !DEBUG
comment = sprintf("%s PORT", CD);
disp(sprintf("%s\n%s",comment, eqn));
endif
endif
## Handle special components
if strcmp(comp_type,"0")||strcmp(comp_type,"1") # Junctions
[eqn,insigs,innames] = junction_seqn (comp_type,Name, outsig, ...
insigs, innames);
else # Everything else
if exist(sprintf("%s_cause", comp_type)) # Simple component
## Do the equations
[eqn,insigs,innames] = eval(sprintf("%s_seqn (Name, name, cr, ...
arg, outsig, ...
insigs, ...
innames, is_port_output);", ...
comp_type));
## Resolve CR
eqn = mtt_resolve_cr(eqn);
else # Compound component
new_NAME = Name;
new_Name = mtt_fullname(Name,name);
|
︙ | | | ︙ | |
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
RHS = Sensor_seqn ("external",new_Name);
eqn = sprintf("%s := %s%s%s;", LHS, RHS, SD, port_name);
if DEBUG
disp("----> same-level subsystem")
endif
[known] = mtt_component_eqn \
(mtt_fullname(new_Name,new_name), port, causality, known, cbg);
endif
endif
comment = \
sprintf("%s Equation for %s signal on port %i of %s (%s), subsystem %s.", \
CD, causality, port, name, comp_type, Name);
if DEBUG
disp(sprintf("%s\n%s",comment, eqn));
endif
is_external = mtt_is_external(comp_type,outsig, insigs, is_port_output);
|
|
|
|
|
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
RHS = Sensor_seqn ("external",new_Name);
eqn = sprintf("%s := %s%s%s;", LHS, RHS, SD, port_name);
if DEBUG
disp("----> same-level subsystem")
endif
[known] = mtt_component_eqn ...
(mtt_fullname(new_Name,new_name), port, causality, known, cbg);
endif
endif
comment = ...
sprintf("%s Equation for %s signal on port %i of %s (%s), subsystem %s.", ...
CD, causality, port, name, comp_type, Name);
if DEBUG
disp(sprintf("%s\n%s",comment, eqn));
endif
is_external = mtt_is_external(comp_type,outsig, insigs, is_port_output);
|
︙ | | | ︙ | |
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
other_port = insigs(i,3);
other_name = deblank(innames(i,:));
if DEBUG
disp("----> same-level component")
endif
[known] = mtt_component_eqn \
(mtt_fullname(Name,other_name), other_port, other_causality, \
known, cbg);
endfor
endif
## Write this signal
##comment_2 = sprintf("Connected to:%s", in_component_list);
if !DEBUG
disp(sprintf("%s\n%s",comment, eqn));
endif
endfunction
|
|
|
|
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
other_port = insigs(i,3);
other_name = deblank(innames(i,:));
if DEBUG
disp("----> same-level component")
endif
[known] = mtt_component_eqn ...
(mtt_fullname(Name,other_name), other_port, other_causality, ...
known, cbg);
endfor
endif
## Write this signal
##comment_2 = sprintf("Connected to:%s", in_component_list);
if !DEBUG
disp(sprintf("%s\n%s",comment, eqn));
endif
endfunction
|