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

simplify test code

i.e. remove some redundant bits
parent 1b40c07b
Branches
Tags
No related merge requests found
......@@ -89,11 +89,13 @@ def double(opt):
subprocess.call([cp_command], shell = True)
return None
def NSlaunch(
def launch(
opt,
nu = None,
tracer_state_file = None):
c = bfps.NavierStokes(
tracer_state_file = None,
vorticity_field = None,
code_class = bfps.NavierStokes):
c = code_class(
work_dir = opt.work_dir,
fluid_precision = opt.precision)
assert((opt.nsteps % 4) == 0)
......@@ -124,7 +126,13 @@ def NSlaunch(
c.set_host_info({'type' : 'pc'})
if opt.run:
if opt.iteration == 0 and opt.initialize:
if type(vorticity_field) == type(None):
c.generate_vector_field(write_to_file = True)
else:
vorticity_field.tofile(
os.path.join(c.work_dir,
c.simname + "_c{0}_i{1:0>5x}".format('vorticity',
opt.iteration)))
if opt.iteration == 0:
for species in range(c.particle_species):
if type(tracer_state_file) == type(None):
......
......@@ -21,13 +21,20 @@
from test_base import *
def convergence_test(opt, code_launch_routine):
def convergence_test(
opt,
code_launch_routine,
init_vorticity = None,
code_class = bfps.NavierStokes):
### 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)
c0 = code_launch_routine(opt)
c0 = code_launch_routine(
opt,
vorticity_field = init_vorticity,
code_class = code_class)
opt.initialize = False
opt.work_dir = default_wd
double(opt)
......@@ -39,6 +46,8 @@ def convergence_test(opt, code_launch_routine):
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)
......@@ -49,6 +58,8 @@ def convergence_test(opt, code_launch_routine):
c2 = 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'))
# get real space fields
converter = bfps.fluid_converter(fluid_precision = opt.precision)
......@@ -202,5 +213,5 @@ def convergence_test(opt, code_launch_routine):
if __name__ == '__main__':
opt = parser.parse_args()
convergence_test(opt, NSlaunch)
convergence_test(opt, launch)
......@@ -70,60 +70,11 @@ class FrozenFieldParticles(bfps.NavierStokes):
"""
return None
def FFPlaunch(
opt,
nu = None,
tracer_state_file = None):
c = FrozenFieldParticles(
work_dir = opt.work_dir,
fluid_precision = opt.precision)
assert((opt.nsteps % 4) == 0)
c.parameters['nx'] = opt.n
c.parameters['ny'] = opt.n
c.parameters['nz'] = opt.n
if type(nu) == type(None):
c.parameters['nu'] = 5.5*opt.n**(-4./3)
else:
c.parameters['nu'] = nu
c.parameters['dt'] = 1e-2 * (64. / opt.n)
c.parameters['niter_todo'] = opt.nsteps
c.parameters['niter_out'] = opt.nsteps
c.parameters['niter_part'] = 1
c.parameters['famplitude'] = 0.2
c.parameters['nparticles'] = opt.nparticles
c.add_particles(kcut = 'fs->kM/2')
c.add_particles(integration_steps = 1, neighbours = opt.neighbours, smoothness = opt.smoothness)
c.add_particles(integration_steps = 2, neighbours = opt.neighbours, smoothness = opt.smoothness)
c.add_particles(integration_steps = 3, neighbours = opt.neighbours, smoothness = opt.smoothness)
c.add_particles(integration_steps = 4, neighbours = opt.neighbours, smoothness = opt.smoothness)
c.add_particles(integration_steps = 5, neighbours = opt.neighbours, smoothness = opt.smoothness)
c.add_particles(integration_steps = 6, neighbours = opt.neighbours, smoothness = opt.smoothness)
c.fill_up_fluid_code()
c.finalize_code()
c.write_src()
c.write_par()
c.set_host_info({'type' : 'pc'})
if opt.run:
if opt.iteration == 0 and opt.initialize:
c.generate_vector_field(write_to_file = True)
if opt.iteration == 0:
for species in range(c.particle_species):
if type(tracer_state_file) == type(None):
data = None
else:
data = tracer_state_file['particles/tracers{0}/state'.format(species)][0]
c.generate_tracer_state(
species = species,
write_to_file = False,
testing = True,
rseed = 3284,
data = data)
c.run(ncpu = opt.ncpu,
njobs = opt.njobs)
return c
from test_convergence import convergence_test
if __name__ == '__main__':
convergence_test(parser.parse_args(), FFPlaunch)
convergence_test(
parser.parse_args(),
launch,
code_class = FrozenFieldParticles)
......@@ -22,87 +22,46 @@
from test_base import *
from test_frozen_field import FrozenFieldParticles
from test_convergence import convergence_test
# use ABC flow
def generate_ABC_flow(c, Fmode, Famp):
Kdata = np.zeros((c.parameters['ny'],
c.parameters['nz'],
c.parameters['nx']//2+1,
def generate_ABC_flow(
parameters = {'nx': 32,
'ny': 32,
'nz': 32},
Fmode = 1,
Famp = 1.0,
dtype = np.complex64):
Kdata = np.zeros((parameters['ny'],
parameters['nz'],
parameters['nx']//2+1,
3),
dtype = c.ctype)
dtype = dtype)
Kdata[ Fmode, 0, 0, 0] = Famp/2.
Kdata[ Fmode, 0, 0, 2] = -Famp/2.*1j
Kdata[c.parameters['ny'] - Fmode, 0, 0, 0] = Famp/2.
Kdata[c.parameters['ny'] - Fmode, 0, 0, 2] = Famp/2.*1j
Kdata[parameters['ny'] - Fmode, 0, 0, 0] = Famp/2.
Kdata[parameters['ny'] - Fmode, 0, 0, 2] = Famp/2.*1j
Kdata[0, Fmode, 0, 0] = -Famp/2.*1j
Kdata[0, Fmode, 0, 1] = Famp/2.
Kdata[0, c.parameters['nz'] - Fmode, 0, 0] = Famp/2.*1j
Kdata[0, c.parameters['nz'] - Fmode, 0, 1] = Famp/2.
Kdata[0, parameters['nz'] - Fmode, 0, 0] = Famp/2.*1j
Kdata[0, parameters['nz'] - Fmode, 0, 1] = Famp/2.
Kdata[0, 0, Fmode, 1] = -Famp/2.*1j
Kdata[0, 0, Fmode, 2] = Famp/2.
return Kdata
def FFPlaunch(
opt,
nu = None,
tracer_state_file = None):
c = FrozenFieldParticles(
work_dir = opt.work_dir,
fluid_precision = opt.precision)
assert((opt.nsteps % 4) == 0)
c.parameters['nx'] = opt.n
c.parameters['ny'] = opt.n
c.parameters['nz'] = opt.n
if type(nu) == type(None):
c.parameters['nu'] = 5.5*opt.n**(-4./3)
else:
c.parameters['nu'] = nu
c.parameters['dt'] = 1e-2 * (64. / opt.n)
c.parameters['niter_todo'] = opt.nsteps
c.parameters['niter_out'] = opt.nsteps
c.parameters['niter_part'] = 1
c.parameters['famplitude'] = 0.2
c.parameters['nparticles'] = opt.nparticles
c.add_particles(kcut = 'fs->kM/2')
c.add_particles(integration_steps = 1, neighbours = opt.neighbours, smoothness = opt.smoothness)
c.add_particles(integration_steps = 2, neighbours = opt.neighbours, smoothness = opt.smoothness)
c.add_particles(integration_steps = 3, neighbours = opt.neighbours, smoothness = opt.smoothness)
c.add_particles(integration_steps = 4, neighbours = opt.neighbours, smoothness = opt.smoothness)
c.add_particles(integration_steps = 5, neighbours = opt.neighbours, smoothness = opt.smoothness)
c.add_particles(integration_steps = 6, neighbours = opt.neighbours, smoothness = opt.smoothness)
c.fill_up_fluid_code()
c.finalize_code()
c.write_src()
c.write_par()
c.set_host_info({'type' : 'pc'})
if opt.run:
if opt.iteration == 0 and opt.initialize:
Kdata = generate_ABC_flow(c, 1, 1)
Kdata.tofile(
os.path.join(c.work_dir,
c.simname + "_c{0}_i{1:0>5x}".format('vorticity', opt.iteration)))
if opt.iteration == 0:
for species in range(c.particle_species):
if type(tracer_state_file) == type(None):
data = None
else:
data = tracer_state_file['particles/tracers{0}/state'.format(species)][0]
c.generate_tracer_state(
species = species,
write_to_file = False,
testing = True,
rseed = 3284,
data = data)
c.run(ncpu = opt.ncpu,
njobs = opt.njobs)
return c
from test_convergence import convergence_test
if __name__ == '__main__':
convergence_test(parser.parse_args(), FFPlaunch)
opt = parser.parse_args()
Kdata = generate_ABC_flow(
parameters = {'nx': opt.n,
'ny': opt.n,
'nz': opt.n})
convergence_test(
opt,
launch,
code_class = FrozenFieldParticles,
init_vorticity = Kdata)
......@@ -24,12 +24,12 @@ from test_base import *
def plain(opt):
wd = opt.work_dir
opt.work_dir = wd + '/N{0:0>3x}_1'.format(opt.n)
c0 = NSlaunch(opt)
c0 = launch(opt)
c0.compute_statistics()
opt.work_dir = wd + '/N{0:0>3x}_2'.format(opt.n)
opt.njobs *= 2
opt.nsteps /= 2
c1 = NSlaunch(opt)
c1 = launch(opt)
c1.compute_statistics()
# plot energy and enstrophy
fig = plt.figure(figsize = (12, 12))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment