diff --git a/__init__.py b/bfps/__init__.py similarity index 99% rename from __init__.py rename to bfps/__init__.py index ae4f14ffded5b15a56b45e77abed87eadd759df5..378822cd19c5836d8fff45186adac4e256fee159 100644 --- a/__init__.py +++ b/bfps/__init__.py @@ -18,4 +18,3 @@ # ######################################################################## - diff --git a/base.py b/bfps/base.py similarity index 100% rename from base.py rename to bfps/base.py diff --git a/code.py b/bfps/code.py similarity index 100% rename from code.py rename to bfps/code.py diff --git a/bfps/tools.py b/bfps/tools.py new file mode 100644 index 0000000000000000000000000000000000000000..1f22dac46c13ef6edd9aec6553ece3ad1c222a5f --- /dev/null +++ b/bfps/tools.py @@ -0,0 +1,64 @@ +######################################################################## +# +# Copyright 2015 Max Planck Institute for Dynamics and SelfOrganization +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Contact: Cristian.Lalescu@ds.mpg.de +# +######################################################################## + + + +import numpy as np + +def generate_data_3D( + n, + dtype = np.complex128, + p = 1.5): + """ + generate something that has the proper shape + """ + assert(n % 2 == 0) + a = np.zeros((n, n, n/2+1), dtype = dtype) + a[:] = np.random.randn(*a.shape) + 1j*np.random.randn(*a.shape) + k, j, i = np.mgrid[-n/2+1:n/2+1, -n/2+1:n/2+1, 0:n/2+1] + k = (k**2 + j**2 + i**2)**.5 + k = np.roll(k, n//2+1, axis = 0) + k = np.roll(k, n//2+1, axis = 1) + a /= k**p + a[0, :, :] = 0 + a[:, 0, :] = 0 + a[:, :, 0] = 0 + ii = np.where(k == 0) + a[ii] = 0 + ii = np.where(k > n/3) + a[ii] = 0 + return a + +def padd_with_zeros( + a, + n, + odtype = None): + if (type(odtype) == type(None)): + odtype = a.dtype + assert(a.shape[0] <= n) + b = np.zeros((n, n, n/2 + 1) + a.shape[3:], dtype = odtype) + m = a.shape[0] + b[ :m/2, :m/2, :m/2+1] = a[ :m/2, :m/2, :m/2+1] + b[ :m/2, n-m/2: , :m/2+1] = a[ :m/2, m-m/2: , :m/2+1] + b[n-m/2: , :m/2, :m/2+1] = a[m-m/2: , :m/2, :m/2+1] + b[n-m/2: , n-m/2: , :m/2+1] = a[m-m/2: , m-m/2: , :m/2+1] + return b + + diff --git a/test.py b/test.py index c413469f69cb0490bc54440642a2f8038d530ad1..c3fa4d36882a637a6f484a893e5374dc65ff800e 100755 --- a/test.py +++ b/test.py @@ -20,8 +20,8 @@ ######################################################################## - -from code import code +import bfps +from bfps.code import code import numpy as np import subprocess import matplotlib.pyplot as plt @@ -202,7 +202,7 @@ class stat_test(code): return Rdata0 def convergence_test(opt): - c = stat_test(name = opt.test_name) + c = stat_test(name = 'convergence_test') c.parameters['nx'] = opt.n c.parameters['ny'] = opt.n c.parameters['nz'] = opt.n @@ -240,7 +240,7 @@ def convergence_test(opt): Kdata2 = padd_with_zeros(Kdata0, opt.n*2) Kdata2.tofile("test2_cvorticity_i00000") c.run(ncpu = opt.ncpu, simname = 'test2') - dtype = pickle.load(open(opt.test_name + '_dtype.pickle')) + dtype = pickle.load(open(c.name + '_dtype.pickle')) stats1 = np.fromfile('test1_stats.bin', dtype = dtype) stats2 = np.fromfile('test2_stats.bin', dtype = dtype) stats_vortex = np.loadtxt('../vortex/sim_000000.log') @@ -285,7 +285,7 @@ def convergence_test(opt): return None def Kolmogorov_flow_test(opt): - c = stat_test(name = opt.test_name) + c = stat_test(name = 'Kflow_test') c.parameters['nx'] = opt.n c.parameters['ny'] = opt.n c.parameters['nz'] = opt.n @@ -311,7 +311,7 @@ def Kolmogorov_flow_test(opt): 'test_rvorticity_i00000', dtype = np.float32).reshape(opt.n, opt.n, opt.n, 3) tdata = Rdata.transpose(3, 0, 1, 2).copy() - dtype = pickle.load(open(opt.test_name + '_dtype.pickle')) + dtype = pickle.load(open(c.name + '_dtype.pickle')) stats = np.fromfile('test_stats.bin', dtype = dtype) fig = plt.figure(figsize = (12,6)) a = fig.add_subplot(121) @@ -385,7 +385,6 @@ def Kolmogorov_flow_test(opt): if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('test_name', type = str) parser.add_argument('--run', dest = 'run', action = 'store_true') parser.add_argument('--ncpu', type = int, dest = 'ncpu', default = 2) parser.add_argument('--nsteps', type = int, dest = 'nsteps', default = 16)