/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>
6
8
9using WaveVec = amrex::GpuArray<amrex::Real, 4>;
10
11AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real free_surface_to_vof(
12 const amrex::Real eta, const amrex::Real z, const amrex::Real dz)
13{
14 amrex::Real volfrac = 0.0;
15 if (eta - z >= dz / 2.) {
16 volfrac = 1.;
17 } else if (eta - z <= -dz / 2.) {
18 volfrac = 0.;
19 } else if (std::abs(eta - z) < dz / 2.) {
20 if (eta <= z) {
21 volfrac = 1. - (z - eta + dz / 2.) / dz;
22 } else {
23 volfrac = (eta - z + dz / 2.) / dz;
24 }
25 }
26
27 return volfrac;
28}
29
30AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
31gamma_generate(const amrex::Real x, const amrex::Real gen_length)
32{
33 const amrex::Real xtilde =
34 std::max(std::min(1. - x / gen_length, 1.0), 0.0);
35 return (1.0 - std::expm1(std::pow(xtilde, 3.5)) / std::expm1(1.0));
36}
37
38AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real gamma_absorb(
39 const amrex::Real x,
40 const amrex::Real absorb_length,
41 const amrex::Real absorb_length_factor)
42{
43 const amrex::Real xtilde = std::max(
44 std::min(x / (absorb_length * absorb_length_factor), 1.0), 0.0);
45 return (1.0 - std::expm1(std::pow(xtilde, 3.5)) / std::expm1(1.0));
46}
47
48AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
49ramp(const amrex::Real time, const amrex::Real ramp_period)
50{
51 amrex::Real f = 1.0;
52 if (time < ramp_period) {
53 f = time / ramp_period -
54 (1.0 / M_PI) * std::sin(M_PI * (time / ramp_period));
55 }
56 return f;
57}
58
59AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real combine_linear(
60 const amrex::Real factor,
61 const amrex::Real target,
62 const amrex::Real current)
63{
64 return (1. - factor) * target + factor * current;
65}
66
67AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE WaveVec harmonize_profiles_1d(
68 const amrex::Real x,
69 const amrex::Real left_bdy,
70 const amrex::Real left_length,
71 const amrex::Real right_bdy,
72 const amrex::Real right_length,
73 const WaveVec left,
74 const WaveVec bulk,
75 const WaveVec right)
76{
77 // Initialize boundary regions entirely with boundary solutions
78 if (x <= left_bdy + left_length) {
79 return left;
80 }
81 if (x + right_length >= right_bdy) {
82 return right;
83 }
84 // Combine solutions in central region using relax zone length scales
85 const amrex::Real Gamma_left =
86 gamma_generate(x - (left_bdy + left_length), 0.5 * left_length);
87 const amrex::Real Gamma_right = gamma_absorb(
88 x - (right_bdy - 1.5 * right_length), 0.5 * right_length, 1.0);
89 const bool right_inactive = Gamma_right > 1.0 - 1e-12;
90 WaveVec combo;
91 for (int n = 0; n < 4; ++n) {
92 combo[n] = right_inactive
93 ? combine_linear(Gamma_left, left[n], bulk[n])
94 : combine_linear(Gamma_right, right[n], bulk[n]);
95 }
96 return combo;
97}
98
99} // namespace amr_wind::ocean_waves::utils
100
101#endif
Definition wave_utils_K.H:7
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:31
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:67
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:11
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real ramp(const amrex::Real time, const amrex::Real ramp_period)
Definition wave_utils_K.H:49
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:59
amrex::GpuArray< amrex::Real, 4 > WaveVec
Definition wave_utils_K.H:9
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:38