Skip to content

Commit 32cfa0f

Browse files
committed
Rebase against develop.
1 parent 2e01743 commit 32cfa0f

23 files changed

+1186
-97
lines changed

components/omega/configs/Default.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Omega:
3232
Density0: 1026.0
3333
BottomDragTendencyEnable: false
3434
BottomDragCoeff: 0.0
35-
TracerHorzAdvTendencyEnable: true
35+
TracerHorzAdvTendencyEnable: false
36+
TracerHighOrderHorzAdvTendencyEnable: true
3637
TracerDiffTendencyEnable: true
3738
EddyDiff2: 10.0
3839
TracerHyperDiffTendencyEnable: true

components/omega/doc/userGuide/TendencyTerms.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ the currently available tendency terms:
4242
| VelocityHyperDiffOnEdge | VelHyperDiffTendencyEnable | enable/disable term
4343
| | ViscDel4 | horizontal biharmonic mixing coefficient for normal velocity
4444
| | DivFactor | scale factor for the divergence term
45-
| TracerHorzAdvOnCell | TracerHorzAdvTendencyEnable | enable/disable term
45+
| TracerHorzAdvOnCell | TracerHorzAdvTendencyEnable
46+
| | TracerHighOrderHorzAdvTendencyEnable | enable/disable term
4647
| TracerDiffOnCell | TracerDiffTendencyEnable | enable/disable term
4748
| | EddyDiff2 | horizontal diffusion coefficient
4849
| TracerHyperDiffOnCell | TracerHyperDiffTendencyEnable | enable/disable term

components/omega/src/infra/OmegaKokkos.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ template <class T> struct ArrayRank {
6969
static constexpr bool Is5D = T::rank == 5;
7070
};
7171

72-
using ExecSpace = MemSpace::execution_space;
73-
using HostExecSpace = HostMemSpace::execution_space;
72+
using ExecSpace = MemSpace::execution_space;
73+
using HostExecSpace = HostMemSpace::execution_space;
7474
using TeamPolicy = Kokkos::TeamPolicy<ExecSpace>;
7575
using TeamMember = TeamPolicy::member_type;
7676
using ScratchMemSpace = ExecSpace::scratch_memory_space;

components/omega/src/infra/TimeMgr.cpp

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ void TimeFrac::setSeconds(R8 Seconds) { // [in] floating point seconds
250250
I8 N; // numerator
251251
I8 D; // denominator
252252
R8 F = 0.0;
253+
I4 I = 0;
253254
do {
254255
// Compute next convergent N/D
255256
A = (I8)R;
@@ -382,8 +383,12 @@ void TimeFrac::getHMS(I4 &Hours, // [out] integer hours
382383
R8 TimeFrac::getSeconds(void) const { // \result Time in real seconds
383384

384385
// check for divide-by-zero
385-
if (Denom == 0)
386-
ABORT_ERROR("TimeMgr: TimeFrac::getSeconds encountered 0 denominator.");
386+
I4 Err{0};
387+
if (Denom == 0) {
388+
Err = 1;
389+
LOG_ERROR("TimeMgr: encountered 0 denominator.");
390+
return 0.0;
391+
}
387392

388393
// convert integer fractional seconds to real result
389394
return (R8)Whole + (R8)Numer / (R8)Denom;
@@ -397,8 +402,12 @@ R8 TimeFrac::getSeconds(void) const { // \result Time in real seconds
397402
R8 TimeFrac::getHours(void) const { // \result Time in real hours
398403

399404
// check for divide-by-zero
400-
if (Denom == 0)
401-
ABORT_ERROR("TimeMgr: TimeFrac::getHours encountered 0 denominator.");
405+
I4 Err{0};
406+
if (Denom == 0) {
407+
Err = 1;
408+
LOG_ERROR("TimeMgr: encountered 0 denominator.");
409+
return 0.0;
410+
}
402411

403412
// make local copy for manipulation
404413
TimeFrac TmpTime = *this;
@@ -420,8 +429,12 @@ R8 TimeFrac::getHours(void) const { // \result Time in real hours
420429
R8 TimeFrac::getMinutes(void) const { // \result Time in real minutes
421430

422431
// check for divide-by-zero
423-
if (Denom == 0)
424-
ABORT_ERROR("TimeMgr: TimeFrac::getMinutes encountered 0 denominator.");
432+
int Err{0};
433+
if (Denom == 0) {
434+
Err = 1;
435+
LOG_ERROR("TimeMgr: encountered 0 denominator.");
436+
return 0.0;
437+
}
425438

426439
// make local copy for manipulation
427440
TimeFrac TmpTime = *this;
@@ -1012,13 +1025,11 @@ std::unique_ptr<Calendar> Calendar::OmegaCal = nullptr;
10121025
//-------------------------------------------------------------------------
10131026
// Calendar::get - retrieves pointer to model calendar
10141027
Calendar *Calendar::get() {
1015-
1016-
// Check for valid calendar
1017-
if (!isDefined())
1018-
ABORT_ERROR("TimeMgr: Attempt to retrieve undefined calendar");
1019-
1020-
return Calendar::OmegaCal.get();
1021-
1028+
if (isDefined()) {
1029+
return Calendar::OmegaCal.get();
1030+
} else {
1031+
LOG_CRITICAL("Attempt to retrieve undefined calendar");
1032+
}
10221033
} // end retrieve calendar pointer
10231034

10241035
//------------------------------------------------------------------------------
@@ -1044,15 +1055,16 @@ CalendarKind Calendar::getKind() {
10441055
std::vector<I4> Calendar::getDaysPerMonth() {
10451056

10461057
// check if calendar defined
1047-
if (!isDefined())
1048-
ABORT_ERROR("TimeMgr: Cannot retrieve DaysPerMonth"
1049-
" - Calendar not initialized");
1050-
1051-
// also check for valid vector
1052-
if (Calendar::OmegaCal->DaysPerMonth.size() < 1)
1053-
ABORT_ERROR("TimeMgr: Invalid DaysPerMonth vector in Calendar");
1054-
1055-
return Calendar::OmegaCal->DaysPerMonth;
1058+
if (isDefined) {
1059+
// also check for valid vector
1060+
if (Calendar::OmegaCal->DaysPerMonth.size() > 0) {
1061+
return Calendar::OmegaCal->DaysPerMonth;
1062+
} else {
1063+
LOG_CRITICAL("Invalid DaysPerMonth vector");
1064+
}
1065+
} else {
1066+
LOG_CRITICAL("Cannot retrieve calendar props - Calendar not initialized");
1067+
}
10561068
}
10571069

10581070
I4 Calendar::getMonthsPerYear() {
@@ -1381,6 +1393,7 @@ TimeFrac Calendar::getElapsedTime(
13811393
// initialize the basetime result, and common temps
13821394
TimeFrac Result(0, 0, 1);
13831395
I8 ResultWhole{0}; // whole seconds for result
1396+
I8 DayOfYear{0}; // day since beginning of year
13841397
I8 JD{0}; // Julian Day used for many conversions
13851398
I8 HourTmp{0}; // For half-day JD conversions
13861399
I4 FebDays{0}; // For tracking leap days
@@ -1979,18 +1992,19 @@ TimeInterval::TimeInterval(
19791992
Units = InUnits;
19801993
IsCalendar = false;
19811994
CalInterval = 0;
1995+
I4 Err{0};
19821996

19831997
// Now set values based on input units
19841998
I8 Length = InLength;
19851999
switch (Units) {
19862000
case TimeUnits::Seconds:
1987-
Interval.set(Length, 0, 1);
2001+
Err = Interval.set(Length, 0, 1);
19882002
break;
19892003
case TimeUnits::Minutes:
1990-
Interval.setHMS(0, Length, 0);
2004+
Err = Interval.setHMS(0, Length, 0);
19912005
break;
19922006
case TimeUnits::Hours:
1993-
Interval.setHMS(Length, 0, 0);
2007+
Err = Interval.setHMS(Length, 0, 0);
19942008
break;
19952009
case TimeUnits::Years: // these three are all calendar
19962010
case TimeUnits::Months: // intervals with the input length
@@ -2019,17 +2033,18 @@ TimeInterval::TimeInterval(
20192033
Units = InUnits;
20202034
IsCalendar = false;
20212035
CalInterval = 0;
2036+
I4 Err{0};
20222037

20232038
// Now set values based on input units
20242039
switch (InUnits) {
20252040
case TimeUnits::Seconds:
2026-
Interval.set(Length, 0, 1);
2041+
Err = Interval.set(Length, 0, 1);
20272042
break;
20282043
case TimeUnits::Minutes:
2029-
Interval.setHMS(0, Length, 0);
2044+
Err = Interval.setHMS(0, Length, 0);
20302045
break;
20312046
case TimeUnits::Hours:
2032-
Interval.setHMS(Length, 0, 0);
2047+
Err = Interval.setHMS(Length, 0, 0);
20332048
break;
20342049
case TimeUnits::Years: // these three are all calendar
20352050
case TimeUnits::Months: // intervals with the input length
@@ -2060,17 +2075,18 @@ TimeInterval::TimeInterval(
20602075
Units = InUnits;
20612076
IsCalendar = false;
20622077
CalInterval = 0;
2078+
I4 Err{0};
20632079

20642080
// Now set values based on input units
20652081
switch (InUnits) {
20662082
case TimeUnits::Seconds:
2067-
Interval.setSeconds(Length); // TimeFrac set
2083+
Err = Interval.setSeconds(Length); // TimeFrac set
20682084
break;
20692085
case TimeUnits::Minutes:
2070-
Interval.setMinutes(Length); // TimeFrac set
2086+
Err = Interval.setMinutes(Length); // TimeFrac set
20712087
break;
20722088
case TimeUnits::Hours:
2073-
Interval.setHours(Length); // TimeFrac set
2089+
Err = Interval.setHours(Length); // TimeFrac set
20742090
break;
20752091
case TimeUnits::Years: // these three are all calendar
20762092
case TimeUnits::Months: // intervals with the input length
@@ -3030,10 +3046,10 @@ bool TimeInterval::isPositive(void) {
30303046
// make sure fraction is in proper form, particularly that the
30313047
// whole and fraction have same sign and numerator and denomintator
30323048
// have the same sign.
3033-
Interval.simplify();
3049+
I4 Err = Interval.simplify();
30343050

30353051
// now retrieve fractional seconds and check components
3036-
Interval.get(W, N, D);
3052+
Err = Interval.get(W, N, D);
30373053
if (W >= 0) { // whole part of seconds non-negative
30383054
// only need check the numerator with simplified form
30393055
if (N > 0)
@@ -3513,10 +3529,9 @@ std::string TimeInstant::getString(
35133529
const char *FormatStr = Tmp.c_str();
35143530

35153531
// now use sprintf to print to C string
3516-
I4 NChars =
3517-
sprintf(TimeStr, FormatStr, Year, Month, Day, Hour, Minute, Second);
3518-
if (NChars < 0)
3519-
ABORT_ERROR("TimeMgr: TimeInstant::getString error in sprintf");
3532+
Err = sprintf(TimeStr, FormatStr, Year, Month, Day, Hour, Minute, Second);
3533+
if (Err < 0)
3534+
LOG_ERROR("TimeMgr: TimeInstant::getString error in sprintf");
35203535

35213536
// now convert C string to std::string for result
35223537
std::string Result(TimeStr);

components/omega/src/ocn/CustomTendencyTerms.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
//
2323
//===----------------------------------------------------------------------===//
2424

25-
#include "HorzMesh.h"
26-
#include "TendencyTerms.h"
25+
#include "AuxiliaryState.h"
26+
#include "OceanState.h"
2727
#include "TimeMgr.h"
2828

2929
namespace OMEGA {

components/omega/src/ocn/HorzMesh.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "Error.h"
1818
#include "IO.h"
1919
#include "Logging.h"
20-
#include "MachEnv.h"
2120
#include "OmegaKokkos.h"
2221

2322
namespace OMEGA {
@@ -57,8 +56,9 @@ void HorzMesh::init() {
5756
HorzMesh::HorzMesh(const std::string &Name, //< [in] Name for new mesh
5857
Decomp *MeshDecomp, //< [in] Decomp for the new mesh
5958
I4 InNVertLevels //< [in} num vertical levels
60-
) {
61-
59+
)
60+
: CellID(MeshDecomp->CellID) ///< global cell ID for each local cell
61+
{
6262
MeshName = Name;
6363

6464
// Retrieve mesh files name from Decomp
@@ -68,11 +68,12 @@ HorzMesh::HorzMesh(const std::string &Name, //< [in] Name for new mesh
6868
NVertLevels = InNVertLevels;
6969

7070
// Retrieve mesh cell/edge/vertex totals from Decomp
71-
NCellsHalo = MeshDecomp->NCellsHalo;
72-
NCellsHaloH = MeshDecomp->NCellsHaloH;
73-
NCellsOwned = MeshDecomp->NCellsOwned;
74-
NCellsAll = MeshDecomp->NCellsAll;
75-
NCellsSize = MeshDecomp->NCellsSize;
71+
NCellsHalo = MeshDecomp->NCellsHalo;
72+
NCellsHaloH = MeshDecomp->NCellsHaloH;
73+
NCellsOwned = MeshDecomp->NCellsOwned;
74+
NCellsAll = MeshDecomp->NCellsAll;
75+
NCellsSize = MeshDecomp->NCellsSize;
76+
NCellsGlobal = MeshDecomp->NCellsGlobal;
7677

7778
NEdgesHalo = MeshDecomp->NEdgesHalo;
7879
NEdgesHaloH = MeshDecomp->NEdgesHaloH;
@@ -81,6 +82,7 @@ HorzMesh::HorzMesh(const std::string &Name, //< [in] Name for new mesh
8182
NEdgesSize = MeshDecomp->NEdgesSize;
8283
MaxCellsOnEdge = MeshDecomp->MaxCellsOnEdge;
8384
MaxEdges = MeshDecomp->MaxEdges;
85+
NEdgesGlobal = MeshDecomp->NEdgesGlobal;
8486

8587
NVerticesHalo = MeshDecomp->NVerticesHalo;
8688
NVerticesHaloH = MeshDecomp->NVerticesHaloH;

components/omega/src/ocn/HorzMesh.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class HorzMesh {
103103
I4 NCellsOwned; ///< Number of cells owned by this task
104104
I4 NCellsAll; ///< Total number of local cells (owned + all halo)
105105
I4 NCellsSize; ///< Array size (incl padding, bndy cell) for cell arrays
106+
I4 NCellsGlobal;
106107

107108
Array1DI4 NEdgesHalo; ///< num cells owned+halo for halo layer
108109
HostArray1DI4 NEdgesHaloH; ///< num cells owned+halo for halo layer
@@ -111,7 +112,8 @@ class HorzMesh {
111112
I4 NEdgesSize; ///< Array length (incl padding, bndy) for edge dim
112113
I4 MaxCellsOnEdge; ///< Max number of cells sharing an edge
113114
I4 MaxEdges; ///< Max number of edges around a cell
114-
I4 MaxEdges2; ///< Max number of edges around a cell x2
115+
I4 NEdgesGlobal;
116+
I4 MaxEdges2; ///< Max number of edges around a cell x2
115117

116118
Array1DI4 NVerticesHalo; ///< num cells owned+halo for halo layer
117119
HostArray1DI4 NVerticesHaloH; ///< num cells owned+halo for halo layer
@@ -152,6 +154,7 @@ class HorzMesh {
152154
Array2DI4 EdgesOnVertex; ///< Indx of edges sharing vertex as endpoint
153155
HostArray2DI4 EdgesOnVertexH; ///< Indx of edges sharing vertex as endpoint
154156

157+
Array1DI4 CellID; ///< global cell ID for each local cell
155158
// Coordinates
156159

157160
Array1DReal XCell; ///< X Coordinates of cell centers (m)

components/omega/src/ocn/HorzOperators.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,45 @@ InterpCellToEdge::InterpCellToEdge(const HorzMesh *Mesh)
2727
KiteAreasOnVertex(Mesh->KiteAreasOnVertex),
2828
VertexDegree(Mesh->VertexDegree) {}
2929

30+
SecondDerivativeOnCell::SecondDerivativeOnCell(HorzMesh const *Mesh)
31+
: OnSphere(true), NCellsAll(Mesh->NCellsAll), MaxEdges(1 + Mesh->MaxEdges),
32+
NEdgesOnCell(Mesh->NEdgesOnCell), EdgesOnCell(Mesh->EdgesOnCell),
33+
CellsOnCell(Mesh->CellsOnCell), CellsOnEdge(Mesh->CellsOnEdge),
34+
VerticesOnEdge(Mesh->VerticesOnEdge),
35+
36+
XCell(Mesh->XCell), YCell(Mesh->YCell),
37+
ZCell(createDeviceMirrorCopy(Mesh->ZCellH)), DvEdge(Mesh->DvEdge),
38+
DcEdge(Mesh->DcEdge), AngleEdge(Mesh->AngleEdge),
39+
AreaCell(Mesh->AreaCell), EdgeSignOnCell(Mesh->EdgeSignOnCell),
40+
XVertex(createDeviceMirrorCopy(Mesh->XVertexH)),
41+
YVertex(createDeviceMirrorCopy(Mesh->YVertexH)),
42+
ZVertex(createDeviceMirrorCopy(Mesh->ZVertexH)),
43+
44+
ThetaAbs("SphereAngle", NCellsAll), XPCell("XP", NCellsAll, MaxEdges),
45+
YPCell("YP", NCellsAll, MaxEdges),
46+
Angle2DCell("Angle2D", NCellsAll, MaxEdges),
47+
BCell("WorkSpaceForLeastSquares", NCellsAll, 6, MaxEdges),
48+
CellListCell("CellList", NCellsAll, MaxEdges) {
49+
if (MaxMaxEdges <= Mesh->MaxEdges)
50+
LOG_CRITICAL(
51+
"SecondDerivativeOnCell::SecondDerivativeOnCell Max Edges exceeded:"
52+
"Max Allowed: {} Found in Mesh:{}",
53+
MaxMaxEdges - 1, Mesh->MaxEdges);
54+
}
55+
56+
MasksAndCoefficients::MasksAndCoefficients(
57+
HorzMesh const *Mesh, const Array3DReal DerivTwo,
58+
Array1DI4 NAdvCellsForEdge, Array2DI4 AdvCellsForEdge,
59+
Array2DI4 AdvMaskHighOrder, Array2DReal AdvCoefs, Array2DReal AdvCoefs3rd)
60+
: NCellsGlobal(Mesh->NCellsGlobal), NCellsAll(Mesh->NCellsAll),
61+
NAdvCellsMax(Mesh->MaxEdges2), OmegaHash(Mesh->NEdgesAll),
62+
NAdvCellsForEdge(NAdvCellsForEdge), AdvCellsForEdge(AdvCellsForEdge),
63+
NEdgesOnEdge(Mesh->NEdgesOnEdge), NEdgesOnCell(Mesh->NEdgesOnCell),
64+
CellIndx("CellIndx", Mesh->MaxEdges2 + 2),
65+
CellIndxSorted("CellIndxSorted", 2, Mesh->MaxEdges2 + 2),
66+
CellID(Mesh->CellID), AdvMaskHighOrder(AdvMaskHighOrder),
67+
EdgesOnEdge(Mesh->EdgesOnEdge), CellsOnCell(Mesh->CellsOnCell),
68+
CellsOnEdge(Mesh->CellsOnEdge), DcEdge(Mesh->DcEdge),
69+
DvEdge(Mesh->DvEdge), AdvCoefs(AdvCoefs), AdvCoefs3rd(AdvCoefs3rd),
70+
DerivTwo(DerivTwo) {}
3071
} // namespace OMEGA

0 commit comments

Comments
 (0)