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