Overview
Comment: | Octave m files for generating sorted equations _sese.r |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | origin/master | trunk |
Files: | files | file ages | folders |
SHA3-256: |
0e41d1033ca447759fa16492b0188ee9 |
User & Date: | gawthrop@users.sourceforge.net on 2003-03-13 15:32:37 |
Other Links: | branch diff | manifest | tags |
Context
2003-03-13
| ||
15:43:36 | Helper for _sese generation check-in: 5d463df513 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
15:32:37 | Octave m files for generating sorted equations _sese.r check-in: 0e41d1033c user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
15:19:04 | Now uses __ to delimit subsystems in names. check-in: 2cf0c97f97 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
Changes
Added mttroot/mtt/bin/trans/m/mtt_check_sigs.m version [f2ac476a38].
> > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | function N = mtt_check_sigs (outsig,insigs) ## usage: N = mtt_check_sigs (outsig,insigs) ## ## ## A signal has the columns: bond number signal causality (+1 or -1) ## and component port number M=3; ## Sanity check [N_out,M_out] = size(outsig); if N_out<>1 error("There must be exactly one outbond"); endif [N_in,M_in] = size(insigs); if (M_out!=M)||(M_in!=M) error(sprintf("There must be exactly %i elements to a bond (number, causality, port)",M)); endif N = N_in; endfunction |
Added mttroot/mtt/bin/trans/m/mtt_component_eqn.m version [adbc638c46].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 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 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 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 282 283 284 285 286 287 288 289 290 291 292 | function [known] = mtt_component_eqn (fullname, port, causality, known) ## 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 ## fullname: name of component and subsystem ## port: port number of component ## causality: effort or flow ## know_list: list of components already known ## Data structures. ## A signal is a row vector containing three numbers: ## Index -- a unique (within a subsystem) signed integer ## abs(index) is the unique bond number, sign is the direction. ## Causality -- 1 for effort, -1 for flow ## Port -- the port of the component to which it is connected. ## [Name,name] = mtt_subname(fullname); # Split fullname SD = "__"; # Subsystem delimiter CD = "\n%%"; # Comment delimiter DEBUG = 0; if DEBUG disp("======================================="); fullname, name, Name, port,causality,known endif eqn="## No equation -- something wrong"; # Default if length(known)<2 # Invalid known = " "; endif ## File containing data structure cbg_file = sprintf("%s_cbg",Name); if (exist(cbg_file)==0) error(sprintf("mtt_component_eqn: subystem \"%s\" does not exist", Name)); endif ## Subsystem data structure cbg = eval(sprintf("%s;", cbg_file)); if struct_contains (cbg, "ports") ## Combine ports with the other subsystems for [component_structure, component] = cbg.ports eval(sprintf("cbg.subsystems.%s=cbg.ports.%s;",component,component)); endfor endif ## Call to a subsystem (represented by name="") if strcmp(name,"") if !struct_contains(cbg,"portlist") N_ports = 0; else [N_ports,M_ports] = size(cbg.portlist); endif 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); return endif endif ## Other causality representations if strcmp(causality,"effort") i_cause = 1; othercausality = "flow"; index_cause = 1; cause = "e"; elseif strcmp(causality,"flow") i_cause = -1; othercausality = "effort"; index_cause = 2; cause = "f"; else error(sprintf("mtt_component_eqn: causality %s invalid", causality)); endif ## 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 ## Component type comp_type = eval(sprintf("cbg.subsystems.%s.type;", name)); if DEBUG comp_type endif ## Component cr cr = eval(sprintf("cbg.subsystems.%s.cr;", name)); ## Component arg arg = eval(sprintf("cbg.subsystems.%s.arg;", name)); ## To which bond(s) is the component connected? connections = eval(sprintf("cbg.subsystems.%s.connections;", name)); bond_list = abs(connections); # Unsigned list out_bond_number = bond_list(port); # The bond at the output of this component direction = sign(connections); # Bond directions directions = direction'*[1 1]; ## List of system bonds 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]; in_ef_ports = [in_e_ports; in_f_ports]; in_causality = [ones(N_e,1); -ones(N_f,1)]; ## Lists of signals relevant to this component outsig = [out_bond_number i_cause port]; insigs = [in_ef_bonds in_causality in_ef_ports]; innames = in_ef_components; if DEBUG outsig insigs innames endif ## Is the signal the output of a port? is_port_output = 0; # Default if struct_contains (cbg, "ports") if struct_contains (cbg.ports,name) is_port_output = (outsig(2)!=insigs(1,2)); endif endif if is_port_output ## Which port (number) is it? [N_ports,M_ports] = size(cbg.portlist); for i=1:N_ports if strcmp(deblank(cbg.portlist(i,:)), name) port_index = i; break; endif endfor ## File containing data structure NAME = mtt_subname(Name); Cbg_file = sprintf("%s_cbg",NAME); if (exist(Cbg_file)==0) error(sprintf("mtt_component_eqn: subsystem %s does not exist", NAME)); endif ## System data structure Cbg = eval(sprintf("%s;", Cbg_file)); ## And to which component (at higher level) is it connected? [new_Name,new_name] = mtt_subname(Name); port_bond = eval(sprintf("Cbg.subsystems.%s.connections(%i);", new_name, port_index)); [in_name, in_port, in_bond] = mtt_other_end (new_name,port_bond,Cbg); ## Find its equation if DEBUG disp("----> higher level system") endif known = mtt_component_eqn (mtt_fullname(new_Name,in_name), in_port, causality, known); 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);", comp_type)); else # Compound component new_NAME = Name; new_Name = mtt_fullname(Name,name); new_name = ""; ## File containing data structure Cbg_file = sprintf("%s_cbg",new_Name); if (exist(Cbg_file)==0) error(sprintf("mtt_component_eqn: subsystem %s does not exist", new_Name)); endif ## System data structure Cbg = eval(sprintf("%s;", Cbg_file)); port_name = Cbg.portlist(port,:); LHS = varname(Name, outsig(1,1), outsig(1,2)); 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); 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); if !is_external ## Find the corresponding input equations [N_other,M_other] = size(insigs); for i = 1:N_other if insigs(i,2)==1 other_causality = "effort"; else other_causality = "flow"; endif 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); 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 |
Added mttroot/mtt/bin/trans/m/mtt_component_inputs.m version [654cc2c381].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 [in_bonds,in_components,in_ports,N] = mtt_component_inputs \ (name,comp_type, out_causality, causality,comp_bonds,bond_list,cbg) ## usage: [in_bonds,in_components,in_ports,N] = mtt_component_inputs ## (name,comp_type, out_causality, causality,comp_bonds,bond_list,cbg) ## ## ## Other causality representations if strcmp(causality,"effort") if strcmp(causality,"effort") i_cause = 1; othercausality = "flow"; index_cause = 1; elseif strcmp(causality,"flow") i_cause = -1; othercausality = "effort"; index_cause = 2; else error(sprintf("mtt_component_eqn: causality %s invalid", causality)); endif in_index = find(comp_bonds(:,index_cause)==i_cause); all_in_bonds = bond_list(in_index); N_all = length(all_in_bonds); ## What components are at the other ends of the in bonds? [in_components,in_ports,in_bonds] = mtt_other_end (name,all_in_bonds,cbg); N = length(in_bonds); endfunction |
Added mttroot/mtt/bin/trans/m/mtt_fullname.m version [95049fcb51].
> > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 | function fullname = mtt_fullname (subname,compname) ## usage: fullname = mtt_fullname (subname,compname) ## ## Finds the standard mtt name of the component delim = "__"; fullname = sprintf("%s%s%s", subname, delim, compname); endfunction |
Added mttroot/mtt/bin/trans/m/mtt_is_external.m version [07ce2338e2].
> > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | function is_external = mtt_is_external (comp_type,outsig, insigs, is_port) ## usage: is_external = mtt_is_external (comp_type,outsig, insigs) ## ## if nargin<4 is_port = 0; endif is_external = 0; # Default if strcmp(comp_type,"SS"); is_external = insigs(1,2)!=outsig(2); else is_external = 0; endif endfunction |
Added mttroot/mtt/bin/trans/m/mtt_name2names.m version [38b510c144].
> > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 | function names = mtt_name2names (name) ## usage: names = mtt_name2names (name) ## ## Converts standard mtt name to an array of subsystem names ## Copyright (C) 2003 by Peter J. Gawthrop delim ="__"; # MTT delimiter names = split(name,delim); endfunction |
Added mttroot/mtt/bin/trans/m/mtt_names2name.m version [569f4874eb].
> > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | function name = mtt_names2name (names) ## usage: name = names2name (names) ## ## Converts array of subsystem names to a standard mtt name delim ="__"; # MTT delimiter [n,m] = size(names); name = deblank(names(1,:)); for i = 2:n name = sprintf("%s%s%s", name, delim, deblank(names(i,:))); endfor endfunction |
Added mttroot/mtt/bin/trans/m/mtt_other_causality.m version [1f9cfc8d6c].
> > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | function other = mtt_other_causality (causality) ## usage: other = mtt_other_causality (causality) ## ## causality = deblank(causality); if strcmp(causality,"effort"); other = "flow"; elseif strcmp(causality,"flow"); other = "effort"; elseif strcmp(causality,"e"); other = "f"; elseif strcmp(causality,"f"); other = "e"; else error(sprintf("Causality \"%s\" not recognised",causality)); endif endfunction |
Added mttroot/mtt/bin/trans/m/mtt_other_end.m version [dfe2387a77].
> > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | function [in_components,in_ports,in_bonds] = mtt_other_end (name,all_in_bonds,cbg); ## usage: [in_components,in_ports,in_bonds] = mtt_other_end (name,all_in_bonds,cbg); ## ## ## What components are at the other ends of the in bonds? in_components = ""; in_ports = []; in_bonds = []; in_direction = []; for i = 1:length(all_in_bonds); for [component_structure, component] = cbg.subsystems if !strcmp(name,component) other_connections = component_structure.connections; one = ones(size(other_connections)); port = find(abs(all_in_bonds(i))*one==abs(other_connections)); if (length(port)==1) in_components = [in_components; component]; in_bonds = [in_bonds; all_in_bonds(i)]; in_ports = [in_ports; port]; endif endif endfor endfor endfunction |
Added mttroot/mtt/bin/trans/m/mtt_subname.m version [653459832d].
> > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | function [subname, compname] = mtt_subname (name) ## usage: subname = mtt_subname (name) ## ## Finds the subsystem name from the component name ## Copyright (C) 2003 by Peter J. Gawthrop names = mtt_name2names(name); [n,m] = size(names); if n<2 # Simple name subname = ""; compname = name; else # Compound name subname = mtt_names2name(names(1:n-1,:)); compname = deblank(names(n,:)); endif endfunction |