Overview
Comment:Equation generatation for sorted equations
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 74b9225cb06fbd4d6462057a04c5b283415d27da7d168332cfbf98ed4acfe4b9
User & Date: gawthrop@users.sourceforge.net on 2003-03-13 14:56:45
Other Links: branch diff | manifest | tags
Context
2003-03-13
15:10:26
Removed redundant final column check-in: 9509f928eb user: gawthrop@users.sourceforge.net tags: origin/master, trunk
14:56:45
Equation generatation for sorted equations check-in: 74b9225cb0 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
14:22:34
No negative bond numbers check-in: 1e4f51e7b0 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Added mttroot/mtt/lib/comp/simple/CI_seqn.m version [827c2f1efc].





































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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
function [eqn,insigs,innames] = CI_seqn (comp_type,Name, name, cr, arg, outsig, insigs ,innames)

  ## usage:  [eqn,inbonds] = CI_seqn (Name, cr, arg, outbond, inbonds)
  ##
  ## 
  ## Multi port C's ??

  delim = "__";
  N = mtt_check_sigs (outsig,insigs);

  state_index=3;
  
  i_cause = outsig(2);		# Extract causality

  state_equation=((i_cause==1)&&strcmp(comp_type,"C"))\
      ||((i_cause==-1)&&strcmp(comp_type,"I"));

  ## Create the equation
  if state_equation			# output/state
    LHS = varname(Name, outsig(1,1), state_index);
    RHS = sprintf("MTTx_%s%s%s", Name, delim, name);
    eqn_1 = sprintf("%s := %s;", LHS, RHS);
    
    inports = [1:N]; 
    comp_type_str=sprintf("""%s""", comp_type);
    eqn_2 = equation(comp_type_str,Name,cr,arg,outsig(1),outsig(2),outsig(3),\
	     insigs(:,1),state_index,inports);
    
    eqn = sprintf("%s\n%s", eqn_1, eqn_2);
  else			# state derivative
    RHS = varname(Name, insigs(1,1), insigs(1,2));
    LHS = sprintf("MTTdx_%s%s%s", Name, delim, name);
    eqn = sprintf("%s := %s;", LHS, RHS);
  endif
  
endfunction

Added mttroot/mtt/lib/comp/simple/C_seqn.m version [40b9922c1a].












1
2
3
4
5
6
7
8
9
10
11
+
+
+
+
+
+
+
+
+
+
+
function [eqn,insigs,innames] = C_seqn (Name, name, cr, arg, outsig, insigs ,innames)

  ## usage:  [eqn,inbonds] = C_seqn (Name, cr, arg, outbond, inbonds)
  ##
  ## 
  ## Multi port C's ??


  [eqn,insigs,innames] = CI_seqn ("C", Name, name, cr, arg, outsig, insigs ,innames);

endfunction

Added mttroot/mtt/lib/comp/simple/GY_seqn.m version [a2d9704220].




























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 [eqn,insigs,innames] = GY_seqn (Name, cr, arg, outsig, insigs, innames)

  ## usage:  [eqn,inbonds] = GY_seqn (Name, cr, arg, outbond, inbonds)
  ##
  ##
  ## GYs have two ports; the input and output ports must be different
  N = mtt_check_sigs (outsig,insigs);

  if N!=2
    error("A GY must have exactly two ports");
  else
    if insigs(1,3)==outsig(3)	# First signal is on output port
      inport = 2;
    else
      inport = 1;
    endif
  endif
  
  insig = insigs(inport,:);
  inname = innames(inport,:);
  eqn = equation("""GY""",Name,cr,arg,outsig(1),outsig(2),outsig(3), ...
		 insig(:,1),insig(:,2),inport);

  insigs = insig;		# Set the correct input signals
  innames = inname;		# Set the correct input names
  
endfunction

Added mttroot/mtt/lib/comp/simple/I_seqn.m version [b8f0958d68].












1
2
3
4
5
6
7
8
9
10
11
+
+
+
+
+
+
+
+
+
+
+
function [eqn,insigs,innames] = I_seqn (Name, name, cr, arg, outsig, insigs ,innames)

  ## usage:  [eqn,inbonds] = I_seqn (Name, cr, arg, outbond, inbonds)
  ##
  ## 
  ## Multi port I's ??


  [eqn,insigs,innames] = CI_seqn ("I", Name, name, cr, arg, outsig, insigs ,innames);

endfunction

Added mttroot/mtt/lib/comp/simple/R_seqn.m version [a084871fab].



















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
function [eqn,insigs,innames] = R_seqn (Name, name, cr, arg, outsig, insigs, innames)

  ## usage:  [eqn,inbonds] = R_seqn (Name, cr, arg, outbond, inbonds)
  ##
  ## 
  ## Multi port R's use all potential signals

  N = mtt_check_sigs (outsig,insigs);
  
  inports = [1:N]; 
  eqn = equation("""R""",Name,cr,arg,outsig(1),outsig(2),outsig(3), ...
		 insigs(:,1),insigs(:,2),inports);

  ## No change
  ## insigs = insigs;
  ## innames = innames;

endfunction

