summaryrefslogtreecommitdiffstats
path: root/core/gas-model.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-08-07 22:28:31 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-08-08 15:22:09 -0700
commit2a966ac2a9a807f4ae45d671cca8b245f8f70ece (patch)
tree05e049de89fb104420b9d5f2057bb85eb6910de4 /core/gas-model.c
parent78f425de68cdb1504e477519577d22efd694fec0 (diff)
downloadsubsurface-2a966ac2a9a807f4ae45d671cca8b245f8f70ece.tar.gz
Cleanup: replace macro by inline function in gas-model.c
Replace a macro calculating a degree-three polynomial by an inline function. Moreover, calculate the powers 1, 2 and 3 of the pressure inside the function. The compiler will be smart enough to optimize this to the same code. The only important thing is to write "x*x*x*coeff" instead of "coeff*x*x*x". The compiler can't optimize the latter because ... wonderful floating point semantics. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/gas-model.c')
-rw-r--r--core/gas-model.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/core/gas-model.c b/core/gas-model.c
index 4dccdf6b3..44c64864a 100644
--- a/core/gas-model.c
+++ b/core/gas-model.c
@@ -6,7 +6,10 @@
#include "dive.h"
/* "Virial minus one" - the virial cubic form without the initial 1.0 */
-#define virial_m1(C, x1, x2, x3) (C[0]*x1+C[1]*x2+C[2]*x3)
+static double virial_m1(const double coeff[], double x)
+{
+ return x*coeff[0] + x*x*coeff[1] + x*x*x*coeff[2];
+}
/*
* Z = pV/nRT
@@ -44,7 +47,6 @@ double gas_compressibility_factor(struct gasmix gas, double bar)
+5.33304543646e-11
};
int o2, he;
- double x1, x2, x3;
double Z;
/*
@@ -58,11 +60,9 @@ double gas_compressibility_factor(struct gasmix gas, double bar)
o2 = get_o2(gas);
he = get_he(gas);
- x1 = bar; x2 = x1*x1; x3 = x2*x1;
-
- Z = virial_m1(o2_coefficients, x1, x2, x3) * o2 +
- virial_m1(he_coefficients, x1, x2, x3) * he +
- virial_m1(n2_coefficients, x1, x2, x3) * (1000 - o2 - he);
+ Z = virial_m1(o2_coefficients, bar) * o2 +
+ virial_m1(he_coefficients, bar) * he +
+ virial_m1(n2_coefficients, bar) * (1000 - o2 - he);
/*
* We add the 1.0 at the very end - the linear mixing of the