|
1 | 1 | disp("Perf and math test matlab driver for FMM3D/Stokes")
|
2 |
| -disp("Source to target, stokeslet+stresslet (1-vec), vel pot only..."); |
3 |
| -% Barnett 8/4/23 |
| 2 | +% Barnett 8/4/23. Added traction output test, 4/12/24. |
4 | 3 |
|
5 | 4 | clear
|
6 | 5 | ns = 100000;
|
7 | 6 | nt = 100000;
|
8 | 7 | eps = 1e-3;
|
| 8 | + |
| 9 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 10 | +disp("Source to target, stokeslet+stresslet (1-vec), vel pot only..."); |
9 | 11 | ifstrs = 1; % include stresslets?
|
10 | 12 | ifppreg = 0; % no eval at sources
|
11 | 13 | ifppregtarg = 1; % just vel out
|
|
24 | 26 | t = toc;
|
25 | 27 | fprintf("%d to %d points, eps=%.3g, done in %.3g s (%.3g tot pts/sec)\n",ns,nt,eps,t,(ns+nt)/t)
|
26 | 28 | u = U.pottarg;
|
27 |
| -i = randi(nt); % which targ |
| 29 | +i = randi(nt); % which targ to check |
28 | 30 | fprintf("velpot targ(i=%d) =\n",i);
|
29 | 31 | disp(u(:,i))
|
30 | 32 |
|
|
42 | 44 | end
|
43 | 45 | end
|
44 | 46 | ui = 0.5 * ui; % FMM3D is 1/4pi off from true 1/8pi prefactor
|
45 |
| -fprintf("rel err vs direct at ith targ: %.3g\n",norm(u(:,i)-ui)/norm(ui)) |
| 47 | +fprintf("rel err vs direct at ith targ: %.3g\n\n",norm(u(:,i)-ui)/norm(ui)) |
| 48 | + |
| 49 | + |
| 50 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 51 | +disp("Stokeslet sources to targets: compute vel pot, traction at oriented targs..."); |
| 52 | +% just give the changes from the above setup... |
| 53 | +ifppregtarg = 3; % request everything |
| 54 | +srcinfo = rmfield(srcinfo,{'strslet','strsvec'}); |
| 55 | +targnor = rand(3,nt); % normal vectors for targets (eg, surface normals) |
| 56 | + |
| 57 | +tic; |
| 58 | +U = stfmm3d(eps,srcinfo,ifppreg,targ,ifppregtarg); |
| 59 | +t = toc; |
| 60 | +fprintf("%d to %d points with u,p,gradu: done in %.3g s (%.3g tot pts/sec)\n",ns,nt,t,(ns+nt)/t) |
| 61 | +p = U.pretarg; % pressure (1*ntarg) |
| 62 | +gradu = U.gradtarg; % grad vel (3*3*ntarg) |
| 63 | +shearstress = gradu + permute(gradu,[2 1 3]); % gradu + gradu^T |
| 64 | +% stress sigma = -pI + mu*(gradu+gradu^T), then T = sigma.n We assume mu=1. |
| 65 | +T = -(ones(3,1)*p).*targnor + squeeze(sum(shearstress .* reshape(kron(ones(3,1),targnor),3,3,nt),1)); % compute all tractions (painful tensor contraction in matlab) |
| 66 | +i = randi(nt); % which targ to check |
| 67 | +%fprintf("targ(i=%d): p=%.15g, gradu = \n",i,p(i)); disp(gradu(:,:,i)) |
| 68 | +fprintf("targ(i=%d) traction T = \n",i); |
| 69 | +disp(T(:,i)) |
46 | 70 |
|
| 71 | +% check T (target tractions) vs direct formula |
| 72 | +Ti = zeros(3,1); |
| 73 | +nori = targnor(:,i); |
| 74 | +for j=1:ns |
| 75 | + R = targ(:,i) - srcinfo.sources(:,j); % x-y with std sign (targ-src). |
| 76 | + r = sqrt(sum(R.^2)); % dist |
| 77 | + f = srcinfo.stoklet(:,j); % strength |
| 78 | + Ti = Ti - (3/(4*pi))*(1/r^5)*R*dot(nori,R)*dot(f,R); % true T_{ijk} n_j f_k |
| 79 | +end |
| 80 | +Ti = Ti * (4*pi); % FMM3D has 1/4pi missing in prefactor |
| 81 | +fprintf("rel err vs direct at ith targ: %.3g\n",norm(T(:,i)-Ti)/norm(Ti)) |
47 | 82 |
|
0 commit comments