|
| 1 | +//===-- ocn/CustomTendencyTerms.cpp - Custom tendency terms -----*- C++ -*-===// |
| 2 | +// |
| 3 | +// The customized tendency terms can be added to the tendency terms based |
| 4 | +// based on an option 'UseCustomTendency' in Tendencies Config group. |
| 5 | +// This file contains functions for initializing customized tendency terms. |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "CustomTendencyTerms.h" |
| 10 | +#include "Config.h" |
| 11 | +#include "TimeStepper.h" |
| 12 | + |
| 13 | +namespace OMEGA { |
| 14 | + |
| 15 | +//===-----------------------------------------------------------------------===/ |
| 16 | +// Initialize the manufactured solution tendency terms. |
| 17 | +//===-----------------------------------------------------------------------===/ |
| 18 | +int ManufacturedSolution::init() { |
| 19 | + int Err; |
| 20 | + |
| 21 | + // Get ManufacturedSolConfig group |
| 22 | + Config *OmegaConfig = Config::getOmegaConfig(); |
| 23 | + Config ManufacturedSolConfig("ManufacturedSolution"); |
| 24 | + Err = OmegaConfig->get(ManufacturedSolConfig); |
| 25 | + if (Err != 0) { |
| 26 | + LOG_CRITICAL("ManufacturedSolution:: ManufacturedSolution group " |
| 27 | + "not found in Config"); |
| 28 | + return Err; |
| 29 | + } |
| 30 | + |
| 31 | + // Get TendConfig group |
| 32 | + Config TendConfig("Tendencies"); |
| 33 | + Err = OmegaConfig->get(TendConfig); |
| 34 | + if (Err != 0) { |
| 35 | + LOG_CRITICAL("ManufacturedSolution:: Tendencies group " |
| 36 | + "not found in Config"); |
| 37 | + return Err; |
| 38 | + } |
| 39 | + |
| 40 | + // Get manufactured solution parameters from Config |
| 41 | + R8 WavelengthX; |
| 42 | + R8 WavelengthY; |
| 43 | + R8 Amplitude; |
| 44 | + |
| 45 | + Err = ManufacturedSolConfig.get("WavelengthX", WavelengthX); |
| 46 | + if (Err != 0) { |
| 47 | + LOG_ERROR("ManufacturedSolution:: WavelengthX not found in " |
| 48 | + "ManufacturedSolConfig"); |
| 49 | + return Err; |
| 50 | + } |
| 51 | + |
| 52 | + Err = ManufacturedSolConfig.get("WavelengthY", WavelengthY); |
| 53 | + if (Err != 0) { |
| 54 | + LOG_ERROR("ManufacturedSolution:: WavelengthY not found in " |
| 55 | + "ManufacturedSolConfig"); |
| 56 | + return Err; |
| 57 | + } |
| 58 | + |
| 59 | + Err = ManufacturedSolConfig.get("Amplitude", Amplitude); |
| 60 | + if (Err != 0) { |
| 61 | + LOG_ERROR("ManufacturedSolution:: Amplitude not found in " |
| 62 | + "ManufacturedSolConfig"); |
| 63 | + return Err; |
| 64 | + } |
| 65 | + |
| 66 | + // Get Tendendices parameters for del2 and del4 source terms |
| 67 | + Err = TendConfig.get("VelDiffTendencyEnable", |
| 68 | + ManufacturedVelTend.VelDiffTendencyEnable); |
| 69 | + Err += TendConfig.get("VelHyperDiffTendencyEnable", |
| 70 | + ManufacturedVelTend.VelHyperDiffTendencyEnable); |
| 71 | + Err += TendConfig.get("ViscDel2", ManufacturedVelTend.ViscDel2); |
| 72 | + Err += TendConfig.get("ViscDel4", ManufacturedVelTend.ViscDel4); |
| 73 | + |
| 74 | + if (Err != 0) { |
| 75 | + LOG_ERROR("ManufacturedSolution::Error reading Tendencies config"); |
| 76 | + return Err; |
| 77 | + } |
| 78 | + |
| 79 | + // Get the reference time to compute the model elapsed time |
| 80 | + /// Get model clock from time stepper |
| 81 | + TimeStepper *DefStepper = TimeStepper::getDefault(); |
| 82 | + Clock *ModelClock = DefStepper->getClock(); |
| 83 | + ManufacturedThickTend.ReferenceTime = ModelClock->getCurrentTime(); |
| 84 | + ManufacturedVelTend.ReferenceTime = ManufacturedThickTend.ReferenceTime; |
| 85 | + |
| 86 | + // Get BottomDepth for the resting thickness |
| 87 | + /// This test case assumes that the restingThickness is horizontally uniform |
| 88 | + /// and that only one vertical level is used so only one set of indices is |
| 89 | + /// used here. |
| 90 | + HorzMesh *DefHorzMesh = HorzMesh::getDefault(); |
| 91 | + R8 H0 = DefHorzMesh->BottomDepthH(0); |
| 92 | + |
| 93 | + // Define and compute common constants |
| 94 | + R8 Grav = 9.80665_Real; // Gravity acceleration |
| 95 | + R8 Pii = 3.141592653589793_Real; // Pi |
| 96 | + R8 Kx = 2.0_Real * Pii / WavelengthX; // Wave in X-dir |
| 97 | + R8 Ky = 2.0_Real * Pii / WavelengthY; // Wave in Y-dir |
| 98 | + R8 AngFreq = sqrt(H0 * Grav * (Kx * Kx + Ky * Ky)); // Angular frequency |
| 99 | + |
| 100 | + // Assign constants for thickness tendency function |
| 101 | + ManufacturedThickTend.H0 = H0; |
| 102 | + ManufacturedThickTend.Eta0 = Amplitude; |
| 103 | + ManufacturedThickTend.Kx = Kx; |
| 104 | + ManufacturedThickTend.Ky = Ky; |
| 105 | + ManufacturedThickTend.AngFreq = AngFreq; |
| 106 | + |
| 107 | + // Assign constants for velocity tendency function |
| 108 | + ManufacturedVelTend.Grav = Grav; |
| 109 | + ManufacturedVelTend.Eta0 = Amplitude; |
| 110 | + ManufacturedVelTend.Kx = Kx; |
| 111 | + ManufacturedVelTend.Ky = Ky; |
| 112 | + ManufacturedVelTend.AngFreq = AngFreq; |
| 113 | + |
| 114 | + return Err; |
| 115 | + |
| 116 | +} // end ManufacturedSolution init |
| 117 | + |
| 118 | +//===--------------------------------------------------------------------===/ |
| 119 | +// Manufactured tendency term for the thickness equation |
| 120 | +//===--------------------------------------------------------------------===/ |
| 121 | +void ManufacturedSolution::ManufacturedThicknessTendency::operator()( |
| 122 | + Array2DReal ThicknessTend, const OceanState *State, |
| 123 | + const AuxiliaryState *AuxState, int ThickTimeLevel, int VelTimeLevel, |
| 124 | + TimeInstant Time) const { |
| 125 | + |
| 126 | + // Get elapsed time since reference time |
| 127 | + R8 ElapsedTimeSec; |
| 128 | + TimeInterval ElapsedTimeInterval = Time - ReferenceTime; |
| 129 | + ElapsedTimeInterval.get(ElapsedTimeSec, TimeUnits::Seconds); |
| 130 | + |
| 131 | + auto *Mesh = HorzMesh::getDefault(); |
| 132 | + auto NVertLevels = ThicknessTend.extent_int(1); |
| 133 | + |
| 134 | + Array1DReal XCell = Mesh->XCell; |
| 135 | + Array1DReal YCell = Mesh->YCell; |
| 136 | + |
| 137 | + OMEGA_SCOPE(LocH0, H0); |
| 138 | + OMEGA_SCOPE(LocEta0, Eta0); |
| 139 | + OMEGA_SCOPE(LocKx, Kx); |
| 140 | + OMEGA_SCOPE(LocKy, Ky); |
| 141 | + OMEGA_SCOPE(LocAngFreq, AngFreq); |
| 142 | + |
| 143 | + parallelFor( |
| 144 | + {Mesh->NCellsAll, NVertLevels}, KOKKOS_LAMBDA(int ICell, int KLevel) { |
| 145 | + R8 X = XCell(ICell); |
| 146 | + R8 Y = YCell(ICell); |
| 147 | + R8 Phase = LocKx * X + LocKy * Y - LocAngFreq * ElapsedTimeSec; |
| 148 | + ThicknessTend(ICell, KLevel) += |
| 149 | + LocEta0 * |
| 150 | + (-LocH0 * (LocKx + LocKy) * sin(Phase) - LocAngFreq * cos(Phase) + |
| 151 | + LocEta0 * (LocKx + LocKy) * cos(2.0_Real * Phase)); |
| 152 | + }); |
| 153 | + |
| 154 | +} // end void ManufacturedThicknessTendency |
| 155 | + |
| 156 | +//===--------------------------------------------------------------------===/ |
| 157 | +// Manufactured tendency term for the momentum equation |
| 158 | +//===--------------------------------------------------------------------===/ |
| 159 | +void ManufacturedSolution::ManufacturedVelocityTendency::operator()( |
| 160 | + Array2DReal NormalVelTend, const OceanState *State, |
| 161 | + const AuxiliaryState *AuxState, int ThickTimeLevel, int VelTimeLevel, |
| 162 | + TimeInstant Time) const { |
| 163 | + |
| 164 | + // Get elapsed time since reference time |
| 165 | + R8 ElapsedTimeSec; |
| 166 | + TimeInterval ElapsedTimeInterval = Time - ReferenceTime; |
| 167 | + ElapsedTimeInterval.get(ElapsedTimeSec, TimeUnits::Seconds); |
| 168 | + |
| 169 | + auto *Mesh = HorzMesh::getDefault(); |
| 170 | + auto NVertLevels = NormalVelTend.extent_int(1); |
| 171 | + |
| 172 | + Array1DReal FEdge = Mesh->FEdge; |
| 173 | + Array1DReal XEdge = Mesh->XEdge; |
| 174 | + Array1DReal YEdge = Mesh->YEdge; |
| 175 | + Array1DReal AngleEdge = Mesh->AngleEdge; |
| 176 | + |
| 177 | + OMEGA_SCOPE(LocGrav, Grav); |
| 178 | + OMEGA_SCOPE(LocEta0, Eta0); |
| 179 | + OMEGA_SCOPE(LocKx, Kx); |
| 180 | + OMEGA_SCOPE(LocKy, Ky); |
| 181 | + OMEGA_SCOPE(LocAngFreq, AngFreq); |
| 182 | + OMEGA_SCOPE(LocViscDel2, ViscDel2); |
| 183 | + OMEGA_SCOPE(LocViscDel4, ViscDel4); |
| 184 | + OMEGA_SCOPE(LocVelDiffTendencyEnable, VelDiffTendencyEnable); |
| 185 | + OMEGA_SCOPE(LocVelHyperDiffTendencyEnable, VelHyperDiffTendencyEnable); |
| 186 | + |
| 187 | + R8 LocKx2 = LocKx * LocKx; |
| 188 | + R8 LocKy2 = LocKy * LocKy; |
| 189 | + R8 LocKx4 = LocKx2 * LocKx2; |
| 190 | + R8 LocKy4 = LocKy2 * LocKy2; |
| 191 | + |
| 192 | + parallelFor( |
| 193 | + {Mesh->NEdgesAll, NVertLevels}, KOKKOS_LAMBDA(int IEdge, int KLevel) { |
| 194 | + R8 X = XEdge(IEdge); |
| 195 | + R8 Y = YEdge(IEdge); |
| 196 | + |
| 197 | + R8 Phase = LocKx * X + LocKy * Y - LocAngFreq * ElapsedTimeSec; |
| 198 | + R8 SourceTerm0 = LocAngFreq * sin(Phase) - 0.5_Real * LocEta0 * |
| 199 | + (LocKx + LocKy) * |
| 200 | + sin(2.0_Real * Phase); |
| 201 | + |
| 202 | + R8 U = LocEta0 * |
| 203 | + ((-FEdge(IEdge) + LocGrav * LocKx) * cos(Phase) + SourceTerm0); |
| 204 | + R8 V = LocEta0 * |
| 205 | + ((FEdge(IEdge) + LocGrav * LocKy) * cos(Phase) + SourceTerm0); |
| 206 | + |
| 207 | + // Del2 and del4 source terms |
| 208 | + if (LocVelDiffTendencyEnable) { |
| 209 | + U += LocViscDel2 * LocEta0 * (LocKx2 + LocKy2) * cos(Phase); |
| 210 | + V += LocViscDel2 * LocEta0 * (LocKx2 + LocKy2) * cos(Phase); |
| 211 | + } |
| 212 | + if (LocVelHyperDiffTendencyEnable) { |
| 213 | + U -= LocViscDel4 * LocEta0 * |
| 214 | + ((LocKx4 + LocKy4 + LocKx2 * LocKy2) * cos(Phase)); |
| 215 | + V -= LocViscDel4 * LocEta0 * |
| 216 | + ((LocKx4 + LocKy4 + LocKx2 * LocKy2) * cos(Phase)); |
| 217 | + } |
| 218 | + |
| 219 | + R8 NormalCompSourceTerm = |
| 220 | + cos(AngleEdge(IEdge)) * U + sin(AngleEdge(IEdge)) * V; |
| 221 | + NormalVelTend(IEdge, KLevel) += NormalCompSourceTerm; |
| 222 | + }); |
| 223 | + |
| 224 | +} // end void ManufacturedVelocityTendency |
| 225 | + |
| 226 | +} // end namespace OMEGA |
| 227 | + |
| 228 | +//=-------------------------------------------------------------------------===/ |
0 commit comments