import functools
from typing import Optional
from scipy import integrate
from .formulas import KuboFormula
[docs]
class Nquad:
r"""Integrates a formula with integration variables, which can be either :math:`k`, :math:`E` or both.
Args:
formula: An instance of :class:`~py4mulas.formulas.KuboFormula`
bounds: Integration bounds, if not provided default model bounds are used
opts: Options to be passed to nquad.
Example:
>>> F = py4mulas.responses.Kubo(some_model, alpha='x', beta='y', kspace_options)
>>> I = py4mulas.integrator.Nquad(F, opts=None)
>>> response = I(mu=0, temperature=0.1, eta=0.01)
"""
def __init__(
self,
formula: KuboFormula,
bounds: Optional[list[tuple]] = None,
opts: Optional[dict] = None,
) -> None:
self.opts = opts
if bounds is not None:
self.bounds = bounds
else:
self.bounds = formula.bounds
self.integrand = formula.integrand
[docs]
def __call__(self, mu: float = 0, temperature: float = 0, eta: float = 0):
transport_params = dict(mu=mu, temperature=temperature, eta=eta)
wrapped_integrand = functools.partial(self.integrand, **transport_params)
result, _ = integrate.nquad(wrapped_integrand, self.bounds, opts=self.opts)
return result