def __init__(self, grid, input_stream): self.grid = grid inputs = ModelParameterDictionary(input_stream) #User sets: self.K = inputs.read_float('K_sp') self.m = inputs.read_float('m_sp') try: self.n = inputs.read_float('n_sp') except: self.n = 1. try: self.dt = inputs.read_float('dt') except: #if dt isn't supplied, it must be set by another module, so look in the grid print 'Set dynamic timestep from the grid. You must call gear_timestep() to set dt each iteration.' else: try: self.r_i = inputs.read_float('dt') except: self.r_i = 1. try: self.value_field = inputs.read_str('value_field') except: self.value_field = 'planet_surface__elevation' #make storage variables self.A_to_the_m = grid.create_node_array_zeros() self.alpha = grid.empty(centering='node') if self.n != 1.: raise ValueError( 'The Braun Willett stream power algorithm requires n==1. at the moment, sorry...' )
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 __init__(self, grid, input_stream): self.grid = grid inputs = ModelParameterDictionary(input_stream) # User sets: self.K = inputs.read_float("K_sp") self.m = inputs.read_float("m_sp") try: self.n = inputs.read_float("n_sp") except: self.n = 1.0 try: self.dt = inputs.read_float("dt") except: # if dt isn't supplied, it must be set by another module, so look in the grid print "Set dynamic timestep from the grid. You must call gear_timestep() to set dt each iteration." else: try: self.r_i = inputs.read_float("dt") except: self.r_i = 1.0 try: self.value_field = inputs.read_str("value_field") except: self.value_field = "planet_surface__elevation" # make storage variables self.A_to_the_m = grid.create_node_array_zeros() self.alpha = grid.empty(centering="node") if self.n != 1.0: raise ValueError("The Braun Willett stream power algorithm requires n==1. at the moment, sorry...")
def __init__(self, grid, input_stream): self.grid = grid inputs = ModelParameterDictionary(input_stream) #User sets: self.K = inputs.read_float('K_sp') self.m = inputs.read_float('m_sp') try: self.n = inputs.read_float('n_sp') except: self.n = 1. try: self.dt = inputs.read_float('dt') except: #if dt isn't supplied, it must be set by another module, so look in the grid print 'Set dynamic timestep from the grid. You must call gear_timestep() to set dt each iteration.' else: try: self.r_i = inputs.read_float('rainfall_intensity') except: self.r_i = 1. try: self.value_field = inputs.read_str('value_field') except: self.value_field = 'planet_surface__elevation' #make storage variables self.A_to_the_m = grid.create_node_array_zeros() self.alpha = grid.empty(centering='node') if self.n != 1.: raise ValueError('The Braun Willett stream power algorithm requires n==1. at the moment, sorry...')
def __init__(self, grid, input_stream): self.grid = grid inputs = ModelParameterDictionary(input_stream) #User sets: try: self.K = inputs.read_float('K_sp') except ParameterValueError: self.use_K = True else: self.use_K = False self.m = inputs.read_float('m_sp') try: self.n = inputs.read_float('n_sp') except: self.n = 1. try: self.dt = inputs.read_float('dt') except: #if dt isn't supplied, it must be set by another module, so look in the grid print('Set dynamic timestep from the grid. You must call gear_timestep() to set dt each iteration.') try: self.r_i = inputs.read_float('rainfall_intensity') except: self.r_i = 1. try: self.value_field = inputs.read_str('value_field') except: self.value_field = 'topographic__elevation' #make storage variables self.A_to_the_m = grid.create_node_array_zeros() self.alpha = grid.empty(centering='node') self.alpha_by_flow_link_lengthtothenless1 = numpy.empty_like(self.alpha) self.grid.node_diagonal_links() #calculates the number of diagonal links if self.n != 1.: #raise ValueError('The Braun Willett stream power algorithm requires n==1. at the moment, sorry...') self.nonlinear_flag = True if self.n<1.: print("***WARNING: With n<1 performance of the Fastscape algorithm is slow!***") else: self.nonlinear_flag = False def func_for_newton(x, last_step_elev, receiver_elev, alpha_by_flow_link_lengthtothenless1, n): y = x - last_step_elev + alpha_by_flow_link_lengthtothenless1*(x-receiver_elev)**n return y def func_for_newton_diff(x, last_step_elev, receiver_elev, alpha_by_flow_link_lengthtothenless1, n): y = 1. + n*alpha_by_flow_link_lengthtothenless1*(x-receiver_elev)**(n-1.) return y self.func_for_newton = func_for_newton self.func_for_newton_diff = func_for_newton_diff
def __init__(self, grid, input_stream): self.grid = grid inputs = ModelParameterDictionary(input_stream) #User sets: try: self.K = inputs.read_float('K_sp') except ParameterValueError: self.use_K = True else: self.use_K = False self.m = inputs.read_float('m_sp') try: self.n = inputs.read_float('n_sp') except: self.n = 1. try: self.dt = inputs.read_float('dt') except: #if dt isn't supplied, it must be set by another module, so look in the grid print 'Set dynamic timestep from the grid. You must call gear_timestep() to set dt each iteration.' try: self.r_i = inputs.read_float('rainfall_intensity') except: self.r_i = 1. try: self.value_field = inputs.read_str('value_field') except: self.value_field = 'topographic_elevation' #make storage variables self.A_to_the_m = grid.create_node_array_zeros() self.alpha = grid.empty(centering='node') self.alpha_by_flow_link_lengthtothenless1 = numpy.empty_like( self.alpha) self.grid.node_diagonal_links( ) #calculates the number of diagonal links if self.n != 1.: #raise ValueError('The Braun Willett stream power algorithm requires n==1. at the moment, sorry...') self.nonlinear_flag = True if self.n < 1.: print "***WARNING: With n<1 performance of the Fastscape algorithm is slow!***" else: self.nonlinear_flag = False self.weave_flag = grid.weave_flag def func_for_newton(x, last_step_elev, receiver_elev, alpha_by_flow_link_lengthtothenless1, n): y = x - last_step_elev + alpha_by_flow_link_lengthtothenless1 * ( x - receiver_elev)**n return y def func_for_newton_diff(x, last_step_elev, receiver_elev, alpha_by_flow_link_lengthtothenless1, n): y = 1. + n * alpha_by_flow_link_lengthtothenless1 * ( x - receiver_elev)**(n - 1.) return y self.func_for_newton = func_for_newton self.func_for_newton_diff = func_for_newton_diff
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