Esempio n. 1
0
    def initialize(self, input_stream):
        
        # Create a ModelParameterDictionary for the inputs
        if type(input_stream)==ModelParameterDictionary:
            inputs = input_stream
        else:
            inputs = ModelParameterDictionary(input_stream)
        
        # Read input/configuration parameters
        self.kd = inputs.read_float('DIFMOD_KD')
        try:
            self.uplift_rate = inputs.read_float('DIFMOD_UPLIFT_RATE')
        except:
            self.uplift_rate = inputs.read_float('uplift_rate')
        try:
            self.values_to_diffuse = inputs.read_str('values_to_diffuse')
        except:
            self.values_to_diffuse = 'planet_surface__elevation'
        try:
            self.timestep_in = inputs.read_float('dt')  
        except:
            print 'No fixed timestep supplied, it must be set dynamically somewhere else. Be sure to call input_timestep(timestep_in) as part of your run loop.'

        
        # Create grid if one doesn't already exist
        if self.grid==None:
            self.grid = create_and_initialize_grid(input_stream)
            
        # Set internal time step
        # ..todo:
        #   implement mechanism to compute time-steps dynamically if grid is 
        #   adaptive/changing
        dx = self.grid.min_active_link_length()  # smallest active link length
        self.dt = _ALPHA*dx*dx/self.kd  # CFL condition
        try:
            self.tstep_ratio = self.timestep_in/self.dt
        except:
            pass
        
        # Get a list of interior cells
        self.interior_cells = self.grid.get_core_cell_node_ids()
        
        # Here we're experimenting with different approaches: with 
        # 'make_all_data', we create and manage all the data we need and embed
        # it all in the grid. With 'explicit', we require the caller/user to 
        # provide data.
        if _VERSION=='make_all_data':
            #print 'creating internal data'
            self.z = self.grid.add_zeros('node', 'landscape_surface__elevation')
            self.g = self.grid.add_zeros('active_link', 'landscape_surface__gradient')  # surface gradients
            self.qs = self.grid.add_zeros('active_link','unit_sediment_flux')  # unit sediment flux
            self.dqds = self.grid.add_zeros('node', 'sediment_flux_divergence')  # sed flux derivative
        elif _VERSION=='explicit':
            pass
        else:
            # Create data arrays for variables that won't (?) be shared with other
            # components
            self.g = self.grid.create_active_link_array_zeros()  # surface gradients
            self.qs = self.grid.create_active_link_array_zeros()  # unit sediment flux
            self.dqds = self.grid.create_node_array_zeros()  # sed flux derivative
 def initialize(self, grid=None, input_file=None, intensity=None, stormduration=None):
     
     self.grid = grid 
     if self.grid==None:
         self.grid = create_and_initialize_grid(input_file)
         
     ##self.current_time = current_time <- this isn't being used yet. 
     
     # Create a ModelParameterDictionary for the inputs
     
     MPD = ModelParameterDictionary()
     ## I am not sure we want to use an instance of MPD as an input_file. I'm confused about this. SO for 
     ## now I changed this to reflect other component types
     
     if input_file is None:
         input_file = _DEFAULT_INPUT_FILE
         
     MPD.read_from_file(input_file)
     
     ## This was the old way... where an instance of MPD is an input_file
     #if type(input_file)==MPD: 
     #    inputs = input_file
     #else:
     #    inputs = MPD(input_file)
     
     # Read input/configuration parameters
     self.m_n = MPD.read_float('MANNINGS_N')
     
     if intensity == None:
         self.rainfall_mmhr = MPD.read_float( 'RAINFALL_RATE')
     else:
         self.rainfall_mmhr = intensity
     
     if stormduration == None:
         self.rain_duration = MPD.read_float( 'RAIN_DURATION' )
     else:
         self.rain_duration = stormduration
       
     #self.h_init = 0.001        # initial thin layer of water (m)
     #self.g = 9.8               # gravitational acceleration (m/s2)
     #self.alpha = 0.2           # time-step factor (ND; from Bates et al., 2010)
     #self.m_n_sq = self.m_n*self.m_n # manning's n squared
     #self.rho = 1000 # density of water, kg/m^3     
     
     # Derived parameters ## THIS IS IMPORTANT - UNITS!!!! Double check precip component...
     self.rainfall_rate = (self.rainfall_mmhr/1000.)/3600.  # rainfall in m/s
     
     
     # Set up state variables
     
     self.hstart = grid.zeros(centering='node') + self.h_init 
     self.h = grid.zeros(centering='node') + self.h_init     # water depth (m)
     #NG why is water depth at each node and not at cells, which are only active
     self.q = grid.zeros(centering='active_link') # unit discharge (m2/s)
     self.dhdt = grid.zeros(centering='active_cell') # rate of water-depth change
