Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding nlte_rate_equation_solver.py #2140

Merged
merged 29 commits into from
Nov 16, 2022

Conversation

sonachitchyan
Copy link
Member

@sonachitchyan sonachitchyan commented Oct 24, 2022

📝 Description

This PR creates the rate matrix which will be further used in NLTE Solver implementation. The matrix is a block diagonal, constructed from blocks corresponding to each species and treating some of the ion numbers in NLTE ionization.

Also, link issues affected by this pull request by using the keywords: close, closes, closed, fix, fixes, fixed, resolve, resolves or resolved.

📌 Resources

Examples, notebooks, and links to useful references.

🚦 Testing

How did you test these changes?

  • Testing pipeline
  • Other method (describe)
  • My changes can't be tested (explain why)

☑️ Checklist

  • I requested two reviewers for this pull request
  • I updated the documentation according to my changes
  • I built the documentation by applying the build_docs label

Note: If you are not allowed to perform any of these actions, ping (@) a contributor.

@codecov
Copy link

codecov bot commented Oct 24, 2022

Codecov Report

Merging #2140 (870a892) into master (e39fa6f) will increase coverage by 0.21%.
The diff coverage is 82.02%.

❗ Current head 870a892 differs from pull request most recent head 121683a. Consider uploading reports for the commit 121683a to get more accurate results

@@            Coverage Diff             @@
##           master    #2140      +/-   ##
==========================================
+ Coverage   61.66%   61.87%   +0.21%     
==========================================
  Files          77       78       +1     
  Lines        8697     8782      +85     
==========================================
+ Hits         5363     5434      +71     
- Misses       3334     3348      +14     
Impacted Files Coverage Δ
tardis/plasma/properties/rate_matrix_index.py 40.00% <33.33%> (ø)
...dis/plasma/properties/nlte_rate_equation_solver.py 83.52% <83.52%> (ø)
tardis/plasma/properties/property_collections.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@sonachitchyan sonachitchyan changed the title Adding nlte_rate_equation_matrix.py Adding nlte_rate_equation_solver.py Oct 27, 2022
@sonachitchyan sonachitchyan self-assigned this Nov 2, 2022
@sonachitchyan sonachitchyan marked this pull request as ready for review November 2, 2022 15:38
Copy link
Contributor

@andrewfullard andrewfullard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass ;)

Copy link
Contributor

@andrewfullard andrewfullard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great, just a few last bits and pieces. It's an important PR to get right!

tardis/plasma/properties/nlte_rate_equation_solver.py Outdated Show resolved Hide resolved
tardis/plasma/properties/nlte_rate_equation_solver.py Outdated Show resolved Hide resolved
)
atomic_numbers = (
rate_matrix_index.get_level_values(0).unique().drop("n_e")
) # dropping the n_e index
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rate_matrix_index's 1st index is atomic number and "n_e" added in the end for constructing the rate_matrix in the right shape. That's why I'm getting rid of the last index and dropping repeated values(as each atomic number has multiple corresponding rows)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you put this in the comments

tardis/plasma/properties/nlte_rate_equation_solver.py Outdated Show resolved Hide resolved
tardis/plasma/properties/nlte_rate_equation_solver.py Outdated Show resolved Hide resolved
tardis/plasma/properties/rate_matrix_index.py Outdated Show resolved Hide resolved
@andrewfullard andrewfullard enabled auto-merge (squash) November 10, 2022 16:22
Copy link
Contributor

@chvogl chvogl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I have left a few small suggestions that fix typos etc.

Saha Factors.
rate_matrix_index : MultiIndex
(atomic_number, ion_number, level/treatment type)
If ion is treated in LTE ionization, 3rd index is "lte_ion",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If ion is treated in LTE ionization, 3rd index is "lte_ion",
If ion is treated in LTE or nebular ionization, 3rd index is "lte_ion",

