Skip to content

Commit 53de139

Browse files
committed
Make tensor size an optional argument
1 parent b3d4919 commit 53de139

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

drive/matlab/operators/conv_tensor_reduced.m

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
%
77
% Note: Dealiasing is not currently implemented. Is it needed?
88
% Wrong, the snapshots are already dealiased.
9+
10+
% C computes Phi.T*(u.grad(u)) = Phi.T*((Phi*u_coef).(grad(Phi)*u_coef))
11+
% By forming the convection tensor.
912
function [out_coef] = conv_tensor_reduced(ucoef, pod_u, pod_v, x, y, tensor_size)
10-
%x=snaps.flds{1}.x;
11-
%y=snaps.flds{1}.y;
12-
persistent Me rx ry sx sy jaci d lgrad nL nb tensor nb_i nb_j nb_k
13-
if isempty(lgrad)
13+
14+
%persistent Me rx ry sx sy jaci d lgrad nL nb tensor nb_i nb_j nb_k
15+
persistent tensor nb nb_i nb_j nb_k
16+
17+
if isempty(tensor)
1418
nx1 = size(x,1);
1519
[zi, w] = zwgll(nx1-1);
1620
d = deriv_mat(zi);
@@ -20,26 +24,32 @@
2024
nb = size(pod_u,2)
2125
Me = reshape(jac.*(w*w'),nL,1);
2226

23-
nb_i = tensor_size(1);
24-
nb_j = tensor_size(2);
25-
nb_k = tensor_size(3);
26-
27-
%nb_j=8;
28-
%nb_i=8;
29-
%nb_k=8;
30-
31-
nb_j = min([nb_j,nb]);%nb - 1; % Number of gradients of pod bases calculated
32-
nb_i = min([nb_i,nb]);%nb - 1; % Number of stacked matrices
33-
nb_k = min([nb_k,nb-1]); % Number of output coefficients
27+
if nargin < 6
28+
% Default to full tensor if dimensions are excluded
29+
nb_i = nb;
30+
nb_j = nb;
31+
nb_k = nb - 1;
32+
else
33+
nb_i = tensor_size(1); % Number of gradients of pod bases calculated (The grad(Phi) contribution to the tensor
34+
nb_j = tensor_size(2); % Number of stacked matrices (The Phi in Phi*u_coef)
35+
nb_k = tensor_size(3); % Number of output coefficients
3436

37+
% Rescue the user or throw an error?
38+
assert(nb_i <= nb);
39+
assert(nb_j <= nb);
40+
assert(nb_k <= nb-1);
41+
end
3542

3643

3744
if false; % Normal way of calculating the gradient
45+
% Should just get rid of this
3846
[ux_fom, uy_fom] = lgrad(u_fom, 0);
3947
[vx_fom, vy_fom] = lgrad(v_fom, 0);
4048
else
4149
% Kento's ROM approach. Calculate the gradients of the POD modes
42-
50+
assert(nb_i <= nb);
51+
assert(nb_j <= nb);
52+
assert(nb_k < nb);
4353

4454
ux_pods = zeros([nL,nb_j]);
4555
uy_pods = zeros(size(ux_pods));

0 commit comments

Comments
 (0)