0001 function dec = addConfinementPartitionData(dec, partitionData, zerotol)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 dec.seScaledToClose = zeros(0, dec.nC);
0026 for iPart = 1:length(partitionData)
0027
0028
0029 if ~partitionData(iPart).isConfined,continue;end;
0030
0031
0032 thisHrepClosed = closeCone(partitionData(iPart).hrep, dec.centerRay);
0033 thisVrepClosed = convertHrepToVrep(thisHrepClosed);
0034 thisVrep = openCone(thisVrepClosed, zerotol);
0035
0036
0037
0038 [thisSeMatrix thisSeIndexVector] = eliminateRows(thisVrep.V, ...
0039 dec.seScaledToClose, zerotol);
0040
0041 thisSeIndexVector = [thisSeIndexVector, size(dec.seScaledToClose, 1) + ...
0042 (1:size(thisSeMatrix, 1))];
0043 dec.seScaledToClose = [dec.seScaledToClose; thisSeMatrix];
0044
0045 partitionData(iPart).seIndexVector = sort(thisSeIndexVector);
0046 end
0047
0048 dec.se = scaleToReal(dec.seScaledToClose, dec, zerotol);
0049
0050
0051 dec.centerRay = mean(dec.se, 1)';
0052 dec.centerRay = dec.centerRay / norm(dec.centerRay);
0053
0054 dec.seScaledToClose = scaleToClose(dec.se, dec);
0055
0056
0057 dec.validityCone = rmfield(dec.validityCone, 'volume');
0058
0059 dec.validityCone.seIndexVector = find(any(abs(dec.validityCone.A * ...
0060 dec.seScaledToClose') < zerotol, 1));
0061
0062
0063
0064
0065 vrepClosedCone.V = closeCone(dec.seScaledToClose);
0066 hrepClosedCone = convertVrepToHrep(vrepClosedCone, zerotol);
0067 dec.confinementCone = openCone(hrepClosedCone);
0068
0069 dec.confinementCone.seIndexVector = find(any(abs(dec.confinementCone.A * ...
0070 dec.seScaledToClose') < zerotol, 1));
0071
0072 dec.confinementCone.volume = computeVolumeVrep(vrepClosedCone);
0073
0074
0075
0076
0077
0078
0079 dec = appendUnifiedPartition(dec);
0080 unifiedVolumeSum = 0;
0081
0082 for iPart = 1:length(partitionData)
0083
0084 if ~partitionData(iPart).isConfined
0085 continue
0086 end
0087
0088
0089 dec = appendUnifiedPartition(dec, partitionData(iPart).seIndexVector, ...
0090 zerotol, partitionData(iPart).isValid, 1);
0091
0092 dec = appendPartitionDataForEmbedding(dec, partitionData(iPart), zerotol);
0093
0094
0095 unifiedVolumeSum = unifiedVolumeSum + ...
0096 dec.unifiedPartition{end}.volumeScaled;
0097
0098 end
0099 dec.nPU = length(dec.unifiedPartition);
0100 dec.nPS = length(dec.simplexPartition);
0101 dec.nS = size(dec.se, 1);
0102
0103
0104
0105
0106 if abs(unifiedVolumeSum - 1) <= zerotol
0107 dec.isOrdinary = 1;
0108 return
0109 else
0110 dec.isOrdinary = 0;
0111
0112 end
0113
0114
0115 for iPart = 1:length(partitionData)
0116
0117 if partitionData(iPart).isConfined, continue;end;
0118
0119
0120 thisHrepClosed = closeCone(struct(...
0121 'A', [dec.confinementCone.A; partitionData(iPart).hrep.A], ...
0122 'h', [dec.confinementCone.h; partitionData(iPart).hrep.h]), ...
0123 dec.centerRay);
0124 thisVrepClosed = convertHrepToVrep(thisHrepClosed);
0125 thisVrep = openCone(thisVrepClosed, zerotol);
0126 thisSeMatrix = scaleToReal(thisVrep.V, dec, zerotol);
0127
0128
0129
0130
0131 if computeVolumeVrep(thisVrepClosed)/dec.confinementCone.volume < zerotol
0132 continue
0133 end
0134
0135
0136
0137
0138
0139 distanceMatrix = dec.confinementCone.A * thisSeMatrix';
0140 if all(distanceMatrix(:) > -zerotol)
0141
0142 continue
0143 elseif all(distanceMatrix(:) < zerotol)
0144
0145 else
0146 error('elk:decomposition:numericalError', ['I''m confused since a ' ...
0147 'partition should either fully reside inside the confinement ' ...
0148 'cone or fully outside. Most likely, the numerics fail, here. ' ...
0149 'This should not happen.']);
0150 end
0151
0152
0153 [thisSeMatrix thisSeIndexVector] = eliminateRows(thisSeMatrix, ...
0154 dec.se, zerotol);
0155
0156 thisSeIndexVector = [thisSeIndexVector, size(dec.se, 1) + ...
0157 (1:size(thisSeMatrix, 1))];
0158 dec.se = [dec.se; thisSeMatrix];
0159 dec.seScaledToClose = [dec.seScaledToClose; ...
0160 scaleToClose(thisSeMatrix, dec)];
0161
0162
0163 dec = appendUnifiedPartition(dec, thisSeIndexVector, zerotol, ...
0164 partitionData(iPart).isValid, 0);
0165 dec = appendPartitionDataForEmbedding(dec, partitionData(iPart), zerotol);
0166
0167
0168 unifiedVolumeSum = unifiedVolumeSum + ...
0169 dec.unifiedPartition{end}.volumeScaled;
0170
0171 end
0172
0173
0174 dec.nPU = length(dec.unifiedPartition);
0175 dec.nPS = length(dec.simplexPartition);
0176 dec.nS = size(dec.se, 1);
0177
0178
0179
0180
0181
0182