-
Notifications
You must be signed in to change notification settings - Fork 170
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
Codata constants. #800
Codata constants. #800
Conversation
Thank you @MilanSkocic for this PR. A general question/comment is about the kinds provided. I think we should try to provide at least single and double precision (it should be easy with |
Just a style comment. Maybe instead of defining the actual value of the constants with |
I have a dedicated repo for generating the constants for the stdlib (https://github.com/MilanSkocic/stdlib_codata) where I have tested single precisions. However, I've got overflows for some constants. I also have my package where I provided codata constants for 2018, 2014 and 2010. In my point of view single precision are not relevant for the codata constants. |
Right! I will make the change as soon as possible. |
This is a very interesting proposal @MilanSkocic. I have a comment that does not want to mandate any specifications, but just lay out ideas on how this could be made the most productive. have looked at the state of the art as offered from other well-established packages: Scipy offers a full range of CODATA constants.
The drawback is you need to import all operators, not only the constant: use stdlib_codata, only: ALPHA_PARTICLE_ELECTRON_MASS_RATIO, operator(+), operator(/), assignment(=), ...
interface gravitational_constant
module procedure g_sp
module procedure g_dp
...
end interface
!...
elemental real(dp) function g_dp(mold)
real(dp), intent(in), optional :: mold ! dp is the default kind
g_dp = real(NEWTONIAN_CONSTANT_OF_GRAVITATION%value, kind=dp)
end function g_dp
elemental real(dp) function g_sp(mold)
real(sp), intent(in) :: mold ! sp is not the default kind -> not optional
g_sp = real(NEWTONIAN_CONSTANT_OF_GRAVITATION%value, kind=sp)
ed function g_sp
!etc. so one could use them like
|
Or maybe use the generic facility to avoid having to declare an interface for each constant? like this: https://godbolt.org/z/17qP4TWoa |
It's definitely useful if this class has a few methods (including a nice |
@perazz You are right, in Scipy, some of the most common physical constants are available directly as reals. They are aliases to the values of the complete list of Codata constants which are implemented as a dictionary where keys are names and items are tuples containing the value, the uncertainty and the unit. An example of using the constants: program test
! use of the aliases to the values of the most common codata constants and mathematical constants
use stdlib_constants, only: c, PI
! use of other codata constants
use stdlib_codata, only: ALPHA_PARTICLE_ELECTRON_MASS_RATIO
real :: b
b = ALPHA_PARTICLE_ELECTRON_MASS_RATIO%eval(b) ! generic facility
end program test A more advanced use of the program test
use stdlib_codata, only: ALPHA_PARTICLE_ELECTRON_MASS_RATIO
use stdlib_kinds, only: dp
real(dp), parameter :: alpha = ALPHA_PARTICLE_ELECTRON_MASS_RATIO%value
end program test |
Update based on suggestions from @perazz and @jalvesz:
|
Do I need to create the associated documentation in |
Yes, please. It could be called
It should be in a dedicated subfolder, e.g., |
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
|
Faire point @perazz
I will not be a user of such data. But i think that they should be kept in
stdlib. Both notations are fine for me
Le mar. 21 mai 2024, 17:43, Federico Perini ***@***.***> a
écrit :
… ***@***.**** commented on this pull request.
------------------------------
In src/stdlib_constants.fypp
<#800 (comment)>:
> + STEFAN_BOLTZMANN_CONSTANT, &
+ WIEN_WAVELENGTH_DISPLACEMENT_LAW_CONSTANT, &
+ RYDBERG_CONSTANT, &
+ ELECTRON_MASS, &
+ PROTON_MASS, &
+ NEUTRON_MASS, &
+ ATOMIC_MASS_CONSTANT
+ private
+
+ ! mathematical constants
+ #:for k in KINDS
+ real(${k}$), parameter, public :: PI_${k}$ = acos(-1.0_${k}$) !! PI
+ #:endfor
+
+ ! Physical constants
+ real(dp), parameter, public :: c = SPEED_OF_LIGHT_IN_VACUUM%value !! Speed of light in vacuum
When using numeric constants, the shorter their names the better imho.
Because they're inside a module that only contains them, I think they're
mostly harmless. In case one has overlapping names, they can always rename
them as:
use stdlib_constants, only: clight => c
Of course, it's important that their names are not confusing as @awvwgk
<https://github.com/awvwgk> is suggesting. But here they're taken from
Scipy, so, probably a good reference for most people coming from the Python
world.
—
Reply to this email directly, view it on GitHub
<#800 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD5RO7DZ36D3LZGQH6ER4JTZDNTSLAVCNFSM6AAAAABGRC7NM6VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDANRYHE4TIMRTGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Do we have an agreement to proceed without any prefix on the constants as they are defined in Scipy? @jvdp1 |
Thank you @MilanSkocic |
LGTM!! brilliant work @MilanSkocic |
thank you @MilanSkocic for this PR. I will merge it. @MilanSkocic Don't hesitate to advertise this new addition on Discourse and other channels. |
Thank you @jvdp1 ! I'm glad the codata constants have been merged. For sure I'll advertise the addition. |
The codata constants are implemented as derived types (#347). This way, the values, the uncertainties and the units are easily available. Only the latest release is implemented i.e. 2018. The 2022 CODATA adjustment are not available yet.
The constants, as provided by the NIST, are double precision reals and I though it was useless to provide to include any other precision.
Your comments and suggestions are welcome.