Skip to content

Commit f0430e7

Browse files
committed
add traction extraction demo to stfmm3dPerfTest.m
1 parent eef9634 commit f0430e7

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

matlab/Contents.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
% hfmm3dTest
1717
% emfmm3dTest
1818
% stfmm3dTest
19-
% stfmm3dPerfTest
19+
% stfmm3dPerfTest - demo and math test for stokeslet & stresslet, traction
2020
%
2121
% For examples of use see:
2222
% lfmm3d_example

matlab/stfmm3dPerfTest.m

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
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.
43

54
clear
65
ns = 100000;
76
nt = 100000;
87
eps = 1e-3;
8+
9+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10+
disp("Source to target, stokeslet+stresslet (1-vec), vel pot only...");
911
ifstrs = 1; % include stresslets?
1012
ifppreg = 0; % no eval at sources
1113
ifppregtarg = 1; % just vel out
@@ -24,7 +26,7 @@
2426
t = toc;
2527
fprintf("%d to %d points, eps=%.3g, done in %.3g s (%.3g tot pts/sec)\n",ns,nt,eps,t,(ns+nt)/t)
2628
u = U.pottarg;
27-
i = randi(nt); % which targ
29+
i = randi(nt); % which targ to check
2830
fprintf("velpot targ(i=%d) =\n",i);
2931
disp(u(:,i))
3032

@@ -42,6 +44,39 @@
4244
end
4345
end
4446
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))
4670

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))
4782

0 commit comments

Comments
 (0)