-
Notifications
You must be signed in to change notification settings - Fork 2
/
phaseflow_cnem.m
60 lines (50 loc) · 1.66 KB
/
phaseflow_cnem.m
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
function v=phaseflow_cnem(yphasep,loc,dt,speedonlyflag)
% v = phaseflow_cnem(yphasep,loc,dt)
% Calculate instantaneous phase flow at every time point
%
% Inputs: yphasep - times-by-regions matrix of phases, assumed unwrapped
% loc - regions-by-3 matrix of points
% dt - time step
%
% Outputs: v - velocity struct, with fields:
% -- vnormp - speed
% -- vxp - x component
% -- vyp - y component
% -- vzp - z component
%
% JA Roberts, QIMR Berghofer, 2018
if nargin<4
speedonlyflag=0;
end
% assume phases unwrapped in time already
[~,dphidtp]=gradient(yphasep,dt);
fprintf('dphidt done...')
shpalpha=30; % alpha radius; may need tweaking depending on geometry
shp=alphaShape(loc,shpalpha);
bdy=shp.boundaryFacets;
B=grad_B_cnem(loc,bdy);
np=size(yphasep,1);
dphidxp=zeros(size(yphasep));
dphidyp=zeros(size(yphasep));
dphidzp=zeros(size(yphasep));
for j=1:np
yphase=yphasep(j,:);
yphase=yphase(:);
% wrap phases by differentiating exp(i*phi)
yphasor=exp(1i*yphase);
gradphasor=grad_cnem(B,yphasor);
dphidxp(j,:)=real(-1i*gradphasor(:,1).*conj(yphasor));
dphidyp(j,:)=real(-1i*gradphasor(:,2).*conj(yphasor));
dphidzp(j,:)=real(-1i*gradphasor(:,3).*conj(yphasor));
end
fprintf('gradphi done...')
normgradphip=sqrt(dphidxp.^2+dphidyp.^2+dphidzp.^2);
% magnitude of velocity = dphidt / magnitude of grad phi, as per Rubino et al. (2006)
vnormp=abs(dphidtp)./normgradphip;
v.vnormp=vnormp;
if ~speedonlyflag
v.vxp=vnormp.*-dphidxp./normgradphip; % magnitude * unit vector component
v.vyp=vnormp.*-dphidyp./normgradphip;
v.vzp=vnormp.*-dphidzp./normgradphip;
end
fprintf('v done...')