<commit_before>import proteus
from proteus.mprans.cKappa import *
from proteus.mprans.cKappa2D import *

"""
NOTES:

Hardwired Numerics include:

lagging all terms from Navier-Stokes, Epsilon equations same solution
space for velocity from Navier-Stokes and Kappa equations

This can be removed by saving gradient calculations in N-S and lagging
rather than passing degrees of freedom between models

"""


class SubgridError(proteus.SubgridError.SGE_base):
    def __init__(self, coefficients, nd):
        proteus.SubgridError.SGE_base.__init__(self, coefficients, nd, lag=False)

    def initializeElementQuadrature(self, mesh, t, cq):
        pass

    def updateSubgridErrorHistory(self, initializationPhase=False):
        pass

    def calculateSubgridError(self, q):
        pass


class ShockCapturing(proteus.ShockCapturing.ShockCapturing_base):
    def __init__(self, coefficients, nd, shockCapturingFactor=0.25, lag=True, nStepsToDelay=None):
        proteus.ShockCapturing.ShockCapturing_base.__init__(self, coefficients, nd, shockCapturingFactor, lag)
        self.nStepsToDelay = nStepsToDelay
        self.nSteps = 0
        if self.lag:
            logEvent("Kappa.ShockCapturing: lagging requested but must lag the first step; switching lagging off and delaying")
            self.nStepsToDelay = 1
            self.lag = False

    def initializeElementQuadrature(self, mesh, t, cq):
        self.mesh = mesh
        self.numDiff = []
        self.numDiff_last = []
        for ci in range(self.nc):
            self.numDiff.append(cq[('numDiff', ci, ci)])
            self.numDiff_last.append(cq[('numDiff', ci, ci)])

    def updateShockCapturingHistory(self):
        self.nSteps += 1
        if self.lag:
            for ci in range(self.nc):
                self.numDiff_last[ci][:] = self.numDiff[ci]
        if self.lag == False and self.nStepsToDelay is not None and self.nSteps > self.nStepsToDelay:
            logEvent("Kappa.ShockCapturing: switched to lagged shock capturing")
            self.lag = True
            self.numDiff_last = []
            for ci in range(self.nc):
                self.numDiff_last.append(self.numDiff[ci].copy())
        logEvent("Kappa: max numDiff %e" % (globalMax(self.numDiff_last[0].max()),))


class NumericalFlux(proteus.NumericalFlux.Advection_DiagonalUpwind_Diffusion_IIPG_exterior):
    def __init__(self, vt, getPointwiseBoundaryConditions,
                 getAdvectiveFluxBoundaryConditions,
                 getDiffusiveFluxBoundaryConditions):
        proteus.NumericalFlux.Advection_DiagonalUpwind_Diffusion_IIPG_exterior.__init__(self, vt, getPointwiseBoundaryConditions,
                                                                                        getAdvectiveFluxBoundaryConditions,
                                                                                        getDiffusiveFluxBoundaryConditions)


class Coefficients(proteus.TransportCoefficients.TC_base):
    """Basic k-epsilon model for incompressible flow from Hutter etal
Chaper 11 but solves for just k assuming epsilon computed
independently and lagged in time

    """
# \bar{\vec v} = <\vec v> Reynolds-ave
# raged (mean) velocity
# \vec v^{'}   = turbulent fluctuation
# assume \vec v = <\vec v> + \vec v^{'}, with <\vec v^{'}> = 0

# Reynolds averaged NS equations

# \deld \bar{\vec v} = 0

# \pd{\bar{\vec v}}{t} + \deld \left(\bar{\vec v} \outer \bar{\vec v}\right)
#                -\nu \deld \ten \bar{D} + \frac{1}{\rho}\grad \bar p
#                - \frac{1}{rho}\deld \ten{R} = 0

# Reynolds stress term

# \ten R = -\rho <\vec v^{'}\outer \vec v^{'}>
# \frac{1}{\rho}\ten{R} = 2 \nu_t \bar{D} - \frac{2}{3}k\ten{I}

# D_{ij}(\vec v) = \frac{1}{2} \left( \pd{v_i}{x_j} + \pd{v_j}{x_i})
# \ten D \bar{\ten D} = D(<\vec v>), \ten D^{'} = \ten D(\vec v^{'})


# k-epsilon tranport equations

# \pd{k}{t} + \deld (k\bar{\vec v})
#           - \deld\left[\left(\frac{\nu_t}{\sigma_k} + \nu\right)\grad k \right]
#           - 4\nu_t \Pi_{D} + \epsilon = 0

