Overview
Comment:Added causal stroke information to ibg.m
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 99a7320daf3784935a207d12407a0c5792b5e8c20234338dd5e0070311b5c011
User & Date: geraint@users.sourceforge.net on 2003-01-07 21:47:35
Other Links: branch diff | manifest | tags
Context
2003-01-09
09:57:42
Added dummy first argument (comp_type) to cr check-in: c76c510fa6 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
2003-01-07
21:47:35
Added causal stroke information to ibg.m check-in: 99a7320daf user: geraint@users.sourceforge.net tags: origin/master, trunk
18:09:21
More informative error message. check-in: d2cfe6e011 user: geraint@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/m/rbg2ibg.m from [5558cbb136] to [4291baf4d9].

71
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
	     port_coord(i,1)/scale, port_coord(i,2)/scale, \
	     deblank(port_name(i,:))));
    endif
    
    ## The (signed) bond corresponding to the ith port label
    port_bond(i) = near_bond(1) * sign(1.5 - near_bond(2));
  endfor
  
  port_bond

  ## Now have (signed) bond (port_bond(i)) corresponding to the ith port
  ## Create inverse mapping
  for i = 1:n_bonds
    eval(sprintf('bond_port_head%i = "[]"', i))
    eval(sprintf('bond_port_tail%i = "[]"', i))
  endfor  
  for i = 1:n_ports







<

>







71
72
73
74
75
76
77

78
79
80
81
82
83
84
85
86
	     port_coord(i,1)/scale, port_coord(i,2)/scale, \
	     deblank(port_name(i,:))));
    endif
    
    ## The (signed) bond corresponding to the ith port label
    port_bond(i) = near_bond(1) * sign(1.5 - near_bond(2));
  endfor

  port_bond

  ## Now have (signed) bond (port_bond(i)) corresponding to the ith port
  ## Create inverse mapping
  for i = 1:n_bonds
    eval(sprintf('bond_port_head%i = "[]"', i))
    eval(sprintf('bond_port_tail%i = "[]"', i))
  endfor  
  for i = 1:n_ports
95
96
97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
  
  ## Locate the components at the ends of each bond
  ## col 1 of comp_near_bond contains component nearest to the arrow end
  ## col 2 of comp_near_bond contains component nearest other end
  for i = 1:n_bonds
    comp_near_bond(i,:) = adjcomp(arrow_end(i,:), other_end(i,:), \
				  rcomponents);
    [hc_type, hc_name] = eval([name, '_cmp(comp_near_bond(i,1))']);
    [tc_type, tc_name] = eval([name, '_cmp(comp_near_bond(i,2))']);
  endfor


  ## Deduce causality from the strokes (if any)
  causality = zeros(n_bonds,2);
  if (n_strokes > 0)
    ## Find location of centre and ends of stroke
    stroke_end_1	= [rstrokes(:,1), rstrokes(:,2)];
    stroke_end_2	= [rstrokes(:,3), rstrokes(:,4)];







<
<

>







95
96
97
98
99
100
101


102
103
104
105
106
107
108
109
110
  
  ## Locate the components at the ends of each bond
  ## col 1 of comp_near_bond contains component nearest to the arrow end
  ## col 2 of comp_near_bond contains component nearest other end
  for i = 1:n_bonds
    comp_near_bond(i,:) = adjcomp(arrow_end(i,:), other_end(i,:), \
				  rcomponents);


  endfor
  comp_near_bond

  ## Deduce causality from the strokes (if any)
  causality = zeros(n_bonds,2);
  if (n_strokes > 0)
    ## Find location of centre and ends of stroke
    stroke_end_1	= [rstrokes(:,1), rstrokes(:,2)];
    stroke_end_2	= [rstrokes(:,3), rstrokes(:,4)];
142
143
144
145
146
147
148

149
150
151



152
153
154
155

156
157







158
159







160



161
162
      else			# bi-causal stroke
	stroke_direction = stroke(1,:) - stroke(stroke_index(1),:);
	flow_side = stroke_direction * arrow_vector(j,:)' > 0;
	causality(j,1+flow_side) = 2 * which_end - 1;
      endif
    endfor
  endif


  ## Return data
  for i = 1:n_bonds



    eval(sprintf("bonds.bond%i.head.component\t= '%s:%s'", i, hc_type, \
		 hc_name));
    eval(sprintf("bonds.bond%i.tail.component\t= '%s:%s'", i, tc_type, \
		 tc_name));

    eval(sprintf("bonds.bond%i.head.ports\t= bond_port_head%i", i, i));
    eval(sprintf("bonds.bond%i.tail.ports\t= bond_port_tail%i", i, i));







  endfor
  







  



  
endfunction







>

|

>
>
>




>


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

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
      else			# bi-causal stroke
	stroke_direction = stroke(1,:) - stroke(stroke_index(1),:);
	flow_side = stroke_direction * arrow_vector(j,:)' > 0;
	causality(j,1+flow_side) = 2 * which_end - 1;
      endif
    endfor
  endif
  causality

  ## Write data
  for i = 1:n_bonds
    [hc_type, hc_name] = eval([name, '_cmp(comp_near_bond(i,1))']);
    [tc_type, tc_name] = eval([name, '_cmp(comp_near_bond(i,2))']);
    ## components
    eval(sprintf("bonds.bond%i.head.component\t= '%s:%s'", i, hc_type, \
		 hc_name));
    eval(sprintf("bonds.bond%i.tail.component\t= '%s:%s'", i, tc_type, \
		 tc_name));
    ## ports
    eval(sprintf("bonds.bond%i.head.ports\t= bond_port_head%i", i, i));
    eval(sprintf("bonds.bond%i.tail.ports\t= bond_port_tail%i", i, i));
    ## causality
    if (causality(i,1) == 1)
      effort_causality = "head"
    elseif (causality(i,1) == -1)
      effort_causality = "tail"
    else
      effort_causality = "none"
    endif

    if (causality(i,2) == 1)
      flow_causality = "tail"
    elseif (causality(i,2) == -1)
      flow_causality = "head"
    else
      flow_causality = "none"
    endif
    
    eval(sprintf("bonds.bond%i.causality.effort\t= '%s'", i, effort_causality));
    eval(sprintf("bonds.bond%i.causality.flow\t= '%s'", i, flow_causality));
  endfor

endfunction

Modified mttroot/mtt/bin/trans/m/write_ibg.m from [8fcc691ebd] to [65712522f3].

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
  format_hp = "  %s.bonds.b%i.head.ports\t= \"%s\";\n";
  format_tp = "  %s.bonds.b%i.tail.ports\t= \"%s\";\n";
  format_ce = "  %s.bonds.b%i.causality.effort\t= \"%s\";\n";
  format_cf = "  %s.bonds.b%i.causality.flow\t= \"%s\";\n";

  fprintf(fid, "## -*-octave-*-\n\n");
  fprintf(fid, "function [%s] = %s_ibg\n\n", system_name, system_name);
  fprintf(fid, "## Intermediate bond graph representation of %s\n", \
	  system_name);

  fprintf(fid, "## Generated by MTT on %s\n", ctime(time));




  for i=1:nbonds
    fprintf(fid, "\n  ## bond %i\n", i);
    fprintf(fid, format_hc, system_name, i, \
	    eval(sprintf("bonds.bond%i.head.component", i)));
    fprintf(fid, format_tc, system_name, i, \
	    eval(sprintf("bonds.bond%i.tail.component", i)));
    fprintf(fid, format_hp, system_name, i, \
	    eval(sprintf("bonds.bond%i.head.ports", i)));
    fprintf(fid, format_tp, system_name, i, \
	    eval(sprintf("bonds.bond%i.tail.ports", i)));
    fprintf(fid, format_ce, system_name, i, "FIXME");

    fprintf(fid, format_cf, system_name, i, "FIXME");

  endfor;

  fprintf(fid, "\nendfunction\n");
  fclose(fid);

endfunction;







|


|
>
>
>











|
>
|
>






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
  format_hp = "  %s.bonds.b%i.head.ports\t= \"%s\";\n";
  format_tp = "  %s.bonds.b%i.tail.ports\t= \"%s\";\n";
  format_ce = "  %s.bonds.b%i.causality.effort\t= \"%s\";\n";
  format_cf = "  %s.bonds.b%i.causality.flow\t= \"%s\";\n";

  fprintf(fid, "## -*-octave-*-\n\n");
  fprintf(fid, "function [%s] = %s_ibg\n\n", system_name, system_name);
  fprintf(fid, "  ## Intermediate bond graph representation of %s\n", \
	  system_name);

  fprintf(fid, "  ## Generated by MTT on %s\n", ctime(time));
  fprintf(fid, "  ## head refers to the harpoon end of a bond\n");
  fprintf(fid, "  ## tail refers to the other end of a bond\n");
  fprintf(fid, "  ## causality.? is the end at which ? is imposed\n\n");

  for i=1:nbonds
    fprintf(fid, "\n  ## bond %i\n", i);
    fprintf(fid, format_hc, system_name, i, \
	    eval(sprintf("bonds.bond%i.head.component", i)));
    fprintf(fid, format_tc, system_name, i, \
	    eval(sprintf("bonds.bond%i.tail.component", i)));
    fprintf(fid, format_hp, system_name, i, \
	    eval(sprintf("bonds.bond%i.head.ports", i)));
    fprintf(fid, format_tp, system_name, i, \
	    eval(sprintf("bonds.bond%i.tail.ports", i)));
    fprintf(fid, format_ce, system_name, i, \
	    eval(sprintf("bonds.bond%i.causality.effort", i)));
    fprintf(fid, format_cf, system_name, i, \
	    eval(sprintf("bonds.bond%i.causality.flow", i)));
  endfor;

  fprintf(fid, "\nendfunction\n");
  fclose(fid);

endfunction;


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