Commit bbe21174 authored by Chichi Lalescu's avatar Chichi Lalescu
Browse files

make convergence test work without particles

parent 8042fd7e
......@@ -103,6 +103,8 @@ class base(object):
return None
def pars_from_namespace(self, opt):
new_pars = vars(opt)
self.simname = opt.simname
self.work_dir = opt.work_dir
for k in self.parameters.keys():
self.parameters[k] = new_pars[k]
return None
......
......@@ -26,7 +26,7 @@ import numpy as np
class fluid_resize(bfps.fluid_base.fluid_particle_base):
def __init__(
self,
name = 'fluid_converter',
name = 'fluid_resize',
work_dir = './',
simname = 'test',
dtype = np.float32):
......@@ -35,6 +35,7 @@ class fluid_resize(bfps.fluid_base.fluid_particle_base):
work_dir = work_dir,
simname = simname,
dtype = dtype)
self.parameters['src_simname'] = 'test'
self.parameters['dst_iter'] = 0
self.parameters['dst_nx'] = 32
self.parameters['dst_ny'] = 32
......@@ -59,7 +60,7 @@ class fluid_resize(bfps.fluid_base.fluid_particle_base):
//begincpp
char fname[512];
fs0 = new fluid_solver<{0}>(
simname,
src_simname,
nx, ny, nz,
dkx, dky, dkz);
fs1 = new fluid_solver<{0}>(
......
......@@ -40,8 +40,8 @@ def double(opt):
old_simname = 'N{0:0>3x}'.format(opt.n)
new_simname = 'N{0:0>3x}'.format(opt.n*2)
c = fluid_resize(
work_dir = opt.work_dir + '/resize',
simname = old_simname,
work_dir = opt.work_dir,
simname = old_simname + '_double',
dtype = opt.precision)
c.parameters['nx'] = opt.n
c.parameters['ny'] = opt.n
......@@ -50,22 +50,13 @@ def double(opt):
c.parameters['dst_ny'] = 2*opt.n
c.parameters['dst_nz'] = 2*opt.n
c.parameters['dst_simname'] = new_simname
c.parameters['src_simname'] = old_simname
c.write_src()
c.set_host_info({'type' : 'pc'})
if not os.path.isdir(os.path.join(opt.work_dir, 'resize')):
os.mkdir(os.path.join(opt.work_dir, 'resize'))
c.write_par()
cp_command = ('cp {0}/test_cvorticity_i{1:0>5x} {2}/{3}_cvorticity_i{1:0>5x}'.format(
opt.work_dir + '/' + old_simname, opt.iteration, opt.work_dir + '/resize', old_simname))
subprocess.call([cp_command], shell = True)
c.run(ncpu = opt.ncpu,
err_file = 'err_' + old_simname + '_' + new_simname,
out_file = 'out_' + old_simname + '_' + new_simname)
if not os.path.isdir(os.path.join(opt.work_dir, new_simname)):
os.mkdir(os.path.join(opt.work_dir, new_simname))
cp_command = ('cp {2}/{3}_cvorticity_i{1:0>5x} {0}/test_cvorticity_i{1:0>5x}'.format(
opt.work_dir + '/' + new_simname, 0, opt.work_dir + '/resize', new_simname))
subprocess.call([cp_command], shell = True)
err_file = 'err_',
out_file = 'out_')
return None
def launch(
......@@ -86,6 +77,7 @@ def launch(
else:
c.parameters['nu'] = nu
c.parameters['dt'] = 5e-3 * (64. / opt.n)
c.parameters['niter_out'] = c.parameters['niter_todo']
c.parameters['niter_part'] = 1
c.parameters['famplitude'] = 0.2
if c.parameters['nparticles'] > 0:
......
......@@ -19,6 +19,11 @@
#
########################################################################
import numpy as np
import h5py
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from test_base import *
def convergence_test(
......@@ -29,32 +34,28 @@ def convergence_test(
### test Navier Stokes convergence
# first, run code three times, doubling and quadrupling the resolution
# initial condition and viscosity must be the same!
default_wd = opt.work_dir
opt.work_dir = default_wd + '/N{0:0>3x}'.format(opt.n)
opt.simname = 'N{0:0>3x}'.format(opt.n)
c0 = code_launch_routine(
opt,
vorticity_field = init_vorticity,
code_class = code_class)
opt.initialize = False
opt.work_dir = default_wd
double(opt)
opt.iteration = 0
opt.n *= 2
opt.nsteps *= 2
opt.niter_todo *= 2
opt.ncpu *= 2
opt.work_dir = default_wd + '/N{0:0>3x}'.format(opt.n)
opt.simname = 'N{0:0>3x}'.format(opt.n)
c1 = code_launch_routine(
opt,
nu = c0.parameters['nu'],
vorticity_field = init_vorticity,
code_class = code_class,
tracer_state_file = h5py.File(os.path.join(c0.work_dir, c0.simname + '.h5'), 'r'))
opt.work_dir = default_wd
double(opt)
opt.n *= 2
opt.nsteps *= 2
opt.niter_todo *= 2
opt.ncpu *= 2
opt.work_dir = default_wd + '/N{0:0>3x}'.format(opt.n)
opt.simname = 'N{0:0>3x}'.format(opt.n)
c2 = code_launch_routine(
opt,
nu = c0.parameters['nu'],
......
......@@ -9,6 +9,6 @@ changedir =
{envtmpdir}
commands =
cp -r {toxinidir}/tests {envtmpdir}
python tests/test_convergence.py -n 32 --run --initialize --ncpu 2 --nsteps 16 --precision single --wd "data/single"
python tests/test_convergence.py -n 32 --run --initialize --ncpu 2 --nsteps 16 --precision double --wd "data/double"
python tests/test_convergence.py -n 32 --run --initialize --ncpu 2 --niter_todo 16 --precision single --wd "data/single"
#python tests/test_convergence.py -n 32 --run --initialize --ncpu 2 --nparticles 32 --niter_todo 16 --precision double --wd "data/double"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment