def sim_checkpoint(discr, visualizer, eos, q, vizname, exact_soln=None, step=0, t=0, dt=0, cfl=1.0, nstatus=-1, nviz=-1, exittol=1e-16, constant_cfl=False, comm=None, overwrite=False): """Check simulation health, status, viz dumps, and restart.""" # TODO: Add restart do_viz = check_step(step=step, interval=nviz) do_status = check_step(step=step, interval=nstatus) if do_viz is False and do_status is False: return 0 from mirgecom.euler import split_conserved cv = split_conserved(discr.dim, q) dependent_vars = eos.dependent_vars(cv) rank = 0 if comm is not None: rank = comm.Get_rank() maxerr = 0.0 if exact_soln is not None: actx = cv.mass.array_context nodes = thaw(actx, discr.nodes()) expected_state = exact_soln(t=t, x_vec=nodes, eos=eos) exp_resid = q - expected_state err_norms = [discr.norm(v, np.inf) for v in exp_resid] maxerr = max(err_norms) if do_viz: io_fields = [ ("cv", cv), ("dv", dependent_vars) ] if exact_soln is not None: exact_list = [ ("exact_soln", expected_state), ] io_fields.extend(exact_list) from mirgecom.io import make_rank_fname, make_par_fname rank_fn = make_rank_fname(basename=vizname, rank=rank, step=step, t=t) visualizer.write_parallel_vtk_file( comm, rank_fn, io_fields, overwrite=overwrite, par_manifest_filename=make_par_fname(basename=vizname, step=step, t=t)) if do_status is True: # if constant_cfl is False: # current_cfl = get_inviscid_cfl(discr=discr, q=q, # eos=eos, dt=dt) statusmesg = make_status_message(discr=discr, t=t, step=step, dt=dt, cfl=cfl, dependent_vars=dependent_vars) if exact_soln is not None: statusmesg += ( "\n------- errors=" + ", ".join("%.3g" % en for en in err_norms)) if rank == 0: logger.info(statusmesg) if maxerr > exittol: raise ExactSolutionMismatch(step, t=t, state=q)
def write_visfile(discr, io_fields, visualizer, vizname, step=0, t=0, overwrite=False, vis_timer=None): """Write VTK output for the fields specified in *io_fields*. .. note:: This is a collective routine and must be called by all MPI ranks. Parameters ---------- visualizer: A :class:`meshmode.discretization.visualization.Visualizer` VTK output object. io_fields: List of tuples indicating the (name, data) for each field to write. """ from contextlib import nullcontext from mirgecom.io import make_rank_fname, make_par_fname comm = discr.mpi_communicator rank = 0 if comm: rank = comm.Get_rank() rank_fn = make_rank_fname(basename=vizname, rank=rank, step=step, t=t) if rank == 0: import os viz_dir = os.path.dirname(rank_fn) if viz_dir and not os.path.exists(viz_dir): os.makedirs(viz_dir) if comm: comm.barrier() if vis_timer: ctm = vis_timer.start_sub_timer() else: ctm = nullcontext() with ctm: visualizer.write_parallel_vtk_file( comm, rank_fn, io_fields, overwrite=overwrite, par_manifest_filename=make_par_fname(basename=vizname, step=step, t=t))