ADDED mttroot/mtt/lib/comp/simple/CI_seqn.m Index: mttroot/mtt/lib/comp/simple/CI_seqn.m ================================================================== --- /dev/null +++ mttroot/mtt/lib/comp/simple/CI_seqn.m @@ -0,0 +1,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 Index: mttroot/mtt/lib/comp/simple/C_seqn.m ================================================================== --- /dev/null +++ mttroot/mtt/lib/comp/simple/C_seqn.m @@ -0,0 +1,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 Index: mttroot/mtt/lib/comp/simple/GY_seqn.m ================================================================== --- /dev/null +++ mttroot/mtt/lib/comp/simple/GY_seqn.m @@ -0,0 +1,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 Index: mttroot/mtt/lib/comp/simple/I_seqn.m ================================================================== --- /dev/null +++ mttroot/mtt/lib/comp/simple/I_seqn.m @@ -0,0 +1,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 Index: mttroot/mtt/lib/comp/simple/R_seqn.m ================================================================== --- /dev/null +++ mttroot/mtt/lib/comp/simple/R_seqn.m @@ -0,0 +1,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 Index: mttroot/mtt/lib/comp/simple/SS_seqn.m ================================================================== --- /dev/null +++ mttroot/mtt/lib/comp/simple/SS_seqn.m @@ -0,0 +1,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 Index: mttroot/mtt/lib/comp/simple/Sensor_seqn.m ================================================================== --- /dev/null +++ mttroot/mtt/lib/comp/simple/Sensor_seqn.m @@ -0,0 +1,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 Index: mttroot/mtt/lib/comp/simple/Source_seqn.m ================================================================== --- /dev/null +++ mttroot/mtt/lib/comp/simple/Source_seqn.m @@ -0,0 +1,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 Index: mttroot/mtt/lib/comp/simple/TF_seqn.m ================================================================== --- /dev/null +++ mttroot/mtt/lib/comp/simple/TF_seqn.m @@ -0,0 +1,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 Index: mttroot/mtt/lib/comp/simple/junction_seqn.m ================================================================== --- /dev/null +++ mttroot/mtt/lib/comp/simple/junction_seqn.m @@ -0,0 +1,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