-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariable_poisson_solver_example.m
More file actions
57 lines (49 loc) · 1.76 KB
/
variable_poisson_solver_example.m
File metadata and controls
57 lines (49 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function variable_poisson_solver_example()
%VARIABLE_POISSON_SOLVER_EXAMPLE End-to-end variable-coefficient Poisson solve.
t = linspace(0, 2*pi, 120).';
t(end) = [];
curve = [cos(t), 0.85 * sin(t)];
surface = kp.geometry.EmbeddedSurface();
surface.setDataSites(curve);
surface.buildClosedGeometricModelPS(2, 0.05, size(curve, 1));
surface.buildLevelSetFromGeometricModel([]);
generator = kp.nodes.DomainNodeGenerator();
domain = generator.buildDomainDescriptorFromGeometry(surface, 0.085, ...
'Seed', 21, ...
'StripCount', 5, ...
'DoOuterRefinement', true, ...
'OuterFractionOfh', 0.5, ...
'OuterRefinementZoneSizeAsMultipleOfh', 2.0);
uExact = @(X) sin(X(:, 1)) + cos(0.75 * X(:, 2)) + 0.2 * X(:, 1) .* X(:, 2);
aCoeff = @(X) 1.5 + 0.3 * X(:, 1) - 0.2 * X(:, 2);
forcing = @(X) manufacturedForcing(X, aCoeff);
solver = kp.solvers.VariablePoissonSolver( ...
'LapAssembler', 'fd', ...
'BCAssembler', 'fd', ...
'LapStencil', 'rbf', ...
'BCStencil', 'rbf');
targetOrder = 4;
solver.init(domain, targetOrder);
result = solver.solve( ...
forcing, ...
aCoeff, ...
@(Xb) zeros(size(Xb, 1), 1), ...
@(Xb) ones(size(Xb, 1), 1), ...
@(NeuCoeffs, DirCoeffs, nr, Xb) uExact(Xb)); %#ok<INUSD>
uTrue = uExact(domain.getIntBdryNodes());
err = result.u - uTrue;
fprintf('Variable-coefficient Poisson example\\n');
fprintf(' physical nodes: %d\\n', numel(result.u));
fprintf(' max error: %.6e\\n', max(abs(err)));
fprintf(' rms error: %.6e\\n', norm(err) / sqrt(numel(err)));
end
function f = manufacturedForcing(X, aCoeff)
x = X(:, 1);
y = X(:, 2);
a = aCoeff(X);
ux = cos(x) + 0.2 * y;
uy = -0.75 * sin(0.75 * y) + 0.2 * x;
lapU = -sin(x) - 0.5625 * cos(0.75 * y);
gradA_dot_gradU = 0.3 * ux - 0.2 * uy;
f = -(a .* lapU + gradA_dot_gradU);
end