Esempio n. 3
0
 def initialize(self, input_stream=None):
 
     # If no input file/stream specified, use default (or command line?)
     # (or default values?)
     if input_stream==None:
         input_stream = str(raw_input('Enter name of input file: '))
     
     # Open input file
     inputs = ModelParameterDictionary(input_stream)
 
     # Create grid
     self.grid = create_and_initialize_grid(inputs)
     
     # Create a diffusion component
     self.diffusion_component = diffusion.DiffusionComponent(self.grid)
     self.diffusion_component.initialize(input_stream)
     
     # Read parameters
     self.run_duration = inputs.get('RUN_DURATION', ptype=float)
     self.opt_netcdf_output = inputs.get('OPT_FILE_OUTPUT', ptype='bool')
     self.opt_display_output = inputs.get('OPT_DISPLAY_OUTPUT', ptype='bool')
     
     self.setup_output_timing(inputs)
    def initialize(self, input_stream=None):

        # If no input file/stream specified, use default (or command line?)
        # (or default values?)
        if input_stream == None:
            input_stream = str(raw_input('Enter name of input file: '))

        # Open input file
        inputs = ModelParameterDictionary(input_stream)

        # Create grid
        self.grid = create_and_initialize_grid(inputs)

        # Create a diffusion component
        self.diffusion_component = diffusion.DiffusionComponent(self.grid)
        self.diffusion_component.initialize(input_stream)

        # Read parameters
        self.run_duration = inputs.get('RUN_DURATION', ptype=float)
        self.opt_netcdf_output = inputs.get('OPT_FILE_OUTPUT', ptype='bool')
        self.opt_display_output = inputs.get('OPT_DISPLAY_OUTPUT',
                                             ptype='bool')

        self.setup_output_timing(inputs)
Esempio n. 5
0
    def initialize(self, input_stream):

        # Create a ModelParameterDictionary for the inputs
        if type(input_stream)==ModelParameterDictionary:
            inputs = input_stream
        else:
            inputs = ModelParameterDictionary(input_stream)

        # Read input/configuration parameters
        self.kd = inputs.read_float('linear_diffusivity')
        try:
            self.uplift_rate = inputs.read_float('uplift_rate')
        except MissingKeyError:
            self.uplift_rate = 0.
        try:
            self.values_to_diffuse = inputs.read_string('values_to_diffuse')
        except MissingKeyError:
            self.values_to_diffuse = 'topographic__elevation'
        else:
            #take switch in the new field name in the class properties
            for mysets in (self._input_var_names, self._output_var_names):
                mysets.remove('topographic__elevation')
                mysets.add(self.values_to_diffuse)
            for mydicts in (self._var_units, self._var_mapping, self._var_doc):
                mydicts[self.values_to_diffuse] = mydicts.pop('topographic__elevation')

        try:
            self.timestep_in = inputs.read_float('dt')
        except MissingKeyError:
            pass


        # Create grid if one doesn't already exist
        if self._grid is None:
            self._grid = create_and_initialize_grid(input_stream)

        # Set internal time step
        # ..todo:
        #   implement mechanism to compute time-steps dynamically if grid is
        #   adaptive/changing
        dx = self._grid.min_active_link_length()  # smallest active link length
        self.dt = _ALPHA*dx*dx/self.kd  # CFL condition
        try:
            self.tstep_ratio = self.timestep_in/self.dt
        except AttributeError:
            pass

        # Get a list of interior cells
        self.interior_cells = self._grid.node_at_core_cell

##DEJH bites the bullet and forces the 2015 style with fields
#        # Here we're experimenting with different approaches: with
#        # 'make_all_data', we create and manage all the data we need and embed
#        # it all in the grid. With 'explicit', we require the caller/user to
#        # provide data.
#        if _VERSION=='make_all_data':
#            #print('creating internal data')
#            self.z = self._grid.add_zeros('node', 'landscape_surface__elevation')
#            self.g = self._grid.add_zeros('active_link', 'landscape_surface__gradient')  # surface gradients
#            self.qs = self._grid.add_zeros('active_link','unit_sediment_flux')  # unit sediment flux
#            self.dqds = self._grid.add_zeros('node', 'sediment_flux_divergence')  # sed flux derivative
#        elif _VERSION=='explicit':
#            pass
#        else:
#            # Create data arrays for variables that won't (?) be shared with other
#            # components
#            self.g = self._grid.create_active_link_array_zeros()  # surface gradients
#            self.qs = self._grid.create_active_link_array_zeros()  # unit sediment flux
#            self.dqds = self._grid.create_node_array_zeros()  # sed flux derivative

        self.z = self._grid.at_node[self.values_to_diffuse]
        g = self._grid.zeros(centering='link')
        qs = self._grid.zeros(centering='link')
        try:
            self.g = self._grid.add_field('link', 'surface__gradient', g, noclobber=True) #note this will object if this exists already
        except FieldError:
            pass #field exists, so no problem
        try:
            self.qs = self._grid.add_field('link', 'unit_flux', qs, noclobber=True)
        except FieldError:
            pass
Esempio n. 6
0
    def initialize(self, input_stream):

        # Create a ModelParameterDictionary for the inputs
        if type(input_stream) == ModelParameterDictionary:
            inputs = input_stream
        else:
            inputs = ModelParameterDictionary(input_stream)

        # Read input/configuration parameters
        self.kd = inputs.read_float('DIFMOD_KD')
        try:
            self.uplift_rate = inputs.read_float('DIFMOD_UPLIFT_RATE')
        except:
            self.uplift_rate = inputs.read_float('uplift_rate')
        try:
            self.values_to_diffuse = inputs.read_str('values_to_diffuse')
        except:
            self.values_to_diffuse = 'topographic_elevation'
        try:
            self.timestep_in = inputs.read_float('dt')
        except:
            print 'No fixed timestep supplied, it must be set dynamically somewhere else. Be sure to call input_timestep(timestep_in) as part of your run loop.'

        # Create grid if one doesn't already exist
        if self.grid == None:
            self.grid = create_and_initialize_grid(input_stream)

        # Set internal time step
        # ..todo:
        #   implement mechanism to compute time-steps dynamically if grid is
        #   adaptive/changing
        dx = self.grid.min_active_link_length()  # smallest active link length
        self.dt = _ALPHA * dx * dx / self.kd  # CFL condition
        try:
            self.tstep_ratio = self.timestep_in / self.dt
        except:
            pass

        # Get a list of interior cells
        self.interior_cells = self.grid.get_core_cell_node_ids()

        # Here we're experimenting with different approaches: with
        # 'make_all_data', we create and manage all the data we need and embed
        # it all in the grid. With 'explicit', we require the caller/user to
        # provide data.
        if _VERSION == 'make_all_data':
            #print 'creating internal data'
            self.z = self.grid.add_zeros('node',
                                         'landscape_surface__elevation')
            self.g = self.grid.add_zeros(
                'active_link',
                'landscape_surface__gradient')  # surface gradients
            self.qs = self.grid.add_zeros(
                'active_link', 'unit_sediment_flux')  # unit sediment flux
            self.dqds = self.grid.add_zeros(
                'node', 'sediment_flux_divergence')  # sed flux derivative
        elif _VERSION == 'explicit':
            pass
        else:
            # Create data arrays for variables that won't (?) be shared with other
            # components
            self.g = self.grid.create_active_link_array_zeros(
            )  # surface gradients
            self.qs = self.grid.create_active_link_array_zeros(
            )  # unit sediment flux
            self.dqds = self.grid.create_node_array_zeros(
            )  # sed flux derivative