From f8bda02888fd90d486d239741d27dc176a5148bb Mon Sep 17 00:00:00 2001 From: Karthik Rishinarada Date: Sat, 11 Jan 2025 00:18:55 +0530 Subject: [PATCH 1/3] disentangle if statements for readability --- .mailmap | 2 + tardis/plasma/assembly/base.py | 75 ++++++++++++++++++---------------- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/.mailmap b/.mailmap index b238be626b3..8cc367cbda4 100644 --- a/.mailmap +++ b/.mailmap @@ -119,6 +119,8 @@ Josh Shields Karan Desai Karan Desai karandesai-96 +Karthik Rishinarada + Kaushik Varanasi Kaushik Varanasi kaushik94 diff --git a/tardis/plasma/assembly/base.py b/tardis/plasma/assembly/base.py index 68ee1c7df02..526500c875e 100644 --- a/tardis/plasma/assembly/base.py +++ b/tardis/plasma/assembly/base.py @@ -185,8 +185,6 @@ def prepare_factory( self.setup_helium_treatment() - if len(self.continuum_interaction_species) > 0: - self.setup_continuum_interactions() def setup_helium_treatment(self): """ @@ -212,49 +210,54 @@ def setup_helium_treatment(self): If the heating rate data file is not specified when using "numerical-nlte" helium treatment. """ - if ( - self.helium_treatment == "recomb-nlte" - or self.helium_treatment == "numerical-nlte" - ) and ( - len(self.nlte_ionization_species + self.nlte_excitation_species) > 0 - ): - # Prevent the user from using helium NLTE treatment with - # NLTE ionization and excitation treatment. This is because - # the helium_nlte_properties could overwrite the NLTE ionization - # and excitation ion number and electron densities. - # helium_numerical_nlte_properties is also included here because - # it is currently in the same if else block, and thus may block - # the addition of the components from the else block. + + # nlte_exists determines if NLTE ionization and excitation ion + # number and electron densities exists so that it can prevent + # user from using Helium NLTE treatments + nlte_exists = len(self.nlte_ionization_species + self.nlte_excitation_species) > 0 + + if self.helium_treatment == "recomb-nlte": + self.set_recomb_nlte_helium_treatment(nlte_exists) + elif self.helium_treatment == "numerical-nlte": + self.set_numerical_nlte_helium_treatment(nlte_exists) + else: + self.set_default_helium_treatment(nlte_exists) + + + def set_recomb_nlte_helium_treatment(self, default_nlte): + if default_nlte: raise PlasmaConfigError( "Helium NLTE treatment is incompatible with the NLTE ionization and excitation treatment." ) - # TODO: Disentangle these if else block such that compatible components - # can be added independently. - if self.helium_treatment == "recomb-nlte": - self.plasma_modules += self.plasma_collection.helium_nlte_properties - elif self.helium_treatment == "numerical-nlte": - self.plasma_modules += ( + self.plasma_modules += self.plasma_collection.helium_nlte_properties + + + def set_numerical_nlte_helium_treatment(self, default_nlte): + if default_nlte: + raise PlasmaConfigError( + "Helium NLTE treatment is incompatible with the NLTE ionization and excitation treatment." + ) + + self.plasma_modules += ( self.plasma_collection.helium_numerical_nlte_properties ) - if self.heating_rate_data_file in ["none", None]: + + if self.heating_rate_data_file in ["none", None]: raise PlasmaConfigError("Heating rate data file not specified") - self.property_kwargs[HeliumNumericalNLTE] = dict( + self.property_kwargs[HeliumNumericalNLTE] = dict( heating_rate_data_file=self.heating_rate_data_file ) - else: - # If nlte ionization species are present, we don't want to add the - # IonNumberDensity from helium_lte_properties, since we want - # to use the IonNumberDensity provided by the NLTE solver. - if ( - len(self.nlte_ionization_species + self.nlte_excitation_species) - > 0 - ): - self.plasma_modules.append(LevelNumberDensity) - else: - self.plasma_modules += ( - self.plasma_collection.helium_lte_properties - ) + + + def set_default_helium_treatment(self, default_nlte): + # If nlte ionization species are present, we don't want to add the + # IonNumberDensity from helium_lte_properties, since we want + # to use the IonNumberDensity provided by the NLTE solver. + self.plasma_modules += [LevelNumberDensity] + if not default_nlte: + self.plasma_modules += [IonNumberDensity] + def setup_legacy_nlte(self, nlte_config): """ From ea59b0b7be910c909f5fd402f523804286c55c18 Mon Sep 17 00:00:00 2001 From: Karthik Rishinarada Date: Sat, 11 Jan 2025 00:23:23 +0530 Subject: [PATCH 2/3] fix a mistake --- tardis/plasma/assembly/base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tardis/plasma/assembly/base.py b/tardis/plasma/assembly/base.py index 526500c875e..df021bcd1b4 100644 --- a/tardis/plasma/assembly/base.py +++ b/tardis/plasma/assembly/base.py @@ -185,6 +185,9 @@ def prepare_factory( self.setup_helium_treatment() + if len(self.continuum_interaction_species) > 0: + self.setup_continuum_interactions() + def setup_helium_treatment(self): """ From f6ab9e8be1c74fa08ec156d20a60264ca3bc33b4 Mon Sep 17 00:00:00 2001 From: Karthik Rishinarada Date: Sat, 11 Jan 2025 00:24:02 +0530 Subject: [PATCH 3/3] removed line --- tardis/plasma/assembly/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tardis/plasma/assembly/base.py b/tardis/plasma/assembly/base.py index df021bcd1b4..9c101f1563c 100644 --- a/tardis/plasma/assembly/base.py +++ b/tardis/plasma/assembly/base.py @@ -188,7 +188,6 @@ def prepare_factory( if len(self.continuum_interaction_species) > 0: self.setup_continuum_interactions() - def setup_helium_treatment(self): """ Set up the helium treatment for the plasma assembly.