diff --git a/PySDM/builder.html b/PySDM/builder.html index f30d9aa25..f5a0ccd70 100644 --- a/PySDM/builder.html +++ b/PySDM/builder.html @@ -34,15 +34,6 @@

Module PySDM.builder

-

Functions

-
-
-def get_key(dynamic) -
-
-
-
-

Classes

@@ -62,11 +53,8 @@

Classes

assert not inspect.isclass(backend) self.formulae = backend.formulae self.particulator = Particulator(n_sd, backend) - self.req_attr = { - "multiplicity": get_attribute_class("multiplicity")(self), - "water mass": get_attribute_class("water mass")(self), - "cell id": get_attribute_class("cell id")(self), - } + self.req_attr_names = ["multiplicity", "water mass", "cell id"] + self.req_attr = None self.aerosol_radius_threshold = 0 self.condensation_params = None @@ -90,34 +78,38 @@

Classes

def add_dynamic(self, dynamic): assert self.particulator.environment is not None - key = get_key(dynamic) + key = inspect.getmro(type(dynamic))[-2].__name__ assert key not in self.particulator.dynamics self.particulator.dynamics[key] = dynamic - def replace_dynamic(self, dynamic): - key = get_key(dynamic) - assert key in self.particulator.dynamics - self.particulator.dynamics.pop(key) - self.add_dynamic(dynamic) - - def register_product(self, product, buffer): + def _register_product(self, product, buffer): if product.name in self.particulator.products: raise ValueError(f'product name "{product.name}" already registered') product.set_buffer(buffer) product.register(self) self.particulator.products[product.name] = product + def _resolve_attribute(self, attr_name): + if attr_name not in self.req_attr: + self.req_attr[attr_name] = get_attribute_class( + attr_name, + self.particulator.dynamics.keys(), + self.formulae, + )(self) + assert self.req_attr is not None + def get_attribute(self, attribute_name): - self.request_attribute(attribute_name) + """intended for obtaining attribute instances during build() logic, + from within register() methods""" + self._resolve_attribute(attribute_name) return self.req_attr[attribute_name] - def request_attribute(self, attribute, variant=None): - if attribute not in self.req_attr: - self.req_attr[attribute] = get_attribute_class( - attribute, self.particulator.dynamics, self.formulae - )(self) - if variant is not None: - assert variant == self.req_attr[attribute] + def request_attribute(self, attribute_name): + """can be called either before or during build()""" + if self.req_attr_names is not None: + self.req_attr_names.append(attribute_name) + else: + self._resolve_attribute(attribute_name) def build( self, @@ -148,12 +140,17 @@

Classes

del attributes["volume"] self.request_attribute("volume") + self.req_attr = {} + for attr_name in self.req_attr_names: + self._resolve_attribute(attr_name) + self.req_attr_names = None + for dynamic in self.particulator.dynamics.values(): dynamic.register(self) single_buffer_for_all_products = np.empty(self.particulator.mesh.grid) for product in products: - self.register_product(product, single_buffer_for_all_products) + self._register_product(product, single_buffer_for_all_products) for attribute in attributes: self.request_attribute(attribute) @@ -198,25 +195,14 @@

Methods

def get_attribute(self, attribute_name)
-
-
-
-def register_product(self, product, buffer) -
-
-
-
-
-def replace_dynamic(self, dynamic) -
-
-
+

intended for obtaining attribute instances during build() logic, +from within register() methods

-def request_attribute(self, attribute, variant=None) +def request_attribute(self, attribute_name)
-
+

can be called either before or during build()

def set_environment(self, environment) @@ -239,21 +225,14 @@

Methods

  • PySDM
  • -
  • Functions

    - -
  • Classes

    • Builder

      -
        + diff --git a/PySDM/dynamics/relaxed_velocity.html b/PySDM/dynamics/relaxed_velocity.html index 4f359de30..f729c5b8a 100644 --- a/PySDM/dynamics/relaxed_velocity.html +++ b/PySDM/dynamics/relaxed_velocity.html @@ -47,7 +47,6 @@

        Classes

        A dynamic which updates the fall momentum according to a relaxation timescale proportional to the sqrt of the droplet radius.

        -

        Should be added first in order to ensure the correct attributes are selected.

        Parameters

        • constant: use a constant relaxation timescale for all droplets
        • @@ -61,8 +60,6 @@

          Parameters

          """ A dynamic which updates the fall momentum according to a relaxation timescale proportional to the sqrt of the droplet radius. - - Should be added first in order to ensure the correct attributes are selected. """ def __init__(self, c: float = 8, constant: bool = False):