def initialize(self, extra_vars=None, ng=4): """ Initialize the grid and variables for compressible flow and set the initial conditions for the chosen problem. """ my_grid = grid_setup(self.rp, ng=ng) my_data = self.data_class(my_grid) # define solver specific boundary condition routines bnd.define_bc("hse", BC.user, is_solid=False) bnd.define_bc("ramp", BC.user, is_solid=False) # for double mach reflection problem bc, bc_xodd, bc_yodd = bc_setup(self.rp) # are we dealing with solid boundaries? we'll use these for # the Riemann solver self.solid = bnd.bc_is_solid(bc) # density and energy my_data.register_var("density", bc) my_data.register_var("energy", bc) my_data.register_var("x-momentum", bc_xodd) my_data.register_var("y-momentum", bc_yodd) # any extras? if extra_vars is not None: for v in extra_vars: my_data.register_var(v, bc) # store the EOS gamma as an auxillary quantity so we can have a # self-contained object stored in output files to make plots. # store grav because we'll need that in some BCs my_data.set_aux("gamma", self.rp.get_param("eos.gamma")) my_data.set_aux("grav", self.rp.get_param("compressible.grav")) my_data.create() self.cc_data = my_data # some auxillary data that we'll need to fill GC in, but isn't # really part of the main solution aux_data = self.data_class(my_grid) aux_data.register_var("ymom_src", bc_yodd) aux_data.register_var("E_src", bc) aux_data.create() self.aux_data = aux_data # derived variables self.cc_data.add_derived(derives.derive_primitives) self.ivars = Variables(my_data) self.cc_data.add_ivars(self.ivars) # initial conditions for the problem problem = importlib.import_module("{}.problems.{}".format( self.solver_name, self.problem_name)) problem.init_data(self.cc_data, self.rp) if self.verbose > 0: print(my_data)
def initialize(self): """ Initialize the grid and variables for compressible flow and set the initial conditions for the chosen problem. """ my_grid = grid_setup(self.rp, ng=4) my_data = patch.CellCenterData2d(my_grid) # define solver specific boundary condition routines bnd.define_bc("hse", BC.user, is_solid=False) bc, bc_xodd, bc_yodd = bc_setup(self.rp) # are we dealing with solid boundaries? we'll use these for # the Riemann solver self.solid = bnd.BCProp( int(bnd.bc_solid[self.rp.get_param("mesh.xlboundary")]), int(bnd.bc_solid[self.rp.get_param("mesh.xrboundary")]), int(bnd.bc_solid[self.rp.get_param("mesh.ylboundary")]), int(bnd.bc_solid[self.rp.get_param("mesh.yrboundary")])) # density and energy my_data.register_var("density", bc) my_data.register_var("energy", bc) my_data.register_var("x-momentum", bc_xodd) my_data.register_var("y-momentum", bc_yodd) # store the EOS gamma as an auxillary quantity so we can have a # self-contained object stored in output files to make plots. # store grav because we'll need that in some BCs my_data.set_aux("gamma", self.rp.get_param("eos.gamma")) my_data.set_aux("grav", self.rp.get_param("compressible.grav")) my_data.create() self.cc_data = my_data # some auxillary data that we'll need to fill GC in, but isn't # really part of the main solution aux_data = patch.CellCenterData2d(my_grid) aux_data.register_var("ymom_src", bc_yodd) aux_data.register_var("E_src", bc) aux_data.create() self.aux_data = aux_data self.vars = Variables(idens=my_data.vars.index("density"), ixmom=my_data.vars.index("x-momentum"), iymom=my_data.vars.index("y-momentum"), iener=my_data.vars.index("energy")) # initial conditions for the problem problem = importlib.import_module("compressible.problems.{}".format( self.problem_name)) problem.init_data(self.cc_data, self.rp) if self.verbose > 0: print(my_data)
def read(filename): """read an HDF5 file and recreate the simulation object that holds the data and state of the simulation. """ if not filename.endswith(".h5"): filename += ".h5" with h5py.File(filename, "r") as f: # read the simulation information -- this only exists if the # file was created as a simulation object try: solver_name = f.attrs["solver"] problem_name = f.attrs["problem"] t = f.attrs["time"] n = f.attrs["nsteps"] except KeyError: # this was just a patch written out solver_name = None # read in the grid info and create our grid grid = f["grid"].attrs myg = patch.Grid2d(grid["nx"], grid["ny"], ng=grid["ng"], xmin=grid["xmin"], xmax=grid["xmax"], ymin=grid["ymin"], ymax=grid["ymax"]) # sometimes problems define custom BCs -- at the moment, we # are going to assume that these always map to BC.user. We # need to read these in now, since the variable creation # requires it. custom_bcs = read_bcs(f) if custom_bcs is not None: if solver_name in [ "compressible_fv4", "compressible_rk", "compressible_sdc" ]: bc_solver = "compressible" else: bc_solver = solver_name bcmod = importlib.import_module("{}.{}".format(bc_solver, "BC")) for name in custom_bcs: bnd.define_bc(name, bcmod.user, is_solid=custom_bcs[name]) # read in the variable info -- start by getting the names gs = f["state"] names = [] for n in gs: names.append(n) # create the CellCenterData2d object myd = patch.CellCenterData2d(myg) for n in names: grp = gs[n] bc = bnd.BC(xlb=grp.attrs["xlb"], xrb=grp.attrs["xrb"], ylb=grp.attrs["ylb"], yrb=grp.attrs["yrb"]) myd.register_var(n, bc) myd.create() # auxillary data for k in f["aux"].attrs: myd.set_aux(k, f["aux"].attrs[k]) # restore the variable data for n in names: grp = gs[n] data = grp["data"] v = myd.get_var(n) v.v()[:, :] = data[:, :] # restore the particle data try: gparticles = f["particles"] particle_data = gparticles["particle_positions"] init_data = gparticles["init_particle_positions"] my_particles = particles.Particles(myd, None, len(particle_data), "array", particle_data, init_data) except KeyError: my_particles = None if solver_name is not None: solver = importlib.import_module(solver_name) sim = solver.Simulation(solver_name, problem_name, None) sim.n = n sim.cc_data = myd sim.cc_data.t = t sim.particles = my_particles sim.read_extras(f) if solver_name is not None: return sim return myd
def initialize(self, extra_vars=None, ng=4): """ Initialize the grid and variables for compressible flow and set the initial conditions for the chosen problem. """ my_grid = grid_setup(self.rp, ng=ng) my_data = self.data_class(my_grid) # define solver specific boundary condition routines bnd.define_bc("hse", BC.user, is_solid=False) bnd.define_bc("ramp", BC.user, is_solid=False) # for double mach reflection problem bc, bc_xodd, bc_yodd = bc_setup(self.rp) # are we dealing with solid boundaries? we'll use these for # the Riemann solver self.solid = bnd.bc_is_solid(bc) # density and energy my_data.register_var("density", bc) my_data.register_var("energy", bc) my_data.register_var("x-momentum", bc_xodd) my_data.register_var("y-momentum", bc_yodd) # any extras? if extra_vars is not None: for v in extra_vars: my_data.register_var(v, bc) # store the EOS gamma as an auxillary quantity so we can have a # self-contained object stored in output files to make plots. # store grav because we'll need that in some BCs my_data.set_aux("gamma", self.rp.get_param("eos.gamma")) my_data.set_aux("grav", self.rp.get_param("compressible.grav")) my_data.create() self.cc_data = my_data if self.rp.get_param("particles.do_particles") == 1: self.particles = particles.Particles(self.cc_data, bc, self.rp) # some auxillary data that we'll need to fill GC in, but isn't # really part of the main solution aux_data = self.data_class(my_grid) aux_data.register_var("ymom_src", bc_yodd) aux_data.register_var("E_src", bc) aux_data.create() self.aux_data = aux_data self.ivars = Variables(my_data) # derived variables self.cc_data.add_derived(derives.derive_primitives) # initial conditions for the problem problem = importlib.import_module("{}.problems.{}".format( self.solver_name, self.problem_name)) problem.init_data(self.cc_data, self.rp) if self.verbose > 0: print(my_data)