Added mttroot/mtt/lib/comp/simple/SS_seqn.m version [557276af06].



























































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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
function [eqn,insigs,innames] = SS_seqn (Name, name, cr, arg, outsig, insigs,innames)

  ## usage:  [eqn,inbonds] = SS_seqn (Name, cr, arg, outbond, inbonds)
  ##
  ## 
  ## Multi port SS's ??

  delim = "__";
  N = mtt_check_sigs (outsig,insigs);

  full_name = sprintf("%s%s%s", Name,delim,name);

  ## Get the special attibutes for SS
  attrib_name = split(arg,",");
  [N_a,M_a]=size(attrib_name);
  if (N_a~=2)		# Must have 2 arguments
    mtt_error(sprintf("SS should have 2 args not %i", N_a));
  end;

  effort_attribute = deblank(attrib_name(1,:));
  flow_attribute   = deblank(attrib_name(2,:));

  ## Default attributes
  if strcmp(effort_attribute,"")
    effort_attribute = "external";
  end;
  
  if strcmp(flow_attribute,"")
    flow_attribute = "external";
  end;


  if mtt_is_external("SS",outsig,insigs) # Source
    if outsig(2)==1		# effort output.
      attribute = effort_attribute;
    else
      attribute = flow_attribute;
    endif

    ## Create the equation
    LHS = varname(Name, outsig(1,1), outsig(1,2));
    RHS = Source_seqn (attribute,full_name);
    eqn = sprintf("%s := %s;", LHS, RHS);
  else				# Sensor
   if insigs(1,2)==1		# effort output.
     attribute = effort_attribute;
   else
     attribute = flow_attribute;
   endif

   ## Create the equation
   LHS = Sensor_seqn (attribute,full_name);
   RHS = varname(Name, insigs(1,1), insigs(1,2));
   eqn = sprintf("%s := %s;", LHS, RHS);
 endif
 

endfunction

Added mttroot/mtt/lib/comp/simple/Sensor_seqn.m version [2a1d2646ad].

















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
function LHS = Sensor_seqn (attribute,name)

  ## usage:  LHS = Sensor_seqn (attribute,name)
  ##
  ## Write the LHS of a sensor equation
  

  if strcmp(attribute,"external")
    LHS = sprintf("MTTy_%s", name);  
  elseif strcmp(attribute,"internal")
    LHS = sprintf("%% NOT USED MTT_y_%s", name); 
  else
    error(sprintf("attribute ""%s"" not appropriate for a \
    source"), attribute);
  endif
endfunction

Added mttroot/mtt/lib/comp/simple/Source_seqn.m version [de06b8124d].

















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
function RHS = Source_seqn (attribute,name)

  ## usage:  RHS = Source_seqn (attribute,name)
  ##
  ## Write the RHS of a source equation
  
  if strcmp(attribute,"external")
    RHS = sprintf("MTTu_%s",name);
   elseif strcmp(attribute,"internal")
     error(sprintf("attribute ""internal"" not appropriate for a \
 	source"));
  else
    RHS = attribute;
  endif
  
endfunction

Added mttroot/mtt/lib/comp/simple/TF_seqn.m version [4d8c4483a1].




























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 [eqn,insigs,innames] = TF_seqn (Name, cr, arg, outsig, insigs, innames)

  ## usage:  [eqn,inbonds] = TF_seqn (Name, cr, arg, outbond, inbonds)
  ##
  ##
  ## TFs have two ports; the input and output ports must be different
  N = mtt_check_sigs (outsig,insigs);

  if N!=2
    error("A TF must have exactly two ports");
  else
    if insigs(1,3)==outsig(3)	# First signal is on output port
      inport = 2;
    else
      inport = 1;
    endif
  endif
  
  insig = insigs(inport,:);
  inname = innames(inport,:);
  eqn = equation("""TF""",Name,cr,arg,outsig(1),outsig(2),outsig(3), ...
			 insig(:,1),insig(:,2),inport);

  insigs = insig;		# Set the correct input signals
  innames = inname;		# Set the correct input names
  
endfunction

Added mttroot/mtt/lib/comp/simple/junction_seqn.m version [53138c6ea2].



























































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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
function [eqn,insigs,innames] = junction_seqn (jun_type,Name, outsig, \
					       insigs, innames)
  ## usage:  [eqn,insigs] = junction_seqn (jun_type,Name, outport, outsig, \
  ##				       insigs)
  ##
  ## 
  ## Junctions

  ## Sanity check
  N = mtt_check_sigs (outsig,insigs);

  outport = outsig(3);

  ## Setup up causality corresponding to junction
  if jun_type=="0"
    i_jun_type = 1;
  elseif jun_type=="1"
    i_jun_type = -1;
  else
    error("Junction type %s unknown", jun_type)
  endif

  ## Is output same causality as junction?
  same_type = outsig(2)==i_jun_type;


  ## LHS 
  eqn = sprintf("%s(%i,%i) :=", Name, abs(outsig(1)), cause2index(outsig(2)));

  ## Find the input bond of the same causality as junction
  one = ones(N,1);
  inport = find(insigs(:,2)==i_jun_type*one);

  ##RHS
  if same_type
    insig = insigs(inport,:);
    inname = innames(inport,:);
    eqn = sprintf("%s\n\t%s(%i,%i)", eqn, Name, abs(insigs(inport,1)),cause2index(i_jun_type));
  else
    insig=[];
    inname="";
    inports = [];
    out_dir = sign(insigs(inport,1));
    for i=1:N
      if i!=inport
	in_dir = sign(insigs(i,1));
	plusminus = sign2name(-in_dir*out_dir);
	eqn = sprintf("%s\n\t%s%s(%i,%i)", eqn, plusminus, Name, \
		      abs(insigs(i,1)), cause2index(-i_jun_type));
	insig = [insig; insigs(i,:)];
	inname = [inname; innames(i,:)];
      endif
    endfor
  endif
  eqn = sprintf("%s;", eqn);
  insigs = insig;
  innames = inname;
endfunction


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