From 0d0fdee44b8727de370fb05be3e39de94a78c352 Mon Sep 17 00:00:00 2001 From: Ryan Kingsbury Date: Tue, 1 Aug 2023 14:28:49 -0400 Subject: [PATCH] Solution: add pre-instance caching to get_property --- src/pyEQL/solution.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pyEQL/solution.py b/src/pyEQL/solution.py index ae341478..a715f158 100644 --- a/src/pyEQL/solution.py +++ b/src/pyEQL/solution.py @@ -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 @@ -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 @@ -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