Home > m > timetools > statespacefunctions > ltpda_ss_assemble_fusion.m

ltpda_ss_assemble_fusion

PURPOSE ^

SystemFlatten makes a system out of assembled subsystems

SYNOPSIS ^

function [varargout] = ltpda_ss_assemble_fusion(varargin)

DESCRIPTION ^

 SystemFlatten makes a system out of assembled subsystems

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: SystemFlatten makes a system out of assembled subsystems,
 whose matrices were already put toghether is a cell array.

 CALL: [Subsys] = ltpda_ss_assemble_fusion(listMeta)

 INPUTS: listMeta - parameter list (meta-system format)
 
 OUTPUTS: Subsys - parameter list (subsystem format)

 PARAMETERS: 
 See ltpda_ss_check function for information on subsys oupput plist content
 See ltpda_ss_assemble_arrange function for information on output plist
 content
 ***** There are no default parameter values *****%
 VERSION: $Id: ltpda_ss_assemble_fusion.m,v 1.3 2008/02/25 12:43:44 adrien Exp $

 HISTORY: 23-01-2008 A Grynagier

 TO DO : Possibly inplement vpa call for D matrix inversion. Think of
 space matrices use for inversion, and how to deal with the case when they
 are full with parameters. Check numerical precision on this step...

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function   [varargout] = ltpda_ss_assemble_fusion(varargin)
0002 % SystemFlatten makes a system out of assembled subsystems
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: SystemFlatten makes a system out of assembled subsystems,
0007 % whose matrices were already put toghether is a cell array.
0008 %
0009 % CALL: [Subsys] = ltpda_ss_assemble_fusion(listMeta)
0010 %
0011 % INPUTS: listMeta - parameter list (meta-system format)
0012 %
0013 % OUTPUTS: Subsys - parameter list (subsystem format)
0014 %
0015 % PARAMETERS:
0016 % See ltpda_ss_check function for information on subsys oupput plist content
0017 % See ltpda_ss_assemble_arrange function for information on output plist
0018 % content
0019 % ***** There are no default parameter values *****%
0020 % VERSION: $Id: ltpda_ss_assemble_fusion.m,v 1.3 2008/02/25 12:43:44 adrien Exp $
0021 %
0022 % HISTORY: 23-01-2008 A Grynagier
0023 %
0024 % TO DO : Possibly inplement vpa call for D matrix inversion. Think of
0025 % space matrices use for inversion, and how to deal with the case when they
0026 % are full with parameters. Check numerical precision on this step...
0027 %
0028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0029 
0030 %% standard calls for LTPDA function data
0031 
0032 ALGONAME = mfilename;
0033 VERSION =  '$Id: ltpda_ss_assemble_fusion.m,v 1.3 2008/02/25 12:43:44 adrien Exp $';
0034 CATEGORY = 'STATESPACE';
0035 display(['starting ' ALGONAME]);
0036 
0037 if isequal( varargin{1}, 'Version')
0038     varargout = VERSION;
0039     return;
0040 elseif isequal(varargin{1}, 'Params')
0041     varargout = plist();
0042     return;
0043 elseif isequal(varargin{1}, 'Category')
0044     varargout = CATEGORY;
0045     return;
0046 end
0047 listMeta = varargin{1};
0048 
0049 %% retriveing fields out of plist
0050 A_meta = find(listMeta,'A_META');
0051 B_meta = find(listMeta,'B_META');
0052 C_meta = find(listMeta,'C_META');
0053 D_meta = find(listMeta,'D_META');
0054 Bext_meta = find(listMeta,'Bext_META');
0055 Dext_meta = find(listMeta,'Dext_META');
0056 Ox_meta = find(listMeta,'Ox_META');
0057 Oy_meta = find(listMeta,'Oy_META');
0058 TIMESTEP = find(listMeta,'TIMESTEP');
0059 Xini_meta = find(listMeta,'XINI_META');
0060 Names_meta = find(listMeta,'NAMES_META');
0061 ParamNames_meta = find(listMeta,'PARAMNAMES_META');
0062 ParamValues_meta = find(listMeta,'PARAMVALUES_META');
0063 ParamSigmas_meta = find(listMeta,'PARAMSIGMAS_META');
0064 NbInputs_meta = find(listMeta,'NBINPUTS_META');
0065 InputNames_meta = find(listMeta,'INPUTNAMES_META');
0066 InputSizes_meta = find(listMeta,'INPUTSIZES_META');
0067 InputIsUsed_meta = find(listMeta,'INPUTISUSED_META');
0068 
0069 %% checking size of meta matrices
0070 
0071 linesMatch = isequal(size(A_meta,1), size(B_meta,1), size(Bext_meta,1)) * isequal(size(C_meta,1), size(D_meta,1), size(Dext_meta,1)) * isequal(size(Oy_meta,1), size(Ox_meta,1) ) ;
0072 columnsMatch = isequal(size(A_meta,2), size(C_meta,2), size(Ox_meta,2)) * isequal(size(B_meta,2), size(D_meta,2), size(Oy_meta,2)) * isequal(size(Bext_meta,2), size(Dext_meta,2), NbInputs_meta) ;
0073 if not(linesMatch*columnsMatch)
0074     error('problem, wrong size in assembling meta matrices A, B, C, D, Bext, Dext, Ox, Oy');
0075 end
0076 
0077 %% building big meta-matrix
0078 BigCell = [    A_meta      B_meta     Bext_meta  ;  C_meta      D_meta    Dext_meta   ;    Ox_meta     Oy_meta   cell( size(Ox_meta,1), size(Dext_meta,2) ) ] ;
0079 % taking bounds of meta-indices
0080 Nss_meta = size(A_meta, 1);
0081 Nout_meta = size(Ox_meta, 1);
0082 Imax_meta = size(BigCell,1);
0083 Jmax_meta = size(BigCell,2);
0084 % declaring tables for width/height of meta-columns/meta-lines
0085 Height = zeros(Imax_meta,1);
0086 Width = zeros(Jmax_meta,1);
0087     
0088 %% Filling the height and width vectors for A, B, C, D, Bext and Dext
0089 % This systematic filling is needed for sizes of A, B, C, D
0090 for i_meta=1:Nss_meta  
0091     Height(i_meta) = size(A_meta{i_meta,i_meta},1);
0092     Height(i_meta + Nss_meta) = size(C_meta{i_meta,i_meta},1);
0093 end
0094 for j_meta=1:Nss_meta
0095     Width(j_meta) = size(A_meta{j_meta,j_meta},1);
0096     Width(j_meta + Nss_meta) = size(C_meta{j_meta,j_meta},1);
0097 end
0098 % Filling the width vectors for Bext and Dext
0099 for j_meta=1:NbInputs_meta
0100     Width(j_meta + 2*Nss_meta ) = InputSizes_meta(j_meta);
0101 end
0102 % Filling the width vectors for Ox and Oy
0103 for i_meta=1:Nout_meta
0104     for j_meta=1:Nss_meta
0105         if not(isequal(Ox_meta{i_meta,j_meta},[]))
0106             Height(i_meta + 2*Nss_meta ) = size(Ox_meta{i_meta,j_meta},1);
0107         elseif not(isequal(Oy_meta{i_meta,j_meta},[]))
0108             Height(i_meta + 2*Nss_meta ) = size(Oy_meta{i_meta,j_meta},1);
0109         end
0110     end
0111 end
0112 
0113 %% checking their meta-size is correct in regard with their content
0114 for i_meta=1:Imax_meta
0115     for j_meta=1:Jmax_meta
0116         if not( isequal( [], BigCell{i_meta,j_meta} ) ) % action only if cell is not empty
0117             %for the widht of the j meta-colums
0118             if not(Width(j_meta) == size(BigCell{i_meta,j_meta},2) || isempty(BigCell{i_meta,j_meta}))
0119                 msg = 'error because matrices inside meta matrices have incompatible sizes';
0120                 error(msg);
0121             end
0122             %same for the heigth of the i-th meta-line
0123             if not(Height(i_meta) == size(BigCell{i_meta,j_meta},1) || isempty(BigCell{i_meta,j_meta}))
0124                 msg = 'error because matrices inside meta matrices have incompatible sizes';
0125                 error(msg);
0126             end
0127         end
0128     end
0129 end
0130 
0131 %% filling the big matrix
0132 
0133 % size of big matrix
0134 Imax_Big = sum(Height);
0135 Jmax_Big = sum(Width);
0136 % taking cumulative sum of size to get to positions
0137 CumulHeight = cumsum([1;Height]);
0138 CumulWidth = cumsum([1;Width]);
0139 H1 = CumulHeight(Nss_meta+1);
0140 H2 = CumulHeight(Nss_meta*2+1);
0141 L1 = CumulWidth(Nss_meta+1);
0142 L2 = CumulWidth(Nss_meta*2+1);
0143 Heigths_block = [1 H1 H2 Imax_Big+1];
0144 Widths_block = [1 L1 L2 Jmax_Big+1];
0145 % declaration of big matrix
0146 Big_mat = zeros(Imax_Big, Jmax_Big);
0147 for i_meta=1:Imax_meta
0148     for j_meta=1:Jmax_meta
0149         % taking indices for the line
0150         iMin = CumulHeight(i_meta);
0151         iMax = CumulHeight(i_meta+1)-1;
0152         % taking indices for the column
0153         jMin=CumulWidth(j_meta);
0154         jMax = CumulWidth(j_meta+1)-1;
0155         if not( isempty(BigCell{i_meta,j_meta}) || (iMin>iMax) || (jMin>jMax) )%if the local cell is not empty, and the column/line does not have zero elements
0156             Big_mat(iMin:iMax, jMin:jMax) = BigCell{i_meta,j_meta};
0157         end
0158     end
0159 end
0160 
0161 %% extraction of the submatrices out of the big matrix
0162 nameMat = {'A' 'B' 'Bext' ; 'C' 'D' 'Dext' ; 'Ox' 'Oy' 'OO'}; % name list of the submatrices, OO is filled with zeros anyway
0163 
0164 %% extracting the submatrices A_mat, B_mat, C_mat, D_mat, Ox_mat, Oy_mat
0165 for I_block=1:3
0166     for J_block=1:2
0167         % meta-line/column are supposed not empty
0168         IisFlat=0;
0169         JisFlat=0;
0170         iMin=Heigths_block(I_block);
0171         iMax=Heigths_block(I_block+1)-1;
0172         if iMax<iMin % if the line is empty
0173             IisFlat=1;
0174         end
0175         jMin=Widths_block(J_block);
0176         jMax=Widths_block(J_block+1)-1;
0177         if jMax<jMin % if the column is empty
0178             JisFlat=1;
0179         end
0180         if IisFlat||JisFlat % if a matrix has zero elements, declare a zero matrix
0181             cmd = [nameMat{I_block,J_block},'_mat = zeros( iMax-iMin+1, jMax-jMin+1 ); '];
0182         else % other case, Extraction out of BigMat matrix.
0183             cmd = [ nameMat{I_block,J_block},'_mat = Big_mat(', num2str(iMin),':', num2str(iMax) ,',',  num2str(jMin),':', num2str(jMax) ,');'];
0184         end
0185         eval(cmd);
0186     end
0187 end
0188 
0189 %% extracting the submatrices Bext_mat, Dext_mat
0190 J_block=3;
0191 for I_block=1:2
0192     for j_meta = (2*Nss_meta+1):(2*Nss_meta+NbInputs_meta)
0193         % meta-line/column are supposed not empty
0194         IisFlat=0;
0195         JisFlat=0;
0196         iMin=Heigths_block(I_block);
0197         iMax=Heigths_block(I_block+1)-1;
0198         if iMax<iMin % if the line is empty
0199             IisFlat=1;
0200         end
0201         jMin=CumulWidth(j_meta);
0202         jMax=CumulWidth(j_meta+1)-1;
0203         if jMax<jMin % if the column is empty
0204             JisFlat=1;
0205         end
0206         if IisFlat||JisFlat % if a matrix has zero elements, declare a zero matrix
0207             cmd = [nameMat{I_block,J_block},'_mats{',num2str(j_meta-2*Nss_meta),'} = zeros( iMax-iMin+1, jMax-jMin+1 ); '];
0208             eval(cmd);
0209         else % other case, Extraction out of BigMat matrix.
0210             cmd = [ nameMat{I_block,J_block},'_mats{',num2str(j_meta-2*Nss_meta),'} = Big_mat(', num2str(iMin),':', num2str(iMax) ,',',  num2str(jMin),':', num2str(jMax) ,');'];
0211         end
0212         eval(cmd);
0213     end
0214 end
0215 
0216            
0217 %% take minimal system
0218 IDinv = inv(eye(size(D_mat,1)) - D_mat); % PROBLEM HERE IF MATRIX IS SYMBOLLIC
0219 A = A_mat + B_mat*IDinv*C_mat;
0220 C = Ox_mat + Oy_mat*IDinv*C_mat;
0221 BMATS = cell(size(Bext_meta, 2),1);
0222 DMATS = cell(size(Bext_meta, 2),1);
0223 for j_input = 1:NbInputs_meta   
0224     BMATS{j_input} = Bext_mats{j_input} + B_mat*IDinv*Dext_mats{j_input}; %#ok<USENS>
0225     DMATS{j_input} = Oy_mat*IDinv*Dext_mats{j_input};
0226 end
0227 
0228 %% builing new initial vector and new name
0229 Xini_mat = [];
0230 NewName = 'SystemAssembled[';
0231 for i=1:length(Xini_meta)
0232     Xini_mat = [Xini_mat ; Xini_meta{i} ]; %#ok<AGROW>
0233     NewName = [NewName,' ',Names_meta{i}]; %#ok<AGROW>
0234 end
0235 NewName = [NewName, ']'];
0236 
0237 %% parsing output
0238 Subsys = plist('TYPE', 'SUBSYSTEM' ,'NAME', NewName ,'TIMESTEP', TIMESTEP , ...
0239     'XISOUTPUT',1,'YISOUTPUT',0,'XINI', Xini_mat , ...
0240     'PARAMNAMES', ParamNames_meta ,'PARAMVALUES', ParamValues_meta ,'PARAMSIGMAS', ParamSigmas_meta ,...
0241     'NBINPUTS', NbInputs_meta ,'INPUTNAMES', InputNames_meta ,'INPUTSIZES', InputSizes_meta , 'INPUTISUSED', InputIsUsed_meta ,...
0242     'AMAT', {A} ,'BMATS', BMATS ,'CMAT', {C} ,'DMATS', DMATS );
0243 ltpda_ss_check(Subsys);
0244 varargout = Subsys;
0245 end
0246         
0247

Generated on Tue 26-Feb-2008 10:52:52 by m2html © 2003