Skip to content

Commit

Permalink
Solution: add pre-instance caching to get_property
Browse files Browse the repository at this point in the history
  • Loading branch information
rkingsbury committed Aug 1, 2023
1 parent 972579e commit 0d0fdee
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/pyEQL/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# import libraries for scientific functions
import math
from functools import lru_cache
from typing import Dict, List, Literal, Optional, Union

from iapws import IAPWS95
Expand Down Expand Up @@ -92,6 +93,9 @@ def __init__(
# create a logger attached to this class
# self.logger = logging.getLogger(type(self).__name__)

# per-instance cache of get_property calls
self.get_property = lru_cache(maxsize=None)(self._get_property)

# initialize the volume with a flag to distinguish user-specified volume
if volume is not None:
volume_set = True
Expand Down Expand Up @@ -1768,7 +1772,7 @@ def get_mobility(self, solute):

return mobility.to("m**2/V/s")

def get_property(self, solute, name):
def _get_property(self, solute, name):
"""Retrieve a thermodynamic property (such as diffusion coefficient)
for solute, and adjust it from the reference conditions to the conditions
of the solution
Expand Down

0 comments on commit 0d0fdee

Please sign in to comment.