Overview
Comment:Coerces port bonds to have smae direction as the imposing bonds
_cbg now generates the (coerced) components as welll as the (coerced)
causality.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 52853415b7528858b2e0a0a89241b8bdd57eb94547542037ec1c98bdc1bdd83d
User & Date: gawthrop@users.sourceforge.net on 1998-04-04 10:46:37
Other Links: branch diff | manifest | tags
Context
1998-04-04
10:47:31
Uses (coerced) components from _cbg file - _abg not now used here. check-in: 493b29d531 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
10:46:37
Coerces port bonds to have smae direction as the imposing bonds
_cbg now generates the (coerced) components as welll as the (coerced)
causality.
check-in: 52853415b7 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
10:45:01
Don't do strokes on port bonds check-in: cc595a7941 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/m/abg2cbg.m from [869686270d] to [5a6470c9cc].

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
function [port_bonds, status] = abg2cbg(system_name, ...
    system_type, full_name, ...
    port_bonds, port_status, typefile, infofile)

% abg2cbg - acausal to causal bg conversion
%
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%     %%%%% Model Transformation Tools %%%%%
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% Matlab function  abg2cbg.m
% Acausal bond graph to causal bond graph: mfile format
% [bonds,status] = abg2cbg(system_name, system_type, full_name, port_bonds, infofile)

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Version control history
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% $Id$
% %% $Log$




% %% Revision 1.21  1997/08/18 16:25:25  peterg
% %% Minor bug fixes
% %%
% %% Revision 1.20  1997/08/18 12:45:24  peterg
% %% Replaced: comp_bonds = bonds(bond_list,:)
% %% by: 	for kk = 1:n_comp
% %% 	  comp_bonds(kk,:) = bonds(comp(kk),:);


|
















>
>
>
>







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
function [port_bonds, status] = abg2cbg(system_name, ...
    system_type, full_name, ...
    port_bonds, port_bond_direction, port_status, typefile, infofile)

% abg2cbg - acausal to causal bg conversion
%
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%     %%%%% Model Transformation Tools %%%%%
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% Matlab function  abg2cbg.m
% Acausal bond graph to causal bond graph: mfile format
% [bonds,status] = abg2cbg(system_name, system_type, full_name, port_bonds, infofile)

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Version control history
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% $Id$
% %% $Log$
% %% Revision 1.22  1997/08/19 10:21:09  peterg
% %% Only copy port cuaslity info if not already set within the
% %% subsystem. I thought I'd done this already ....
% %%
% %% Revision 1.21  1997/08/18 16:25:25  peterg
% %% Minor bug fixes
% %%
% %% Revision 1.20  1997/08/18 12:45:24  peterg
% %% Replaced: comp_bonds = bonds(bond_list,:)
% %% by: 	for kk = 1:n_comp
% %% 	  comp_bonds(kk,:) = bonds(comp(kk),:);
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162




























163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
  mtt_info(['m-file ', fun_name, ' does not exist'], infofile);
  bonds = [];
  status = [];
  return
end;

% Evaluate the system function to get the bonds and number of ports
eval(['[bonds,components,n_ports]=', fun_name, ';']);


% Find number of bonds
[n_bonds,columns] = size(bonds);
if (columns ~= 2)&(n_bonds>0)
  error('Incorrect bonds matrix: must have 2 columns');
end;

 
% Find number of components
[n_components,columns] = size(components);
if n_components==0 % there is nothing to be done
  return
end;





























% Set initial status
status = -ones(n_components,1);

% If not at top level, then copy the port bonds.
if ~at_top_level 
  % Find number of port bonds
  [n_port_bonds,columns] = size(port_bonds);

  % Check compatibility - if ok copy port bonds to the internal bonds list.
  if n_port_bonds~=n_ports
  mtt_info(sprintf('%s: %1.0f port bonds incompatible with %1.0f ports', ...
               full_name, n_port_bonds, n_ports), infofile);

  else % Copy the port bonds & status
    port_bond_index = abs(components(1:n_ports,1)) % relevant bond numbers
    for j = 1:n_port_bonds
      jj = port_bond_index(j);
      for k = 1:2
	if bonds(jj,k)==0 % only copy if not already set
	bonds(jj,k) = port_bonds(j,k);
	end;
      end;
      status(1:n_ports) = port_status;
    end
  end
else
  n_port_bonds=0;
end;
bonds,port_bonds

% Causality indicator
total = 2*n_bonds;
done = sum(sum(abs(bonds)))/total*100;

% Outer while loop sets preferred causality
ci_index=1; 







|
<













>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>















<













|







145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
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
  mtt_info(['m-file ', fun_name, ' does not exist'], infofile);
  bonds = [];
  status = [];
  return
end;

% Evaluate the system function to get the bonds and number of ports
eval(['[bonds,components,n_ports]=', fun_name, ',']);


% Find number of bonds
[n_bonds,columns] = size(bonds);
if (columns ~= 2)&(n_bonds>0)
  error('Incorrect bonds matrix: must have 2 columns');
end;

 
% Find number of components
[n_components,columns] = size(components);
if n_components==0 % there is nothing to be done
  return
end;

port_bond_direction

% Coerce the port (SS:[]) component bonds to have the same direction as
% of the bonds in the encapsulating system 
if n_ports>0
  port_bond_index = abs(components(1:n_ports,1)) % relevant bond numbers
  for i=1:n_ports
    % Is the direction different?
    if (sign(components(i,1))~=port_bond_direction(i))
      disp(sprintf("Flip port %i",i));
      % Flip direction at port
      components(i,1) = - components(i,1);
      % and at the other end
      for j=n_ports+1:n_components
	for k=1:columns
	  if (abs(components(j,k))==port_bond_index(i))
	    components(j,k) = - components(j,k);
	  end
	end
      end;
      % Flip the bond causalities (these are arrow-orientated)
      bonds(port_bond_index(i),:) = -bonds(port_bond_index(i),:);
    end
  end
end



% Set initial status
status = -ones(n_components,1);

% If not at top level, then copy the port bonds.
if ~at_top_level 
  % Find number of port bonds
  [n_port_bonds,columns] = size(port_bonds);

  % Check compatibility - if ok copy port bonds to the internal bonds list.
  if n_port_bonds~=n_ports
  mtt_info(sprintf('%s: %1.0f port bonds incompatible with %1.0f ports', ...
               full_name, n_port_bonds, n_ports), infofile);

  else % Copy the port bonds & status

    for j = 1:n_port_bonds
      jj = port_bond_index(j);
      for k = 1:2
	if bonds(jj,k)==0 % only copy if not already set
	bonds(jj,k) = port_bonds(j,k);
	end;
      end;
      status(1:n_ports) = port_status;
    end
  end
else
  n_port_bonds=0;
end;
% bonds,port_bonds

% Causality indicator
total = 2*n_bonds;
done = sum(sum(abs(bonds)))/total*100;

% Outer while loop sets preferred causality
ci_index=1; 
243
244
245
246
247
248
249


250
251
252
253
254
255
256
257
258

      % Invoke  the appropriate causality procedure
      if exist(cause_name)~=2 % Try a compound component
        % Port status depends on whether the corresponding bonds are
        %  fully causal at this stage.
        one = ones(n_bonds,1);
        port_status = (sum(abs(comp_bonds'))'==2*one) - one;


	[comp_bonds,s] = abg2cbg(name, comp_type, full_name, 
            comp_bonds, port_status, ...
	    typefile, infofile);
	
	% Create a single status from the status vector s
	if max(abs(s)) == 0 % Causal
	  status(i) = 0;
	else
	  if max(s) == 1 % At least one component is overcausal







>
>

|







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

      % Invoke  the appropriate causality procedure
      if exist(cause_name)~=2 % Try a compound component
        % Port status depends on whether the corresponding bonds are
        %  fully causal at this stage.
        one = ones(n_bonds,1);
        port_status = (sum(abs(comp_bonds'))'==2*one) - one;
	% Direction of bonds on the ports (0 if next to port)
	port_bond_direction = -sign(components(i,1:n_bonds))';
	[comp_bonds,s] = abg2cbg(name, comp_type, full_name, 
            comp_bonds, port_bond_direction, port_status, ...
	    typefile, infofile);
	
	% Create a single status from the status vector s
	if max(abs(s)) == 0 % Causal
	  status(i) = 0;
	else
	  if max(s) == 1 % At least one component is overcausal
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
  end;
end;

% $$$ file_name = [full_name, '_', system_type]
file_name = [full_name, '_cbg.m'];
disp(['Writing ', file_name]);
cbgfilenum = fopen(file_name,'w');
write_cbg(cbgfilenum,full_name,system_type,bonds,status);
fclose(cbgfilenum);

% Return the port bonds - arrow orientated causality
if ~at_top_level % Not at top level
  j = abs(components(1:n_ports,1)) %relevant bond numbers
  port_bonds = bonds(j,:)
end;

disp('====================================');
disp(['END: ', full_name, ' (', fun_name, ')']);
disp('====================================');








|


|









358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
  end;
end;

% $$$ file_name = [full_name, '_', system_type]
file_name = [full_name, '_cbg.m'];
disp(['Writing ', file_name]);
cbgfilenum = fopen(file_name,'w');
write_cbg(cbgfilenum,full_name,system_type,bonds,status,components);
fclose(cbgfilenum);

% Return the port bonds - arrow orientated causality - and the direction 
if ~at_top_level % Not at top level
  j = abs(components(1:n_ports,1)) %relevant bond numbers
  port_bonds = bonds(j,:)
end;

disp('====================================');
disp(['END: ', full_name, ' (', fun_name, ')']);
disp('====================================');


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