Skip to content

Commit 0ee6238

Browse files
committed
adds global constants header file
1 parent 24b2b8f commit 0ee6238

File tree

4 files changed

+85
-16
lines changed

4 files changed

+85
-16
lines changed

components/omega/src/ocn/CustomTendencyTerms.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "CustomTendencyTerms.h"
1010
#include "Config.h"
11+
#include "GlobalConstants.h"
1112
#include "TimeStepper.h"
1213

1314
namespace OMEGA {
@@ -79,11 +80,9 @@ void ManufacturedSolution::init() {
7980
R8 H0 = DefHorzMesh->BottomDepthH(0);
8081

8182
// Define and compute common constants
82-
R8 Grav = 9.80665_Real; // Gravity acceleration
83-
R8 Pii = 3.141592653589793_Real; // Pi
84-
R8 Kx = 2.0_Real * Pii / WavelengthX; // Wave in X-dir
85-
R8 Ky = 2.0_Real * Pii / WavelengthY; // Wave in Y-dir
86-
R8 AngFreq = sqrt(H0 * Grav * (Kx * Kx + Ky * Ky)); // Angular frequency
83+
R8 Kx = 2.0_Real * Pi / WavelengthX; // Wave in X-dir
84+
R8 Ky = 2.0_Real * Pi / WavelengthY; // Wave in Y-dir
85+
R8 AngFreq = sqrt(H0 * Gravity * (Kx * Kx + Ky * Ky)); // Angular frequency
8786

8887
// Assign constants for thickness tendency function
8988
ManufacturedThickTend.H0 = H0;
@@ -93,7 +92,7 @@ void ManufacturedSolution::init() {
9392
ManufacturedThickTend.AngFreq = AngFreq;
9493

9594
// Assign constants for velocity tendency function
96-
ManufacturedVelTend.Grav = Grav;
95+
ManufacturedVelTend.Grav = Gravity;
9796
ManufacturedVelTend.Eta0 = Amplitude;
9897
ManufacturedVelTend.Kx = Kx;
9998
ManufacturedVelTend.Ky = Ky;
@@ -160,7 +159,7 @@ void ManufacturedSolution::ManufacturedVelocityTendency::operator()(
160159
Array1DReal YEdge = Mesh->YEdge;
161160
Array1DReal AngleEdge = Mesh->AngleEdge;
162161

163-
OMEGA_SCOPE(LocGrav, Grav);
162+
OMEGA_SCOPE(LocGrav, Gravity);
164163
OMEGA_SCOPE(LocEta0, Eta0);
165164
OMEGA_SCOPE(LocKx, Kx);
166165
OMEGA_SCOPE(LocKy, Ky);

components/omega/src/ocn/Eos.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "AuxiliaryState.h"
1414
#include "Config.h"
15+
#include "GlobalConstants.h"
1516
#include "HorzMesh.h"
1617
#include "MachEnv.h"
1718
#include "OmegaKokkos.h"
@@ -205,8 +206,7 @@ class Teos10Eos {
205206
KOKKOS_FUNCTION Real calcDelta(const Array2DReal &SpecVolPCoeffs, const I4 K,
206207
const Real P) const {
207208

208-
constexpr Real Pu = 1e4;
209-
Real Pp = P / Pu;
209+
Real Pp = P * Pa2Db;
210210

211211
Real Delta = ((((SpecVolPCoeffs(5, K) * Pp + SpecVolPCoeffs(4, K)) * Pp +
212212
SpecVolPCoeffs(3, K)) *
@@ -221,14 +221,13 @@ class Teos10Eos {
221221

222222
/// Calculate reference profile for TEOS-10
223223
KOKKOS_FUNCTION Real calcRefProfile(Real P) const {
224-
constexpr Real Pu = 1e4;
225224
constexpr Real V00 = -4.4015007269e-05;
226225
constexpr Real V01 = 6.9232335784e-06;
227226
constexpr Real V02 = -7.5004675975e-07;
228227
constexpr Real V03 = 1.7009109288e-08;
229228
constexpr Real V04 = -1.6884162004e-08;
230229
constexpr Real V05 = 1.9613503930e-09;
231-
Real Pp = P / Pu;
230+
Real Pp = P * Pa2Db;
232231

233232
Real V0 =
234233
(((((V05 * Pp + V04) * Pp + V03) * Pp + V02) * Pp + V01) * Pp + V00) *
@@ -244,9 +243,9 @@ class Teos10Eos {
244243
class LinearEos {
245244
public:
246245
/// Coefficients for LinearEos (overwritten by config file if set there)
247-
Real DRhodT = -0.2; ///< Thermal expansion coefficient (kg m^-3 degC^-1)
248-
Real DRhodS = 0.8; ///< Haline contraction coefficient (kg m^-3)
249-
Real RhoT0S0 = 1000.0; ///< Reference density (kg m^-3) at (T,S)=(0,0)
246+
Real DRhodT = -0.2; ///< Thermal expansion coefficient (kg m^-3 degC^-1)
247+
Real DRhodS = 0.8; ///< Haline contraction coefficient (kg m^-3)
248+
Real RhoT0S0 = RhoFw; ///< Reference density (kg m^-3) at (T,S)=(0,0)
250249

251250
/// constructor declaration
252251
LinearEos();
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#ifndef OMEGA_GLOBALCONSTANTS_H
2+
#define OMEGA_GLOBALCONSTANTS_H
3+
//===-- ocn/GlobalConstants.h - Global Constants --------------------*- C++
4+
//-*-===//
5+
//
6+
/// \file
7+
/// \brief Contains global constants for use across Omega
8+
///
9+
/// This header defines constants to be used across Omega (to be replaced by a
10+
/// shared E3SM constants file when that becomes available)
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
namespace OMEGA {
15+
16+
// Earth constants
17+
constexpr double Gravity = 9.80616; // Acceleration due to gravity ~ m/s^2
18+
constexpr double Pi = 3.14159265358979323846; // Pi
19+
constexpr double CDay = 86400.0; // Seconds in a calendar day ~ sec
20+
constexpr double SDay = 86164.0; // Seconds in a sidereal day ~ sec
21+
constexpr double Omega =
22+
2.0 * Pi / SDay; // Angular velocity of the Earth ~ rad/sec
23+
constexpr double REarth = 6.37122e6; // Mean radius of the Earth ~ m
24+
25+
/// Physical constants
26+
constexpr double TkTrip = 273.16; // Triple point of fresh water ~ K
27+
constexpr double TkFrz = 273.15; // Freezing point of fresh water ~ K
28+
constexpr double TkFrzSw = TkFrz - 1.8; // Freezing point of seawater ~ K
29+
constexpr double RhoAir = 1.2; // Density of air ~ kg/m^3
30+
constexpr double RhoFw = 1.000e3; // Density of fresh water ~ kg/m^3
31+
constexpr double RhoSw = 1.026e3; // Density of seawater ~ kg/m^3
32+
constexpr double RhoIce = 0.917e3; // Density of ice ~ kg/m^3
33+
constexpr double CpAir = 1005.0; // Specific heat capacity of air ~ J/(kg*K)
34+
constexpr double CpFw =
35+
4.188e3; // Specific heat capacity of fresh water ~ J/(kg*K)
36+
constexpr double CpSw =
37+
3.996e3; // Specific heat capacity of seawater ~ J/(kg*K)
38+
constexpr double CpIce = 2.108e3; // Specific heat capacity of ice ~ J/(kg*K)
39+
constexpr double LatIce = 3.337e5; // Latent heat of fusion ~ J/kg
40+
constexpr double LatVap = 2.501e6; // Latent heat of vaporization ~ J/kg
41+
constexpr double LatSub = LatIce + LatVap; // Latent heat of sublimation ~ J/kg
42+
constexpr double CondIce = 2.1; // Universal gas constant ~ J/(mol*K)
43+
constexpr double OcnRefSal = 34.7; // Reference ocean salinity ~ psu
44+
constexpr double IceRefSal = 4.0; // Reference ice salinity ~ psu
45+
constexpr double Sound = 1.5e2; // Speed of sound ~ m/s
46+
constexpr double VonKar = 0.4; // Von Karman constant ~ dimensionless
47+
constexpr double Emiss = 1.0; // Emissivity ~ dimensionless
48+
constexpr double AtmRefP = 101325.0; // Reference atmospheric pressure ~ Pa
49+
50+
// Conversion factors
51+
constexpr double Sec2Day = 1.0 / 86400.0; // Seconds to days
52+
constexpr double Day2Sec = 86400.0; // Days to seconds
53+
constexpr double Salt2PPt = 1000.0; // Salinity (kg/kg) to parts per thousand
54+
constexpr double PPt2Salt = 1.0e-3; // Parts per thousand to salinity (kg/kg)
55+
constexpr double Mass2Sv = 1.0e-12; // Mass flux (kg/s) to Sverdrup
56+
constexpr double Heat2Pw = 4.186e-15; // Heat flux (W) to Petawatt
57+
constexpr double Salt2SvPpt = 1.0e-9; // Salt flux (kg/s) to Sv*ppt
58+
constexpr double Salt2MmDay = 3.1536e+5; // Salt flux to water flux (mm/day)
59+
constexpr double Db2Pa = 1.0e4; // Decibar to Pascal
60+
constexpr double Pa2Db = 1.0e-4; // Pascal to Decibar
61+
constexpr double Cm2M = 1.0e-2; // Centimeters to meters
62+
constexpr double M2Cm = 1.0e2; // Meters to centimeters
63+
constexpr double HFluxFac =
64+
1.0 / (RhoSw * CpSw); // Heat flux (W/m^2) to temp flux (C*m/s)
65+
constexpr double FwFluxFac = 1.e-6; // Fw flux (kg/m^2/s) to salt((msu/psu)*m/s)
66+
constexpr double SaltFac =
67+
-OcnRefSal * FwFluxFac; // Fw flux (kg/m^2/s) to salt flux (msu*m/s)
68+
constexpr double SFluxFac = 1.0; // Salt flux (kg/m^2/s) to salt flux (msu*m/s)
69+
70+
} // namespace OMEGA
71+
#endif

components/omega/src/ocn/TendencyTerms.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "AuxiliaryState.h"
14+
#include "GlobalConstants.h"
1415
#include "HorzMesh.h"
1516
#include "MachEnv.h"
1617
#include "OceanState.h"
@@ -166,14 +167,13 @@ class SSHGradOnEdge {
166167

167168
for (int KVec = 0; KVec < VecLength; ++KVec) {
168169
const I4 K = KStart + KVec;
169-
Tend(IEdge, K) -= EdgeMask(IEdge, K) * Grav *
170+
Tend(IEdge, K) -= EdgeMask(IEdge, K) * Gravity *
170171
(SshCell(ICell1, K) - SshCell(ICell0, K)) *
171172
InvDcEdge;
172173
}
173174
}
174175

175176
private:
176-
Real Grav = 9.80665_Real;
177177
Array2DI4 CellsOnEdge;
178178
Array1DReal DcEdge;
179179
Array2DReal EdgeMask;

0 commit comments

Comments
 (0)