From 2f689f46726939810c3e848dacb7ddf0355f0792 Mon Sep 17 00:00:00 2001 From: Tulio Date: Mon, 3 Jul 2023 10:48:33 -0500 Subject: [PATCH 01/12] Small tweaks to transport --- mirgecom/transport.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/mirgecom/transport.py b/mirgecom/transport.py index 0208b4e5f..1a414bf2a 100644 --- a/mirgecom/transport.py +++ b/mirgecom/transport.py @@ -50,7 +50,6 @@ from dataclasses import dataclass from arraycontext import dataclass_array_container import numpy as np -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa from meshmode.dof_array import DOFArray from mirgecom.fluid import ConservedVars from mirgecom.eos import GasEOS, GasDependentVars @@ -76,9 +75,9 @@ class GasTransportVars: .. attribute:: species_diffusivity """ - bulk_viscosity: np.ndarray - viscosity: np.ndarray - thermal_conductivity: np.ndarray + bulk_viscosity: DOFArray + viscosity: DOFArray + thermal_conductivity: DOFArray species_diffusivity: np.ndarray @@ -198,7 +197,7 @@ def species_diffusivity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the vector of species diffusivities, ${d}_{\alpha}$.""" - return self._d_alpha*(0*cv.mass + 1.0) + return self._d_alpha*(0*cv.species_mass + 1.0) class PowerLawTransport(TransportModel): @@ -317,7 +316,7 @@ def species_diffusivity(self, cv: ConservedVars, # type: ignore[override] return (self._sigma * self.viscosity(cv, dv)/( cv.mass*self._lewis*eos.gamma(cv, dv.temperature)) ) - return self._d_alpha*(0*cv.mass + 1.) + return self._d_alpha*(0*cv.species_mass + 1.) class MixtureAveragedTransport(TransportModel): From 5e5bee30e520dd1fed365ba1fde8fdb52f0b8758 Mon Sep 17 00:00:00 2001 From: Tulio Date: Thu, 13 Jul 2023 20:34:01 -0500 Subject: [PATCH 02/12] cosmetics --- mirgecom/gas_model.py | 2 +- mirgecom/transport.py | 43 ++++++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/mirgecom/gas_model.py b/mirgecom/gas_model.py index 132bf5476..0f7724e5b 100644 --- a/mirgecom/gas_model.py +++ b/mirgecom/gas_model.py @@ -83,7 +83,7 @@ class GasModel: A gas equation of state to provide thermal properties. - .. attribute:: transport_model + .. attribute:: transport A gas transport model to provide transport properties. None for inviscid models. diff --git a/mirgecom/transport.py b/mirgecom/transport.py index 56200c47c..9200c4fbe 100644 --- a/mirgecom/transport.py +++ b/mirgecom/transport.py @@ -97,37 +97,37 @@ class TransportModel: """ def bulk_viscosity(self, cv: ConservedVars, - dv: Optional[GasDependentVars] = None, + dv: Optional[GasDependentVars], eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the bulk viscosity for the gas (${\mu}_{B}$).""" raise NotImplementedError() def viscosity(self, cv: ConservedVars, - dv: Optional[GasDependentVars] = None, + dv: Optional[GasDependentVars], eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the gas dynamic viscosity, $\mu$.""" raise NotImplementedError() def volume_viscosity(self, cv: ConservedVars, - dv: Optional[GasDependentVars] = None, + dv: Optional[GasDependentVars], eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the 2nd coefficent of viscosity, $\lambda$.""" raise NotImplementedError() def thermal_conductivity(self, cv: ConservedVars, - dv: Optional[GasDependentVars] = None, - eos: Optional[GasEOS] = None) -> DOFArray: + dv: Optional[GasDependentVars], + eos: Optional[GasEOS]) -> DOFArray: r"""Get the gas thermal_conductivity, $\kappa$.""" raise NotImplementedError() def species_diffusivity(self, cv: ConservedVars, - dv: Optional[GasDependentVars] = None, - eos: Optional[GasEOS] = None) -> DOFArray: + dv: Optional[GasDependentVars], + eos: Optional[GasEOS]) -> DOFArray: r"""Get the vector of species diffusivities, ${d}_{\alpha}$.""" raise NotImplementedError() def transport_vars(self, cv: ConservedVars, - dv: Optional[GasDependentVars] = None, + dv: Optional[GasDependentVars], eos: Optional[GasEOS] = None) -> GasTransportVars: r"""Compute the transport properties from the conserved state.""" return GasTransportVars( @@ -248,7 +248,7 @@ def __init__(self, alpha=0.6, beta=4.093e-7, sigma=2.5, n=.666, self._d_alpha = species_diffusivity self._lewis = lewis - def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] + def bulk_viscosity(self, cv: ConservedVars, dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the bulk viscosity for the gas, $\mu_{B}$. @@ -261,7 +261,7 @@ def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] return self._alpha * self.viscosity(cv, dv) # TODO: Should this be memoized? Avoid multiple calls? - def viscosity(self, cv: ConservedVars, # type: ignore[override] + def viscosity(self, cv: ConservedVars, dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the gas dynamic viscosity, $\mu$. @@ -270,7 +270,7 @@ def viscosity(self, cv: ConservedVars, # type: ignore[override] """ return self._beta * dv.temperature**self._n - def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] + def volume_viscosity(self, cv: ConservedVars, dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the 2nd viscosity coefficent, $\lambda$. @@ -284,10 +284,11 @@ def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] """ return (self._alpha - 2.0/3.0) * self.viscosity(cv, dv) - def thermal_conductivity(self, cv: ConservedVars, # type: ignore[override] + def thermal_conductivity(self, cv: ConservedVars, dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the gas thermal conductivity, $\kappa$. + The thermal conductivity is obatained by the Chapman-Enskog approach: .. math:: \kappa = \sigma\mu{C}_{v} @@ -297,13 +298,13 @@ def thermal_conductivity(self, cv: ConservedVars, # type: ignore[override] * eos.heat_capacity_cv(cv, dv.temperature) ) - def species_diffusivity(self, cv: ConservedVars, # type: ignore[override] + def species_diffusivity(self, cv: ConservedVars, dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the vector of species diffusivities, ${d}_{\alpha}$. The species diffusivities can be either (1) specified directly or - (2) using user-imposed Lewis number $Le$ w/shape "nspecies" + (2) using user-imposed Lewis number $Le$ w/ shape "nspecies" In the latter, it is then evaluate based on the heat capacity at constant pressure $C_p$ and the thermal conductivity $\kappa$ as: @@ -337,7 +338,7 @@ class MixtureAveragedTransport(TransportModel): def __init__(self, pyrometheus_mech, alpha=0.6, factor=1.0, lewis=None, epsilon=1e-4, singular_diffusivity=1e-6): - r"""Initialize power law coefficients and parameters. + r"""Initialize coefficients and parameters. Parameters ---------- @@ -379,10 +380,10 @@ def __init__(self, pyrometheus_mech, alpha=0.6, factor=1.0, lewis=None, self._epsilon = epsilon self._singular_diffusivity = singular_diffusivity if self._lewis is not None: - if (len(self._lewis) != self._pyro_mech.num_species): + if len(self._lewis) != self._pyro_mech.num_species: raise ValueError("Lewis number should match number of species") - def viscosity(self, cv: ConservedVars, # type: ignore[override] + def viscosity(self, cv: ConservedVars, dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the mixture dynamic viscosity, $\mu^{(m)}$. @@ -408,7 +409,7 @@ def viscosity(self, cv: ConservedVars, # type: ignore[override] dv.temperature, cv.species_mass_fractions) ) - def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] + def bulk_viscosity(self, cv: ConservedVars, dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the bulk viscosity for the gas, $\mu_{B}$. @@ -420,7 +421,7 @@ def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] """ return self._alpha*self.viscosity(cv, dv) - def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] + def volume_viscosity(self, cv: ConservedVars, dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the 2nd viscosity coefficent, $\lambda$. @@ -434,7 +435,7 @@ def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] """ return (self._alpha - 2.0/3.0)*self.viscosity(cv, dv) - def thermal_conductivity(self, cv: ConservedVars, # type: ignore[override] + def thermal_conductivity(self, cv: ConservedVars, dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the gas thermal_conductivity, $\kappa$. @@ -452,7 +453,7 @@ def thermal_conductivity(self, cv: ConservedVars, # type: ignore[override] return self._factor*(self._pyro_mech.get_mixture_thermal_conductivity_mixavg( dv.temperature, cv.species_mass_fractions,)) - def species_diffusivity(self, cv: ConservedVars, # type: ignore[override] + def species_diffusivity(self, cv: ConservedVars, dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the vector of species diffusivities, ${d}_{i}$. From dde5e41ef0de55d8898f2d425f3e92ca828f0f17 Mon Sep 17 00:00:00 2001 From: Tulio Date: Mon, 24 Jul 2023 16:21:24 -0500 Subject: [PATCH 03/12] More fixes --- mirgecom/transport.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/mirgecom/transport.py b/mirgecom/transport.py index 9200c4fbe..54b3ca6d4 100644 --- a/mirgecom/transport.py +++ b/mirgecom/transport.py @@ -4,7 +4,7 @@ Transport Models ^^^^^^^^^^^^^^^^ This module is designed provide Transport Model objects used to compute and -manage the transport properties in viscous flows. The transport properties +manage the transport properties in viscous flows. The transport properties currently implemented are the dynamic viscosity ($\mu$), the bulk viscosity ($\mu_{B}$), the thermal conductivity ($\kappa$), and the species diffusivities ($d_{\alpha}$). @@ -96,30 +96,35 @@ class TransportModel: .. automethod:: transport_vars """ + @abstractmethod def bulk_viscosity(self, cv: ConservedVars, dv: Optional[GasDependentVars], eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the bulk viscosity for the gas (${\mu}_{B}$).""" raise NotImplementedError() + @abstractmethod def viscosity(self, cv: ConservedVars, dv: Optional[GasDependentVars], eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the gas dynamic viscosity, $\mu$.""" raise NotImplementedError() + @abstractmethod def volume_viscosity(self, cv: ConservedVars, dv: Optional[GasDependentVars], eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the 2nd coefficent of viscosity, $\lambda$.""" raise NotImplementedError() + @abstractmethod def thermal_conductivity(self, cv: ConservedVars, dv: Optional[GasDependentVars], eos: Optional[GasEOS]) -> DOFArray: r"""Get the gas thermal_conductivity, $\kappa$.""" raise NotImplementedError() + @abstractmethod def species_diffusivity(self, cv: ConservedVars, dv: Optional[GasDependentVars], eos: Optional[GasEOS]) -> DOFArray: @@ -532,7 +537,8 @@ def __init__(self, self._av_mu = av_mu self._av_prandtl = av_prandtl - def av_viscosity(self, cv, dv, eos): + def av_viscosity(self, cv: ConservedVars, dv: GasDependentVars, + eos: GasEOS) -> DOFArray: r"""Get the artificial viscosity for the gas.""" actx = cv.array_context return self._av_mu*actx.np.sqrt(np.dot(cv.velocity, cv.velocity) @@ -577,7 +583,8 @@ def species_diffusivity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the vector of species diffusivities, ${d}_{\alpha}$.""" - return self._physical_transport.species_diffusivity(cv, dv, eos) + return (av_species_diffusivity + + self._physical_transport.species_diffusivity(cv, dv, eos)) class ArtificialViscosityTransportDiv2(TransportModel): @@ -615,21 +622,24 @@ def __init__(self, self._av_kappa = av_kappa self._av_prandtl = av_prandtl - def av_mu(self, cv, dv, eos): + def av_mu(self, cv: ConservedVars, dv: GasDependentVars, + eos: GasEOS) -> DOFArray: r"""Get the shear artificial viscosity for the gas.""" actx = cv.array_context return (self._av_mu * cv.mass * actx.np.sqrt(np.dot(cv.velocity, cv.velocity) + dv.speed_of_sound**2)) - def av_beta(self, cv, dv, eos): + def av_beta(self, cv: ConservedVars, dv: GasDependentVars, + eos: GasEOS) -> DOFArray: r"""Get the shear artificial viscosity for the gas.""" actx = cv.array_context return (self._av_beta * cv.mass * actx.np.sqrt(np.dot(cv.velocity, cv.velocity) + dv.speed_of_sound**2)) - def av_kappa(self, cv, dv, eos): + def av_kappa(self, cv: ConservedVars, dv: GasDependentVars, + eos: GasEOS) -> DOFArray: r"""Get the shear artificial viscosity for the gas.""" actx = cv.array_context return (self._av_kappa * cv.mass @@ -697,4 +707,5 @@ def species_diffusivity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the vector of species diffusivities, ${d}_{\alpha}$.""" - return self._physical_transport.species_diffusivity(cv, dv, eos) + return (av_species_diffusivity + + self._physical_transport.species_diffusivity(cv, dv, eos)) From 7a3bfebb417ab6debb06a83e8b62108fb734440e Mon Sep 17 00:00:00 2001 From: Tulio Date: Fri, 18 Aug 2023 13:05:11 -0500 Subject: [PATCH 04/12] Some changes to transport.py --- mirgecom/transport.py | 57 +++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/mirgecom/transport.py b/mirgecom/transport.py index 54b3ca6d4..a7bd63060 100644 --- a/mirgecom/transport.py +++ b/mirgecom/transport.py @@ -48,6 +48,7 @@ from typing import Optional from dataclasses import dataclass +from abc import abstractmethod from arraycontext import dataclass_array_container import numpy as np from meshmode.dof_array import DOFArray @@ -97,43 +98,37 @@ class TransportModel: """ @abstractmethod - def bulk_viscosity(self, cv: ConservedVars, - dv: Optional[GasDependentVars], - eos: Optional[GasEOS] = None) -> DOFArray: + def bulk_viscosity(self, cv: ConservedVars, dv: GasDependentVars, + eos: GasEOS) -> DOFArray: r"""Get the bulk viscosity for the gas (${\mu}_{B}$).""" raise NotImplementedError() @abstractmethod - def viscosity(self, cv: ConservedVars, - dv: Optional[GasDependentVars], - eos: Optional[GasEOS] = None) -> DOFArray: + def viscosity(self, cv: ConservedVars, dv: GasDependentVars, + eos: GasEOS) -> DOFArray: r"""Get the gas dynamic viscosity, $\mu$.""" raise NotImplementedError() @abstractmethod - def volume_viscosity(self, cv: ConservedVars, - dv: Optional[GasDependentVars], - eos: Optional[GasEOS] = None) -> DOFArray: + def volume_viscosity(self, cv: ConservedVars, dv: GasDependentVars, + eos: GasEOS) -> DOFArray: r"""Get the 2nd coefficent of viscosity, $\lambda$.""" raise NotImplementedError() @abstractmethod - def thermal_conductivity(self, cv: ConservedVars, - dv: Optional[GasDependentVars], - eos: Optional[GasEOS]) -> DOFArray: + def thermal_conductivity(self, cv: ConservedVars, dv: GasDependentVars, + eos: GasEOS) -> DOFArray: r"""Get the gas thermal_conductivity, $\kappa$.""" raise NotImplementedError() @abstractmethod - def species_diffusivity(self, cv: ConservedVars, - dv: Optional[GasDependentVars], - eos: Optional[GasEOS]) -> DOFArray: + def species_diffusivity(self, cv: ConservedVars, dv: GasDependentVars, + eos: GasEOS) -> DOFArray: r"""Get the vector of species diffusivities, ${d}_{\alpha}$.""" raise NotImplementedError() - def transport_vars(self, cv: ConservedVars, - dv: Optional[GasDependentVars], - eos: Optional[GasEOS] = None) -> GasTransportVars: + def transport_vars(self, cv: ConservedVars, dv: GasDependentVars, + eos: GasEOS) -> GasTransportVars: r"""Compute the transport properties from the conserved state.""" return GasTransportVars( bulk_viscosity=self.bulk_viscosity(cv=cv, dv=dv, eos=eos), @@ -532,7 +527,9 @@ def __init__(self, self._physical_transport = physical_transport if av_species_diffusivity is None: - av_species_diffusivity = np.empty((0,), dtype=object) + self.av_species_diffusivity = np.empty((0,), dtype=object) + else: + self.av_species_diffusivity = av_species_diffusivity self._av_mu = av_mu self._av_prandtl = av_prandtl @@ -544,20 +541,20 @@ def av_viscosity(self, cv: ConservedVars, dv: GasDependentVars, return self._av_mu*actx.np.sqrt(np.dot(cv.velocity, cv.velocity) + dv.speed_of_sound**2) - def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] + def bulk_viscosity(self, cv: ConservedVars, dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the bulk viscosity for the gas, $\mu_{B}$.""" return self._physical_transport.bulk_viscosity(cv, dv) - def viscosity(self, cv: ConservedVars, # type: ignore[override] + def viscosity(self, cv: ConservedVars, dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the gas dynamic viscosity, $\mu$.""" return (dv.smoothness_mu*self.av_viscosity(cv, dv, eos) + self._physical_transport.viscosity(cv, dv)) - def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] + def volume_viscosity(self, cv: ConservedVars, dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the 2nd viscosity coefficent, $\lambda$. @@ -569,7 +566,7 @@ def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] return (dv.smoothness_mu*self.av_viscosity(cv, dv, eos) + self._physical_transport.volume_viscosity(cv, dv)) - def thermal_conductivity(self, cv: ConservedVars, # type: ignore[override] + def thermal_conductivity(self, cv: ConservedVars, dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the gas thermal_conductivity, $\kappa$.""" @@ -583,7 +580,7 @@ def species_diffusivity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the vector of species diffusivities, ${d}_{\alpha}$.""" - return (av_species_diffusivity + return (self.av_species_diffusivity + 0*cv.species_mass + self._physical_transport.species_diffusivity(cv, dv, eos)) @@ -615,7 +612,9 @@ def __init__(self, self._physical_transport = physical_transport if av_species_diffusivity is None: - av_species_diffusivity = np.empty((0,), dtype=object) + self.av_species_diffusivity = np.empty((0,), dtype=object) + else: + self.av_species_diffusivity = av_species_diffusivity self._av_mu = av_mu self._av_beta = av_beta @@ -646,7 +645,7 @@ def av_kappa(self, cv: ConservedVars, dv: GasDependentVars, * actx.np.sqrt(np.dot(cv.velocity, cv.velocity) + dv.speed_of_sound**2)) - def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] + def bulk_viscosity(self, cv: ConservedVars, dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the bulk viscosity for the gas, $\mu_{B}$.""" @@ -656,7 +655,7 @@ def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] return (smoothness_beta*self.av_beta(cv, dv, eos) + self._physical_transport.bulk_viscosity(cv, dv)) - def viscosity(self, cv: ConservedVars, # type: ignore[override] + def viscosity(self, cv: ConservedVars, dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the gas dynamic viscosity, $\mu$.""" @@ -666,7 +665,7 @@ def viscosity(self, cv: ConservedVars, # type: ignore[override] return (smoothness_mu*self.av_mu(cv, dv, eos) + self._physical_transport.viscosity(cv, dv)) - def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] + def volume_viscosity(self, cv: ConservedVars, dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the 2nd viscosity coefficent, $\lambda$. @@ -707,5 +706,5 @@ def species_diffusivity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the vector of species diffusivities, ${d}_{\alpha}$.""" - return (av_species_diffusivity + return (self.av_species_diffusivity + 0*cv.species_mass + self._physical_transport.species_diffusivity(cv, dv, eos)) From ba31034d2703400d6cd8d94a756c8e1558e5f79a Mon Sep 17 00:00:00 2001 From: Tulio Date: Wed, 25 Sep 2024 12:37:09 -0500 Subject: [PATCH 05/12] Add Sutherland Law transport --- mirgecom/transport.py | 133 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 117 insertions(+), 16 deletions(-) diff --git a/mirgecom/transport.py b/mirgecom/transport.py index d585272ba..b107cf57f 100644 --- a/mirgecom/transport.py +++ b/mirgecom/transport.py @@ -12,6 +12,7 @@ .. autoclass:: GasTransportVars .. autoclass:: TransportModel .. autoclass:: SimpleTransport +.. autoclass:: SutherlandTransport .. autoclass:: PowerLawTransport .. autoclass:: MixtureAveragedTransport .. autoclass:: ArtificialViscosityTransportDiv @@ -98,39 +99,39 @@ class TransportModel: .. automethod:: transport_vars """ - @abstractmethod - def bulk_viscosity(self, cv: ConservedVars, dv: GasDependentVars, - eos: GasEOS) -> DOFArray: + def bulk_viscosity(self, cv: ConservedVars, + dv: Optional[GasDependentVars] = None, + eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the bulk viscosity for the gas (${\mu}_{B}$).""" raise NotImplementedError() - @abstractmethod - def viscosity(self, cv: ConservedVars, dv: GasDependentVars, - eos: GasEOS) -> DOFArray: + def viscosity(self, cv: ConservedVars, + dv: Optional[GasDependentVars] = None, + eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the gas dynamic viscosity, $\mu$.""" raise NotImplementedError() - @abstractmethod - def volume_viscosity(self, cv: ConservedVars, dv: GasDependentVars, - eos: GasEOS) -> DOFArray: + def volume_viscosity(self, cv: ConservedVars, + dv: Optional[GasDependentVars] = None, + eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the 2nd coefficent of viscosity, $\lambda$.""" raise NotImplementedError() - @abstractmethod - def thermal_conductivity(self, cv: ConservedVars, dv: GasDependentVars, - eos: GasEOS) -> DOFArray: + def thermal_conductivity(self, cv: ConservedVars, + dv: Optional[GasDependentVars] = None, + eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the gas thermal_conductivity, $\kappa$.""" raise NotImplementedError() - @abstractmethod def species_diffusivity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, eos: Optional[GasEOS] = None) -> np.ndarray: r"""Get the vector of species diffusivities, ${d}_{\alpha}$.""" raise NotImplementedError() - def transport_vars(self, cv: ConservedVars, dv: GasDependentVars, - eos: GasEOS) -> GasTransportVars: + def transport_vars(self, cv: ConservedVars, + dv: Optional[GasDependentVars] = None, + eos: Optional[GasEOS] = None) -> GasTransportVars: r"""Compute the transport properties from the conserved state.""" return GasTransportVars( bulk_viscosity=self.bulk_viscosity(cv=cv, dv=dv, eos=eos), @@ -202,6 +203,106 @@ def species_diffusivity(self, cv: ConservedVars, return self._d_alpha*(0*cv.species_mass + 1.0) # type: ignore +class SutherlandTransport(TransportModel): + r"""Transport model with Sutherland law properties. + + Inherits from (and implements) :class:`TransportModel` based on the + temperature-dependent Sutherland law. + + .. automethod:: __init__ + .. automethod:: bulk_viscosity + .. automethod:: viscosity + .. automethod:: volume_viscosity + .. automethod:: thermal_conductivity + .. automethod:: species_diffusivity + """ + + # air-like defaults here + def __init__(self, a_sutherland=1.4792e-06, t_sutherland=116., + prandtl=0.71, species_diffusivity=None, lewis=None): + """Initialize Sutherland law coefficients and parameters. + + Parameters + ---------- + lewis: numpy.ndarray + If required, the Lewis number specify the relation between the + thermal conductivity and the species diffusivities. The input array + must have a shape of "nspecies". + + prandtl: float + The Prandtl number specify the relation between the thermal conductivity + and the viscosity. Defaults to 0.71. + """ + if species_diffusivity is None and lewis is None: + species_diffusivity = np.empty((0,), dtype=object) + self._d_alpha = species_diffusivity + self._lewis = lewis + self._prandtl = prandtl + self._as = a_sutherland + self._ts = t_sutherland + + def bulk_viscosity(self, cv: ConservedVars, + dv: GasDependentVars, + eos: Optional[GasEOS] = None) -> DOFArray: + r"""Get the bulk viscosity for the gas, $\mu_{B}$.""" + return cv.mass*0.0 + + # TODO: How to weight the different species? Simple averaging by Y, IIUC + def viscosity(self, cv: ConservedVars, + dv: GasDependentVars, + eos: Optional[GasEOS] = None) -> DOFArray: + r"""Get the gas dynamic viscosity, $\mu$.""" + actx = cv.mass.array_context + return self._as*actx.np.sqrt(dv.temperature)/(1.0 + self._ts/dv.temperature) + + def volume_viscosity(self, cv: ConservedVars, + dv: GasDependentVars, + eos: Optional[GasEOS] = None) -> DOFArray: + r"""Get the 2nd viscosity coefficent, $\lambda$. + + In this transport model, the second coefficient of viscosity is defined as: + + .. math:: + + \lambda = - \frac{2}{3} \mu + + """ + return - 2.0/3.0 * self.viscosity(cv, dv) + + def thermal_conductivity(self, cv: ConservedVars, + dv: GasDependentVars, eos: GasEOS) -> DOFArray: + r"""Get the gas thermal conductivity, $\kappa$.""" + if self._prandtl is not None: + return self.viscosity(cv, dv) * ( + eos.heat_capacity_cp(cv, dv.temperature)/self._prandtl + ) + return self.viscosity(cv, dv) * ( + 1.32*eos.heat_capacity_cv(cv, dv.temperature) + + 1.77*eos.gas_const(y=cv.species_mass_fractions) + ) + + def species_diffusivity(self, cv: ConservedVars, + dv: GasDependentVars, eos: GasEOS) -> DOFArray: + r"""Get the vector of species diffusivities, ${d}_{\alpha}$. + + The species diffusivities can be either + (1) specified directly or + (2) using user-imposed Lewis number $Le$ w/ shape "nspecies" + + In the latter, it is then evaluate based on the heat capacity at + constant pressure $C_p$ and the thermal conductivity $\kappa$ as: + + .. math:: + + d_{\alpha} = \frac{\kappa}{\rho \; Le \; C_p} + """ + if self._lewis is not None: + return self.thermal_conductivity(cv, dv, eos)/( + cv.mass * self._lewis * eos.heat_capacity_cp(cv, dv.temperature) + ) + return self._d_alpha*(0*cv.species_mass + 1.) # type: ignore + + class PowerLawTransport(TransportModel): r"""Transport model with simple power law properties. @@ -290,7 +391,7 @@ def thermal_conductivity(self, cv: ConservedVars, dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the gas thermal conductivity, $\kappa$. - The thermal conductivity is obatained by the Chapman-Enskog approach: + The thermal conductivity is obtained by the Chapman-Enskog approach: .. math:: \kappa = \sigma\mu{C}_{v} From 0aaea98d259e31756e8fc189010a644c0592fb00 Mon Sep 17 00:00:00 2001 From: Tulio Date: Thu, 26 Sep 2024 12:05:08 -0500 Subject: [PATCH 06/12] Fix some bugs --- mirgecom/transport.py | 99 ++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 44 deletions(-) diff --git a/mirgecom/transport.py b/mirgecom/transport.py index b107cf57f..03fb98bfe 100644 --- a/mirgecom/transport.py +++ b/mirgecom/transport.py @@ -50,7 +50,6 @@ from typing import Optional from dataclasses import dataclass -from abc import abstractmethod from arraycontext import dataclass_array_container import numpy as np from meshmode.dof_array import DOFArray @@ -168,13 +167,13 @@ def bulk_viscosity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the bulk viscosity for the gas, $\mu_{B}$.""" - return self._mu_bulk*(0*cv.mass + 1.0) # type: ignore + return self._mu_bulk*(0*cv.mass + 1.0) def viscosity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the gas dynamic viscosity, $\mu$.""" - return self._mu*(0*cv.mass + 1.0) # type: ignore + return self._mu*(0*cv.mass + 1.0) def volume_viscosity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, @@ -188,26 +187,27 @@ def volume_viscosity(self, cv: ConservedVars, \lambda = \left(\mu_{B} - \frac{2\mu}{3}\right) """ - return (self._mu_bulk - 2 * self._mu / 3)*(0*cv.mass + 1.0) # type: ignore + return (self._mu_bulk - 2 * self._mu / 3)*(0*cv.mass + 1.0) def thermal_conductivity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the gas thermal_conductivity, $\kappa$.""" - return self._kappa*(0*cv.mass + 1.0) # type: ignore + return self._kappa*(0*cv.mass + 1.0) def species_diffusivity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, eos: Optional[GasEOS] = None) -> np.ndarray: r"""Get the vector of species diffusivities, ${d}_{\alpha}$.""" - return self._d_alpha*(0*cv.species_mass + 1.0) # type: ignore + return self._d_alpha*(0*cv.species_mass + 1.0) class SutherlandTransport(TransportModel): r"""Transport model with Sutherland law properties. Inherits from (and implements) :class:`TransportModel` based on the - temperature-dependent Sutherland law. + temperature-dependent Sutherland law. The implementation here follows OpenFOAM + for a comparison between both codes. .. automethod:: __init__ .. automethod:: bulk_viscosity @@ -218,8 +218,8 @@ class SutherlandTransport(TransportModel): """ # air-like defaults here - def __init__(self, a_sutherland=1.4792e-06, t_sutherland=116., - prandtl=0.71, species_diffusivity=None, lewis=None): + def __init__(self, a_sutherland, t_sutherland, + prandtl=None, species_diffusivity=None, lewis=None): """Initialize Sutherland law coefficients and parameters. Parameters @@ -231,7 +231,7 @@ def __init__(self, a_sutherland=1.4792e-06, t_sutherland=116., prandtl: float The Prandtl number specify the relation between the thermal conductivity - and the viscosity. Defaults to 0.71. + and the viscosity. """ if species_diffusivity is None and lewis is None: species_diffusivity = np.empty((0,), dtype=object) @@ -241,21 +241,31 @@ def __init__(self, a_sutherland=1.4792e-06, t_sutherland=116., self._as = a_sutherland self._ts = t_sutherland - def bulk_viscosity(self, cv: ConservedVars, + def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the bulk viscosity for the gas, $\mu_{B}$.""" return cv.mass*0.0 - # TODO: How to weight the different species? Simple averaging by Y, IIUC - def viscosity(self, cv: ConservedVars, + def viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: - r"""Get the gas dynamic viscosity, $\mu$.""" + r"""Get the gas dynamic viscosity, $\mu$. + + The mixture viscosity, in this case, is simply the weighted sum of + individual viscosities by the respective mass fractions. + """ actx = cv.mass.array_context - return self._as*actx.np.sqrt(dv.temperature)/(1.0 + self._ts/dv.temperature) - def volume_viscosity(self, cv: ConservedVars, + mu = cv.mass*0.0 + nspecies = len(cv.species_mass_fractions) + for i in range(0, nspecies): + mu = mu + cv.species_mass_fractions[i]*self._as[i]*( + actx.np.sqrt(dv.temperature)/(1.0 + self._ts[i]/dv.temperature)) + + return mu + + def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the 2nd viscosity coefficent, $\lambda$. @@ -269,19 +279,20 @@ def volume_viscosity(self, cv: ConservedVars, """ return - 2.0/3.0 * self.viscosity(cv, dv) - def thermal_conductivity(self, cv: ConservedVars, + def thermal_conductivity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the gas thermal conductivity, $\kappa$.""" if self._prandtl is not None: return self.viscosity(cv, dv) * ( eos.heat_capacity_cp(cv, dv.temperature)/self._prandtl ) + # Eucken correlation return self.viscosity(cv, dv) * ( 1.32*eos.heat_capacity_cv(cv, dv.temperature) - + 1.77*eos.gas_const(y=cv.species_mass_fractions) + + 1.77*eos.gas_const(species_mass_fractions=cv.species_mass_fractions) ) - def species_diffusivity(self, cv: ConservedVars, + def species_diffusivity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the vector of species diffusivities, ${d}_{\alpha}$. @@ -300,7 +311,7 @@ def species_diffusivity(self, cv: ConservedVars, return self.thermal_conductivity(cv, dv, eos)/( cv.mass * self._lewis * eos.heat_capacity_cp(cv, dv.temperature) ) - return self._d_alpha*(0*cv.species_mass + 1.) # type: ignore + return self._d_alpha*(0*cv.species_mass + 1.) class PowerLawTransport(TransportModel): @@ -351,7 +362,7 @@ def __init__(self, alpha=0.6, beta=4.093e-7, sigma=2.5, n=.666, self._d_alpha = species_diffusivity self._lewis = lewis - def bulk_viscosity(self, cv: ConservedVars, + def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the bulk viscosity for the gas, $\mu_{B}$. @@ -364,7 +375,7 @@ def bulk_viscosity(self, cv: ConservedVars, return self._alpha * self.viscosity(cv, dv) # TODO: Should this be memoized? Avoid multiple calls? - def viscosity(self, cv: ConservedVars, + def viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the gas dynamic viscosity, $\mu$. @@ -373,7 +384,7 @@ def viscosity(self, cv: ConservedVars, """ return self._beta * dv.temperature**self._n - def volume_viscosity(self, cv: ConservedVars, + def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the 2nd viscosity coefficent, $\lambda$. @@ -387,7 +398,7 @@ def volume_viscosity(self, cv: ConservedVars, """ return (self._alpha - 2.0/3.0) * self.viscosity(cv, dv) - def thermal_conductivity(self, cv: ConservedVars, + def thermal_conductivity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the gas thermal conductivity, $\kappa$. @@ -401,7 +412,7 @@ def thermal_conductivity(self, cv: ConservedVars, * eos.heat_capacity_cv(cv, dv.temperature) ) - def species_diffusivity(self, cv: ConservedVars, + def species_diffusivity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the vector of species diffusivities, ${d}_{\alpha}$. @@ -420,7 +431,7 @@ def species_diffusivity(self, cv: ConservedVars, return (self._sigma * self.viscosity(cv, dv)/( cv.mass*self._lewis*eos.gamma(cv, dv.temperature)) ) - return self._d_alpha*(0*cv.species_mass + 1.) # type: ignore + return self._d_alpha*(0*cv.species_mass + 1.) class MixtureAveragedTransport(TransportModel): @@ -486,7 +497,7 @@ def __init__(self, pyrometheus_mech, alpha=0.6, factor=1.0, lewis=None, if len(self._lewis) != self._pyro_mech.num_species: raise ValueError("Lewis number should match number of species") - def viscosity(self, cv: ConservedVars, + def viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the mixture dynamic viscosity, $\mu^{(m)}$. @@ -512,7 +523,7 @@ def viscosity(self, cv: ConservedVars, dv.temperature, cv.species_mass_fractions) ) - def bulk_viscosity(self, cv: ConservedVars, + def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the bulk viscosity for the gas, $\mu_{B}$. @@ -524,7 +535,7 @@ def bulk_viscosity(self, cv: ConservedVars, """ return self._alpha*self.viscosity(cv, dv) - def volume_viscosity(self, cv: ConservedVars, + def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the 2nd viscosity coefficent, $\lambda$. @@ -538,7 +549,7 @@ def volume_viscosity(self, cv: ConservedVars, """ return (self._alpha - 2.0/3.0)*self.viscosity(cv, dv) - def thermal_conductivity(self, cv: ConservedVars, + def thermal_conductivity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the gas thermal_conductivity, $\kappa$. @@ -556,7 +567,7 @@ def thermal_conductivity(self, cv: ConservedVars, return self._factor*(self._pyro_mech.get_mixture_thermal_conductivity_mixavg( dv.temperature, cv.species_mass_fractions,)) - def species_diffusivity(self, cv: ConservedVars, + def species_diffusivity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the vector of species diffusivities, ${d}_{i}$. @@ -644,20 +655,20 @@ def av_viscosity(self, cv: ConservedVars, dv: GasDependentVars, return self._av_mu*actx.np.sqrt(np.dot(cv.velocity, cv.velocity) + dv.speed_of_sound**2) - def bulk_viscosity(self, cv: ConservedVars, + def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the bulk viscosity for the gas, $\mu_{B}$.""" return self._physical_transport.bulk_viscosity(cv, dv) - def viscosity(self, cv: ConservedVars, + def viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the gas dynamic viscosity, $\mu$.""" return (dv.smoothness_mu*self.av_viscosity(cv, dv, eos) + self._physical_transport.viscosity(cv, dv)) - def volume_viscosity(self, cv: ConservedVars, + def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the 2nd viscosity coefficent, $\lambda$. @@ -669,7 +680,7 @@ def volume_viscosity(self, cv: ConservedVars, return (dv.smoothness_mu*self.av_viscosity(cv, dv, eos) + self._physical_transport.volume_viscosity(cv, dv)) - def thermal_conductivity(self, cv: ConservedVars, + def thermal_conductivity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the gas thermal_conductivity, $\kappa$.""" @@ -724,31 +735,31 @@ def __init__(self, self._av_kappa = av_kappa self._av_prandtl = av_prandtl - def av_mu(self, cv: ConservedVars, dv: GasDependentVars, - eos: GasEOS) -> DOFArray: + def av_mu(self, cv: ConservedVars, + dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the shear artificial viscosity for the gas.""" actx = cv.array_context return (self._av_mu * cv.mass * actx.np.sqrt(np.dot(cv.velocity, cv.velocity) + dv.speed_of_sound**2)) - def av_beta(self, cv: ConservedVars, dv: GasDependentVars, - eos: GasEOS) -> DOFArray: + def av_beta(self, cv: ConservedVars, + dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the shear artificial viscosity for the gas.""" actx = cv.array_context return (self._av_beta * cv.mass * actx.np.sqrt(np.dot(cv.velocity, cv.velocity) + dv.speed_of_sound**2)) - def av_kappa(self, cv: ConservedVars, dv: GasDependentVars, - eos: GasEOS) -> DOFArray: + def av_kappa(self, cv: ConservedVars, + dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the shear artificial viscosity for the gas.""" actx = cv.array_context return (self._av_kappa * cv.mass * actx.np.sqrt(np.dot(cv.velocity, cv.velocity) + dv.speed_of_sound**2)) - def bulk_viscosity(self, cv: ConservedVars, + def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the bulk viscosity for the gas, $\mu_{B}$.""" @@ -758,7 +769,7 @@ def bulk_viscosity(self, cv: ConservedVars, return (smoothness_beta*self.av_beta(cv, dv, eos) + self._physical_transport.bulk_viscosity(cv, dv)) - def viscosity(self, cv: ConservedVars, + def viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the gas dynamic viscosity, $\mu$.""" @@ -768,7 +779,7 @@ def viscosity(self, cv: ConservedVars, return (smoothness_mu*self.av_mu(cv, dv, eos) + self._physical_transport.viscosity(cv, dv)) - def volume_viscosity(self, cv: ConservedVars, + def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the 2nd viscosity coefficent, $\lambda$. From 752e57f9355d3ed4b9c125d7952cd20160655e94 Mon Sep 17 00:00:00 2001 From: Tulio Date: Thu, 26 Sep 2024 13:51:53 -0500 Subject: [PATCH 07/12] Improve docs and put the mypy stuff back --- mirgecom/transport.py | 53 +++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/mirgecom/transport.py b/mirgecom/transport.py index 03fb98bfe..a51ca9f38 100644 --- a/mirgecom/transport.py +++ b/mirgecom/transport.py @@ -167,13 +167,13 @@ def bulk_viscosity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the bulk viscosity for the gas, $\mu_{B}$.""" - return self._mu_bulk*(0*cv.mass + 1.0) + return self._mu_bulk*(0*cv.mass + 1.0) # type: ignore def viscosity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the gas dynamic viscosity, $\mu$.""" - return self._mu*(0*cv.mass + 1.0) + return self._mu*(0*cv.mass + 1.0) # type: ignore def volume_viscosity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, @@ -187,19 +187,19 @@ def volume_viscosity(self, cv: ConservedVars, \lambda = \left(\mu_{B} - \frac{2\mu}{3}\right) """ - return (self._mu_bulk - 2 * self._mu / 3)*(0*cv.mass + 1.0) + return (self._mu_bulk - 2 * self._mu / 3)*(0*cv.mass + 1.0) # type: ignore def thermal_conductivity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the gas thermal_conductivity, $\kappa$.""" - return self._kappa*(0*cv.mass + 1.0) + return self._kappa*(0*cv.mass + 1.0) # type: ignore def species_diffusivity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, eos: Optional[GasEOS] = None) -> np.ndarray: r"""Get the vector of species diffusivities, ${d}_{\alpha}$.""" - return self._d_alpha*(0*cv.species_mass + 1.0) + return self._d_alpha*(0*cv.species_mass + 1.0) # type: ignore class SutherlandTransport(TransportModel): @@ -209,6 +209,22 @@ class SutherlandTransport(TransportModel): temperature-dependent Sutherland law. The implementation here follows OpenFOAM for a comparison between both codes. + The species viscosity is given by + + .. math:: + \mu_i = A_{s,i} \frac{\sqrt{T}}{1 + \frac{T_{s,i}}{T}} + + The mixture viscosity, in this case, is simply the weighted sum of + individual viscosities by the respective mass fractions. + + .. math:: + \mu = \sum_i \mu_i + + The thermal conductivity is given by the Eucken correlation as + + .. math:: + \kappa = \mu c_v \left( 1.32 + 1.77 \frac{R}{c_v} \right) + .. automethod:: __init__ .. automethod:: bulk_viscosity .. automethod:: viscosity @@ -224,14 +240,22 @@ def __init__(self, a_sutherland, t_sutherland, Parameters ---------- + a_sutherland: numpy.ndarray + Linear coefficient for the viscosity. The input array + must have a shape of "nspecies". + + t_sutherland: numpy.ndarray + Temperature coefficient for the viscosity. The input array + must have a shape of "nspecies". + lewis: numpy.ndarray If required, the Lewis number specify the relation between the thermal conductivity and the species diffusivities. The input array must have a shape of "nspecies". prandtl: float - The Prandtl number specify the relation between the thermal conductivity - and the viscosity. + The Prandtl number specify the relation between the thermal + conductivity and the viscosity. """ if species_diffusivity is None and lewis is None: species_diffusivity = np.empty((0,), dtype=object) @@ -244,17 +268,16 @@ def __init__(self, a_sutherland, t_sutherland, def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: - r"""Get the bulk viscosity for the gas, $\mu_{B}$.""" + r"""Get the bulk viscosity for the gas, $\mu_{B}$. + + This model assumes no bulk viscosity. + """ return cv.mass*0.0 def viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: Optional[GasEOS] = None) -> DOFArray: - r"""Get the gas dynamic viscosity, $\mu$. - - The mixture viscosity, in this case, is simply the weighted sum of - individual viscosities by the respective mass fractions. - """ + r"""Get the gas dynamic viscosity, $\mu$.""" actx = cv.mass.array_context mu = cv.mass*0.0 @@ -311,7 +334,7 @@ def species_diffusivity(self, cv: ConservedVars, # type: ignore[override] return self.thermal_conductivity(cv, dv, eos)/( cv.mass * self._lewis * eos.heat_capacity_cp(cv, dv.temperature) ) - return self._d_alpha*(0*cv.species_mass + 1.) + return self._d_alpha*(0*cv.species_mass + 1.) # type: ignore class PowerLawTransport(TransportModel): @@ -431,7 +454,7 @@ def species_diffusivity(self, cv: ConservedVars, # type: ignore[override] return (self._sigma * self.viscosity(cv, dv)/( cv.mass*self._lewis*eos.gamma(cv, dv.temperature)) ) - return self._d_alpha*(0*cv.species_mass + 1.) + return self._d_alpha*(0*cv.species_mass + 1.) # type: ignore class MixtureAveragedTransport(TransportModel): From feb3f05467714be8d44d95b0e44fe2e50d2d9e42 Mon Sep 17 00:00:00 2001 From: Tulio Date: Thu, 26 Sep 2024 14:06:14 -0500 Subject: [PATCH 08/12] mypy --- mirgecom/transport.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mirgecom/transport.py b/mirgecom/transport.py index a51ca9f38..4f26af682 100644 --- a/mirgecom/transport.py +++ b/mirgecom/transport.py @@ -199,7 +199,7 @@ def species_diffusivity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, eos: Optional[GasEOS] = None) -> np.ndarray: r"""Get the vector of species diffusivities, ${d}_{\alpha}$.""" - return self._d_alpha*(0*cv.species_mass + 1.0) # type: ignore + return self._d_alpha*(0*cv.species_mass + 1.0) class SutherlandTransport(TransportModel): @@ -272,7 +272,7 @@ def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] This model assumes no bulk viscosity. """ - return cv.mass*0.0 + return actx.np.zeros_like(cv.mass) def viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, @@ -280,7 +280,7 @@ def viscosity(self, cv: ConservedVars, # type: ignore[override] r"""Get the gas dynamic viscosity, $\mu$.""" actx = cv.mass.array_context - mu = cv.mass*0.0 + mu = actx.np.zeros_like(cv.mass) nspecies = len(cv.species_mass_fractions) for i in range(0, nspecies): mu = mu + cv.species_mass_fractions[i]*self._as[i]*( @@ -313,7 +313,7 @@ def thermal_conductivity(self, cv: ConservedVars, # type: ignore[override] return self.viscosity(cv, dv) * ( 1.32*eos.heat_capacity_cv(cv, dv.temperature) + 1.77*eos.gas_const(species_mass_fractions=cv.species_mass_fractions) - ) + ) # type: ignore def species_diffusivity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: @@ -334,7 +334,7 @@ def species_diffusivity(self, cv: ConservedVars, # type: ignore[override] return self.thermal_conductivity(cv, dv, eos)/( cv.mass * self._lewis * eos.heat_capacity_cp(cv, dv.temperature) ) - return self._d_alpha*(0*cv.species_mass + 1.) # type: ignore + return self._d_alpha*(0*cv.species_mass + 1.) class PowerLawTransport(TransportModel): @@ -454,7 +454,7 @@ def species_diffusivity(self, cv: ConservedVars, # type: ignore[override] return (self._sigma * self.viscosity(cv, dv)/( cv.mass*self._lewis*eos.gamma(cv, dv.temperature)) ) - return self._d_alpha*(0*cv.species_mass + 1.) # type: ignore + return self._d_alpha*(0*cv.species_mass + 1.) class MixtureAveragedTransport(TransportModel): From cdb01aff00999477d895aa2b2e5c7a89181aedb4 Mon Sep 17 00:00:00 2001 From: Tulio Date: Thu, 26 Sep 2024 14:15:48 -0500 Subject: [PATCH 09/12] mypy --- mirgecom/transport.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mirgecom/transport.py b/mirgecom/transport.py index 4f26af682..9a0d3fa64 100644 --- a/mirgecom/transport.py +++ b/mirgecom/transport.py @@ -272,6 +272,7 @@ def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] This model assumes no bulk viscosity. """ + actx = cv.mass.array_context return actx.np.zeros_like(cv.mass) def viscosity(self, cv: ConservedVars, # type: ignore[override] @@ -298,9 +299,8 @@ def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] .. math:: \lambda = - \frac{2}{3} \mu - """ - return - 2.0/3.0 * self.viscosity(cv, dv) + return - 2.0/3.0 * self.viscosity(cv, dv) # type: ignore def thermal_conductivity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: @@ -310,10 +310,11 @@ def thermal_conductivity(self, cv: ConservedVars, # type: ignore[override] eos.heat_capacity_cp(cv, dv.temperature)/self._prandtl ) # Eucken correlation + y = cv.species_mass_fractions return self.viscosity(cv, dv) * ( 1.32*eos.heat_capacity_cv(cv, dv.temperature) - + 1.77*eos.gas_const(species_mass_fractions=cv.species_mass_fractions) - ) # type: ignore + + 1.77*eos.gas_const(species_mass_fractions=y) # type: ignore + ) def species_diffusivity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: @@ -676,7 +677,7 @@ def av_viscosity(self, cv: ConservedVars, dv: GasDependentVars, r"""Get the artificial viscosity for the gas.""" actx = cv.array_context return self._av_mu*actx.np.sqrt(np.dot(cv.velocity, cv.velocity) - + dv.speed_of_sound**2) + + dv.speed_of_sound**2) # type: ignore def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, @@ -688,7 +689,7 @@ def viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the gas dynamic viscosity, $\mu$.""" - return (dv.smoothness_mu*self.av_viscosity(cv, dv, eos) + return (dv.smoothness_mu*self.av_viscosity(cv, dv, eos) # type: ignore + self._physical_transport.viscosity(cv, dv)) def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] @@ -700,7 +701,7 @@ def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] $\lambda = \left(\mu_{B} - \frac{2\mu}{3}\right)$ """ - return (dv.smoothness_mu*self.av_viscosity(cv, dv, eos) + return (dv.smoothness_mu*self.av_viscosity(cv, dv, eos) # type: ignore + self._physical_transport.volume_viscosity(cv, dv)) def thermal_conductivity(self, cv: ConservedVars, # type: ignore[override] From 8c8664e380aff984c14107b33bd9830bb6531654 Mon Sep 17 00:00:00 2001 From: Tulio Date: Thu, 26 Sep 2024 14:20:53 -0500 Subject: [PATCH 10/12] mypy --- mirgecom/transport.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mirgecom/transport.py b/mirgecom/transport.py index 9a0d3fa64..70badd359 100644 --- a/mirgecom/transport.py +++ b/mirgecom/transport.py @@ -709,7 +709,7 @@ def thermal_conductivity(self, cv: ConservedVars, # type: ignore[override] eos: GasEOS) -> DOFArray: r"""Get the gas thermal_conductivity, $\kappa$.""" mu = self.av_viscosity(cv, dv, eos) - av_kappa = (dv.smoothness_mu*mu + av_kappa = (dv.smoothness_mu*mu # type: ignore * eos.heat_capacity_cp(cv, dv.temperature)/self._av_prandtl) return \ av_kappa + self._physical_transport.thermal_conductivity(cv, dv, eos) @@ -765,7 +765,7 @@ def av_mu(self, cv: ConservedVars, actx = cv.array_context return (self._av_mu * cv.mass * actx.np.sqrt(np.dot(cv.velocity, cv.velocity) - + dv.speed_of_sound**2)) + + dv.speed_of_sound**2)) # type: ignore def av_beta(self, cv: ConservedVars, dv: GasDependentVars, eos: GasEOS) -> DOFArray: @@ -773,7 +773,7 @@ def av_beta(self, cv: ConservedVars, actx = cv.array_context return (self._av_beta * cv.mass * actx.np.sqrt(np.dot(cv.velocity, cv.velocity) - + dv.speed_of_sound**2)) + + dv.speed_of_sound**2)) # type: ignore def av_kappa(self, cv: ConservedVars, dv: GasDependentVars, eos: GasEOS) -> DOFArray: @@ -781,7 +781,7 @@ def av_kappa(self, cv: ConservedVars, actx = cv.array_context return (self._av_kappa * cv.mass * actx.np.sqrt(np.dot(cv.velocity, cv.velocity) - + dv.speed_of_sound**2)) + + dv.speed_of_sound**2)) # type: ignore def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, From c65077383145bdc40a043f540884e9cc518567ba Mon Sep 17 00:00:00 2001 From: Tulio Date: Thu, 26 Sep 2024 14:58:54 -0500 Subject: [PATCH 11/12] Don't mess around with AV --- mirgecom/transport.py | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/mirgecom/transport.py b/mirgecom/transport.py index 70badd359..311a52cbc 100644 --- a/mirgecom/transport.py +++ b/mirgecom/transport.py @@ -665,19 +665,16 @@ def __init__(self, self._physical_transport = physical_transport if av_species_diffusivity is None: - self.av_species_diffusivity = np.empty((0,), dtype=object) - else: - self.av_species_diffusivity = av_species_diffusivity + av_species_diffusivity = np.empty((0,), dtype=object) self._av_mu = av_mu self._av_prandtl = av_prandtl - def av_viscosity(self, cv: ConservedVars, dv: GasDependentVars, - eos: GasEOS) -> DOFArray: + def av_viscosity(self, cv, dv, eos): r"""Get the artificial viscosity for the gas.""" actx = cv.array_context return self._av_mu*actx.np.sqrt(np.dot(cv.velocity, cv.velocity) - + dv.speed_of_sound**2) # type: ignore + + dv.speed_of_sound**2) def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, @@ -689,7 +686,7 @@ def viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, eos: GasEOS) -> DOFArray: r"""Get the gas dynamic viscosity, $\mu$.""" - return (dv.smoothness_mu*self.av_viscosity(cv, dv, eos) # type: ignore + return (dv.smoothness_mu*self.av_viscosity(cv, dv, eos) + self._physical_transport.viscosity(cv, dv)) def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] @@ -701,7 +698,7 @@ def volume_viscosity(self, cv: ConservedVars, # type: ignore[override] $\lambda = \left(\mu_{B} - \frac{2\mu}{3}\right)$ """ - return (dv.smoothness_mu*self.av_viscosity(cv, dv, eos) # type: ignore + return (dv.smoothness_mu*self.av_viscosity(cv, dv, eos) + self._physical_transport.volume_viscosity(cv, dv)) def thermal_conductivity(self, cv: ConservedVars, # type: ignore[override] @@ -709,7 +706,7 @@ def thermal_conductivity(self, cv: ConservedVars, # type: ignore[override] eos: GasEOS) -> DOFArray: r"""Get the gas thermal_conductivity, $\kappa$.""" mu = self.av_viscosity(cv, dv, eos) - av_kappa = (dv.smoothness_mu*mu # type: ignore + av_kappa = (dv.smoothness_mu*mu * eos.heat_capacity_cp(cv, dv.temperature)/self._av_prandtl) return \ av_kappa + self._physical_transport.thermal_conductivity(cv, dv, eos) @@ -718,8 +715,7 @@ def species_diffusivity(self, cv: ConservedVars, dv: Optional[GasDependentVars] = None, eos: Optional[GasEOS] = None) -> np.ndarray: r"""Get the vector of species diffusivities, ${d}_{\alpha}$.""" - return (self.av_species_diffusivity + 0*cv.species_mass - + self._physical_transport.species_diffusivity(cv, dv, eos)) + return self._physical_transport.species_diffusivity(cv, dv, eos) class ArtificialViscosityTransportDiv2(TransportModel): @@ -750,38 +746,33 @@ def __init__(self, self._physical_transport = physical_transport if av_species_diffusivity is None: - self.av_species_diffusivity = np.empty((0,), dtype=object) - else: - self.av_species_diffusivity = av_species_diffusivity + av_species_diffusivity = np.empty((0,), dtype=object) self._av_mu = av_mu self._av_beta = av_beta self._av_kappa = av_kappa self._av_prandtl = av_prandtl - def av_mu(self, cv: ConservedVars, - dv: GasDependentVars, eos: GasEOS) -> DOFArray: + def av_mu(self, cv, dv, eos): r"""Get the shear artificial viscosity for the gas.""" actx = cv.array_context return (self._av_mu * cv.mass * actx.np.sqrt(np.dot(cv.velocity, cv.velocity) - + dv.speed_of_sound**2)) # type: ignore + + dv.speed_of_sound**2)) - def av_beta(self, cv: ConservedVars, - dv: GasDependentVars, eos: GasEOS) -> DOFArray: + def av_beta(self, cv, dv, eos): r"""Get the shear artificial viscosity for the gas.""" actx = cv.array_context return (self._av_beta * cv.mass * actx.np.sqrt(np.dot(cv.velocity, cv.velocity) - + dv.speed_of_sound**2)) # type: ignore + + dv.speed_of_sound**2)) - def av_kappa(self, cv: ConservedVars, - dv: GasDependentVars, eos: GasEOS) -> DOFArray: + def av_kappa(self, cv, dv, eos): r"""Get the shear artificial viscosity for the gas.""" actx = cv.array_context return (self._av_kappa * cv.mass * actx.np.sqrt(np.dot(cv.velocity, cv.velocity) - + dv.speed_of_sound**2)) # type: ignore + + dv.speed_of_sound**2)) def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] dv: GasDependentVars, From 6d2f35cf47ef99cb90503c413f563be0ded58a34 Mon Sep 17 00:00:00 2001 From: Tulio Date: Fri, 27 Sep 2024 09:56:05 -0500 Subject: [PATCH 12/12] Small fix to docs and comments --- mirgecom/transport.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mirgecom/transport.py b/mirgecom/transport.py index 311a52cbc..8662e7c68 100644 --- a/mirgecom/transport.py +++ b/mirgecom/transport.py @@ -218,7 +218,7 @@ class SutherlandTransport(TransportModel): individual viscosities by the respective mass fractions. .. math:: - \mu = \sum_i \mu_i + \mu = \sum_i Y_i \mu_i The thermal conductivity is given by the Eucken correlation as @@ -233,7 +233,6 @@ class SutherlandTransport(TransportModel): .. automethod:: species_diffusivity """ - # air-like defaults here def __init__(self, a_sutherland, t_sutherland, prandtl=None, species_diffusivity=None, lewis=None): """Initialize Sutherland law coefficients and parameters. @@ -270,7 +269,7 @@ def bulk_viscosity(self, cv: ConservedVars, # type: ignore[override] eos: Optional[GasEOS] = None) -> DOFArray: r"""Get the bulk viscosity for the gas, $\mu_{B}$. - This model assumes no bulk viscosity. + This model assumes zero bulk viscosity. """ actx = cv.mass.array_context return actx.np.zeros_like(cv.mass)