Overview
Comment:Now recursively does causality on subsystems.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 0476f9f15253359a5d8d4da4a70161681dcbf6b275cd4a7d81bd75d7610b0021
User & Date: gawthrop@users.sourceforge.net on 1996-08-05 15:41:41
Other Links: branch diff | manifest | tags
Context
1996-08-05
18:12:25
Initial revision check-in: 8024abf9e9 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
15:41:41
Now recursively does causality on subsystems. check-in: 0476f9f152 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
12:22:16
Initial revision check-in: f15a184147 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/m/abg2cbg.m from [ffe620077d] to [88d6038942].

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
function [bonds,status] = abg2cbg(system_name,bonds,infofile)


% [bonds,status] = abg2cbg(system_name,bonds,infofile)
% 
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%     %%%%% Model Transformation Tools %%%%%
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% Matlab function  abg2cbg.m
% Acausal bond graph to causal bond graph: mfile format

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



% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


pc = '%';
if nargin<3








  infofile = 'stdout';
end;

% Evaluate the system function to get the bonds
fun_name = [system_name, '_abg']


if exist(fun_name)~=2
  mtt_info(['m-file ', fun_name, ' does not exist'], infofile);
  bonds = [];
  status = [];






else




  eval(['[bonds,components]=', 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);



















  % Set initial status
  status = -ones(n_components,1);
  total = 2*n_bonds;
  done = sum(sum(abs(bonds)))/total*100;
  mtt_info(sprintf('Initial causality is %3.0f%s complete.', done, pc), infofile);


  old_done = inf;

  while done~=old_done
    disp(sprintf('Causality is %3.0f%s complete.', done, pc));
    old_done = done;

    for i = 1:n_components
      comp = nozeros(components(i,:));
      bond_list = abs(comp);
      direction = sign(comp)'*[1 1];
      % Convert from arrow orientated to component orientated causality
      comp_bonds = bonds(bond_list,:).*direction;
      eval([ '[comp_type,name,cr,arg] = ', system_name, '_cmp(i);' ]);
      % change name of 0 and 1 components -- matlab doesn't like numbers here
      if strcmp(comp_type,'0')
	comp_type = 'zero';
      end;
      if strcmp(comp_type,'1')
	comp_type = 'one';
      end;
      
      % Invoke  the appropriate causality procedure
      cause_name = [comp_type, '_cause'];
      if exist(cause_name)~=2 % Try a compound component -- need doing
       mtt_info(sprintf('Component %s is unknown', comp_type), infofile);
% $$$ 	sys_name = [comp_type, '_abg'];
% $$$ 	agb2cbg(sys_name,comp_bonds,infofile);


      else % its a simple component
	cause_name
	eval([ '[comp_bonds,status(i)] = ', cause_name, '(comp_bonds);' ]);
        % Convert from component orientated to arrow orientated causality
	bonds(bond_list,:) = comp_bonds.*direction; 
      end;
    end;

    done = sum(sum(abs(bonds)))/total*100;
%  mtt_info(sprintf('Causality is %3.0f%s complete.', done, pc), infofile);

  end;
end;

final_done =  (sum(status==zeros(n_components,1))/n_components)*100;;

mtt_info(sprintf('Final causality is %3.0f%s complete.', final_done, pc),
infofile);

% List overcausal bonds
[over_causal_bonds,n] = getindex(status,1)
if n>0
  for i=over_causal_bonds'
    eval([ '[comp_type,name] = ', system_name, '_cmp(i);' ]);
    mtt_info(sprintf('Component %s (%s) is overcausal', name, comp_type), ...
      infofile);
  end;
end;

% List undercausal bonds
[under_causal_bonds,n] = getindex(status,-1)
if n>0
  for i=under_causal_bonds'
    eval([ '[comp_type,name] = ', system_name, '_cmp(i);' ]);
    mtt_info(sprintf('Component %s (%s) is undercausal', name, comp_type), ...
      infofile);
  end;
end;















|
>
>
|













>
>
>




|
>
>
>
>
>
>
>
>



<
|
>
>




>
>
>
>
>
>

>
>
>
>
|

|
|
|
|
|

>
|
|
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|

>
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|










|









|





|

|
<
<
<
<







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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162




163
164
165
166
167
168
169
function [bonds, status] = abg2cbg(system_name, ...
    system_type, full_name, ...
    port_bonds,infofile)
% [bonds,status] = abg2cbg(system_name,infofile)
% 
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%     %%%%% Model Transformation Tools %%%%%
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% Matlab function  abg2cbg.m
% Acausal bond graph to causal bond graph: mfile format

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Version control history
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% $Id$
% %% $Log$
% %% Revision 1.1  1996/08/04 17:55:55  peter
% %% Initial revision
% %%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


pc = '%';
if nargin<1
  system_name = 'no_name';
end;

if nargin<4
  port_bonds = [];
end;

if nargin<5
  infofile = 'stdout';
end;


fun_name = [system_type, '_abg']

% If no such function - then there is nothing to be done.
if exist(fun_name)~=2
  mtt_info(['m-file ', fun_name, ' does not exist'], infofile);
  bonds = [];
  status = [];
  return
end;

% Create the (full) system name
if length(full_name)==0
  full_name = system_name;
else
  full_name = [full_name, '_', system_name];
end;

% Evaluate the system function to get the bonds
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;

% Find number of port bonds
[n_port_bonds,columns] = size(port_bonds);
if n_port_bonds~=n_ports
  mtt_info(sprintf('%1.0f port bonds incompatible with %1.0f ports', ...
      n_port_bonds, n_ports), infofile);
else % Copy the port bonds
  for i = 1:n_ports
    bonds(i,:) = port_bonds(i,:);
  end;
end;

bonds,port_bonds



% Set initial status
status = -ones(n_components,1);
total = 2*n_bonds;
done = sum(sum(abs(bonds)))/total*100;
% $$$ mtt_info(sprintf('Initial causality is %3.0f%s complete.', done, pc), infofile);

% Set the causality of the ports
old_done = inf;

while done~=old_done
  disp(sprintf('Causality is %3.0f%s complete.', done, pc));
  old_done = done;
  
  for i = 1:n_components
    comp = nozeros(components(i,:));
    bond_list = abs(comp);
    direction = sign(comp)'*[1 1];
    % Convert from arrow orientated to component orientated causality
    comp_bonds = bonds(bond_list,:).*direction;
    eval([ '[comp_type,name,cr,arg] = ', system_type, '_cmp(i);' ]);
    % change name of 0 and 1 components -- matlab doesn't like numbers here
    if strcmp(comp_type,'0')
      comp_type = 'zero';
    end;
    if strcmp(comp_type,'1')
      comp_type = 'one';
    end;
    
    % Invoke  the appropriate causality procedure
    cause_name = [comp_type, '_cause'];
    if exist(cause_name)~=2 % Try a compound component
      disp('------------PUSH-----------------');
      [b,s] = abg2cbg(name, comp_type, full_name, comp_bonds, ...
	  infofile)
      status(i)=max(s);
      disp('------------POP-----------------');
    else % its a simple component
      cause_name
      eval([ '[comp_bonds,status(i)] = ', cause_name, '(comp_bonds);' ]);
      % Convert from component orientated to arrow orientated causality
      bonds(bond_list,:) = comp_bonds.*direction; 
    end;
  end;
  
  done = sum(sum(abs(bonds)))/total*100;
  %  mtt_info(sprintf('Causality is %3.0f%s complete.', done, pc), infofile);
  
end;


final_done =  (sum(status==zeros(n_components,1))/n_components)*100;;

mtt_info(sprintf('Final causality is %3.0f%s complete.', final_done, pc),
infofile);

% List overcausal bonds
[over_causal_bonds,n] = getindex(status,1)
if n>0
  for i=over_causal_bonds'
    eval([ '[comp_type,name] = ', system_type, '_cmp(i);' ]);
    mtt_info(sprintf('Component %s (%s) is overcausal', name, comp_type), ...
      infofile);
  end;
end;

% List undercausal bonds
[under_causal_bonds,n] = getindex(status,-1)
if n>0
  for i=under_causal_bonds'
    eval([ '[comp_type,name] = ', system_type, '_cmp(i);' ]);
    mtt_info(sprintf('Component %s (%s) is undercausal', name, comp_type), ...
      infofile);
  end;
end;

write_cbg(full_name,bonds,status);

disp('----------------------');












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