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

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003