[PATCH 1/2] gas model: split up gas compressibility into a file of its own

Linus Torvalds torvalds at linux-foundation.org
Wed Mar 2 14:20:20 PST 2016


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Wed, 2 Mar 2016 13:49:59 -0800
Subject: [PATCH 1/2] gas model: split up gas compressibility into a file of its own

The gas compressibility is such a specialized thing that I really prefer
having it separate.

This keeps Robert's Redlich-Kwong equation as-is, but let's experiment
with other models soon...

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---
 subsurface-core/CMakeLists.txt |  1 +
 subsurface-core/dive.c         | 43 -------------------------------------
 subsurface-core/gas-model.c    | 48 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 43 deletions(-)
 create mode 100644 subsurface-core/gas-model.c

diff --git a/subsurface-core/CMakeLists.txt b/subsurface-core/CMakeLists.txt
index 703864ad0b22..d9b1d3421a6a 100644
--- a/subsurface-core/CMakeLists.txt
+++ b/subsurface-core/CMakeLists.txt
@@ -36,6 +36,7 @@ set(SUBSURFACE_CORE_LIB_SRCS
 	divelist.c
 	equipment.c
 	file.c
+	gas-model.c
 	git-access.c
 	libdivecomputer.c
 	liquivision.c
diff --git a/subsurface-core/dive.c b/subsurface-core/dive.c
index 4108c0942711..0837675826d9 100644
--- a/subsurface-core/dive.c
+++ b/subsurface-core/dive.c
@@ -846,49 +846,6 @@ static void update_min_max_temperatures(struct dive *dive, temperature_t tempera
 	}
 }
 
-/*
- * This gives an interative solution of hte Redlich-Kwong equation for the compressibility factor
- * according to https://en.wikipedia.org/wiki/Redlich–Kwong_equation_of_state
- * in terms of the reduced temperature T/T_crit and pressure p/p_crit.
- *
- * Iterate this three times for good results in our pressur range.
- *
- */
-
-double redlich_kwong_equation(double t_red, double p_red, double z_init)
-{
-	return (1.0/(1.0 - 0.08664*p_red/(t_red * z_init)) -
-		 0.42748/(sqrt(t_red * t_red * t_red) * ((t_red*z_init/p_red + 0.08664))));
-}
-
-/*
- * At high pressures air becomes less compressible, and
- * does not follow the ideal gas law any more.
- */
-#define STANDARD_TEMPERATURE 293.0
-
-double gas_compressibility_factor(struct gasmix *gas, double bar)
-{
-	/* Critical points according to https://en.wikipedia.org/wiki/Critical_point_(thermodynamics) */
-
-	double tcn2 = 126.2;
-	double tco2 = 154.6;
-	double tche = 5.19;
-
-	double pcn2 = 33.9;
-	double pco2 = 50.5;
-	double pche = 2.27;
-
-	double tc, pc;
-
-	tc = (tco2 * get_o2(gas) + tche * get_he(gas) + tcn2 * (1000 - get_o2(gas) - get_he(gas))) / 1000.0;
-	pc = (pco2 * get_o2(gas) + pche * get_he(gas) + pcn2 * (1000 - get_o2(gas) - get_he(gas))) / 1000.0;
-
-	return (redlich_kwong_equation(STANDARD_TEMPERATURE/tc, bar/pc,
-				       redlich_kwong_equation(STANDARD_TEMPERATURE/tc, bar/pc,
-							      redlich_kwong_equation(STANDARD_TEMPERATURE/tc, bar/pc,1.0))));
-}
-
 int gas_volume(cylinder_t *cyl, pressure_t p)
 {
 	double bar = p.mbar / 1000.0;
diff --git a/subsurface-core/gas-model.c b/subsurface-core/gas-model.c
new file mode 100644
index 000000000000..9cffd5e470e0
--- /dev/null
+++ b/subsurface-core/gas-model.c
@@ -0,0 +1,48 @@
+/* gas-model.c */
+/* gas compressibility model */
+#include <stdio.h>
+#include <stdlib.h>
+#include "dive.h"
+
+/*
+ * This gives an interative solution of hte Redlich-Kwong equation for the compressibility factor
+ * according to https://en.wikipedia.org/wiki/Redlich–Kwong_equation_of_state
+ * in terms of the reduced temperature T/T_crit and pressure p/p_crit.
+ *
+ * Iterate this three times for good results in our pressur range.
+ *
+ */
+
+double redlich_kwong_equation(double t_red, double p_red, double z_init)
+{
+	return (1.0/(1.0 - 0.08664*p_red/(t_red * z_init)) -
+		 0.42748/(sqrt(t_red * t_red * t_red) * ((t_red*z_init/p_red + 0.08664))));
+}
+
+/*
+ * At high pressures air becomes less compressible, and
+ * does not follow the ideal gas law any more.
+ */
+#define STANDARD_TEMPERATURE 293.0
+
+double gas_compressibility_factor(struct gasmix *gas, double bar)
+{
+	/* Critical points according to https://en.wikipedia.org/wiki/Critical_point_(thermodynamics) */
+
+	double tcn2 = 126.2;
+	double tco2 = 154.6;
+	double tche = 5.19;
+
+	double pcn2 = 33.9;
+	double pco2 = 50.5;
+	double pche = 2.27;
+
+	double tc, pc;
+
+	tc = (tco2 * get_o2(gas) + tche * get_he(gas) + tcn2 * (1000 - get_o2(gas) - get_he(gas))) / 1000.0;
+	pc = (pco2 * get_o2(gas) + pche * get_he(gas) + pcn2 * (1000 - get_o2(gas) - get_he(gas))) / 1000.0;
+
+	return (redlich_kwong_equation(STANDARD_TEMPERATURE/tc, bar/pc,
+				       redlich_kwong_equation(STANDARD_TEMPERATURE/tc, bar/pc,
+							      redlich_kwong_equation(STANDARD_TEMPERATURE/tc, bar/pc,1.0))));
+}
-- 
2.7.2.334.g7c0da37



More information about the subsurface mailing list