From e13b4a928f01fe3355d30686838df5c4a8c6417e Mon Sep 17 00:00:00 2001 From: ignis Date: Mon, 8 Mar 2021 11:40:21 +0900 Subject: [PATCH] initial commit for run all step bash script --- extract_all.py | 42 +++++++++++++++++++++++++ fluctuation_product_u_ddxc.py | 51 ++++++++++++++++++++++++++++++ run_in_case_dir.sh | 58 +++++++++++++++++++++++++++++++++++ sbatch-job-binning-ddxc-array | 35 +++++++++++++++++++++ 4 files changed, 186 insertions(+) create mode 100644 extract_all.py create mode 100644 fluctuation_product_u_ddxc.py create mode 100755 run_in_case_dir.sh create mode 100644 sbatch-job-binning-ddxc-array diff --git a/extract_all.py b/extract_all.py new file mode 100644 index 0000000..921e708 --- /dev/null +++ b/extract_all.py @@ -0,0 +1,42 @@ +import argparse +import datetime +import numpy as np +import dnstool +from pycompact import CompactScheme + +# Commandline argument parser +parser = argparse.ArgumentParser() +parser.add_argument("-c", "--case", help="target case name", required=True) +args = parser.parse_args() +params = vars(args) + +casename = params["case"] +u_idx = 1 +y_idx = 4 + +cases = dnstool.case_library() + +case = cases[casename] + +nx, ny, nz = case.shape + +cs = CompactScheme(nx, ny, nz, False, True, True, 4, 2, 2) + +file1 = "u.dat" +file2 = "c.dat" +file3 = "ddxc.dat" + +storage1 = np.memmap(file1, mode='w+', dtype=np.double, shape=(nx, len(case.data_files), ny, nz)) +storage2 = np.memmap(file2, mode='w+', dtype=np.double, shape=(nx, len(case.data_files), ny, nz)) +storage3 = np.memmap(file3, mode='w+', dtype=np.double, shape=(nx, len(case.data_files), ny, nz)) + +for i, fname in enumerate(case.data_files): + print(datetime.datetime.now(), i, fname) + time, u = case.read_single_field(fname, u_idx) + time, y = case.read_single_field(fname, y_idx) + c = (1. - y) + storage1[:,i,:,:] = u.T + storage2[:,i,:,:] = c.T + storage3[:,i,:,:] = cs.ddx(c).T + +storage.flush() diff --git a/fluctuation_product_u_ddxc.py b/fluctuation_product_u_ddxc.py new file mode 100644 index 0000000..03344fe --- /dev/null +++ b/fluctuation_product_u_ddxc.py @@ -0,0 +1,51 @@ +import argparse +import datetime +import numpy as np +import dnstool +from pycompact import CompactScheme + +# Commandline argument parser +parser = argparse.ArgumentParser() +parser.add_argument("-c", "--case", help="target case name", required=True) +args = parser.parse_args() +params = vars(args) + +casename = params["case"] + +cases = dnstool.case_library() + +case = cases[casename] + +nx, ny, nz = case.shape + +cs = CompactScheme(nx, ny, nz, False, True, True, 4, 2, 2) + + +cfile = "c.dat" +ufile = "u.dat" +ddxcfile = "ddxc.dat" +resfile = "uddxc.dat" + +c = np.memmap(cfile, mode="r", dtype=np.double).reshape((512,-1,256,256)) +u = np.memmap(ufile, mode="r", dtype=np.double).reshape((512,-1,256,256)) +ddxc = np.memmap(ufile, mode="r", dtype=np.double).reshape((512,-1,256,256)) +storage = np.memmap(resfile, mode='w+', dtype=np.double, shape=(nx, len(case.data_files), ny, nz)) + + +for xidx in range(nx): + + u_cstar = + u_mean = + u_mean_at_x = np.interp (c[xidx], u_cstar, u_mean) + u_at_x = u[xidx] + u_flux_at_x = u_at_x - u_mean_at_x + + ddxc_cstar = + ddxc_mean = + ddxc_mean_at_x = np.interp (c[xidx], ddxc_cstar, ddxc_mean) + ddxc_at_x = u[xidx] + ddxc_flux_at_x = ddxc_at_x - ddxc_mean_at_x + + storage[xidx,:,:,:] = u_flux_at_x * ddxc_flux_at_x + +storage.flush() diff --git a/run_in_case_dir.sh b/run_in_case_dir.sh new file mode 100755 index 0000000..f4e67d9 --- /dev/null +++ b/run_in_case_dir.sh @@ -0,0 +1,58 @@ +#!/usr/bin/bash + +# >>> conda initialize >>> +# !! Contents within this block are managed by 'conda init' !! +__conda_setup="$('/home/ignis/anaconda2/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" +if [ $? -eq 0 ]; then + eval "$__conda_setup" +else + if [ -f "/home/ignis/anaconda2/etc/profile.d/conda.sh" ]; then + . "/home/ignis/anaconda2/etc/profile.d/conda.sh" + else + export PATH="/home/ignis/anaconda2/bin:$PATH" + fi +fi +unset __conda_setup +# <<< conda initialize <<< + +conda activate fkde-jupyter-py3 + + +SCRIPT_ROOT=/home/ignis/dns/CNF2021-Figures + + + + + +echo time python $SCRIPT_ROOT/extract_all.py -c $1 + + +#=============================================================================# + + +echo Batch running - binning_v_given_c.py + +export BIN_TARGET=u.dat +sbatch --array=0,1 -J $1-u-c $SCRIPT_ROOT/sbatch-job-binning-ddxc-array +echo sbatch --array=0,511 -J $1-u-c $SCRIPT_ROOT/sbatch-job-binning-ddxc-array + +export BIN_TARGET=ddxc.dat +echo sbatch --wait --array=0,511 -J $1-ddxc-c $SCRIPT_ROOT/sbatch-job-binning-ddxc-array + + +#=============================================================================# + + +echo time python $SCRIPT_ROOT/fluctuation_product_u_ddxc.py -c $1 + + +#=============================================================================# + + +echo Batch Running - binning_v_given_c.py +export BIN_TARGET=uddxc.dat +echo sbatch --wait --array=0,511 -J $1-uddxc-c $SCRIPT_ROOT/sbatch-job-binning-ddxc-array + + +#=============================================================================# +echo Done diff --git a/sbatch-job-binning-ddxc-array b/sbatch-job-binning-ddxc-array new file mode 100644 index 0000000..775eb41 --- /dev/null +++ b/sbatch-job-binning-ddxc-array @@ -0,0 +1,35 @@ +#!/bin/bash + +#SBATCH -J IC1-ddxc # Job name +#SBATCH -o ddxc-binning.%j.out # Name of stdout output file (%j expands to jobId) +#SBATCH -N 1 # Total number of nodes requested +#SBATCH -n 1 # Total number of mpi tasks requested +#SBATCH -c 4 # number of cpus required per task +# #SBATCH --mail-user=ignis@postech.ac.kr +# #SBATCH --mail-type=NONE + +# Launch MPI-based executable + +if [ -n "$SLURM_CPUS_PER_TASK" ]; then + omp_threads=$SLURM_CPUS_PER_TASK +else + omp_threads=1 +fi +export MKL_NUM_THREADS=$omp_threads +export OMP_NUM_THREADS=$omp_threads +export OPENBLAS_NUM_THREADS=$omp_threads + +echo $OMP_NUM_THREADS / $XINDEX / $SLURM_ARRAY_TASK_ID + +if [ -n "$SLURM_ARRAY_TASK_ID" ]; then + echo Using Array Task ID + XINDEX=$SLURM_ARRAY_TASK_ID +elif [ -n "$XINDEX" ]; then + echo XINDEX given explicitly +else + echo ERROR: XINDEX Required +fi + + +echo python /home/ignis/dns/CNF2021-Figures/binning_v_given_c.py -x $XINDEX -v $BIN_TARGET +time python /home/ignis/dns/CNF2021-Figures/binning_v_given_c.py -x $XINDEX -v $BIN_TARGET