1 /*
2  * Copyright (c) 2019-2020 Kevin Townsend (KTOWN)
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @addtogroup ELECTRIC Electric
9  *
10  * @brief Electric functions.
11  *
12  * @ingroup PHYSICS
13  *  @{ */
14 
15 /**
16  * @file
17  * @brief API header file for electrics in zscilib.
18  *
19  * This file contains the zscilib electric APIs
20  */
21 
22 #ifndef ZEPHYR_INCLUDE_ZSL_ELECTRIC_H_
23 #define ZEPHYR_INCLUDE_ZSL_ELECTRIC_H_
24 
25 #include <zsl/zsl.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /**
32  * @brief Calculates the uniform charge density of an charged body based on its
33  *        charge and its volume.
34  *
35  * @param q    Charge of the body in coulombs.
36  * @param v    Volume of the body in meters cubed.
37  * @param d    Pointer to the output uniform charge density in coulombs per
38  *             meter cubed. Will be set to NAN if the volume is negative
39  *             or zero.
40  *
41  * @return 0 if everything executed properly, error code on failure.
42  */
43 int zsl_phy_elec_charge_dens(zsl_real_t q, zsl_real_t v, zsl_real_t *d);
44 
45 /**
46  * @brief Calculates the electric force in newtons between two charged
47  *        bodies based on their charges and the distance between them.
48  *
49  * @param q1   Charge of the first body in coulombs.
50  * @param q2   Charge of the second body in coulombs.
51  * @param r    Distance between the two bodies.
52  * @param f    Pointer to the output electric force in newtons. Will be set to
53  *             NAN if the distance is negative or zero.
54  *
55  * @return 0 if everything executed properly, error code on failure.
56  */
57 int zsl_phy_elec_force(zsl_real_t q1, zsl_real_t q2, zsl_real_t r,
58 		       zsl_real_t *f);
59 
60 /**
61  * @brief Calculates the electric force in newtons that a charged body
62  *        experiences when it enters an electric field.
63  *
64  * @param q    Charge of the body in coulombs.
65  * @param e    Electric field in newtons per coulomb.
66  * @param f    Pointer to the output electric force in newtons.
67  *
68  * @return 0 if everything executed properly, error code on failure.
69  */
70 int zsl_phy_elec_force2(zsl_real_t q, zsl_real_t e, zsl_real_t *f);
71 
72 /**
73  * @brief Calculates the electric field created by a charged body anywhere in
74  *        space.
75  *
76  * @param q    Charge of the body in coulombs.
77  * @param r    Distance to the body in meters.
78  * @param e    Pointer to the output electric field in newtons per coulomb.
79  *             Will be set to NAN if the distance is negative or zero.
80  *
81  * @return 0 if everything executed properly, error code on failure.
82  */
83 int zsl_phy_elec_field(zsl_real_t q, zsl_real_t r, zsl_real_t *e);
84 
85 /**
86  * @brief Calculates the electric potential energy in joules of two charged
87  *        bodies based on their charges and the distance between them.
88  *
89  * @param q1   Charge of the first body in coulombs.
90  * @param q2   Charge of the second body in coulombs.
91  * @param r    Distance between the two bodies.
92  * @param u    Pointer to the output potential energy in joules. Will be set to
93  *             NAN if the distance is negative or zero.
94  *
95  * @return 0 if everything executed properly, error code on failure.
96  */
97 int zsl_phy_elec_pot_ener(zsl_real_t q1, zsl_real_t q2, zsl_real_t r,
98 			  zsl_real_t *u);
99 
100 /**
101  * @brief Calculates the Coulomb's potential of a charged body anywhere in
102  *        space.
103  *
104  * @param q    Charge of the body in coulombs.
105  * @param r    Distance to the body in meters.
106  * @param v    Pointer to the output potential in volts. Will be set to NAN if
107  *             the distance is negative or zero.
108  *
109  * @return 0 if everything executed properly, error code on failure.
110  */
111 int zsl_phy_elec_potential(zsl_real_t q, zsl_real_t r, zsl_real_t *v);
112 
113 /**
114  * @brief Calculates the electric flux that flows across a surface based on the
115  *        area (a), the electric field (b) and the angle they form.
116  *
117  * @param e       Module of the electric field vector in newtons per coulomb.
118  * @param a       Surface in meters squared.
119  * @param theta   Angle between the vector normal to the surface and the
120  *                electric field vector in radians.
121  * @param fl      Pointer to the output electric flux in newtons and meters
122  *                squared per coulomb. Will be set to NAN if the area or the
123  *                electric field are negative values.
124  *
125  * @return 0 if everything executed properly, error code on failure.
126  */
127 int zsl_phy_elec_flux(zsl_real_t e, zsl_real_t a, zsl_real_t theta,
128 		      zsl_real_t *fl);
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 #endif /* ZEPHYR_INCLUDE_ZSL_ELECTRIC_H_ */
135 
136 /** @} */ /* End of electric group */
137