Skip to content
Snippets Groups Projects
Commit c84855d5 authored by Chichi Lalescu's avatar Chichi Lalescu
Browse files

move py files to own folder

parent f74eb0b5
No related branches found
No related tags found
No related merge requests found
...@@ -18,4 +18,3 @@ ...@@ -18,4 +18,3 @@
# #
######################################################################## ########################################################################
File moved
File moved
########################################################################
#
# 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
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
######################################################################## ########################################################################
import bfps
from code import code from bfps.code import code
import numpy as np import numpy as np
import subprocess import subprocess
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
...@@ -202,7 +202,7 @@ class stat_test(code): ...@@ -202,7 +202,7 @@ class stat_test(code):
return Rdata0 return Rdata0
def convergence_test(opt): def convergence_test(opt):
c = stat_test(name = opt.test_name) c = stat_test(name = 'convergence_test')
c.parameters['nx'] = opt.n c.parameters['nx'] = opt.n
c.parameters['ny'] = opt.n c.parameters['ny'] = opt.n
c.parameters['nz'] = opt.n c.parameters['nz'] = opt.n
...@@ -240,7 +240,7 @@ def convergence_test(opt): ...@@ -240,7 +240,7 @@ def convergence_test(opt):
Kdata2 = padd_with_zeros(Kdata0, opt.n*2) Kdata2 = padd_with_zeros(Kdata0, opt.n*2)
Kdata2.tofile("test2_cvorticity_i00000") Kdata2.tofile("test2_cvorticity_i00000")
c.run(ncpu = opt.ncpu, simname = 'test2') 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) stats1 = np.fromfile('test1_stats.bin', dtype = dtype)
stats2 = np.fromfile('test2_stats.bin', dtype = dtype) stats2 = np.fromfile('test2_stats.bin', dtype = dtype)
stats_vortex = np.loadtxt('../vortex/sim_000000.log') stats_vortex = np.loadtxt('../vortex/sim_000000.log')
...@@ -285,7 +285,7 @@ def convergence_test(opt): ...@@ -285,7 +285,7 @@ def convergence_test(opt):
return None return None
def Kolmogorov_flow_test(opt): 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['nx'] = opt.n
c.parameters['ny'] = opt.n c.parameters['ny'] = opt.n
c.parameters['nz'] = opt.n c.parameters['nz'] = opt.n
...@@ -311,7 +311,7 @@ def Kolmogorov_flow_test(opt): ...@@ -311,7 +311,7 @@ def Kolmogorov_flow_test(opt):
'test_rvorticity_i00000', 'test_rvorticity_i00000',
dtype = np.float32).reshape(opt.n, opt.n, opt.n, 3) dtype = np.float32).reshape(opt.n, opt.n, opt.n, 3)
tdata = Rdata.transpose(3, 0, 1, 2).copy() 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) stats = np.fromfile('test_stats.bin', dtype = dtype)
fig = plt.figure(figsize = (12,6)) fig = plt.figure(figsize = (12,6))
a = fig.add_subplot(121) a = fig.add_subplot(121)
...@@ -385,7 +385,6 @@ def Kolmogorov_flow_test(opt): ...@@ -385,7 +385,6 @@ def Kolmogorov_flow_test(opt):
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('test_name', type = str)
parser.add_argument('--run', dest = 'run', action = 'store_true') parser.add_argument('--run', dest = 'run', action = 'store_true')
parser.add_argument('--ncpu', type = int, dest = 'ncpu', default = 2) parser.add_argument('--ncpu', type = int, dest = 'ncpu', default = 2)
parser.add_argument('--nsteps', type = int, dest = 'nsteps', default = 16) parser.add_argument('--nsteps', type = int, dest = 'nsteps', default = 16)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment