/* Title: equations.h
 * Author: Jed Marti KI7NNP
 * Description: Prototypes and constants for inductance calculations.
 * Revision History: (Created Thu Jan 25 19:39:01 2024)
 */

#ifndef equations_h
#define equations_h

#ifndef M_PI
  #define M_PI 3.14159265358979323846
#endif

// Free space permeability. This is 4 pi * 10(-7)
#define u0 1.256637061435916e-06

// The new value based on Plank's constant and elementary charge in 2019.
#define u0x 1.25663706212e-06

// For the table of equations and their analysis.
typedef double (*eqn)(double rm, int32_t n, double lm, double wm);
typedef uint8_t (*isgood)(double rm, int32_t n, double lm, double wm);

typedef struct {
  eqn    computeUh;            // Compute inductance in uH.
  isgood recommend;            // Recommend or not.
} equations;
  
enum {
      bletcherous,             // Worse than 100%
      notRecommended,          // Worse than 10%
      marginal,                // Worse than 7.5% but < 10%
      reasonable,              // Worse than 5% but < 7.5%
      recommended,             // Worse than 2% but < 5%
      highlyRecommended        // Best.
};

#define REC  { \
      "notRecommended", \
      "marginal", \
      "reasonable", \
      "recommended", \
	"highlyRecommended" }

#define inches2meters(x) ((x) * 0.0254)
#define meters2inches(x) ((x) / 0.0254)

// Elliptical Miller solver - nearly the same as Lundin.
double miller(double rm, int32_t turns, double len, double wm);
uint8_t recmiller(double rm, int32_t turns, double len, double wm);

// ARRL and modifications.
double ARRLOriginal(double rm, int32_t n, double lm, double wm);
uint8_t recARRLOriginal(double rm, int32_t n, double lm, double wm);
double ARRLTurns(double rm, int32_t n, double lm, double wm);
uint8_t recARRLTurns(double rm, int32_t n, double lm, double wm);
double ARRLcspacing(double rm, int32_t n, double lm, double wm);
uint8_t recARRLcspacing(double rm, int32_t n, double lm, double wm);
double ARRLall22(double rm, int32_t n, double lm, double wm);
uint8_t recARRLall22(double rm, int32_t n, double lm, double wm);
double ARRLall(double rm, int32_t n, double lm, double wm);
uint8_t recARRLall(double rm, int32_t n, double lm, double wm);

// Simple.
double Simple(double rm, int32_t n, double lm, double wm);
uint8_t recSimple(double rm, int32_t n, double lm, double wm);

// Equation 8. ARRL with cubics.
double Equation8(double rm, int32_t n, double lm, double wm);
uint8_t recEquation8(double rm, int32_t n, double lm, double wm);

// Equation A - only 22.
double EquationA(double rm, int32_t n, double lm, double wm);
uint8_t recEquationA(double rm, int32_t n, double lm, double wm);

// Equation D - everybody.
double EquationD(double rm, int32_t n, double lm, double wm);
uint8_t recEquationD(double rm, int32_t n, double lm, double wm);

// Equation F - Cubics all around, no wire gauge.
double EquationF(double rm, int32_t n, double lm, double wm);
uint8_t recEquationF(double rm, int32_t n, double lm, double wm);

// Equation G - Poor - only 22.
double EquationG(double rm, int32_t n, double lm, double wm);
uint8_t recEquationG(double rm, int32_t n, double lm, double wm);

// Equation H - Poor - only 22.
double EquationH(double rm, int32_t n, double lm, double wm);
uint8_t recEquationH(double rm, int32_t n, double lm, double wm);

// Equation I - All, reasonable.
double EquationI(double rm, int32_t n, double lm, double wm);
uint8_t recEquationI(double rm, int32_t n, double lm, double wm);

// RF Circuit design
double rfc(double rm, int32_t n, double lm, double wm);
uint8_t recrfc(double rm, int32_t n, double lm, double wm);

// Ludwig and Bdanov.
double rf1(double rm, int32_t n, double lm, double wm);
uint8_t recrf1(double rm, int32_t n, double lm, double wm);

// Lundin - simple version of Miller.
double lundin(double rm, int32_t n, double lm, double wm);
uint8_t reclundin(double rm, int32_t n, double lm, double wm);

#endif


// EOF
