예제 #1
0
    def run(self):
        r"""
        Convenience routine that will evolve solution based on the 
        traditional clawpack output and run parameters.
        
        This function uses the run parameters and solver parameters to evolve
        the solution to the end time specified in run_data, outputting at the
        appropriate times.
        
        :Input:
            None
            
        :Ouput:
            (dict) - Return a dictionary of the status of the solver.
            
        :Version: 1.0 (2009-05-01)
        """
        
        import numpy as np

        frame = FrameCounter()
        frame.set_counter(self.start_frame)
        if self.keep_copy:
            self.frames = []
                    
        self.solver.setup(self.solution)
        self.solver.dt = self.solver.dt_initial
            
        self.check_validity()

        # Write initial gauge values
        self.solver.write_gauge_values(self.solution)

        # Output styles
        if self.outstyle == 1:
            output_times = np.linspace(self.solution.t,
                    self.tfinal,self.nout+1)
        elif self.outstyle == 2:
            output_times = self.out_times
        elif self.outstyle == 3:
            output_times = np.ones((self.nout+1))
        else:
            raise Exception("Invalid output style %s" % self.outstyle)  
         
        # Output and save initial frame
        if self.keep_copy:
            self.frames.append(copy.deepcopy(self.solution))
        if self.output_format is not None:
            if os.path.exists(self.outdir) and self.overwrite==False:
                raise Exception("Refusing to overwrite existing output data. \
                 \nEither delete/move the directory or set controller.overwrite=True.")
            if self.compute_p is not None:
                self.compute_p(self.solution.state)
                self.solution.write(frame,self.outdir_p,
                                        self.output_format,
                                        self.file_prefix_p,
                                        write_aux = False,
                                        options = self.output_options,
                                        write_p = True) 

            self.solution.write(frame,self.outdir,
                                        self.output_format,
                                        self.output_file_prefix,
                                        self.write_aux_init,
                                        self.output_options)

        self.write_F('w')

        logging.info("Solution %s computed for time t=%f" % 
                        (frame,self.solution.t) )

        for t in output_times[1:]:                
            if self.outstyle < 3:
                status = self.solver.evolve_to_time(self.solution,t)
            else:
                # Take nstepout steps and output
                for n in xrange(self.nstepout):
                    status = self.solver.evolve_to_time(self.solution)
            frame.increment()
            if self.keep_copy:
                # Save current solution to dictionary with frame as key
                self.frames.append(copy.deepcopy(self.solution))
            if self.output_format is not None:
                if self.compute_p is not None:
                    self.compute_p(self.solution.state)
                    self.solution.write(frame,self.outdir_p,
                                            self.output_format,
                                            self.file_prefix_p,
                                            write_aux = False, 
                                            options = self.output_options,
                                            write_p = True) 
                
                self.solution.write(frame,self.outdir,
                                            self.output_format,
                                            self.output_file_prefix,
                                            self.write_aux_always,
                                            self.output_options)
            self.write_F()

            logging.info("Solution %s computed for time t=%f"
                % (frame,self.solution.t))
            for file in self.solution.state.grid.gauge_files: 
                file.flush()
            
        self.solver.teardown()
        for file in self.solution.state.grid.gauge_files: file.close()

        # Return the current status of the solver
        return status
