Example #1
0
    def __init__(self, problem_name, rp, timers=None):
        """
        Initialize the Simulation object for compressible hydrodynamics.

        Parameters
        ----------
        problem_name : str
            The name of the problem we wish to run.  This should
            correspond to one of the modules in compressible/problems/
        rp : RuntimeParameters object
            The runtime parameters for the simulation
        timers : TimerCollection object, optional
            The timers used for profiling this simulation
        """

        self.rp = rp
        self.cc_data = None
        self.problem_name = problem_name

        self.vars = None

        self.SMALL = 1.e-12

        if timers == None:
            self.tc = profile.TimerCollection()
        else:
            self.tc = timers
Example #2
0
    def __init__(self, solver_name):
        """
        Constructor

        Parameters
        ----------
        solver_name : str
            Name of solver to use
        """

        msg.bold('pyro ...')

        if solver_name not in valid_solvers:
            msg.fail("ERROR: %s is not a valid solver" % solver_name)

        self.pyro_home = os.path.dirname(os.path.realpath(__file__)) + '/'

        # import desired solver under "solver" namespace
        self.solver = importlib.import_module(solver_name)
        self.solver_name = solver_name

        # -------------------------------------------------------------------------
        # runtime parameters
        # -------------------------------------------------------------------------

        # parameter defaults
        self.rp = runparams.RuntimeParameters()
        self.rp.load_params(self.pyro_home + "_defaults")
        self.rp.load_params(self.pyro_home + solver_name + "/_defaults")

        self.tc = profile.TimerCollection()

        self.is_initialized = False
Example #3
0
    def __init__(self,
                 solver_name,
                 problem_name,
                 rp,
                 timers=None,
                 data_class=patch.CellCenterData2d):
        """
        Initialize the Simulation object

        Parameters
        ----------
        problem_name : str
            The name of the problem we wish to run.  This should
            correspond to one of the modules in advection/problems/
        rp : RuntimeParameters object
            The runtime parameters for the simulation
        timers : TimerCollection object, optional
            The timers used for profiling this simulation
        """

        self.n = 0
        self.dt = -1.e33
        self.old_dt = -1.e33

        self.data_class = data_class

        try:
            self.tmax = rp.get_param("driver.tmax")
        except (AttributeError, KeyError):
            self.tmax = None

        try:
            self.max_steps = rp.get_param("driver.max_steps")
        except (AttributeError, KeyError):
            self.max_steps = None

        self.rp = rp
        self.cc_data = None
        self.particles = None

        self.SMALL = 1.e-12

        self.solver_name = solver_name
        self.problem_name = problem_name

        if timers is None:
            self.tc = profile.TimerCollection()
        else:
            self.tc = timers

        try:
            self.verbose = self.rp.get_param("driver.verbose")
        except (AttributeError, KeyError):
            self.verbose = 0

        self.n_num_out = 0

        # plotting
        self.cm = "viridis"
Example #4
0
    def __init__(self, solver_name, problem_name, rp, timers=None):
        """
        Initialize the Simulation object

        Parameters
        ----------
        problem_name : str
            The name of the problem we wish to run.  This should
            correspond to one of the modules in advection/problems/
        rp : RuntimeParameters object
            The runtime parameters for the simulation
        timers : TimerCollection object, optional
            The timers used for profiling this simulation
        """

        self.n = 0
        self.dt = -1.e33

        try:
            self.tmax = rp.get_param("driver.tmax")
        except:
            self.tmax = None

        try:
            self.max_steps = rp.get_param("driver.max_steps")
        except:
            self.max_steps = None

        self.rp = rp
        self.cc_data = None

        self.SMALL = 1.e-12

        self.solver_name = solver_name
        self.problem_name = problem_name

        if timers == None:
            self.tc = profile.TimerCollection()
        else:
            self.tc = timers

        try:
            self.verbose = self.rp.get_param("driver.verbose")
        except:
            self.verbose = None

        self.n_num_out = 0
