File size: 15,994 Bytes
5ab75a9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | function [Status] = CollisionConsequenceFigures(PrimaryMass,VRel,OutputFolder,OutputID,Catastrophic,NumOfPieces,massVec)
%
% CollisionConsequenceFigures - Generates Figures for representing the
% collision consequence numbers including the number of pieces
% distribution and secondary object mass distribution. The secondary object
% mass distribution can only be generated if a non-empty massVec is passed
% in.
%
% Note: The graph for non-catastrophic collisions will only be generated if
% more than 5% of "Catastrophic" array indicates non-catastrophic
% collisions. Likewise, the graph for a catastrophic collisions will
% only be generated if more than 5% of the "Catastrophic" array
% indicates catastrophic collisions.
%
% Syntax: [Status] = CollisionConsequenceFigures(PrimaryMass,VRel,OutputFolder,OutputID,Catastrophic,NumOfPieces,massVec)
%
% Inputs:
% PrimaryMass - 1X1 Mass of Primary Object (kg)
% VRel - 1x1, 3X1, or 1X3 vector of the relative velocity
% between the primary and secondary objects (m/s)
% OutputFolder - String location of output file directory folder where
% figures will be saved (optional)
% - If no output location specified, figures will not
% be saved but will remain on screen
% - If output location specified, figures will be
% saved and then automatically closed
% OutputID - String for output figure ID (optional) used to
% identify specific event
% Catastrophic - [n x 1] logical array indicating whether the
% sampled collision is catastrophic (comes from
% CollisionConsequenceNumPieces.m outputs where "n"
% corresponds to the size of the SecondaryMass array)
% NumOfPieces - [n x 1] array of the number of pieces
% expected to be generated from a collision for each
% sample (comes from CollisionConsequenceNumPieces.m
% outputs where "n" corresponds to the size of the
% SecondaryMass array)
% massVec - [m x 1] array of the secondary object mass
% estimates for each individual sample (comes from
% EstimatedObjectMassQuantiles.m outputs where "m"
% corresponds to the NumOfSamples input parameter)
%
% Outputs:
% Status - Success Status of operation
% 1 - Figures generated Successfully
% 0 - Error Encountered
%
% Example/Validation Cases:
%
% Example 1: Generating graphs for expected number of pieces when
% non-catastrophic and catastrophic collisions occur
%
% % Calculate the number of pieces generated by various secondary mass
% % values and whether or not the number of pieces is characterized as
% % catastrophic
% PrimaryMass = 2000;
% VRel = 10000;
% SecondaryMass = logspace(-2,3,1000); % 1000 evenly spaced masses (in log space) from 0.01 kg to 1000 kg
% [Catastrophic,NumOfPieces] = CollisionConsequenceNumPieces(PrimaryMass,VRel,SecondaryMass);
% % Display the distribution of catastrophic vs. non-catastrophic
% % collisions based on the primary mass, relative velocity, and
% % values calculated in the previous step
% CollisionConsequenceFigures(PrimaryMass, VRel, [], [], Catastrophic, NumOfPieces, []);
%
% Example 2: Generating graphs for expected number of pieces when
% non-catastrophic and catastrophic collisions occur, in
% addition generate a graph of the mass distribution
% (requires knowledge of the object's RCS, drag coefficient,
% drag coefficient variance, ballistic coefficient, and
% ballistic coefficient variance)
%
% % First step:
% % Calculate the number of pieces generated by various secondary mass
% % values and whether or not the number of pieces is characterized as
% % catastrophic
% PrimaryMass = 2000;
% VRel = 10000;
% SecondaryMass = logspace(-2,3,1000); % 1000 evenly spaced masses (in log space) from 0.01 kg to 1000 kg
% [Catastrophic,NumOfPieces] = CollisionConsequenceNumPieces(PrimaryMass,VRel,SecondaryMass);
%
% % Second step:
% % Generate a sample distribution of masses for an unknown secondary
% % based on the RCS, drag coefficient & variance, and ballistic
% % coefficient & variance for the secondary object
% Accuracy = 0.05; % Relative 5% tolerance for well defined quantiles
% RCSdB = -21.52;
% RCS = 10^(RCSdB/10);
% Cd = 2.1;
% CdVar = (0.05*Cd)^2;
% B = 0.059683;
% BVar = 0.0143760217028217*B^2;
% QuantileVector = [.5 .75 .95 .99 0.999 0.9999];
% NumOfSamples = 100000;
% [massVec,QuantileArray] = EstimateObjectMassQuantiles(RCS,B,BVar,Cd,CdVar,QuantileVector,NumOfSamples);
%
% % Display the distribution of catastrophic vs. non-catastrophic
% % collisions based on the primary mass, relative velocity, and
% % values calculated in the first step. In addition, display the
% % distribution of secondary masses based on the values from the
% % second step.
% CollisionConsequenceFigures(PrimaryMass, VRel, [], [], Catastrophic, NumOfPieces, massVec);
%
% Other m-files required: None
%
% Subfunctions: None
% MAT-files required: None
%
% See also: none
%
% May 2018; Last revision: Feb 2024
%
% ----------------- BEGIN CODE -----------------
try
%% Set Constants
CatastrophicThreshold = 40000; % Threshold for Catastrophic Collision (Joules/kg)
CatastrophicThresholdMass = CatastrophicThreshold*2*PrimaryMass/norm(VRel)^2;
if sum(Catastrophic)/length(Catastrophic)*100 > 0.005
CollisionProbabilityText = num2str(sum(Catastrophic)/length(Catastrophic)*100,'%.2f');
else
CollisionProbabilityText = '<0.005';
end
if ~isempty(OutputFolder)
CloseFigures = 1; % Toggle Variable for whether to close figures after generation and saving
else
CloseFigures = 0;
end
%% Close Existing Collision Consequence figure windows if open
try
close('Secondary Mass Distribution')
catch
end
try
close('Non-Catastrophic Debris Piece Distribution')
catch
end
try
close('Catastrophic Debris Piece Distribution')
catch
end
%% Generate Number of Pieces Distribution Plots for Non-Catastrophic Collisions
CDFcounts = [0:100/length(NumOfPieces):100];
% Only generate figure if Non-Catastrophic Collision Probability above 5%
if (1-sum(Catastrophic)/length(Catastrophic))*100 > 5
idx = find(~Catastrophic);
ExpectedNumberofPieces = round(10^mean(log10(NumOfPieces(idx))));
h= figure('Position',[75 75 550 700],...
'Name','Non-Catastrophic Debris Piece Distribution');
% generate Histogram of distribution
subplot(2,1,1);
% define bin edges expecting to represet a chi square distribution
edges = [0:median(NumOfPieces(idx))/4:median(NumOfPieces(idx))*6];
histogram(NumOfPieces(idx),edges)
title({'Expected Number of Debris Pieces Generated'; 'If a Non-Catastrophic Collision Occurs'})
xlabel('Number of Pieces')
ylabel({'Incidence Count ';['(' num2str(length(NumOfPieces),'%.0f') ' Total Trials)']})
box on
grid on
% Add Text Indicating probability of Catastrophic Collision
yl = ylim;
xl = xlim;
text(xl(2)*0.98,yl(2)*0.97,...
{[CollisionProbabilityText '% Chance of Catastrophic Collision'];
[num2str(ExpectedNumberofPieces,'%.0f') ' Expected Debris Pieces '];
'(Non-Catastrophic Collision)'},...
'HorizontalAlignment','right',...
'VerticalAlignment','top',...
'EdgeColor','k',...
'BackgroundColor',[1 1 1])
% Generate CDF of distribution
subplot(2,1,2);
hold on
% Plot CDF
plot([0 reshape(sort(NumOfPieces(idx),'ascend'),1,length(NumOfPieces(idx))) xl(2)],...
[CDFcounts(1:length(idx)+1) CDFcounts(length(idx)+1)],...
'LineWidth',2,...
'Color','b')
hold off
title({'Cumulative Distribution Function of';'Expected Non-Catastrophic Debris Pieces'})
xlabel('Number of Pieces')
ylabel({'Cumulative Percentage'})
box on
grid on
xlim(xl);
ylim([0 100]);
if ~isempty(OutputFolder)
% Save Figures
saveas(h,fullfile(OutputFolder,[OutputID '_CollisionConsequence_NonCatastrophicDebrisPieces.fig']));
saveas(h,fullfile(OutputFolder,[OutputID '_CollisionConsequence_NonCatastrophicDebrisPieces.png']));
end
if CloseFigures
close(h)
end
end
%% Generate Number of Pieces Distribution Plots for Catastrophic Collisions
% Only generate figure if Catastrophic Collision Probability above 5%
if sum(Catastrophic)/length(Catastrophic)*100 > 5
h= figure('Position',[75 75 550 700],...
'Name','Catastrophic Debris Piece Distribution');
idx = find(Catastrophic);
ExpectedNumberofPieces = round(10^mean(log10(NumOfPieces(idx))));
% generate Histogram of distribution
subplot(2,1,1);
% define bin edges expecting to represet a chi square distribution
edges = [min(NumOfPieces(idx)):(median(NumOfPieces(idx))-min(NumOfPieces(idx)))/4:median(NumOfPieces(idx))+(median(NumOfPieces(idx))-min(NumOfPieces(idx)))*6];
histogram(NumOfPieces(idx),edges)
title({'Expected Number of Debris Pieces Generated'; 'If a Catastrophic Collision Occurs'})
xlabel('Number of Pieces')
ylabel({'Incidence Count ';['(' num2str(length(NumOfPieces),'%.0f') ' Total Trials)']})
box on
grid on
% Add Text Indicating probability of Catastrophic Collision
yl = ylim;
xl = xlim;
text(xl(1)+(xl(2)-xl(1))*0.98,yl(2)*0.97,...
{[CollisionProbabilityText '% Chance of Catastrophic Collision'];
[num2str(ExpectedNumberofPieces,'%.0f') ' Expected Debris Pieces '];
'(Catastrophic Collision)'},...
'HorizontalAlignment','right',...
'VerticalAlignment','top',...
'EdgeColor','k',...
'BackgroundColor',[1 1 1])
% Generate CDF of distribution
subplot(2,1,2);
hold on
% Plot CDF
plot([xl(1) reshape(sort(NumOfPieces(idx),'ascend'),1,length(NumOfPieces(idx)))],...
[CDFcounts(length(NumOfPieces)-length(idx)+2) CDFcounts(length(NumOfPieces)-length(idx)+2:end)],...
'LineWidth',2,...
'Color','b')
hold off
title({'Cumulative Distribution Function of';'Expected Catastrophic Debris Pieces'})
xlabel('Number of Pieces')
ylabel({'Cumulative Percentage'})
box on
grid on
xlim(xl);
ylim([0 100]);
if ~isempty(OutputFolder)
% Save Figures
saveas(h,fullfile(OutputFolder,[OutputID '_CollisionConsequence_CatastrophicDebrisPieces.fig']));
saveas(h,fullfile(OutputFolder,[OutputID '_CollisionConsequence_CatastrophicDebrisPieces.png']));
end
if CloseFigures
close(h)
end
end
%% Generate Secondary Object Mass Distribution Plots
if ~isempty(massVec)
g= figure('Position',[75 75 550 700],...
'Name','Secondary Mass Distribution');
% generate Histogram of distribution
subplot(2,1,1);
% define bin edges expecting to represet a chi square distribution
edges = [0:median(massVec)/4:median(massVec)*6];
histogram(massVec,edges)
title({'Predicted Secondary Object Mass Distribution'})
xlabel('Secondary Mass (kg)')
ylabel({'Incidence Count ';['(' num2str(length(massVec),'%.0f') ' Total Trials)']})
box on
grid on
% Add Text Indicating probability of Catastrophic Collision
yl = ylim;
xl = xlim;
text(xl(2)*0.98,yl(2)*0.97,...
[CollisionProbabilityText '% Chance of Catastrophic Collision'],...
'HorizontalAlignment','right',...
'VerticalAlignment','top',...
'EdgeColor','k',...
'BackgroundColor',[1 1 1])
% Generate CDF of distribution
subplot(2,1,2);
hold on
% Plot CDF
plot([0 reshape(sort(massVec,'ascend'),1,length(massVec))],...
[0:100/length(massVec):100],...
'LineWidth',2,...
'Color','b')
% Add Catastrophic Collision Threshold
if CatastrophicThresholdMass < xl(2)
plot([CatastrophicThresholdMass CatastrophicThresholdMass],...
[0 100],...
'LineWidth',2,...
'Color','r')
legend('CDF','Catastrophic Collision Threshold')
else
text(xl(2)*0.98,3,...
{'Catastrophic Collision Threshold';
['(40,000 J/kg): ' num2str(CatastrophicThresholdMass,'%0.2f') ' kg']},...
'HorizontalAlignment','right',...
'VerticalAlignment','bottom',...
'EdgeColor','k',...
'BackgroundColor',[1 1 1])
end
hold off
title({'Cumulative Distribution Function of';'Secondary Object Mass'})
xlabel('Secondary Mass (kg)')
ylabel({'Cumulative Percentage'})
box on
grid on
xlim(xl);
ylim([0 100]);
if ~isempty(OutputFolder)
% Save Figures
saveas(g,fullfile(OutputFolder,[OutputID '_CollisionConsequence_SecondaryMass.fig']));
saveas(g,fullfile(OutputFolder,[OutputID '_CollisionConsequence_SecondaryMass.png']));
end
if CloseFigures
close(g)
end
end
Status = 1;
catch
%% Close Existing Collision Consequence figure windows if open
try
close('Secondary Mass Distribution')
catch
end
try
close('Non-Catastrophic Debris Piece Distribution')
catch
end
try
close('Catastrophic Debris Piece Distribution')
catch
end
warning('An Error occured attempting to generate collision consequence plots')
Status = 0;
return
end
% ----------------- END OF CODE ------------------
%
% Please record any changes to the software in the change history
% shown below:
%
% ----------------- CHANGE HISTORY ------------------
% Developer | Date | Description
% ---------------------------------------------------
% T. Lechtenberg | 05-22-2018 | Initial Development
% L. Baars | 02-14-2024 | Added extra documentation for using this
% function. In addition, made the massVec
% array optional so that the other two graphs
% can be generated if this data is not
% available.
% |