1 /*
2  * Copyright (c) 2019-2020 Kevin Townsend (KTOWN)
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @addtogroup GASES Gases
9  *
10  * @brief Gas functions.
11  *
12  * @ingroup PHYSICS
13  *  @{ */
14 
15 /**
16  * @file
17  * @brief API header file for gases in zscilib.
18  *
19  * This file contains the zscilib gases APIs
20  */
21 
22 #ifndef ZEPHYR_INCLUDE_ZSL_GASES_H_
23 #define ZEPHYR_INCLUDE_ZSL_GASES_H_
24 
25 #include <zsl/zsl.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /**
32  * @brief Calculates the average velocity of a gas molecule based on the mass of
33  *        gas (m), its temperature (t) and the number of moles of gas (n).
34  *
35  * @param m    Mass of gas in kilograms.
36  * @param n    Number of moles of gas.
37  * @param t    Temperature in kelvins.
38  * @param v    Pointer to the calculated velocity in meters per second. Will be
39  *             set to NAN if the temperature, mass or moles of gas are negative,
40  *             or if m = 0.
41  *
42  * @return 0 on success, and non-zero error code on failure.
43  */
44 int zsl_phy_gas_av_vel(zsl_real_t m, zsl_real_t n, zsl_real_t t, zsl_real_t *v);
45 
46 /**
47  * @brief Calculates the pressure of an ideal gas based on the number of moles,
48  *        the temperature and the volume of gas.
49  *
50  * @param v    Volume of gas in meters cubed.
51  * @param n    Number of moles of gas.
52  * @param t    Temperature in kelvins.
53  * @param p    Pointer to the placeholder for calculated pressure in pascals.
54  *             Will be set to NAN if the temperature, volume or moles of gas
55  *             are negative, or if v = 0.
56  *
57  * @return 0 on success, and non-zero error code on failure.
58  */
59 int zsl_phy_gas_press(zsl_real_t v, zsl_real_t n, zsl_real_t t, zsl_real_t *p);
60 
61 /**
62  * @brief Given the initial and final pressure, and the initial volume of an
63  *        ideal gas, this function calculates the final volume of the gas
64  *        supposing the temperature hasn't changed through the process.
65  *
66  * @param pi    Initial pressure in pascals.
67  * @param vi    Initial volume in meters cubed.
68  * @param pf    Final pressure in pascals.
69  * @param vf    Pointer to the output final volume in meters cubed. Will be set
70  *              to NAN if any of the input values are negative or if pf = 0.
71  *
72  * @return 0 on success, and non-zero error code on failure.
73  */
74 int zsl_phy_gas_boyle(zsl_real_t pi, zsl_real_t vi, zsl_real_t pf,
75 		      zsl_real_t *vf);
76 
77 /**
78  * @brief Given the initial and final temperature, and the initial volume of an
79  *        ideal gas, this function calculates the final volume of the gas
80  *        supposing its pressure hasn't changed through the process.
81  *
82  * @param ti    Initial temperature in kelvins.
83  * @param vi    Initial volume in meters cubed.
84  * @param tf    Final temperature in kelvins.
85  * @param vf    Pointer to the output final volume in meters cubed. Will be set
86  *              to NAN if any of the input values are negative or if ti = 0.
87  *
88  * @return 0 on success, and non-zero error code on failure.
89  */
90 int zsl_phy_gas_charles_lussac(zsl_real_t ti, zsl_real_t vi, zsl_real_t tf,
91 			       zsl_real_t *vf);
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
97 #endif /* ZEPHYR_INCLUDE_ZSL_GASES_H_ */
98 
99 /** @} */ /* End of gases group */
100