Ejemplo n.º 1
0
    def update_until(self, run_to_time):
        """Advance up to a specified time."""
        while self.current_time < run_to_time:

            # Figure out what time to run to this iteration
            next_pause = min(self.next_output, self.next_plot)
            next_pause = min(next_pause, self.next_uplift)
            next_pause = min(next_pause, self.next_baselevel)
            next_pause = min(next_pause, run_to_time)

            # 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 >= self.next_report:
                print('Current sim time ' + str(self.current_time) + ' (' + \
                      str(100 * self.current_time / self.run_duration) + '%)')
                self.next_report = current_real_time + self.report_interval

            # Run the model forward in time until the next output step
            print('Running to...' + str(next_pause))
            self.ca.run(next_pause, self.ca.node_state)
            self.current_time = next_pause

            # Handle output to file
            if self.current_time >= self.next_output:
                self.next_output += self.output_interval

            # Handle plotting on display
            if self.current_time >= self.next_plot:
                if self.save_plots:
                    this_filename = (self.plot_filename
                                     + str(self.plot_iteration).zfill(self.ndigits)
                                     + self.plot_filetype)
                else:
                    this_filename = None
                plot_hill(self.grid, this_filename)
                self.plot_iteration += 1
                self.next_plot += self.plot_interval

            # Handle fault slip
            if self.current_time >= self.next_uplift:
                self.uplifter.do_offset(ca=self.ca,
                                        current_time=self.current_time,
                                        rock_state=8)
#                for i in range(self.grid.number_of_links):
#                    if self.grid.status_at_link[i] == 4 and self.ca.next_trn_id[i] != -1:
#                        print((i, self.ca.next_trn_id[i]))
#                        print((self.grid.x_of_node[self.grid.node_at_link_tail[i]]))
#                        print((self.grid.y_of_node[self.grid.node_at_link_tail[i]]))
#                        print((self.grid.x_of_node[self.grid.node_at_link_head[i]]))
#                        print((self.grid.y_of_node[self.grid.node_at_link_head[i]]))
                self.next_uplift += self.uplift_interval

            # Handle baselevel rise
            if self.current_time >= self.next_baselevel:
                self.raise_baselevel(self.baselevel_row)
                self.baselevel_row += 1
                self.next_baselevel += self.baselevel_rise_interval
Ejemplo n.º 2
0
 def plot_to_file(self):
     """Plot profile of hill to file."""
     fname = self.plot_file_name + str(self.plot_number).zfill(4) + '.png'
     plot_hill(self.ca.grid, filename=fname)
     self.plot_number += 1
Ejemplo n.º 3
0
    def initialize(self, grid_size, report_interval, run_duration,
                   output_interval, disturbance_rate, weathering_rate,
                   dissolution_rate, uplift_interval, baselevel_rise_interval,
                   plot_interval, friction_coef, fault_x, cell_width,
                   grav_accel, init_state_grid=None, save_plots=False,
                   plot_filename=None, plot_filetype='.png', seed=0, **kwds):
        """Initialize the grain hill model."""
        self.disturbance_rate = disturbance_rate
        self.weathering_rate = weathering_rate
        self.dissolution_rate = dissolution_rate
        self.uplift_interval = uplift_interval
        self.baselevel_rise_interval = baselevel_rise_interval
        self.plot_interval = plot_interval
        self.friction_coef = friction_coef

        self.settling_rate = calculate_settling_rate(cell_width, grav_accel)

        # Call base class init
        super(GrainFacetSimulator, self).initialize(grid_size=grid_size,
                                          report_interval=report_interval,
                                          grid_orientation='vertical',
                                          grid_shape='rect',
                                          show_plots=False,
                                          cts_type='oriented_hex',
                                          run_duration=run_duration,
                                          output_interval=output_interval,
                                          plot_every_transition=False,
                                          initial_state_grid=init_state_grid,
                                          closed_boundaries=(True, True,
                                                             False, False),
                                          seed=seed)

        ns = self.grid.at_node['node_state']
        self.uplifter = LatticeNormalFault(fault_x_intercept=fault_x,
                                           grid=self.grid,
                                           node_state=ns)

        # initialize plotting
        if plot_interval <= run_duration:
            import matplotlib.pyplot as plt
            plt.ion()
            plt.figure(1)
            self.save_plots = save_plots
            if save_plots:
                self.plot_filename = plot_filename
                self.plot_filetype = plot_filetype
                nplots = (self.run_duration / self.plot_interval) + 1
                self.ndigits = int(np.floor(np.log10(nplots))) + 1
                this_filename = (plot_filename + '0'.zfill(self.ndigits)
                                 + plot_filetype)
                print(this_filename)
            else:
                this_filename = None
            plot_hill(self.grid, this_filename)

        # Work out the next times to plot and output
        self.next_output = self.output_interval
        self.next_plot = self.plot_interval
        self.plot_iteration = 1

        # Next time for a progress report to user
        self.next_report = self.report_interval

        # And baselevel adjustment
        self.next_uplift = self.uplift_interval
        if self.baselevel_rise_interval > 0:
            self.next_baselevel = self.baselevel_rise_interval
            self.baselevel_row = 1
        else:
            self.next_baselevel = self.run_duration + 1

        self.current_time = 0.0
Ejemplo n.º 4
0
 def plot_to_file(self):
     """Plot current hillslope to file."""
     fname = (self.output_name + '/' + self.output_name +
              str(self.plot_number).zfill(4) + '.png')
     plot_hill(self.model.grid, filename=fname, cmap=self.cmap)
     self.plot_number += 1
Ejemplo n.º 5
0
 def plot_to_file(self):
     """Plot profile of hill to file."""
     fname = self.plot_file_name + str(self.plot_number).zfill(4) + '.png'
     plot_hill(self.ca.grid, filename=fname)
     self.plot_number += 1