Goby3  3.1.4
2024.02.22
soundspeed.h
Go to the documentation of this file.
1 // Copyright 2010-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_SEAWATER_SOUNDSPEED_H
26 #define GOBY_UTIL_SEAWATER_SOUNDSPEED_H
27 
28 #include <stdexcept>
29 
30 #include <boost/units/quantity.hpp>
31 #include <boost/units/systems/si.hpp>
32 #include <boost/units/systems/temperature/celsius.hpp>
33 
34 namespace goby
35 {
36 namespace util
37 {
38 namespace seawater
39 {
48 template <typename TemperatureUnit = boost::units::celsius::temperature,
49  typename DimensionlessUnit = boost::units::si::dimensionless,
50  typename LengthUnit = boost::units::si::length>
51 boost::units::quantity<boost::units::si::velocity>
52 mackenzie_soundspeed(boost::units::quantity<boost::units::absolute<TemperatureUnit>> temperature,
53  boost::units::quantity<DimensionlessUnit> salinity,
54  boost::units::quantity<LengthUnit> depth, bool ignore_bounds = false)
55 {
56  using namespace boost::units;
57 
58  double T = quantity<absolute<celsius::temperature> >(temperature).value();
59  double S = quantity<si::dimensionless>(salinity).value();
60  double D = quantity<si::length>(depth).value();
61 
62  double min_T(-2);
63  double max_T(30);
64 
65  double min_S(25);
66  double max_S(40);
67 
68  double min_D(0);
69  double max_D(8000);
70 
71  if (!ignore_bounds)
72  {
73  if (T < min_T || T > max_T)
74  throw std::out_of_range("Temperature not in valid range [-2, 30] deg C");
75  if (S < min_S || S > max_S)
76  throw std::out_of_range("Salinity not in valid range [25, 40]");
77  if (D < min_D || D > max_D)
78  throw std::out_of_range("Depth not in valid range [0, 8000] meters");
79  }
80 
81  return (1448.96 + 4.591 * T - 5.304e-2 * T * T + 2.374e-4 * T * T * T + 1.340 * (S - 35) +
82  1.630e-2 * D + 1.675e-7 * D * D - 1.025e-2 * T * (S - 35) - 7.139e-13 * T * D * D * D) *
83  si::meters_per_second;
84 }
85 
94 template <typename TemperatureUnit = boost::units::celsius::temperature,
95  typename LengthUnit = boost::units::si::length>
96 boost::units::quantity<boost::units::si::velocity>
97 mackenzie_soundspeed(boost::units::quantity<boost::units::absolute<TemperatureUnit>> temperature,
98  double salinity, boost::units::quantity<LengthUnit> depth,
99  bool ignore_bounds = false)
100 {
101  return mackenzie_soundspeed(temperature,
102  boost::units::quantity<boost::units::si::dimensionless>(salinity),
103  depth, ignore_bounds);
104 }
105 } // namespace seawater
106 } // namespace util
107 } // namespace goby
108 
109 #endif
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::util::e
constexpr T e
Definition: constants.h:35
goby::util::units::rpm::dimensionless
boost::units::unit< boost::units::dimensionless_type, system > dimensionless
Definition: system.hpp:47
goby::util::seawater::mackenzie_soundspeed
boost::units::quantity< boost::units::si::velocity > mackenzie_soundspeed(boost::units::quantity< boost::units::absolute< TemperatureUnit >> temperature, boost::units::quantity< DimensionlessUnit > salinity, boost::units::quantity< LengthUnit > depth, bool ignore_bounds=false)
Definition: soundspeed.h:52
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
boost::units
Definition: time.hpp:18
goby::util::seawater::depth
boost::units::quantity< boost::units::si::length > depth(boost::units::quantity< PressureUnit > pressure, boost::units::quantity< LatitudeUnit > latitude)
Calculates depth from pressure and latitude Adapted from "Algorithms for computation of fundamental p...
Definition: depth.h:57