ADDED mttroot/mtt/lib/comp/simple/AE_cause.m Index: mttroot/mtt/lib/comp/simple/AE_cause.m ================================================================== --- /dev/null +++ mttroot/mtt/lib/comp/simple/AE_cause.m @@ -0,0 +1,69 @@ +function [bonds,status] = AE_cause(bonds); +% AE_cause - Causality for Flow amplifier component +% +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %%%%% Model Transformation Tools %%%%% +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Matlab function AE_cause +% [bonds,status] = AE_cause(bonds) + +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% Version control history +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% $Id$ +% %% $Log$ +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +% Copyright (c) P.J. Gawthrop, 1996. + + +status = -1; + +% Check that there are exactly two bonds. +if check_bonds(bonds,2,'AE')==0 + return +end + +% There are 2 ports; extract the information +e_1 = bonds(1,1); +f_1 = bonds(1,2); +e_2 = bonds(2,1); +f_2 = bonds(2,2); + +% Port 1 must impose (zero) flow and port 2 have flow imposed +if (f_1==-1)|(f_2==1) % Conflict + status = 1; + else % Do the rest of the causality + + if f_1 == 0 % Set port 1 effort + f_1 = 1; + end; + + if f_2 == 0 % Set port 2 effort + f_2 = -1; + end; + + number_set = sum(sum([e_1 e_2]~=zeros(1,2) )); + if number_set==0 % Under causal + status = -1; + elseif number_set==1 % Set the causality + if e_1 == 0 + e_1 = -e_2; + else + e_2 = -e_1; + end + status = 0; + elseif number_set==2 % Check the causality + if e_1==-e_2 + status = 0; + else + status = 1; + end + end; +end; + + bonds = [e_1 f_1 + e_2 f_2]; + ADDED mttroot/mtt/lib/comp/simple/AF_cause.m Index: mttroot/mtt/lib/comp/simple/AF_cause.m ================================================================== --- /dev/null +++ mttroot/mtt/lib/comp/simple/AF_cause.m @@ -0,0 +1,67 @@ +function [bonds,status] = AF_cause(bonds); +% AF_cause - Causality for Flow amplifier component +% +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %%%%% Model Transformation Tools %%%%% +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Matlab function AF_cause +% [bonds,status] = AF_cause(bonds) + +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% Version control history +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% $Id$ +% %% $Log$ +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +% Copyright (c) P.J. Gawthrop, 1996. + +status = -1; + +% Check that there are exactly two bonds. +if check_bonds(bonds,2,'AF')==0 + return +end + +% There are 2 ports; extract the information +e_1 = bonds(1,1); +f_1 = bonds(1,2); +e_2 = bonds(2,1); +f_2 = bonds(2,2); + +% Port 1 must impose (zero) effort and port 2 have effort imposed +if (e_1==1)|(e_2==-1) % Conflict + status = 1; + else % Do the rest of the causality + + if e_1 == 0 % Set port 1 effort + e_1 = -1; + end; + + if e_2 == 0 % Set port 2 effort + e_2 = 1; + end; + + number_set = sum(sum([f_1 f_2]~=zeros(1,2) )); + if number_set==0 % Under causal + status = -1; + elseif number_set==1 % Set the causality + if f_1 == 0 + f_1 = -f_2; + else + f_2 = -f_1; + end + status = 0; + elseif number_set==2 % Check the causality + if f_1==-f_2 + status = 0; + else + status = 1; + end + end; +end; + + bonds = [e_1 f_1 + e_2 f_2]; ADDED mttroot/mtt/lib/comp/simple/R_cause.m Index: mttroot/mtt/lib/comp/simple/R_cause.m ================================================================== --- /dev/null +++ mttroot/mtt/lib/comp/simple/R_cause.m @@ -0,0 +1,49 @@ +function [bonds,status] = R_cause(bonds); +% R_cause - Causality function for a (multi-port) unicausal R component +% +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %%%%% Model Transformation Tools %%%%% +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Matlab function R_cause +% [bonds,status] = R_cause(bonds) + +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% Version control history +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% $Id$ +% %% $Log$ +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +% Copyright (c) P.J. Gawthrop, 1996. + + +% Find the number of ports +[ports,junk] = size(bonds); + +% default undercausal status +statuses = -ones(ports,1); + +% Force unicausality +for i = 1:ports + if (bonds(i,1)~=0)&(bonds(i,2)~=0) % Both bonds set + statuses(i) = bonds(i,1)~=bonds(i,2); + elseif bonds(i,2)~=0 % Bond 1 set + bonds(i,1) = bonds(i,2); + statuses(i) = 0; + elseif bonds(i,1)~=0 % Bond 2 set + bonds(i,2) = bonds(i,1); + statuses(i) = 0; + end; +end; + +if max(statuses)==1 + status = 1; +elseif min(statuses)==-1 + status = -1; +else + status = 0; +end; + + ADDED mttroot/mtt/lib/comp/simple/check_bonds.m Index: mttroot/mtt/lib/comp/simple/check_bonds.m ================================================================== --- /dev/null +++ mttroot/mtt/lib/comp/simple/check_bonds.m @@ -0,0 +1,28 @@ +function ok = check_bonds(bonds,n,component); +% check_bonds - check to see correct number (n) of bonds. +% +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %%%%% Model Transformation Tools %%%%% +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Matlab function check_bonds +% err = check_bonds(bonds,n); + +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% Version control history +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% $Id$ +% %% $Log$ +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +% Copyright (c) P.J. Gawthrop, 1996. +% Check that there are exactly two bonds. +[n_bonds,cols] = size(bonds); +if n_bonds~=n + mtt_info(sprintf('MTT error: %s must have %1.0f (not %1.0f) bonds', ... + component, n, n_bonds)); + ok=0; +else + ok=1; +end ADDED mttroot/mtt/lib/comp/simple/oneeqn.m Index: mttroot/mtt/lib/comp/simple/oneeqn.m ================================================================== --- /dev/null +++ mttroot/mtt/lib/comp/simple/oneeqn.m @@ -0,0 +1,28 @@ +function oneeqn(name,LHS_number,LHS_cause,RHS_number,RHS_cause,cr,args, ... + eqnfile); +% oneeqn - prints a single equation +% +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %%%%% Model Transformation Tools %%%%% +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Matlab function oneeqn +% oneeqn(name,LHS_number,LHS_cause,RHS_number,RHS_cause,cr,args,eqnfile) + +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% Version control history +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% $Id$ +% %% $Log$ +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +if nargin<7 + eqnfile = 'stdout'; +end; + + +fprintf(eqnfile, '%s := %s;\n', ... + varname(name, LHS_number,LHS_cause), ... + cr2name(name,RHS_number,LHS_cause,RHS_cause,cr,args));