# \pd{\varepsilon}{t} + \deld (\varepsilon \bar{\vec v})
#           - \deld\left[\left(\frac{\nu_t}{\sigma_\varepsilon} + \nu\right)\grad \varepsilon \right]
#           - 4c_1 k \Pi_{D} + c_2 \frac{\epsilon^2}{k} = 0


# k              -- turbulent kinetic energy = <\vec v^{'}\dot \vec v^{'}>
# \varepsilon    -- turbulent dissipation rate = 4 \nu <\Pi_{D^{'}}>

# \nu            -- kinematic viscosity (\mu/\rho)
# \nu_t          -- turbulent viscosity = c_mu \frac{k^2}{\varepsilon}


# \Pi_{\ten A} = \frac{1}{2}tr(\ten A^2) = 1/2 \ten A\cdot \ten A
# \ten D \cdot \ten D = \frac{1}{4}\left[ (4 u_x^2 + 4 v_y^2 +
#                                         1/2 (u_y + v_x)^2 \right]

# 4 \Pi_{D} = 2 \frac{1}{4}\left[ (4 u_x^2 + 4 v_y^2 +
#                                 1/2 (u_y + v_x)^2 \right]
#           = \left[ (2 u_x^2 + 2 v_y^2 + (u_y + v_x)^2 \right]

# \sigma_k -- Prandtl number \approx 1
# \sigma_e -- c_{\mu}/c_e

# c_{\mu} = 0.09, c_1 = 0.126, c_2 = 1.92, c_{\varepsilon} = 0.07


#     """

    from proteus.ctransportCoefficients import kEpsilon_k_3D_Evaluate_sd
    from proteus.ctransportCoefficients import kEpsilon_k_2D_Evaluate_sd

    def __init__(self,
                 VOS_mode=None,
                 LS_model=None,
                 V_model=0,
                 RD_model=None,
                 dissipation_model=None,
                 ME_model=6,
                 dissipation_model_flag=1,  # default K-Epsilon, 2 --> K-Omega, 1998, 3 --> K-Omega 1988
                 c_mu=0.09,
                 sigma_k=1.0,  # Prandtl Number<commit_msg>Fix typo<commit_after>import proteus
from proteus.mprans.cKappa import *
from proteus.mprans.cKappa2D import *

"""
NOTES:

Hardwired Numerics include:

lagging all terms from Navier-Stokes, Epsilon equations same solution
space for velocity from Navier-Stokes and Kappa equations

This can be removed by saving gradient calculations in N-S and lagging
rather than passing degrees of freedom between models

"""


class SubgridError(proteus.SubgridError.SGE_base):
    def __init__(self, coefficients, nd):
        proteus.SubgridError.SGE_base.__init__(self, coefficients, nd, lag=False)

    def initializeElementQuadrature(self, mesh, t, cq):
        pass

    def updateSubgridErrorHistory(self, initializationPhase=False):
        pass

    def calculateSubgridError(self, q):
        pass


class ShockCapturing(proteus.ShockCapturing.ShockCapturing_base):
    def __init__(self, coefficients, nd, shockCapturingFactor=0.25, lag=True, nStepsToDelay=None):
        proteus.ShockCapturing.ShockCapturing_base.__init__(self, coefficients, nd, shockCapturingFactor, lag)
        self.nStepsToDelay = nStepsToDelay
        self.nSteps = 0
        if self.lag:
            logEvent("Kappa.ShockCapturing: lagging requested but must lag the first step; switching lagging off and delaying")
            self.nStepsToDelay = 1
            self.lag = False

    def initializeElementQuadrature(self, mesh, t, cq):
        self.mesh = mesh
        self.numDiff = []
        self.numDiff_last = []
        for ci in range(self.nc):
            self.numDiff.append(cq[('numDiff', ci, ci)])
            self.numDiff_last.append(cq[('numDiff', ci, ci)])

    def updateShockCapturingHistory(self):
        self.nSteps += 1
        if self.lag:
            for ci in range(self.nc):
                self.numDiff_last[ci][:] = self.numDiff[ci]
        if self.lag == False and self.nStepsToDelay is not None and self.nSteps > self.nStepsToDelay:
            logEvent("Kappa.ShockCapturing: switched to lagged shock capturing")
            self.lag = True
            self.numDiff_last = []
            for ci in range(self.nc):
                self.numDiff_last.append(self.numDiff[ci].copy())
        logEvent("Kappa: max numDiff %e" % (globalMax(self.numDiff_last[0].max()),))


class NumericalFlux(proteus.NumericalFlux.Advection_DiagonalUpwind_Diffusion_IIPG_exterior):
    def __init__(self, vt, getPointwiseBoundaryConditions,
                 getAdvectiveFluxBoundaryConditions,
                 getDiffusiveFluxBoundaryConditions):
        proteus.NumericalFlux.Advection_DiagonalUpwind_Diffusion_IIPG_exterior.__init__(self, vt, getPointwiseBoundaryConditions,
                                                                                        getAdvectiveFluxBoundaryConditions,
                                                                                        getDiffusiveFluxBoundaryConditions)


class Coefficients(proteus.TransportCoefficients.TC_base):
    """Basic k-epsilon model for incompressible flow from Hutter etal
Chaper 11 but solves for just k assuming epsilon computed
independently and lagged in time

    """
# \bar{\vec v} = <\vec v> Reynolds-ave
# raged (mean) velocity
# \vec v^{'}   = turbulent fluctuation
# assume \vec v = <\vec v> + \vec v^{'}, with <\vec v^{'}> = 0

# Reynolds averaged NS equations

# \deld \bar{\vec v} = 0

# \pd{\bar{\vec v}}{t} + \deld \left(\bar{\vec v} \outer \bar{\vec v}\right)
#                -\nu \deld \ten \bar{D} + \frac{1}{\rho}\grad \bar p
#                - \frac{1}{rho}\deld \ten{R} = 0

# Reynolds stress term

# \ten R = -\rho <\vec v^{'}\outer \vec v^{'}>
# \frac{1}{\rho}\ten{R} = 2 \nu_t \bar{D} - \frac{2}{3}k\ten{I}

# D_{ij}(\vec v) = \frac{1}{2} \left( \pd{v_i}{x_j} + \pd{v_j}{x_i})
# \ten D \bar{\ten D} = D(<\vec v>), \ten D^{'} = \ten D(\vec v^{'})


# k-epsilon tranport equations

# \pd{k}{t} + \deld (k\bar{\vec v})
#           - \deld\left[\left(\frac{\nu_t}{\sigma_k} + \nu\right)\grad k \right]
#           - 4\nu_t \Pi_{D} + \epsilon = 0

# \pd{\varepsilon}{t} + \deld (\varepsilon \bar{\vec v})
#           - \deld\left[\left(\frac{\nu_t}{\sigma_\varepsilon} + \nu\right)\grad \varepsilon \right]
#           - 4c_1 k \Pi_{D} + c_2 \frac{\epsilon^2}{k} = 0


# k              -- turbulent kinetic energy = <\vec v^{'}\dot \vec v^{'}>
# \varepsilon    -- turbulent dissipation rate = 4 \nu <\Pi_{D^{'}}>

# \nu            -- kinematic viscosity (\mu/\rho)
# \nu_t          -- turbulent viscosity = c_mu \frac{k^2}{\varepsilon}


# \Pi_{\ten A} = \frac{1}{2}tr(\ten A^2) = 1/2 \ten A\cdot \ten A
# \ten D \cdot \ten D = \frac{1}{4}\left[ (4 u_x^2 + 4 v_y^2 +
#                                         1/2 (u_y + v_x)^2 \right]

# 4 \Pi_{D} = 2 \frac{1}{4}\left[ (4 u_x^2 + 4 v_y^2 +
#                                 1/2 (u_y + v_x)^2 \right]
#           = \left[ (2 u_x^2 + 2 v_y^2 + (u_y + v_x)^2 \right]

# \sigma_k -- Prandtl number \approx 1
# \sigma_e -- c_{\mu}/c_e

# c_{\mu} = 0.09, c_1 = 0.126, c_2 = 1.92, c_{\varepsilon} = 0.07


#     """

    from proteus.ctransportCoefficients import kEpsilon_k_3D_Evaluate_sd
    from proteus.ctransportCoefficients import kEpsilon_k_2D_Evaluate_sd

    def __init__(self,
                 VOS_model=None,
                 LS_model=None,
                 V_model=0,
                 RD_model=None,
                 dissipation_model=None,
                 ME_model=6,
                 dissipation_model_flag=1,  # default K-Epsilon, 2 --> K-Omega, 1998, 3 --> K-Omega 1988
                 c_mu=0.09,
                 sigma_k=1.0,  # Prandtl Number
{'fraction_non_alphanumeric': 0.1355265510459503, 'fraction_numerical': 0.01716431253352405, 'mean_word_length': 2.2444895591647334, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2607795', 'n_tokens_mistral': 3951, 'n_tokens_neox': 3738, 'n_words': 866}