Skip to content
Snippets Groups Projects
Commit c1b51c1d authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

update fftw test, put in CI script

parent fcf9ac62
Branches
Tags
1 merge request!23WIP: Feature/use cmake
Pipeline #
......@@ -69,15 +69,12 @@ int symmetrize_test<rnumber>::do_work(void)
ptrdiff_t yindex,
ptrdiff_t zindex,
double k2){
if (k2 < kk->kM2)
{
test_field0->cval(cindex, 0, 0) = rdist(rgen);
test_field0->cval(cindex, 0, 1) = rdist(rgen);
test_field0->cval(cindex, 1, 0) = rdist(rgen);
test_field0->cval(cindex, 1, 1) = rdist(rgen);
test_field0->cval(cindex, 2, 0) = rdist(rgen);
test_field0->cval(cindex, 2, 1) = rdist(rgen);
}
if (k2 > 0)
{
test_field0->cval(cindex, 0, 0) /= sqrt(k2);
......@@ -98,12 +95,11 @@ int symmetrize_test<rnumber>::do_work(void)
}
});
// dealias (?!)
//kk->template low_pass<rnumber, THREE>(test_field0->get_cdata(), kk->kM);
kk->template dealias<rnumber, THREE>(test_field0->get_cdata());
// make the field divergence free
kk->template force_divfree<rnumber>(test_field0->get_cdata());
// apply symmetrize to test_field0
//test_field0->symmetrize();
test_field0->symmetrize();
// make copy in test_field1
......
#! /usr/bin/env python
import os
import numpy as np
#import cupy as np
import h5py
import sys
import bfps
from bfps import TEST
try:
import matplotlib.pyplot as plt
except:
plt = None
def main():
niterations = 10
nlist = [16, 32, 48, 24, 64, 12]
for ii in range(len(nlist)):
c = TEST()
c.launch(
['symmetrize_test',
'--nx', '32',
'--ny', '32',
'--nz', '32',
'--nx', str(nlist[ii]),
'--ny', str(nlist[(ii+1)%(len(nlist))]),
'--nz', str(nlist[(ii+2)%(len(nlist))]),
'--Lx', str(2+np.random.random()),
'--Ly', str(2+np.random.random()),
'--Lz', str(2+np.random.random()),
'--simname', 'fftw_vs_numpy_{0}'.format(ii),
'--np', '4',
'--ntpp', '1',
'--wd', './'] +
sys.argv[1:])
df = h5py.File(c.simname + '.h5', 'r')
df = h5py.File(c.simname + '_fields.h5', 'r')
field1_complex = df['field1/complex/0'].value
field1_real = df['field1/real/0'].value
npoints = field1_real.size//3
np_field1_real = np.fft.irfftn(field1_complex, axes = (0, 1, 2)).transpose(1, 0, 2, 3)
L2normr = np.sqrt(np.mean(field1_real**2))
err = np.max(np.abs(field1_real - np_field1_real*(np_field1_real.size/3)))
L2normr = np.sqrt(np.mean(np.sum(field1_real**2, axis = 3)))
np_L2normr = np.sqrt(np.mean(np.sum(np_field1_real**2, axis = 3)))
err = np.max(np.abs(field1_real - np_field1_real*npoints)) / L2normr
assert(err < 1e-5)
np_field1_complex = np.fft.rfftn(field1_real.transpose(1, 0, 2, 3), axes = (0, 1, 2)) / (np_field1_real.size/3)
np_field1_complex = np.fft.rfftn(field1_real.transpose(1, 0, 2, 3), axes = (0, 1, 2)) / npoints
L2norm0 = np.sqrt(np.sum(np.abs(field1_complex[:, :, 0])**2) + 2*np.sum(np.abs(field1_complex[:, :, 1:])**2))
L2norm1 = np.sqrt(np.sum(np.abs(np_field1_complex[:, :, 0])**2) + 2*np.sum(np.abs(np_field1_complex[:, :, 1:])**2))
err = np.max(np.abs(np_field1_complex - field1_complex))
err = np.max(np.abs(np_field1_complex - field1_complex)) / L2norm0
assert(err < 1e-5)
err = abs(L2normr - L2norm0) / L2norm0
assert(err < 1e-5)
print(L2normr, L2norm0, L2norm1)
if not type(plt) == type(None):
f = plt.figure()
a = f.add_subplot(121)
a.imshow(np.log(np.abs(np_field1_complex[:, :, 0, 0])), interpolation = 'nearest')
a = f.add_subplot(122)
a.imshow(np.log(np.abs(field1_complex[:, :, 0, 0])), interpolation = 'nearest')
f.savefig('symmetrize_test.pdf')
f.savefig(c.simname + '_complex_slice_kx0.pdf')
return None
if __name__ == '__main__':
......
......@@ -291,7 +291,8 @@ setup(
'bfps1 = bfps.__main__:main',
'bfps.test_NSVEparticles = bfps.test.test_bfps_NSVEparticles:main',
'bfps.test_particles = bfps.test.test_particles:main',
'bfps.test_Parseval = bfps.test.test_Parseval:main'],
'bfps.test_Parseval = bfps.test.test_Parseval:main',
'bfps.test_fftw = bfps.test.test_fftw:main'],
},
version = VERSION,
########################################################################
......
......@@ -36,10 +36,12 @@ $pythonbin setup.py install --prefix=$destdir
ls $destdir
ls $destdir/bin/
$pythonbin $destdir/bin/bfps.test_NSVEparticles
$pythonbin $destdir/bin/bfps.test_fftw
$pythonbin $destdir/bin/bfps.test_Parseval
$pythonbin $destdir/bin/bfps.test_NSVEparticles
# Clean
if [[ -d $destdir ]] ; then
rm -rf $destdir ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment