Skip to content

Commit

Permalink
Lazy grid evaluation and get rid of itertools
Browse files Browse the repository at this point in the history
  • Loading branch information
oashour committed May 6, 2024
1 parent b344d2a commit 468aaec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
9 changes: 2 additions & 7 deletions darkmagic/numerics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import itertools
from copy import deepcopy
from typing import TYPE_CHECKING, Tuple

Expand Down Expand Up @@ -169,12 +168,8 @@ def _get_G_vectors(
A tuple containing the Cartesian and fractional coordinates of the G vectors.
"""
# Generate the 8 closest G-vectors to each q-point
G_frac = np.array(
[
list(itertools.product(*zip(np.floor(q), np.ceil(q))))
for q in self.q_frac
]
)
offsets = np.indices((2,) * 3).reshape(3, -1).T
G_frac = np.floor(self.q_frac)[:, None, :] + offsets
# TODO: double check that right multiplication works well
G_cart = np.matmul(G_frac, recip_frac_to_cart)
# Compute the distances between the q-point and each of the 8 G-vectors
Expand Down
18 changes: 15 additions & 3 deletions darkmagic/rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,24 @@ def __init__(
numerics: Numerics,
):
self.m_chi = m_chi
self.v_e = v_e # self.compute_ve(time) if time is not None else v_e
self.v_e = v_e
self.material = material
self.model = model
self.numerics = numerics
self.grid = numerics.get_grid(m_chi, self.v_e, material)
self.dwf_grid = numerics.get_DWF_grid(material)
self._grid = None
self._dwf_grid = None

@property
def grid(self):
if self._grid is None:
self._grid = self.numerics.get_grid(self.m_chi, self.v_e, self.material)
return self._grid

@property
def dwf_grid(self):
if self._dwf_grid is None:
self._dwf_grid = self.numerics.get_DWF_grid(self.material)
return self._dwf_grid

@abstractmethod
def calculate_sigma_q_nu(self, omegas, epsilons):
Expand Down

0 comments on commit 468aaec

Please sign in to comment.