Example #5
0
def doit(solver_name, problem_name, param_file,
         other_commands=None,
         comp_bench=False, reset_bench_on_fail=False, make_bench=False):
    """The main driver to run pyro"""

    msg.bold('pyro ...')

    tc = profile.TimerCollection()

    tm_main = tc.timer("main")
    tm_main.begin()

    # import desired solver under "solver" namespace
    solver = importlib.import_module(solver_name)

    #-------------------------------------------------------------------------
    # runtime parameters
    #-------------------------------------------------------------------------

    # parameter defaults
    rp = runparams.RuntimeParameters()
    rp.load_params("_defaults")
    rp.load_params(solver_name + "/_defaults")

    # problem-specific runtime parameters
    rp.load_params(solver_name + "/problems/_" + problem_name + ".defaults")

    # now read in the inputs file
    if not os.path.isfile(param_file):
        # check if the param file lives in the solver's problems directory
        param_file = solver_name + "/problems/" + param_file
        if not os.path.isfile(param_file):
            msg.fail("ERROR: inputs file does not exist")

    rp.load_params(param_file, no_new=1)

    # and any commandline overrides
    if other_commands is not None:
        rp.command_line_params(other_commands)

    # write out the inputs.auto
    rp.print_paramfile()


    #-------------------------------------------------------------------------
    # initialization
    #-------------------------------------------------------------------------

    # initialize the Simulation object -- this will hold the grid and
    # data and know about the runtime parameters and which problem we
    # are running
    sim = solver.Simulation(solver_name, problem_name, rp, timers=tc)

    sim.initialize()
    sim.preevolve()


    #-------------------------------------------------------------------------
    # evolve
    #-------------------------------------------------------------------------
    verbose = rp.get_param("driver.verbose")

    plt.ion()

    sim.cc_data.t = 0.0

    # output the 0th data
    basename = rp.get_param("io.basename")
    sim.write("{}{:04d}".format(basename, sim.n))

    dovis = rp.get_param("vis.dovis")
    if dovis:
        plt.figure(num=1, figsize=(8, 6), dpi=100, facecolor='w')
        sim.dovis()

    while not sim.finished():

        # fill boundary conditions
        sim.cc_data.fill_BC_all()

        # get the timestep
        sim.compute_timestep()

        # evolve for a single timestep
        sim.evolve()

        if verbose > 0:
            print("%5d %10.5f %10.5f" % (sim.n, sim.cc_data.t, sim.dt))

        # output
        if sim.do_output():
            if verbose > 0:
                msg.warning("outputting...")
            basename = rp.get_param("io.basename")
            sim.write("{}{:04d}".format(basename, sim.n))

        # visualization
        if dovis:
            tm_vis = tc.timer("vis")
            tm_vis.begin()

            sim.dovis()
            store = rp.get_param("vis.store_images")

            if store == 1:
                basename = rp.get_param("io.basename")
                plt.savefig("{}{:04d}.png".format(basename, sim.n))

            tm_vis.end()

    # final output
    if verbose > 0:
        msg.warning("outputting...")
    basename = rp.get_param("io.basename")
    sim.write("{}{:04d}".format(basename, sim.n))

    tm_main.end()


    #-------------------------------------------------------------------------
    # benchmarks (for regression testing)
    #-------------------------------------------------------------------------
    result = 0
    # are we comparing to a benchmark?
    if comp_bench:
        compare_file = "{}/tests/{}{:04d}".format(
            solver_name, basename, sim.n)
        msg.warning("comparing to: {} ".format(compare_file))
        try:
            sim_bench = io.read(compare_file)
        except:
            msg.warning("ERROR openning compare file")
            return "ERROR openning compare file"


        result = compare.compare(sim.cc_data, sim_bench.cc_data)

        if result == 0:
            msg.success("results match benchmark\n")
        else:
            msg.warning("ERROR: " + compare.errors[result] + "\n")


    # are we storing a benchmark?
    if make_bench or (result != 0 and reset_bench_on_fail):
        if not os.path.isdir(solver_name + "/tests/"):
            try:
                os.mkdir(solver_name + "/tests/")
            except:
                msg.fail("ERROR: unable to create the solver's tests/ directory")

        bench_file = solver_name + "/tests/" + basename + "%4.4d" % (sim.n)
        msg.warning("storing new benchmark: {}\n".format(bench_file))
        sim.write(bench_file)


    #-------------------------------------------------------------------------
    # final reports
    #-------------------------------------------------------------------------
    if verbose > 0:
        rp.print_unused_params()
        tc.report()

    sim.finalize()

    if comp_bench:
        return result