def main(): """ The basic algorithm for a LinkCA model is as follows: Initialize Set grid size, run duration, and plotting/output parameters Set up node states Set up link transitions Create and initialize the starting grid Create the CA model Create a CA plotter Set up (custom) boundary-control parameters Set up any other custom things Run Optionally report output to user in real time Figure out when the next interruption will be Run until that interruption If it's time to plot, do so If it's time to control boundaries, do so If it's time for file output, do so Finalize Do the last plot, if applicable Do any custom post-processing """ # INITIALIZE # User-defined parameters: general nr = 129 nc = 129 opt_screen_display = True plot_interval = 1 opt_file_output = False file_output_interval = 1 run_duration = 127 report_interval = 5.0 # report interval, in real-time seconds # User-defined parameters: boundary control boundary_update_interval = 0.1 # interval for baselevel lowering initial_hill_height = nr - 3 # must be < nr-1 # Initialize real time and intervals for reporting, plotting, and file output current_real_time = time.time() next_report = current_real_time + report_interval never = run_duration + 1 # anything that scheduled for later than run_duration never happens! if opt_screen_display: next_plot = plot_interval else: next_plot = never if opt_file_output: next_file_write = file_output_interval else: next_file_write = never # Custom: initialize information for baselevel lowering next_boundary_update = boundary_update_interval left_edge_alinks = (nc - 2) * (nr - 1) + (nc - 1) * numpy.arange(nr - 2) right_edge_alinks = left_edge_alinks + (nc - 2) bl_height = initial_hill_height bl_left_alink = left_edge_alinks[bl_height - 1] bl_right_alink = right_edge_alinks[bl_height - 1] # Create grid and set up boundaries mg = RasterModelGrid(nr, nc, 1.0) # Set up node states and pair transitions ns_dict = {0: 'air', 1: 'mobile left', 2: 'mobile right', 3: 'immobile'} xn_list = setup_transition_list() # Create the node-state map and attach it to the grid node_state_grid = mg.add_zeros('node', 'node_state', dtype=int) # Custom: set initial values in the node-state grid (initial_hill, ) = numpy.where(mg.node_y <= initial_hill_height) node_state_grid[initial_hill] = 3 # Custom: Set the left and right boundary conditions left_side_ids = mg.left_edge_node_ids() right_side_ids = mg.right_edge_node_ids() # Create the CA model ca = LinkCellularAutomaton(mg, ns_dict, xn_list, node_state_grid) # Debug output if needed if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print '{0:.0f}'.format(ca.node_state[n]), print # Create a CAPlotter object to handle screen display if opt_screen_display: ca_plotter = CAPlotter(ca) # RUN current_time = 0.0 while current_time < run_duration: # Once in a while, print out simulation and real time to let the user # know that the sim is running ok current_real_time = time.time() if current_real_time >= next_report: print 'Current sim time', current_time, '(', 100 * current_time / run_duration, '%)' next_report = current_real_time + report_interval # Find out when the next interruption (for plotting, boundary control, # file I/O, etc.) will be next_interrupt = min(next_plot, next_file_write, next_boundary_update, run_duration) # Run the model forward in time until the next output step ca.run(next_interrupt, ca.node_state, plot_each_transition=False) #, plotter=ca_plotter) # Update the current time current_time = next_interrupt # Plot the current grid if current_time >= next_plot: ca_plotter.update_plot() next_plot += plot_interval # Write the current grid to file if current_time >= next_file_write: print 'FILE OUTPUT NOT YET IMPLEMENTED' next_file_write += file_output_interval # Custom boundary control: baselevel lowering if current_time >= next_boundary_update: #print 'doing bl drop at time', current_time next_boundary_update += boundary_update_interval if bl_height > 0: ca.node_state[left_side_ids[ bl_height]] = 0 # turn the former baselevel to air ca.node_state[right_side_ids[ bl_height]] = 0 # turn the former baselevel to air ca.update_link_state(bl_left_alink, 0, current_time) ca.update_link_state(bl_right_alink, 0, current_time) bl_height -= 1 bl_left_alink = left_edge_alinks[bl_height - 1] bl_right_alink = right_edge_alinks[bl_height - 1] # for debugging if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print '{0:.0f}'.format(ca.node_state[n]), print # FINALIZE # Plot if opt_screen_display: ca_plotter.finalize() # Custom post-processing z = extract_hillslope_profile(mg.node_vector_to_raster(ca.node_state)) #numpy.savetxt('h0822-01-u125.txt',z) print 'PEAK ELEV = ', numpy.amax(z)
def main(): # INITIALIZE # User-defined parameters nr = 128 nc = 128 plot_interval = 5.0 run_duration = 5000.0 report_interval = 5.0 # report interval, in real-time seconds uplift_interval = 1. # Initialize real time current_real_time = time.time() next_report = current_real_time + report_interval # Create grid and set up boundaries mg = RasterModelGrid(nr, nc, 1.0) # Transition data here represent a body of fractured rock, with rock # represented by nodes with state 0, and saprolite (weathered rock) # represented by nodes with state 1. Node pairs (links) with 0-1 or 1-0 # can undergo a transition to 1-1, representing chemical weathering of the # rock. #ns_dict = { 0 : 'air', 1 : 'mobile left', 2 : 'mobile right', 3 : 'immobile' } ns_dict = { 0: 'air', 1: 'mobile left', 2: 'mobile right', 3: 'immobile', 4: 'rock' } xn_list = setup_transition_list() # Create the node-state map and attach it to the grid node_state_grid = mg.add_zeros('node', 'node_state_map', dtype=int) (lower_half, ) = numpy.where(mg.node_y < nr / 2) node_state_grid[lower_half] = 4 # Set the left and right boundary conditions node_state_grid[mg.left_edge_node_ids()] = 0 node_state_grid[mg.right_edge_node_ids()] = 0 # Create the CA model ca = LinkCellularAutomaton(mg, ns_dict, xn_list, node_state_grid) # Debug output if needed if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print '{0:.0f}'.format(ca.node_state[n]), print ca_plotter = CAPlotter(ca) # RUN BC_type = 2 #0: Block decay, disabled if BC_type == 0: current_time = 0.0 while current_time < run_duration: # Once in a while, print out simulation and real time to let the user # know that the sim is running ok current_real_time = time.time() if current_real_time >= next_report: print 'Current sim time', current_time, '(', 100 * current_time / run_duration, '%)' next_report = current_real_time + report_interval # Run the model forward in time until the next output step ca.run(current_time + plot_interval, ca.node_state, plot_each_transition=False) #, plotter=ca_plotter) current_time += plot_interval # Plot the current grid ca_plotter.update_plot() # for debugging if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print '{0:.0f}'.format(ca.node_state[n]), print elif BC_type == 1: # 1: block uplift # set all nodes as air, except bottom row: ca.node_state[:] = 0 ca.node_state[mg.bottom_edge_node_ids()[1:-1]] = 3 current_time = 0.0 while current_time < run_duration: # Once in a while, print out simulation and real time to let the user # know that the sim is running ok current_real_time = time.time() if current_real_time >= next_report: print 'Current sim time', current_time, '(', 100 * current_time / run_duration, '%)' next_report = current_real_time + report_interval #make the uplift state_raster = mg.node_vector_to_raster(ca.node_state) for i in range(state_raster.shape[0])[::-1][:-2]: state_raster[i, 20:-20] = state_raster[i - 1, 20:-20] state_raster[:2, 20:-20] = 3 ca.update_component_data(state_raster.ravel(), (numpy.arange( mg.number_of_nodes).reshape(mg.shape))[1, 20:-20], (0, 1)) # Run the model forward in time until the next output step ca.run(current_time + uplift_interval, ca.node_state, plot_each_transition=False) #, plotter=ca_plotter) current_time += uplift_interval # Plot the current grid ca_plotter.update_plot() elif BC_type == 2: #2: BC condition lowering #set all blocks as solid, except the top 3 rows: ca.node_state[:] = 3 ca.node_state[-3 * mg.shape[1]:] = 0 current_time = 0.0 i = 0 while current_time < run_duration: # Once in a while, print out simulation and real time to let the user # know that the sim is running ok current_real_time = time.time() if current_real_time >= next_report: print 'Current sim time', current_time, '(', 100 * current_time / run_duration, '%)' next_report = current_real_time + report_interval #drop the baselevel ca.node_state[mg.left_edge_node_ids()[-(i + 2):]] = 0 ca.node_state[mg.right_edge_node_ids()[-(i + 2):]] = 0 ca.assign_link_states_from_node_types() ca.push_transitions_to_event_queue() # Run the model forward in time until the next output step ca.run(current_time + uplift_interval, ca.node_state, plot_each_transition=False) #, plotter=ca_plotter) current_time += uplift_interval i += 1 # Plot the current grid ca_plotter.update_plot() # FINALIZE # Plot ca_plotter.finalize()
def main(): # INITIALIZE # User-defined parameters nr = 128 nc = 128 fracture_spacing = 10 # fracture spacing, cell widths plot_interval = 0.25 run_duration = 4.0 report_interval = 5.0 # report interval, in real-time seconds # Remember the clock time, and calculate when we next want to report # progress. current_real_time = time.time() next_report = current_real_time + report_interval # Create grid mg = RasterModelGrid(nr, nc, 1.0) # Set up the states and pair transitions. # Transition data here represent a body of fractured rock, with rock # represented by nodes with state 0, and saprolite (weathered rock) # represented by nodes with state 1. Node pairs (links) with 0-1 or 1-0 # can undergo a transition to 1-1, representing chemical weathering of the # rock. ns_dict = { 0 : 'rock', 1 : 'saprolite' } xn_list = setup_transition_list() # Create the node-state array and attach it to the grid node_state_grid = mg.add_zeros('node', 'node_state_map', dtype=int) # Initialize the node-state array as a "fracture grid" in which randomly # oriented fractures are represented as lines of saprolite embedded in # bedrock. node_state_grid[:] = make_frac_grid(fracture_spacing, model_grid=mg) # Create the CA model ca = LinkCellularAutomaton(mg, ns_dict, xn_list, node_state_grid) # Debug output if needed if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print '{0:.0f}'.format(ca.node_state[n]), print # Create a CAPlotter object for handling screen display ca_plotter = CAPlotter(ca) # Plot the initial grid ca_plotter.update_plot() # RUN current_time = 0.0 while current_time < run_duration: # Once in a while, print out simulation and real time to let the user # know that the sim is running ok current_real_time = time.time() if current_real_time >= next_report: print 'Current sim time',current_time,'(',100*current_time/run_duration,'%)' next_report = current_real_time + report_interval # Run the model forward in time until the next output step ca.run(current_time+plot_interval, ca.node_state, plot_each_transition=False) #, plotter=ca_plotter) current_time += plot_interval # Plot the current grid ca_plotter.update_plot() # for debugging if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print '{0:.0f}'.format(ca.node_state[n]), print # FINALIZE # Plot ca_plotter.finalize()
def main(): """ The basic algorithm for a LinkCA model is as follows: Initialize Set grid size, run duration, and plotting/output parameters Set up node states Set up link transitions Create and initialize the starting grid Create the CA model Create a CA plotter Set up (custom) boundary-control parameters Set up any other custom things Run Optionally report output to user in real time Figure out when the next interruption will be Run until that interruption If it's time to plot, do so If it's time to control boundaries, do so If it's time for file output, do so Finalize Do the last plot, if applicable Do any custom post-processing """ # INITIALIZE # User-defined parameters: general nr = 129 nc = 129 opt_screen_display = True plot_interval = 1 opt_file_output = False file_output_interval = 1 run_duration = 127 report_interval = 5.0 # report interval, in real-time seconds # User-defined parameters: boundary control boundary_update_interval = 0.1 # interval for baselevel lowering initial_hill_height = nr-3 # must be < nr-1 # Initialize real time and intervals for reporting, plotting, and file output current_real_time = time.time() next_report = current_real_time + report_interval never = run_duration+1 # anything that scheduled for later than run_duration never happens! if opt_screen_display: next_plot = plot_interval else: next_plot = never if opt_file_output: next_file_write = file_output_interval else: next_file_write = never # Custom: initialize information for baselevel lowering next_boundary_update = boundary_update_interval left_edge_alinks = (nc-2)*(nr-1)+(nc-1)*numpy.arange(nr-2) right_edge_alinks = left_edge_alinks + (nc-2) bl_height = initial_hill_height bl_left_alink = left_edge_alinks[bl_height-1] bl_right_alink = right_edge_alinks[bl_height-1] # Create grid and set up boundaries mg = RasterModelGrid(nr, nc, 1.0) # Set up node states and pair transitions ns_dict = { 0 : 'air', 1 : 'mobile left', 2 : 'mobile right', 3 : 'immobile' } xn_list = setup_transition_list() # Create the node-state map and attach it to the grid node_state_grid = mg.add_zeros('node', 'node_state', dtype=int) # Custom: set initial values in the node-state grid (initial_hill,) = numpy.where(mg.node_y<=initial_hill_height) node_state_grid[initial_hill] = 3 # Custom: Set the left and right boundary conditions left_side_ids = mg.left_edge_node_ids() right_side_ids = mg.right_edge_node_ids() # Create the CA model ca = LinkCellularAutomaton(mg, ns_dict, xn_list, node_state_grid) # Debug output if needed if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print '{0:.0f}'.format(ca.node_state[n]), print # Create a CAPlotter object to handle screen display if opt_screen_display: ca_plotter = CAPlotter(ca) # RUN current_time = 0.0 while current_time < run_duration: # Once in a while, print out simulation and real time to let the user # know that the sim is running ok current_real_time = time.time() if current_real_time >= next_report: print 'Current sim time',current_time,'(',100*current_time/run_duration,'%)' next_report = current_real_time + report_interval # Find out when the next interruption (for plotting, boundary control, # file I/O, etc.) will be next_interrupt = min(next_plot, next_file_write, next_boundary_update, run_duration) # Run the model forward in time until the next output step ca.run(next_interrupt, ca.node_state, plot_each_transition=False) #, plotter=ca_plotter) # Update the current time current_time = next_interrupt # Plot the current grid if current_time >= next_plot: ca_plotter.update_plot() next_plot += plot_interval # Write the current grid to file if current_time >= next_file_write: print 'FILE OUTPUT NOT YET IMPLEMENTED' next_file_write += file_output_interval # Custom boundary control: baselevel lowering if current_time >= next_boundary_update: #print 'doing bl drop at time', current_time next_boundary_update += boundary_update_interval if bl_height>0: ca.node_state[left_side_ids[bl_height]] = 0 # turn the former baselevel to air ca.node_state[right_side_ids[bl_height]] = 0 # turn the former baselevel to air ca.update_link_state(bl_left_alink, 0, current_time) ca.update_link_state(bl_right_alink, 0, current_time) bl_height -= 1 bl_left_alink = left_edge_alinks[bl_height-1] bl_right_alink = right_edge_alinks[bl_height-1] # for debugging if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print '{0:.0f}'.format(ca.node_state[n]), print # FINALIZE # Plot if opt_screen_display: ca_plotter.finalize() # Custom post-processing z = extract_hillslope_profile(mg.node_vector_to_raster(ca.node_state)) #numpy.savetxt('h0822-01-u125.txt',z) print 'PEAK ELEV = ',numpy.amax(z)
def main(): # INITIALIZE # User-defined parameters nr = 64 nc = 130 plot_interval = 1 run_duration = 100 report_interval = 5.0 # report interval, in real-time seconds baselevel_lowering_interval = 1 initial_hill_height = 60 # Initialize real time current_real_time = time.time() next_report = current_real_time + report_interval # Initialize information for baselevel lowering next_bl_drop = baselevel_lowering_interval left_edge_alinks = (nc-2)*(nr-1)+(nc-1)*numpy.arange(nr-2) #print left_edge_alinks right_edge_alinks = left_edge_alinks + (nc-2) #print right_edge_alinks bl_height = initial_hill_height bl_left_alink = left_edge_alinks[bl_height-1] bl_right_alink = right_edge_alinks[bl_height-1] #print 'bllal',bl_left_alink,'blral',bl_right_alink # Create grid and set up boundaries mg = RasterModelGrid(nr, nc, 1.0) # Transition data here represent a body of fractured rock, with rock # represented by nodes with state 0, and saprolite (weathered rock) # represented by nodes with state 1. Node pairs (links) with 0-1 or 1-0 # can undergo a transition to 1-1, representing chemical weathering of the # rock. ns_dict = { 0 : 'air', 1 : 'mobile left', 2 : 'mobile right', 3 : 'immobile' } xn_list = setup_transition_list() # Create the node-state map and attach it to the grid node_state_grid = mg.add_zeros('node', 'node_state', dtype=int) (initial_hill,) = numpy.where(mg.node_y<=initial_hill_height) node_state_grid[initial_hill] = 3 above_dam = numpy.where(mg.node_y>130-mg.node_x)[0] node_state_grid[above_dam] = 0 # Set the left and right boundary conditions left_side_ids = mg.left_edge_node_ids() right_side_ids = mg.right_edge_node_ids() #node_state_grid[mg.left_edge_node_ids()] = 0 #node_state_grid[mg.right_edge_node_ids()] = 0 # Remember the IDs of the lower row of nodes, so we can keep them set to # state 3 when we do uplift #bottom_row = mg.bottom_edge_node_ids() # Create the CA model ca = LinkCellularAutomaton(mg, ns_dict, xn_list, node_state_grid) # Debug output if needed if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print('{0:.0f}'.format(ca.node_state[n]), end=' ') print() ca_plotter = CAPlotter(ca) # RUN current_time = 0.0 while current_time < run_duration: # Once in a while, print out simulation and real time to let the user # know that the sim is running ok current_real_time = time.time() if current_real_time >= next_report: print('Current sim time',current_time,'(',100*current_time/run_duration,'%)') next_report = current_real_time + report_interval # Run the model forward in time until the next output step ca.run(current_time+plot_interval, ca.node_state, plot_each_transition=False) #, plotter=ca_plotter) current_time += plot_interval # Plot the current grid ca_plotter.update_plot() # Uplift if current_time >= next_bl_drop and bl_height>0: #print 'doing bl drop at time', current_time next_bl_drop += baselevel_lowering_interval ca.node_state[left_side_ids[bl_height]] = 0 # turn the former baselevel to air ca.node_state[right_side_ids[bl_height]] = 0 # turn the former baselevel to air ca.update_link_state(bl_left_alink, 0, current_time) ca.update_link_state(bl_right_alink, 0, current_time) bl_height -= 1 #ca.node_state[left_side_ids[bl_height]] = 3 # turn the new baselevel to regolith #ca.node_state[right_side_ids[bl_height]] = 3 # turn the new baselevel to regolith bl_left_alink = left_edge_alinks[bl_height-1] bl_right_alink = right_edge_alinks[bl_height-1] #ca.update_link_state(bl_left_alink, 0, current_time) #ca.update_link_state(bl_right_alink, 0, current_time) #ca.node_state[left_side_ids[:bl_height]] = 3 #ca.node_state[left_side_ids[bl_height:]] = 0 #ca.node_state[right_side_ids[:bl_height]] = 3 #ca.node_state[right_side_ids[bl_height:]] = 0 #next_uplift += uplift_interval #ca.grid.roll_nodes_ud('node_state', 1, interior_only=True) #ca.node_state[bottom_row] = 3 #print 'after roll:',ca.node_state # for debugging if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print('{0:.0f}'.format(ca.node_state[n]), end=' ') print() # FINALIZE # Plot ca_plotter.finalize() z = extract_hillslope_profile(mg.node_vector_to_raster(ca.node_state)) numpy.savetxt('h0822-01-u125.txt',z) print('PEAK ELEV = ',numpy.amax(z))
def main(): # INITIALIZE # User-defined parameters nr = 128 nc = 128 plot_interval = 5.0 run_duration = 5000.0 report_interval = 5.0 # report interval, in real-time seconds uplift_interval = 1. # Initialize real time current_real_time = time.time() next_report = current_real_time + report_interval # Create grid and set up boundaries mg = RasterModelGrid(nr, nc, 1.0) # Transition data here represent a body of fractured rock, with rock # represented by nodes with state 0, and saprolite (weathered rock) # represented by nodes with state 1. Node pairs (links) with 0-1 or 1-0 # can undergo a transition to 1-1, representing chemical weathering of the # rock. #ns_dict = { 0 : 'air', 1 : 'mobile left', 2 : 'mobile right', 3 : 'immobile' } ns_dict = { 0 : 'air', 1 : 'mobile left', 2 : 'mobile right', 3 : 'immobile', 4 : 'rock' } xn_list = setup_transition_list() # Create the node-state map and attach it to the grid node_state_grid = mg.add_zeros('node', 'node_state_map', dtype=int) (lower_half,) = numpy.where(mg.node_y<nr/2) node_state_grid[lower_half] = 4 # Set the left and right boundary conditions node_state_grid[mg.left_edge_node_ids()] = 0 node_state_grid[mg.right_edge_node_ids()] = 0 # Create the CA model ca = LinkCellularAutomaton(mg, ns_dict, xn_list, node_state_grid) # Debug output if needed if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print('{0:.0f}'.format(ca.node_state[n]), end=' ') print() ca_plotter = CAPlotter(ca) # RUN BC_type = 2 #0: Block decay, disabled if BC_type==0: current_time = 0.0 while current_time < run_duration: # Once in a while, print out simulation and real time to let the user # know that the sim is running ok current_real_time = time.time() if current_real_time >= next_report: print('Current sim time',current_time,'(',100*current_time/run_duration,'%)') next_report = current_real_time + report_interval # Run the model forward in time until the next output step ca.run(current_time+plot_interval, ca.node_state, plot_each_transition=False) #, plotter=ca_plotter) current_time += plot_interval # Plot the current grid ca_plotter.update_plot() # for debugging if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print('{0:.0f}'.format(ca.node_state[n]), end=' ') print() elif BC_type==1: # 1: block uplift # set all nodes as air, except bottom row: ca.node_state[:] = 0 ca.node_state[mg.bottom_edge_node_ids()[1:-1]] = 3 current_time = 0.0 while current_time < run_duration: # Once in a while, print out simulation and real time to let the user # know that the sim is running ok current_real_time = time.time() if current_real_time >= next_report: print('Current sim time',current_time,'(',100*current_time/run_duration,'%)') next_report = current_real_time + report_interval #make the uplift state_raster = mg.node_vector_to_raster(ca.node_state) for i in range(state_raster.shape[0])[::-1][:-2]: state_raster[i,20:-20] = state_raster[i-1,20:-20] state_raster[:2,20:-20] = 3 ca.update_component_data(state_raster.ravel(), (numpy.arange(mg.number_of_nodes).reshape(mg.shape))[1,20:-20], (0,1)) # Run the model forward in time until the next output step ca.run(current_time+uplift_interval, ca.node_state, plot_each_transition=False) #, plotter=ca_plotter) current_time += uplift_interval # Plot the current grid ca_plotter.update_plot() elif BC_type==2: #2: BC condition lowering #set all blocks as solid, except the top 3 rows: ca.node_state[:] = 3 ca.node_state[-3*mg.shape[1]:] = 0 current_time = 0.0 i = 0 while current_time < run_duration: # Once in a while, print out simulation and real time to let the user # know that the sim is running ok current_real_time = time.time() if current_real_time >= next_report: print('Current sim time',current_time,'(',100*current_time/run_duration,'%)') next_report = current_real_time + report_interval #drop the baselevel ca.node_state[mg.left_edge_node_ids()[-(i+2):]] = 0 ca.node_state[mg.right_edge_node_ids()[-(i+2):]] = 0 ca.assign_link_states_from_node_types() ca.push_transitions_to_event_queue() # Run the model forward in time until the next output step ca.run(current_time+uplift_interval, ca.node_state, plot_each_transition=False) #, plotter=ca_plotter) current_time += uplift_interval i += 1 # Plot the current grid ca_plotter.update_plot() # FINALIZE # Plot ca_plotter.finalize()
def main(): # INITIALIZE # User-defined parameters nr = 128 nc = 128 fracture_spacing = 10 # fracture spacing, cell widths plot_interval = 0.25 run_duration = 4.0 report_interval = 5.0 # report interval, in real-time seconds # Remember the clock time, and calculate when we next want to report # progress. current_real_time = time.time() next_report = current_real_time + report_interval # Create grid mg = RasterModelGrid(nr, nc, 1.0) # Set up the states and pair transitions. # Transition data here represent a body of fractured rock, with rock # represented by nodes with state 0, and saprolite (weathered rock) # represented by nodes with state 1. Node pairs (links) with 0-1 or 1-0 # can undergo a transition to 1-1, representing chemical weathering of the # rock. ns_dict = {0: 'rock', 1: 'saprolite'} xn_list = setup_transition_list() # Create the node-state array and attach it to the grid node_state_grid = mg.add_zeros('node', 'node_state_map', dtype=int) # Initialize the node-state array as a "fracture grid" in which randomly # oriented fractures are represented as lines of saprolite embedded in # bedrock. node_state_grid[:] = make_frac_grid(fracture_spacing, model_grid=mg) # Create the CA model ca = LinkCellularAutomaton(mg, ns_dict, xn_list, node_state_grid) # Debug output if needed if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print '{0:.0f}'.format(ca.node_state[n]), print # Create a CAPlotter object for handling screen display ca_plotter = CAPlotter(ca) # Plot the initial grid ca_plotter.update_plot() # RUN current_time = 0.0 while current_time < run_duration: # Once in a while, print out simulation and real time to let the user # know that the sim is running ok current_real_time = time.time() if current_real_time >= next_report: print 'Current sim time', current_time, '(', 100 * current_time / run_duration, '%)' next_report = current_real_time + report_interval # Run the model forward in time until the next output step ca.run(current_time + plot_interval, ca.node_state, plot_each_transition=False) #, plotter=ca_plotter) current_time += plot_interval # Plot the current grid ca_plotter.update_plot() # for debugging if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print '{0:.0f}'.format(ca.node_state[n]), print # FINALIZE # Plot ca_plotter.finalize()
def main(): # INITIALIZE # User-defined parameters nr = 64 nc = 130 plot_interval = 1 run_duration = 100 report_interval = 5.0 # report interval, in real-time seconds baselevel_lowering_interval = 1 initial_hill_height = 60 # Initialize real time current_real_time = time.time() next_report = current_real_time + report_interval # Initialize information for baselevel lowering next_bl_drop = baselevel_lowering_interval left_edge_alinks = (nc - 2) * (nr - 1) + (nc - 1) * numpy.arange(nr - 2) #print left_edge_alinks right_edge_alinks = left_edge_alinks + (nc - 2) #print right_edge_alinks bl_height = initial_hill_height bl_left_alink = left_edge_alinks[bl_height - 1] bl_right_alink = right_edge_alinks[bl_height - 1] #print 'bllal',bl_left_alink,'blral',bl_right_alink # Create grid and set up boundaries mg = RasterModelGrid(nr, nc, 1.0) # Transition data here represent a body of fractured rock, with rock # represented by nodes with state 0, and saprolite (weathered rock) # represented by nodes with state 1. Node pairs (links) with 0-1 or 1-0 # can undergo a transition to 1-1, representing chemical weathering of the # rock. ns_dict = {0: 'air', 1: 'mobile left', 2: 'mobile right', 3: 'immobile'} xn_list = setup_transition_list() # Create the node-state map and attach it to the grid node_state_grid = mg.add_zeros('node', 'node_state', dtype=int) (initial_hill, ) = numpy.where(mg.node_y <= initial_hill_height) node_state_grid[initial_hill] = 3 above_dam = numpy.where(mg.node_y > 130 - mg.node_x)[0] node_state_grid[above_dam] = 0 # Set the left and right boundary conditions left_side_ids = mg.left_edge_node_ids() right_side_ids = mg.right_edge_node_ids() #node_state_grid[mg.left_edge_node_ids()] = 0 #node_state_grid[mg.right_edge_node_ids()] = 0 # Remember the IDs of the lower row of nodes, so we can keep them set to # state 3 when we do uplift #bottom_row = mg.bottom_edge_node_ids() # Create the CA model ca = LinkCellularAutomaton(mg, ns_dict, xn_list, node_state_grid) # Debug output if needed if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print '{0:.0f}'.format(ca.node_state[n]), print ca_plotter = CAPlotter(ca) # RUN current_time = 0.0 while current_time < run_duration: # Once in a while, print out simulation and real time to let the user # know that the sim is running ok current_real_time = time.time() if current_real_time >= next_report: print 'Current sim time', current_time, '(', 100 * current_time / run_duration, '%)' next_report = current_real_time + report_interval # Run the model forward in time until the next output step ca.run(current_time + plot_interval, ca.node_state, plot_each_transition=False) #, plotter=ca_plotter) current_time += plot_interval # Plot the current grid ca_plotter.update_plot() # Uplift if current_time >= next_bl_drop and bl_height > 0: #print 'doing bl drop at time', current_time next_bl_drop += baselevel_lowering_interval ca.node_state[left_side_ids[ bl_height]] = 0 # turn the former baselevel to air ca.node_state[right_side_ids[ bl_height]] = 0 # turn the former baselevel to air ca.update_link_state(bl_left_alink, 0, current_time) ca.update_link_state(bl_right_alink, 0, current_time) bl_height -= 1 #ca.node_state[left_side_ids[bl_height]] = 3 # turn the new baselevel to regolith #ca.node_state[right_side_ids[bl_height]] = 3 # turn the new baselevel to regolith bl_left_alink = left_edge_alinks[bl_height - 1] bl_right_alink = right_edge_alinks[bl_height - 1] #ca.update_link_state(bl_left_alink, 0, current_time) #ca.update_link_state(bl_right_alink, 0, current_time) #ca.node_state[left_side_ids[:bl_height]] = 3 #ca.node_state[left_side_ids[bl_height:]] = 0 #ca.node_state[right_side_ids[:bl_height]] = 3 #ca.node_state[right_side_ids[bl_height:]] = 0 #next_uplift += uplift_interval #ca.grid.roll_nodes_ud('node_state', 1, interior_only=True) #ca.node_state[bottom_row] = 3 #print 'after roll:',ca.node_state # for debugging if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print '{0:.0f}'.format(ca.node_state[n]), print # FINALIZE # Plot ca_plotter.finalize() z = extract_hillslope_profile(mg.node_vector_to_raster(ca.node_state)) numpy.savetxt('h0822-01-u125.txt', z) print 'PEAK ELEV = ', numpy.amax(z)
def main(): # INITIALIZE # User-defined parameters nr = 128 nc = 128 plot_interval = 0.25 run_duration = 4.0 report_interval = 5.0 # report interval, in real-time seconds # Initialize real time current_real_time = time.time() next_report = current_real_time + report_interval # Create grid and set up boundaries mg = RasterModelGrid(nr, nc, 1.0) # Transition data here represent a body of fractured rock, with rock # represented by nodes with state 0, and saprolite (weathered rock) # represented by nodes with state 1. Node pairs (links) with 0-1 or 1-0 # can undergo a transition to 1-1, representing chemical weathering of the # rock. ns_dict = { 0 : 'rock', 1 : 'saprolite' } xn_list = setup_transition_list() # The initial grid node_state_grid = mg.add_zeros('node', 'node_state_map', dtype=int) node_state_grid[:] = make_frac_grid(10, model_grid=mg) # Create the CA model ca = LinkCellularAutomaton(mg, ns_dict, xn_list, node_state_grid) # Debug output if needed if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print '{0:.0f}'.format(ca.node_state[n]), print ca_plotter = CAPlotter(ca) # RUN current_time = 0.0 while current_time < run_duration: # Once in a while, print out simulation and real time to let the user # know that the sim is running ok current_real_time = time.time() if current_real_time >= next_report: print 'Current sim time',current_time,'(',100*current_time/run_duration,'%)' next_report = current_real_time + report_interval # Run the model forward in time until the next output step ca.run(current_time+plot_interval, ca.node_state, plot_each_transition=False) #, plotter=ca_plotter) current_time += plot_interval # Plot the current grid ca_plotter.update_plot() # for debugging if _DEBUG: n = ca.grid.number_of_nodes for r in range(ca.grid.number_of_node_rows): for c in range(ca.grid.number_of_node_columns): n -= 1 print '{0:.0f}'.format(ca.node_state[n]), print # FINALIZE # Plot ca_plotter.finalize()