Changeset bb6ceba in subsurface


Ignore:
Timestamp:
May 26, 2017, 3:52:04 PM (3 months ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
98a65b7
Parents:
e6d884c
git-author:
Robert C. Helling <helling@…> (05/12/17 06:36:24)
git-committer:
Dirk Hohndel <dirk@…> (05/26/17 15:52:04)
Message:

Compute and display gas density

This appears to be critical for work of breathing so it might be
worthwhile to compute. So far only in infobox.

For background, see

https://www.youtube.com/watch?v=QBajM3xmOtc

Signed-off-by: Robert C. Helling <helling@…>

Location:
core
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • core/dive.h

    r7b18be2a rbb6ceba  
    140140extern double gas_compressibility_factor(struct gasmix *gas, double bar);
    141141extern double isothermal_pressure(struct gasmix *gas, double p1, int volume1, int volume2);
     142extern double gas_density(struct gasmix *gas, int pressure);
     143
    142144
    143145
  • core/gas-model.c

    rb368ecd rbb6ceba  
    1010
    1111/*
     12 * Z = pV/nRT
     13 *
    1214 * Cubic virial least-square coefficients for O2/N2/He based on data from
    1315 *
     
    7476        return p_ideal * gas_compressibility_factor(gas, p_ideal);
    7577}
     78
     79inline double gas_density(struct gasmix *gas, int pressure) {
     80        int density =  gas->he.permille * HE_DENSITY + gas->o2.permille * O2_DENSITY + (1000 - gas->he.permille - gas->o2.permille) * N2_DENSITY;
     81
     82        return density * (double) pressure / gas_compressibility_factor(gas, pressure / 1000.0) / SURFACE_PRESSURE / 1000000.0;
     83}
  • core/profile.c

    r7b18be2a rbb6ceba  
    11521152                                       entry->pressures.he / amb_pressure * HE_DENSITY) /
    11531153                                      (O2_IN_AIR * O2_DENSITY + N2_IN_AIR * N2_DENSITY) * 1000 - 10000;
     1154                entry->density = gas_density(&dive->cylinder[cylinderindex].gasmix, depth_to_mbar(entry->depth, dive));
    11541155                if (entry->mod < 0)
    11551156                        entry->mod = 0;
     
    12931294        int pressurevalue, mod, ead, end, eadd;
    12941295        const char *depth_unit, *pressure_unit, *temp_unit, *vertical_speed_unit;
    1295         double depthvalue, tempvalue, speedvalue, sacvalue;
     1296        double depthvalue, tempvalue, speedvalue, sacvalue, density;
    12961297        int decimals;
    12971298        const char *unit;
     
    13281329        }
    13291330        eadd = lrint(get_depth_units(lrint(entry->eadd), NULL, &depth_unit));
     1331
    13301332        if (prefs.ead) {
    13311333                switch (pi->dive_type) {
     
    13331335                        ead = lrint(get_depth_units(lrint(entry->ead), NULL, &depth_unit));
    13341336                        put_format(b, translate("gettextFromC", "EAD: %d%s\nEADD: %d%s\n"), ead, depth_unit, eadd, depth_unit);
     1337                        put_format(b, translate("gettextFromC", "density: %.1fg/l\n"), entry->density);
    13351338                        break;
    13361339                case TRIMIX:
    13371340                        end = lrint(get_depth_units(lrint(entry->end), NULL, &depth_unit));
    13381341                        put_format(b, translate("gettextFromC", "END: %d%s\nEADD: %d%s\n"), end, depth_unit, eadd, depth_unit);
     1342                        put_format(b, translate("gettextFromC", "density: %.1fg/l\n"), entry->density);
    13391343                        break;
    13401344                case AIR:
  • core/profile.h

    rb368ecd rbb6ceba  
    6565        double ambpressure;
    6666        double gfline;
     67        double density;
    6768};
    6869
  • core/units.h

    r876b479 rbb6ceba  
    1515#define N2_IN_AIR 781
    1616#define O2_DENSITY 1429 // mg/Liter
    17 #define N2_DENSITY 1251
     17#define N2_DENSITY 1165
    1818#define HE_DENSITY 179
    1919#define SURFACE_PRESSURE 1013 // mbar
Note: See TracChangeset for help on using the changeset viewer.