1 /*
2 * Copyright (c) 2019 Kevin Townsend (KTOWN)
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <math.h>
8 #include <errno.h>
9 #include <zsl/zsl.h>
10 #include <zsl/physics/atomic.h>
11
12 int
zsl_phy_atom_nucl_radius(uint8_t a,zsl_real_t * r)13 zsl_phy_atom_nucl_radius(uint8_t a, zsl_real_t *r)
14 {
15 if (a == 0) {
16 *r = NAN;
17 return -EINVAL;
18 }
19
20 *r = ZSL_NUCL_RADIUS * ZSL_POW((zsl_real_t) a, 1.0 / 3.0) * 1E15;
21
22 return 0;
23 }
24
25 int
zsl_phy_atom_bohr_orb_radius(uint8_t z,uint8_t n,zsl_real_t * r)26 zsl_phy_atom_bohr_orb_radius(uint8_t z, uint8_t n, zsl_real_t *r)
27 {
28 if (z == 0) {
29 *r = NAN;
30 return -EINVAL;
31 }
32
33 *r = ((zsl_real_t) n * (zsl_real_t) n * ZSL_RED_PLANCK *
34 ZSL_RED_PLANCK * 1E9) / ((zsl_real_t) z * ZSL_COULOMB *
35 ZSL_E_CHARGE * ZSL_E_CHARGE * ZSL_E_MASS);
36
37
38 return 0;
39 }
40
41 int
zsl_phy_atom_bohr_orb_vel(uint8_t z,uint8_t n,zsl_real_t * v)42 zsl_phy_atom_bohr_orb_vel(uint8_t z, uint8_t n, zsl_real_t *v)
43 {
44 if (z == 0) {
45 *v = NAN;
46 return -EINVAL;
47 }
48
49 *v = ((zsl_real_t) z * ZSL_COULOMB * ZSL_E_CHARGE * ZSL_E_CHARGE *
50 1E-3) / ((zsl_real_t) n * ZSL_RED_PLANCK);
51
52 return 0;
53 }
54
55 int
zsl_phy_atom_bohr_orb_ener(uint8_t z,uint8_t n,zsl_real_t * e)56 zsl_phy_atom_bohr_orb_ener(uint8_t z, uint8_t n, zsl_real_t *e)
57 {
58 if (z == 0) {
59 *e = NAN;
60 return -EINVAL;
61 }
62
63 *e = -(ZSL_POW(((zsl_real_t) z * ZSL_COULOMB * ZSL_E_CHARGE *
64 ZSL_E_CHARGE) / ((zsl_real_t) n * ZSL_RED_PLANCK), 2.0) * 0.5 *
65 ZSL_E_MASS) / 1.602176634E-19;
66
67 return 0;
68 }
69
70 int
zsl_phy_atom_rad_decay(zsl_real_t qi,zsl_real_t t,zsl_real_t lambda,zsl_real_t * qf)71 zsl_phy_atom_rad_decay(zsl_real_t qi, zsl_real_t t, zsl_real_t lambda,
72 zsl_real_t *qf)
73 {
74 if (t < 0 || lambda < 0) {
75 *qf = NAN;
76 return -EINVAL;
77 }
78
79 *qf = qi * ZSL_POW(ZSL_E, -lambda * t);
80
81 return 0;
82 }
83
84 int
zsl_phy_atom_bragg(uint8_t n,zsl_real_t theta,zsl_real_t lambda,zsl_real_t * d)85 zsl_phy_atom_bragg(uint8_t n, zsl_real_t theta, zsl_real_t lambda,
86 zsl_real_t *d)
87 {
88 if (lambda < 0 || sin(theta) <= 0) {
89 *d = NAN;
90 return -EINVAL;
91 }
92
93 *d = ((zsl_real_t) n * lambda) / (2.0 * ZSL_SIN(theta));
94
95 return 0;
96 }
97