Goby3  3.1.5a
2024.05.23
salinity.h
Go to the documentation of this file.
1 // Copyright 2013-2021:
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 // File authors:
6 // Toby Schneider <toby@gobysoft.org>
7 //
8 //
9 // This file is part of the Goby Underwater Autonomy Project Libraries
10 // ("The Goby Libraries").
11 //
12 // The Goby Libraries are free software: you can redistribute them and/or modify
13 // them under the terms of the GNU Lesser General Public License as published by
14 // the Free Software Foundation, either version 2.1 of the License, or
15 // (at your option) any later version.
16 //
17 // The Goby Libraries are distributed in the hope that they will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public License
23 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef GOBY_UTIL_SALINITY_H
26 #define GOBY_UTIL_SALINITY_H
27 
28 #include <cmath>
29 
30 #include <boost/units/quantity.hpp>
31 #include <boost/units/systems/si.hpp>
33 #include <boost/units/systems/temperature/celsius.hpp>
34 
36 #include "units.h"
37 
38 namespace goby
39 {
40 namespace util
41 {
42 namespace seawater
43 {
44 static const boost::units::quantity<decltype(milli_siemens_per_cm)> conductivity_at_standard{
45  42.914 * milli_siemens_per_cm}; // S = 35, T = 15 deg C, P = 0 dbar
46 
54 template <typename ConductivityUnit = decltype(milli_siemens_per_cm),
55  typename TemperatureUnit = boost::units::celsius::temperature,
56  typename PressureUnit = decltype(boost::units::si::deci* bar)>
57 boost::units::quantity<boost::units::si::dimensionless>
58 salinity(boost::units::quantity<ConductivityUnit> conductivity,
59  boost::units::quantity<boost::units::absolute<TemperatureUnit> > temperature,
60  boost::units::quantity<PressureUnit> pressure)
61 {
62  using namespace boost::units;
63  double CND = quantity<decltype(milli_siemens_per_cm)>(conductivity) / conductivity_at_standard;
64  double T = quantity<absolute<celsius::temperature> >(temperature).value();
65  double P = quantity<decltype(si::deci * bar)>(pressure).value();
66 
67  return quantity<si::dimensionless>(
69 }
70 
78 template <typename TemperatureUnit = boost::units::celsius::temperature,
79  typename DimensionlessUnit = boost::units::si::dimensionless,
80  typename PressureUnit = decltype(boost::units::si::deci* bar)>
81 boost::units::quantity<decltype(milli_siemens_per_cm)>
82 conductivity(boost::units::quantity<DimensionlessUnit> salinity,
83  boost::units::quantity<boost::units::absolute<TemperatureUnit> > temperature,
84  boost::units::quantity<PressureUnit> pressure)
85 {
86  using namespace boost::units;
87  double SAL = salinity;
88  double T = quantity<absolute<celsius::temperature> >(temperature).value();
89  double P = quantity<decltype(si::deci * bar)>(pressure).value();
90 
91  return detail::SalinityCalculator::compute(SAL, T, P,
94 }
95 
103 template <typename TemperatureUnit = boost::units::celsius::temperature,
104  typename PressureUnit = decltype(boost::units::si::deci* bar)>
105 boost::units::quantity<decltype(milli_siemens_per_cm)>
107  boost::units::quantity<boost::units::absolute<TemperatureUnit> > temperature,
108  boost::units::quantity<PressureUnit> pressure)
109 {
110  return conductivity(boost::units::quantity<boost::units::si::dimensionless>(salinity),
111  temperature, pressure);
112 }
113 
114 } // namespace seawater
115 } // namespace util
116 } // namespace goby
117 
118 #endif
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::util::seawater::milli_siemens_per_cm
static const decltype((boost::units::si::milli *boost::units::si::siemen)/(boost::units::si::centi *boost::units::si::meters) milli_siemens_per_cm)
Definition: units.h:38
salinity_impl.h
prefixes.hpp
goby::util::seawater::detail::SalinityCalculator::TO_SALINITY
@ TO_SALINITY
Definition: salinity_impl.h:73
goby::util::seawater::bar
static const boost::units::metric::bar_base_unit::unit_type bar
Definition: units.h:36
goby::util::units::rpm::dimensionless
boost::units::unit< boost::units::dimensionless_type, system > dimensionless
Definition: system.hpp:47
goby::util::seawater::detail::SalinityCalculator::compute
static double compute(double CND, double T, double P, bool M)
Definition: salinity_impl.h:77
units.h
goby::util::seawater::salinity
boost::units::quantity< boost::units::si::dimensionless > salinity(boost::units::quantity< ConductivityUnit > conductivity, boost::units::quantity< boost::units::absolute< TemperatureUnit > > temperature, boost::units::quantity< PressureUnit > pressure)
Calculates salinity from conductivity, temperature, and pressure Adapted from "Algorithms for computa...
Definition: salinity.h:58
goby::util::seawater::conductivity_at_standard
static const boost::units::quantity< decltype(milli_siemens_per_cm)> conductivity_at_standard
Definition: salinity.h:44
goby::util::seawater::pressure
boost::units::quantity< decltype(boost::units::si::deci *bar)> pressure(boost::units::quantity< DepthUnit > depth, boost::units::quantity< LatitudeUnit > latitude)
Calculates pressure from depth and latitude.
Definition: pressure.h:55
boost::units
Definition: time.hpp:18
goby::util::seawater::conductivity
boost::units::quantity< decltype(milli_siemens_per_cm)> conductivity(boost::units::quantity< DimensionlessUnit > salinity, boost::units::quantity< boost::units::absolute< TemperatureUnit > > temperature, boost::units::quantity< PressureUnit > pressure)
Calculates conductivity from salinity, temperature, and pressure Adapted from "Algorithms for computa...
Definition: salinity.h:82
goby::util::seawater::detail::SalinityCalculator::FROM_SALINITY
@ FROM_SALINITY
Definition: salinity_impl.h:74