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