-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCombinatorialVortexDetection.m
More file actions
161 lines (137 loc) · 7.87 KB
/
CombinatorialVortexDetection.m
File metadata and controls
161 lines (137 loc) · 7.87 KB
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
%--------------------------------------------------------------------------
% Title: COMBINATORIAL VORTEX DETECTION (CVD) ALGORITHM
%
%
% Description:
% The CVD Algorithm is a research tool designed to streamline and automate vortex analysis in velocity vector fields
% obtained from simulations or experiments. Applicable to 2D2C datasets from computational fluid dynamics (CFD)
% and particle image velocimetry (PIV), the code implements a processing workflow to identify potential vortices,
% confirm and characterize them using advanced methods, and generate visualizations to explore dynamics.
% The first stage detects possible vortex regions by locating local maxima in vorticity magnitude using
% the Maximum Vorticity (MV) method. Around each detected maximum, a Cross-Sectional Lines (CSL) approach
% further refines the estimated core location by analyzing circumferential velocities. Regions of Interest (ROIs)
% encompassing each potential vortex are then generated.
% The Winding Angle (WA) method next analyzes the ROIs to definitively identify and characterize vortices based
% on a winding angle threshold criterion. Key vortex properties are computed including circulation, area,
% core location, rotation direction and drift velocity.
% Finally, the code produces a serie of visualizations including streamline plots, color maps of vorticity magnitude,
% and vorticity profiles. These outputs help researchers visually examine vortex dynamics within the flow,
% complementing the quantitative analysis.
% In summary, the CVD Algorithm automates complex vortex identification and quantification tasks that
% previously required manual processing. By streamlining these processes and generating insightful visualizations,
% it enables deeper exploration of fluid flows and facilitates research in domains relying on analysis of coherent structures.
%
% Usage:
% 1. Load a vector field ('B00001.vc7') using the 'loadvec' function.
% 2. Adjust the orientation of the vector field for processing. This is a
% specific requirement for the current example.
% 3. Set parameters for vortex detection, such as intensity thresholds,
% structuring elements, and interpolation factor.
% 4. Initialize storage for vortex analysis results.
% 5. Process the vector field frames using the CVD algorithm and store
% vortex-related data.
%
% Dependencies:
% - The code assumes that you have the external toolboxes 'Image Processing',
% 'Signal Processing', 'PIVmat', and 'Wavelet'available in your MATLAB environment.
%
% Authors: Mathew Bussière, Guilherme Bessa, Bob Koch, and David Nobes.
% Department of Mechanical Engineering, University of Alberta,
% Edmonton, Alberta
% Contact: dnobes@ualberta.ca
% Version: 1.0
% Date: 10/6/2023
%--------------------------------------------------------------------------
%% INPUTS
vectorfield = loadvec('B00001.vc7');
imageInterval = [1]; % Range of image frames to analyze
timeStep = 2; % Increment between frames to process
timeIncrement = 1.6129e-04; % Time between each frame
%% Adjusting vector field orientation for processing
% This is a specific requirement for the current example.
v = vectorfield;
% Rotate matrices in proper orientation
v = rotatef(v,pi()/2,'trunc');
% Move the y-origin and x-origin to the center of the local vector map
v = shiftf(v,'c');
% Calculate vorticity and smooth
w = vec2scal(v, 'curl');
w = filterf(w, 1, 'gauss', 'same');
% Transpose matrices for construction of new matrix in proper orientation
vectorfield.vx = v.vx';
vectorfield.vy = v.vy';
vectorfield.rot = w.w';
%% PARAMETERS
thresholdIntensityVector = [0.2, 0.4, 0.6]; % Intensity thresholds for vortex detection
structuringElements = [3, 2, 1]; % Structuring elements for image thresholding
%% INITIALIZE STORAGE
vortexCirculation = {}; % Circulation for each vortex in each frame
vortexArea = {}; % Area for each vortex in each frame
vortexCircle = {}; % Circle fit parameters for each vortex
vortexLocation = {}; % Vortex core (x,y) coordinates
vortexWAngleStreamlines = {}; % Winding angle for each vortex line
vortexRotationSign = {}; % Rotation direction (+1/-1) for each vortex
vortexDriftVelocity = {}; % Drift velocity for each vortex
processedFrame = {}; % Track frames processed
%% INICIALIZE COUNTER
counter = 1;
%% MAIN PROCESSING LOOP
tic
for currentImage = imageInterval(1):timeStep:imageInterval(end)
%% Load vector field data
disp(['Processing frame: ' num2str(currentImage)]);
vectorFieldData = vectorfield(currentImage);
fileName = vectorfield(currentImage).name;
%% Detect vortices using Maximum Vorticity method (MV)
[vortexROIMap, numROIs, velocityData] = MaximumVorticityMethod ...
(vectorFieldData, thresholdIntensityVector, structuringElements);
%% Refine vortex locations using Cross-sectional Lines method (CSL)
[drift_vx, drift_vy, driftVelocity, xVortexCore, yVortexCore, radiiVortexCore] = CrossSectionLinesMethod ...
(vortexROIMap, numROIs, velocityData);
%% Generate Regions Of Interest (ROI)
% Inputs
skip = 5; % Spacing between streamline points (controls density)
boxFactorX = 2; % Factor to determine the size of the box around x-direction
boxFactorY = 2; % Factor to determine the size of the box around y-direction
[vortexXY, numStreamlines, ROIbox, ROIboxIndex] = RegionsOfInterest ...
(numROIs, velocityData, xVortexCore, yVortexCore, radiiVortexCore, skip, boxFactorX, boxFactorY, ...
drift_vx, drift_vy);
%% Winding Angle method (WA)
% Inputs
StartEndDistance = 8; % Threshold distance for start and end points of streamlines
maxThetaMax = pi()/3; % Maximum angle threshold for winding angle criteria
thresholdD = 12; % Threshold distance for streamline trimming
[windingAngleStreamlines, numROIs, bulkStreamlines, xVortexCore, yVortexCore, xacc, yacc,...
drift_vx, drift_vy, driftVelocity, ROIbox, ROIboxIndex, rotationSign] = WindingAngleMethod ...
(velocityData, numStreamlines, numROIs, vortexXY, StartEndDistance,...
maxThetaMax, thresholdD, xVortexCore, yVortexCore, drift_vx, drift_vy,...
driftVelocity, ROIbox, ROIboxIndex);
%% Compute circulation and area
[circulationValues, areaValues, circleProperties, vortexCore] = Circulation ...
(velocityData, numROIs, bulkStreamlines, xacc, yacc,...
xVortexCore, yVortexCore, radiiVortexCore);
%% Store data for this frame
vortexCirculation{counter} = circulationValues;
vortexArea{counter} = areaValues;
vortexCircle{counter} = circleProperties;
vortexLocation{counter} = vortexCore;
vortexWAngleStreamlines{counter} = windingAngleStreamlines;
vortexRotationSign{counter} = rotationSign;
vortexDriftVelocity{counter} = driftVelocity;
processedFrame{counter} = currentImage;
numVortices = numROIs;
%% PLOTS
% Streamlines + Vorticity Field
[figs1] = plotStreamlines(vortexXY, numStreamlines, ROIboxIndex, numROIs, velocityData, xVortexCore, yVortexCore);
% Streamlines according to WA:
[figs2] = plotStreamlinesWA(numROIs, xVortexCore, yVortexCore, windingAngleStreamlines, rotationSign, xacc, yacc);
% Vorticity and Velocity Profiles
[figs3, figs4] = plotProfiles(numROIs, velocityData, xVortexCore, yVortexCore, radiiVortexCore, drift_vy, rotationSign);
% Vortices Map
[figs5] = plotVorticesMap(thresholdIntensityVector, velocityData, circleProperties, windingAngleStreamlines, xVortexCore, yVortexCore, radiiVortexCore);
%% Increment counter
counter = counter + 1;
end
toc
clearvars -except vortexCirculation vortexArea vortexLocation...
vortexDriftVelocity vortexWAngleStreamlines vortexRotationSign processedFrame numVortices