Skip to content

Commit 313a621

Browse files
committed
Flow velocity improvements in the new system
1 parent 29b445e commit 313a621

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

src/+otp/+qg/QuasiGeostrophicProblem.m

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ function onSettingsChanged(obj)
119119

120120
bc = 'DD';
121121

122-
% create Laplacian
123-
Ddx = otp.utils.pde.Dd(n, xdomain, 1, 2, bc(1));
124-
Ddy = otp.utils.pde.Dd(n, ydomain, 2, 2, bc(2));
125-
126122
% create the spatial derivatives
127123
Dx = otp.utils.pde.Dd(nx, xdomain, 1, 1, bc(1));
128124
DxT = Dx.';
@@ -167,9 +163,9 @@ function onSettingsChanged(obj)
167163
%% Distance function, and flow velocity
168164
obj.DistanceFunction = @(t, y, i, j) otp.qg.distfn(t, y, i, j, nx, ny);
169165

170-
obj.FlowVelocityMagnitude = @(psi) otp.qg.flowvelmag(psi, Ddx, Ddy);
166+
obj.FlowVelocityMagnitude = @(psi) otp.qg.flowvelmag(psi, Dx, Dy);
171167

172-
obj.JacobianFlowVelocityMagnitudeVectorProduct = @(psi, u) otp.qg.jacflowvelmagvp(psi, u, Ddx, Ddy);
168+
obj.JacobianFlowVelocityMagnitudeVectorProduct = @(psi, u) otp.qg.jacflowvelmagvp(psi, u, Dx, Dy);
173169

174170
end
175171

src/+otp/+qg/flowvelmag.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
function m = flowvelmag(psi, Ddx, Ddy)
1+
function m = flowvelmag(psi, Dx, Dy)
22

3-
m = sqrt((Ddx*psi).^2 + (Ddy*psi).^2);
3+
nx = size(Dx, 1);
4+
ny = size(Dy, 1);
5+
6+
Dxpsi = reshape(Dx*reshape(psi, nx, []), nx, ny, []);
7+
Dypsi = permute(reshape(Dy*reshape(permute(reshape(psi, nx, ny, []), [2, 1, 3]), ny, []), ny, nx, []), [2, 1, 3]);
8+
9+
m = reshape(sqrt((Dxpsi).^2 + (Dypsi).^2), nx*ny, []);
410

511
end

src/+otp/+qg/jacflowvelmagvp.m

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
function J = jacflowvelmagvp(psi, u, Ddx, Ddy)
1+
function J = jacflowvelmagvp(psi, v, Dx, Dy)
22

3-
m = sqrt((Ddx*psi).^2 + (Ddy*psi).^2);
3+
nx = size(Dx, 1);
4+
ny = size(Dy, 1);
45

5-
dpsix = Ddx*psi;
6-
dpsiy = Ddy*psi;
6+
N = size(v, 2);
77

8-
J = (1./m).*(dpsix.*(Ddx*u) + dpsiy.*(Ddy*u));
8+
psi = repmat(psi, 1, N);
9+
10+
dpsix = reshape(Dx*reshape(psi, nx, []), nx, ny, []);
11+
dpsiy = permute(reshape(Dy*reshape(permute(reshape(psi, nx, ny, []), [2, 1, 3]), ny, []), ny, nx, []), [2, 1, 3]);
12+
13+
dvx = reshape(Dx*reshape(v, nx, []), nx, ny, []);
14+
dvy = permute(reshape(Dy*reshape(permute(reshape(v, nx, ny, []), [2, 1, 3]), ny, []), ny, nx, []), [2, 1, 3]);
15+
16+
m = sqrt((dpsix).^2 + (dpsiy).^2);
17+
18+
J = reshape((1./m).*(dpsix.*(dvx) + dpsiy.*(dvy)), nx*ny, []);
919

1020
end

0 commit comments

Comments
 (0)