예제 #2
0
    def run(self):
        r"""
        Convenience routine that will evolve solutions['n'] based on the 
        traditional clawpack output and run parameters.
        
        This function uses the run parameters and solver parameters to evolve
        the solution to the end time specified in run_data, outputting at the
        appropriate times.
        
        :Input:
            None
            
        :Ouput:
            (dict) - Return a dictionary of the status of the solver.
            
        :Version: 1.0 (2009-05-01)
        """
        
        frame = FrameCounter()
        if self.keep_copy:
            self.frames = []
                    
        # Check to make sure we have a valid solver to use
        if self.solver is None:
            raise Exception("No solver set in controller.")
        if not isinstance(self.solver,Solver):
            raise Exception("Solver is not of correct type.")
        if not self.solver.is_valid():
            raise Exception("The solver failed to initialize properly.") 
            
        # Call solver's setup routine
        self.solver.setup()
            
        # Check to make sure the initial solutions are valid
        if not reduce(lambda x,y: x*y,[sol.is_valid() for sol in 
                        self.solutions.itervalues()]):
            raise Exception("Initial solutions are not valid.")
        
        # Output styles
        if self.outstyle == 1:
            output_times = np.linspace(self.t0,
                    self.tfinal,self.nout+1)
        elif self.outstyle == 2:
            output_times = self.out_times
        elif self.outstyle == 3:
            output_times = np.ones((self.nout+1))
        else:
            raise Exception("Invalid output style %s" % self.outstyle)  
         
        # Output and save initial time
        if self.keep_copy:
            self.frames.append(copy.deepcopy(self.solutions['n']))
        if self.output_format is not None:
            self.solutions['n'].write(0,self.outdir,
                                        self.output_format,
                                        self.output_file_prefix,
                                        self.write_aux_init,
                                        self.output_options)                            
        logging.info("Solution %s computed for time t=%f" % 
                        (0,self.solutions['n'].t) )
        
        for t in output_times[1:]:
            if self.outstyle < 3:
                status = self.solver.evolve_to_time(self.solutions,t)
            else:
                # Take nstepout steps and output
                for n in xrange(self.nstepout):
                    status = self.solver.evolve_to_time(self.solutions)
            frame.increment()
            # Save current solution to dictionary with frame as key
            if self.keep_copy:
                self.frames.append(copy.deepcopy(self.solutions['n']))
            if self.output_format is not None:
                self.solutions['n'].write(frame,self.outdir,
                                            self.output_format,
                                            self.output_file_prefix,
                                            self.write_aux_always,
                                            self.output_options)

            logging.info("Solution %s computed for time t=%f"
                % (frame,self.solutions['n'].t))
            
        # Return the current status of the solver
        return status
예제 #3
0
    def run(self):
        r"""
        Convenience routine that will evolve solutions['n'] based on the 
        traditional clawpack output and run parameters.
        
        This function uses the run parameters and solver parameters to evolve
        the solution to the end time specified in run_data, outputting at the
        appropriate times.
        
        :Input:
            None
            
        :Ouput:
            (dict) - Return a dictionary of the status of the solver.
            
        :Version: 1.0 (2009-05-01)
        """

        frame = FrameCounter()
        if self.keep_copy:
            self.frames = []

        # Check to make sure we have a valid solver to use
        if self.solver is None:
            raise Exception("No solver set in controller.")
        if not isinstance(self.solver, Solver):
            raise Exception("Solver is not of correct type.")
        if not self.solver.is_valid():
            raise Exception("The solver failed to initialize properly.")

        # Call solver's setup routine
        self.solver.setup()

        # Check to make sure the initial solutions are valid
        if not reduce(lambda x, y: x * y,
                      [sol.is_valid() for sol in self.solutions.itervalues()]):
            raise Exception("Initial solutions are not valid.")

        # Output styles
        if self.outstyle == 1:
            output_times = np.linspace(self.t0, self.tfinal, self.nout + 1)
        elif self.outstyle == 2:
            output_times = self.out_times
        elif self.outstyle == 3:
            output_times = np.ones((self.nout + 1))
        else:
            raise Exception("Invalid output style %s" % self.outstyle)

        # Output and save initial time
        if self.keep_copy:
            self.frames.append(copy.deepcopy(self.solutions['n']))
        if self.output_format is not None:
            self.solutions['n'].write(0, self.outdir, self.output_format,
                                      self.output_file_prefix,
                                      self.write_aux_init, self.output_options)
        logging.info("Solution %s computed for time t=%f" %
                     (0, self.solutions['n'].t))

        for t in output_times[1:]:
            if self.outstyle < 3:
                status = self.solver.evolve_to_time(self.solutions, t)
            else:
                # Take nstepout steps and output
                for n in xrange(self.nstepout):
                    status = self.solver.evolve_to_time(self.solutions)
            frame.increment()
            # Save current solution to dictionary with frame as key
            if self.keep_copy:
                self.frames.append(copy.deepcopy(self.solutions['n']))
            if self.output_format is not None:
                self.solutions['n'].write(frame, self.outdir,
                                          self.output_format,
                                          self.output_file_prefix,
                                          self.write_aux_always,
                                          self.output_options)

            logging.info("Solution %s computed for time t=%f" %
                         (frame, self.solutions['n'].t))

        # Return the current status of the solver
        return status