Skip to content

Conversation

@lucafedeli88
Copy link
Member

@lucafedeli88 lucafedeli88 commented May 5, 2022

This PR does mainly three things:

  • It adds new species to the possible PhysicalSpecies (muon, antimuon, protium, deuterium, tritium, helium3, helium4, lithium, lithium6, lithium7, beryllium, carbon12, carbon13, nitrogen14, nitrogen15, oxygen16, oxygen17, oxygen18, fluorine, neon, neon20, neon21, neon22, aluminum, gold). All the stable isotopes with Z<=10 and selected heavier elements are provided.

  • It consistently uses atomic mass units for the ion masses. Note that the mass of the proton is now slightly different from the mass of protium, which includes the mass of the bound electron. Similarly, the mass of alpha is not exactly equal to the mass of helium4

  • It refactors the SpeciesPhysicalProperties source file. All the properties are now in a .cpp file and are stored using std::map

The documentation has been updated to include the new options for the physical species.

⚠️ Some tests are failing because now the hydrogen mass and the helium mass are not equal to the proton mass and the alpha mass (atomic masses include the electron contributions). We may want to discuss this point.

@lucafedeli88 lucafedeli88 added the question Further information is requested label May 6, 2022
@ax3l
Copy link
Member

ax3l commented May 9, 2022

Hi @lucafedeli88 , splendid :)

@lucafedeli88 lucafedeli88 changed the title Add new entries in Physical Species properties (+ refactoring of the SpeciesPhysicalProperties file) [WIP] Add new entries in Physical Species properties (+ refactoring of the SpeciesPhysicalProperties file) May 18, 2022
@ax3l ax3l mentioned this pull request May 31, 2022
@ax3l
Copy link
Member

ax3l commented May 31, 2022

@lucafedeli88 please feel free to remove the [WIP] once ready.

I think we would use this in #3153

Currently, the accepted species are ``"electron"``, ``"positron"``, ``"photon"``, ``"hydrogen"`` (or equivalently ``"proton"``), ``"helium"`` (or equivalently ``"alpha"``), ``"boron"``, ``"carbon"``, ``"oxygen"``, ``"nitrogen"``, ``"argon"``, ``"copper"`` and ``"xenon"``.
Either this or both ``mass`` and ``charge`` have to be specified.
Currently, the accepted species are
``"electron"``, ``"positron"``, ``"muon"``, ``"antimuon"``, ``"photon"``, ``"proton"`` , ``"alpha"``,
Copy link
Member

Choose a reason for hiding this comment

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

Could you also add neutron?

Copy link
Member

@RemiLehe RemiLehe left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this PR! This is very useful.
I added a few inline comments.

@RemiLehe RemiLehe changed the title [WIP] Add new entries in Physical Species properties (+ refactoring of the SpeciesPhysicalProperties file) Add new entries in Physical Species properties (+ refactoring of the SpeciesPhysicalProperties file) Jun 3, 2022
@RemiLehe
Copy link
Member

RemiLehe commented Jun 9, 2022

I have updated the values according to this NIST page

Here is the Python script that I used in order to parse and re-format this data:

import re
from scipy.constants import m_e, m_u
import periodictable

# Extract the element names from the package `periodictable`
element_names = {}
for el in periodictable.elements:
    element_names[el.number] = el.name

# Read file (downloaded from
# https://physics.nist.gov/cgi-bin/Compositions/stand_alone.pl?ele=&ascii=ascii2&isotype=some
with open('./data.html') as f:
    text = f.read()

# Parse the file to extract the numbers
atomic_data = re.findall(r'Atomic Number = (.*)\nAtomic Symbol = (.*)\nMass Number = (.*)\nRelative Atomic Mass = (\d+.\d*).*\n.*\nStandard Atomic Weight = (.*)', text)

# Go through the isotopes and print the information in the right format.
already_printed_Z_avg = []

for line in atomic_data:
    Z = int(line[0])
    N = line[2]

    # Average property across isotopes
    if Z <= 10 or element_names[Z] in ["aluminium", "argon", "copper", "xenon", "gold"]:
        if Z not in already_printed_Z_avg:
            already_printed_Z_avg.append(Z)
            values = re.findall('\d+\.\d+', line[4])
            n_digits = len(values[0])
            m_avg = sum([ float(v) for v in values])/len(values)
            m_avg = str(m_avg)[:n_digits]
            print('{PhysicalSpecies::' + element_names[Z]
                  + ', Properties{\n     amrex::Real(' + str(m_avg)
                  +') * PhysConst::m_u,\n     amrex::Real(' + str(Z) + ') * PhysConst::q_e}},')

    # Properties specific to that isotope
    m = line[3]
    if Z <= 10:
        print('{PhysicalSpecies::' + element_names[Z] + N
              + ', Properties{\n     amrex::Real(' + str(m)
              +') * PhysConst::m_u,\n     amrex::Real(' + str(Z) + ') * PhysConst::q_e}},')

@RemiLehe RemiLehe enabled auto-merge (squash) June 9, 2022 21:04
@RemiLehe RemiLehe force-pushed the improve_SpeciesPhysicalProperties branch from c416b0e to 73c8d9d Compare June 10, 2022 18:04
@RemiLehe
Copy link
Member

Latest update:
The changes in this PR cause a few checksum changes (which is to be expected) but also causes the physics check of the automated test for the fusion module to fail (which is not really expected).
This will probably need to be investigated.

@NeilZaim
Copy link
Contributor

Hi @RemiLehe. I've looked into the fusion test failing with this PR. Basically this is because the masses of helium and of boron11 have been changed (at the keV level, which is small but sufficient to trigger the CI test). There are a few places where this change needs to be taken into account:

I have tested with these changes locally and the CI tests almost passed, I just needed to make one more small modification here:

https://github.com/ECP-WarpX/WarpX/blob/542ef3c09b467974b5bd9d1e3b25a208e3296562/Examples/Modules/nuclear_fusion/analysis_proton_boron_fusion.py#L384
I've replaced that line with return E_com_kin*(p_proton_sq>0.) (because of machine precision errors, that function was returning a small but negative number instead of 0 when p_proton_sq was 0, which made the test fail later on).

@RemiLehe
Copy link
Member

RemiLehe commented Jul 1, 2022

@NeilZaim Thanks a lot for looking into this.
Do you want me to make the above-mentioned changes on this PR, or are you also able to push those changes here?

@NeilZaim
Copy link
Contributor

NeilZaim commented Jul 1, 2022

@RemiLehe I don't think I have write access, so it's probably easier if you or @lucafedeli88 do the changes.

@RemiLehe
Copy link
Member

RemiLehe commented Jul 5, 2022

OK, I have made the above-mentioned changes and have reset the benchmarks.

@RemiLehe RemiLehe merged commit 5d5f118 into BLAST-WarpX:development Jul 5, 2022
dpgrote pushed a commit to RemiLehe/WarpX that referenced this pull request Jul 30, 2022
…SpeciesPhysicalProperties file) (BLAST-WarpX#3090)

* initial work

* fixed bugs and added species

* update documentation

* delete unused file

* Add neutron

* Fix nuclear fusion

* Reset benchmarks

* Update values of mass and charge

* Correct compilation error

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: Remi Lehe <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@lucafedeli88 lucafedeli88 deleted the improve_SpeciesPhysicalProperties branch May 10, 2023 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleaning Clean code, improve readability enhancement New feature or request question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants