#

For intermediate regime equilibrium particles, density, energy density and pressure are obtained through integration of distribution function

from common import integrators
import numpy


name = 'intermediate'
#

Particle density

def density(particle):

    density, _ = integrators.integrate_1D(
        lambda p: (
            particle.equilibrium_distribution_function(
                particle.energy(p) / particle.T
            ) * p**2 * particle.dof / 2. / numpy.pi**2
        ), (particle.grid.MIN_MOMENTUM / particle.params.a,
            particle.grid.MAX_MOMENTUM / particle.params.a)
    )
    return density
#

def energy_density_integrand(p, particle):

    E = particle.energy(p)
    return (
        particle.equilibrium_distribution_function(E / particle.T)
        * p**2 * E
        * particle.dof / 2. / numpy.pi**2
    )
#

def energy_density(particle):

    energy_density, _ = integrators.integrate_1D(
        lambda p: energy_density_integrand(p, particle),
        (particle.grid.MIN_MOMENTUM / particle.params.a,
         particle.grid.MAX_MOMENTUM / particle.params.a)
    )
    return energy_density
#

def pressure_integrand(p, particle):

    E = particle.energy(p)
    return (
        particle.equilibrium_distribution_function(E / particle.T)
        * p**4 / E
        * particle.dof / 6. / numpy.pi**2
    )
#

def pressure(particle):

    pressure, _ = integrators.integrate_1D(
        lambda p: pressure_integrand(p, particle),
        (particle.grid.MIN_MOMENTUM / particle.params.a,
         particle.grid.MAX_MOMENTUM / particle.params.a)
    )
    return pressure
#

def numerator(particle):

    return (particle.mass**2 * particle.params.x
            / particle.params.m**2 / particle.aT
            * I(particle, 2))
#

def denominator(particle):

    return (I(particle, 4) + particle.conformal_mass**2 * I(particle)) / particle.aT**2
#

def I(particle, y_power=2):

    return particle.dof / 2. / numpy.pi**2 * integrators.integrate_1D(
        lambda y: (
            y**y_power * numpy.exp(-particle.conformal_energy(y) / particle.aT)
            / (numpy.exp(-particle.conformal_energy(y) / particle.aT) + particle.eta) ** 2
        ),
        (particle.grid.MIN_MOMENTUM, particle.grid.MAX_MOMENTUM)
    )[0]