Select Git revision
build_config_2.py
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
build_config_2.py 6.13 KiB
import json
from func_bound_values import *
import os
# set wd to build_config_files folder
wd = os.getcwd()
# check if already in correct wd
if wd[-18:] == 'build_config_files':
pass
# if not, change to build_config_files
else:
path = wd + '/Python_files/Code/build_config_files'
os.chdir(path)
# set constants
rho_l = 1028
c_l = 3400
# **********************************************************************************************************************
# Initialize array containig all parameters and set path to its directory
# **********************************************************************************************************************
config = {}
path_config = r'../../../Run_specifics/'
path_input = '../../../input/'
# **********************************************************************************************************************
# Set description of run
# **********************************************************************************************************************
description = "Testcase_2"
file = open(path_config + r"description.txt", "w")
file.write(description)
file.close()
# **********************************************************************************************************************
# Initial layer thickness, timestep, output time and simulation time
# **********************************************************************************************************************
config['dt'] = 30 # time increment [s]]
config['time'] = 0.0 # initial value of time [s]
config['time_out'] = 3600 * 6 # time between outputs [s]
config['time_total'] = config['time_out'] * 4 * 30 # total length of simulation [s]
# **********************************************************************************************************************
# Time settings needed when input is given
# **********************************************************************************************************************
config['length_input'] = config['time_total'] / config['dt'] # Length of your input files. Must match with timestep_data
config['timestep_data'] = 30 # timestep of input data [s]
# **********************************************************************************************************************
# Layer settings and allocation
# **********************************************************************************************************************
config['thick_0'] = 0.01
config['Nlayer'] = 100
config['N_active'] = 1
config['N_top'] = 3
config['N_bottom'] = 10
config['N_middle'] = config['Nlayer'] - config['N_top'] - config['N_bottom']
# **********************************************************************************************************************
# Flags
# **********************************************************************************************************************
# ________________________top heat flux____________
config['boundflux_flag'] = 3
config['albedo_flag'] = 2
# ________________________brine_dynamics____________
config['grav_heat_flag'] = 1
config['flush_heat_flag'] = 1
config['flood_flag'] = 2
config['flush_flag'] = 5
config['grav_flag'] = 2
config['harmonic_flag'] = 2
# ________________________Salinity____________
config['prescribe_flag'] = 1
config['salt_flag'] = 1
# ________________________bottom setting______________________
config['turb_flag'] = 2
config['bottom_flag'] = 1
config['tank_flag'] = 2
# ________________________snow______________________
config['precip_flag'] = 0
config['freeboard_snow_flag'] = 0
config['snow_flush_flag'] = 1
config['styropor_flag'] = 0
config['lab_snow_flag'] = 0
# ________________________debugging_____________________
config['debug_flag'] = 1 # set to 2 for output of all ice layers each timestep
# ________________________bgc_______________________
config['bgc_flag'] = 2
# ________________________initial state_______________________
config['initial_state_flag'] = 1
# **********************************************************************************************************************
# Tank and turbulent fluxes settings
# **********************************************************************************************************************
config['tank_depth'] = 1
config['alpha_flux_stable'] = 15
config['alpha_flux_instable'] = 22
# **********************************************************************************************************************
# BGC Settings
# **********************************************************************************************************************
config['N_bgc'] = 2
config['bgc_bottom_1'] = 385
config['bgc_bottom_2'] = 385
# **********************************************************************************************************************
# Construct Input files
# **********************************************************************************************************************
# Set constant inputs
const_inputs = {'T_top': -18, 'T_bottom': 0, 'S_bu_bottom': 31.2,
'fl_q_bottom': 10, 'precip_l': 0, 'precip_s': 0}
for input in list(const_inputs.keys()):
data = np.ones(int(config['time_total']/config['timestep_data'])) * const_inputs[input]
np.savetxt(path_input + input + '.txt', data)
# Set variable inputs
T2m = t2m_testcase_2(config['time_total'], config['timestep_data'])
np.savetxt(path_input + 'T2m.txt', T2m)
# **********************************************************************************************************************
# setting the initial values of the top and only layer
# **********************************************************************************************************************
config['thick_1'] = config['thick_0']
config['m_1'] = config['thick_0'] * rho_l
config['S_abs_1'] = config['m_1'] * const_inputs['S_bu_bottom']
config['H_abs_1'] = config['m_1'] * const_inputs['T_bottom']
# **********************************************************************************************************************
# Write init to .json file
# **********************************************************************************************************************
json_object = json.dumps(config, indent=4)
with open(path_config + "config.json", "w") as outfile:
outfile.write(json_object)