sandbox/bderembl/filter.c
Filter function
#include "grid/multigrid.h"
#include "run.h"
The function below will replace the default one.
void waveletb (scalar s, scalar w)
{
({s});
restriction for (int l = depth() - 1; l >= 0; l--) {
foreach_coarse_level (l) {
foreach_child()
[] = s[]; w
.prolongation (point, s);
sforeach_child() {
double sp = s[];
[] = w[];
s/* difference between fine value and its prolongation */
[] -= sp;
w}
}
({w}, l + 1);
boundary_level }
/* root cell */
foreach_level(0)
[] = s[];
w({w}, 0);
boundary_level }
Inverse wavelet transform
void inverse_waveletb (scalar s, scalar w)
{
foreach_level(0)
[] = w[];
s({s}, 0);
boundary_level for (int l = 0; l <= depth() - 1; l++) {
foreach_coarse_level (l) {
.prolongation (point, s);
sforeach_child()
[] += w[];
s}
({s}, l + 1);
boundary_level }
}
Main loop
int main() {
= 1 << 8;
N init_grid (N);
scalar s[], w[], s2[];
[top] = 0;
s[bottom] = 0;
s[right] = 0;
s[left] = 0;
s
[top] = 0;
w[bottom] = 0;
w[right] = 0;
w[left] = 0;
w
[top] = 0;
s2[bottom] = 0;
s2[right] = 0;
s2[left] = 0;
s2
foreach()
[] = sin(2*pi*x)*sin(10*pi*y);
sboundary({s});
Wavelet transform
waveletb (s, w);
inverse_waveletb (s2, w);
Check that we recover the original signal (almost) exactly.
foreach()
assert (fabs(s[] - s2[]) < 1e-10);
char name[80];
sprintf (name,"out.dat");
FILE * fp = fopen (name, "w");
output_field ({s, s2}, fp, linear=1);
fclose(fp);
}
We plot the filtered field and the filter
import numpy as np
import matplotlib.pyplot as plt
= 'out.dat'
file1
= np.loadtxt(file1)
data
= data.shape
n1, n2
= int(np.sqrt(n1))
N = data[:,0].reshape((N,N))
x = data[:,1].reshape((N,N))
y = data[:,2].reshape((N,N))
p0 = data[:,3].reshape((N,N))
p1
plt.figure()
plt.contourf(x,y,p0)'field.png')
plt.savefig(
plt.figure()
plt.contourf(x,y,p1)'filter.png') plt.savefig(
