|
6 | 6 | % |
7 | 7 | % Note: Dealiasing is not currently implemented. Is it needed? |
8 | 8 | % 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. |
9 | 12 | 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) |
14 | 18 | nx1 = size(x,1); |
15 | 19 | [zi, w] = zwgll(nx1-1); |
16 | 20 | d = deriv_mat(zi); |
|
20 | 24 | nb = size(pod_u,2) |
21 | 25 | Me = reshape(jac.*(w*w'),nL,1); |
22 | 26 |
|
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 |
34 | 36 |
|
| 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 |
35 | 42 |
|
36 | 43 |
|
37 | 44 | if false; % Normal way of calculating the gradient |
| 45 | + % Should just get rid of this |
38 | 46 | [ux_fom, uy_fom] = lgrad(u_fom, 0); |
39 | 47 | [vx_fom, vy_fom] = lgrad(v_fom, 0); |
40 | 48 | else |
41 | 49 | % 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); |
43 | 53 |
|
44 | 54 | ux_pods = zeros([nL,nb_j]); |
45 | 55 | uy_pods = zeros(size(ux_pods)); |
|
0 commit comments