sandbox/YiDai/BASI/relax_basi2D.c
Relaxation function in basilisk
The relaxation function in poisson solver is used here to solver 2D poisson equation same as here
// #include "grid/multigrid.h"
#include "utils.h"
#include "poisson.h"
double solution(double x, double y) { return (sin(pi * x) + cos(pi * y)); }
scalar U[], f[], ee[];
// int nrelax = 10000;
int depth = 8;
// void * data;
struct Poisson pp;
const scalar lambda[] = 0;
[right] = dirichlet(solution(x, y));
U[left] = dirichlet(solution(x, y));
U[top] = dirichlet(solution(x, y));
U[bottom] = dirichlet(solution(x, y));
U
int main()
{
.a = U;
pp.b = f;
pp.alpha = unityf;
pp.lambda = lambda;
pp= 2 * pi;
L0 = -L0 / 2.;
X0 = -L0 / 2.;
Y0
(1 << depth);
init_gridforeach ()
{
[] = 0;
U[] = -sq(pi) * sin(pi * x) - sq(pi) * cos(pi * y);
f}
double Tolerance = 2;
double sumerror = 0.;
foreach ()
{
+= fabs(solution(x, y));
sumerror }
printf("%g\n", sumerror);
int j = 0;
while (sumerror > Tolerance)
{
double e = 0;
relax({U}, {f}, depth, &pp);
foreach ()
{
+= fabs(U[] - solution(x, y));
e }
if (e < sumerror)
= e;
sumerror printf("%d %g %g\n", j, sumerror, e);
++;
j}
foreach ()
{
[] = U[] - solution(x, y);
ee}
FILE *fp1 = fopen("outputfield_U", "w");
output_field({U}, fp1);
FILE *fp2 = fopen("outputfield_e", "w");
output_field({ee}, fp2);
}
reset
plot[-1:7] 'log' using 1:2 with points t "solver", sin(3.*pi*x) with lines t "analytical"
reset
plot[-1:7][-0.35:0.35] 'log' using 1:3 with l t "error"
Using brutal force iteration does not work in this case