phi : DataFrame
Saha Factors.
rate_matrix_index : MultiIndex
(atomic_number, ion_number, level/treatment type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess for now you could remove the level/ since we are only doing NLTE ionization (and the levels part is also not explained in the rest of the docstring).


Returns
-------
ion_number_densities_nlte: DataFrame
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ion_number_densities_nlte: DataFrame
ion_number_densities_nlte : DataFrame

-------
ion_number_densities_nlte: DataFrame
Number density with NLTE ionization treatment.
electron_densities_nlte: Series
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
electron_densities_nlte: Series
electron_densities_nlte : Series

ion_number_densities_nlte: DataFrame
Number density with NLTE ionization treatment.
electron_densities_nlte: Series
Electron density with NLTE ionizaion treatment.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Electron density with NLTE ionizaion treatment.
Electron density with NLTE ionization treatment.

-------
total_photo_ion_coefficients:
Photoinization coefficients grouped by atomic number and ion number.
total_rad_recomb_coefficients:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
total_rad_recomb_coefficients:
total_rad_recomb_coefficients

Photoinization coefficients grouped by atomic number and ion number.
total_rad_recomb_coefficients:
Radiative recombination coefficients grouped by atomic number and ion number.
total_coll_ion_coefficients:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
total_coll_ion_coefficients:
total_coll_ion_coefficients

Radiative recombination coefficients grouped by atomic number and ion number.
total_coll_ion_coefficients:
Collisional ionization coefficients grouped by atomic number and ion number.
total_coll_recomb_coefficients:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
total_coll_recomb_coefficients:
total_coll_recomb_coefficients

Returns
-------
total_photo_ion_coefficients:
Photoinization coefficients grouped by atomic number and ion number.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Photoinization coefficients grouped by atomic number and ion number.
Photoionization coefficients grouped by atomic number and ion number.

@@ -14,24 +14,41 @@ def __init__(self, plasma_parent, nlte_ionization_species=0):
self.nlte_ionization_species = nlte_ionization_species

def calculate(self, levels, nlte_ionization_species):
"""Generates rate_matrix_index using levels and changing the last index(level) to
"lte_ion" if that ion_number is treated in LTE, "nlte_ion" for NLTE ionizatin and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"lte_ion" if that ion_number is treated in LTE, "nlte_ion" for NLTE ionizatin and
"lte_ion" if that ion_number is treated in LTE or nebular, "nlte_ion" for NLTE ionization and

@andrewfullard andrewfullard merged commit ef15f1b into master Nov 16, 2022
epassaro added a commit to epassaro/tardis that referenced this pull request Mar 21, 2023
* Adding rate matrix index (tardis-sn#2132)

* adding NlteIndexHelper class

* adding nlte_ionization_species to io/schemas/plasma.yml

* adding nlte_excitation_species to io/schemas/plasma.yml

* added nlte_ionization_species in assemble_plasma

* fixed the issue with getting nlte_ionization_species from config

* fixed transforming string from config to tuple for nlte ionization species

* ran black

* attempt of writing tests 1

* ran black

* test attempt 2

* black on test_hdf_plasma

* experimenting with revert

* attempt 3

* reverted tardis/plasma/tests/test_complete_plasmas.py

* reverted tardis/plasma/tests/test_hdf_plasma.py

* adding cofig for nlte

* adding fixture for tardis_cofig_verysimple_nlte

* added test_plasma_nlte_section_config

* ran black

* fixed the issue with the test, ran it locally

* ran black on necessary files

* updated description in schemas

* switching from nlte_ionization to be used from self

* ran black

* changed nlte_properties_new to nlte_solver_properties

* adding nlte_rate_equation_matrix.py

* reverting to previous commit

* Restructuring NumbaModel (tardis-sn#2136)

* Added NumbaRadial1DGeometry

* Added to_numba function

* Fixed incorrect naming of numba spec

* Updated docstring

* Updated to_numba docstring

* Updated docstring

* Updated numba model to contain only time explosion

* updated docstring formatting error

* Moved geometry to new geometry sub package

* Updated all functions where numba model was used

* Updated to specify units

* converting time_explosion to seconds specifically

* Added numba geometry fixture

* Updated tests to work with numba geometry

* Updated formatting

* Fixed issue with geometry initialization

* Fixed formatting

* Add missing cell to download atom data (tardis-sn#2146)

* Possible fix for prerelease workflow (tardis-sn#2127)

* Possible fix for prerelease workflow

* Fix double @ symbol

* Changed to v2

* Pin setuptools_scm to v6 (tardis-sn#2147)

* Pin setuptools_scm to v6

* Fix typo

* Adding nlte_rate_equation_solver.py (tardis-sn#2140)

* added nlte_rate_equation_matrix

* adding the rate_equation_matrix

* moved rate_matrix into a class NLTERateEquationSolver

* fixed a bug in rate_matrix_index, added an example for checking if rate matrix works properly

* changed the initial electron density for now

* added tests, fixed a small bug

* added some doctrings

* fixed a typo

* added some doctrings

* added some doctrings part 2

* added some docstrings part 3

* removed unnecessary import

* Update tardis/plasma/properties/nlte_rate_equation_solver.py

Co-authored-by: Christian Vogl <[email protected]>

* changed how atomic number is created from rate_matrix_index

* changed call of a function

* got rid of unnecessary if statement in set_nlte_ion_rate

* renamed last_row to charge_conservation_row

* switched 0, 1 to atomic_number and ion_number to make it more readable

* swtihed from rates to coefficients

* changed the matrix set up to only keep necessary row for nlte_ion

* ran black

* fixing some doctrings

* swtiched from using numbers to index names

* switched the return statement to NotImplementedError

* changed groupby from 0, 1 to atomic number, ion number

* fixed an issue in the test

* ran black

Co-authored-by: Christian Vogl <[email protected]>

* Set specific qgrid feedstock version (tardis-sn#2152)

* Pre-release 2022.11.17 (tardis-sn#2155)

Automated changes for pre-release 2022.11.17

* Post-release 2022.11.17 (tardis-sn#2156)

Automated changes for post-release 2022.11.17

* Pre-release 2022.11.20 (tardis-sn#2160)

Automated changes for pre-release 2022.11.20

* Fix relativistic packet initialization (tardis-sn#2159)

* Fix setting of full relativity flag

* Add relativistic packet source

Co-authored-by: Stuart Sim <[email protected]>

* Fix relativistic vpackets on inner boundary

Co-authored-by: Stuart Sim <[email protected]>

* Fixing typos for nlte ion (tardis-sn#2154)

* fixing typos on rate_matrix

* changed the np arange to use 0 instead of 0.0

* NLTE jacobian matrix (tardis-sn#2158)

* added jacobian matrix and deriv block functions

* added doctrings

* ran black

* switched from df to array

* added an initial test

* ran black

* reorganized the tests

* added doctrings

* added todo comments for future work

* ran black

* Kilonova missing zeta (tardis-sn#2150)

* solved KN ZetaData issue

* KN missing Zeta fixed

* mailmap changed

* Pre-release 2022.12.11 (tardis-sn#2172)

Automated changes for pre-release 2022.12.11

* Post-release 2022.12.12 (tardis-sn#2173)

Automated changes for post-release 2022.12.12

* Add missing __init__.py files to transport and geometry subpackages (tardis-sn#2170)

* Add missing __init__.py files to transport subpackage

* Add missing __init__.py file to geometry subpackage

* Pre-release 2022.12.25 (tardis-sn#2180)

Automated changes for pre-release 2022.12.25

* Post-release 2022.12.26 (tardis-sn#2182)

Automated changes for post-release 2022.12.26

* Pre-release 2023.01.08 (tardis-sn#2186)

Automated changes for pre-release 2023.01.08

* Post-release 2023.01.11 (tardis-sn#2188)

Automated changes for post-release 2023.01.11

* Downloading nlte_atom_data in ref data (tardis-sn#2187)

adding nlte_atom_data to be downloaded

* Adding nlte solver (tardis-sn#2171)

* adding solver part in the calculate method

* adding the objective function

* added the solution vector method

* final touches for the solver

* tests, attempt 1

* ran black

* fixed the issue with tests

* ran black

* added missing doctrings in the nlte_rate_equation_solver.py

* added doctrings to tests

* changed the test to explicitly calculate the lte solution ion number densities.

* ran black

* added the atom data file to download_reference_data.sh

* fixed download_reference_data.sh

* Revert "added the atom data file to download_reference_data.sh"

This reverts commit 58ce29e.

* got rid of index i, kept only shell

* switched DataFrame to pandas.DataFrame in the docstrings

* docstring bug fix

* got rid of the deepcopy of nlte atomic data file

* changed the number of shells to 5

* Update tardis/io/tests/data/tardis_configv1_nlte.yml

Co-authored-by: Christian Vogl <[email protected]>

* Update tardis/plasma/properties/nlte_rate_equation_solver.py

Co-authored-by: Christian Vogl <[email protected]>

* Update tardis/io/tests/data/tardis_configv1_nlte.yml

Co-authored-by: Christian Vogl <[email protected]>

* Update tardis/io/tests/data/tardis_configv1_nlte.yml

Co-authored-by: Christian Vogl <[email protected]>

* ran black

* Update tardis/plasma/properties/nlte_rate_equation_solver.py

Co-authored-by: Christian Vogl <[email protected]>

* Update tardis/plasma/tests/test_nlte_solver.py

Co-authored-by: Christian Vogl <[email protected]>

* restructured a summary in a docstring for the solution_vector_block

* ran black

* added the test for w=0 case

* Update tardis/plasma/properties/nlte_rate_equation_solver.py

Co-authored-by: Christian Vogl <[email protected]>

* Update tardis/plasma/properties/nlte_rate_equation_solver.py

Co-authored-by: Christian Vogl <[email protected]>

* Update tardis/plasma/tests/test_nlte_solver.py

Co-authored-by: Christian Vogl <[email protected]>

* fixed an issue in a docsting

* fixed an issue in a docsting

* removed a TODO comment

Co-authored-by: Christian Vogl <[email protected]>

* Rename T variables to temperature  (tardis-sn#2185)

* fixes tardis-sn#1600

* fixes tardis-sn#1600

* Update tardis/montecarlo/packet_source.py

Co-authored-by: Atharva Arya <[email protected]>

* fixes codestyle

* improve codestyle

* rename the function

* Update packet_source.py

* improve codequality

* add commit

* Update packet_source.py

Co-authored-by: Atharva Arya <[email protected]>

* Fixing test_store_runner_to_hdf (tardis-sn#2198)

* checking if the object has the attribute decode

* fixed another decode issue

* Reading nlte_excitation_species from config (tardis-sn#2195)

* implementing nlte_excitation

* ran black

* fixed a typo

* got rid of unnecessary lines

* rewrote tests

* made a change on assigning the config values to plasma properties

* fixed the tests

* Update tardis/io/tests/test_config_reader.py

Co-authored-by: Christian Vogl <[email protected]>

---------

Co-authored-by: Christian Vogl <[email protected]>

* Fix config reader tests (tardis-sn#2200)

Fix config tests

* Pre-release 2023.02.05 (tardis-sn#2205)

Automated changes for pre-release 2023.02.05

* Post-release 2023.02.06 (tardis-sn#2206)

Automated changes for post-release 2023.02.06

* Add version tag to simulation objects (tardis-sn#2190)

* Add test for versioning info

* Add version string to simulation objects

* Add name to mailmap

* Add another alias to mailmap

* Pre-release 2023.02.12 (tardis-sn#2208)

Automated changes for pre-release 2023.02.12

* Post-release 2023.02.16 (tardis-sn#2210)

Automated changes for post-release 2023.02.16

* Pre-release 2023.02.19 (tardis-sn#2211)

Automated changes for pre-release 2023.02.19

* Cache LFS objects in the tests workflow (tardis-sn#2194)

* Cache LFS objects (actions/checkout#165)

* Delete steps to see file size

Delete commented step which used to download LFS objects using the bash script

* Add lfs:false flag

* Add my username to .mailmap

* Cache hit and allow pytest to run all tests

* Do git lfs checkout if the cache key is found

* Post-release 2023.02.20 (tardis-sn#2213)

Automated changes for post-release 2023.02.20

* Correct the description of 'no_of_packets' in Monte Carlo Configuration (tardis-sn#2214)

* Correct the description of 'no_of_packets' in Monte Carlo Configuration

* Added a simple description

* Pre-release 2023.02.26 (tardis-sn#2222)

Automated changes for pre-release 2023.02.26

* Post-release 2023.02.27 (tardis-sn#2223)

Automated changes for post-release 2023.02.27

* Add docstrings to subpackages (tardis-sn#2204)

* add docstring to subpackage grid

* Add docstrings to subpackages

* Change comments to docstrings

* add docstrings to subpackages

* rename gui/__init__.py

* Reformat using black

* add contributor infos to mailmap file

* add extended summary to docstrings

* Add extended summary to plasma/properties

* Update tardis/io/parsers/__init__.py

Co-authored-by: Sona Chitchyan <[email protected]>

---------

Co-authored-by: kim <[email protected]>
Co-authored-by: Sona Chitchyan <[email protected]>

* Docs Fix: Download Atom Data in rpacket_tracking.ipynb (tardis-sn#2236)

Download atom data from the function

* Fix for automerge (tardis-sn#2242)

Use gh CLI to approve pull requests; use new token

* Fix for release dates (tardis-sn#2243)

* MonteCarlo packet progress bar completes to 100% (tardis-sn#2237)

* Refresh packet progress bar after every iteration

* Udpdated .mailmap

* Reformatted with black

* Fix team reviewers on workflows (tardis-sn#2246)

* Pre-release 2023.03.20 (tardis-sn#2247)

Automated changes for pre-release 2023.03.20

* Post-release 2023.03.20 (tardis-sn#2248)

Automated changes for post-release 2023.03.20

* Create new workflow

* Patch for arepo tests

* Restore deleted parameter

* Black format; Add missing skip reason

* Fix typo in comment

* Add more comments

* Create slash command dispatcher

* Changes to dispatcher

* Black format

---------

Co-authored-by: Sona Chitchyan <[email protected]>
Co-authored-by: Satwik Kambham <[email protected]>
Co-authored-by: Andrew <[email protected]>
Co-authored-by: Christian Vogl <[email protected]>
Co-authored-by: tardis-bot <[email protected]>
Co-authored-by: Stuart Sim <[email protected]>
Co-authored-by: gleck97 <[email protected]>
Co-authored-by: ABHISHEK PATIDAR <[email protected]>
Co-authored-by: Atharva Arya <[email protected]>
Co-authored-by: Kim <[email protected]>
Co-authored-by: Abhishek Patidar <[email protected]>
Co-authored-by: Le Truong <[email protected]>
Co-authored-by: kim <[email protected]>
Co-authored-by: Shreyas Singh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants