Example #1
0
    def fromfilename(cls, gpu_ctx, filename, cont_write_netcdf=True):
        """
        Initialize and hotstart simulation from nc-file.
        cont_write_netcdf: Continue to write the results after each superstep to a new netCDF file
        filename: Continue simulation based on parameters and last timestep in this file
        """
        # open nc-file
        sim_reader = SimReader.SimNetCDFReader(filename,
                                               ignore_ghostcells=False)
        sim_name = str(sim_reader.get('simulator_short'))
        assert sim_name == cls.__name__, \
               "Trying to initialize a " + \
               cls.__name__ + " simulator with netCDF file based on " \
               + sim_name + " results."

        # read parameters
        nx = sim_reader.get("nx")
        ny = sim_reader.get("ny")

        dx = sim_reader.get("dx")
        dy = sim_reader.get("dy")

        width = nx * dx
        height = ny * dy

        dt = sim_reader.get("dt")
        g = sim_reader.get("g")
        r = sim_reader.get("bottom_friction_r")
        f = sim_reader.get("coriolis_force")
        beta = sim_reader.get("coriolis_beta")

        minmodTheta = sim_reader.get("minmod_theta")
        timeIntegrator = sim_reader.get("time_integrator")
        y_zero_reference_cell = sim_reader.get("y_zero_reference_cell")

        try:
            wind_stress_type = sim_reader.get("wind_stress_type")
            wind = Common.WindStressParams(type=wind_stress_type)
        except:
            wind = WindStress.WindStress()

        boundaryConditions = Common.BoundaryConditions( \
            sim_reader.getBC()[0], sim_reader.getBC()[1], \
            sim_reader.getBC()[2], sim_reader.getBC()[3], \
            sim_reader.getBCSpongeCells())

        h0 = sim_reader.getH()

        # get last timestep (including simulation time of last timestep)
        eta0, hu0, hv0, time0 = sim_reader.getLastTimeStep()

        return cls(gpu_ctx, \
                h0, eta0, hu0, hv0, \
                nx, ny, \
                dx, dy, dt, \
                g, f, r, \
                t=time0, \
                wind_stress=wind, \
                boundary_conditions=boundaryConditions, \
                write_netcdf=cont_write_netcdf)
Example #2
0
 def fromfilename(cls, gpu_ctx, filename, cont_write_netcdf=True, use_lcg=False, new_netcdf_filename=None):
     """
     Initialize and hotstart simulation from nc-file.
     cont_write_netcdf: Continue to write the results after each superstep to a new netCDF file
     filename: Continue simulation based on parameters and last timestep in this file
     new_netcdf_filename: If we want to continue to write netcdf, we should use this filename. Automatically generated if None.
     """
     # open nc-file
     sim_reader = SimReader.SimNetCDFReader(filename, ignore_ghostcells=False)
     sim_name = str(sim_reader.get('simulator_short'))
     assert sim_name == cls.__name__, \
            "Trying to initialize a " + \
            cls.__name__ + " simulator with netCDF file based on " \
            + sim_name + " results."
     
     # read the most recent state 
     H = sim_reader.getH();
     
     # get last timestep (including simulation time of last timestep)
     eta0, hu0, hv0, time0 = sim_reader.getLastTimeStep()
     
     # For some reason, some old netcdf had 3-dimensional bathymetry.
     # This fix ensures that we only use a valid H
     if len(H.shape) == 3:
         print("norm diff H: ", np.linalg.norm(H[0,:,:] - H[1,:,:]))
         H = H[0,:,:]
    
     # Set simulation parameters
     sim_params = {
         'gpu_ctx': gpu_ctx,
         'eta0': eta0,
         'hu0': hu0,
         'hv0': hv0,
         'H': H,
         'nx': sim_reader.get("nx"), 
         'ny': sim_reader.get("ny"),
         'dx': sim_reader.get("dx"),
         'dy': sim_reader.get("dy"),
         'dt': sim_reader.get("dt"),
         'g': sim_reader.get("g"),
         'f': sim_reader.get("coriolis_force"),
         'r': sim_reader.get("bottom_friction_r"),
         't': time0,
         'theta': sim_reader.get("minmod_theta"),
         'rk_order': sim_reader.get("time_integrator"),
         'coriolis_beta': sim_reader.get("coriolis_beta"),
         'y_zero_reference_cell': sim_reader.get("y_zero_reference_cell"),
         'write_netcdf': cont_write_netcdf,
         'use_lcg': use_lcg,
         'netcdf_filename': new_netcdf_filename
     }    
     
     # Wind stress
     try:
         wind_stress_type = sim_reader.get("wind_stress_type")
         wind = Common.WindStressParams(type=wind_stress_type)
     except:
         wind = WindStress.WindStress()
     sim_params['wind_stress'] = wind
         
     # Boundary conditions
     sim_params['boundary_conditions'] = Common.BoundaryConditions( \
         sim_reader.getBC()[0], sim_reader.getBC()[1], \
         sim_reader.getBC()[2], sim_reader.getBC()[3], \
         sim_reader.getBCSpongeCells())
 
     # Model errors
     if sim_reader.has('small_scale_perturbation'):
         sim_params['small_scale_perturbation'] = sim_reader.get('small_scale_perturbation') == 'True'
         if sim_params['small_scale_perturbation']:
             sim_params['small_scale_perturbation_amplitude'] = sim_reader.get('small_scale_perturbation_amplitude')
             sim_params['small_scale_perturbation_interpolation_factor'] = sim_reader.get('small_scale_perturbation_interpolation_factor')
         
         
     # Data assimilation parameters:
     if sim_reader.has('model_time_step'):
         sim_params['model_time_step'] = sim_reader.get('model_time_step')
 
     return cls(**sim_params)
Example #3
0
 def _initializeTruthFromFile(self):
     self.true_state_reader = SimReader.SimNetCDFReader(self.true_state_nc_files[0])