1#ifndef REMORA_DateClock_H
2#define REMORA_DateClock_H
9#include <AMReX_Extension.H>
10#include <AMReX_GpuQualifiers.H>
69 const bool leap = (((
year % 4) == 0) && ((
year % 100) != 0)) || ((
year % 400) == 0);
71 return static_cast<int>((275.0 *
month) / 9.0) -
fac * ((
month + 9) / 12) +
day - 30;
88 const int cal =
static_cast<int>(time_ref);
109 }
else if (
cal == -1) {
115 constexpr int offset = 61;
121 static_cast<int>(0.25 *
my_year) -
122 static_cast<int>(0.01 *
my_year) +
123 static_cast<int>(0.0025 *
my_year) +
124 static_cast<int>(0.1 * (
my_month * 306.0 + 5.0)) +
136 return amrex::Real(
my_day) +
137 amrex::Real(
hour) / amrex::Real(24.0) +
138 amrex::Real(
minutes) / amrex::Real(1440.0) +
139 seconds / amrex::Real(86400.0);
153 const int cal =
static_cast<int>(time_ref);
158 const int iyear = std::max(1,
static_cast<int>(time_ref * amrex::Real(0.0001)));
159 const int month = std::min(12, std::max(1,
static_cast<int>(
160 (time_ref - amrex::Real(
iyear * 10000)) * amrex::Real(0.01))));
161 const amrex::Real
day = time_ref -
162 std::trunc(time_ref * amrex::Real(0.01)) * amrex::Real(100.0);
163 const int iday = std::max(1,
static_cast<int>(
day));
164 const amrex::Real
sec = (
day - std::trunc(
day)) * amrex::Real(86400.0);
165 const int ihour =
static_cast<int>(
sec / amrex::Real(3600.0));
166 const int minute =
static_cast<int>(std::fmod(
sec, amrex::Real(3600.0)) /
168 const int isec =
static_cast<int>(std::fmod(
sec, amrex::Real(60.0)));
173 return amrex::Real(359.0);
176 return amrex::Real(2440000.0);
195 const int cal =
static_cast<int>(time_ref);
216 amrex::Real
js = amrex::Real(4.0) *
jr - amrex::Real(1.0);
217 amrex::Real
yy = std::floor(
js / amrex::Real(146097.0));
218 jr =
js - amrex::Real(146097.0) *
yy;
219 js = std::floor(
jr * amrex::Real(0.25));
220 js = amrex::Real(4.0) *
js + amrex::Real(3.0);
221 jr = std::floor(
js / amrex::Real(1461.0));
222 const amrex::Real
dd =
223 std::floor(((
js - amrex::Real(1461.0) *
jr) + amrex::Real(4.0)) * amrex::Real(0.25));
224 js = amrex::Real(5.0) *
dd - amrex::Real(3.0);
225 const amrex::Real
mo = std::floor(
js / amrex::Real(153.0));
226 yy =
yy * amrex::Real(100.0) +
jr;
228 if (
mo < amrex::Real(10.0)) {
229 year =
static_cast<int>(
yy);
230 month =
static_cast<int>(
mo + amrex::Real(3.0));
232 year =
static_cast<int>(
yy + amrex::Real(1.0));
233 month =
static_cast<int>(
mo - amrex::Real(9.0));
235 day =
static_cast<int>(((
js - amrex::Real(153.0) *
mo) + amrex::Real(5.0)) *
238 }
else if (
cal == -1) {
247 amrex::Real(1.0)) / amrex::Real(86400.0));
254 constexpr amrex::Real
offset = amrex::Real(61.0);
267 return static_cast<int>(365.0 *
y) +
static_cast<int>(0.25 *
y) -
268 static_cast<int>(0.01 *
y) +
static_cast<int>(0.0025 *
y);
276 const int my_month =
static_cast<int>((100.0 *
my_day + 52.0) / 3060.0);
306 const int cal =
static_cast<int>(time_ref);
325 ?
static_cast<int>(
date_number - amrex::Real(
year * 360) + amrex::Real(1.0))
334 int&
year, amrex::Real&
yday)
noexcept
350 return static_cast<int>(time_ref) >= -2;
367 if (time_ref <= amrex::Real(0.0)) {
370 return std::is_same<amrex::Real, double>::value;
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void remora_datevec(amrex::Real time_ref, amrex::Real date_number, bool is_day_units, int &year, int &month, int &day) noexcept
Calendar date for a day (or second) number. ROMS datevec.
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int remora_yearday(int year, int month, int day) noexcept
Day of the year for a calendar date. ROMS yearday.
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool remora_time_ref_is_valid(amrex::Real time_ref) noexcept
Whether time_ref names a calendar this header implements.
static constexpr int remora_gregorian_daynum
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void remora_caldate(amrex::Real time_ref, amrex::Real current_time_days, int &year, int &month, int &day, amrex::Real &yday) noexcept
Model time in days to calendar date. ROMS caldate.
AMREX_FORCE_INLINE bool remora_time_ref_is_representable(amrex::Real time_ref) noexcept
Whether time_ref survives a round trip through amrex::Real.
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real remora_ref_datenum(amrex::Real time_ref) noexcept
Day number of the reference date implied by time_ref.
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real remora_datenum(amrex::Real time_ref, int year, int month, int day, int hour=0, int minutes=0, amrex::Real seconds=amrex::Real(0.0)) noexcept
Fractional day number for a calendar date. ROMS datenum.
mf_h setVal(geomdata.ProbHi(2))