Tuesday, October 10, 2017

The Art of Making Thermal Expansion Graphs

Gardens By The Bay
It has been a while since I published any C++ source code (Weekend Rebel Science Excursion - 49).

The last one, linked to above, had to do with some of the simple basics of sea level rise calculations.

As with ghost-water (NASA Busts The Ghost), calculating thermal expansion is another one of those "mysto" areas being focused on by scientists.

Today, I present source code written in the C++ programming language.

It is real code, but the data is limited to a ten episode (e.g. year) range., nevertheless, it shows how the thermosteric volume of the ocean can change even if the mass volume does not.

Those thermosteric volume changes are caused by temperature change in the body of water being measured.

Before we look at the code and what it produces, here are some comments about the subject:
"To be a bit more scientific about the matter before we end, let’s quote an interesting study by the Potsdam Institute for Climate Impact Research, published in 2013 in PNAS (called ‘The Multi-millenial sea level commitment of global warming’). This research group thinks of the final future sea level rise Greenland would contribute about 25 percent, Antarctica (combined) about 50 percent, smaller glaciers about 5 percent – and thermal expansion about 20 percent."
(Bits of Science). There is another paper which I have quoted that points out a wide spread problem of improper calculations routinely done in this matter (On The More Robust Sea Level Computation Techniques - 5).

Some of the models are even older than some of the software advances in recent years (e.g. TEOS-10 toolkit), as regular readers know.

But there are other issues too:
"The thermal expansion of the ocean has been investigated by a spectrum of climate models of different complexity, ranging from zero-dimensional diffusion models ... via Earth System Models of Intermediate Complexity (EMIC) ... to comprehensive general circulation models ... Although uncertainty remains, especially owing to uncertainty in the ocean circulation and thereby the distribution of heat within the ocean, the physical processes are relatively well understood even if not fully represented in all models."
(The multimillennial sea-level commitment of global warming). Scientists are not unified as to whether or not thermal expansion is "a" or "the" major cause of sea level rise.

A recent paper points this out:
"On the basis of the GRACE data, we conclude that most of the change in ocean mass is caused by the melting of polar ice sheets and mountain glaciers. This contribution of ice melt is larger than previous estimates, but agrees with reports of accelerated ice melt in recent years."
(Nature, emphasis added). One limiting factor is calculating the thermal coefficient of sea water (Thermal expansion co-efficient of sea water), which the TEOS-10 toolkit solves nicely with the "gsw_alpha" function.

Anyway, here is the software code:

/** std C++ header files */
#include <iostream>
#include <fstream>
#include <iomanip>

/** TEOS header file */
#include <gswteos-10 .h>

using namespace std;

V1 = V0(1 + β ΔT)
V1 means new volume
V0 means original volume
β means thermal expansion coefficient
ΔT means change in temperature (t1 - t0)
double thermalExpansion(double currentOceanVolume, /** V0 */
                                          double tec, /** β */
                                          double t1, /** ΔT half */
                                          double t0) /** ΔT half */
        double V0 = currentOceanVolume;
        double B = tec;
        double DT = t1 - t0;
        double V1 = V0*(1 + B * DT);

        return V1;

This sample program
calculates thermal
expansion & contraction
from a list of ocean water
temperatures which
represent in situ

Those in situ measurements
are converted to TEOS
values via TEOS
(gsw_....) functions.
int main()
         volume acquired at: Live Science
        const double oceanVol2010 = 1332370930.2; /** cu km */

        number of cubic kilometers per millimeter of sea level change
        const double cuKmPerMm = 361.841;

        /** maximum number of temperatures */
        const unsigned maxTemperatures = 11;

        /** in situ temperatures, in degrees C */
        const double temperatures[maxTemperatures] =
        {5.5,6.5,7.5,8.0,8.5,8.0,7.5,7.0,6.5,6.0, 5.5};

        /** practical salinity */
        const double Sp = 34.15;

        /** ocean depth of measurements, in meters */
        const double depth = 60.25;

        latitude, longitude of measurements
        (off W. Coast of U.S.)
        const double lat = 35.33;
        const double lon = -150.21;

        /** variables for storing net steric balances */
        double netTETC = 0; /** net thermal expansion / contraction */
        double netSLC = 0; /** net sea level change, in millimeters */

        /** report text file */
        ofstream textFile("output-files/thermal_expansion.txt");

        textFile << setprecision(12)
        << "initial volume of ocean: "
        << oceanVol2010 << " (cu. km.)"
        << endl << endl;

         for loop: calculates thermal expansion/contraction
         from temperatures specified @ the temperature array         **********************************************************/
        for (unsigned tPos = 1; tPos < maxTemperatures; tPos++)
                /** select temperatures */
                double Tnow = temperatures[tPos];
                double Tbefore = temperatures[tPos-1];

                /** save temperature changes to text file */
                textFile << setprecision(2)
                << tPos << ")\t"
                << "Temp. before: " << Tbefore << endl
                << "\tTemp. now: " << Tnow << endl
                << "\tTemp. change: "
                << Tnow - Tbefore << " (deg C)"
                << endl;

                 convert depth @ lat to TEOS Z
                double Z = gsw_z_from_p(depth, lat);

                /** calculate TEOS pressure (dbars) */
                double P = gsw_p_from_z(Z, lat);

                /** calculate TEOS absolute salinity (g/kg) */
                double SA = gsw_sa_from_sp(Sp,P,lon,lat);

                /** calculate TEOS conservative temperature */
                double CT = gsw_ct_from_t(SA,Tnow,P);

                /** calculate TEOS thermal expansion coefficient */
                double tec = gsw_alpha(SA, CT, P);

                 calculate thermosteric
                 volume using a constant
                 mass-volume value
                double TEvolume = thermalExpansion(oceanVol2010, tec, Tbefore, Tnow);

                /** record the TE volume changes */
                netTETC += oceanVol2010 - TEvolume;

                /** record sea level changes (mm) */
                netSLC = netTETC / cuKmPerMm;

                /** save changes to report file */
                textFile << setprecision(12)
                << "\tthis volume change: " << oceanVol2010 - TEvolume
                << " (cu. km)"
                << endl
                << "\tnet volume change: " << netTETC
                << " (cu. km)"
                << endl
                << "\tnet sea level change: " << netSLC
                << " (mm)"
                << endl << "\t---------------" << endl;
        } /** for loop */

        /** clean up */

        return 0;
}/** end of source code */

Here is what the above program prints out:

initial volume of ocean: 1332370930.2 (cu. km.)

1)  Temp. before: 5.5
     Temp. now: 6.5
     Temp. change: 1 (deg C)
     this volume change: 172385.525115 (cu. km)
     net volume change: 172385.525115 (cu. km)
     net sea level change: 476.412360995 (mm)
2)  Temp. before: 6.5
     Temp. now: 7.5
     Temp. change: 1 (deg C)
     this volume change: 186669.887116 (cu. km)
     net volume change: 359055.412231 (cu. km)
     net sea level change: 992.301624832 (mm)
3)  Temp. before: 7.5
     Temp. now: 8
     Temp. change: 0.5 (deg C)
     this volume change: 96841.4510376 (cu. km)
     net volume change: 455896.863269 (cu. km)
     net sea level change: 1259.93699793 (mm)
4)  Temp. before: 8
     Temp. now: 8.5
     Temp. change: 0.5 (deg C)
     this volume change: 100306.653495 (cu. km)
     net volume change: 556203.516764 (cu. km)
     net sea level change: 1537.1489598 (mm)
5)  Temp. before: 8.5
     Temp. now: 8
     Temp. change: -0.5 (deg C)
     this volume change: -96841.4510376 (cu. km)
     net volume change: 459362.065726 (cu. km)
     net sea level change: 1269.5135867 (mm)
6)  Temp. before: 8
     Temp. now: 7.5
     Temp. change: -0.5 (deg C)
     this volume change: -93334.9435582 (cu. km)
     net volume change: 366027.122168 (cu. km)
     net sea level change: 1011.56895478 (mm)
7)    Temp. before: 7.5
    Temp. now: 7
    Temp. change: -0.5 (deg C)
    this volume change: -89785.8304353 (cu. km)
    net volume change: 276241.291733 (cu. km)
    net sea level change: 763.432810911 (mm)
8)  Temp. before: 7
     Temp. now: 6.5
     Temp. change: -0.5 (deg C)
     this volume change: -86192.7625573 (cu. km)
     net volume change: 190048.529176 (cu. km)
     net sea level change: 525.226630414 (mm)
9)  Temp. before: 6.5
     Temp. now: 6
     Temp. change: -0.5 (deg C)
     this volume change: -82554.3415222 (cu. km)
     net volume change: 107494.187653 (cu. km)
     net sea level change: 297.07575331 (mm)
10) Temp. before: 6
      Temp. now: 5.5
      Temp. change: -0.5 (deg C)
      this volume change: -78869.118834 (cu. km)
      net volume change: 28625.0688193 (cu. km)
      net sea level change: 79.1095227442 (mm)

NOTE: Use a g++ compliant compiler, and download the TEOS-10 toolkit.

More on the more difficult part of the process (handling the real WOD data) in a future post.

1 comment:

  1. Pretty nice post. I just stumbled upon your blog and wanted to
    say that I have truly enjoyed surfing around your blog posts.

    After all I will be sujbscribing to your rss feed and I hope you rite again soon!