/home/runner/work/amr-wind/amr-wind/amr-wind/ocean_waves/utils/wave_utils_K.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/ocean_waves/utils/wave_utils_K.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
wave_utils_K.H
Go to the documentation of this file.
1#ifndef WAVES_UTILS_H_
2#define WAVES_UTILS_H_
3
4#include <AMReX_FArrayBox.H>
5#include <cmath>
7#include "AMReX_REAL.H"
8
9using namespace amrex::literals;
10
12
13using WaveVec = amrex::GpuArray<amrex::Real, 4>;
14
15AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real free_surface_to_vof(
16 const amrex::Real eta, const amrex::Real z, const amrex::Real dz)
17{
18 amrex::Real volfrac = 0.0_rt;
19 if (eta - z >= dz / 2.0_rt) {
20 volfrac = 1.0_rt;
21 } else if (eta - z <= -dz / 2.0_rt) {
22 volfrac = 0.0_rt;
23 } else if (std::abs(eta - z) < dz / 2.0_rt) {
24 if (eta <= z) {
25 volfrac = 1.0_rt - (z - eta + dz / 2.0_rt) / dz;
26 } else {
27 volfrac = (eta - z + dz / 2.0_rt) / dz;
28 }
29 }
30
31 return volfrac;
32}
33
34AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
35gamma_generate(const amrex::Real x, const amrex::Real gen_length)
36{
37 const amrex::Real xtilde = amrex::max<amrex::Real>(
38 amrex::min<amrex::Real>(1.0_rt - x / gen_length, 1.0_rt), 0.0_rt);
39 return (1.0_rt - std::expm1(std::pow(xtilde, 3.5_rt)) / std::expm1(1.0_rt));
40}
41
42AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real gamma_absorb(
43 const amrex::Real x,
44 const amrex::Real absorb_length,
45 const amrex::Real absorb_length_factor)
46{
47 const amrex::Real xtilde = amrex::max<amrex::Real>(
48 amrex::min<amrex::Real>(
49 x / (absorb_length * absorb_length_factor), 1.0_rt),
50 0.0_rt);
51 return (1.0_rt - std::expm1(std::pow(xtilde, 3.5_rt)) / std::expm1(1.0_rt));
52}
53
54AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
55ramp(const amrex::Real time, const amrex::Real ramp_period)
56{
57 amrex::Real f = 1.0_rt;
58 if (time < ramp_period) {
59 f = time / ramp_period -
60 (1.0_rt / static_cast<amrex::Real>(M_PI)) *
61 std::sin(static_cast<amrex::Real>(M_PI) * (time / ramp_period));
62 }
63 return f;
64}
65
66AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real combine_linear(
67 const amrex::Real factor,
68 const amrex::Real target,
69 const amrex::Real current)
70{
71 return (1.0_rt - factor) * target + factor * current;
72}
73
74AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE WaveVec harmonize_profiles_1d(
75 const amrex::Real x,
76 const amrex::Real left_bdy,
77 const amrex::Real left_length,
78 const amrex::Real right_bdy,
79 const amrex::Real right_length,
80 const WaveVec left,
81 const WaveVec bulk,
82 const WaveVec right)
83{
84 // Initialize boundary regions entirely with boundary solutions
85 if (x <= left_bdy + left_length) {
86 return left;
87 }
88 if (x + right_length >= right_bdy) {
89 return right;
90 }
91 // Combine solutions in central region using relax zone length scales
92 const amrex::Real Gamma_left =
93 gamma_generate(x - (left_bdy + left_length), 0.5_rt * left_length);
94 const amrex::Real Gamma_right = gamma_absorb(
95 x - (right_bdy - 1.5_rt * right_length), 0.5_rt * right_length, 1.0_rt);
96 const bool right_inactive = Gamma_right > 1.0_rt - constants::TIGHT_TOL;
97 WaveVec combo;
98 for (int n = 0; n < 4; ++n) {
99 combo[n] = right_inactive
100 ? combine_linear(Gamma_left, left[n], bulk[n])
101 : combine_linear(Gamma_right, right[n], bulk[n]);
102 }
103 return combo;
104}
105
106AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE WaveVec harmonize_profiles_2d(
107 const amrex::Real x,
108 const amrex::Real y,
109 const amrex::Real left_bdy,
110 const amrex::Real left_length,
111 const amrex::Real right_bdy,
112 const amrex::Real right_length,
113 const amrex::Real lo_y_bdy,
114 const amrex::Real hi_y_bdy,
115 const amrex::Real y_length,
116 const WaveVec left,
117 const WaveVec bulk,
118 const WaveVec right)
119{
120 // First get forcing profile, applies in x and y zones
121 auto profile_forcing = harmonize_profiles_1d(
122 x, left_bdy, left_length, right_bdy, right_length, left, left, right);
123
124 // Also get initial profile according to x direction
125 auto profile_init = harmonize_profiles_1d(
126 x, left_bdy, left_length, right_bdy, right_length, left, bulk, right);
127
128 // Then harmonize in y direction if applicable
129 if (y_length >= constants::EPS) {
130 profile_init = harmonize_profiles_1d(
131 y, lo_y_bdy, y_length, hi_y_bdy, y_length, profile_forcing,
132 profile_init, profile_forcing);
133 }
134
135 return profile_init;
136}
137
138} // namespace amr_wind::ocean_waves::utils
139
140#endif
static constexpr amrex::Real TIGHT_TOL
A tight tolerance.
Definition constants.H:17
static constexpr amrex::Real EPS
A number very close to zero.
Definition constants.H:13
Definition wave_utils_K.H:11
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real gamma_generate(const amrex::Real x, const amrex::Real gen_length)
Definition wave_utils_K.H:35
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE WaveVec harmonize_profiles_1d(const amrex::Real x, const amrex::Real left_bdy, const amrex::Real left_length, const amrex::Real right_bdy, const amrex::Real right_length, const WaveVec left, const WaveVec bulk, const WaveVec right)
Definition wave_utils_K.H:74
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real free_surface_to_vof(const amrex::Real eta, const amrex::Real z, const amrex::Real dz)
Definition wave_utils_K.H:15
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ramp(const amrex::Real time, const amrex::Real ramp_period)
Definition wave_utils_K.H:55
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real combine_linear(const amrex::Real factor, const amrex::Real target, const amrex::Real current)
Definition wave_utils_K.H:66
amrex::GpuArray< amrex::Real, 4 > WaveVec
Definition wave_utils_K.H:13
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real gamma_absorb(const amrex::Real x, const amrex::Real absorb_length, const amrex::Real absorb_length_factor)
Definition wave_utils_K.H:42
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE WaveVec harmonize_profiles_2d(const amrex::Real x, const amrex::Real y, const amrex::Real left_bdy, const amrex::Real left_length, const amrex::Real right_bdy, const amrex::Real right_length, const amrex::Real lo_y_bdy, const amrex::Real hi_y_bdy, const amrex::Real y_length, const WaveVec left, const WaveVec bulk, const WaveVec right)
Definition wave_utils_K.H:106