コード例 #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
コード例 #3
0
ファイル: setup.py プロジェクト: Mads-J/wave
def setup_model_run(**kwargs):

    sim_dir = path.join(getcwd(), kwargs['sim_label'])

    if not path.isdir(sim_dir):
        mkdir(sim_dir)

    sim_info = CMSConfig(kwargs['sim_name'])

    # Copy static files containing bathymetry info into the simulation directory.
    for static_file in sim_info.static_files:
        file_ext = path.splitext(static_file)[1]
        if file_ext == '.h5':
            file_ext = '_' + re.split('_', path.basename(static_file)).pop()
        sim_file = path.join(sim_dir, kwargs['sim_name'] + file_ext)
        copy(static_file, sim_file)

    gen_sim_file(path.join(sim_dir, kwargs['sim_name'] + '.sim'), kwargs)
    gen_cmcards_file(path.join(sim_dir, kwargs['sim_name'] + '.cmcards'),
                     kwargs)
    gen_std_file(path.join(sim_dir, kwargs['sim_name'] + '.std'),
                 kwargs['sim_name'])

    gen_wind_file(path.join(sim_dir, kwargs['sim_name'] + '.wind'), kwargs)
    gen_eng_file(path.join(sim_dir, 'nest.dat'), kwargs)

    # Hack... hack... hack...
    patch_wind_into_flow(sim_dir, kwargs)

    return None
コード例 #4
0
def gen_std_file(output_path, sim_name, params=STD_DEFAULT_PARAMS):
    std_template = CMS_TEMPLATES.get_template('WAVE.std')

    model_config = CMSConfig(sim_name).load_sim_config()

    # Set up a grid for observation cells.  This could probably live in the
    # gridfiles module.
    nx = int(model_config['nx'])
    ny = int(model_config['ny'])
    grid = meshgrid(xrange(1, nx + 1), xrange(1, ny + 1))

    params['kout'] = nx * ny
    params['observation_cells'] = zip(grid[0].flatten('F'),
                                      grid[1].flatten('F'))

    with open(output_path, 'w') as std_output:
        std_output.writelines(std_template.render(**params))

    return None
コード例 #5
0
ファイル: setup.py プロジェクト: Mads-J/wave
def gen_wind_file(output_path, params):
    from wavecon import CMSman, GETman
    model_config = CMSConfig(params['sim_name']).load_sim_config()

    #DEFINE SPATIAL/TEMPORAL DOMAIN
    grid = CMSman.makegrid(model_config)
    steeringtimes = CMSman.maketimes(params['sim_starttime'],
                                     params['sim_runtime'],
                                     params['sim_timestep'])

    #RETRIEVE WIND DATA FROM DATABASE
    windata = CMSman.getwinddata(None, steeringtimes,
                                 model_config)  #add wintype
    if (windata == None):
        print '\n... downloading new wind data ... \n'
        GETman.getWIND(model_config, params['sim_starttime'],
                       params['sim_runtime'], params['sim_timestep'])
        windata = CMSman.getwinddata(None, steeringtimes,
                                     model_config)  #add wintype

    # CONSTRUCT THE FILE
    CMSman.gen_windfiles(windata, grid, steeringtimes, model_config,
                         output_path)
コード例 #6
0
ファイル: engfiles.py プロジェクト: Mads-J/wave
def gen_eng_file(output_path, params):
    # This routine started out as makeWaveInput in prepareCMS.py

    model_config = CMSConfig(params['sim_name']).load_sim_config()

    #DEFINE SPATIAL/TEMPORAL DOMAIN
    box = CMSman.makebox(model_config)
    steeringtimes = CMSman.maketimes(params['sim_starttime'],
                                     params['sim_runtime'],
                                     params['sim_timestep'])

    #RETRIEVE WAVE DATA FROM DATABASE
    wavdata = CMSman.getwavedata(box, steeringtimes,
                                 model_config)  #add wavtype
    if (wavdata == None):
        print '\n... downloading new wave data ... \n'
        GETman.getWAVE(model_config, params['sim_starttime'],
                       params['sim_runtime'], params['sim_timestep'])
        wavdata = CMSman.getwavedata(box, steeringtimes,
                                     model_config)  #add wavtype

    # CONSTRUCT THE FILE
    CMSman.gen_wavefiles(wavdata, steeringtimes, model_config, output_path)