From d91aab1ce6bd4bc84c1b0d3601a726a3557bdb34 Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Mon, 22 Jul 2024 18:57:54 -0500 Subject: [PATCH 1/3] switch to ruff --- bin/mirgecompare.py | 5 +- doc/conf.py | 1 + examples/ablation-workshop.py | 208 +++++++++--------- examples/advdiff-tpe.py | 52 ++--- examples/advection_diffusion_reaction.py | 37 ++-- examples/autoignition.py | 54 ++--- examples/blasius.py | 56 ++--- examples/combozzle.py | 93 ++++---- examples/doublemach.py | 48 ++-- examples/doublemach_physical_av.py | 57 +++-- examples/gas-in-box.py | 85 +++---- examples/heat-source.py | 33 +-- examples/hotplate.py | 49 ++--- examples/lump.py | 38 ++-- examples/mixture-tpe.py | 51 ++--- examples/mixture.py | 49 ++--- examples/multiple-volumes.py | 53 ++--- examples/orthotropic-diffusion.py | 22 +- examples/poiseuille-multispecies.py | 50 ++--- examples/poiseuille-tpe.py | 51 +++-- examples/poiseuille.py | 51 +++-- examples/pulse-mixture.py | 45 ++-- examples/pulse-tpe.py | 48 ++-- examples/pulse.py | 46 ++-- examples/scalar-advdiff.py | 50 ++--- examples/scalar-lump.py | 40 ++-- examples/sod.py | 37 ++-- examples/taylor-green.py | 40 ++-- examples/thermally-coupled-tpe.py | 49 +++-- examples/thermally-coupled.py | 49 +++-- examples/vortex.py | 40 ++-- examples/wave.py | 18 +- mirgecom/__init__.py | 2 + mirgecom/array_context.py | 25 ++- mirgecom/artificial_viscosity.py | 45 ++-- mirgecom/boundary.py | 13 +- mirgecom/diffusion.py | 34 +-- mirgecom/discretization.py | 5 +- mirgecom/eos.py | 13 +- mirgecom/euler.py | 6 +- mirgecom/filter.py | 7 +- mirgecom/fluid.py | 2 +- mirgecom/gas_model.py | 31 ++- mirgecom/initializers.py | 3 +- mirgecom/integrators/__init__.py | 7 +- mirgecom/inviscid.py | 18 +- mirgecom/io.py | 4 +- mirgecom/limiter.py | 3 +- mirgecom/logging_quantities.py | 35 +-- mirgecom/materials/carbon_fiber.py | 4 +- mirgecom/materials/initializer.py | 2 +- .../materials/prescribed_porous_material.py | 2 + mirgecom/materials/tacot.py | 3 +- mirgecom/math.py | 9 +- mirgecom/mechanisms/__init__.py | 2 + mirgecom/mpi.py | 11 +- .../thermally_coupled_fluid_wall.py | 81 ++++--- mirgecom/navierstokes.py | 40 ++-- mirgecom/operators.py | 1 - mirgecom/profiling.py | 16 +- mirgecom/restart.py | 1 + mirgecom/simutil.py | 20 +- mirgecom/steppers.py | 4 +- mirgecom/symbolic_fluid.py | 6 +- mirgecom/transport.py | 11 +- mirgecom/utils.py | 7 +- mirgecom/viscous.py | 23 +- mirgecom/wall_model.py | 19 +- mirgecom/wave.py | 9 +- pyproject.toml | 65 ++++++ setup.py | 7 +- test/test_av.py | 61 +++-- test/test_bc.py | 41 ++-- test/test_chemistry.py | 26 +-- test/test_diffusion.py | 54 ++--- test/test_eos.py | 27 ++- test/test_euler.py | 61 +++-- test/test_filter.py | 20 +- test/test_fluid.py | 19 +- test/test_flux.py | 29 ++- test/test_init.py | 23 +- test/test_inviscid.py | 45 ++-- test/test_lazy.py | 42 ++-- test/test_limiter.py | 23 +- test/test_mech_input.py | 2 + test/test_multiphysics.py | 46 ++-- test/test_navierstokes.py | 55 ++--- test/test_operators.py | 13 +- test/test_restart.py | 12 +- test/test_simutil.py | 11 +- test/test_symbolic.py | 20 +- test/test_time_integrators.py | 33 ++- test/test_transport.py | 34 ++- test/test_viscous.py | 41 ++-- test/test_wallmodel.py | 9 +- test/test_wave.py | 31 ++- 96 files changed, 1470 insertions(+), 1509 deletions(-) create mode 100644 pyproject.toml diff --git a/bin/mirgecompare.py b/bin/mirgecompare.py index 21767c278..41590e3fd 100755 --- a/bin/mirgecompare.py +++ b/bin/mirgecompare.py @@ -2,8 +2,9 @@ import json -from mirgecom.simutil import\ - compare_files_vtu, compare_files_xdmf, compare_files_hdf5 + +from mirgecom.simutil import compare_files_hdf5, compare_files_vtu, compare_files_xdmf + # run fidelity check if __name__ == "__main__": diff --git a/doc/conf.py b/doc/conf.py index 362edebee..56b985030 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,6 +1,7 @@ # -- Project information ----------------------------------------------------- import sys + project = "mirgecom" copyright = ("2020, University of Illinois Board of Trustees") author = "Center for Exascale-Enabled Scramjet Design at the University of Illinois" diff --git a/examples/ablation-workshop.py b/examples/ablation-workshop.py index 4062024aa..a78c642bf 100644 --- a/examples/ablation-workshop.py +++ b/examples/ablation-workshop.py @@ -22,66 +22,56 @@ THE SOFTWARE. """ -import logging import gc +import logging +from typing import Optional, Union + +import grudge.geometry as geo import numpy as np import scipy # type: ignore[import-untyped] -from scipy.interpolate import CubicSpline # type: ignore[import-untyped] - -from meshmode.dof_array import DOFArray -from meshmode.discretization.connection import FACE_RESTR_ALL - -from grudge.trace_pair import ( - TracePair, interior_trace_pairs, tracepair_with_discr_tag -) from grudge import op -import grudge.geometry as geo -from grudge.dof_desc import DD_VOLUME_ALL +from grudge.dof_desc import DD_VOLUME_ALL, DISCR_TAG_BASE, BoundaryDomainTag from grudge.shortcuts import make_visualizer -from grudge.dof_desc import ( - BoundaryDomainTag, - DISCR_TAG_BASE -) -from mirgecom.discretization import create_discretization_collection -from mirgecom.integrators import ssprk43_step +from grudge.trace_pair import TracePair, interior_trace_pairs, tracepair_with_discr_tag +from logpyle import IntervalTimer, set_dt +from meshmode.discretization.connection import FACE_RESTR_ALL +from meshmode.dof_array import DOFArray +from scipy.interpolate import CubicSpline # type: ignore[import-untyped] + from mirgecom.diffusion import ( - diffusion_operator, DirichletDiffusionBoundary, + NeumannDiffusionBoundary, PrescribedFluxDiffusionBoundary, - NeumannDiffusionBoundary -) -from mirgecom.simutil import ( - check_naninf_local, - generate_and_distribute_mesh, - write_visfile, - check_step + diffusion_operator, ) -from mirgecom.mpi import mpi_entry_point -from mirgecom.utils import force_evaluation +from mirgecom.discretization import create_discretization_collection +from mirgecom.eos import GasDependentVars, GasEOS, MixtureDependentVars, MixtureEOS +from mirgecom.fluid import ConservedVars +from mirgecom.gas_model import PorousFlowFluidState +from mirgecom.integrators import ssprk43_step from mirgecom.logging_quantities import ( initialize_logmgr, logmgr_add_cl_device_info, - logmgr_add_device_memory_usage + logmgr_add_device_memory_usage, ) -from mirgecom.eos import ( - MixtureDependentVars, - MixtureEOS, - GasEOS, - GasDependentVars +from mirgecom.materials.tacot import TacotEOS as OriginalTacotEOS +from mirgecom.mpi import mpi_entry_point +from mirgecom.simutil import ( + check_naninf_local, + check_step, + generate_and_distribute_mesh, + write_visfile, ) from mirgecom.transport import TransportModel -from mirgecom.gas_model import PorousFlowFluidState +from mirgecom.utils import force_evaluation from mirgecom.wall_model import ( - PorousWallVars, PorousFlowModel as BasePorousFlowModel, - PorousWallTransport + PorousWallTransport, + PorousWallVars, ) -from mirgecom.fluid import ConservedVars -from mirgecom.materials.tacot import TacotEOS as OriginalTacotEOS -from logpyle import IntervalTimer, set_dt -from typing import Optional, Union from pytools.obj_array import make_obj_array + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ logger = logging.getLogger(__name__) @@ -270,39 +260,39 @@ def __init__(self, prandtl=1.0, lewis=1.0): # T , viscosity gas_data = np.array([ - [200.00, 0.086881], - [350.00, 0.144380], - [500.00, 0.196150], - [650.00, 0.243230], - [700.00, 0.258610], - [750.00, 0.274430], - [800.00, 0.290920], - [850.00, 0.307610], - [900.00, 0.323490], - [975.00, 0.344350], - [1025.0, 0.356630], - [1100.0, 0.373980], - [1150.0, 0.385360], - [1175.0, 0.391330], - [1200.0, 0.397930], - [1275.0, 0.421190], - [1400.0, 0.458870], - [1525.0, 0.483230], - [1575.0, 0.487980], - [1625.0, 0.491950], - [1700.0, 0.502120], - [1775.0, 0.516020], - [1925.0, 0.545280], - [2000.0, 0.559860], - [2150.0, 0.588820], - [2300.0, 0.617610], - [2450.0, 0.646380], - [2600.0, 0.675410], - [2750.0, 0.705000], - [2900.0, 0.735570], - [3050.0, 0.767590], - [3200.0, 0.801520], - [3350.0, 0.837430], + [200.00, 0.086881], + [350.00, 0.144380], + [500.00, 0.196150], + [650.00, 0.243230], + [700.00, 0.258610], + [750.00, 0.274430], + [800.00, 0.290920], + [850.00, 0.307610], + [900.00, 0.323490], + [975.00, 0.344350], + [1025.0, 0.356630], + [1100.0, 0.373980], + [1150.0, 0.385360], + [1175.0, 0.391330], + [1200.0, 0.397930], + [1275.0, 0.421190], + [1400.0, 0.458870], + [1525.0, 0.483230], + [1575.0, 0.487980], + [1625.0, 0.491950], + [1700.0, 0.502120], + [1775.0, 0.516020], + [1925.0, 0.545280], + [2000.0, 0.559860], + [2150.0, 0.588820], + [2300.0, 0.617610], + [2450.0, 0.646380], + [2600.0, 0.675410], + [2750.0, 0.705000], + [2900.0, 0.735570], + [3050.0, 0.767590], + [3200.0, 0.801520], + [3350.0, 0.837430], ]) self._cs_viscosity = CubicSpline(gas_data[:, 0], gas_data[:, 1]*1e-4) @@ -359,39 +349,39 @@ def __init__(self): # T , M , Cp , gamma , enthalpy gas_data = np.array([ - [200.00, 21.996, 1.5119, 1.3334, -7246.50], - [350.00, 21.995, 1.7259, 1.2807, -7006.30], - [500.00, 21.948, 2.2411, 1.2133, -6715.20], - [650.00, 21.418, 4.3012, 1.1440, -6265.70], - [700.00, 20.890, 6.3506, 1.1242, -6004.60], - [750.00, 19.990, 9.7476, 1.1131, -5607.70], - [800.00, 18.644, 14.029, 1.1116, -5014.40], - [850.00, 17.004, 17.437, 1.1171, -4218.50], - [900.00, 15.457, 17.009, 1.1283, -3335.30], - [975.00, 14.119, 8.5576, 1.1620, -2352.90], - [1025.0, 13.854, 4.7840, 1.1992, -2034.20], - [1100.0, 13.763, 3.5092, 1.2240, -1741.20], - [1150.0, 13.737, 3.9008, 1.2087, -1560.90], - [1175.0, 13.706, 4.8067, 1.1899, -1453.50], - [1200.0, 13.639, 6.2353, 1.1737, -1315.90], - [1275.0, 13.256, 8.4790, 1.1633, -739.700], - [1400.0, 12.580, 9.0239, 1.1583, 353.3100], - [1525.0, 11.982, 11.516, 1.1377, 1608.400], - [1575.0, 11.732, 12.531, 1.1349, 2214.000], - [1625.0, 11.495, 11.514, 1.1444, 2826.800], - [1700.0, 11.255, 7.3383, 1.1849, 3529.400], - [1775.0, 11.139, 5.3118, 1.2195, 3991.000], - [1925.0, 11.046, 4.2004, 1.2453, 4681.800], - [2000.0, 11.024, 4.0784, 1.2467, 4991.300], - [2150.0, 10.995, 4.1688, 1.2382, 5605.400], - [2300.0, 10.963, 4.5727, 1.2214, 6257.300], - [2450.0, 10.914, 5.3049, 1.2012, 6993.500], - [2600.0, 10.832, 6.4546, 1.1815, 7869.600], - [2750.0, 10.701, 8.1450, 1.1650, 8956.900], - [2900.0, 10.503, 10.524, 1.1528, 10347.00], - [3050.0, 10.221, 13.755, 1.1449, 12157.00], - [3200.0, 9.8394, 17.957, 1.1408, 14523.00], - [3350.0, 9.3574, 22.944, 1.1401, 17584.00], + [200.00, 21.996, 1.5119, 1.3334, -7246.50], + [350.00, 21.995, 1.7259, 1.2807, -7006.30], + [500.00, 21.948, 2.2411, 1.2133, -6715.20], + [650.00, 21.418, 4.3012, 1.1440, -6265.70], + [700.00, 20.890, 6.3506, 1.1242, -6004.60], + [750.00, 19.990, 9.7476, 1.1131, -5607.70], + [800.00, 18.644, 14.029, 1.1116, -5014.40], + [850.00, 17.004, 17.437, 1.1171, -4218.50], + [900.00, 15.457, 17.009, 1.1283, -3335.30], + [975.00, 14.119, 8.5576, 1.1620, -2352.90], + [1025.0, 13.854, 4.7840, 1.1992, -2034.20], + [1100.0, 13.763, 3.5092, 1.2240, -1741.20], + [1150.0, 13.737, 3.9008, 1.2087, -1560.90], + [1175.0, 13.706, 4.8067, 1.1899, -1453.50], + [1200.0, 13.639, 6.2353, 1.1737, -1315.90], + [1275.0, 13.256, 8.4790, 1.1633, -739.700], + [1400.0, 12.580, 9.0239, 1.1583, 353.3100], + [1525.0, 11.982, 11.516, 1.1377, 1608.400], + [1575.0, 11.732, 12.531, 1.1349, 2214.000], + [1625.0, 11.495, 11.514, 1.1444, 2826.800], + [1700.0, 11.255, 7.3383, 1.1849, 3529.400], + [1775.0, 11.139, 5.3118, 1.2195, 3991.000], + [1925.0, 11.046, 4.2004, 1.2453, 4681.800], + [2000.0, 11.024, 4.0784, 1.2467, 4991.300], + [2150.0, 10.995, 4.1688, 1.2382, 5605.400], + [2300.0, 10.963, 4.5727, 1.2214, 6257.300], + [2450.0, 10.914, 5.3049, 1.2012, 6993.500], + [2600.0, 10.832, 6.4546, 1.1815, 7869.600], + [2750.0, 10.701, 8.1450, 1.1650, 8956.900], + [2900.0, 10.503, 10.524, 1.1528, 10347.00], + [3050.0, 10.221, 13.755, 1.1449, 12157.00], + [3200.0, 9.8394, 17.957, 1.1408, 14523.00], + [3350.0, 9.3574, 22.944, 1.1401, 17584.00], ]) self._cs_molar_mass = CubicSpline(gas_data[:, 0], gas_data[:, 1]) @@ -597,7 +587,7 @@ def main(actx_class=None, use_logmgr=True, casename=None, restart_file=None): logmgr = initialize_logmgr(use_logmgr, filename="ablation.sqlite", mode="wo", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -611,7 +601,7 @@ def main(actx_class=None, use_logmgr=True, casename=None, restart_file=None): order = 3 dt = 2.0e-8 - pressure_scaling_factor = 1.0 # noqa N806 + pressure_scaling_factor = 1.0 # N806 nviz = 200 ngarbage = 50 @@ -1206,7 +1196,7 @@ def my_post_step(step, t, dt, state): help="use leap timestepper") parser.add_argument("--numpy", action="store_true", help="use numpy-based eager actx.") - parser.add_argument("-r", "--restart_file", type=ascii, + parser.add_argument("-r", "--restart_file", type=ascii, dest="restart_file", nargs="?", action="store", help="simulation restart file") parser.add_argument("--casename", help="casename to use for i/o") diff --git a/examples/advdiff-tpe.py b/examples/advdiff-tpe.py index 6fb524898..3fe799114 100644 --- a/examples/advdiff-tpe.py +++ b/examples/advdiff-tpe.py @@ -24,42 +24,41 @@ THE SOFTWARE. """ import logging -import numpy as np from functools import partial -from pytools.obj_array import make_obj_array -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from mirgecom.discretization import create_discretization_collection +import numpy as np from grudge.shortcuts import make_visualizer +from logpyle import IntervalTimer, set_dt +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from mirgecom.discretization import create_discretization_collection -from mirgecom.transport import SimpleTransport -from mirgecom.navierstokes import ns_operator -from mirgecom.simutil import ( - # get_sim_timestep, - generate_and_distribute_mesh, - compare_fluid_solutions -) -from mirgecom.limiter import bound_preserving_limiter -from mirgecom.fluid import make_conserved -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point - -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state # from mirgecom.boundary import PrescribedFluidBoundary # from mirgecom.initializers import MulticomponentLump from mirgecom.eos import IdealSingleGas - -from logpyle import IntervalTimer, set_dt from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.fluid import make_conserved +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message +from mirgecom.limiter import bound_preserving_limiter from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, - logmgr_add_device_name, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_device_name, + logmgr_add_many_discretization_quantities, + set_sim_state, +) +from mirgecom.mpi import mpi_entry_point +from mirgecom.navierstokes import ns_operator +from mirgecom.simutil import ( + compare_fluid_solutions, + # get_sim_timestep, + generate_and_distribute_mesh, ) +from mirgecom.steppers import advance_state +from mirgecom.transport import SimpleTransport +from pytools.obj_array import make_obj_array + logger = logging.getLogger(__name__) @@ -88,7 +87,7 @@ def main(actx_class, use_overintegration=False, use_esdg=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm, use_axis_tag_inference_fallback=True, use_einsum_inference_fallback=True) @@ -135,8 +134,8 @@ def main(actx_class, use_overintegration=False, use_esdg=False, box_ll = -.5 box_ur = .5 periodic = (True, )*dim - from meshmode.mesh.generation import generate_regular_rect_mesh from meshmode.mesh import TensorProductElementGroup + from meshmode.mesh.generation import generate_regular_rect_mesh grp_cls = TensorProductElementGroup if use_tpe else None generate_mesh = partial(generate_regular_rect_mesh, a=(box_ll,)*dim, b=(box_ur,) * dim, nelements_per_axis=(nel_1d,)*dim, @@ -217,7 +216,7 @@ def vol_max(x): ("step.max", "step = {value}, "), ("t_sim.max", "sim time: {value:1.6e} s\n"), ("min_pressure", "------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("t_step.max", "------- step walltime: {value:6g} s, "), ("t_log.max", "log walltime: {value:6g} s") ]) @@ -474,6 +473,7 @@ def my_rhs(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/advection_diffusion_reaction.py b/examples/advection_diffusion_reaction.py index 2e82cd1bb..b1c31a431 100644 --- a/examples/advection_diffusion_reaction.py +++ b/examples/advection_diffusion_reaction.py @@ -24,35 +24,35 @@ import logging import numpy as np - -from meshmode.mesh import BTAG_ALL - +from grudge import op +from grudge.dof_desc import DD_VOLUME_ALL, BoundaryDomainTag from grudge.geometry import normal as normal_vector -from grudge.trace_pair import TracePair, interior_trace_pairs -from grudge.dof_desc import BoundaryDomainTag, DD_VOLUME_ALL from grudge.shortcuts import make_visualizer -from grudge import op - +from grudge.trace_pair import TracePair, interior_trace_pairs from logpyle import set_dt +from meshmode.mesh import BTAG_ALL -from mirgecom.io import make_init_message +from mirgecom.diffusion import ( + NeumannDiffusionBoundary, + RobinDiffusionBoundary, + diffusion_operator, +) from mirgecom.discretization import create_discretization_collection -from mirgecom.mpi import mpi_entry_point from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message +from mirgecom.logging_quantities import ( + initialize_logmgr, + logmgr_add_cl_device_info, + logmgr_set_time, +) +from mirgecom.mpi import mpi_entry_point from mirgecom.simutil import ( + check_naninf_local, + check_step, generate_and_distribute_mesh, write_visfile, - check_naninf_local, - check_step ) from mirgecom.utils import force_evaluation -from mirgecom.diffusion import ( - diffusion_operator, - NeumannDiffusionBoundary, - RobinDiffusionBoundary) -from mirgecom.logging_quantities import ( - initialize_logmgr, logmgr_set_time, logmgr_add_cl_device_info -) logger = logging.getLogger(__name__) @@ -127,6 +127,7 @@ def main(actx_class, use_overintegration=False, casename=None, rst_filename=None rank = comm.Get_rank() from functools import partial + from mirgecom.simutil import global_reduce as _global_reduce global_reduce = partial(_global_reduce, comm=comm) diff --git a/examples/autoignition.py b/examples/autoignition.py index 2ec92e9e1..53b4d01b5 100644 --- a/examples/autoignition.py +++ b/examples/autoignition.py @@ -23,42 +23,44 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -import sys import logging -import numpy as np +import sys from functools import partial -from pytools.obj_array import make_obj_array -from grudge.shortcuts import make_visualizer +import cantera import grudge.op as op +import numpy as np +from grudge.shortcuts import make_visualizer from logpyle import IntervalTimer, set_dt + from mirgecom.discretization import create_discretization_collection -from mirgecom.euler import extract_vars_for_logging, units_for_logging -from mirgecom.simutil import ( - get_sim_timestep, - generate_and_distribute_mesh, - write_visfile, - ApplicationOptionsError, - check_step, check_naninf_local, check_range_local -) -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state -from mirgecom.initializers import Uniform from mirgecom.eos import PyrometheusMixture +from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.fluid import make_conserved from mirgecom.gas_model import GasModel, make_fluid_state -from mirgecom.utils import force_evaluation +from mirgecom.initializers import Uniform +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.limiter import bound_preserving_limiter -from mirgecom.fluid import make_conserved from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, + logmgr_add_many_discretization_quantities, ) - -import cantera +from mirgecom.mpi import mpi_entry_point +from mirgecom.simutil import ( + ApplicationOptionsError, + check_naninf_local, + check_range_local, + check_step, + generate_and_distribute_mesh, + get_sim_timestep, + write_visfile, +) +from mirgecom.steppers import advance_state +from mirgecom.utils import force_evaluation +from pytools.obj_array import make_obj_array class SingleLevelFilter(logging.Filter): @@ -112,7 +114,7 @@ def main(actx_class, use_leap=False, use_overintegration=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -207,9 +209,9 @@ def main(actx_class, use_leap=False, use_overintegration=False, units_for_logging) logmgr.add_watches([ ("min_pressure", "\n------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("min_temperature", "------- T (min, max) (K) = ({value:7g}, "), - ("max_temperature", "{value:7g})\n")]) + ("max_temperature", "{value:7g})\n")]) # {{{ Set up initial state using Cantera @@ -446,7 +448,7 @@ def my_write_status(t, dt, cfl, dv=None): temp = dv.temperature press = dv.pressure - from grudge.op import nodal_min_loc, nodal_max_loc + from grudge.op import nodal_max_loc, nodal_min_loc tmin = global_reduce(actx.to_numpy(nodal_min_loc(dcoll, "vol", temp)), op="min") tmax = global_reduce(actx.to_numpy(nodal_max_loc(dcoll, "vol", temp)), diff --git a/examples/blasius.py b/examples/blasius.py index 6d0fe00af..fcf20be26 100644 --- a/examples/blasius.py +++ b/examples/blasius.py @@ -24,46 +24,48 @@ THE SOFTWARE. """ -import os import logging -import numpy as np +import os +import numpy as np +from grudge.dof_desc import DD_VOLUME_ALL, DISCR_TAG_QUAD +from grudge.shortcuts import compiled_lsrk45_step, make_visualizer from logpyle import IntervalTimer, set_dt -from grudge.shortcuts import make_visualizer, compiled_lsrk45_step -from grudge.dof_desc import DISCR_TAG_QUAD, DD_VOLUME_ALL - -from mirgecom.discretization import create_discretization_collection -from mirgecom.navierstokes import ns_operator -from mirgecom.simutil import ( - check_step, - get_sim_timestep, - write_visfile, - check_naninf_local, - distribute_mesh, - global_reduce -) -from mirgecom.restart import write_restart_file -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point -from mirgecom.steppers import advance_state from mirgecom.boundary import ( - PressureOutflowBoundary, AdiabaticSlipBoundary, IsothermalWallBoundary, LinearizedInflowBoundary, LinearizedOutflowBoundary, + PressureOutflowBoundary, ) -from mirgecom.utils import force_evaluation -from mirgecom.fluid import make_conserved +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas +from mirgecom.fluid import make_conserved from mirgecom.gas_model import GasModel, make_fluid_state +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_cl_device_info, logmgr_set_time, + logmgr_add_cl_device_info, + logmgr_set_time, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.navierstokes import ns_operator +from mirgecom.restart import write_restart_file +from mirgecom.simutil import ( + check_naninf_local, + check_step, + distribute_mesh, + get_sim_timestep, + global_reduce, + write_visfile, +) +from mirgecom.steppers import advance_state +from mirgecom.utils import force_evaluation + from arraycontext import get_container_context_recursively + logger = logging.getLogger(__name__) @@ -110,7 +112,7 @@ def main(actx_class, use_overintegration, casename, rst_filename, use_esdg): logmgr = initialize_logmgr(True, filename=(f"{casename}.sqlite"), mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -502,13 +504,13 @@ def my_post_step(step, t, dt, state): import argparse parser = argparse.ArgumentParser(description="MIRGE-Com 1D Flame Driver") - parser.add_argument("-r", "--restart_file", type=ascii, + parser.add_argument("-r", "--restart_file", type=ascii, dest="restart_file", nargs="?", action="store", help="simulation restart file") - parser.add_argument("-i", "--input_file", type=ascii, + parser.add_argument("-i", "--input_file", type=ascii, dest="input_file", nargs="?", action="store", help="simulation config file") - parser.add_argument("-c", "--casename", type=ascii, + parser.add_argument("-c", "--casename", type=ascii, dest="casename", nargs="?", action="store", help="simulation case name") parser.add_argument("--overintegration", action="store_true", diff --git a/examples/combozzle.py b/examples/combozzle.py index ddf9ee385..34882ec99 100644 --- a/examples/combozzle.py +++ b/examples/combozzle.py @@ -25,56 +25,44 @@ """ import logging import time -import yaml -import numpy as np from functools import partial +import cantera +import numpy as np +import yaml +from grudge.dof_desc import DISCR_TAG_QUAD, BoundaryDomainTag +from grudge.shortcuts import compiled_lsrk45_step, make_visualizer +from logpyle import IntervalTimer, set_dt from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from grudge.shortcuts import make_visualizer -from grudge.dof_desc import BoundaryDomainTag, DISCR_TAG_QUAD -from mirgecom.discretization import create_discretization_collection - -from logpyle import IntervalTimer, set_dt -from mirgecom.euler import extract_vars_for_logging, units_for_logging -from mirgecom.euler import euler_operator +from mirgecom.artificial_viscosity import av_laplacian_operator, smoothness_indicator +from mirgecom.discretization import create_discretization_collection +from mirgecom.eos import IdealSingleGas, PyrometheusMixture +from mirgecom.euler import euler_operator, extract_vars_for_logging, units_for_logging +from mirgecom.gas_model import GasModel +from mirgecom.initializers import Uniform +from mirgecom.integrators import euler_step, lsrk54_step, lsrk144_step, rk4_step +from mirgecom.io import make_init_message +from mirgecom.logging_quantities import ( + initialize_logmgr, + logmgr_add_cl_device_info, + logmgr_add_device_memory_usage, + logmgr_add_many_discretization_quantities, + set_sim_state, +) +from mirgecom.mpi import mpi_entry_point from mirgecom.navierstokes import ns_operator - from mirgecom.simutil import ( - get_sim_timestep, - generate_and_distribute_mesh, - write_visfile, + ApplicationOptionsError, force_evaluation, + generate_and_distribute_mesh, get_box_mesh, - ApplicationOptionsError -) -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point -from mirgecom.integrators import ( - rk4_step, euler_step, - lsrk54_step, lsrk144_step + get_sim_timestep, + write_visfile, ) -from grudge.shortcuts import compiled_lsrk45_step from mirgecom.steppers import advance_state -from mirgecom.initializers import Uniform -from mirgecom.eos import ( - PyrometheusMixture, - IdealSingleGas -) from mirgecom.transport import SimpleTransport -from mirgecom.gas_model import GasModel -from mirgecom.artificial_viscosity import ( - av_laplacian_operator, - smoothness_indicator -) -from mirgecom.logging_quantities import ( - initialize_logmgr, - logmgr_add_many_discretization_quantities, - logmgr_add_cl_device_info, - logmgr_add_device_memory_usage, - set_sim_state -) -import cantera + logger = logging.getLogger(__name__) @@ -471,7 +459,7 @@ def main(actx_class, rst_filename=None, use_tpe=False, # param sanity check allowed_integrators = ["rk4", "euler", "lsrk54", "lsrk144", "compiled_lsrk45"] if integrator not in allowed_integrators: - error_message = "Invalid time integrator: {}".format(integrator) + error_message = f"Invalid time integrator: {integrator}" raise RuntimeError(error_message) if rank == 0: @@ -579,7 +567,7 @@ def main(actx_class, rst_filename=None, use_tpe=False, print(f"ACTX setup start: {time.ctime(time.time())}") comm.Barrier() - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -700,9 +688,9 @@ def vol_max(x): units_for_logging) logmgr.add_watches([ ("min_pressure", "\n------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("min_temperature", "------- T (min, max) (K) = ({value:7g}, "), - ("max_temperature", "{value:7g})\n")]) + ("max_temperature", "{value:7g})\n")]) init_y = 0 if single_gas_only: @@ -766,15 +754,17 @@ def vol_max(x): eos = IdealSingleGas() else: if use_cantera: - from mirgecom.thermochemistry \ - import get_pyrometheus_wrapper_class_from_cantera + from mirgecom.thermochemistry import ( + get_pyrometheus_wrapper_class_from_cantera, + ) pyro_mechanism = \ get_pyrometheus_wrapper_class_from_cantera(cantera_soln)(actx.np) eos = PyrometheusMixture(pyro_mechanism, temperature_guess=temperature_seed) else: - from mirgecom.thermochemistry \ - import get_thermochemistry_class_by_mechanism_name + from mirgecom.thermochemistry import ( + get_thermochemistry_class_by_mechanism_name, + ) pyro_mechanism = \ get_thermochemistry_class_by_mechanism_name("uiuc_7sp")(actx.np) nspecies = pyro_mechanism.num_species @@ -833,10 +823,7 @@ def get_fluid_state(cv, tseed): dim=dim, pressure=init_pressure, velocity=velocity, temperature=init_temperature, species_mass_fractions=init_y) - from mirgecom.boundary import ( - AdiabaticNoslipWallBoundary, - IsothermalWallBoundary - ) + from mirgecom.boundary import AdiabaticNoslipWallBoundary, IsothermalWallBoundary adiabatic_wall = AdiabaticNoslipWallBoundary() isothermal_wall = IsothermalWallBoundary(wall_temperature=wall_temperature) if adiabatic_boundary: @@ -938,7 +925,7 @@ def my_write_status(dt, cfl, dv=None): temp = dv.temperature press = dv.pressure - from grudge.op import nodal_min_loc, nodal_max_loc + from grudge.op import nodal_max_loc, nodal_min_loc tmin = global_reduce(actx.to_numpy(nodal_min_loc(dcoll, "vol", temp)), op="min") tmax = global_reduce(actx.to_numpy(nodal_max_loc(dcoll, "vol", temp)), @@ -1076,8 +1063,8 @@ def my_post_step(step, t, dt, state): return state, dt from mirgecom.inviscid import ( + entropy_stable_inviscid_facial_flux_rusanov, inviscid_facial_flux_rusanov, - entropy_stable_inviscid_facial_flux_rusanov ) inv_num_flux_func = entropy_stable_inviscid_facial_flux_rusanov if use_esdg \ else inviscid_facial_flux_rusanov diff --git a/examples/doublemach.py b/examples/doublemach.py index eb1484dbc..960eba908 100644 --- a/examples/doublemach.py +++ b/examples/doublemach.py @@ -25,38 +25,37 @@ """ import logging -import numpy as np from functools import partial -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +import numpy as np from grudge.dof_desc import BoundaryDomainTag from grudge.shortcuts import make_visualizer +from logpyle import set_dt +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa - -from mirgecom.euler import euler_operator from mirgecom.artificial_viscosity import ( + AdiabaticNoSlipWallAV, + PrescribedFluidBoundaryAV, av_laplacian_operator, smoothness_indicator, - AdiabaticNoSlipWallAV, - PrescribedFluidBoundaryAV ) -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state -from mirgecom.initializers import DoubleMachReflection from mirgecom.eos import IdealSingleGas -from mirgecom.transport import SimpleTransport -from mirgecom.simutil import get_sim_timestep, ApplicationOptionsError -from logpyle import set_dt -from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.euler import euler_operator, extract_vars_for_logging, units_for_logging +from mirgecom.initializers import DoubleMachReflection +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.simutil import ApplicationOptionsError, get_sim_timestep +from mirgecom.steppers import advance_state +from mirgecom.transport import SimpleTransport + logger = logging.getLogger(__name__) @@ -76,12 +75,13 @@ def get_doublemach_mesh(): This routine will generate a new grid if it does not find the grid file (doubleMach.msh). """ + import os + from meshmode.mesh.io import ( - read_gmsh, - generate_gmsh, ScriptSource, + generate_gmsh, + read_gmsh, ) - import os meshfile = "doubleMach.msh" if not os.path.exists(meshfile): mesh = generate_gmsh( @@ -130,7 +130,7 @@ def main(actx_class, use_esdg=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -181,7 +181,7 @@ def main(actx_class, use_esdg=False, if use_overintegration: quadrature_tag = DISCR_TAG_QUAD else: - quadrature_tag = None # noqa + quadrature_tag = None dim = 2 if logmgr: @@ -194,9 +194,9 @@ def main(actx_class, use_esdg=False, ("step.max", "step = {value}, "), ("t_sim.max", "sim time: {value:1.6e} s\n"), ("min_pressure", "------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("min_temperature", "------- T (min, max) (K) = ({value:1.9e}, "), - ("max_temperature", "{value:1.9e})\n"), + ("max_temperature", "{value:1.9e})\n"), ("t_step.max", "------- step walltime: {value:6g} s, "), ("t_log.max", "log walltime: {value:6g} s") ]) diff --git a/examples/doublemach_physical_av.py b/examples/doublemach_physical_av.py index 51212822d..56823c8c5 100644 --- a/examples/doublemach_physical_av.py +++ b/examples/doublemach_physical_av.py @@ -25,44 +25,37 @@ """ import logging -import numpy as np from functools import partial -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +import numpy as np from grudge.dof_desc import BoundaryDomainTag -from grudge.shortcuts import make_visualizer +from grudge.shortcuts import compiled_lsrk45_step, make_visualizer +from logpyle import set_dt +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from mirgecom.euler import euler_operator -from mirgecom.navierstokes import ns_operator -from mirgecom.artificial_viscosity import ( - av_laplacian_operator, - smoothness_indicator -) -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point -from mirgecom.integrators import rk4_step, euler_step -from grudge.shortcuts import compiled_lsrk45_step -from mirgecom.steppers import advance_state +from mirgecom.artificial_viscosity import av_laplacian_operator, smoothness_indicator from mirgecom.boundary import ( + AdiabaticSlipBoundary, PrescribedFluidBoundary, PressureOutflowBoundary, - AdiabaticSlipBoundary ) -from mirgecom.initializers import DoubleMachReflection from mirgecom.eos import IdealSingleGas -from mirgecom.transport import ( - SimpleTransport, - ArtificialViscosityTransportDiv -) -from mirgecom.simutil import get_sim_timestep -from mirgecom.utils import force_evaluation - -from logpyle import set_dt +from mirgecom.euler import euler_operator +from mirgecom.initializers import DoubleMachReflection +from mirgecom.integrators import euler_step, rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, logmgr_add_cl_device_info, - logmgr_add_device_memory_usage + logmgr_add_device_memory_usage, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.navierstokes import ns_operator +from mirgecom.simutil import get_sim_timestep +from mirgecom.steppers import advance_state +from mirgecom.transport import ArtificialViscosityTransportDiv, SimpleTransport +from mirgecom.utils import force_evaluation + logger = logging.getLogger(__name__) @@ -82,12 +75,13 @@ def get_doublemach_mesh(): This routine will generate a new grid if it does not find the grid file (doubleMach.msh). """ + import os + from meshmode.mesh.io import ( - read_gmsh, - generate_gmsh, ScriptSource, + generate_gmsh, + read_gmsh, ) - import os meshfile = "doubleMach.msh" if not os.path.exists(meshfile): mesh = generate_gmsh( @@ -145,7 +139,7 @@ def main(actx_class, use_esdg=False, logmgr = initialize_logmgr(True, filename=logname, mode="wo", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -213,7 +207,7 @@ def _compiled_stepper_wrapper(state, t, dt, rhs): if use_overintegration: quadrature_tag = DISCR_TAG_QUAD else: - quadrature_tag = None # noqa + quadrature_tag = None dim = 2 if logmgr: @@ -396,7 +390,7 @@ def my_write_status(cv, dv, dt, cfl): if rank == 0: logger.info(status_msg) - from mirgecom.viscous import get_viscous_timestep, get_viscous_cfl + from mirgecom.viscous import get_viscous_cfl, get_viscous_timestep def my_get_timestep(t, dt, state): t_remaining = max(0, t_final - t) @@ -719,6 +713,7 @@ def _my_rhs_phys_visc_div_av(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/gas-in-box.py b/examples/gas-in-box.py index bfac79294..70b693533 100644 --- a/examples/gas-in-box.py +++ b/examples/gas-in-box.py @@ -24,64 +24,49 @@ THE SOFTWARE. """ -import logging import argparse -import numpy as np +import logging from functools import partial -from meshmode.mesh import BTAG_ALL -from grudge.shortcuts import make_visualizer -from grudge.dof_desc import DISCR_TAG_QUAD, BoundaryDomainTag +import cantera import grudge.op as op - +import numpy as np +from grudge.dof_desc import DISCR_TAG_QUAD, BoundaryDomainTag +from grudge.shortcuts import make_visualizer from logpyle import IntervalTimer, set_dt -from pytools.obj_array import make_obj_array -from mirgecom.mpi import mpi_entry_point +from meshmode.mesh import BTAG_ALL + +from mirgecom.boundary import AdiabaticSlipBoundary, IsothermalWallBoundary from mirgecom.discretization import create_discretization_collection +from mirgecom.eos import IdealSingleGas, PyrometheusMixture from mirgecom.euler import euler_operator -from mirgecom.navierstokes import ns_operator -from mirgecom.simutil import ( - get_sim_timestep, - distribute_mesh -) -from mirgecom.utils import force_evaluation +from mirgecom.fluid import make_conserved +from mirgecom.gas_model import GasModel, make_fluid_state +from mirgecom.initializers import AcousticPulse, Uniform +from mirgecom.integrators import euler_step, rk4_step from mirgecom.io import make_init_message - -from mirgecom.integrators import rk4_step, euler_step -from mirgecom.steppers import advance_state -from mirgecom.boundary import ( - AdiabaticSlipBoundary, - IsothermalWallBoundary -) -from mirgecom.initializers import ( - Uniform, - AcousticPulse -) -from mirgecom.eos import ( - IdealSingleGas, - PyrometheusMixture -) -from mirgecom.gas_model import ( - GasModel, - make_fluid_state -) -from mirgecom.transport import ( - SimpleTransport, - MixtureAveragedTransport, - PowerLawTransport, - ArtificialViscosityTransportDiv, - ArtificialViscosityTransportDiv2, - ArtificialViscosityTransportDiv3 -) from mirgecom.limiter import bound_preserving_limiter -from mirgecom.fluid import make_conserved from mirgecom.logging_quantities import ( initialize_logmgr, # logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, - logmgr_add_device_memory_usage + logmgr_add_device_memory_usage, ) -import cantera +from mirgecom.mpi import mpi_entry_point +from mirgecom.navierstokes import ns_operator +from mirgecom.simutil import distribute_mesh, get_sim_timestep +from mirgecom.steppers import advance_state +from mirgecom.transport import ( + ArtificialViscosityTransportDiv, + ArtificialViscosityTransportDiv2, + ArtificialViscosityTransportDiv3, + MixtureAveragedTransport, + PowerLawTransport, + SimpleTransport, +) +from mirgecom.utils import force_evaluation +from pytools.obj_array import make_obj_array + logger = logging.getLogger(__name__) @@ -119,7 +104,7 @@ def main(actx_class, use_esdg=False, use_tpe=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm, use_axis_tag_inference_fallback=use_tpe, use_einsum_inference_fallback=use_tpe) @@ -295,8 +280,7 @@ def add_wonk(x: np.ndarray) -> np.ndarray: # Create a Pyrometheus EOS with the Cantera soln. Pyrometheus uses # Cantera and generates a set of methods to calculate chemothermomechanical # properties and states for this particular mechanism. - from mirgecom.thermochemistry import \ - get_pyrometheus_wrapper_class_from_cantera + from mirgecom.thermochemistry import get_pyrometheus_wrapper_class_from_cantera pyro_mechanism = \ get_pyrometheus_wrapper_class_from_cantera( cantera_soln, temperature_niter=newton_iters)(actx.np) @@ -366,7 +350,7 @@ def add_wonk(x: np.ndarray) -> np.ndarray: if transport_type == 2: if not use_mixture: error_message = "Invalid transport_type "\ - "{} for single gas.".format(transport_type) + f"{transport_type} for single gas." raise RuntimeError(error_message) if rank == 0: print("Pyrometheus transport model:") @@ -398,7 +382,7 @@ def add_wonk(x: np.ndarray) -> np.ndarray: sigma=transport_sigma, n=transport_n, species_diffusivity=species_diffusivity) else: - error_message = "Unknown transport_type {}".format(transport_type) + error_message = f"Unknown transport_type {transport_type}" raise RuntimeError(error_message) transport = physical_transport_model @@ -452,7 +436,7 @@ def add_wonk(x: np.ndarray) -> np.ndarray: f"\tav_prantdl {av2_prandtl0}" f"stagnation temperature {static_temp}") else: - error_message = "Unknown artifical viscosity model {}".format(use_av) + error_message = f"Unknown artifical viscosity model {use_av}" raise RuntimeError(error_message) gas_model = GasModel(eos=eos, transport=transport) @@ -802,6 +786,7 @@ def my_rhs(t, stepper_state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/heat-source.py b/examples/heat-source.py index 66b8a9f63..a334fe104 100644 --- a/examples/heat-source.py +++ b/examples/heat-source.py @@ -23,24 +23,26 @@ """ import logging -import numpy as np - import grudge.op as op -from grudge.shortcuts import make_visualizer +import numpy as np from grudge.dof_desc import BoundaryDomainTag -from mirgecom.discretization import create_discretization_collection -from mirgecom.integrators import rk4_step +from grudge.shortcuts import make_visualizer +from logpyle import IntervalTimer, set_dt + from mirgecom.diffusion import ( - diffusion_operator, DirichletDiffusionBoundary, - NeumannDiffusionBoundary) + NeumannDiffusionBoundary, + diffusion_operator, +) +from mirgecom.discretization import create_discretization_collection +from mirgecom.integrators import rk4_step +from mirgecom.logging_quantities import ( + initialize_logmgr, + logmgr_add_cl_device_info, + logmgr_add_device_memory_usage, +) from mirgecom.mpi import mpi_entry_point -from mirgecom.simutil import write_visfile, check_step, check_naninf_local -from mirgecom.logging_quantities import (initialize_logmgr, - logmgr_add_cl_device_info, - logmgr_add_device_memory_usage) - -from logpyle import IntervalTimer, set_dt +from mirgecom.simutil import check_naninf_local, check_step, write_visfile logger = logging.getLogger(__name__) @@ -64,13 +66,14 @@ def main(actx_class, use_esdg=False, num_parts = comm.Get_size() from functools import partial + from mirgecom.simutil import global_reduce as _global_reduce global_reduce = partial(_global_reduce, comm=comm) logmgr = initialize_logmgr(True, filename="heat-source.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -120,7 +123,7 @@ def main(actx_class, use_esdg=False, if use_overintegration: quadrature_tag = DISCR_TAG_QUAD else: - quadrature_tag = None # noqa + quadrature_tag = None if dim == 2: # no deep meaning here, just a fudge factor diff --git a/examples/hotplate.py b/examples/hotplate.py index 6bbbaa0e1..6efdc0b5e 100644 --- a/examples/hotplate.py +++ b/examples/hotplate.py @@ -24,42 +24,34 @@ THE SOFTWARE. """ import logging -import numpy as np from functools import partial -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa - -from grudge.shortcuts import make_visualizer +import numpy as np from grudge.dof_desc import BoundaryDomainTag +from grudge.shortcuts import make_visualizer +from logpyle import IntervalTimer, set_dt +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from mirgecom.boundary import IsothermalWallBoundary, PrescribedFluidBoundary from mirgecom.discretization import create_discretization_collection -from mirgecom.fluid import make_conserved -from mirgecom.navierstokes import ns_operator -from mirgecom.simutil import ( - get_sim_timestep, - get_box_mesh -) - -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state -from mirgecom.boundary import ( - PrescribedFluidBoundary, - IsothermalWallBoundary -) -from mirgecom.transport import SimpleTransport from mirgecom.eos import IdealSingleGas -from mirgecom.gas_model import GasModel, make_fluid_state -from logpyle import IntervalTimer, set_dt from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.fluid import make_conserved +from mirgecom.gas_model import GasModel, make_fluid_state +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.navierstokes import ns_operator +from mirgecom.simutil import get_box_mesh, get_sim_timestep +from mirgecom.steppers import advance_state +from mirgecom.transport import SimpleTransport logger = logging.getLogger(__name__) @@ -89,7 +81,7 @@ def main(actx_class, use_esdg=False, use_leap=False, casename=None, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -163,9 +155,9 @@ def main(actx_class, use_esdg=False, use_leap=False, casename=None, ("step.max", "step = {value}, "), ("t_sim.max", "sim time: {value:1.6e} s\n"), ("min_pressure", "------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("min_temperature", "------- T (min, max) (K) = ({value:1.9e}, "), - ("max_temperature", "{value:1.9e})\n"), + ("max_temperature", "{value:1.9e})\n"), ("t_step.max", "------- step walltime: {value:6g} s, "), ("t_log.max", "log walltime: {value:6g} s") ]) @@ -246,7 +238,7 @@ def _boundary_state(dcoll, dd_bdry, gas_model, state_minus, **kwargs): logger.info(init_message) def my_write_status(step, t, dt, state, component_errors): - from grudge.op import nodal_min, nodal_max + from grudge.op import nodal_max, nodal_min dv = state.dv p_min = actx.to_numpy(nodal_min(dcoll, "vol", dv.pressure)) p_max = actx.to_numpy(nodal_max(dcoll, "vol", dv.pressure)) @@ -451,6 +443,7 @@ def my_rhs(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/lump.py b/examples/lump.py index 672fa5e09..5acced971 100644 --- a/examples/lump.py +++ b/examples/lump.py @@ -24,37 +24,32 @@ THE SOFTWARE. """ import logging -import numpy as np from functools import partial +import numpy as np from grudge.dof_desc import DISCR_TAG_QUAD -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa from grudge.shortcuts import make_visualizer +from logpyle import IntervalTimer, set_dt +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from mirgecom.discretization import create_discretization_collection -from mirgecom.euler import euler_operator -from mirgecom.simutil import ( - get_sim_timestep, - generate_and_distribute_mesh -) -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point - -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state from mirgecom.boundary import PrescribedFluidBoundary -from mirgecom.initializers import Lump, Uniform # noqa +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas - -from logpyle import IntervalTimer, set_dt -from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.euler import euler_operator, extract_vars_for_logging, units_for_logging +from mirgecom.initializers import Lump, Uniform # noqa +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.simutil import generate_and_distribute_mesh, get_sim_timestep +from mirgecom.steppers import advance_state + logger = logging.getLogger(__name__) @@ -84,7 +79,7 @@ def main(actx_class, use_esdg=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -158,7 +153,7 @@ def main(actx_class, use_esdg=False, ("step.max", "step = {value}, "), ("t_sim.max", "sim time: {value:1.6e} s\n"), ("min_pressure", "------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("t_step.max", "------- step walltime: {value:6g} s, "), ("t_log.max", "log walltime: {value:6g} s") ]) @@ -386,6 +381,7 @@ def my_rhs(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/mixture-tpe.py b/examples/mixture-tpe.py index 9b730048b..14943f4c8 100644 --- a/examples/mixture-tpe.py +++ b/examples/mixture-tpe.py @@ -24,42 +24,33 @@ THE SOFTWARE. """ import logging -import numpy as np from functools import partial -from meshmode.mesh import BTAG_ALL -from grudge.shortcuts import make_visualizer +import cantera +import numpy as np from grudge.dof_desc import DISCR_TAG_QUAD +from grudge.shortcuts import make_visualizer +from logpyle import IntervalTimer, set_dt +from meshmode.mesh import BTAG_ALL +from mirgecom.boundary import AdiabaticSlipBoundary, PrescribedFluidBoundary from mirgecom.discretization import create_discretization_collection -from mirgecom.euler import euler_operator -from mirgecom.simutil import ( - get_sim_timestep, - generate_and_distribute_mesh -) -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point - -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state -from mirgecom.boundary import ( - PrescribedFluidBoundary, - AdiabaticSlipBoundary -) -from mirgecom.initializers import Uniform from mirgecom.eos import PyrometheusMixture - -import cantera - -from logpyle import IntervalTimer, set_dt -from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.euler import euler_operator, extract_vars_for_logging, units_for_logging +from mirgecom.initializers import Uniform +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.simutil import generate_and_distribute_mesh, get_sim_timestep +from mirgecom.steppers import advance_state + logger = logging.getLogger(__name__) @@ -89,7 +80,7 @@ def main(actx_class, use_esdg=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm, use_axis_tag_inference_fallback=True, use_einsum_inference_fallback=True) @@ -133,8 +124,8 @@ def main(actx_class, use_esdg=False, nel_1d = 16 box_ll = -5.0 box_ur = 5.0 - from meshmode.mesh.generation import generate_regular_rect_mesh from meshmode.mesh import TensorProductElementGroup + from meshmode.mesh.generation import generate_regular_rect_mesh grp_cls = TensorProductElementGroup if use_tpe else None generate_mesh = partial(generate_regular_rect_mesh, a=(box_ll,)*dim, b=(box_ur,) * dim, nelements_per_axis=(nel_1d,)*dim, @@ -175,9 +166,9 @@ def main(actx_class, use_esdg=False, units_for_logging) logmgr.add_watches([ ("min_pressure", "\n------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("min_temperature", "------- T (min, max) (K) = ({value:7g}, "), - ("max_temperature", "{value:7g})\n")]) + ("max_temperature", "{value:7g})\n")]) # Pyrometheus initialization from mirgecom.mechanisms import get_mechanism_input @@ -261,7 +252,7 @@ def my_write_status(component_errors, dv=None): temp = dv.temperature press = dv.pressure - from grudge.op import nodal_min_loc, nodal_max_loc + from grudge.op import nodal_max_loc, nodal_min_loc tmin = global_reduce(actx.to_numpy(nodal_min_loc(dcoll, "vol", temp)), op="min") tmax = global_reduce(actx.to_numpy(nodal_max_loc(dcoll, "vol", temp)), diff --git a/examples/mixture.py b/examples/mixture.py index 4beba862c..6a5b79d4c 100644 --- a/examples/mixture.py +++ b/examples/mixture.py @@ -24,42 +24,33 @@ THE SOFTWARE. """ import logging -import numpy as np from functools import partial -from meshmode.mesh import BTAG_ALL -from grudge.shortcuts import make_visualizer +import cantera +import numpy as np from grudge.dof_desc import DISCR_TAG_QUAD +from grudge.shortcuts import make_visualizer +from logpyle import IntervalTimer, set_dt +from meshmode.mesh import BTAG_ALL +from mirgecom.boundary import AdiabaticSlipBoundary, PrescribedFluidBoundary from mirgecom.discretization import create_discretization_collection -from mirgecom.euler import euler_operator -from mirgecom.simutil import ( - get_sim_timestep, - generate_and_distribute_mesh -) -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point - -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state -from mirgecom.boundary import ( - PrescribedFluidBoundary, - AdiabaticSlipBoundary -) -from mirgecom.initializers import Uniform from mirgecom.eos import PyrometheusMixture - -import cantera - -from logpyle import IntervalTimer, set_dt -from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.euler import euler_operator, extract_vars_for_logging, units_for_logging +from mirgecom.initializers import Uniform +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.simutil import generate_and_distribute_mesh, get_sim_timestep +from mirgecom.steppers import advance_state + logger = logging.getLogger(__name__) @@ -89,7 +80,7 @@ def main(actx_class, use_esdg=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -169,9 +160,9 @@ def main(actx_class, use_esdg=False, units_for_logging) logmgr.add_watches([ ("min_pressure", "\n------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("min_temperature", "------- T (min, max) (K) = ({value:7g}, "), - ("max_temperature", "{value:7g})\n")]) + ("max_temperature", "{value:7g})\n")]) # Pyrometheus initialization from mirgecom.mechanisms import get_mechanism_input @@ -255,7 +246,7 @@ def my_write_status(component_errors, dv=None): temp = dv.temperature press = dv.pressure - from grudge.op import nodal_min_loc, nodal_max_loc + from grudge.op import nodal_max_loc, nodal_min_loc tmin = global_reduce(actx.to_numpy(nodal_min_loc(dcoll, "vol", temp)), op="min") tmax = global_reduce(actx.to_numpy(nodal_max_loc(dcoll, "vol", temp)), diff --git a/examples/multiple-volumes.py b/examples/multiple-volumes.py index 8feed339a..fb44f906e 100644 --- a/examples/multiple-volumes.py +++ b/examples/multiple-volumes.py @@ -30,46 +30,34 @@ """ import logging -from mirgecom.mpi import mpi_entry_point -import numpy as np from functools import partial -from pytools.obj_array import make_obj_array -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +import numpy as np +from grudge.dof_desc import DISCR_TAG_BASE, DISCR_TAG_QUAD, DOFDesc, VolumeDomainTag from grudge.shortcuts import make_visualizer -from grudge.dof_desc import VolumeDomainTag, DISCR_TAG_BASE, DISCR_TAG_QUAD, DOFDesc - -from mirgecom.discretization import create_discretization_collection -from mirgecom.euler import ( - euler_operator, - extract_vars_for_logging -) -from mirgecom.simutil import ( - get_sim_timestep, - generate_and_distribute_mesh -) -from mirgecom.io import make_init_message +from logpyle import IntervalTimer, set_dt +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state from mirgecom.boundary import AdiabaticSlipBoundary -from mirgecom.initializers import ( - Lump, - AcousticPulse -) +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas -from mirgecom.gas_model import ( - GasModel, - make_fluid_state -) -from logpyle import IntervalTimer, set_dt +from mirgecom.euler import euler_operator, extract_vars_for_logging +from mirgecom.gas_model import GasModel, make_fluid_state +from mirgecom.initializers import AcousticPulse, Lump +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.simutil import generate_and_distribute_mesh, get_sim_timestep +from mirgecom.steppers import advance_state +from pytools.obj_array import make_obj_array + logger = logging.getLogger(__name__) @@ -99,7 +87,7 @@ def main(actx_class, use_esdg=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -147,7 +135,7 @@ def main(actx_class, use_esdg=False, local_prototype_mesh, global_prototype_nelements = \ generate_and_distribute_mesh(comm, generate_mesh) - volume_to_local_mesh = {i: local_prototype_mesh for i in range(nvolumes)} + volume_to_local_mesh = dict.fromkeys(range(nvolumes), local_prototype_mesh) local_nelements = local_prototype_mesh.nelements * nvolumes global_nelements = global_prototype_nelements * nvolumes @@ -198,7 +186,7 @@ def units(quantity): logmgr.add_watches([ (f"min_pressure_{i}", "------- P (vol. " + str(i) + ") (min, max) (Pa) = ({value:1.9e}, "), - (f"max_pressure_{i}", "{value:1.9e})\n"), + (f"max_pressure_{i}", "{value:1.9e})\n"), ]) eos = IdealSingleGas() @@ -395,6 +383,7 @@ def my_rhs(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/orthotropic-diffusion.py b/examples/orthotropic-diffusion.py index 0014ad059..c1f098a3e 100644 --- a/examples/orthotropic-diffusion.py +++ b/examples/orthotropic-diffusion.py @@ -22,20 +22,23 @@ THE SOFTWARE. """ import logging + import numpy as np -from grudge.shortcuts import make_visualizer from grudge.dof_desc import BoundaryDomainTag +from grudge.shortcuts import make_visualizer +from logpyle import IntervalTimer, set_dt + +from mirgecom.diffusion import DirichletDiffusionBoundary, diffusion_operator from mirgecom.discretization import create_discretization_collection from mirgecom.integrators import rk4_step -from mirgecom.diffusion import diffusion_operator, DirichletDiffusionBoundary +from mirgecom.logging_quantities import ( + initialize_logmgr, + logmgr_add_cl_device_info, + logmgr_add_device_memory_usage, +) from mirgecom.mpi import mpi_entry_point +from mirgecom.simutil import check_step, generate_and_distribute_mesh, write_visfile from mirgecom.utils import force_evaluation -from mirgecom.simutil import (generate_and_distribute_mesh, - write_visfile, check_step) -from mirgecom.logging_quantities import (initialize_logmgr, - logmgr_add_cl_device_info, - logmgr_add_device_memory_usage) -from logpyle import IntervalTimer, set_dt logger = logging.getLogger(__name__) @@ -58,7 +61,7 @@ def main(actx_class, use_overintegration=False, casename=None, rst_filename=None logmgr = initialize_logmgr(True, filename="heat-diffusion.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -83,6 +86,7 @@ def main(actx_class, use_overintegration=False, casename=None, rst_filename=None _kappa[0] = factor*_kappa[1] from functools import partial + from meshmode.mesh.generation import generate_regular_rect_mesh generate_mesh = partial(generate_regular_rect_mesh, a=(-1.0*np.sqrt(factor), -1.0), b=(+1.0*np.sqrt(factor), +1.0), diff --git a/examples/poiseuille-multispecies.py b/examples/poiseuille-multispecies.py index ebe1b18fd..5d4de86d9 100644 --- a/examples/poiseuille-multispecies.py +++ b/examples/poiseuille-multispecies.py @@ -24,40 +24,35 @@ THE SOFTWARE. """ import logging -import numpy as np -from pytools.obj_array import make_obj_array from functools import partial +import numpy as np +from grudge.dof_desc import BoundaryDomainTag +from grudge.shortcuts import make_visualizer +from logpyle import IntervalTimer, set_dt from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from mirgecom.boundary import IsothermalWallBoundary, PrescribedFluidBoundary from mirgecom.discretization import create_discretization_collection -from grudge.shortcuts import make_visualizer -from grudge.dof_desc import BoundaryDomainTag - -from mirgecom.fluid import make_conserved -from mirgecom.navierstokes import ns_operator -from mirgecom.simutil import get_sim_timestep - -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state -from mirgecom.boundary import ( - PrescribedFluidBoundary, - IsothermalWallBoundary -) -from mirgecom.transport import SimpleTransport from mirgecom.eos import IdealSingleGas # , PyrometheusMixture -from mirgecom.gas_model import GasModel, make_fluid_state -from logpyle import IntervalTimer, set_dt from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.fluid import make_conserved +from mirgecom.gas_model import GasModel, make_fluid_state +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, - logmgr_add_device_name, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_device_name, + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.navierstokes import ns_operator +from mirgecom.simutil import get_sim_timestep +from mirgecom.steppers import advance_state +from mirgecom.transport import SimpleTransport +from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) @@ -98,7 +93,7 @@ def main(actx_class, use_overintegration=False, use_leap=False, casename=None, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -176,9 +171,9 @@ def main(actx_class, use_overintegration=False, use_leap=False, casename=None, ("step.max", "step = {value}, "), ("t_sim.max", "sim time: {value:1.6e} s\n"), ("min_pressure", "------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("min_temperature", "------- T (min, max) (K) = ({value:1.9e}, "), - ("max_temperature", "{value:1.9e})\n"), + ("max_temperature", "{value:1.9e})\n"), ("t_step.max", "------- step walltime: {value:6g} s, "), ("t_log.max", "log walltime: {value:6g} s") ]) @@ -285,7 +280,7 @@ def _exact_boundary_solution(dcoll, dd_bdry, gas_model, state_minus, **kwargs): def my_write_status(step, t, dt, state, component_errors): dv = state.dv - from grudge.op import nodal_min, nodal_max + from grudge.op import nodal_max, nodal_min p_min = actx.to_numpy(nodal_min(dcoll, "vol", dv.pressure)) p_max = actx.to_numpy(nodal_max(dcoll, "vol", dv.pressure)) t_min = actx.to_numpy(nodal_min(dcoll, "vol", dv.temperature)) @@ -498,6 +493,7 @@ def my_rhs(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/poiseuille-tpe.py b/examples/poiseuille-tpe.py index cb9b0364c..f7e074bdc 100644 --- a/examples/poiseuille-tpe.py +++ b/examples/poiseuille-tpe.py @@ -24,42 +24,40 @@ THE SOFTWARE. """ import logging -import numpy as np -from pytools.obj_array import make_obj_array from functools import partial -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +import numpy as np +from grudge.dof_desc import DISCR_TAG_QUAD, BoundaryDomainTag from grudge.shortcuts import make_visualizer -from grudge.dof_desc import BoundaryDomainTag, DISCR_TAG_QUAD +from logpyle import IntervalTimer, set_dt +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from mirgecom.discretization import create_discretization_collection -from mirgecom.fluid import make_conserved -from mirgecom.navierstokes import ns_operator -from mirgecom.simutil import ( - get_sim_timestep, - get_box_mesh -) -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state from mirgecom.boundary import ( - PrescribedFluidBoundary, AdiabaticNoslipWallBoundary, - IsothermalWallBoundary + IsothermalWallBoundary, + PrescribedFluidBoundary, ) -from mirgecom.transport import SimpleTransport +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas -from mirgecom.gas_model import GasModel, make_fluid_state -from logpyle import IntervalTimer, set_dt from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.fluid import make_conserved +from mirgecom.gas_model import GasModel, make_fluid_state +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.navierstokes import ns_operator +from mirgecom.simutil import get_box_mesh, get_sim_timestep +from mirgecom.steppers import advance_state +from mirgecom.transport import SimpleTransport +from pytools.obj_array import make_obj_array + logger = logging.getLogger(__name__) @@ -88,7 +86,7 @@ def main(actx_class, use_esdg=False, use_overintegration=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm, use_axis_tag_inference_fallback=True, use_einsum_inference_fallback=True) @@ -169,9 +167,9 @@ def main(actx_class, use_esdg=False, use_overintegration=False, ("step.max", "step = {value}, "), ("t_sim.max", "sim time: {value:1.6e} s\n"), ("min_pressure", "------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("min_temperature", "------- T (min, max) (K) = ({value:1.9e}, "), - ("max_temperature", "{value:1.9e})\n"), + ("max_temperature", "{value:1.9e})\n"), ("t_step.max", "------- step walltime: {value:6g} s, "), ("t_log.max", "log walltime: {value:6g} s") ]) @@ -276,7 +274,7 @@ def _make_fluid_state(cv): def my_write_status(step, t, dt, state, component_errors): dv = state.dv - from grudge.op import nodal_min, nodal_max + from grudge.op import nodal_max, nodal_min p_min = actx.to_numpy(nodal_min(dcoll, "vol", dv.pressure)) p_max = actx.to_numpy(nodal_max(dcoll, "vol", dv.pressure)) t_min = actx.to_numpy(nodal_min(dcoll, "vol", dv.temperature)) @@ -482,6 +480,7 @@ def my_rhs(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/poiseuille.py b/examples/poiseuille.py index a3838b5b7..a993be4a9 100644 --- a/examples/poiseuille.py +++ b/examples/poiseuille.py @@ -24,42 +24,40 @@ THE SOFTWARE. """ import logging -import numpy as np -from pytools.obj_array import make_obj_array from functools import partial -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +import numpy as np +from grudge.dof_desc import DISCR_TAG_QUAD, BoundaryDomainTag from grudge.shortcuts import make_visualizer -from grudge.dof_desc import BoundaryDomainTag, DISCR_TAG_QUAD +from logpyle import IntervalTimer, set_dt +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from mirgecom.discretization import create_discretization_collection -from mirgecom.fluid import make_conserved -from mirgecom.navierstokes import ns_operator -from mirgecom.simutil import ( - get_sim_timestep, - get_box_mesh -) -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state from mirgecom.boundary import ( - PrescribedFluidBoundary, AdiabaticNoslipWallBoundary, - IsothermalWallBoundary + IsothermalWallBoundary, + PrescribedFluidBoundary, ) -from mirgecom.transport import SimpleTransport +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas -from mirgecom.gas_model import GasModel, make_fluid_state -from logpyle import IntervalTimer, set_dt from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.fluid import make_conserved +from mirgecom.gas_model import GasModel, make_fluid_state +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.navierstokes import ns_operator +from mirgecom.simutil import get_box_mesh, get_sim_timestep +from mirgecom.steppers import advance_state +from mirgecom.transport import SimpleTransport +from pytools.obj_array import make_obj_array + logger = logging.getLogger(__name__) @@ -88,7 +86,7 @@ def main(actx_class, use_esdg=False, use_overintegration=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -165,9 +163,9 @@ def main(actx_class, use_esdg=False, use_overintegration=False, ("step.max", "step = {value}, "), ("t_sim.max", "sim time: {value:1.6e} s\n"), ("min_pressure", "------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("min_temperature", "------- T (min, max) (K) = ({value:1.9e}, "), - ("max_temperature", "{value:1.9e})\n"), + ("max_temperature", "{value:1.9e})\n"), ("t_step.max", "------- step walltime: {value:6g} s, "), ("t_log.max", "log walltime: {value:6g} s") ]) @@ -272,7 +270,7 @@ def _make_fluid_state(cv): def my_write_status(step, t, dt, state, component_errors): dv = state.dv - from grudge.op import nodal_min, nodal_max + from grudge.op import nodal_max, nodal_min p_min = actx.to_numpy(nodal_min(dcoll, "vol", dv.pressure)) p_max = actx.to_numpy(nodal_max(dcoll, "vol", dv.pressure)) t_min = actx.to_numpy(nodal_min(dcoll, "vol", dv.temperature)) @@ -478,6 +476,7 @@ def my_rhs(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/pulse-mixture.py b/examples/pulse-mixture.py index 56d068141..c5a02e5f0 100644 --- a/examples/pulse-mixture.py +++ b/examples/pulse-mixture.py @@ -26,44 +26,40 @@ import logging from functools import partial -import numpy as np -import cantera -from grudge.shortcuts import make_visualizer -from grudge.dof_desc import BoundaryDomainTag, DISCR_TAG_QUAD, DD_VOLUME_ALL +import cantera +import numpy as np from grudge import op - +from grudge.dof_desc import DD_VOLUME_ALL, DISCR_TAG_QUAD, BoundaryDomainTag +from grudge.shortcuts import make_visualizer from logpyle import IntervalTimer, set_dt -from mirgecom.mpi import mpi_entry_point -from mirgecom.discretization import create_discretization_collection -from mirgecom.euler import euler_operator -from mirgecom.simutil import generate_and_distribute_mesh -from mirgecom.io import make_init_message -from mirgecom.utils import force_evaluation -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state from mirgecom.boundary import ( - LinearizedOutflowBoundary, + AdiabaticSlipBoundary, LinearizedInflowBoundary, + LinearizedOutflowBoundary, # RiemannInflowBoundary, PressureOutflowBoundary, - AdiabaticSlipBoundary ) -from mirgecom.initializers import AcousticPulse, initialize_flow_solution +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import PyrometheusMixture -from mirgecom.gas_model import ( - GasModel, - make_fluid_state -) -from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.euler import euler_operator, extract_vars_for_logging, units_for_logging +from mirgecom.gas_model import GasModel, make_fluid_state +from mirgecom.initializers import AcousticPulse, initialize_flow_solution +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, - logmgr_add_device_memory_usage + logmgr_add_device_memory_usage, + logmgr_add_many_discretization_quantities, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.simutil import generate_and_distribute_mesh +from mirgecom.steppers import advance_state from mirgecom.thermochemistry import get_pyrometheus_wrapper_class_from_cantera +from mirgecom.utils import force_evaluation + logger = logging.getLogger(__name__) @@ -93,7 +89,7 @@ def main(actx_class, use_esdg=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -424,6 +420,7 @@ def my_rhs(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/pulse-tpe.py b/examples/pulse-tpe.py index 50d10e84f..d86bbcdbe 100644 --- a/examples/pulse-tpe.py +++ b/examples/pulse-tpe.py @@ -25,44 +25,33 @@ """ import logging -import numpy as np from functools import partial -from meshmode.mesh import BTAG_ALL -from grudge.shortcuts import make_visualizer +import numpy as np from grudge.dof_desc import DISCR_TAG_QUAD - +from grudge.shortcuts import make_visualizer from logpyle import IntervalTimer, set_dt +from meshmode.mesh import BTAG_ALL -from mirgecom.mpi import mpi_entry_point -from mirgecom.discretization import create_discretization_collection -from mirgecom.euler import euler_operator -from mirgecom.simutil import ( - get_sim_timestep, - distribute_mesh -) -from mirgecom.io import make_init_message - -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state from mirgecom.boundary import AdiabaticSlipBoundary -from mirgecom.initializers import ( - Uniform, - AcousticPulse -) +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas -from mirgecom.gas_model import ( - GasModel, - make_fluid_state -) -from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.euler import euler_operator, extract_vars_for_logging, units_for_logging +from mirgecom.gas_model import GasModel, make_fluid_state +from mirgecom.initializers import AcousticPulse, Uniform +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.simutil import distribute_mesh, get_sim_timestep +from mirgecom.steppers import advance_state + logger = logging.getLogger(__name__) @@ -92,7 +81,7 @@ def main(actx_class, use_esdg=False, use_tpe=True, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm, use_axis_tag_inference_fallback=True, use_einsum_inference_fallback=True) @@ -132,8 +121,8 @@ def main(actx_class, use_esdg=False, use_tpe=True, global_nelements = restart_data["global_nelements"] assert restart_data["num_parts"] == num_parts else: # generate the grid from scratch - from meshmode.mesh.generation import generate_regular_rect_mesh from meshmode.mesh import TensorProductElementGroup + from meshmode.mesh.generation import generate_regular_rect_mesh grp_cls = TensorProductElementGroup if use_tpe else None box_ll = -1 box_ur = 1 @@ -169,7 +158,7 @@ def main(actx_class, use_esdg=False, use_tpe=True, ("step.max", "step = {value}, "), ("t_sim.max", "sim time: {value:1.6e} s\n"), ("min_pressure", "------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("t_step.max", "------- step walltime: {value:6g} s, "), ("t_log.max", "log walltime: {value:6g} s") ]) @@ -351,6 +340,7 @@ def my_rhs(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError warn("This version of the pulse example is forced to use quads/hexes.") diff --git a/examples/pulse.py b/examples/pulse.py index 74b5bb6aa..e5eedbfa2 100644 --- a/examples/pulse.py +++ b/examples/pulse.py @@ -25,44 +25,33 @@ """ import logging -import numpy as np from functools import partial -from meshmode.mesh import BTAG_ALL -from grudge.shortcuts import make_visualizer +import numpy as np from grudge.dof_desc import DISCR_TAG_QUAD - +from grudge.shortcuts import make_visualizer from logpyle import IntervalTimer, set_dt +from meshmode.mesh import BTAG_ALL -from mirgecom.mpi import mpi_entry_point -from mirgecom.discretization import create_discretization_collection -from mirgecom.euler import euler_operator -from mirgecom.simutil import ( - get_sim_timestep, - distribute_mesh -) -from mirgecom.io import make_init_message - -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state from mirgecom.boundary import AdiabaticSlipBoundary -from mirgecom.initializers import ( - Uniform, - AcousticPulse -) +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas -from mirgecom.gas_model import ( - GasModel, - make_fluid_state -) -from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.euler import euler_operator, extract_vars_for_logging, units_for_logging +from mirgecom.gas_model import GasModel, make_fluid_state +from mirgecom.initializers import AcousticPulse, Uniform +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.simutil import distribute_mesh, get_sim_timestep +from mirgecom.steppers import advance_state + logger = logging.getLogger(__name__) @@ -92,7 +81,7 @@ def main(actx_class, use_esdg=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -163,7 +152,7 @@ def main(actx_class, use_esdg=False, ("step.max", "step = {value}, "), ("t_sim.max", "sim time: {value:1.6e} s\n"), ("min_pressure", "------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("t_step.max", "------- step walltime: {value:6g} s, "), ("t_log.max", "log walltime: {value:6g} s") ]) @@ -345,6 +334,7 @@ def my_rhs(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/scalar-advdiff.py b/examples/scalar-advdiff.py index 8b6a40215..23bb3a4ed 100644 --- a/examples/scalar-advdiff.py +++ b/examples/scalar-advdiff.py @@ -24,42 +24,41 @@ THE SOFTWARE. """ import logging -import numpy as np from functools import partial -from pytools.obj_array import make_obj_array -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from mirgecom.discretization import create_discretization_collection +import numpy as np from grudge.shortcuts import make_visualizer +from logpyle import IntervalTimer, set_dt +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from mirgecom.discretization import create_discretization_collection -from mirgecom.transport import SimpleTransport -from mirgecom.navierstokes import ns_operator -from mirgecom.simutil import ( - # get_sim_timestep, - generate_and_distribute_mesh, - compare_fluid_solutions -) -from mirgecom.limiter import bound_preserving_limiter -from mirgecom.fluid import make_conserved -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point - -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state # from mirgecom.boundary import PrescribedFluidBoundary # from mirgecom.initializers import MulticomponentLump from mirgecom.eos import IdealSingleGas - -from logpyle import IntervalTimer, set_dt from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.fluid import make_conserved +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message +from mirgecom.limiter import bound_preserving_limiter from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, - logmgr_add_device_name, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_device_name, + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.navierstokes import ns_operator +from mirgecom.simutil import ( + compare_fluid_solutions, + # get_sim_timestep, + generate_and_distribute_mesh, +) +from mirgecom.steppers import advance_state +from mirgecom.transport import SimpleTransport +from pytools.obj_array import make_obj_array + logger = logging.getLogger(__name__) @@ -88,7 +87,7 @@ def main(actx_class, use_overintegration=False, use_esdg=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -212,7 +211,7 @@ def vol_max(x): ("step.max", "step = {value}, "), ("t_sim.max", "sim time: {value:1.6e} s\n"), ("min_pressure", "------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("t_step.max", "------- step walltime: {value:6g} s, "), ("t_log.max", "log walltime: {value:6g} s") ]) @@ -470,6 +469,7 @@ def my_rhs(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/scalar-lump.py b/examples/scalar-lump.py index 4a02af72f..6690e5030 100644 --- a/examples/scalar-lump.py +++ b/examples/scalar-lump.py @@ -24,38 +24,33 @@ THE SOFTWARE. """ import logging -import numpy as np from functools import partial -from pytools.obj_array import make_obj_array +import numpy as np from grudge.dof_desc import DISCR_TAG_QUAD -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa from grudge.shortcuts import make_visualizer +from logpyle import IntervalTimer, set_dt +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from mirgecom.discretization import create_discretization_collection -from mirgecom.euler import euler_operator -from mirgecom.simutil import ( - get_sim_timestep, - generate_and_distribute_mesh -) -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point - -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state from mirgecom.boundary import PrescribedFluidBoundary -from mirgecom.initializers import MulticomponentLump +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas - -from logpyle import IntervalTimer, set_dt -from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.euler import euler_operator, extract_vars_for_logging, units_for_logging +from mirgecom.initializers import MulticomponentLump +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.simutil import generate_and_distribute_mesh, get_sim_timestep +from mirgecom.steppers import advance_state +from pytools.obj_array import make_obj_array + logger = logging.getLogger(__name__) @@ -85,7 +80,7 @@ def main(actx_class, use_leap=False, casename=None, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -158,7 +153,7 @@ def main(actx_class, use_leap=False, casename=None, ("step.max", "step = {value}, "), ("t_sim.max", "sim time: {value:1.6e} s\n"), ("min_pressure", "------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("t_step.max", "------- step walltime: {value:6g} s, "), ("t_log.max", "log walltime: {value:6g} s") ]) @@ -396,6 +391,7 @@ def my_rhs(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/sod.py b/examples/sod.py index 7c6227b8a..366df0bca 100644 --- a/examples/sod.py +++ b/examples/sod.py @@ -24,36 +24,32 @@ THE SOFTWARE. """ import logging -import numpy as np # noqa from functools import partial -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +import numpy as np from grudge.shortcuts import make_visualizer +from logpyle import IntervalTimer, set_dt +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from mirgecom.discretization import create_discretization_collection -from mirgecom.euler import euler_operator -from mirgecom.simutil import ( - get_sim_timestep, - generate_and_distribute_mesh -) -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point - -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state from mirgecom.boundary import PrescribedFluidBoundary -from mirgecom.initializers import SodShock1D +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas +from mirgecom.euler import euler_operator, extract_vars_for_logging, units_for_logging from mirgecom.gas_model import GasModel, make_fluid_state -from logpyle import IntervalTimer, set_dt -from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.initializers import SodShock1D +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.simutil import generate_and_distribute_mesh, get_sim_timestep +from mirgecom.steppers import advance_state + logger = logging.getLogger(__name__) @@ -82,7 +78,7 @@ def main(actx_class, use_overintegration=False, use_esdg=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -164,7 +160,7 @@ def main(actx_class, use_overintegration=False, use_esdg=False, ("step.max", "step = {value}, "), ("t_sim.max", "sim time: {value:1.6e} s\n"), ("min_pressure", "------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("t_step.max", "------- step walltime: {value:6g} s, "), ("t_log.max", "log walltime: {value:6g} s") ]) @@ -394,6 +390,7 @@ def my_rhs(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/taylor-green.py b/examples/taylor-green.py index 7e087f0d4..6940f36f9 100644 --- a/examples/taylor-green.py +++ b/examples/taylor-green.py @@ -24,38 +24,31 @@ THE SOFTWARE. """ -import numpy as np import logging - -from mirgecom.mpi import mpi_entry_point - from functools import partial +import numpy as np from grudge.shortcuts import make_visualizer +from logpyle import IntervalTimer, set_dt -from mirgecom.euler import euler_operator -from mirgecom.simutil import ( - generate_and_distribute_mesh -) -from mirgecom.io import make_init_message from mirgecom.discretization import create_discretization_collection -from mirgecom.integrators import lsrk54_step -from mirgecom.steppers import advance_state -from mirgecom.initializers import InviscidTaylorGreenVortex from mirgecom.eos import IdealSingleGas -from mirgecom.gas_model import ( - GasModel, - make_fluid_state -) -from logpyle import IntervalTimer, set_dt -from mirgecom.euler import extract_vars_for_logging, units_for_logging +from mirgecom.euler import euler_operator, extract_vars_for_logging, units_for_logging +from mirgecom.gas_model import GasModel, make_fluid_state +from mirgecom.initializers import InviscidTaylorGreenVortex +from mirgecom.integrators import lsrk54_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, - logmgr_add_device_name, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_device_name, + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.simutil import generate_and_distribute_mesh +from mirgecom.steppers import advance_state + logger = logging.getLogger(__name__) @@ -85,7 +78,7 @@ def main(actx_class, order=1, t_final=1, resolution=4, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -156,7 +149,7 @@ def main(actx_class, order=1, t_final=1, resolution=4, ("step.max", "step = {value}, "), ("t_sim.max", "sim time: {value:1.6e} s\n"), ("min_pressure", "------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("t_step.max", "------- step walltime: {value:6g} s, "), ("t_log.max", "log walltime: {value:6g} s") ]) @@ -337,6 +330,7 @@ def my_rhs(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/thermally-coupled-tpe.py b/examples/thermally-coupled-tpe.py index a733c4fdc..3cb432984 100644 --- a/examples/thermally-coupled-tpe.py +++ b/examples/thermally-coupled-tpe.py @@ -26,53 +26,53 @@ import logging import os -from mirgecom.mpi import mpi_entry_point -import numpy as np from functools import partial -from pytools.obj_array import make_obj_array - -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from meshmode.discretization.connection import FACE_RESTR_ALL # noqa -from grudge.shortcuts import make_visualizer -from grudge.op import nodal_min, nodal_max +import numpy as np from grudge.dof_desc import ( - VolumeDomainTag, DISCR_TAG_BASE, DISCR_TAG_QUAD, DOFDesc, + VolumeDomainTag, ) -from mirgecom.diffusion import NeumannDiffusionBoundary -from mirgecom.discretization import create_discretization_collection -from mirgecom.simutil import ( - get_sim_timestep, -) -from mirgecom.io import make_init_message +from grudge.op import nodal_max, nodal_min +from grudge.shortcuts import make_visualizer +from logpyle import IntervalTimer, set_dt +from meshmode.discretization.connection import FACE_RESTR_ALL # noqa +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state from mirgecom.boundary import ( IsothermalWallBoundary, ) +from mirgecom.diffusion import NeumannDiffusionBoundary +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas -from mirgecom.transport import SimpleTransport +from mirgecom.euler import extract_vars_for_logging from mirgecom.fluid import make_conserved from mirgecom.gas_model import ( GasModel, make_fluid_state, ) -from logpyle import IntervalTimer, set_dt -from mirgecom.euler import extract_vars_for_logging +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point from mirgecom.multiphysics.thermally_coupled_fluid_wall import ( basic_coupled_ns_heat_operator as coupled_ns_heat_operator, ) +from mirgecom.simutil import ( + get_sim_timestep, +) +from mirgecom.steppers import advance_state +from mirgecom.transport import SimpleTransport +from pytools.obj_array import make_obj_array + logger = logging.getLogger(__name__) @@ -101,7 +101,7 @@ def main(actx_class, use_esdg=False, use_overintegration=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm, use_axis_tag_inference_fallback=True, use_einsum_inference_fallback=True) @@ -228,7 +228,7 @@ def units(quantity): ("step.max", "step = {value}, "), ("t_sim.max", "sim time: {value:1.6e} s\n"), ("min_pressure_Fluid", "------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure_Fluid", "{value:1.9e})\n"), + ("max_pressure_Fluid", "{value:1.9e})\n"), ("t_step.max", "------- step walltime: {value:6g} s, "), ("t_log.max", "log walltime: {value:6g} s") ]) @@ -595,6 +595,7 @@ def my_rhs_and_gradients(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/thermally-coupled.py b/examples/thermally-coupled.py index 7ef400f1e..34940071f 100644 --- a/examples/thermally-coupled.py +++ b/examples/thermally-coupled.py @@ -26,53 +26,53 @@ import logging import os -from mirgecom.mpi import mpi_entry_point -import numpy as np from functools import partial -from pytools.obj_array import make_obj_array - -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from meshmode.discretization.connection import FACE_RESTR_ALL # noqa -from grudge.shortcuts import make_visualizer -from grudge.op import nodal_min, nodal_max +import numpy as np from grudge.dof_desc import ( - VolumeDomainTag, DISCR_TAG_BASE, DISCR_TAG_QUAD, DOFDesc, + VolumeDomainTag, ) -from mirgecom.diffusion import NeumannDiffusionBoundary -from mirgecom.discretization import create_discretization_collection -from mirgecom.simutil import ( - get_sim_timestep, -) -from mirgecom.io import make_init_message +from grudge.op import nodal_max, nodal_min +from grudge.shortcuts import make_visualizer +from logpyle import IntervalTimer, set_dt +from meshmode.discretization.connection import FACE_RESTR_ALL # noqa +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state from mirgecom.boundary import ( IsothermalWallBoundary, ) +from mirgecom.diffusion import NeumannDiffusionBoundary +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas -from mirgecom.transport import SimpleTransport +from mirgecom.euler import extract_vars_for_logging from mirgecom.fluid import make_conserved from mirgecom.gas_model import ( GasModel, make_fluid_state, ) -from logpyle import IntervalTimer, set_dt -from mirgecom.euler import extract_vars_for_logging +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point from mirgecom.multiphysics.thermally_coupled_fluid_wall import ( basic_coupled_ns_heat_operator as coupled_ns_heat_operator, ) +from mirgecom.simutil import ( + get_sim_timestep, +) +from mirgecom.steppers import advance_state +from mirgecom.transport import SimpleTransport +from pytools.obj_array import make_obj_array + logger = logging.getLogger(__name__) @@ -101,7 +101,7 @@ def main(actx_class, use_esdg=False, use_overintegration=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -220,7 +220,7 @@ def units(quantity): ("step.max", "step = {value}, "), ("t_sim.max", "sim time: {value:1.6e} s\n"), ("min_pressure_Fluid", "------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure_Fluid", "{value:1.9e})\n"), + ("max_pressure_Fluid", "{value:1.9e})\n"), ("t_step.max", "------- step walltime: {value:6g} s, "), ("t_log.max", "log walltime: {value:6g} s") ]) @@ -587,6 +587,7 @@ def my_rhs_and_gradients(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/vortex.py b/examples/vortex.py index ca8fce34d..7f8185ca8 100644 --- a/examples/vortex.py +++ b/examples/vortex.py @@ -24,38 +24,32 @@ THE SOFTWARE. """ import logging -import numpy as np from functools import partial -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +import numpy as np from grudge.shortcuts import make_visualizer +from logpyle import IntervalTimer, set_dt +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from mirgecom.discretization import create_discretization_collection -from mirgecom.euler import euler_operator -from mirgecom.simutil import ( - get_sim_timestep, - generate_and_distribute_mesh, - check_step -) -from mirgecom.io import make_init_message -from mirgecom.mpi import mpi_entry_point - -from mirgecom.integrators import rk4_step -from mirgecom.steppers import advance_state from mirgecom.boundary import PrescribedFluidBoundary -from mirgecom.initializers import Vortex2D +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas +from mirgecom.euler import euler_operator, extract_vars_for_logging, units_for_logging from mirgecom.gas_model import GasModel, make_fluid_state -from logpyle import IntervalTimer, set_dt -from mirgecom.euler import extract_vars_for_logging, units_for_logging - +from mirgecom.initializers import Vortex2D +from mirgecom.integrators import rk4_step +from mirgecom.io import make_init_message from mirgecom.logging_quantities import ( initialize_logmgr, - logmgr_add_many_discretization_quantities, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, - set_sim_state + logmgr_add_many_discretization_quantities, + set_sim_state, ) +from mirgecom.mpi import mpi_entry_point +from mirgecom.simutil import check_step, generate_and_distribute_mesh, get_sim_timestep +from mirgecom.steppers import advance_state + logger = logging.getLogger(__name__) @@ -84,7 +78,7 @@ def main(actx_class, use_overintegration=False, use_esdg=False, logmgr = initialize_logmgr(True, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - from mirgecom.array_context import initialize_actx, actx_class_is_profiling + from mirgecom.array_context import actx_class_is_profiling, initialize_actx actx = initialize_actx(actx_class, comm) queue = getattr(actx, "queue", None) use_profiling = actx_class_is_profiling(actx_class) @@ -160,7 +154,7 @@ def main(actx_class, use_overintegration=False, use_esdg=False, ("step.max", "step = {value}, "), ("t_sim.max", "sim time: {value:1.6e} s\n"), ("min_pressure", "------- P (min, max) (Pa) = ({value:1.9e}, "), - ("max_pressure", "{value:1.9e})\n"), + ("max_pressure", "{value:1.9e})\n"), ("t_step.max", "------- step walltime: {value:6g} s, "), ("t_log.max", "log walltime: {value:6g} s") ]) @@ -225,6 +219,7 @@ def my_write_status(state, component_errors, cfl=None): cfl = current_cfl else: from grudge.op import nodal_max + from mirgecom.inviscid import get_inviscid_cfl cfl = actx.to_numpy( nodal_max( @@ -404,6 +399,7 @@ def my_rhs(t, state): args = parser.parse_args() from warnings import warn + from mirgecom.simutil import ApplicationOptionsError if args.esdg: if not args.lazy and not args.numpy: diff --git a/examples/wave.py b/examples/wave.py index f6c920b83..37fc5b3c5 100644 --- a/examples/wave.py +++ b/examples/wave.py @@ -22,25 +22,27 @@ THE SOFTWARE. """ import logging - import sys + import grudge.op as op import numpy as np from grudge.shortcuts import make_visualizer from logpyle import IntervalTimer, set_dt from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from pytools.obj_array import flat_obj_array from mirgecom.array_context import initialize_actx from mirgecom.discretization import create_discretization_collection from mirgecom.integrators import rk4_step -from mirgecom.logging_quantities import (initialize_logmgr, - logmgr_add_cl_device_info, - logmgr_add_device_memory_usage, - logmgr_add_mempool_usage) +from mirgecom.logging_quantities import ( + initialize_logmgr, + logmgr_add_cl_device_info, + logmgr_add_device_memory_usage, + logmgr_add_mempool_usage, +) from mirgecom.mpi import mpi_entry_point from mirgecom.utils import force_evaluation from mirgecom.wave import wave_operator +from pytools.obj_array import flat_obj_array def bump(actx, nodes, t=0): @@ -98,6 +100,7 @@ def main(actx_class, casename="wave", nel_1d = 16 from functools import partial + from meshmode.mesh.generation import generate_regular_rect_mesh generate_mesh = partial(generate_regular_rect_mesh, @@ -159,8 +162,7 @@ def main(actx_class, casename="wave", if old_order != order: old_dcoll = create_discretization_collection( actx, local_mesh, order=old_order) - from meshmode.discretization.connection import \ - make_same_mesh_connection + from meshmode.discretization.connection import make_same_mesh_connection connection = make_same_mesh_connection(actx, dcoll.discr_from_dd("vol"), old_dcoll.discr_from_dd("vol")) fields = connection(restart_fields) diff --git a/mirgecom/__init__.py b/mirgecom/__init__.py index dcb37be8d..b41a42477 100644 --- a/mirgecom/__init__.py +++ b/mirgecom/__init__.py @@ -25,4 +25,6 @@ """ import mirgecom.version + + __version__ = mirgecom.version.VERSION_TEXT diff --git a/mirgecom/array_context.py b/mirgecom/array_context.py index f6c066565..1e080a776 100644 --- a/mirgecom/array_context.py +++ b/mirgecom/array_context.py @@ -32,13 +32,14 @@ THE SOFTWARE. """ -from typing import Type, Dict, Any -import os import logging +import os +from typing import Any, Dict, Type import pyopencl as cl -from arraycontext import (ArrayContext, PyOpenCLArrayContext, - PytatoPyOpenCLArrayContext) + +from arraycontext import ArrayContext, PyOpenCLArrayContext, PytatoPyOpenCLArrayContext + logger = logging.getLogger(__name__) @@ -69,8 +70,9 @@ def get_reasonable_array_context_class(*, lazy: bool, distributed: bool, from mirgecom.profiling import PyOpenCLProfilingArrayContext return PyOpenCLProfilingArrayContext - from grudge.array_context import \ - get_reasonable_array_context_class as grudge_get_reasonable_actx_class + from grudge.array_context import ( + get_reasonable_array_context_class as grudge_get_reasonable_actx_class, + ) return grudge_get_reasonable_actx_class(lazy=lazy, distributed=distributed) @@ -168,6 +170,7 @@ def _check_gpu_oversubscription(actx: ArrayContext) -> None: PCI_DOMAIN_ID_NV extension. """ from mpi4py import MPI + import pyopencl as cl assert isinstance(actx, (PyOpenCLArrayContext, PytatoPyOpenCLArrayContext)) @@ -225,7 +228,7 @@ def log_disk_cache_config(actx: ArrayContext) -> None: rank = MPI.COMM_WORLD.Get_rank() res = f"Rank {rank} disk cache config: " - from pyopencl.characterize import nv_compute_capability, get_pocl_version + from pyopencl.characterize import get_pocl_version, nv_compute_capability dev = actx.queue.device # Variables set to a 'True' value => cache is disabled @@ -270,9 +273,11 @@ def initialize_actx( use_axis_tag_inference_fallback: bool = False, use_einsum_inference_fallback: bool = False) -> ArrayContext: """Initialize a new :class:`~arraycontext.ArrayContext` based on *actx_class*.""" - from grudge.array_context import (MPIPyOpenCLArrayContext, - MPIPytatoArrayContext, - MPINumpyArrayContext) + from grudge.array_context import ( + MPINumpyArrayContext, + MPIPyOpenCLArrayContext, + MPIPytatoArrayContext, + ) actx_kwargs: Dict[str, Any] = {} diff --git a/mirgecom/artificial_viscosity.py b/mirgecom/artificial_viscosity.py index fc9a0c57a..e64e067dc 100644 --- a/mirgecom/artificial_viscosity.py +++ b/mirgecom/artificial_viscosity.py @@ -125,39 +125,32 @@ THE SOFTWARE. """ -import numpy as np - -from pytools import memoize_in, keyed_memoize_in from functools import partial -from meshmode.dof_array import DOFArray -from meshmode.discretization.connection import FACE_RESTR_ALL - -from mirgecom.flux import num_flux_central -from mirgecom.operators import div_operator - -from grudge.trace_pair import ( - interior_trace_pairs, - tracepair_with_discr_tag -) +import grudge.op as op +import numpy as np from grudge.dof_desc import ( DD_VOLUME_ALL, - VolumeDomainTag, DISCR_TAG_BASE, DISCR_TAG_MODAL, + VolumeDomainTag, + as_dofdesc, ) - -from mirgecom.utils import normalize_boundaries -from arraycontext import get_container_context_recursively -from grudge.dof_desc import as_dofdesc -from grudge.trace_pair import TracePair -import grudge.op as op +from grudge.trace_pair import TracePair, interior_trace_pairs, tracepair_with_discr_tag +from meshmode.discretization.connection import FACE_RESTR_ALL +from meshmode.dof_array import DOFArray from mirgecom.boundary import ( AdiabaticNoslipWallBoundary, + IsothermalWallBoundary, PrescribedFluidBoundary, - IsothermalWallBoundary ) +from mirgecom.flux import num_flux_central +from mirgecom.operators import div_operator +from mirgecom.utils import normalize_boundaries +from pytools import keyed_memoize_in, memoize_in + +from arraycontext import get_container_context_recursively class _AVRTag: @@ -443,10 +436,14 @@ def smoothness_indicator(dcoll, u, kappa=1.0, s0=-6.0, dd=DD_VOLUME_ALL): @memoize_in(actx, (smoothness_indicator, "smooth_comp_knl", dd)) def indicator_prg(): """Compute the smoothness indicator for all elements.""" - from arraycontext import make_loopy_program - from meshmode.transform_metadata import (ConcurrentElementInameTag, - ConcurrentDOFInameTag) + from meshmode.transform_metadata import ( + ConcurrentDOFInameTag, + ConcurrentElementInameTag, + ) + import loopy as lp + + from arraycontext import make_loopy_program t_unit = make_loopy_program([ "{[iel]: 0 <= iel < nelements}", "{[idof]: 0 <= idof < ndiscr_nodes_in}", diff --git a/mirgecom/boundary.py b/mirgecom/boundary.py index bc467219d..b1022b77b 100644 --- a/mirgecom/boundary.py +++ b/mirgecom/boundary.py @@ -52,18 +52,21 @@ """ from abc import ABCMeta, abstractmethod -import numpy as np + import grudge.op as op -from arraycontext import outer, get_container_context_recursively -from meshmode.discretization.connection import FACE_RESTR_ALL +import numpy as np from grudge.dof_desc import as_dofdesc from grudge.trace_pair import TracePair -from pytools.obj_array import make_obj_array +from meshmode.discretization.connection import FACE_RESTR_ALL + from mirgecom.fluid import make_conserved from mirgecom.gas_model import make_fluid_state, replace_fluid_state +from mirgecom.inviscid import inviscid_facial_flux_rusanov, inviscid_flux from mirgecom.utils import project_from_base from mirgecom.viscous import viscous_facial_flux_central, viscous_flux -from mirgecom.inviscid import inviscid_facial_flux_rusanov, inviscid_flux +from pytools.obj_array import make_obj_array + +from arraycontext import get_container_context_recursively, outer def _ldg_bnd_flux_for_grad(internal_quantity, external_quantity): diff --git a/mirgecom/diffusion.py b/mirgecom/diffusion.py index ab9759084..bb72f0d25 100644 --- a/mirgecom/diffusion.py +++ b/mirgecom/diffusion.py @@ -86,22 +86,24 @@ import abc from functools import partial + import numpy as np -from pytools.obj_array import make_obj_array, obj_array_vectorize_n_args -from meshmode.discretization.connection import FACE_RESTR_ALL # noqa +from grudge import op from grudge.dof_desc import ( DD_VOLUME_ALL, - VolumeDomainTag, DISCR_TAG_BASE, + VolumeDomainTag, ) from grudge.trace_pair import ( TracePair, interior_trace_pairs, tracepair_with_discr_tag, ) -from grudge import op +from meshmode.discretization.connection import FACE_RESTR_ALL + from mirgecom.math import harmonic_mean from mirgecom.utils import normalize_boundaries +from pytools.obj_array import make_obj_array, obj_array_vectorize_n_args def grad_facial_flux_central(kappa_tpair, u_tpair, normal): @@ -324,7 +326,7 @@ def __init__(self, value): def get_grad_flux( self, dcoll, dd_bdry, kappa_minus, u_minus, *, - numerical_flux_func=grad_facial_flux_weighted): # noqa: D102 + numerical_flux_func=grad_facial_flux_weighted): actx = u_minus.array_context kappa_tpair = TracePair(dd_bdry, interior=kappa_minus, @@ -338,7 +340,7 @@ def get_grad_flux( def get_diffusion_flux( self, dcoll, dd_bdry, kappa_minus, u_minus, grad_u_minus, lengthscales_minus, *, penalty_amount=None, - numerical_flux_func=diffusion_facial_flux_harmonic): # noqa: D102 + numerical_flux_func=diffusion_facial_flux_harmonic): actx = u_minus.array_context kappa_tpair = TracePair(dd_bdry, interior=kappa_minus, @@ -397,7 +399,7 @@ def __init__(self, value): def get_grad_flux( self, dcoll, dd_bdry, kappa_minus, u_minus, *, - numerical_flux_func=grad_facial_flux_weighted): # noqa: D102 + numerical_flux_func=grad_facial_flux_weighted): actx = u_minus.array_context kappa_tpair = TracePair(dd_bdry, interior=kappa_minus, @@ -411,7 +413,7 @@ def get_grad_flux( def get_diffusion_flux( self, dcoll, dd_bdry, kappa_minus, u_minus, grad_u_minus, lengthscales_minus, *, penalty_amount=None, - numerical_flux_func=diffusion_facial_flux_harmonic): # noqa: D102 + numerical_flux_func=diffusion_facial_flux_harmonic): actx = u_minus.array_context kappa_tpair = TracePair(dd_bdry, interior=kappa_minus, @@ -484,7 +486,7 @@ def __init__(self, u_ref, alpha): def get_grad_flux( self, dcoll, dd_bdry, kappa_minus, u_minus, *, - numerical_flux_func=grad_facial_flux_weighted): # noqa: D102 + numerical_flux_func=grad_facial_flux_weighted): actx = u_minus.array_context kappa_tpair = TracePair(dd_bdry, interior=kappa_minus, @@ -498,7 +500,7 @@ def get_grad_flux( def get_diffusion_flux( self, dcoll, dd_bdry, kappa_minus, u_minus, grad_u_minus, lengthscales_minus, *, penalty_amount=None, - numerical_flux_func=diffusion_facial_flux_harmonic): # noqa: D102 + numerical_flux_func=diffusion_facial_flux_harmonic): actx = u_minus.array_context kappa_tpair = TracePair(dd_bdry, interior=kappa_minus, @@ -555,7 +557,7 @@ def __init__(self, value): self.value = value def get_grad_flux(self, dcoll, dd_bdry, kappa_minus, u_minus, *, - numerical_flux_func=grad_facial_flux_weighted): # noqa: D102 + numerical_flux_func=grad_facial_flux_weighted): actx = u_minus.array_context kappa_tpair = TracePair( dd_bdry, interior=kappa_minus, exterior=kappa_minus) @@ -567,7 +569,7 @@ def get_grad_flux(self, dcoll, dd_bdry, kappa_minus, u_minus, *, def get_diffusion_flux( self, dcoll, dd_bdry, kappa_minus, u_minus, grad_u_minus, lengthscales_minus, *, penalty_amount=None, - numerical_flux_func=diffusion_facial_flux_harmonic): # noqa: D102 + numerical_flux_func=diffusion_facial_flux_harmonic): actx = u_minus.array_context # returns the product "flux @ normal" @@ -578,7 +580,7 @@ class DummyDiffusionBoundary(DiffusionBoundary): """Dummy boundary condition that duplicates the internal values.""" def get_grad_flux(self, dcoll, dd_bdry, kappa_minus, u_minus, *, - numerical_flux_func): # noqa: D102 + numerical_flux_func): actx = u_minus.array_context kappa_tpair = TracePair(dd_bdry, interior=kappa_minus, @@ -592,7 +594,7 @@ def get_grad_flux(self, dcoll, dd_bdry, kappa_minus, u_minus, *, def get_diffusion_flux(self, dcoll, dd_bdry, kappa_minus, u_minus, grad_u_minus, lengthscales_minus, *, numerical_flux_func=diffusion_facial_flux_harmonic, - penalty_amount=None): # noqa: D102 + penalty_amount=None): actx = u_minus.array_context kappa_tpair = TracePair(dd_bdry, interior=kappa_minus, @@ -727,7 +729,7 @@ def boundary_flux(bdtag, bdry): return op.inverse_mass( dcoll, dd_vol, op.weak_local_grad(dcoll, dd_vol, -u) - - # noqa: W504 + - op.face_mass( dcoll, dd_allfaces_quad, sum( @@ -890,7 +892,7 @@ def boundary_flux(bdtag, bdry): diff_u = op.inverse_mass( dcoll, dd_vol, op.weak_local_div(dcoll, dd_vol_quad, -kappa_quad*grad_u_quad) - - # noqa: W504 + - op.face_mass( dcoll, dd_allfaces_quad, sum( diff --git a/mirgecom/discretization.py b/mirgecom/discretization.py index 2d4458678..3f2c1d10a 100644 --- a/mirgecom/discretization.py +++ b/mirgecom/discretization.py @@ -31,6 +31,7 @@ """ import logging + logger = logging.getLogger(__name__) @@ -53,12 +54,12 @@ def create_discretization_collection(actx, volume_meshes, order, *, "tensor_product_elements argument is not needed and will vanish soon.", DeprecationWarning, stacklevel=2) - from grudge.dof_desc import DISCR_TAG_BASE, DISCR_TAG_QUAD, DISCR_TAG_MODAL from grudge.discretization import make_discretization_collection + from grudge.dof_desc import DISCR_TAG_BASE, DISCR_TAG_MODAL, DISCR_TAG_QUAD from meshmode.discretization.poly_element import ( InterpolatoryEdgeClusteredGroupFactory, + ModalGroupFactory, QuadratureGroupFactory, - ModalGroupFactory ) if quadrature_order < 0: diff --git a/mirgecom/eos.py b/mirgecom/eos.py index 03e2ba81b..1eba3b600 100644 --- a/mirgecom/eos.py +++ b/mirgecom/eos.py @@ -42,14 +42,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -from typing import Union, Optional -from dataclasses import dataclass from abc import ABCMeta, abstractmethod -from arraycontext import dataclass_array_container +from dataclasses import dataclass +from typing import Optional, Union + import numpy as np from meshmode.dof_array import DOFArray + from mirgecom.fluid import ConservedVars, make_conserved +from arraycontext import dataclass_array_container + class TemperatureSeedMissingError(Exception): """Indicate that EOS is inappropriately called without seeding temperature.""" @@ -478,8 +481,8 @@ def temperature(self, cv: ConservedVars, Unused for this EOS. """ return ( - (((self._gamma - 1.0) / self._gas_const) - * self.internal_energy(cv) / cv.mass) + ((self._gamma - 1.0) / self._gas_const) + * self.internal_energy(cv) / cv.mass ) def total_energy(self, cv: ConservedVars, pressure: DOFArray, diff --git a/mirgecom/euler.py b/mirgecom/euler.py index c314a1260..d6c4f98b2 100644 --- a/mirgecom/euler.py +++ b/mirgecom/euler.py @@ -63,7 +63,7 @@ ) from mirgecom.gas_model import make_operator_fluid_states -from mirgecom.inviscid import ( # noqa +from mirgecom.inviscid import ( inviscid_flux, inviscid_facial_flux_rusanov, inviscid_flux_on_element_boundary, @@ -99,11 +99,11 @@ import grudge.op as op -class _ESFluidCVTag(): +class _ESFluidCVTag: pass -class _ESFluidTemperatureTag(): +class _ESFluidTemperatureTag: pass diff --git a/mirgecom/filter.py b/mirgecom/filter.py index 9a4aa5959..4ecc9634b 100644 --- a/mirgecom/filter.py +++ b/mirgecom/filter.py @@ -49,21 +49,20 @@ THE SOFTWARE. """ -import numpy as np from functools import partial +import numpy as np from grudge.dof_desc import ( DD_VOLUME_ALL, DISCR_TAG_BASE, DISCR_TAG_MODAL, ) - -from arraycontext import map_array_container - from meshmode.dof_array import DOFArray from pytools import keyed_memoize_in +from arraycontext import map_array_container + # TODO: Revisit for multi-group meshes def get_element_spectrum_from_modal_representation(actx, vol_discr, modal_fields, diff --git a/mirgecom/fluid.py b/mirgecom/fluid.py index 0019fb5d3..0594e1791 100644 --- a/mirgecom/fluid.py +++ b/mirgecom/fluid.py @@ -37,7 +37,7 @@ THE SOFTWARE. """ import numpy as np # noqa -from meshmode.dof_array import DOFArray # noqa +from meshmode.dof_array import DOFArray from dataclasses import dataclass, fields, field from arraycontext import ( dataclass_array_container, diff --git a/mirgecom/gas_model.py b/mirgecom/gas_model.py index 7730f00dc..b33f3f4bb 100644 --- a/mirgecom/gas_model.py +++ b/mirgecom/gas_model.py @@ -49,34 +49,31 @@ THE SOFTWARE. """ -from functools import partial from dataclasses import dataclass +from functools import partial from typing import Optional -import numpy as np # noqa -from arraycontext import dataclass_array_container + +import grudge.op as op +import numpy as np from grudge.dof_desc import ( DD_VOLUME_ALL, - VolumeDomainTag, DISCR_TAG_BASE, + VolumeDomainTag, ) -import grudge.op as op -from grudge.trace_pair import ( - interior_trace_pairs, - tracepair_with_discr_tag -) -from mirgecom.fluid import ConservedVars +from grudge.trace_pair import interior_trace_pairs, tracepair_with_discr_tag + from mirgecom.eos import ( - GasEOS, GasDependentVars, + GasEOS, MixtureDependentVars, - MixtureEOSNeededError -) -from mirgecom.transport import ( - TransportModel, - GasTransportVars + MixtureEOSNeededError, ) +from mirgecom.fluid import ConservedVars +from mirgecom.transport import GasTransportVars, TransportModel from mirgecom.utils import normalize_boundaries -from mirgecom.wall_model import PorousWallVars, PorousFlowModel +from mirgecom.wall_model import PorousFlowModel, PorousWallVars + +from arraycontext import dataclass_array_container @dataclass(frozen=True) diff --git a/mirgecom/initializers.py b/mirgecom/initializers.py index 3ec306252..8f47370cd 100644 --- a/mirgecom/initializers.py +++ b/mirgecom/initializers.py @@ -51,9 +51,10 @@ """ import numpy as np -from pytools.obj_array import make_obj_array + from mirgecom.eos import IdealSingleGas from mirgecom.fluid import make_conserved +from pytools.obj_array import make_obj_array def initialize_flow_solution(actx, coords, gas_model=None, eos=None, diff --git a/mirgecom/integrators/__init__.py b/mirgecom/integrators/__init__.py index 844fc9874..e5bdc6661 100644 --- a/mirgecom/integrators/__init__.py +++ b/mirgecom/integrators/__init__.py @@ -24,9 +24,10 @@ THE SOFTWARE. """ -from .explicit_rk import rk4_step # noqa: F401 -from .lsrk import euler_step, lsrk54_step, lsrk144_step # noqa: F401 -from .ssprk import ssprk43_step # noqa: F401 +from .explicit_rk import rk4_step # noqa: F401 +from .lsrk import euler_step, lsrk54_step, lsrk144_step # noqa: F401 +from .ssprk import ssprk43_step # noqa: F401 + __doc__ = """ .. automodule:: mirgecom.integrators.explicit_rk diff --git a/mirgecom/inviscid.py b/mirgecom/inviscid.py index f1c713a6d..03cf08bb0 100644 --- a/mirgecom/inviscid.py +++ b/mirgecom/inviscid.py @@ -43,22 +43,20 @@ THE SOFTWARE. """ +import grudge.op as op import numpy as np -from meshmode.discretization.connection import FACE_RESTR_ALL from grudge.dof_desc import ( DD_VOLUME_ALL, - VolumeDomainTag, DISCR_TAG_BASE, + VolumeDomainTag, ) -import grudge.op as op -from mirgecom.fluid import ( - make_conserved, - ConservedVars -) +from meshmode.discretization.connection import FACE_RESTR_ALL +from meshmode.dof_array import DOFArray + +from mirgecom.fluid import ConservedVars, make_conserved from mirgecom.utils import normalize_boundaries from arraycontext import outer -from meshmode.dof_array import DOFArray def inviscid_flux(state): @@ -443,7 +441,7 @@ def ln_mean(x: DOFArray, y: DOFArray, epsilon=1e-4): specific_kin_rr = 0.5 * np.dot(u_rr, u_rr) rho_avg = 0.5 * (rho_ll + rho_rr) - rho_mean = ln_mean(rho_ll, rho_rr) + rho_mean = ln_mean(rho_ll, rho_rr) y_mean = 0.5 * (y_ll + y_rr) rho_species_mean = rho_mean * y_mean @@ -525,7 +523,7 @@ def ln_mean(x: DOFArray, y: DOFArray, epsilon=1e-4): kin_comb = 0.5 * np.dot(u_ll, u_rr) - rho_mean = ln_mean(rho_ll, rho_rr) + rho_mean = ln_mean(rho_ll, rho_rr) y_avg = 0.5 * (y_ll + y_rr) species_mass_mean = rho_mean * y_avg diff --git a/mirgecom/io.py b/mirgecom/io.py index 628605361..b57495b5e 100644 --- a/mirgecom/io.py +++ b/mirgecom/io.py @@ -30,10 +30,10 @@ THE SOFTWARE. """ from functools import partial -import grudge.op as op -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +import grudge.op as op from grudge.dof_desc import DD_VOLUME_ALL +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa def make_init_message(*, dim, order, dt, t_final, diff --git a/mirgecom/limiter.py b/mirgecom/limiter.py index 4e99ad699..77b56e0ed 100644 --- a/mirgecom/limiter.py +++ b/mirgecom/limiter.py @@ -30,9 +30,8 @@ THE SOFTWARE. """ -from grudge.discretization import DiscretizationCollection import grudge.op as op - +from grudge.discretization import DiscretizationCollection from grudge.dof_desc import DD_VOLUME_ALL diff --git a/mirgecom/logging_quantities.py b/mirgecom/logging_quantities.py index 96ae05d82..7ee4442d5 100644 --- a/mirgecom/logging_quantities.py +++ b/mirgecom/logging_quantities.py @@ -40,20 +40,27 @@ .. autofunction:: logmgr_set_time """ -from logpyle import (LogQuantity, PostLogQuantity, LogManager, - MultiPostLogQuantity, add_run_info, - add_general_quantities, add_simulation_quantities) -from arraycontext.container import get_container_context_recursively -from meshmode.array_context import PyOpenCLArrayContext +from typing import Callable, List, Optional, Tuple, Union + +import grudge.op as oper +import numpy as np from grudge.discretization import DiscretizationCollection +from grudge.dof_desc import DD_VOLUME_ALL +from logpyle import ( + LogManager, + LogQuantity, + MultiPostLogQuantity, + PostLogQuantity, + add_general_quantities, + add_run_info, + add_simulation_quantities, +) +from meshmode.array_context import PyOpenCLArrayContext + import pyopencl as cl -from typing import Optional, Callable, Union, Tuple -import numpy as np +from arraycontext.container import get_container_context_recursively -from grudge.dof_desc import DD_VOLUME_ALL -import grudge.op as oper -from typing import List MemPoolType = Union[cl.tools.MemoryPool, cl.tools.SVMPool] @@ -102,7 +109,7 @@ def logmgr_add_cl_device_info(logmgr: LogManager, queue: cl.CommandQueue) -> Non logmgr.set_constant("cl_platform_version", dev.platform.version) -def logmgr_add_device_name(logmgr: LogManager, queue: cl.CommandQueue): # noqa: D401 +def logmgr_add_device_name(logmgr: LogManager, queue: cl.CommandQueue): """Deprecated. Do not use in new code.""" from warnings import warn warn("logmgr_add_device_name is deprecated and will disappear in Q3 2021. " @@ -176,6 +183,7 @@ def add_package_versions(mgr: LogManager, path_to_version_sh: Optional[str] = No # Find emirge's version.sh in any parent directory if path_to_version_sh is None: import pathlib + import mirgecom p = pathlib.Path(mirgecom.__file__).resolve() @@ -229,7 +237,7 @@ def set_sim_state(mgr: LogManager, dim, state, eos) -> None: def logmgr_set_time(mgr: LogManager, steps: int, time: float) -> None: """Set the (current/initial) time/step count explicitly (e.g., for restart).""" - from logpyle import TimestepCounter, SimulationTime + from logpyle import SimulationTime, TimestepCounter for gd_lst in [mgr.before_gather_descriptors, mgr.after_gather_descriptors]: @@ -350,9 +358,10 @@ def __init__(self, actx: PyOpenCLArrayContext, assert isinstance(actx, PyOpenCLProfilingArrayContext) from dataclasses import fields + from mirgecom.profiling import MultiCallKernelProfile - units_default = {"num_calls": "1", "time": "s", "flops": "GFlops", + units_default = {"num_calls": "1", "time": "s", "flops": "GFlops", "bytes_accessed": "GByte", "footprint_bytes": "GByte"} names = [f"{kernel_name}_{f.name}" for f in fields(MultiCallKernelProfile)] diff --git a/mirgecom/materials/carbon_fiber.py b/mirgecom/materials/carbon_fiber.py index d1e984cde..12c0d4358 100644 --- a/mirgecom/materials/carbon_fiber.py +++ b/mirgecom/materials/carbon_fiber.py @@ -29,10 +29,12 @@ THE SOFTWARE. """ -from typing import Optional from abc import abstractmethod +from typing import Optional + import numpy as np from meshmode.dof_array import DOFArray + from mirgecom.wall_model import PorousWallEOS from pytools.obj_array import make_obj_array diff --git a/mirgecom/materials/initializer.py b/mirgecom/materials/initializer.py index c39973180..b386aab1a 100644 --- a/mirgecom/materials/initializer.py +++ b/mirgecom/materials/initializer.py @@ -28,9 +28,9 @@ THE SOFTWARE. """ -from pytools.obj_array import make_obj_array from mirgecom.fluid import make_conserved from mirgecom.wall_model import SolidWallConservedVars +from pytools.obj_array import make_obj_array class SolidWallInitializer: diff --git a/mirgecom/materials/prescribed_porous_material.py b/mirgecom/materials/prescribed_porous_material.py index 9b7ced291..f6c77909e 100644 --- a/mirgecom/materials/prescribed_porous_material.py +++ b/mirgecom/materials/prescribed_porous_material.py @@ -30,7 +30,9 @@ """ from typing import Optional + from meshmode.dof_array import DOFArray + from mirgecom.wall_model import PorousWallEOS diff --git a/mirgecom/materials/tacot.py b/mirgecom/materials/tacot.py index b3baa6422..86b66b00e 100644 --- a/mirgecom/materials/tacot.py +++ b/mirgecom/materials/tacot.py @@ -34,8 +34,9 @@ import numpy as np from meshmode.dof_array import DOFArray -from pytools.obj_array import make_obj_array + from mirgecom.wall_model import PorousWallEOS +from pytools.obj_array import make_obj_array class Pyrolysis: diff --git a/mirgecom/math.py b/mirgecom/math.py index 6116f4f04..230a19b2c 100644 --- a/mirgecom/math.py +++ b/mirgecom/math.py @@ -51,10 +51,12 @@ """ import numpy as np -import numpy.linalg as la # noqa -from pytools.obj_array import make_obj_array +import numpy.linalg as la # noqa import pymbolic as pmbl from pymbolic.primitives import Expression + +from pytools.obj_array import make_obj_array + from arraycontext import ( get_container_context_recursively, get_container_context_recursively_opt, @@ -92,8 +94,9 @@ def scalar_harmonic_mean(a, b): a_plus_b = a + b if a + b > 0 else 1 return 2*a*b/a_plus_b - from arraycontext import rec_multimap_array_container from meshmode.dof_array import DOFArray + + from arraycontext import rec_multimap_array_container return rec_multimap_array_container( scalar_harmonic_mean, x, y, leaf_class=DOFArray) diff --git a/mirgecom/mechanisms/__init__.py b/mirgecom/mechanisms/__init__.py index 5752ea84d..958929373 100644 --- a/mirgecom/mechanisms/__init__.py +++ b/mirgecom/mechanisms/__init__.py @@ -31,6 +31,8 @@ THE SOFTWARE. """ import sys + + if sys.version_info < (3, 9): # importlib.resources either doesn't exist or lacks the files() # function, so use the PyPI version: diff --git a/mirgecom/mpi.py b/mirgecom/mpi.py index 4dbdf66a7..d56264f65 100644 --- a/mirgecom/mpi.py +++ b/mirgecom/mpi.py @@ -29,13 +29,13 @@ THE SOFTWARE. """ -from functools import wraps +import logging import sys - from contextlib import contextmanager -from typing import Callable, Any, Generator, TYPE_CHECKING +from functools import wraps +from typing import TYPE_CHECKING, Any, Callable, Generator + -import logging logger = logging.getLogger(__name__) @@ -66,6 +66,7 @@ def _check_isl_version() -> None: library to determine if we are running with imath-32. """ import ctypes + import islpy # type: ignore[import-untyped] try: @@ -161,8 +162,8 @@ def main(...) @wraps(func) def wrapped_func(*args: Any, **kwargs: Any) -> None: # pylint: disable=import-error - from pudb.remote import debug_remote_on_single_rank from mpi4py import MPI + from pudb.remote import debug_remote_on_single_rank debug_remote_on_single_rank(MPI.COMM_WORLD, 0, func, *args, **kwargs) return wrapped_func diff --git a/mirgecom/multiphysics/thermally_coupled_fluid_wall.py b/mirgecom/multiphysics/thermally_coupled_fluid_wall.py index 392ce95ad..0bf40544a 100644 --- a/mirgecom/multiphysics/thermally_coupled_fluid_wall.py +++ b/mirgecom/multiphysics/thermally_coupled_fluid_wall.py @@ -65,51 +65,50 @@ THE SOFTWARE. """ -from dataclasses import dataclass, replace -import numpy as np from abc import abstractmethod +from dataclasses import dataclass, replace from functools import partial -from arraycontext import dataclass_array_container -from meshmode.dof_array import DOFArray -from grudge.trace_pair import ( - TracePair, - inter_volume_trace_pairs -) +import grudge.op as op +import numpy as np from grudge.dof_desc import ( DISCR_TAG_BASE, as_dofdesc, ) -import grudge.op as op +from grudge.trace_pair import TracePair, inter_volume_trace_pairs +from meshmode.dof_array import DOFArray -from mirgecom.math import harmonic_mean from mirgecom.boundary import ( + IsothermalSlipWallBoundary, + IsothermalWallBoundary, MengaldoBoundaryCondition, - _SlipBoundaryComponent, - _NoSlipBoundaryComponent, _ImpermeableBoundaryComponent, - IsothermalSlipWallBoundary, - IsothermalWallBoundary) + _NoSlipBoundaryComponent, + _SlipBoundaryComponent, +) +from mirgecom.diffusion import ( + DiffusionBoundary, + diffusion_facial_flux_harmonic, + diffusion_flux, + diffusion_operator, + grad_facial_flux_weighted, + grad_operator as wall_grad_t_operator, +) from mirgecom.flux import num_flux_central -from mirgecom.viscous import viscous_facial_flux_harmonic from mirgecom.gas_model import ( - replace_fluid_state, make_operator_fluid_states, + replace_fluid_state, ) +from mirgecom.math import harmonic_mean +from mirgecom.multiphysics import make_interface_boundaries from mirgecom.navierstokes import ( grad_t_operator as fluid_grad_t_operator, ns_operator, ) -from mirgecom.diffusion import ( - grad_facial_flux_weighted, - diffusion_flux, - diffusion_facial_flux_harmonic, - DiffusionBoundary, - grad_operator as wall_grad_t_operator, - diffusion_operator, -) -from mirgecom.multiphysics import make_interface_boundaries from mirgecom.utils import project_from_base +from mirgecom.viscous import viscous_facial_flux_harmonic + +from arraycontext import dataclass_array_container class _ThermalDataNoGradInterVolTag: @@ -372,7 +371,7 @@ def __init__( self._impermeable = _ImpermeableBoundaryComponent() def state_plus( - self, dcoll, dd_bdry, gas_model, state_minus, **kwargs): # noqa: D102 + self, dcoll, dd_bdry, gas_model, state_minus, **kwargs): actx = state_minus.array_context # Grab a unit normal to the boundary @@ -385,7 +384,7 @@ def state_plus( return replace_fluid_state(state_minus, gas_model, momentum=mom_plus) def state_bc( - self, dcoll, dd_bdry, gas_model, state_minus, **kwargs): # noqa: D102 + self, dcoll, dd_bdry, gas_model, state_minus, **kwargs): actx = state_minus.array_context cv_minus = state_minus.cv @@ -422,7 +421,7 @@ def state_bc( def grad_cv_bc( self, dcoll, dd_bdry, gas_model, state_minus, grad_cv_minus, - normal, **kwargs): # noqa: D102 + normal, **kwargs): dd_bdry = as_dofdesc(dd_bdry) state_bc = self.state_bc( dcoll=dcoll, dd_bdry=dd_bdry, gas_model=gas_model, @@ -443,16 +442,16 @@ def grad_cv_bc( species_mass=grad_species_mass_bc) def temperature_plus( - self, dcoll, dd_bdry, state_minus, **kwargs): # noqa: D102 + self, dcoll, dd_bdry, state_minus, **kwargs): return self._thermally_coupled.temperature_plus(dcoll, dd_bdry) - def temperature_bc(self, dcoll, dd_bdry, state_minus, **kwargs): # noqa: D102 + def temperature_bc(self, dcoll, dd_bdry, state_minus, **kwargs): kappa_minus = state_minus.tv.thermal_conductivity return self._thermally_coupled.temperature_bc( dcoll, dd_bdry, kappa_minus, state_minus.temperature) def grad_temperature_bc( - self, dcoll, dd_bdry, grad_t_minus, normal, **kwargs): # noqa: D102 + self, dcoll, dd_bdry, grad_t_minus, normal, **kwargs): return self._thermally_coupled.grad_temperature_bc( dcoll, dd_bdry, grad_t_minus) @@ -515,7 +514,7 @@ def __init__( self._impermeable = _ImpermeableBoundaryComponent() def state_plus( - self, dcoll, dd_bdry, gas_model, state_minus, **kwargs): # noqa: D102 + self, dcoll, dd_bdry, gas_model, state_minus, **kwargs): dd_bdry = as_dofdesc(dd_bdry) mom_plus = self._no_slip.momentum_plus(state_minus.momentum_density) @@ -523,7 +522,7 @@ def state_plus( return replace_fluid_state(state_minus, gas_model, momentum=mom_plus) def state_bc( - self, dcoll, dd_bdry, gas_model, state_minus, **kwargs): # noqa: D102 + self, dcoll, dd_bdry, gas_model, state_minus, **kwargs): dd_bdry = as_dofdesc(dd_bdry) kappa_minus = state_minus.tv.thermal_conductivity @@ -551,23 +550,23 @@ def state_bc( def grad_cv_bc( self, dcoll, dd_bdry, gas_model, state_minus, grad_cv_minus, normal, - **kwargs): # noqa: D102 + **kwargs): grad_species_mass_bc = self._impermeable.grad_species_mass_bc( state_minus, grad_cv_minus, normal) return grad_cv_minus.replace(species_mass=grad_species_mass_bc) def temperature_plus( - self, dcoll, dd_bdry, state_minus, **kwargs): # noqa: D102 + self, dcoll, dd_bdry, state_minus, **kwargs): return self._thermally_coupled.temperature_plus(dcoll, dd_bdry) - def temperature_bc(self, dcoll, dd_bdry, state_minus, **kwargs): # noqa: D102 + def temperature_bc(self, dcoll, dd_bdry, state_minus, **kwargs): kappa_minus = state_minus.tv.thermal_conductivity return self._thermally_coupled.temperature_bc( dcoll, dd_bdry, kappa_minus, state_minus.temperature) def grad_temperature_bc( - self, dcoll, dd_bdry, grad_t_minus, normal, **kwargs): # noqa: D102 + self, dcoll, dd_bdry, grad_t_minus, normal, **kwargs): return self._thermally_coupled.grad_temperature_bc( dcoll, dd_bdry, grad_t_minus) @@ -610,7 +609,7 @@ def __init__(self, kappa_plus, u_plus, grad_u_plus=None): def get_grad_flux( self, dcoll, dd_bdry, kappa_minus, u_minus, *, - numerical_flux_func=grad_facial_flux_weighted): # noqa: D102 + numerical_flux_func=grad_facial_flux_weighted): actx = u_minus.array_context normal = actx.thaw(dcoll.normal(dd_bdry)) @@ -627,7 +626,7 @@ def get_grad_flux( def get_diffusion_flux( self, dcoll, dd_bdry, kappa_minus, u_minus, grad_u_minus, lengthscales_minus, *, penalty_amount=None, - numerical_flux_func=diffusion_facial_flux_harmonic): # noqa: D102 + numerical_flux_func=diffusion_facial_flux_harmonic): if self.grad_u_plus is None: raise TypeError( "Boundary does not have external gradient data.") @@ -714,7 +713,7 @@ def __init__( def get_grad_flux( self, dcoll, dd_bdry, kappa_minus, u_minus, *, - numerical_flux_func=grad_facial_flux_weighted): # noqa: D102 + numerical_flux_func=grad_facial_flux_weighted): actx = u_minus.array_context normal = actx.thaw(dcoll.normal(dd_bdry)) @@ -727,7 +726,7 @@ def get_grad_flux( def get_diffusion_flux( self, dcoll, dd_bdry, kappa_minus, u_minus, grad_u_minus, lengthscales_minus, *, penalty_amount=None, - numerical_flux_func=diffusion_facial_flux_harmonic): # noqa: D102 + numerical_flux_func=diffusion_facial_flux_harmonic): if self.grad_u_plus is None: raise TypeError("External temperature gradient is not specified.") if self.emissivity is None: diff --git a/mirgecom/navierstokes.py b/mirgecom/navierstokes.py index 3d7f26ec3..9daae32a8 100644 --- a/mirgecom/navierstokes.py +++ b/mirgecom/navierstokes.py @@ -60,42 +60,30 @@ from functools import partial from warnings import warn -from meshmode.discretization.connection import FACE_RESTR_ALL - -from grudge.trace_pair import ( - TracePair, - interior_trace_pairs, - tracepair_with_discr_tag -) +import grudge.op as op from grudge.dof_desc import ( DD_VOLUME_ALL, - VolumeDomainTag, DISCR_TAG_BASE, + VolumeDomainTag, ) +from grudge.trace_pair import TracePair, interior_trace_pairs, tracepair_with_discr_tag +from meshmode.discretization.connection import FACE_RESTR_ALL -import grudge.op as op - -from mirgecom.euler import ( - euler_operator, - entropy_stable_euler_operator -) +from mirgecom.euler import entropy_stable_euler_operator, euler_operator +from mirgecom.flux import num_flux_central +from mirgecom.gas_model import make_operator_fluid_states from mirgecom.inviscid import ( - inviscid_flux, inviscid_facial_flux_rusanov, + inviscid_flux, inviscid_flux_on_element_boundary, ) +from mirgecom.operators import div_operator, grad_operator +from mirgecom.utils import normalize_boundaries from mirgecom.viscous import ( - viscous_flux, viscous_facial_flux_central, - viscous_flux_on_element_boundary -) -from mirgecom.flux import num_flux_central - -from mirgecom.operators import ( - div_operator, grad_operator + viscous_flux, + viscous_flux_on_element_boundary, ) -from mirgecom.gas_model import make_operator_fluid_states -from mirgecom.utils import normalize_boundaries class _NSGradCVTag: @@ -106,11 +94,11 @@ class _NSGradTemperatureTag: pass -class _ESFluidCVTag(): +class _ESFluidCVTag: pass -class _ESFluidTemperatureTag(): +class _ESFluidTemperatureTag: pass diff --git a/mirgecom/operators.py b/mirgecom/operators.py index 3984f1656..979af5e7a 100644 --- a/mirgecom/operators.py +++ b/mirgecom/operators.py @@ -29,7 +29,6 @@ """ import grudge.op as op - from grudge.dof_desc import DISCR_TAG_BASE diff --git a/mirgecom/profiling.py b/mirgecom/profiling.py index 9bde1284c..3bf80cb50 100644 --- a/mirgecom/profiling.py +++ b/mirgecom/profiling.py @@ -24,18 +24,20 @@ THE SOFTWARE. """ +from dataclasses import dataclass +from typing import Dict, List, Optional + +import numpy as np +from logpyle import LogManager from meshmode.array_context import PyOpenCLArrayContext -import pyopencl as cl -from pytools.py_codegen import PythonFunctionGenerator + import loopy as lp -import numpy as np -from dataclasses import dataclass +import pyopencl as cl import pytools -from logpyle import LogManager from mirgecom.logging_quantities import KernelProfile from mirgecom.utils import StatisticsAccumulator +from pytools.py_codegen import PythonFunctionGenerator -from typing import List, Dict, Optional __doc__ = """ .. autoclass:: PyOpenCLProfilingArrayContext @@ -344,7 +346,7 @@ def _cache_kernel_stats(self, t_unit: lp.TranslationUnit, kwargs: dict) \ param_names = kernel.all_params() gen("return {%s}" % ", ".join( - f"{repr(name)}: {name}" for name in param_names)) + f"{name!r}: {name}" for name in param_names)) # Run the wrapper code, save argument values in domain_params domain_params = gen.get_picklable_function()(**param_dict) diff --git a/mirgecom/restart.py b/mirgecom/restart.py index d5b95bdc2..35d5206c1 100644 --- a/mirgecom/restart.py +++ b/mirgecom/restart.py @@ -29,6 +29,7 @@ """ import pickle + from meshmode.dof_array import array_context_for_pickling diff --git a/mirgecom/simutil.py b/mirgecom/simutil.py index c4285e262..467532c94 100644 --- a/mirgecom/simutil.py +++ b/mirgecom/simutil.py @@ -73,24 +73,25 @@ import logging from functools import partial from typing import Dict, List, Optional -from logpyle import IntervalTimer import grudge.op as op import numpy as np -import pyopencl as cl -from arraycontext import tag_axes -from meshmode.transform_metadata import ( - DiscretizationElementAxisTag, - DiscretizationDOFAxisTag -) -from arraycontext import flatten, map_array_container from grudge.discretization import DiscretizationCollection, PartID from grudge.dof_desc import DD_VOLUME_ALL +from logpyle import IntervalTimer from meshmode.dof_array import DOFArray +from meshmode.transform_metadata import ( + DiscretizationDOFAxisTag, + DiscretizationElementAxisTag, +) +import pyopencl as cl from mirgecom.utils import normalize_boundaries from mirgecom.viscous import get_viscous_timestep +from arraycontext import flatten, map_array_container, tag_axes + + logger = logging.getLogger(__name__) @@ -1010,8 +1011,7 @@ def get_rank_to_mesh_data(): part_id_to_part_index = { part_id: part_index for part_index, part_id in enumerate(part_id_to_elements.keys())} - from meshmode.mesh.processing import \ - _compute_global_elem_to_part_elem + from meshmode.mesh.processing import _compute_global_elem_to_part_elem global_elem_to_part_elem = _compute_global_elem_to_part_elem( mesh.nelements, part_id_to_elements, part_id_to_part_index, mesh.element_id_dtype) diff --git a/mirgecom/steppers.py b/mirgecom/steppers.py index 57f302309..7adf92006 100644 --- a/mirgecom/steppers.py +++ b/mirgecom/steppers.py @@ -29,8 +29,10 @@ """ import numpy as np + from mirgecom.utils import force_evaluation from pytools import memoize_in + from arraycontext import get_container_context_recursively_opt @@ -61,7 +63,7 @@ def get_rhs(): def _is_unevaluated(actx, ary): """Check if an array contains an unevaluated :module:`pytato` expression.""" - from arraycontext import serialize_container, NotAnArrayContainerError + from arraycontext import NotAnArrayContainerError, serialize_container try: iterable = serialize_container(ary) for _, subary in iterable: diff --git a/mirgecom/symbolic_fluid.py b/mirgecom/symbolic_fluid.py index 064a2c76e..c2d0b2ab9 100644 --- a/mirgecom/symbolic_fluid.py +++ b/mirgecom/symbolic_fluid.py @@ -16,13 +16,11 @@ """ import numpy as np import numpy.random - from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa + from mirgecom.fluid import make_conserved +from mirgecom.symbolic import div as sym_div, grad as sym_grad -from mirgecom.symbolic import ( - grad as sym_grad, - div as sym_div) # from mirgecom.eos import IdealSingleGas # from mirgecom.transport import SimpleTransport diff --git a/mirgecom/transport.py b/mirgecom/transport.py index 8d7a7137b..fa3031df8 100644 --- a/mirgecom/transport.py +++ b/mirgecom/transport.py @@ -47,14 +47,17 @@ THE SOFTWARE. """ -from typing import Optional from dataclasses import dataclass -from arraycontext import dataclass_array_container +from typing import Optional + import numpy as np -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa from meshmode.dof_array import DOFArray +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa + +from mirgecom.eos import GasDependentVars, GasEOS from mirgecom.fluid import ConservedVars -from mirgecom.eos import GasEOS, GasDependentVars + +from arraycontext import dataclass_array_container class TransportModelError(Exception): diff --git a/mirgecom/utils.py b/mirgecom/utils.py index ac46dcc73..531b71ad4 100644 --- a/mirgecom/utils.py +++ b/mirgecom/utils.py @@ -34,11 +34,14 @@ """ from typing import Optional -from arraycontext import tag_axes + from meshmode.dof_array import DOFArray from meshmode.transform_metadata import ( + DiscretizationDOFAxisTag, DiscretizationElementAxisTag, - DiscretizationDOFAxisTag) +) + +from arraycontext import tag_axes def asdict_shallow(dc_instance) -> dict: diff --git a/mirgecom/viscous.py b/mirgecom/viscous.py index 7a4a5bdb3..33a0b0905 100644 --- a/mirgecom/viscous.py +++ b/mirgecom/viscous.py @@ -44,27 +44,26 @@ THE SOFTWARE. """ +import grudge.op as op import numpy as np -from arraycontext import outer -from grudge.trace_pair import TracePair -from meshmode.dof_array import DOFArray -from meshmode.discretization.connection import FACE_RESTR_ALL from grudge.dof_desc import ( DD_VOLUME_ALL, - VolumeDomainTag, DISCR_TAG_BASE, + VolumeDomainTag, ) - -import grudge.op as op +from grudge.trace_pair import TracePair +from meshmode.discretization.connection import FACE_RESTR_ALL +from meshmode.dof_array import DOFArray from mirgecom.fluid import ( - velocity_gradient, + make_conserved, species_mass_fraction_gradient, - make_conserved + velocity_gradient, ) - from mirgecom.utils import normalize_boundaries +from arraycontext import outer + # low level routine works with numpy arrays and can be tested without # a full grid + fluid state, etc @@ -523,7 +522,7 @@ def _fvisc_divergence_flux_boundary(bdtag, boundary, state_minus_quad): bnd_term = ( # All surface contributions from the viscous fluxes - ( + # Domain boundary contributions for the viscous terms sum(_fvisc_divergence_flux_boundary( bdtag, @@ -537,7 +536,7 @@ def _fvisc_divergence_flux_boundary(bdtag, boundary, state_minus_quad): for q_p, dq_p, dt_p in zip(interior_state_pairs, interior_grad_cv_pairs, interior_grad_t_pairs)) - ) + ) return bnd_term diff --git a/mirgecom/wall_model.py b/mirgecom/wall_model.py index 7011ad3ca..f10d3d57f 100644 --- a/mirgecom/wall_model.py +++ b/mirgecom/wall_model.py @@ -68,23 +68,22 @@ """ -from dataclasses import dataclass from abc import abstractmethod -from typing import Union, Optional +from dataclasses import dataclass +from typing import Optional, Union + import numpy as np from meshmode.dof_array import DOFArray + +from mirgecom.eos import GasDependentVars, GasEOS, MixtureEOS +from mirgecom.fluid import ConservedVars +from mirgecom.transport import GasTransportVars, TransportModel + from arraycontext import ( dataclass_array_container, + get_container_context_recursively, with_container_arithmetic, - get_container_context_recursively ) -from mirgecom.fluid import ConservedVars -from mirgecom.eos import ( - GasEOS, - MixtureEOS, - GasDependentVars -) -from mirgecom.transport import GasTransportVars, TransportModel @with_container_arithmetic(bcast_obj_array=False, diff --git a/mirgecom/wave.py b/mirgecom/wave.py index a41d0cb29..86c6b91c3 100644 --- a/mirgecom/wave.py +++ b/mirgecom/wave.py @@ -27,12 +27,13 @@ THE SOFTWARE. """ +import grudge.op as op import numpy as np import numpy.linalg as la # noqa -from pytools.obj_array import flat_obj_array -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa from grudge.trace_pair import TracePair, interior_trace_pairs -import grudge.op as op +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa + +from pytools.obj_array import flat_obj_array def _flux(dcoll, c, w_tpair): @@ -93,7 +94,7 @@ def wave_operator(dcoll, c, w, *, comm_tag=None): -c*op.weak_local_div(dcoll, v), -c*op.weak_local_grad(dcoll, u) ) - + # noqa: W504 + + op.face_mass(dcoll, _flux(dcoll, c=c, w_tpair=TracePair(BTAG_ALL, interior=dir_bval, diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..37727dabe --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,65 @@ +[tool.ruff] +target-version = "py38" +preview = true + +[tool.ruff.lint] +extend-select = [ + "B", # flake8-bugbear + "C", # flake8-comprehensions + "E", # pycodestyle + "F", # pyflakes + "G", # flake8-logging-format + "I", # flake8-isort + "N", # pep8-naming + "NPY", # numpy + "Q", # flake8-quotes + "UP", # pyupgrade + "RUF", # ruff + "W", # pycodestyle +] +extend-ignore = [ + "C90", # McCabe complexity + "E221", # multiple spaces before operator + "E226", # missing whitespace around arithmetic operator + "E402", # module-level import not at top of file + "UP006", # updated annotations due to __future__ import + "UP007", # updated annotations due to __future__ import +] + +[tool.ruff.lint.flake8-quotes] +docstring-quotes = "double" +inline-quotes = "double" +multiline-quotes = "double" + +[tool.ruff.lint.isort] +combine-as-imports = true +known-local-folder = [ + "arraycontext", +] +known-first-party = [ + "pytools", + "pyopencl", + "pytato", + "loopy", +] +lines-after-imports = 2 + +[tool.mypy] +python_version = "3.8" +warn_unused_ignores = true +# TODO: enable this +# check_untyped_defs = true + +[[tool.mypy.overrides]] + +module = [ + "islpy", + "loopy.*", + "meshmode.*", + "pymbolic", + "pymbolic.*", + "pyopencl.*", + "jax.*", +] + +ignore_missing_imports = true diff --git a/setup.py b/setup.py index 99dda9b64..564b71fd4 100644 --- a/setup.py +++ b/setup.py @@ -1,20 +1,19 @@ # !/usr/bin/env python -# -*- coding: utf-8 -*- def main(): - from setuptools import setup, find_packages + from setuptools import find_packages, setup version_dict = {} init_filename = "mirgecom/version.py" exec( - compile(open(init_filename, "r").read(), init_filename, "exec"), + compile(open(init_filename).read(), init_filename, "exec"), version_dict) setup(name="mirgecom", version=version_dict["VERSION_TEXT"], description=("TBD"), - long_description=open("README.md", "rt").read(), + long_description=open("README.md").read(), author="CEESD", author_email="inform@tiker.net", license="MIT", diff --git a/test/test_av.py b/test/test_av.py index 5503ebd7c..dc16840b1 100644 --- a/test/test_av.py +++ b/test/test_av.py @@ -26,37 +26,35 @@ """ import logging + +import grudge.op as op import numpy as np -import pyopencl as cl import pytest -from meshmode.array_context import ( # noqa +from meshmode.array_context import ( PyOpenCLArrayContext, - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, ) -from meshmode.mesh import BTAG_ALL from meshmode.discretization.connection import FACE_RESTR_ALL -import grudge.op as op +from meshmode.mesh import BTAG_ALL + +import pyopencl as cl from mirgecom.artificial_viscosity import ( + AdiabaticNoSlipWallAV, + PrescribedFluidBoundaryAV, av_laplacian_operator, smoothness_indicator, - AdiabaticNoSlipWallAV, - PrescribedFluidBoundaryAV -) -from mirgecom.fluid import make_conserved -from mirgecom.gas_model import ( - GasModel, - make_fluid_state ) -from mirgecom.eos import IdealSingleGas - from mirgecom.discretization import create_discretization_collection +from mirgecom.eos import IdealSingleGas +from mirgecom.fluid import make_conserved +from mirgecom.gas_model import GasModel, make_fluid_state +from mirgecom.simutil import get_box_mesh from pyopencl.tools import ( # noqa pytest_generate_tests_for_pyopencl as pytest_generate_tests, ) -from mirgecom.simutil import get_box_mesh from pytools.obj_array import make_obj_array + logger = logging.getLogger(__name__) @@ -69,8 +67,8 @@ # Tracking the replacement endeavor: # https://github.com/illinois-ceesd/mirgecom/issues/684 -@pytest.mark.parametrize("dim", [1, 2, 3]) -@pytest.mark.parametrize("order", [1, 5]) +@pytest.mark.parametrize("dim", [1, 2, 3]) +@pytest.mark.parametrize("order", [1, 5]) def test_tag_cells(ctx_factory, dim, order): """Test tag_cells. @@ -96,7 +94,7 @@ def norm_indicator(expected, dcoll, soln, **kwargs): from meshmode.mesh.generation import generate_regular_rect_mesh mesh = generate_regular_rect_mesh( - a=(-1.0, )*dim, b=(1.0, )*dim, n=(nel_1d, ) * dim + a=(-1.0, )*dim, b=(1.0, )*dim, n=(nel_1d, ) * dim ) dcoll = create_discretization_collection(actx, mesh, order=order) @@ -107,7 +105,7 @@ def norm_indicator(expected, dcoll, soln, **kwargs): # Test jump discontinuity soln = actx.np.where(nodes[0] > 0.0+zeros, 1.0+zeros, zeros) err = norm_indicator(1.0, dcoll, soln) - assert err < tolerance, "Jump discontinuity should trigger indicator (1.0)" + assert err < tolerance, "Jump discontinuity should trigger indicator (1.0)" # get meshmode polynomials group = dcoll.discr_from_dd("vol").groups[0] @@ -125,7 +123,7 @@ def norm_indicator(expected, dcoll, soln, **kwargs): else: expected = 0.0 err = norm_indicator(expected, dcoll, soln) - assert err < tolerance, "Only highest modes should trigger indicator (1.0)" + assert err < tolerance, "Only highest modes should trigger indicator (1.0)" # Test s0 s0 = -1. @@ -135,8 +133,8 @@ def norm_indicator(expected, dcoll, soln, **kwargs): phi_n_pm1 = np.sqrt(1. - np.power(10, s0)) # pick a polynomial of order n_p, n_p-1 - n_p = np.array(np.nonzero((np.sum(modes, axis=1) == order))).flat[0] - n_pm1 = np.array(np.nonzero((np.sum(modes, axis=1) == order-1))).flat[0] + n_p = np.array(np.nonzero(np.sum(modes, axis=1) == order)).flat[0] + n_pm1 = np.array(np.nonzero(np.sum(modes, axis=1) == order-1)).flat[0] # create test soln perturbed around # Solution above s0 @@ -144,7 +142,7 @@ def norm_indicator(expected, dcoll, soln, **kwargs): + phi_n_pm1*basis[n_pm1](unit_nodes)) soln[0].set(np.tile(ele_soln, (nele, 1))) err = norm_indicator(1.0, dcoll, soln, s0=s0, kappa=0.0) - assert err < tolerance, ( + assert err < tolerance, ( "A function with an indicator >s0 should trigger indicator") # Solution below s0 @@ -163,15 +161,15 @@ def norm_indicator(expected, dcoll, soln, **kwargs): + phi_n_pm1*basis[n_pm1](unit_nodes)) soln[0].set(np.tile(ele_soln, (nele, 1))) err = norm_indicator(0.5, dcoll, soln, s0=s0, kappa=kappa) - assert err < 1.0e-10, "A function with s_e=s_0 should return 0.5" + assert err < 1.0e-10, "A function with s_e=s_0 should return 0.5" # test bounds # lower bound shift = 1.0e-5 err = norm_indicator(0.0, dcoll, soln, s0=s0+kappa+shift, kappa=kappa) - assert err < tolerance, "s_e tolerance, "s_e>s_0-kappa should trigger indicator" + assert err > tolerance, "s_e>s_0-kappa should trigger indicator" # upper bound err = norm_indicator(1.0, dcoll, soln, s0=s0-(kappa+shift), kappa=kappa) @@ -182,8 +180,8 @@ def norm_indicator(expected, dcoll, soln, **kwargs): assert err > tolerance -@pytest.mark.parametrize("dim", [1, 2, 3]) -@pytest.mark.parametrize("order", [2, 3]) +@pytest.mark.parametrize("dim", [1, 2, 3]) +@pytest.mark.parametrize("order", [2, 3]) def test_artificial_viscosity(ctx_factory, dim, order): """Test artificial_viscosity. @@ -216,6 +214,7 @@ def cv_gradient_flux(self, dcoll, dd_bdry, state_minus, gas_model, **kwargs): exterior=cv_int) nhat = actx.thaw(dcoll.normal(dd_bdry)) from mirgecom.flux import num_flux_central + from arraycontext import outer # Do not project to "all_faces" as now we use built-in grad_cv_operator return outer(num_flux_central(bnd_pair.int, bnd_pair.ext), nhat) @@ -271,8 +270,8 @@ def av_flux(self, dcoll, dd_bdry, diffusion, **kwargs): assert err < tolerance -@pytest.mark.parametrize("order", [2, 3]) -@pytest.mark.parametrize("dim", [1, 2]) +@pytest.mark.parametrize("order", [2, 3]) +@pytest.mark.parametrize("dim", [1, 2]) def test_trig(ctx_factory, dim, order): """Test artificial_viscosity. diff --git a/test/test_bc.py b/test/test_bc.py index f34f17767..9411b1b18 100644 --- a/test/test_bc.py +++ b/test/test_bc.py @@ -24,37 +24,34 @@ THE SOFTWARE. """ +import logging + +import grudge.op as op import numpy as np import numpy.linalg as la # noqa -import logging import pytest -from pytools.obj_array import make_obj_array - -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from grudge.dof_desc import as_dofdesc +from grudge.trace_pair import TracePair, interior_trace_pair, interior_trace_pairs +from meshmode.array_context import ( # noqa + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, +) from meshmode.discretization.connection import FACE_RESTR_ALL -from mirgecom.initializers import Lump +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa + +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas -from grudge.trace_pair import interior_trace_pair, interior_trace_pairs -from grudge.trace_pair import TracePair -from grudge.dof_desc import as_dofdesc from mirgecom.fluid import make_conserved -from mirgecom.discretization import create_discretization_collection -from mirgecom.inviscid import ( - inviscid_facial_flux_rusanov, - inviscid_facial_flux_hll -) from mirgecom.gas_model import ( GasModel, make_fluid_state, + make_fluid_state_trace_pairs, project_fluid_state, - make_fluid_state_trace_pairs ) -import grudge.op as op +from mirgecom.initializers import Lump +from mirgecom.inviscid import inviscid_facial_flux_hll, inviscid_facial_flux_rusanov from mirgecom.simutil import get_box_mesh +from pytools.obj_array import make_obj_array -from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) logger = logging.getLogger(__name__) @@ -322,8 +319,8 @@ def test_outflow_boundary(actx_factory, dim, flux_func): eos = IdealSingleGas(gas_const=gas_const) - from mirgecom.transport import SimpleTransport from mirgecom.initializers import Uniform + from mirgecom.transport import SimpleTransport gas_model = GasModel(eos=eos, transport=SimpleTransport(viscosity=sigma, @@ -437,8 +434,8 @@ def test_isothermal_wall_boundary(actx_factory, dim, flux_func): sigma = 5.0 exp_temp_bc_val = wall_temp - from mirgecom.transport import SimpleTransport from mirgecom.boundary import IsothermalWallBoundary + from mirgecom.transport import SimpleTransport gas_model = GasModel(eos=IdealSingleGas(gas_const=1.0), transport=SimpleTransport(viscosity=sigma, @@ -603,8 +600,8 @@ def test_adiabatic_noslip_wall_boundary(actx_factory, dim, flux_func): kappa = 3.0 sigma = 5.0 - from mirgecom.transport import SimpleTransport from mirgecom.boundary import AdiabaticNoslipWallBoundary + from mirgecom.transport import SimpleTransport gas_model = GasModel(eos=IdealSingleGas(gas_const=4.0), transport=SimpleTransport(viscosity=sigma, @@ -784,8 +781,8 @@ def test_symmetry_wall_boundary(actx_factory, dim, flux_func): kappa = 3.0 sigma = 5.0 - from mirgecom.transport import SimpleTransport from mirgecom.boundary import AdiabaticSlipBoundary + from mirgecom.transport import SimpleTransport gas_const = 4.0 gas_model = GasModel(eos=IdealSingleGas(gas_const=gas_const), diff --git a/test/test_chemistry.py b/test/test_chemistry.py index 5c8862a7f..1ccef6613 100644 --- a/test/test_chemistry.py +++ b/test/test_chemistry.py @@ -24,28 +24,26 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ +import cantera import numpy as np -import pyopencl as cl import pytest -import cantera -from pytools.obj_array import make_obj_array - from grudge import op - -from meshmode.array_context import PyOpenCLArrayContext -from meshmode.mesh.generation import generate_regular_rect_mesh from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) + PyOpenCLArrayContext, + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, +) +from meshmode.mesh.generation import generate_regular_rect_mesh -from mirgecom.fluid import make_conserved -from mirgecom.eos import PyrometheusMixture +import pyopencl as cl from mirgecom.discretization import create_discretization_collection +from mirgecom.eos import PyrometheusMixture +from mirgecom.fluid import make_conserved from mirgecom.mechanisms import get_mechanism_input from mirgecom.thermochemistry import ( + get_pyrometheus_wrapper_class, get_pyrometheus_wrapper_class_from_cantera, - get_pyrometheus_wrapper_class ) +from pytools.obj_array import make_obj_array @pytest.mark.parametrize(("mechname", "fuel", "rate_tol"), @@ -211,7 +209,7 @@ def get_mixture_entropy_mole(pressure, temperature, mass_fractions): # see CHEMKIN manual for more details mmw = pyro_obj.get_mix_molecular_weight(yin) _x = pyro_obj.get_mole_fractions(mmw, yin) - mole_fracs = actx.np.where(actx.np.less(_x, 1e-15), 1e-15, _x) # noqa + mole_fracs = actx.np.where(actx.np.less(_x, 1e-15), 1e-15, _x) delta_s = nu.T@(pyro_obj.get_species_entropies_r(pin, tin) - actx.np.log(mole_fracs)) # exclude meaningless check on entropy for irreversible reaction @@ -348,7 +346,7 @@ def inf_norm(x): omega_mc = eos.get_production_rates(cv, temp) omega_ct = cantera_soln.net_production_rates for i in range(cantera_soln.n_species): - assert inf_norm((omega_mc[i] - omega_ct[i])) < rate_tol + assert inf_norm(omega_mc[i] - omega_ct[i]) < rate_tol # check that the reactions progress far enough and are stable assert reactor.T > 1800.0 diff --git a/test/test_diffusion.py b/test/test_diffusion.py index 08e4d7e10..4da43592b 100644 --- a/test/test_diffusion.py +++ b/test/test_diffusion.py @@ -22,36 +22,41 @@ THE SOFTWARE. """ -from abc import ABCMeta, abstractmethod import logging +from abc import ABCMeta, abstractmethod + import numpy as np import pymbolic as pmbl -import mirgecom.math as mm import pytest -from pytools.obj_array import make_obj_array from grudge import op -from grudge.dof_desc import BoundaryDomainTag, DISCR_TAG_BASE, DISCR_TAG_QUAD +from grudge.dof_desc import DISCR_TAG_BASE, DISCR_TAG_QUAD, BoundaryDomainTag from grudge.shortcuts import make_visualizer -from meshmode.dof_array import DOFArray from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) -from mirgecom.symbolic import ( - diff as sym_diff, - grad as sym_grad, - div as sym_div, - evaluate) + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, +) +from meshmode.dof_array import DOFArray + +import mirgecom.math as mm from mirgecom.diffusion import ( + DirichletDiffusionBoundary, + NeumannDiffusionBoundary, + PrescribedFluxDiffusionBoundary, + RobinDiffusionBoundary, diffusion_flux, diffusion_operator, grad_facial_flux_weighted, - PrescribedFluxDiffusionBoundary, - DirichletDiffusionBoundary, - NeumannDiffusionBoundary, - RobinDiffusionBoundary) +) +from mirgecom.discretization import create_discretization_collection from mirgecom.integrators import rk4_step from mirgecom.simutil import get_box_mesh -from mirgecom.discretization import create_discretization_collection +from mirgecom.symbolic import ( + diff as sym_diff, + div as sym_div, + evaluate, + grad as sym_grad, +) +from pytools.obj_array import make_obj_array + logger = logging.getLogger(__name__) @@ -443,8 +448,7 @@ def get_rhs(t, u): if visualize: vis = make_visualizer(dcoll, order+3) - vis.write_vtk_file("diffusion_accuracy_{dim}_{order}_{n}.vtu".format( - dim=p.dim, order=order, n=n), [ + vis.write_vtk_file(f"diffusion_accuracy_{p.dim}_{order}_{n}.vtu", [ ("u", u), ("x", nodes[0] if p.dim == 1 else None), ("expected_u", expected_u) @@ -500,8 +504,8 @@ def test_diffusion_discontinuous_kappa(actx_factory, order, visualize=False): flux = -kappa_lower*kappa_upper/(kappa_lower + kappa_upper) u_steady = ( - -flux/kappa_lower * (nodes[0] + 1) * lower_mask # noqa: E126, E221 - + (1 - flux/kappa_upper * (nodes[0] - 1)) * upper_mask) # noqa: E131 + -flux/kappa_lower * (nodes[0] + 1) * lower_mask + + (1 - flux/kappa_upper * (nodes[0] - 1)) * upper_mask) def get_rhs(t, u, return_grad_u=False): return diffusion_operator( @@ -514,8 +518,8 @@ def get_rhs(t, u, return_grad_u=False): if visualize: vis = make_visualizer(dcoll, order+3) - vis.write_vtk_file("diffusion_discontinuous_kappa_rhs_{order}.vtu" - .format(order=order), [ + vis.write_vtk_file(f"diffusion_discontinuous_kappa_rhs_{order}.vtu" + , [ ("kappa", kappa), ("u_steady", u_steady), ("grad_u_steady", grad_u_steady), @@ -548,8 +552,8 @@ def get_rhs(t, u, return_grad_u=False): t += dt if visualize: - vis.write_vtk_file("diffusion_disc_kappa_stability_{order}.vtu" - .format(order=order), [ + vis.write_vtk_file(f"diffusion_disc_kappa_stability_{order}.vtu" + , [ ("kappa", kappa), ("u", u), ("u_steady", u_steady), diff --git a/test/test_eos.py b/test/test_eos.py index d3d48092d..5ce5b00c1 100644 --- a/test/test_eos.py +++ b/test/test_eos.py @@ -25,30 +25,28 @@ THE SOFTWARE. """ import logging + +import cantera import numpy as np -import pyopencl as cl import pytest -import cantera -from pytools.obj_array import make_obj_array - from grudge import op - -from meshmode.array_context import ( # noqa +from meshmode.array_context import ( # noqa # noqa PyOpenCLArrayContext, - PytatoPyOpenCLArrayContext + PytatoPyOpenCLArrayContext, + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, ) from meshmode.mesh.generation import generate_regular_rect_mesh -from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) -from mirgecom.fluid import make_conserved +import pyopencl as cl +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas, PyrometheusMixture +from mirgecom.fluid import make_conserved from mirgecom.gas_model import GasModel, make_fluid_state -from mirgecom.initializers import Vortex2D, Lump, Uniform -from mirgecom.discretization import create_discretization_collection +from mirgecom.initializers import Lump, Uniform, Vortex2D from mirgecom.mechanisms import get_mechanism_input from mirgecom.thermochemistry import get_pyrometheus_wrapper_class_from_cantera +from pytools.obj_array import make_obj_array + logger = logging.getLogger(__name__) @@ -291,6 +289,7 @@ def inf_norm(x): print(code, file=mech_file) import importlib + from mirgecom.thermochemistry import get_pyrometheus_wrapper_class pyromechlib = importlib.import_module(f"{mechname}") pyro_mechanism = get_pyrometheus_wrapper_class( @@ -332,7 +331,7 @@ def inf_norm(x): pyro_h = pyro_mechanism.get_mixture_enthalpy_mass(pyro_t, yin) pyro_c = pyro_mechanism.get_concentrations(pyro_m, yin) - assert inf_norm((pyro_c - can_c)) < 1e-14 + assert inf_norm(pyro_c - can_c) < 1e-14 assert inf_norm((pyro_t - can_t) / can_t) < 1e-14 assert inf_norm((pyro_m - can_m) / can_m) < 1e-14 assert inf_norm((pyro_p - can_p) / can_p) < 1e-14 diff --git a/test/test_euler.py b/test/test_euler.py index 4caf23165..a6a8fa065 100644 --- a/test/test_euler.py +++ b/test/test_euler.py @@ -24,51 +24,42 @@ THE SOFTWARE. """ -import numpy as np -import numpy.random -import numpy.linalg as la # noqa -import pyopencl.clmath # noqa import logging -import pytest import math from functools import partial -from pytools.obj_array import ( - flat_obj_array, - make_obj_array, -) - -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from mirgecom.euler import euler_operator -from mirgecom.fluid import make_conserved -from mirgecom.initializers import Vortex2D, Lump, MulticomponentLump -from mirgecom.boundary import ( - PrescribedFluidBoundary, - DummyBoundary -) -from mirgecom.eos import IdealSingleGas -from mirgecom.gas_model import ( - GasModel, - make_fluid_state -) import grudge.op as op -from mirgecom.discretization import create_discretization_collection +import numpy as np +import numpy.linalg as la # noqa +import numpy.random +import pytest from grudge.dof_desc import DISCR_TAG_QUAD - +from grudge.shortcuts import make_visualizer from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) - -from mirgecom.simutil import max_component_norm + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, +) +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from grudge.shortcuts import make_visualizer +import pyopencl.clmath # noqa +from mirgecom.boundary import DummyBoundary, PrescribedFluidBoundary +from mirgecom.discretization import create_discretization_collection +from mirgecom.eos import IdealSingleGas +from mirgecom.euler import euler_operator +from mirgecom.fluid import make_conserved +from mirgecom.gas_model import GasModel, make_fluid_state +from mirgecom.initializers import Lump, MulticomponentLump, Vortex2D +from mirgecom.integrators import rk4_step from mirgecom.inviscid import ( get_inviscid_timestep, + inviscid_facial_flux_hll, inviscid_facial_flux_rusanov, - inviscid_facial_flux_hll +) +from mirgecom.simutil import max_component_norm +from pytools.obj_array import ( + flat_obj_array, + make_obj_array, ) -from mirgecom.integrators import rk4_step logger = logging.getLogger(__name__) @@ -281,7 +272,7 @@ def test_entropy_to_conserved_conversion(actx_factory, nspecies, dim, order): from mirgecom.gas_model import ( conservative_to_entropy_vars, - entropy_to_conservative_vars + entropy_to_conservative_vars, ) temp_state = make_fluid_state(cv, gas_model) gamma = gas_model.eos.gamma(temp_state.cv, temp_state.temperature) @@ -749,7 +740,7 @@ def rhs(t, q): filter_order = 8 eta = .5 alpha = -1.0*np.log(np.finfo(float).eps) - nummodes = int(1) + nummodes = 1 for _ in range(dim): nummodes *= int(order + dim + 1) nummodes /= math.factorial(int(dim)) @@ -757,7 +748,7 @@ def rhs(t, q): from mirgecom.filter import ( exponential_mode_response_function as xmrfunc, - filter_modally + filter_modally, ) frfunc = partial(xmrfunc, alpha=alpha, filter_order=filter_order) diff --git a/test/test_filter.py b/test/test_filter.py index 264bdce96..8848c0e2c 100644 --- a/test/test_filter.py +++ b/test/test_filter.py @@ -24,18 +24,17 @@ THE SOFTWARE. """ -import pytest -import numpy as np from functools import partial -from mirgecom.discretization import create_discretization_collection +import numpy as np +import pytest from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) -from pytools.obj_array import ( - make_obj_array + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, ) + +from mirgecom.discretization import create_discretization_collection from mirgecom.filter import make_spectral_filter +from pytools.obj_array import make_obj_array @pytest.mark.parametrize("dim", [1, 2, 3]) @@ -183,10 +182,13 @@ def test_spectral_filter(actx_factory, element_order, dim): nodes = actx.thaw(dcoll.nodes()) vol_discr = dcoll.discr_from_dd("vol") - from mirgecom.filter import exponential_mode_response_function as xmrfunc - from mirgecom.filter import filter_modally from grudge.dof_desc import DD_VOLUME_ALL, DD_VOLUME_ALL_MODAL + from mirgecom.filter import ( + exponential_mode_response_function as xmrfunc, + filter_modally, + ) + # make it sharp filter_order = 2 alpha = -1000.0*np.log(np.finfo(float).eps) diff --git a/test/test_fluid.py b/test/test_fluid.py index 26fd3feb2..d534ded65 100644 --- a/test/test_fluid.py +++ b/test/test_fluid.py @@ -24,21 +24,22 @@ THE SOFTWARE. """ +import logging + +import grudge.op as op import numpy as np -import numpy.random import numpy.linalg as la # noqa -import pyopencl.clmath # noqa -import logging +import numpy.random import pytest +from meshmode.array_context import ( # noqa + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, +) +import pyopencl.clmath # noqa +from mirgecom.discretization import create_discretization_collection +from mirgecom.fluid import make_conserved from pytools.obj_array import make_obj_array -from mirgecom.fluid import make_conserved -from mirgecom.discretization import create_discretization_collection -import grudge.op as op -from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) logger = logging.getLogger(__name__) diff --git a/test/test_flux.py b/test/test_flux.py index a72dec470..dd3bae85c 100644 --- a/test/test_flux.py +++ b/test/test_flux.py @@ -24,28 +24,27 @@ THE SOFTWARE. """ +import logging + import numpy as np -import numpy.random import numpy.linalg as la # noqa -import pyopencl.clmath # noqa -import logging +import numpy.random import pytest - -from pytools.obj_array import make_obj_array -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from meshmode.dof_array import DOFArray from grudge.dof_desc import as_dofdesc from grudge.trace_pair import TracePair -from mirgecom.fluid import make_conserved -from mirgecom.eos import IdealSingleGas -from mirgecom.gas_model import ( - GasModel, - make_fluid_state -) from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, +) +from meshmode.dof_array import DOFArray +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa + +import pyopencl.clmath # noqa +from mirgecom.eos import IdealSingleGas +from mirgecom.fluid import make_conserved +from mirgecom.gas_model import GasModel, make_fluid_state from mirgecom.inviscid import inviscid_flux +from pytools.obj_array import make_obj_array + logger = logging.getLogger(__name__) diff --git a/test/test_init.py b/test/test_init.py index 946d3f67d..190a58a55 100644 --- a/test/test_init.py +++ b/test/test_init.py @@ -23,30 +23,25 @@ """ import logging + +import grudge.op as op import numpy as np import numpy.linalg as la # noqa -import pyopencl as cl -import pyopencl.clrandom -import pyopencl.clmath -from pytools.obj_array import make_obj_array import pytest - from meshmode.array_context import PyOpenCLArrayContext from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from mirgecom.initializers import Vortex2D -from mirgecom.initializers import Lump -from mirgecom.initializers import MulticomponentLump - -from mirgecom.initializers import SodShock1D -from mirgecom.eos import IdealSingleGas - +import pyopencl as cl +import pyopencl.clmath +import pyopencl.clrandom from mirgecom.discretization import create_discretization_collection -import grudge.op as op - +from mirgecom.eos import IdealSingleGas +from mirgecom.initializers import Lump, MulticomponentLump, SodShock1D, Vortex2D from pyopencl.tools import ( # noqa pytest_generate_tests_for_pyopencl as pytest_generate_tests, ) +from pytools.obj_array import make_obj_array + logger = logging.getLogger(__name__) diff --git a/test/test_inviscid.py b/test/test_inviscid.py index c78b6d79b..6ee23d539 100644 --- a/test/test_inviscid.py +++ b/test/test_inviscid.py @@ -24,35 +24,36 @@ THE SOFTWARE. """ +import logging + +import grudge.op as op import numpy as np +import numpy.linalg as la import numpy.random -import numpy.linalg as la # noqa -import pyopencl.clmath # noqa -import logging import pytest - -from pytools.obj_array import ( - flat_obj_array, - make_obj_array, -) - -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from meshmode.discretization.connection import FACE_RESTR_ALL from grudge.dof_desc import as_dofdesc from grudge.trace_pair import TracePair -from mirgecom.fluid import make_conserved -from mirgecom.eos import IdealSingleGas -from mirgecom.discretization import create_discretization_collection -import grudge.op as op from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, +) +from meshmode.discretization.connection import FACE_RESTR_ALL +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa + +import pyopencl.clmath # noqa +from mirgecom.discretization import create_discretization_collection +from mirgecom.eos import IdealSingleGas +from mirgecom.fluid import make_conserved from mirgecom.inviscid import ( - inviscid_flux, + inviscid_facial_flux_hll, inviscid_facial_flux_rusanov, - inviscid_facial_flux_hll + inviscid_flux, +) +from pytools.obj_array import ( + flat_obj_array, + make_obj_array, ) + logger = logging.getLogger(__name__) @@ -289,6 +290,7 @@ def test_facial_flux(actx_factory, nspecies, order, dim, num_flux): p0 = 1.0 from meshmode.mesh.generation import generate_regular_rect_mesh + from pytools.convergence import EOCRecorder eoc_rec0 = EOCRecorder() @@ -322,10 +324,7 @@ def test_facial_flux(actx_factory, nspecies, order, dim, num_flux): cv_interior_pairs = interior_trace_pairs(dcoll, cv) # Check the boundary facial fluxes as called on an interior boundary # eos = IdealSingleGas() - from mirgecom.gas_model import ( - GasModel, - make_fluid_state - ) + from mirgecom.gas_model import GasModel, make_fluid_state gas_model = GasModel(eos=IdealSingleGas()) from mirgecom.gas_model import make_fluid_state_trace_pairs diff --git a/test/test_lazy.py b/test/test_lazy.py index 7c91ff718..7382833ee 100644 --- a/test/test_lazy.py +++ b/test/test_lazy.py @@ -22,27 +22,27 @@ THE SOFTWARE. """ -import numpy as np +import logging from functools import partial -from pytools.obj_array import make_obj_array, obj_array_vectorize # noqa -import pyopencl as cl -import pyopencl.tools as cl_tools -import pyopencl.array as cla # noqa -import pyopencl.clmath as clmath # noqa -from meshmode.array_context import ( # noqa + +import grudge.op as op +import numpy as np +import pytest +from meshmode.array_context import ( # noqa # noqa PyOpenCLArrayContext, - PytatoPyOpenCLArrayContext + PytatoPyOpenCLArrayContext, + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, ) from meshmode.discretization.connection import FACE_RESTR_ALL + +import pyopencl as cl +import pyopencl.array as cla # noqa +import pyopencl.clmath as clmath # noqa +import pyopencl.tools as cl_tools from mirgecom.discretization import create_discretization_collection -import grudge.op as op -from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) +from pytools.obj_array import make_obj_array, obj_array_vectorize # noqa -import pytest # noqa -import logging logger = logging.getLogger(__name__) @@ -80,6 +80,7 @@ def get_dcoll(order): def _isclose(dcoll, x, y, rel_tol=1e-9, abs_tol=0, return_operands=False): from mirgecom.simutil import componentwise_norms + from arraycontext import flatten actx = x.array_context lhs = actx.to_numpy(flatten(componentwise_norms(dcoll, x - y, np.inf), actx)) @@ -128,8 +129,9 @@ def test_lazy_op_divergence(op_test_data, order): eager_actx, lazy_actx, get_dcoll = op_test_data dcoll = get_dcoll(order) - from grudge.trace_pair import interior_trace_pair from grudge.dof_desc import as_dofdesc + from grudge.trace_pair import interior_trace_pair + from mirgecom.operators import div_operator dd_vol = as_dofdesc("vol") @@ -175,10 +177,12 @@ def test_lazy_op_diffusion(op_test_data, order): dcoll = get_dcoll(order) from grudge.dof_desc import BoundaryDomainTag + from mirgecom.diffusion import ( - diffusion_operator, DirichletDiffusionBoundary, - NeumannDiffusionBoundary) + NeumannDiffusionBoundary, + diffusion_operator, + ) boundaries = { BoundaryDomainTag("x"): DirichletDiffusionBoundary(0), @@ -214,7 +218,7 @@ def _get_pulse(): from mirgecom.gas_model import GasModel gas_model = GasModel(eos=IdealSingleGas()) - from mirgecom.initializers import Uniform, AcousticPulse + from mirgecom.initializers import AcousticPulse, Uniform uniform_init = Uniform(dim=2, pressure=1.0, rho=1.0) pulse_init = AcousticPulse(dim=2, center=np.zeros(2), amplitude=1.0, width=.1) @@ -223,6 +227,7 @@ def init(nodes): return pulse_init(x_vec=nodes, cv=cv, eos=gas_model.eos) from meshmode.mesh import BTAG_ALL + from mirgecom.boundary import AdiabaticSlipBoundary boundaries = { BTAG_ALL: AdiabaticSlipBoundary() @@ -249,6 +254,7 @@ def _my_boundary(dcoll, dd_bdry, gas_model, state_minus, **kwargs): **kwargs), gas_model) from meshmode.mesh import BTAG_ALL + from mirgecom.boundary import PrescribedFluidBoundary boundaries = { BTAG_ALL: PrescribedFluidBoundary(boundary_state_func=_my_boundary) diff --git a/test/test_limiter.py b/test/test_limiter.py index 7693392ba..1ec686f59 100644 --- a/test/test_limiter.py +++ b/test/test_limiter.py @@ -20,24 +20,23 @@ THE SOFTWARE. """ import numpy as np -from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) -from meshmode.array_context import ( # noqa +import pytest +from meshmode.array_context import ( # noqa # noqa PyOpenCLArrayContext, - PytatoPyOpenCLArrayContext + PytatoPyOpenCLArrayContext, + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, ) -from mirgecom.limiter import bound_preserving_limiter -from mirgecom.discretization import create_discretization_collection -from mirgecom.initializers import Uniform +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas +from mirgecom.fluid import make_conserved from mirgecom.gas_model import ( # noqa - GasModel, make_fluid_state, make_operator_fluid_states + GasModel, + make_fluid_state, + make_operator_fluid_states, ) -from mirgecom.fluid import make_conserved - -import pytest +from mirgecom.initializers import Uniform +from mirgecom.limiter import bound_preserving_limiter def test_fluid_api(actx_factory): diff --git a/test/test_mech_input.py b/test/test_mech_input.py index 26e026172..cc752b0e1 100644 --- a/test/test_mech_input.py +++ b/test/test_mech_input.py @@ -23,8 +23,10 @@ """ import logging + from mirgecom.mechanisms import get_mechanism_input + logger = logging.getLogger(__name__) diff --git a/test/test_multiphysics.py b/test/test_multiphysics.py index 48ea892cb..367a3e692 100644 --- a/test/test_multiphysics.py +++ b/test/test_multiphysics.py @@ -20,44 +20,42 @@ THE SOFTWARE. """ -import numpy as np +import logging from dataclasses import replace from functools import partial -import pyopencl.array as cla # noqa -import pyopencl.clmath as clmath # noqa -from pytools.obj_array import make_obj_array + import grudge.op as op -from mirgecom.simutil import ( - max_component_norm, - get_box_mesh +import numpy as np +import pytest +from grudge.dof_desc import DISCR_TAG_BASE, DISCR_TAG_QUAD, DOFDesc, VolumeDomainTag +from meshmode.array_context import ( # noqa + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, ) + import mirgecom.math as mm +import pyopencl.array as cla # noqa +import pyopencl.clmath as clmath # noqa +from mirgecom.boundary import ( + AdiabaticNoslipWallBoundary, + IsothermalWallBoundary, +) from mirgecom.diffusion import ( - diffusion_operator, DirichletDiffusionBoundary, - NeumannDiffusionBoundary) -from grudge.dof_desc import DOFDesc, VolumeDomainTag, DISCR_TAG_BASE, DISCR_TAG_QUAD + NeumannDiffusionBoundary, + diffusion_operator, +) from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas -from mirgecom.transport import SimpleTransport from mirgecom.fluid import make_conserved -from mirgecom.gas_model import ( - GasModel, - make_fluid_state -) -from mirgecom.boundary import ( - AdiabaticNoslipWallBoundary, - IsothermalWallBoundary, -) +from mirgecom.gas_model import GasModel, make_fluid_state from mirgecom.multiphysics.thermally_coupled_fluid_wall import ( basic_coupled_ns_heat_operator as coupled_ns_heat_operator, ) -from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) -import pytest +from mirgecom.simutil import get_box_mesh, max_component_norm +from mirgecom.transport import SimpleTransport +from pytools.obj_array import make_obj_array + -import logging logger = logging.getLogger(__name__) diff --git a/test/test_navierstokes.py b/test/test_navierstokes.py index 40cb40607..a4ec6e51f 100644 --- a/test/test_navierstokes.py +++ b/test/test_navierstokes.py @@ -24,48 +24,38 @@ THE SOFTWARE. """ +import logging +from abc import ABCMeta, abstractmethod + +import grudge.op as op import numpy as np -import numpy.random import numpy.linalg as la # noqa -import pyopencl.clmath # noqa -import logging +import numpy.random +import pymbolic as pmbl import pytest - -from pytools.obj_array import ( - flat_obj_array, - make_obj_array, +from meshmode.array_context import ( # noqa + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, ) - +from meshmode.dof_array import DOFArray from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -from mirgecom.navierstokes import ns_operator -from mirgecom.fluid import make_conserved +import mirgecom.math as mm +import pyopencl.clmath # noqa from mirgecom.boundary import ( DummyBoundary, PrescribedFluidBoundary, ) +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas +from mirgecom.fluid import make_conserved +from mirgecom.gas_model import GasModel, make_fluid_state +from mirgecom.navierstokes import ns_operator +from mirgecom.simutil import compare_fluid_solutions, componentwise_norms, get_box_mesh +from mirgecom.symbolic import diff as sym_diff, evaluate from mirgecom.transport import SimpleTransport -from mirgecom.discretization import create_discretization_collection -import grudge.op as op -from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) -from abc import ABCMeta, abstractmethod -from meshmode.dof_array import DOFArray -import pymbolic as pmbl -from mirgecom.symbolic import ( - diff as sym_diff, - evaluate) -import mirgecom.math as mm -from mirgecom.gas_model import ( - GasModel, - make_fluid_state -) -from mirgecom.simutil import ( - compare_fluid_solutions, - componentwise_norms, - get_box_mesh +from pytools.obj_array import ( + flat_obj_array, + make_obj_array, ) @@ -588,7 +578,7 @@ def test_exact_mms(actx_factory, order, dim, manufactured_soln, mu): dcv_dt = sym_diff(sym_t)(sym_cv) print(f"{dcv_dt=}") - from mirgecom.symbolic_fluid import sym_ns, sym_euler + from mirgecom.symbolic_fluid import sym_euler, sym_ns sym_ns_rhs = sym_ns(sym_cv, sym_prs, sym_tmp, mu) sym_euler_rhs = sym_euler(sym_cv, sym_prs) @@ -708,8 +698,7 @@ def _boundary_state_func(dcoll, dd_bdry, gas_model, state_minus, time=0, if visualize: from grudge.shortcuts import make_visualizer vis = make_visualizer(dcoll, order) - vis.write_vtk_file("shear_flow_test_{order}_{n}.vtu".format( - order=order, n=n), [ + vis.write_vtk_file(f"shear_flow_test_{order}_{n}.vtu", [ ("shear_flow", exact_fluid_state.cv), ("rhs", ns_rhs), ("grad(E)", grad_cv.energy), diff --git a/test/test_operators.py b/test/test_operators.py index 04ee9e86d..435c9ecc4 100644 --- a/test/test_operators.py +++ b/test/test_operators.py @@ -25,14 +25,14 @@ """ import numpy as np # noqa -import pytest # noqa +import pytest import logging from meshmode.array_context import ( # noqa pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests ) from pytools.obj_array import make_obj_array -import pymbolic as pmbl # noqa +import pymbolic as pmbl import pymbolic.primitives as prim from meshmode.mesh import BTAG_ALL from grudge.dof_desc import as_dofdesc @@ -170,14 +170,15 @@ def test_grad_operator(actx_factory, dim, mesh_name, rot_axis, wonk, - trig funcs - :class:`~mirgecom.fluid.ConservedVars` composed of funcs from above """ - import pyopencl as cl from grudge.array_context import PyOpenCLArrayContext - from meshmode.mesh.processing import rotate_mesh_around_axis from grudge.dt_utils import h_max_from_volume + from meshmode.mesh.processing import map_mesh, rotate_mesh_around_axis + + import pyopencl as cl + from mirgecom.operators import grad_operator from mirgecom.simutil import componentwise_norms + from arraycontext import flatten - from mirgecom.operators import grad_operator - from meshmode.mesh.processing import map_mesh def add_wonk(x: np.ndarray) -> np.ndarray: wonk_field = np.empty_like(x) diff --git a/test/test_restart.py b/test/test_restart.py index cb05ef624..b1a0d7292 100644 --- a/test/test_restart.py +++ b/test/test_restart.py @@ -24,15 +24,17 @@ THE SOFTWARE. """ +import logging + import numpy as np import numpy.random -import logging import pytest -from pytools.obj_array import make_obj_array -from mirgecom.discretization import create_discretization_collection from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, +) + +from mirgecom.discretization import create_discretization_collection +from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/test/test_simutil.py b/test/test_simutil.py index 6678213b0..67295d135 100644 --- a/test/test_simutil.py +++ b/test/test_simutil.py @@ -27,16 +27,15 @@ import numpy as np import pytest # noqa +from mirgecom.discretization import create_discretization_collection +from mirgecom.eos import IdealSingleGas +from mirgecom.fluid import make_conserved + from arraycontext import ( # noqa flatten, - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, ) -from mirgecom.fluid import make_conserved -from mirgecom.eos import IdealSingleGas -from mirgecom.discretization import create_discretization_collection - def test_basic_cfd_healthcheck(actx_factory): """Quick test of some health checking utilities.""" diff --git a/test/test_symbolic.py b/test/test_symbolic.py index b40818e4c..8a36e9abd 100644 --- a/test/test_symbolic.py +++ b/test/test_symbolic.py @@ -20,22 +20,24 @@ THE SOFTWARE. """ +import logging + +import grudge.op as op import numpy as np -import pyopencl.array as cla # noqa -import pyopencl.clmath as clmath # noqa -from pytools.obj_array import make_obj_array import pymbolic as pmbl +import pytest +from meshmode.array_context import ( # noqa + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, +) from meshmode.mesh.generation import generate_regular_rect_mesh + import mirgecom.symbolic as sym +import pyopencl.array as cla # noqa +import pyopencl.clmath as clmath # noqa from mirgecom.discretization import create_discretization_collection -import grudge.op as op -from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) +from pytools.obj_array import make_obj_array -import pytest -import logging logger = logging.getLogger(__name__) diff --git a/test/test_time_integrators.py b/test/test_time_integrators.py index 8a734901d..9c96752ec 100644 --- a/test/test_time_integrators.py +++ b/test/test_time_integrators.py @@ -24,19 +24,24 @@ THE SOFTWARE. """ -import numpy as np +import importlib import logging + +import numpy as np import pytest -import importlib from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, +) from mirgecom.integrators import ( - euler_step, lsrk54_step, lsrk144_step, - rk4_step, ssprk43_step + euler_step, + lsrk54_step, + lsrk144_step, + rk4_step, + ssprk43_step, ) + logger = logging.getLogger(__name__) @@ -140,14 +145,20 @@ def rhs(t, state): found = leap_spec is not None if found: from leap.rk import ( - ODE23MethodBuilder, ODE45MethodBuilder, ForwardEulerMethodBuilder, - MidpointMethodBuilder, HeunsMethodBuilder, - RK3MethodBuilder, RK4MethodBuilder, RK5MethodBuilder, + HeunsMethodBuilder, LSRK4MethodBuilder, - SSPRK22MethodBuilder, SSPRK33MethodBuilder, - ) + MidpointMethodBuilder, + ODE23MethodBuilder, + ODE45MethodBuilder, + RK3MethodBuilder, + RK4MethodBuilder, + RK5MethodBuilder, + SSPRK22MethodBuilder, + SSPRK33MethodBuilder, + ) from leap.rk.imex import KennedyCarpenterIMEXARK4MethodBuilder + from mirgecom.steppers import advance_state @pytest.mark.parametrize(("method", "method_order"), [ diff --git a/test/test_transport.py b/test/test_transport.py index 186d204b3..3951f5b45 100644 --- a/test/test_transport.py +++ b/test/test_transport.py @@ -25,37 +25,35 @@ THE SOFTWARE. """ import logging + +import cantera import numpy as np -import pyopencl as cl +import pyrometheus import pytest -import cantera -from pytools.obj_array import make_obj_array - from grudge import op - -from meshmode.array_context import ( # noqa +from meshmode.array_context import ( # noqa # noqa PyOpenCLArrayContext, - PytatoPyOpenCLArrayContext + PytatoPyOpenCLArrayContext, + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, ) from meshmode.mesh.generation import generate_regular_rect_mesh -from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) -from pyopencl.tools import ( # noqa - pytest_generate_tests_for_pyopencl as pytest_generate_tests, -) -from mirgecom.transport import MixtureAveragedTransport -from mirgecom.fluid import make_conserved +import pyopencl as cl +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import PyrometheusMixture +from mirgecom.fluid import make_conserved from mirgecom.gas_model import GasModel, make_fluid_state -from mirgecom.discretization import create_discretization_collection from mirgecom.mechanisms import get_mechanism_input from mirgecom.thermochemistry import ( + get_pyrometheus_wrapper_class, get_pyrometheus_wrapper_class_from_cantera, - get_pyrometheus_wrapper_class ) -import pyrometheus +from mirgecom.transport import MixtureAveragedTransport +from pyopencl.tools import ( # noqa + pytest_generate_tests_for_pyopencl as pytest_generate_tests, +) +from pytools.obj_array import make_obj_array + logger = logging.getLogger(__name__) diff --git a/test/test_viscous.py b/test/test_viscous.py index ecbbcaf59..855e44e8d 100644 --- a/test/test_viscous.py +++ b/test/test_viscous.py @@ -24,36 +24,31 @@ THE SOFTWARE. """ -import numpy as np -import numpy.random -import numpy.linalg as la # noqa -import pyopencl.clmath # noqa import logging -import pytest # noqa -from pytools.obj_array import make_obj_array -from meshmode.discretization.connection import FACE_RESTR_ALL -from meshmode.mesh import BTAG_ALL -from grudge.dof_desc import as_dofdesc import grudge.op as op +import numpy as np +import numpy.linalg as la # noqa +import numpy.random +import pytest +from grudge.dof_desc import as_dofdesc from grudge.trace_pair import interior_trace_pairs -from mirgecom.discretization import create_discretization_collection - from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) - -from mirgecom.fluid import make_conserved -from mirgecom.transport import ( - SimpleTransport, - PowerLawTransport + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, ) +from meshmode.discretization.connection import FACE_RESTR_ALL +from meshmode.mesh import BTAG_ALL + +import pyopencl.clmath # noqa +from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas -from mirgecom.gas_model import ( - GasModel, - make_fluid_state -) +from mirgecom.fluid import make_conserved +from mirgecom.gas_model import GasModel, make_fluid_state from mirgecom.simutil import get_box_mesh +from mirgecom.transport import PowerLawTransport, SimpleTransport +from pytools.obj_array import make_obj_array + + logger = logging.getLogger(__name__) @@ -417,7 +412,7 @@ def test_diffusive_heat_flux(actx_factory): gas_model = GasModel(eos=eos, transport=tv_model) fluid_state = make_fluid_state(cv, gas_model) - from mirgecom.viscous import diffusive_flux, conductive_heat_flux + from mirgecom.viscous import conductive_heat_flux, diffusive_flux q = conductive_heat_flux(fluid_state, grad_t) j = diffusive_flux(fluid_state, grad_cv) diff --git a/test/test_wallmodel.py b/test/test_wallmodel.py index 9fed63bf7..84a29488e 100644 --- a/test/test_wallmodel.py +++ b/test/test_wallmodel.py @@ -22,14 +22,15 @@ THE SOFTWARE. """ +import grudge.op as op import numpy as np -from pytools.obj_array import make_obj_array from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) -import grudge.op as op + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, +) + from mirgecom.discretization import create_discretization_collection from mirgecom.simutil import get_box_mesh +from pytools.obj_array import make_obj_array def test_tacot_decomposition(actx_factory): diff --git a/test/test_wave.py b/test/test_wave.py index 61eb14d09..9cdae6857 100644 --- a/test/test_wave.py +++ b/test/test_wave.py @@ -20,27 +20,27 @@ THE SOFTWARE. """ +import logging +from dataclasses import dataclass +from typing import Callable + +import grudge.op as op import numpy as np -import pyopencl.array as cla # noqa -import pyopencl.clmath as clmath # noqa -from pytools.obj_array import flat_obj_array, make_obj_array import pymbolic as pmbl import pymbolic.primitives as prim -import mirgecom.symbolic as sym -from mirgecom.wave import wave_operator -from mirgecom.discretization import create_discretization_collection -import grudge.op as op - +import pytest from meshmode.array_context import ( # noqa - pytest_generate_tests_for_pyopencl_array_context - as pytest_generate_tests) + pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, +) -import pytest +import mirgecom.symbolic as sym +import pyopencl.array as cla # noqa +import pyopencl.clmath as clmath # noqa +from mirgecom.discretization import create_discretization_collection +from mirgecom.wave import wave_operator +from pytools.obj_array import flat_obj_array, make_obj_array -from dataclasses import dataclass -from typing import Callable -import logging logger = logging.getLogger(__name__) @@ -191,8 +191,7 @@ def sym_eval(expr, t): if visualize: from grudge.shortcuts import make_visualizer vis = make_visualizer(dcoll, order) - vis.write_vtk_file("wave_accuracy_{order}_{n}.vtu".format(order=order, - n=n), [ + vis.write_vtk_file(f"wave_accuracy_{order}_{n}.vtu", [ ("u", fields[0]), ("v", fields[1:]), ("rhs_u_actual", rhs[0]), From 3950a75d292b07a62f9a04ae0664c4e7985caa7b Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Mon, 22 Jul 2024 19:00:25 -0500 Subject: [PATCH 2/3] pass 2 --- examples/ablation-workshop.py | 3 ++- examples/advdiff-tpe.py | 3 ++- examples/autoignition.py | 3 ++- examples/blasius.py | 3 +-- examples/gas-in-box.py | 3 ++- examples/multiple-volumes.py | 3 ++- examples/poiseuille-multispecies.py | 3 ++- examples/poiseuille-tpe.py | 3 ++- examples/poiseuille.py | 3 ++- examples/scalar-advdiff.py | 3 ++- examples/scalar-lump.py | 3 ++- examples/thermally-coupled-tpe.py | 3 ++- examples/thermally-coupled.py | 3 ++- examples/wave.py | 3 ++- mirgecom/array_context.py | 4 ++-- mirgecom/artificial_viscosity.py | 9 ++++----- mirgecom/boundary.py | 6 +++--- mirgecom/diffusion.py | 3 ++- mirgecom/eos.py | 3 +-- mirgecom/filter.py | 3 +-- mirgecom/gas_model.py | 3 +-- mirgecom/initializers.py | 3 ++- mirgecom/inviscid.py | 3 +-- mirgecom/logging_quantities.py | 3 +-- mirgecom/materials/carbon_fiber.py | 3 ++- mirgecom/materials/initializer.py | 3 ++- mirgecom/materials/tacot.py | 3 ++- mirgecom/math.py | 10 ++++------ .../multiphysics/thermally_coupled_fluid_wall.py | 3 +-- mirgecom/profiling.py | 3 ++- mirgecom/simutil.py | 4 ++-- mirgecom/steppers.py | 4 ++-- mirgecom/transport.py | 3 +-- mirgecom/utils.py | 3 +-- mirgecom/viscous.py | 3 +-- mirgecom/wall_model.py | 11 +++++------ pyproject.toml | 2 +- test/test_av.py | 13 +++++++------ test/test_bc.py | 3 ++- test/test_chemistry.py | 3 ++- test/test_diffusion.py | 3 ++- test/test_eos.py | 3 ++- test/test_euler.py | 9 +++++---- test/test_filter.py | 3 ++- test/test_fluid.py | 3 ++- test/test_flux.py | 3 ++- test/test_init.py | 7 ++++--- test/test_inviscid.py | 9 +++++---- test/test_lazy.py | 7 ++++--- test/test_multiphysics.py | 5 +++-- test/test_navierstokes.py | 11 ++++++----- test/test_operators.py | 4 ++-- test/test_restart.py | 3 ++- test/test_simutil.py | 9 ++++----- test/test_symbolic.py | 5 +++-- test/test_transport.py | 9 +++++---- test/test_viscous.py | 3 ++- test/test_wallmodel.py | 3 ++- test/test_wave.py | 5 +++-- 59 files changed, 142 insertions(+), 118 deletions(-) diff --git a/examples/ablation-workshop.py b/examples/ablation-workshop.py index a78c642bf..655ca5afa 100644 --- a/examples/ablation-workshop.py +++ b/examples/ablation-workshop.py @@ -38,6 +38,8 @@ from meshmode.dof_array import DOFArray from scipy.interpolate import CubicSpline # type: ignore[import-untyped] +from pytools.obj_array import make_obj_array + from mirgecom.diffusion import ( DirichletDiffusionBoundary, NeumannDiffusionBoundary, @@ -69,7 +71,6 @@ PorousWallTransport, PorousWallVars, ) -from pytools.obj_array import make_obj_array # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/examples/advdiff-tpe.py b/examples/advdiff-tpe.py index 3fe799114..9438ab4cb 100644 --- a/examples/advdiff-tpe.py +++ b/examples/advdiff-tpe.py @@ -31,6 +31,8 @@ from logpyle import IntervalTimer, set_dt from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from pytools.obj_array import make_obj_array + from mirgecom.discretization import create_discretization_collection # from mirgecom.boundary import PrescribedFluidBoundary @@ -57,7 +59,6 @@ ) from mirgecom.steppers import advance_state from mirgecom.transport import SimpleTransport -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/examples/autoignition.py b/examples/autoignition.py index 53b4d01b5..224a7cb17 100644 --- a/examples/autoignition.py +++ b/examples/autoignition.py @@ -33,6 +33,8 @@ from grudge.shortcuts import make_visualizer from logpyle import IntervalTimer, set_dt +from pytools.obj_array import make_obj_array + from mirgecom.discretization import create_discretization_collection from mirgecom.eos import PyrometheusMixture from mirgecom.euler import extract_vars_for_logging, units_for_logging @@ -60,7 +62,6 @@ ) from mirgecom.steppers import advance_state from mirgecom.utils import force_evaluation -from pytools.obj_array import make_obj_array class SingleLevelFilter(logging.Filter): diff --git a/examples/blasius.py b/examples/blasius.py index fcf20be26..fe1880532 100644 --- a/examples/blasius.py +++ b/examples/blasius.py @@ -28,6 +28,7 @@ import os import numpy as np +from arraycontext import get_container_context_recursively from grudge.dof_desc import DD_VOLUME_ALL, DISCR_TAG_QUAD from grudge.shortcuts import compiled_lsrk45_step, make_visualizer from logpyle import IntervalTimer, set_dt @@ -63,8 +64,6 @@ from mirgecom.steppers import advance_state from mirgecom.utils import force_evaluation -from arraycontext import get_container_context_recursively - logger = logging.getLogger(__name__) diff --git a/examples/gas-in-box.py b/examples/gas-in-box.py index 70b693533..4ac7b701a 100644 --- a/examples/gas-in-box.py +++ b/examples/gas-in-box.py @@ -36,6 +36,8 @@ from logpyle import IntervalTimer, set_dt from meshmode.mesh import BTAG_ALL +from pytools.obj_array import make_obj_array + from mirgecom.boundary import AdiabaticSlipBoundary, IsothermalWallBoundary from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas, PyrometheusMixture @@ -65,7 +67,6 @@ SimpleTransport, ) from mirgecom.utils import force_evaluation -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/examples/multiple-volumes.py b/examples/multiple-volumes.py index fb44f906e..209428d3e 100644 --- a/examples/multiple-volumes.py +++ b/examples/multiple-volumes.py @@ -38,6 +38,8 @@ from logpyle import IntervalTimer, set_dt from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from pytools.obj_array import make_obj_array + from mirgecom.boundary import AdiabaticSlipBoundary from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas @@ -56,7 +58,6 @@ from mirgecom.mpi import mpi_entry_point from mirgecom.simutil import generate_and_distribute_mesh, get_sim_timestep from mirgecom.steppers import advance_state -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/examples/poiseuille-multispecies.py b/examples/poiseuille-multispecies.py index 5d4de86d9..9748d9572 100644 --- a/examples/poiseuille-multispecies.py +++ b/examples/poiseuille-multispecies.py @@ -32,6 +32,8 @@ from logpyle import IntervalTimer, set_dt from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from pytools.obj_array import make_obj_array + from mirgecom.boundary import IsothermalWallBoundary, PrescribedFluidBoundary from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas # , PyrometheusMixture @@ -52,7 +54,6 @@ from mirgecom.simutil import get_sim_timestep from mirgecom.steppers import advance_state from mirgecom.transport import SimpleTransport -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/examples/poiseuille-tpe.py b/examples/poiseuille-tpe.py index f7e074bdc..3082145ab 100644 --- a/examples/poiseuille-tpe.py +++ b/examples/poiseuille-tpe.py @@ -32,6 +32,8 @@ from logpyle import IntervalTimer, set_dt from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from pytools.obj_array import make_obj_array + from mirgecom.boundary import ( AdiabaticNoslipWallBoundary, IsothermalWallBoundary, @@ -56,7 +58,6 @@ from mirgecom.simutil import get_box_mesh, get_sim_timestep from mirgecom.steppers import advance_state from mirgecom.transport import SimpleTransport -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/examples/poiseuille.py b/examples/poiseuille.py index a993be4a9..09a8469b0 100644 --- a/examples/poiseuille.py +++ b/examples/poiseuille.py @@ -32,6 +32,8 @@ from logpyle import IntervalTimer, set_dt from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from pytools.obj_array import make_obj_array + from mirgecom.boundary import ( AdiabaticNoslipWallBoundary, IsothermalWallBoundary, @@ -56,7 +58,6 @@ from mirgecom.simutil import get_box_mesh, get_sim_timestep from mirgecom.steppers import advance_state from mirgecom.transport import SimpleTransport -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/examples/scalar-advdiff.py b/examples/scalar-advdiff.py index 23bb3a4ed..46914d27a 100644 --- a/examples/scalar-advdiff.py +++ b/examples/scalar-advdiff.py @@ -31,6 +31,8 @@ from logpyle import IntervalTimer, set_dt from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from pytools.obj_array import make_obj_array + from mirgecom.discretization import create_discretization_collection # from mirgecom.boundary import PrescribedFluidBoundary @@ -57,7 +59,6 @@ ) from mirgecom.steppers import advance_state from mirgecom.transport import SimpleTransport -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/examples/scalar-lump.py b/examples/scalar-lump.py index 6690e5030..e19644b42 100644 --- a/examples/scalar-lump.py +++ b/examples/scalar-lump.py @@ -32,6 +32,8 @@ from logpyle import IntervalTimer, set_dt from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from pytools.obj_array import make_obj_array + from mirgecom.boundary import PrescribedFluidBoundary from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas @@ -49,7 +51,6 @@ from mirgecom.mpi import mpi_entry_point from mirgecom.simutil import generate_and_distribute_mesh, get_sim_timestep from mirgecom.steppers import advance_state -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/examples/thermally-coupled-tpe.py b/examples/thermally-coupled-tpe.py index 3cb432984..73b98824e 100644 --- a/examples/thermally-coupled-tpe.py +++ b/examples/thermally-coupled-tpe.py @@ -41,6 +41,8 @@ from meshmode.discretization.connection import FACE_RESTR_ALL # noqa from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from pytools.obj_array import make_obj_array + from mirgecom.boundary import ( IsothermalWallBoundary, ) @@ -71,7 +73,6 @@ ) from mirgecom.steppers import advance_state from mirgecom.transport import SimpleTransport -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/examples/thermally-coupled.py b/examples/thermally-coupled.py index 34940071f..8cb77cc18 100644 --- a/examples/thermally-coupled.py +++ b/examples/thermally-coupled.py @@ -41,6 +41,8 @@ from meshmode.discretization.connection import FACE_RESTR_ALL # noqa from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from pytools.obj_array import make_obj_array + from mirgecom.boundary import ( IsothermalWallBoundary, ) @@ -71,7 +73,6 @@ ) from mirgecom.steppers import advance_state from mirgecom.transport import SimpleTransport -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/examples/wave.py b/examples/wave.py index 37fc5b3c5..d91ec7b99 100644 --- a/examples/wave.py +++ b/examples/wave.py @@ -30,6 +30,8 @@ from logpyle import IntervalTimer, set_dt from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from pytools.obj_array import flat_obj_array + from mirgecom.array_context import initialize_actx from mirgecom.discretization import create_discretization_collection from mirgecom.integrators import rk4_step @@ -42,7 +44,6 @@ from mirgecom.mpi import mpi_entry_point from mirgecom.utils import force_evaluation from mirgecom.wave import wave_operator -from pytools.obj_array import flat_obj_array def bump(actx, nodes, t=0): diff --git a/mirgecom/array_context.py b/mirgecom/array_context.py index 1e080a776..1f736ff92 100644 --- a/mirgecom/array_context.py +++ b/mirgecom/array_context.py @@ -36,10 +36,10 @@ import os from typing import Any, Dict, Type -import pyopencl as cl - from arraycontext import ArrayContext, PyOpenCLArrayContext, PytatoPyOpenCLArrayContext +import pyopencl as cl + logger = logging.getLogger(__name__) diff --git a/mirgecom/artificial_viscosity.py b/mirgecom/artificial_viscosity.py index e64e067dc..541ed8fb7 100644 --- a/mirgecom/artificial_viscosity.py +++ b/mirgecom/artificial_viscosity.py @@ -129,6 +129,7 @@ import grudge.op as op import numpy as np +from arraycontext import get_container_context_recursively from grudge.dof_desc import ( DD_VOLUME_ALL, DISCR_TAG_BASE, @@ -140,6 +141,8 @@ from meshmode.discretization.connection import FACE_RESTR_ALL from meshmode.dof_array import DOFArray +from pytools import keyed_memoize_in, memoize_in + from mirgecom.boundary import ( AdiabaticNoslipWallBoundary, IsothermalWallBoundary, @@ -148,9 +151,6 @@ from mirgecom.flux import num_flux_central from mirgecom.operators import div_operator from mirgecom.utils import normalize_boundaries -from pytools import keyed_memoize_in, memoize_in - -from arraycontext import get_container_context_recursively class _AVRTag: @@ -436,14 +436,13 @@ def smoothness_indicator(dcoll, u, kappa=1.0, s0=-6.0, dd=DD_VOLUME_ALL): @memoize_in(actx, (smoothness_indicator, "smooth_comp_knl", dd)) def indicator_prg(): """Compute the smoothness indicator for all elements.""" + from arraycontext import make_loopy_program from meshmode.transform_metadata import ( ConcurrentDOFInameTag, ConcurrentElementInameTag, ) import loopy as lp - - from arraycontext import make_loopy_program t_unit = make_loopy_program([ "{[iel]: 0 <= iel < nelements}", "{[idof]: 0 <= idof < ndiscr_nodes_in}", diff --git a/mirgecom/boundary.py b/mirgecom/boundary.py index b1022b77b..996b55ad7 100644 --- a/mirgecom/boundary.py +++ b/mirgecom/boundary.py @@ -55,18 +55,18 @@ import grudge.op as op import numpy as np +from arraycontext import get_container_context_recursively, outer from grudge.dof_desc import as_dofdesc from grudge.trace_pair import TracePair from meshmode.discretization.connection import FACE_RESTR_ALL +from pytools.obj_array import make_obj_array + from mirgecom.fluid import make_conserved from mirgecom.gas_model import make_fluid_state, replace_fluid_state from mirgecom.inviscid import inviscid_facial_flux_rusanov, inviscid_flux from mirgecom.utils import project_from_base from mirgecom.viscous import viscous_facial_flux_central, viscous_flux -from pytools.obj_array import make_obj_array - -from arraycontext import get_container_context_recursively, outer def _ldg_bnd_flux_for_grad(internal_quantity, external_quantity): diff --git a/mirgecom/diffusion.py b/mirgecom/diffusion.py index bb72f0d25..6528a8f67 100644 --- a/mirgecom/diffusion.py +++ b/mirgecom/diffusion.py @@ -101,9 +101,10 @@ ) from meshmode.discretization.connection import FACE_RESTR_ALL +from pytools.obj_array import make_obj_array, obj_array_vectorize_n_args + from mirgecom.math import harmonic_mean from mirgecom.utils import normalize_boundaries -from pytools.obj_array import make_obj_array, obj_array_vectorize_n_args def grad_facial_flux_central(kappa_tpair, u_tpair, normal): diff --git a/mirgecom/eos.py b/mirgecom/eos.py index 1eba3b600..c28a1156d 100644 --- a/mirgecom/eos.py +++ b/mirgecom/eos.py @@ -47,12 +47,11 @@ from typing import Optional, Union import numpy as np +from arraycontext import dataclass_array_container from meshmode.dof_array import DOFArray from mirgecom.fluid import ConservedVars, make_conserved -from arraycontext import dataclass_array_container - class TemperatureSeedMissingError(Exception): """Indicate that EOS is inappropriately called without seeding temperature.""" diff --git a/mirgecom/filter.py b/mirgecom/filter.py index 4ecc9634b..48f7d2a03 100644 --- a/mirgecom/filter.py +++ b/mirgecom/filter.py @@ -52,6 +52,7 @@ from functools import partial import numpy as np +from arraycontext import map_array_container from grudge.dof_desc import ( DD_VOLUME_ALL, DISCR_TAG_BASE, @@ -61,8 +62,6 @@ from pytools import keyed_memoize_in -from arraycontext import map_array_container - # TODO: Revisit for multi-group meshes def get_element_spectrum_from_modal_representation(actx, vol_discr, modal_fields, diff --git a/mirgecom/gas_model.py b/mirgecom/gas_model.py index b33f3f4bb..30746f4de 100644 --- a/mirgecom/gas_model.py +++ b/mirgecom/gas_model.py @@ -55,6 +55,7 @@ import grudge.op as op import numpy as np +from arraycontext import dataclass_array_container from grudge.dof_desc import ( DD_VOLUME_ALL, DISCR_TAG_BASE, @@ -73,8 +74,6 @@ from mirgecom.utils import normalize_boundaries from mirgecom.wall_model import PorousFlowModel, PorousWallVars -from arraycontext import dataclass_array_container - @dataclass(frozen=True) class GasModel: diff --git a/mirgecom/initializers.py b/mirgecom/initializers.py index 8f47370cd..b4b7a93e2 100644 --- a/mirgecom/initializers.py +++ b/mirgecom/initializers.py @@ -52,9 +52,10 @@ import numpy as np +from pytools.obj_array import make_obj_array + from mirgecom.eos import IdealSingleGas from mirgecom.fluid import make_conserved -from pytools.obj_array import make_obj_array def initialize_flow_solution(actx, coords, gas_model=None, eos=None, diff --git a/mirgecom/inviscid.py b/mirgecom/inviscid.py index 03cf08bb0..e58c57e1c 100644 --- a/mirgecom/inviscid.py +++ b/mirgecom/inviscid.py @@ -45,6 +45,7 @@ import grudge.op as op import numpy as np +from arraycontext import outer from grudge.dof_desc import ( DD_VOLUME_ALL, DISCR_TAG_BASE, @@ -56,8 +57,6 @@ from mirgecom.fluid import ConservedVars, make_conserved from mirgecom.utils import normalize_boundaries -from arraycontext import outer - def inviscid_flux(state): r"""Compute the inviscid flux vectors from fluid conserved vars *cv*. diff --git a/mirgecom/logging_quantities.py b/mirgecom/logging_quantities.py index 7ee4442d5..1f80d6ddc 100644 --- a/mirgecom/logging_quantities.py +++ b/mirgecom/logging_quantities.py @@ -44,6 +44,7 @@ import grudge.op as oper import numpy as np +from arraycontext.container import get_container_context_recursively from grudge.discretization import DiscretizationCollection from grudge.dof_desc import DD_VOLUME_ALL from logpyle import ( @@ -59,8 +60,6 @@ import pyopencl as cl -from arraycontext.container import get_container_context_recursively - MemPoolType = Union[cl.tools.MemoryPool, cl.tools.SVMPool] diff --git a/mirgecom/materials/carbon_fiber.py b/mirgecom/materials/carbon_fiber.py index 12c0d4358..80cdbf6a6 100644 --- a/mirgecom/materials/carbon_fiber.py +++ b/mirgecom/materials/carbon_fiber.py @@ -35,9 +35,10 @@ import numpy as np from meshmode.dof_array import DOFArray -from mirgecom.wall_model import PorousWallEOS from pytools.obj_array import make_obj_array +from mirgecom.wall_model import PorousWallEOS + class Oxidation: """Abstract interface for wall oxidation model. diff --git a/mirgecom/materials/initializer.py b/mirgecom/materials/initializer.py index b386aab1a..15925139b 100644 --- a/mirgecom/materials/initializer.py +++ b/mirgecom/materials/initializer.py @@ -28,9 +28,10 @@ THE SOFTWARE. """ +from pytools.obj_array import make_obj_array + from mirgecom.fluid import make_conserved from mirgecom.wall_model import SolidWallConservedVars -from pytools.obj_array import make_obj_array class SolidWallInitializer: diff --git a/mirgecom/materials/tacot.py b/mirgecom/materials/tacot.py index 86b66b00e..0d00acd90 100644 --- a/mirgecom/materials/tacot.py +++ b/mirgecom/materials/tacot.py @@ -35,9 +35,10 @@ import numpy as np from meshmode.dof_array import DOFArray -from mirgecom.wall_model import PorousWallEOS from pytools.obj_array import make_obj_array +from mirgecom.wall_model import PorousWallEOS + class Pyrolysis: r"""Evaluate the source terms for the pyrolysis decomposition of TACOT. diff --git a/mirgecom/math.py b/mirgecom/math.py index 230a19b2c..80ed7468e 100644 --- a/mirgecom/math.py +++ b/mirgecom/math.py @@ -53,14 +53,13 @@ import numpy as np import numpy.linalg as la # noqa import pymbolic as pmbl -from pymbolic.primitives import Expression - -from pytools.obj_array import make_obj_array - from arraycontext import ( get_container_context_recursively, get_container_context_recursively_opt, ) +from pymbolic.primitives import Expression + +from pytools.obj_array import make_obj_array def harmonic_mean(x, y): @@ -94,9 +93,8 @@ def scalar_harmonic_mean(a, b): a_plus_b = a + b if a + b > 0 else 1 return 2*a*b/a_plus_b - from meshmode.dof_array import DOFArray - from arraycontext import rec_multimap_array_container + from meshmode.dof_array import DOFArray return rec_multimap_array_container( scalar_harmonic_mean, x, y, leaf_class=DOFArray) diff --git a/mirgecom/multiphysics/thermally_coupled_fluid_wall.py b/mirgecom/multiphysics/thermally_coupled_fluid_wall.py index 0bf40544a..6fdfb7fc1 100644 --- a/mirgecom/multiphysics/thermally_coupled_fluid_wall.py +++ b/mirgecom/multiphysics/thermally_coupled_fluid_wall.py @@ -71,6 +71,7 @@ import grudge.op as op import numpy as np +from arraycontext import dataclass_array_container from grudge.dof_desc import ( DISCR_TAG_BASE, as_dofdesc, @@ -108,8 +109,6 @@ from mirgecom.utils import project_from_base from mirgecom.viscous import viscous_facial_flux_harmonic -from arraycontext import dataclass_array_container - class _ThermalDataNoGradInterVolTag: pass diff --git a/mirgecom/profiling.py b/mirgecom/profiling.py index 3bf80cb50..32845e953 100644 --- a/mirgecom/profiling.py +++ b/mirgecom/profiling.py @@ -34,9 +34,10 @@ import loopy as lp import pyopencl as cl import pytools +from pytools.py_codegen import PythonFunctionGenerator + from mirgecom.logging_quantities import KernelProfile from mirgecom.utils import StatisticsAccumulator -from pytools.py_codegen import PythonFunctionGenerator __doc__ = """ diff --git a/mirgecom/simutil.py b/mirgecom/simutil.py index 467532c94..a0ee535e4 100644 --- a/mirgecom/simutil.py +++ b/mirgecom/simutil.py @@ -76,6 +76,7 @@ import grudge.op as op import numpy as np +from arraycontext import flatten, map_array_container, tag_axes from grudge.discretization import DiscretizationCollection, PartID from grudge.dof_desc import DD_VOLUME_ALL from logpyle import IntervalTimer @@ -86,11 +87,10 @@ ) import pyopencl as cl + from mirgecom.utils import normalize_boundaries from mirgecom.viscous import get_viscous_timestep -from arraycontext import flatten, map_array_container, tag_axes - logger = logging.getLogger(__name__) diff --git a/mirgecom/steppers.py b/mirgecom/steppers.py index 7adf92006..196397b0a 100644 --- a/mirgecom/steppers.py +++ b/mirgecom/steppers.py @@ -29,11 +29,11 @@ """ import numpy as np +from arraycontext import get_container_context_recursively_opt -from mirgecom.utils import force_evaluation from pytools import memoize_in -from arraycontext import get_container_context_recursively_opt +from mirgecom.utils import force_evaluation def _compile_timestepper(actx, timestepper, rhs): diff --git a/mirgecom/transport.py b/mirgecom/transport.py index fa3031df8..d90ad19bb 100644 --- a/mirgecom/transport.py +++ b/mirgecom/transport.py @@ -51,14 +51,13 @@ from typing import Optional import numpy as np +from arraycontext import dataclass_array_container from meshmode.dof_array import DOFArray from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa from mirgecom.eos import GasDependentVars, GasEOS from mirgecom.fluid import ConservedVars -from arraycontext import dataclass_array_container - class TransportModelError(Exception): """Indicate that transport model is required for model evaluation.""" diff --git a/mirgecom/utils.py b/mirgecom/utils.py index 531b71ad4..32006da79 100644 --- a/mirgecom/utils.py +++ b/mirgecom/utils.py @@ -35,14 +35,13 @@ from typing import Optional +from arraycontext import tag_axes from meshmode.dof_array import DOFArray from meshmode.transform_metadata import ( DiscretizationDOFAxisTag, DiscretizationElementAxisTag, ) -from arraycontext import tag_axes - def asdict_shallow(dc_instance) -> dict: """Convert a dataclass into a dict. diff --git a/mirgecom/viscous.py b/mirgecom/viscous.py index 33a0b0905..c623f6778 100644 --- a/mirgecom/viscous.py +++ b/mirgecom/viscous.py @@ -46,6 +46,7 @@ import grudge.op as op import numpy as np +from arraycontext import outer from grudge.dof_desc import ( DD_VOLUME_ALL, DISCR_TAG_BASE, @@ -62,8 +63,6 @@ ) from mirgecom.utils import normalize_boundaries -from arraycontext import outer - # low level routine works with numpy arrays and can be tested without # a full grid + fluid state, etc diff --git a/mirgecom/wall_model.py b/mirgecom/wall_model.py index f10d3d57f..1963c6b06 100644 --- a/mirgecom/wall_model.py +++ b/mirgecom/wall_model.py @@ -73,17 +73,16 @@ from typing import Optional, Union import numpy as np -from meshmode.dof_array import DOFArray - -from mirgecom.eos import GasDependentVars, GasEOS, MixtureEOS -from mirgecom.fluid import ConservedVars -from mirgecom.transport import GasTransportVars, TransportModel - from arraycontext import ( dataclass_array_container, get_container_context_recursively, with_container_arithmetic, ) +from meshmode.dof_array import DOFArray + +from mirgecom.eos import GasDependentVars, GasEOS, MixtureEOS +from mirgecom.fluid import ConservedVars +from mirgecom.transport import GasTransportVars, TransportModel @with_container_arithmetic(bcast_obj_array=False, diff --git a/pyproject.toml b/pyproject.toml index 37727dabe..ec9e71bf6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ multiline-quotes = "double" [tool.ruff.lint.isort] combine-as-imports = true known-local-folder = [ - "arraycontext", + "mirgecom", ] known-first-party = [ "pytools", diff --git a/test/test_av.py b/test/test_av.py index dc16840b1..e94f96d55 100644 --- a/test/test_av.py +++ b/test/test_av.py @@ -38,6 +38,11 @@ from meshmode.mesh import BTAG_ALL import pyopencl as cl +from pyopencl.tools import ( # noqa + pytest_generate_tests_for_pyopencl as pytest_generate_tests, +) +from pytools.obj_array import make_obj_array + from mirgecom.artificial_viscosity import ( AdiabaticNoSlipWallAV, PrescribedFluidBoundaryAV, @@ -49,10 +54,6 @@ from mirgecom.fluid import make_conserved from mirgecom.gas_model import GasModel, make_fluid_state from mirgecom.simutil import get_box_mesh -from pyopencl.tools import ( # noqa - pytest_generate_tests_for_pyopencl as pytest_generate_tests, -) -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) @@ -213,9 +214,9 @@ def cv_gradient_flux(self, dcoll, dd_bdry, state_minus, gas_model, **kwargs): interior=cv_int, exterior=cv_int) nhat = actx.thaw(dcoll.normal(dd_bdry)) - from mirgecom.flux import num_flux_central - from arraycontext import outer + + from mirgecom.flux import num_flux_central # Do not project to "all_faces" as now we use built-in grad_cv_operator return outer(num_flux_central(bnd_pair.int, bnd_pair.ext), nhat) diff --git a/test/test_bc.py b/test/test_bc.py index 9411b1b18..ec47d8f8c 100644 --- a/test/test_bc.py +++ b/test/test_bc.py @@ -38,6 +38,8 @@ from meshmode.discretization.connection import FACE_RESTR_ALL from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from pytools.obj_array import make_obj_array + from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas from mirgecom.fluid import make_conserved @@ -50,7 +52,6 @@ from mirgecom.initializers import Lump from mirgecom.inviscid import inviscid_facial_flux_hll, inviscid_facial_flux_rusanov from mirgecom.simutil import get_box_mesh -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/test/test_chemistry.py b/test/test_chemistry.py index 1ccef6613..16ace64ac 100644 --- a/test/test_chemistry.py +++ b/test/test_chemistry.py @@ -35,6 +35,8 @@ from meshmode.mesh.generation import generate_regular_rect_mesh import pyopencl as cl +from pytools.obj_array import make_obj_array + from mirgecom.discretization import create_discretization_collection from mirgecom.eos import PyrometheusMixture from mirgecom.fluid import make_conserved @@ -43,7 +45,6 @@ get_pyrometheus_wrapper_class, get_pyrometheus_wrapper_class_from_cantera, ) -from pytools.obj_array import make_obj_array @pytest.mark.parametrize(("mechname", "fuel", "rate_tol"), diff --git a/test/test_diffusion.py b/test/test_diffusion.py index 4da43592b..1e81f5d5a 100644 --- a/test/test_diffusion.py +++ b/test/test_diffusion.py @@ -36,6 +36,8 @@ ) from meshmode.dof_array import DOFArray +from pytools.obj_array import make_obj_array + import mirgecom.math as mm from mirgecom.diffusion import ( DirichletDiffusionBoundary, @@ -55,7 +57,6 @@ evaluate, grad as sym_grad, ) -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/test/test_eos.py b/test/test_eos.py index 5ce5b00c1..484d8402e 100644 --- a/test/test_eos.py +++ b/test/test_eos.py @@ -38,6 +38,8 @@ from meshmode.mesh.generation import generate_regular_rect_mesh import pyopencl as cl +from pytools.obj_array import make_obj_array + from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas, PyrometheusMixture from mirgecom.fluid import make_conserved @@ -45,7 +47,6 @@ from mirgecom.initializers import Lump, Uniform, Vortex2D from mirgecom.mechanisms import get_mechanism_input from mirgecom.thermochemistry import get_pyrometheus_wrapper_class_from_cantera -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/test/test_euler.py b/test/test_euler.py index a6a8fa065..73545942b 100644 --- a/test/test_euler.py +++ b/test/test_euler.py @@ -41,6 +41,11 @@ from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa import pyopencl.clmath # noqa +from pytools.obj_array import ( + flat_obj_array, + make_obj_array, +) + from mirgecom.boundary import DummyBoundary, PrescribedFluidBoundary from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas @@ -55,10 +60,6 @@ inviscid_facial_flux_rusanov, ) from mirgecom.simutil import max_component_norm -from pytools.obj_array import ( - flat_obj_array, - make_obj_array, -) logger = logging.getLogger(__name__) diff --git a/test/test_filter.py b/test/test_filter.py index 8848c0e2c..a64d25ef1 100644 --- a/test/test_filter.py +++ b/test/test_filter.py @@ -32,9 +32,10 @@ pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, ) +from pytools.obj_array import make_obj_array + from mirgecom.discretization import create_discretization_collection from mirgecom.filter import make_spectral_filter -from pytools.obj_array import make_obj_array @pytest.mark.parametrize("dim", [1, 2, 3]) diff --git a/test/test_fluid.py b/test/test_fluid.py index d534ded65..a5300b208 100644 --- a/test/test_fluid.py +++ b/test/test_fluid.py @@ -36,9 +36,10 @@ ) import pyopencl.clmath # noqa +from pytools.obj_array import make_obj_array + from mirgecom.discretization import create_discretization_collection from mirgecom.fluid import make_conserved -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/test/test_flux.py b/test/test_flux.py index dd3bae85c..db532e925 100644 --- a/test/test_flux.py +++ b/test/test_flux.py @@ -39,11 +39,12 @@ from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa import pyopencl.clmath # noqa +from pytools.obj_array import make_obj_array + from mirgecom.eos import IdealSingleGas from mirgecom.fluid import make_conserved from mirgecom.gas_model import GasModel, make_fluid_state from mirgecom.inviscid import inviscid_flux -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/test/test_init.py b/test/test_init.py index 190a58a55..8a63e560e 100644 --- a/test/test_init.py +++ b/test/test_init.py @@ -34,14 +34,15 @@ import pyopencl as cl import pyopencl.clmath import pyopencl.clrandom -from mirgecom.discretization import create_discretization_collection -from mirgecom.eos import IdealSingleGas -from mirgecom.initializers import Lump, MulticomponentLump, SodShock1D, Vortex2D from pyopencl.tools import ( # noqa pytest_generate_tests_for_pyopencl as pytest_generate_tests, ) from pytools.obj_array import make_obj_array +from mirgecom.discretization import create_discretization_collection +from mirgecom.eos import IdealSingleGas +from mirgecom.initializers import Lump, MulticomponentLump, SodShock1D, Vortex2D + logger = logging.getLogger(__name__) diff --git a/test/test_inviscid.py b/test/test_inviscid.py index 6ee23d539..b40ea7d69 100644 --- a/test/test_inviscid.py +++ b/test/test_inviscid.py @@ -40,6 +40,11 @@ from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa import pyopencl.clmath # noqa +from pytools.obj_array import ( + flat_obj_array, + make_obj_array, +) + from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas from mirgecom.fluid import make_conserved @@ -48,10 +53,6 @@ inviscid_facial_flux_rusanov, inviscid_flux, ) -from pytools.obj_array import ( - flat_obj_array, - make_obj_array, -) logger = logging.getLogger(__name__) diff --git a/test/test_lazy.py b/test/test_lazy.py index 7382833ee..90763703e 100644 --- a/test/test_lazy.py +++ b/test/test_lazy.py @@ -39,9 +39,10 @@ import pyopencl.array as cla # noqa import pyopencl.clmath as clmath # noqa import pyopencl.tools as cl_tools -from mirgecom.discretization import create_discretization_collection from pytools.obj_array import make_obj_array, obj_array_vectorize # noqa +from mirgecom.discretization import create_discretization_collection + logger = logging.getLogger(__name__) @@ -79,9 +80,9 @@ def get_dcoll(order): # Mimics math.isclose for state arrays def _isclose(dcoll, x, y, rel_tol=1e-9, abs_tol=0, return_operands=False): - from mirgecom.simutil import componentwise_norms - from arraycontext import flatten + + from mirgecom.simutil import componentwise_norms actx = x.array_context lhs = actx.to_numpy(flatten(componentwise_norms(dcoll, x - y, np.inf), actx)) diff --git a/test/test_multiphysics.py b/test/test_multiphysics.py index 367a3e692..9e9ea7066 100644 --- a/test/test_multiphysics.py +++ b/test/test_multiphysics.py @@ -32,9 +32,11 @@ pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, ) -import mirgecom.math as mm import pyopencl.array as cla # noqa import pyopencl.clmath as clmath # noqa +from pytools.obj_array import make_obj_array + +import mirgecom.math as mm from mirgecom.boundary import ( AdiabaticNoslipWallBoundary, IsothermalWallBoundary, @@ -53,7 +55,6 @@ ) from mirgecom.simutil import get_box_mesh, max_component_norm from mirgecom.transport import SimpleTransport -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/test/test_navierstokes.py b/test/test_navierstokes.py index a4ec6e51f..aaf0bc21b 100644 --- a/test/test_navierstokes.py +++ b/test/test_navierstokes.py @@ -39,8 +39,13 @@ from meshmode.dof_array import DOFArray from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa -import mirgecom.math as mm import pyopencl.clmath # noqa +from pytools.obj_array import ( + flat_obj_array, + make_obj_array, +) + +import mirgecom.math as mm from mirgecom.boundary import ( DummyBoundary, PrescribedFluidBoundary, @@ -53,10 +58,6 @@ from mirgecom.simutil import compare_fluid_solutions, componentwise_norms, get_box_mesh from mirgecom.symbolic import diff as sym_diff, evaluate from mirgecom.transport import SimpleTransport -from pytools.obj_array import ( - flat_obj_array, - make_obj_array, -) logger = logging.getLogger(__name__) diff --git a/test/test_operators.py b/test/test_operators.py index 435c9ecc4..54d7b7252 100644 --- a/test/test_operators.py +++ b/test/test_operators.py @@ -170,16 +170,16 @@ def test_grad_operator(actx_factory, dim, mesh_name, rot_axis, wonk, - trig funcs - :class:`~mirgecom.fluid.ConservedVars` composed of funcs from above """ + from arraycontext import flatten from grudge.array_context import PyOpenCLArrayContext from grudge.dt_utils import h_max_from_volume from meshmode.mesh.processing import map_mesh, rotate_mesh_around_axis import pyopencl as cl + from mirgecom.operators import grad_operator from mirgecom.simutil import componentwise_norms - from arraycontext import flatten - def add_wonk(x: np.ndarray) -> np.ndarray: wonk_field = np.empty_like(x) if len(x) >= 2: diff --git a/test/test_restart.py b/test/test_restart.py index b1a0d7292..f772a67a4 100644 --- a/test/test_restart.py +++ b/test/test_restart.py @@ -33,9 +33,10 @@ pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, ) -from mirgecom.discretization import create_discretization_collection from pytools.obj_array import make_obj_array +from mirgecom.discretization import create_discretization_collection + logger = logging.getLogger(__name__) diff --git a/test/test_simutil.py b/test/test_simutil.py index 67295d135..303767c08 100644 --- a/test/test_simutil.py +++ b/test/test_simutil.py @@ -26,16 +26,15 @@ import numpy as np import pytest # noqa - -from mirgecom.discretization import create_discretization_collection -from mirgecom.eos import IdealSingleGas -from mirgecom.fluid import make_conserved - from arraycontext import ( # noqa flatten, pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, ) +from mirgecom.discretization import create_discretization_collection +from mirgecom.eos import IdealSingleGas +from mirgecom.fluid import make_conserved + def test_basic_cfd_healthcheck(actx_factory): """Quick test of some health checking utilities.""" diff --git a/test/test_symbolic.py b/test/test_symbolic.py index 8a36e9abd..cb636e57d 100644 --- a/test/test_symbolic.py +++ b/test/test_symbolic.py @@ -31,12 +31,13 @@ ) from meshmode.mesh.generation import generate_regular_rect_mesh -import mirgecom.symbolic as sym import pyopencl.array as cla # noqa import pyopencl.clmath as clmath # noqa -from mirgecom.discretization import create_discretization_collection from pytools.obj_array import make_obj_array +import mirgecom.symbolic as sym +from mirgecom.discretization import create_discretization_collection + logger = logging.getLogger(__name__) diff --git a/test/test_transport.py b/test/test_transport.py index 3951f5b45..eee37f624 100644 --- a/test/test_transport.py +++ b/test/test_transport.py @@ -39,6 +39,11 @@ from meshmode.mesh.generation import generate_regular_rect_mesh import pyopencl as cl +from pyopencl.tools import ( # noqa + pytest_generate_tests_for_pyopencl as pytest_generate_tests, +) +from pytools.obj_array import make_obj_array + from mirgecom.discretization import create_discretization_collection from mirgecom.eos import PyrometheusMixture from mirgecom.fluid import make_conserved @@ -49,10 +54,6 @@ get_pyrometheus_wrapper_class_from_cantera, ) from mirgecom.transport import MixtureAveragedTransport -from pyopencl.tools import ( # noqa - pytest_generate_tests_for_pyopencl as pytest_generate_tests, -) -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/test/test_viscous.py b/test/test_viscous.py index 855e44e8d..f18a72f90 100644 --- a/test/test_viscous.py +++ b/test/test_viscous.py @@ -40,13 +40,14 @@ from meshmode.mesh import BTAG_ALL import pyopencl.clmath # noqa +from pytools.obj_array import make_obj_array + from mirgecom.discretization import create_discretization_collection from mirgecom.eos import IdealSingleGas from mirgecom.fluid import make_conserved from mirgecom.gas_model import GasModel, make_fluid_state from mirgecom.simutil import get_box_mesh from mirgecom.transport import PowerLawTransport, SimpleTransport -from pytools.obj_array import make_obj_array logger = logging.getLogger(__name__) diff --git a/test/test_wallmodel.py b/test/test_wallmodel.py index 84a29488e..7d4400297 100644 --- a/test/test_wallmodel.py +++ b/test/test_wallmodel.py @@ -28,9 +28,10 @@ pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, ) +from pytools.obj_array import make_obj_array + from mirgecom.discretization import create_discretization_collection from mirgecom.simutil import get_box_mesh -from pytools.obj_array import make_obj_array def test_tacot_decomposition(actx_factory): diff --git a/test/test_wave.py b/test/test_wave.py index 9cdae6857..32c7652cf 100644 --- a/test/test_wave.py +++ b/test/test_wave.py @@ -33,12 +33,13 @@ pytest_generate_tests_for_pyopencl_array_context as pytest_generate_tests, ) -import mirgecom.symbolic as sym import pyopencl.array as cla # noqa import pyopencl.clmath as clmath # noqa +from pytools.obj_array import flat_obj_array, make_obj_array + +import mirgecom.symbolic as sym from mirgecom.discretization import create_discretization_collection from mirgecom.wave import wave_operator -from pytools.obj_array import flat_obj_array, make_obj_array logger = logging.getLogger(__name__) From 97c8d442b177d4079e4743362eb45eb99a6bf4fe Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Mon, 22 Jul 2024 19:10:57 -0500 Subject: [PATCH 3/3] Become ruffian --- .github/workflows/ci.yaml | 19 +++++---------- examples/advdiff-tpe.py | 2 +- examples/advection_diffusion_reaction.py | 4 ++-- examples/combozzle.py | 2 +- examples/doublemach_physical_av.py | 4 ++-- examples/gas-in-box.py | 2 +- examples/heat-source.py | 2 +- examples/hotplate.py | 2 +- examples/lump.py | 2 +- examples/mixture-tpe.py | 4 ++-- examples/mixture.py | 4 ++-- examples/multiple-volumes.py | 5 ++-- examples/orthotropic-diffusion.py | 2 +- examples/poiseuille-multispecies.py | 2 +- examples/poiseuille-tpe.py | 2 +- examples/poiseuille.py | 2 +- examples/scalar-advdiff.py | 2 +- examples/scalar-lump.py | 2 +- examples/sod.py | 2 +- examples/vortex.py | 2 +- mirgecom/artificial_viscosity.py | 2 +- mirgecom/fluid.py | 2 +- mirgecom/mpi.py | 2 +- mirgecom/profiling.py | 6 ++--- mirgecom/simutil.py | 30 ++++++++++++------------ pyproject.toml | 4 ++++ test/test_bc.py | 2 +- test/test_diffusion.py | 2 +- test/test_eos.py | 2 +- test/test_euler.py | 12 +++++----- test/test_fluid.py | 4 ++-- test/test_inviscid.py | 2 +- test/test_navierstokes.py | 2 +- test/test_time_integrators.py | 5 ++-- test/test_viscous.py | 10 ++++---- test/test_wave.py | 2 +- 36 files changed, 76 insertions(+), 81 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c2f462aaa..20e31a9c2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,23 +14,16 @@ concurrency: cancel-in-progress: true jobs: - flake8: - name: Flake8 + ruff: + name: Ruff runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - - uses: actions/setup-python@v5 - with: - # matches compat target in setup.py - python-version: '3.8' - - name: Flake8 test + - uses: actions/setup-python@v5 + - name: Run ruff run: | - python3 -m venv myenv - source myenv/bin/activate - python -m pip install wheel - python -m pip install flake8 pep8-naming flake8-quotes flake8-bugbear - python -m flake8 --show-source --statistics "$(basename $GITHUB_REPOSITORY)" test examples setup.py doc/conf.py bin/ && echo "Flake8 found no errors." + pip install ruff + ruff check mypy: name: Mypy diff --git a/examples/advdiff-tpe.py b/examples/advdiff-tpe.py index 9438ab4cb..1575bd2e7 100644 --- a/examples/advdiff-tpe.py +++ b/examples/advdiff-tpe.py @@ -308,7 +308,7 @@ def my_write_status(component_errors): if rank == 0: logger.info( "------- errors=" - + ", ".join("%.3g" % en for en in component_errors)) + + ", ".join(f"{en:.3g}" for en in component_errors)) def my_write_viz(step, t, cv, dv, exact): resid = cv - exact diff --git a/examples/advection_diffusion_reaction.py b/examples/advection_diffusion_reaction.py index b1c31a431..fd671e2e9 100644 --- a/examples/advection_diffusion_reaction.py +++ b/examples/advection_diffusion_reaction.py @@ -108,7 +108,7 @@ def linear_advection_operator(dcoll, u, u_bc, *, comm_tag=None): el_bnd_flux = ( _facial_flux(dcoll, u_tpair=TracePair(dd=dd.with_domain_tag(BTAG_ALL), interior=u_bnd, exterior=u_bc)) - + sum([_facial_flux(dcoll, u_tpair=tpair) for tpair in itp])) + + sum(_facial_flux(dcoll, u_tpair=tpair) for tpair in itp)) # volume term vol_flux = op.weak_local_d_dx(dcoll, 0, u) @@ -303,7 +303,7 @@ def my_rhs(t, u): # ~~~ compute BC error dd = DD_VOLUME_ALL - visc, grad = diffusion_operator(dcoll, kappa=kappa, boundaries=boundaries, + _visc, grad = diffusion_operator(dcoll, kappa=kappa, boundaries=boundaries, u=current_cv, penalty_amount=0.0, return_grad_u=True) diff --git a/examples/combozzle.py b/examples/combozzle.py index 34882ec99..e3e4f5014 100644 --- a/examples/combozzle.py +++ b/examples/combozzle.py @@ -1052,7 +1052,7 @@ def my_pre_step(step, t, dt, state): return state, dt def my_post_step(step, t, dt, state): - cv, tseed = state + cv, _tseed = state if logmgr: set_dt(logmgr, dt) diff --git a/examples/doublemach_physical_av.py b/examples/doublemach_physical_av.py index 56823c8c5..05750e98c 100644 --- a/examples/doublemach_physical_av.py +++ b/examples/doublemach_physical_av.py @@ -540,7 +540,7 @@ def my_pre_step(step, t, dt, state): if do_viz: my_write_viz(step=step, t=t, fluid_state=fluid_state) - ts_field, cfl, dt = my_get_timestep(t, dt, fluid_state) + _ts_field, cfl, dt = my_get_timestep(t, dt, fluid_state) if do_health: health_errors = \ @@ -677,7 +677,7 @@ def _my_rhs_phys_visc_div_av(t, state): current_state = replace(current_state, dv=new_dv) final_dv = current_state.dv - ts_field, cfl, dt = my_get_timestep(t=current_t, dt=current_dt, + _ts_field, cfl, dt = my_get_timestep(t=current_t, dt=current_dt, state=current_state) my_write_status(dt=dt, cfl=cfl, cv=current_cv, dv=final_dv) my_write_viz(step=current_step, t=current_t, fluid_state=current_state) diff --git a/examples/gas-in-box.py b/examples/gas-in-box.py index 4ac7b701a..df1ee7816 100644 --- a/examples/gas-in-box.py +++ b/examples/gas-in-box.py @@ -268,7 +268,7 @@ def add_wonk(x: np.ndarray) -> np.ndarray: # Pull temperature, total density, mass fractions, and pressure # from Cantera. We need total density, and mass fractions to initialize # the fluid/gas state. - can_t, can_rho, can_y = cantera_soln.TDY + can_t, _can_rho, can_y = cantera_soln.TDY can_p = cantera_soln.P # *can_t*, *can_p* should not differ (significantly) from user's # initial data, but we want to ensure that we use exactly the same diff --git a/examples/heat-source.py b/examples/heat-source.py index a334fe104..3c220763f 100644 --- a/examples/heat-source.py +++ b/examples/heat-source.py @@ -217,7 +217,7 @@ def my_post_step(step, t, dt, state): return state, dt from mirgecom.steppers import advance_state - current_step, current_t, advanced_state = \ + _current_step, _current_t, advanced_state = \ advance_state(rhs=my_rhs, timestepper=rk4_step, pre_step_callback=my_pre_step, post_step_callback=my_post_step, dt=dt, state=u, t=t, diff --git a/examples/hotplate.py b/examples/hotplate.py index 6efdc0b5e..7c0dca8fe 100644 --- a/examples/hotplate.py +++ b/examples/hotplate.py @@ -257,7 +257,7 @@ def my_write_status(step, t, dt, state, component_errors): f"----- Pressure({p_min}, {p_max})\n" f"----- Temperature({t_min}, {t_max})\n" "----- errors=" - + ", ".join("%.3g" % en for en in component_errors)) + + ", ".join(f"{en:.3g}" for en in component_errors)) def my_write_viz(step, t, state, dv): resid = state - exact diff --git a/examples/lump.py b/examples/lump.py index 5acced971..5fd16e9bd 100644 --- a/examples/lump.py +++ b/examples/lump.py @@ -298,7 +298,7 @@ def my_pre_step(step, t, dt, state): component_errors = compare_fluid_solutions(dcoll, state, exact) status_msg = ( "------- errors=" - + ", ".join("%.3g" % en for en in component_errors)) + + ", ".join(f"{en:.3g}" for en in component_errors)) if rank == 0: logger.info(status_msg) diff --git a/examples/mixture-tpe.py b/examples/mixture-tpe.py index 14943f4c8..05727c9de 100644 --- a/examples/mixture-tpe.py +++ b/examples/mixture-tpe.py @@ -187,7 +187,7 @@ def main(actx_class, use_esdg=False, y0s = np.zeros(shape=(nspecies,)) for i in range(nspecies-1): y0s[i] = 1.0 / (10.0 ** (i + 1)) - spec_sum = sum([y0s[i] for i in range(nspecies-1)]) + spec_sum = sum(y0s[i] for i in range(nspecies-1)) y0s[nspecies-1] = 1.0 - spec_sum # Mixture defaults to STP (p, T) = (1atm, 300K) @@ -247,7 +247,7 @@ def get_fluid_state(cv, tseed): def my_write_status(component_errors, dv=None): status_msg = ( "------- errors=" - + ", ".join("%.3g" % en for en in component_errors)) + + ", ".join(f"{en:.3g}" for en in component_errors)) if ((dv is not None) and (not log_dependent)): temp = dv.temperature press = dv.pressure diff --git a/examples/mixture.py b/examples/mixture.py index 6a5b79d4c..7150ee176 100644 --- a/examples/mixture.py +++ b/examples/mixture.py @@ -181,7 +181,7 @@ def main(actx_class, use_esdg=False, y0s = np.zeros(shape=(nspecies,)) for i in range(nspecies-1): y0s[i] = 1.0 / (10.0 ** (i + 1)) - spec_sum = sum([y0s[i] for i in range(nspecies-1)]) + spec_sum = sum(y0s[i] for i in range(nspecies-1)) y0s[nspecies-1] = 1.0 - spec_sum # Mixture defaults to STP (p, T) = (1atm, 300K) @@ -241,7 +241,7 @@ def get_fluid_state(cv, tseed): def my_write_status(component_errors, dv=None): status_msg = ( "------- errors=" - + ", ".join("%.3g" % en for en in component_errors)) + + ", ".join(f"{en:.3g}" for en in component_errors)) if ((dv is not None) and (not log_dependent)): temp = dv.temperature press = dv.pressure diff --git a/examples/multiple-volumes.py b/examples/multiple-volumes.py index 209428d3e..152b7004f 100644 --- a/examples/multiple-volumes.py +++ b/examples/multiple-volumes.py @@ -233,10 +233,9 @@ def init(nodes, pulse_amplitude): logger.info(init_message) def my_get_timestep(step, t, dt, fluid_states): - return min([ - get_sim_timestep( + return min(get_sim_timestep( dcoll, fluid_state, t, dt, current_cfl, t_final, constant_cfl) - for fluid_state in fluid_states]) + for fluid_state in fluid_states) def my_write_viz(step, t, cvs, dvs=None): if dvs is None: diff --git a/examples/orthotropic-diffusion.py b/examples/orthotropic-diffusion.py index c1f098a3e..a0268472e 100644 --- a/examples/orthotropic-diffusion.py +++ b/examples/orthotropic-diffusion.py @@ -184,7 +184,7 @@ def my_post_step(step, t, dt, state): return state, dt from mirgecom.steppers import advance_state - current_step, current_t, advanced_state = \ + _current_step, _current_t, _advanced_state = \ advance_state(rhs=my_rhs, timestepper=rk4_step, pre_step_callback=my_pre_step, post_step_callback=my_post_step, dt=dt, state=u, t=t, diff --git a/examples/poiseuille-multispecies.py b/examples/poiseuille-multispecies.py index 9748d9572..975f533e7 100644 --- a/examples/poiseuille-multispecies.py +++ b/examples/poiseuille-multispecies.py @@ -297,7 +297,7 @@ def my_write_status(step, t, dt, state, component_errors): f"----- Pressure({p_min}, {p_max})\n" f"----- Temperature({t_min}, {t_max})\n" "----- errors=" - + ", ".join("%.3g" % en for en in component_errors)) + + ", ".join(f"{en:.3g}" for en in component_errors)) def my_write_viz(step, t, state, dv): resid = state - exact diff --git a/examples/poiseuille-tpe.py b/examples/poiseuille-tpe.py index 3082145ab..690cb1a3e 100644 --- a/examples/poiseuille-tpe.py +++ b/examples/poiseuille-tpe.py @@ -291,7 +291,7 @@ def my_write_status(step, t, dt, state, component_errors): f"----- Pressure({p_min}, {p_max})\n" f"----- Temperature({t_min}, {t_max})\n" "----- errors=" - + ", ".join("%.3g" % en for en in component_errors)) + + ", ".join(f"{en:.3g}" for en in component_errors)) def my_write_viz(step, t, state, dv): resid = state - exact diff --git a/examples/poiseuille.py b/examples/poiseuille.py index 09a8469b0..5d1745a6e 100644 --- a/examples/poiseuille.py +++ b/examples/poiseuille.py @@ -287,7 +287,7 @@ def my_write_status(step, t, dt, state, component_errors): f"----- Pressure({p_min}, {p_max})\n" f"----- Temperature({t_min}, {t_max})\n" "----- errors=" - + ", ".join("%.3g" % en for en in component_errors)) + + ", ".join(f"{en:.3g}" for en in component_errors)) def my_write_viz(step, t, state, dv): resid = state - exact diff --git a/examples/scalar-advdiff.py b/examples/scalar-advdiff.py index 46914d27a..673187544 100644 --- a/examples/scalar-advdiff.py +++ b/examples/scalar-advdiff.py @@ -303,7 +303,7 @@ def my_write_status(component_errors): if rank == 0: logger.info( "------- errors=" - + ", ".join("%.3g" % en for en in component_errors)) + + ", ".join(f"{en:.3g}" for en in component_errors)) def my_write_viz(step, t, cv, dv, exact): resid = cv - exact diff --git a/examples/scalar-lump.py b/examples/scalar-lump.py index e19644b42..a7571e317 100644 --- a/examples/scalar-lump.py +++ b/examples/scalar-lump.py @@ -214,7 +214,7 @@ def my_write_status(component_errors): if rank == 0: logger.info( "------- errors=" - + ", ".join("%.3g" % en for en in component_errors)) + + ", ".join(f"{en:.3g}" for en in component_errors)) def my_write_viz(step, t, state, dv=None, exact=None, resid=None): if dv is None: diff --git a/examples/sod.py b/examples/sod.py index 366df0bca..c014206ff 100644 --- a/examples/sod.py +++ b/examples/sod.py @@ -212,7 +212,7 @@ def my_write_status(component_errors): if rank == 0: logger.info( "------- errors=" - + ", ".join("%.3g" % en for en in component_errors) + + ", ".join(f"{en:.3g}" for en in component_errors) ) def my_write_viz(step, t, state, dv=None, exact=None, resid=None): diff --git a/examples/vortex.py b/examples/vortex.py index 7f8185ca8..a97d0eaab 100644 --- a/examples/vortex.py +++ b/examples/vortex.py @@ -229,7 +229,7 @@ def my_write_status(state, component_errors, cfl=None): logger.info( f"------ {cfl=}\n" "------- errors=" - + ", ".join("%.3g" % en for en in component_errors)) + + ", ".join(f"{en:.3g}" for en in component_errors)) def my_write_viz(step, t, state, dv=None, exact=None, resid=None): if exact is None: diff --git a/mirgecom/artificial_viscosity.py b/mirgecom/artificial_viscosity.py index 541ed8fb7..631c0c160 100644 --- a/mirgecom/artificial_viscosity.py +++ b/mirgecom/artificial_viscosity.py @@ -355,7 +355,7 @@ def interp_to_vol_quad(u): dcoll, fluid_state, gas_model, boundaries, quadrature_tag, dd=dd_vol, comm_tag=comm_tag) - vol_state_quad, inter_elem_bnd_states_quad, domain_bnd_states_quad = \ + _vol_state_quad, _inter_elem_bnd_states_quad, _domain_bnd_states_quad = \ operator_states_quad # Get smoothness indicator based on mass component diff --git a/mirgecom/fluid.py b/mirgecom/fluid.py index 0594e1791..32562193c 100644 --- a/mirgecom/fluid.py +++ b/mirgecom/fluid.py @@ -324,7 +324,7 @@ def _join_conserved(dim, mass, energy, momentum, species_mass=None): from pytools import single_valued aux_shape = single_valued(aux_shapes) - result = np.empty((2+dim+nspec,) + aux_shape, dtype=object) + result = np.empty((2 + dim + nspec, *aux_shape), dtype=object) result[0] = mass result[1] = energy result[2:dim+2] = momentum diff --git a/mirgecom/mpi.py b/mirgecom/mpi.py index d56264f65..05d3d6d7e 100644 --- a/mirgecom/mpi.py +++ b/mirgecom/mpi.py @@ -70,7 +70,7 @@ def _check_isl_version() -> None: import islpy # type: ignore[import-untyped] try: - ctypes.cdll.LoadLibrary(islpy._isl.__file__).isl_val_get_num_gmp + ctypes.cdll.LoadLibrary(islpy._isl.__file__).isl_val_get_num_gmp # noqa: B018 except AttributeError: # We are running with imath or imath-32. pass diff --git a/mirgecom/profiling.py b/mirgecom/profiling.py index 32845e953..941d3b479 100644 --- a/mirgecom/profiling.py +++ b/mirgecom/profiling.py @@ -296,7 +296,7 @@ def tabulate_profiling_data(self) -> pytools.Table: fprint_min, fprint_mean, fprint_max, bytes_per_flop_mean)) - tbl.add_row(("Total", total_calls, f"{total_time:{g}}") + tuple(["--"] * 13)) + tbl.add_row(("Total", total_calls, f"{total_time:{g}}", *tuple(["--"] * 13))) return tbl @@ -346,8 +346,8 @@ def _cache_kernel_stats(self, t_unit: lp.TranslationUnit, kwargs: dict) \ wrapper.generate_integer_arg_finding_from_strides(gen, kernel, idi) param_names = kernel.all_params() - gen("return {%s}" % ", ".join( - f"{name!r}: {name}" for name in param_names)) + gen("return {{{}}}".format(", ".join( + f"{name!r}: {name}" for name in param_names))) # Run the wrapper code, save argument values in domain_params domain_params = gen.get_picklable_function()(**param_dict) diff --git a/mirgecom/simutil.py b/mirgecom/simutil.py index a0ee535e4..ffdacdf69 100644 --- a/mirgecom/simutil.py +++ b/mirgecom/simutil.py @@ -825,9 +825,9 @@ def geometric_mesh_partitioner(mesh, num_ranks=None, *, nranks_per_axis=None, print(f"-Part({adv_part}): {nelem_part[adv_part]=}") # Validate the partitioning before returning - total_partitioned_elements = sum([len(part_to_elements[r]) - for r in range(num_ranks)]) - total_nelem_part = sum([nelem_part[r] for r in range(num_ranks)]) + total_partitioned_elements = sum(len(part_to_elements[r]) + for r in range(num_ranks)) + total_nelem_part = sum(nelem_part[r] for r in range(num_ranks)) if debug: print("Validating mesh parts.") @@ -1165,7 +1165,7 @@ def boundary_report(dcoll, boundaries, outfile_name, *, dd=DD_VOLUME_ALL, for bdtag in boundaries: boundary_discr = dcoll.discr_from_dd(bdtag) - nnodes = sum([grp.ndofs for grp in boundary_discr.groups]) + nnodes = sum(grp.ndofs for grp in boundary_discr.groups) local_report.write(f"{bdtag}: {nnodes}\n") from meshmode.distributed import get_connected_parts @@ -1177,7 +1177,7 @@ def boundary_report(dcoll, boundaries, outfile_name, *, dd=DD_VOLUME_ALL, for connected_part_id in connected_part_ids: boundary_discr = dcoll.discr_from_dd( dd.trace(BTAG_PARTITION(connected_part_id))) - nnodes = sum([grp.ndofs for grp in boundary_discr.groups]) + nnodes = sum(grp.ndofs for grp in boundary_discr.groups) part_nodes.append(nnodes) if part_nodes: local_report.write(f"nnodes_pb: {part_nodes}\n") @@ -1376,12 +1376,12 @@ def numranks(filename: str) -> int: if ignore_field: continue - max_true_component = max([max(abs(arr2.GetComponent(j, icomp)) + max_true_component = max(max(abs(arr2.GetComponent(j, icomp)) for j in range(num_points)) - for icomp in range(num_components)]) - max_other_component = max([max(abs(arr1.GetComponent(j, icomp)) + for icomp in range(num_components)) + max_other_component = max(max(abs(arr1.GetComponent(j, icomp)) for j in range(num_points)) - for icomp in range(num_components)]) + for icomp in range(num_components)) # FIXME # Choose an arbitrary "level" to define what is a "significant" field @@ -1575,8 +1575,8 @@ def compare_files_xdmf(first_file: str, second_file: str, tolerance: float = 1e- raise ValueError("Fidelity test failed: Mismatched topology type") # check number of connectivity values - connectivities1 = file_reader1.read_data_item(tuple(top1)[0]) - connectivities2 = file_reader2.read_data_item(tuple(top2)[0]) + connectivities1 = file_reader1.read_data_item(next(iter(top1))) + connectivities2 = file_reader2.read_data_item(next(iter(top2))) connectivities1 = np.array(connectivities1) connectivities2 = np.array(connectivities2) @@ -1602,8 +1602,8 @@ def compare_files_xdmf(first_file: str, second_file: str, tolerance: float = 1e- raise ValueError("Fidelity test failed: Mismatched geometry type") # check number of node values - nodes1 = file_reader1.read_data_item(tuple(geo1)[0]) - nodes2 = file_reader2.read_data_item(tuple(geo2)[0]) + nodes1 = file_reader1.read_data_item(next(iter(geo1))) + nodes2 = file_reader2.read_data_item(next(iter(geo2))) nodes1 = np.array(nodes1) nodes2 = np.array(nodes2) @@ -1640,8 +1640,8 @@ def compare_files_xdmf(first_file: str, second_file: str, tolerance: float = 1e- raise ValueError("Fidelity test failed: Mismatched cell name") # check number of Attribute values - values1 = file_reader1.read_data_item(tuple(curr_cell1)[0]) - values2 = file_reader2.read_data_item(tuple(curr_cell2)[0]) + values1 = file_reader1.read_data_item(next(iter(curr_cell1))) + values2 = file_reader2.read_data_item(next(iter(curr_cell2))) if len(values1) != len(values2): print("File 1,", curr_cell1.get("Name"), ":", len(values1), "\n", diff --git a/pyproject.toml b/pyproject.toml index ec9e71bf6..bb531a202 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,12 +18,16 @@ extend-select = [ "W", # pycodestyle ] extend-ignore = [ + "B023", # Function definition does not bind loop variable" "C90", # McCabe complexity "E221", # multiple spaces before operator "E226", # missing whitespace around arithmetic operator "E402", # module-level import not at top of file "UP006", # updated annotations due to __future__ import "UP007", # updated annotations due to __future__ import + "B028", # No explicit `stacklevel` keyword argument + "G003", # Logging statement uses `+` + "G004", # Logging statement uses f-string ] [tool.ruff.lint.flake8-quotes] diff --git a/test/test_bc.py b/test/test_bc.py index ec47d8f8c..d59d6fe58 100644 --- a/test/test_bc.py +++ b/test/test_bc.py @@ -1074,7 +1074,7 @@ def test_slipwall_flux(actx_factory, dim, order, flux_func): h = 1.0 / nel_1d def bnd_norm(vec): - return actx.to_numpy(op.norm(dcoll, vec, p=np.inf, dd=BTAG_ALL)) # noqa + return actx.to_numpy(op.norm(dcoll, vec, p=np.inf, dd=BTAG_ALL)) logger.info(f"Number of {dim}d elems: {mesh.nelements}") # for velocities in each direction diff --git a/test/test_diffusion.py b/test/test_diffusion.py index 1e81f5d5a..ed1f4d593 100644 --- a/test/test_diffusion.py +++ b/test/test_diffusion.py @@ -540,7 +540,7 @@ def get_rhs(t, u, return_grad_u=False): from numpy.random import rand perturb_np = np.empty((n, order+1), dtype=float) for i in range(n): - perturb_np[i, :] = 0.1*(rand()-0.5) + perturb_np[i, :] = 0.1*(rand()-0.5) # noqa: NPY002 perturb = DOFArray(actx, (actx.from_numpy(perturb_np),)) u = u_steady + perturb diff --git a/test/test_eos.py b/test/test_eos.py index 484d8402e..a9ef7a688 100644 --- a/test/test_eos.py +++ b/test/test_eos.py @@ -423,7 +423,7 @@ def inf_norm(x): yin = y0s * ones # avoid starting too far from the actual temperature - tguess = tempin + ones*100.0*np.random.random() + tguess = tempin + ones*100.0*np.random.random() # noqa: NPY002 assert inf_norm(tguess) > 0.0 pyro_rho = pyro_mechanism.get_density(pin, tin, yin) diff --git a/test/test_euler.py b/test/test_euler.py index 73545942b..3c5f4caac 100644 --- a/test/test_euler.py +++ b/test/test_euler.py @@ -158,7 +158,7 @@ def test_uniform_rhs(actx_factory, nspecies, dim, order, use_overintegration, ) def inf_norm(x): - return actx.to_numpy(op.norm(dcoll, x, np.inf)) # noqa + return actx.to_numpy(op.norm(dcoll, x, np.inf)) assert inf_norm(rho_resid) < tolerance assert inf_norm(rhoe_resid) < tolerance @@ -319,7 +319,7 @@ def test_entropy_to_conserved_conversion(actx_factory, nspecies, dim, order): ) def inf_norm(x): - return actx.to_numpy(op.norm(dcoll, x, np.inf)) # noqa + return actx.to_numpy(op.norm(dcoll, x, np.inf)) assert inf_norm(rho_resid) < tolerance assert inf_norm(rhoe_resid) < tolerance @@ -436,7 +436,7 @@ def _vortex_boundary(dcoll, dd_bdry, gas_model, state_minus, **kwargs): actx = state_minus.array_context bnd_discr = dcoll.discr_from_dd(dd_bdry) nodes = actx.thaw(bnd_discr.nodes()) - return make_fluid_state(vortex(x_vec=nodes, **kwargs), gas_model) # noqa + return make_fluid_state(vortex(x_vec=nodes, **kwargs), gas_model) boundaries = { BTAG_ALL: PrescribedFluidBoundary(boundary_state_func=_vortex_boundary) @@ -516,7 +516,7 @@ def _lump_boundary(dcoll, dd_bdry, gas_model, state_minus, **kwargs): actx = state_minus.array_context bnd_discr = dcoll.discr_from_dd(dd_bdry) nodes = actx.thaw(bnd_discr.nodes()) - return make_fluid_state(lump(x_vec=nodes, cv=state_minus, **kwargs), # noqa + return make_fluid_state(lump(x_vec=nodes, cv=state_minus, **kwargs), gas_model) boundaries = { @@ -611,7 +611,7 @@ def _my_boundary(dcoll, dd_bdry, gas_model, state_minus, **kwargs): actx = state_minus.array_context bnd_discr = dcoll.discr_from_dd(dd_bdry) nodes = actx.thaw(bnd_discr.nodes()) - return make_fluid_state(lump(x_vec=nodes, **kwargs), gas_model) # noqa + return make_fluid_state(lump(x_vec=nodes, **kwargs), gas_model) boundaries = { BTAG_ALL: PrescribedFluidBoundary(boundary_state_func=_my_boundary) @@ -830,7 +830,7 @@ def _vortex_boundary(dcoll, dd_bdry, state_minus, gas_model, **kwargs): actx = state_minus.array_context bnd_discr = dcoll.discr_from_dd(dd_bdry) nodes = actx.thaw(bnd_discr.nodes()) - return make_fluid_state(initializer(x_vec=nodes, **kwargs), gas_model) # noqa + return make_fluid_state(initializer(x_vec=nodes, **kwargs), gas_model) boundaries = { BTAG_ALL: PrescribedFluidBoundary(boundary_state_func=_vortex_boundary) diff --git a/test/test_fluid.py b/test/test_fluid.py index a5300b208..26c315d13 100644 --- a/test/test_fluid.py +++ b/test/test_fluid.py @@ -224,8 +224,8 @@ def test_species_mass_gradient(actx_factory, dim): y = make_obj_array([ones for _ in range(nspecies)]) for idim in range(dim): ispec = 2*idim - y[ispec] = ispec*(idim*dim+1)*sum([(iidim+1)*nodes[iidim] - for iidim in range(dim)]) + y[ispec] = ispec*(idim*dim+1)*sum((iidim+1)*nodes[iidim] + for iidim in range(dim)) y[ispec+1] = -y[ispec] species_mass = mass*y diff --git a/test/test_inviscid.py b/test/test_inviscid.py index b40ea7d69..2821a4c1f 100644 --- a/test/test_inviscid.py +++ b/test/test_inviscid.py @@ -91,7 +91,7 @@ def rand(): from meshmode.dof_array import DOFArray return DOFArray( actx, - tuple(actx.from_numpy(np.random.rand(grp.nelements, grp.nunit_dofs)) + tuple(actx.from_numpy(np.random.rand(grp.nelements, grp.nunit_dofs)) # noqa: NPY002 for grp in dcoll.discr_from_dd("vol").groups) ) diff --git a/test/test_navierstokes.py b/test/test_navierstokes.py index aaf0bc21b..7773b611d 100644 --- a/test/test_navierstokes.py +++ b/test/test_navierstokes.py @@ -691,7 +691,7 @@ def _boundary_state_func(dcoll, dd_bdry, gas_model, state_minus, time=0, fluid_state = exact_fluid_state # Exact solution should have RHS=0, so the RHS itself is the residual - ns_rhs, grad_cv, grad_t = ns_operator(dcoll, gas_model=gas_model, + ns_rhs, grad_cv, _grad_t = ns_operator(dcoll, gas_model=gas_model, state=fluid_state, boundaries=boundaries, return_gradients=True) diff --git a/test/test_time_integrators.py b/test/test_time_integrators.py index 9c96752ec..acdfaf761 100644 --- a/test/test_time_integrators.py +++ b/test/test_time_integrators.py @@ -118,7 +118,7 @@ def rhs(t, state): t = 0*dt state = exact_soln(t) - advanced_step, advanced_t, advanced_state = \ + _advanced_step, advanced_t, advanced_state = \ advance_state(rhs=rhs, timestepper=integrator, dt=dt, state=state, t=t, t_final=t_final, max_steps=max_steps, local_dt=local_dt, @@ -196,9 +196,8 @@ def rhs(t, y): state = exact_soln(t) t_final = 4 - step = 0 - (step, t, state) = \ + (_step, t, state) = \ advance_state(rhs=rhs, timestepper=method, dt=dt, state=state, t=t, t_final=t_final, component_id="y") diff --git a/test/test_viscous.py b/test/test_viscous.py index f18a72f90..7f1387983 100644 --- a/test/test_viscous.py +++ b/test/test_viscous.py @@ -188,7 +188,7 @@ def cv_flux_boundary(dd_bdry): nodes = actx.thaw(dcoll.nodes()) def inf_norm(x): - return actx.to_numpy(op.norm(dcoll, x, np.inf)) # noqa + return actx.to_numpy(op.norm(dcoll, x, np.inf)) # compute max element size from grudge.dt_utils import h_max_from_volume @@ -301,8 +301,8 @@ def test_species_diffusive_flux(actx_factory): y = make_obj_array([ones for _ in range(nspecies)]) for idim in range(dim): ispec = 2*idim - y[ispec] = (ispec+1)*(idim*dim+1)*sum([(iidim+1)*nodes[iidim] - for iidim in range(dim)]) + y[ispec] = (ispec+1)*(idim*dim+1)*sum((iidim+1)*nodes[iidim] + for iidim in range(dim)) y[ispec+1] = -y[ispec] massval = 2 @@ -379,8 +379,8 @@ def test_diffusive_heat_flux(actx_factory): y = make_obj_array([ones for _ in range(nspecies)]) for idim in range(dim): ispec = 2*idim - y[ispec] = (ispec+1)*(idim*dim+1)*sum([(iidim+1)*nodes[iidim] - for iidim in range(dim)]) + y[ispec] = (ispec+1)*(idim*dim+1)*sum((iidim+1)*nodes[iidim] + for iidim in range(dim)) y[ispec+1] = -y[ispec] # create a gradient of temperature diff --git a/test/test_wave.py b/test/test_wave.py index 32c7652cf..1c345083a 100644 --- a/test/test_wave.py +++ b/test/test_wave.py @@ -223,7 +223,7 @@ def test_wave_stability(actx_factory, problem, timestep_scale, order, p = problem - sym_u, sym_v, sym_f, sym_rhs = sym_wave(p.dim, p.sym_phi) + sym_u, sym_v, sym_f, _sym_rhs = sym_wave(p.dim, p.sym_phi) mesh = p.mesh_factory(8)