mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
78f425de68
commit
2a966ac2a9
1 changed files with 7 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue