示例#1
0
文件: cmcards.py 项目: Mads-J/wave
def gen_cmcards_file(output_path, params = DEFAULT_SIM_PARAMS):
  cmcards_template = CMS_TEMPLATES.get_template('FLOW.cmcards')
  cmcards_config = CMSConfig(params['sim_name']).load_sim_config()

  cmcards_config['sim_start_date'] = params['sim_starttime'].strftime('%y%j')
  cmcards_config['sim_start_hour'] = params['sim_starttime'].strftime('%H')

  # Godawful, ugly code coming up---avert your eyes!
  sim_output_times = [0.0, 0.0, 0.0]
  n_tstep = 1
  sim_endtime = params['sim_starttime'] + timedelta(hours = params['sim_runtime'])
  time_step = params['sim_timestep']
  while (params['sim_starttime'] + timedelta(hours = time_step)) <= sim_endtime:
    sim_output_times.append(time_step)
    sim_output_times.append(time_step)
    sim_output_times.append(0.0)

    time_step += params['sim_timestep']
    n_tstep += 1

  sim_output_times.insert(0, n_tstep)
  sim_output_times = ' '.join(str(x) for x in sim_output_times)

  cmcards_config['sim_output_times'] = sim_output_times
  cmcards_config.update(params)

  with open(output_path, 'w') as cmcards_output:
    cmcards_output.writelines(cmcards_template.render(**cmcards_config))

  return None
示例#2
0
文件: simfiles.py 项目: Mads-J/wave
def gen_sim_file(output_path, params = DEFAULT_SIM_PARAMS):
  sim_template = CMS_TEMPLATES.get_template('WAVE.sim')
  sim_config = CMSConfig(params['sim_name']).load_sim_config()

  sim_config.update(params)

  with open(output_path, 'w') as sim_output:
    sim_output.writelines(sim_template.render(**sim_config))

  return None