Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
pressure.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// modified for C++ by s. petillo spetillo@mit.edu
26// ocean engineering graduate student - mit / whoi joint program
27// massachusetts institute of technology (mit)
28// laboratory for autonomous marine sensing systems (lamss)
29
30#ifndef GOBY_UTIL_SEAWATER_PRESSURE_H
31#define GOBY_UTIL_SEAWATER_PRESSURE_H
32
33#include <cmath>
34
35#include "goby/util/constants.h"
36
37// Calculate water density anomaly at a given Salinity, Temperature, Pressure using the seawater Equation of State.
38// Taken directly from MATLAB OceansToolbox pressure.m
39
40namespace goby
41{
42namespace util
43{
44namespace seawater
45{
52template <typename DepthUnit = boost::units::si::length,
53 typename LatitudeUnit = boost::units::degree::plane_angle>
54inline boost::units::quantity<decltype(boost::units::si::deci * bar)>
55pressure(boost::units::quantity<DepthUnit> depth, boost::units::quantity<LatitudeUnit> latitude)
56{
57 // function P80=pressure(DPTH,XLAT);
58 /*
59 Computes pressure given the depth at some latitude
60 P = depth2pressure(DPTH,XLAT) gives the pressure P (dbars) at a depth DPTH (m) at some latitude Xdecltype(boost::units::si::deci* bar)LAT (degrees).
61
62 This probably works best in mid-latitude oceans, if anywhere!
63
64 Ref: Saunders, "Practical Conversion of Pressure to Depth",
65 J. Phys. Oceanog., April 1981.
66
67 I copied this from the Matlab OceansToolbox pressure.m, copied directly from the UNESCO algorithms.
68
69
70 CHECK VALUE: P80=7500.004 DBARS;FOR LAT=30 DEG., DEPTH=7321.45 METERS
71 ^P80 test value should be 7500.006 (from spetillo@mit.edu)
72 */
73 using namespace boost::units;
74
75 double DPTH = quantity<boost::units::si::length>(depth).value();
76 double XLAT = quantity<degree::plane_angle>(latitude).value();
77
78 const double pi = goby::util::pi<double>;
79
80 double PLAT = std::abs(XLAT * pi / 180);
81 double D = std::sin(PLAT);
82 double C1 = (5.92E-3) + (D * D) * (5.25E-3);
83 double P80 = ((1 - C1) - sqrt(((1 - C1) * (1 - C1)) - ((8.84E-6) * DPTH))) / 4.42E-6;
84
85 return P80 * boost::units::si::deci * bar;
86}
87} // namespace seawater
88} // namespace util
89} // namespace goby
90
91#endif
static const boost::units::metric::bar_base_unit::unit_type bar
Definition units.h:36
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::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
constexpr T pi
Definition constants.h:34
The global namespace for the Goby project.