/home/runner/work/kynema-sgf/kynema-sgf/src/equation_systems/icns/source_terms/ABLForcing.H Source File

Kynema-SGF API: /home/runner/work/kynema-sgf/kynema-sgf/src/equation_systems/icns/source_terms/ABLForcing.H Source File
Kynema-SGF API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
ABLForcing.H
Go to the documentation of this file.
1#ifndef ABLFORCING_H
2#define ABLFORCING_H
3
5#include "src/core/SimTime.H"
8#include "AMReX_REAL.H"
9
10using namespace amrex::literals;
11
12namespace kynema_sgf::pde::icns {
13
19class ABLForcing : public MomentumSource::Register<ABLForcing>
20{
21public:
22 static std::string identifier() { return "ABLForcing"; }
23
24 explicit ABLForcing(const CFDSim& sim);
25
26 ~ABLForcing() override;
27
28 void operator()(
29 int lev, FieldState fstate, amrex::MultiFab& src_term) const override;
30
31 void set_target_velocities(amrex::Real ux, amrex::Real uy)
32 {
33 m_target_vel[0] = ux;
34 m_target_vel[1] = uy;
35 }
36
37 void set_mean_velocities(amrex::Real ux, amrex::Real uy)
38 {
39 m_mean_vel[0] = ux;
40 m_mean_vel[1] = uy;
41
42 const auto& current_time = m_time.current_time();
43 const auto& new_time = m_time.new_time();
44 const auto& nph_time = 0.5_rt * (current_time + new_time);
45 const auto& dt = m_time.delta_t();
46 const auto& t_step = m_time.time_index();
47
48 if (!m_vel_timetable.empty()) {
49 // Forces should be applied at n+1/2. Because ABL forcing is a
50 // delta, the difference between the target velocity (at n+1) and
51 // the current velocity (at n) puts the force term at n+1/2
52 const amrex::Real new_spd = ::kynema_sgf::interp::linear(
53 m_time_table, m_speed_table, new_time);
54 const amrex::Real new_dir = ::kynema_sgf::interp::linear_angle(
56 2.0_rt * std::numbers::pi_v<amrex::Real>);
57
58 m_target_vel[0] = new_spd * std::cos(new_dir);
59 m_target_vel[1] = new_spd * std::sin(new_dir);
60 }
61
62 m_abl_forcing[0] = (m_target_vel[0] - m_mean_vel[0]) / dt;
63 m_abl_forcing[1] = (m_target_vel[1] - m_mean_vel[1]) / dt;
64
66 amrex::ParallelDescriptor::IOProcessor() &&
67 (t_step % m_force_outfreq == 0) &&
68 (current_time >= m_force_outstart)) {
69 std::ofstream outfile;
70 // Forces are recorded at n+1/2
71 outfile.open(m_force_timetable, std::ios::out | std::ios::app);
72 outfile << std::setprecision(17) << nph_time << "\t"
73 << m_abl_forcing[0] << "\t" << m_abl_forcing[1] << "\t"
74 << 0.0_rt << '\n';
75 }
76 }
77
78 [[nodiscard]] amrex::RealArray abl_forcing() const { return m_abl_forcing; }
79
80 [[nodiscard]] amrex::Real forcing_height() const
81 {
82 return m_forcing_height;
83 }
84
85private:
87 const amrex::AmrCore& m_mesh;
88
90 bool m_use_phase_ramp{false};
91
93 int m_n_band{2};
94
96 amrex::RealArray m_abl_forcing{0.0_rt};
97
99 std::string m_vel_timetable;
100
104 std::string m_force_timetable;
108 amrex::Real m_force_outstart{0.0_rt};
109
111 amrex::Vector<amrex::Real> m_time_table;
112
114 amrex::Vector<amrex::Real> m_speed_table;
115
117 amrex::Vector<amrex::Real> m_direction_table;
118
120 amrex::Vector<amrex::Real> m_target_vel{0.0_rt, 0.0_rt, 0.0_rt};
121
123 amrex::RealArray m_mean_vel{0.0_rt};
124
126 amrex::Real m_forcing_height;
127
129 amrex::Real m_forcing_mphase0;
131 amrex::Real m_forcing_mphase1;
132
134 amrex::Real m_water_level;
135
137 const Field* m_vof;
138};
139
140} // namespace kynema_sgf::pde::icns
141
142#endif /* ABLFORCING_H */
Definition CFDSim.H:55
Definition Field.H:112
Definition SimTime.H:33
amrex::Real m_forcing_height
Height at which the velocities are forcing.
Definition ABLForcing.H:126
amrex::Real forcing_height() const
Definition ABLForcing.H:80
amrex::RealArray m_mean_vel
Current mean vel.
Definition ABLForcing.H:123
amrex::RealArray m_abl_forcing
ABL forcing terms.
Definition ABLForcing.H:96
const Field * m_vof
VOF field, to avoid forcing on liquid above force-off height.
Definition ABLForcing.H:137
int m_n_band
Number of cells in band to prevent forcing near liquid.
Definition ABLForcing.H:93
static std::string identifier()
Definition ABLForcing.H:22
amrex::Vector< amrex::Real > m_direction_table
Velocity forcing direction table.
Definition ABLForcing.H:117
amrex::Real m_forcing_mphase1
Height from water interface over which force is ramped.
Definition ABLForcing.H:131
amrex::Vector< amrex::Real > m_target_vel
Target velocity.
Definition ABLForcing.H:120
ABLForcing(const CFDSim &sim)
Definition ABLForcing.cpp:16
void operator()(int lev, FieldState fstate, amrex::MultiFab &src_term) const override
Definition ABLForcing.cpp:91
void set_target_velocities(amrex::Real ux, amrex::Real uy)
Definition ABLForcing.H:31
const SimTime & m_time
Definition ABLForcing.H:86
void set_mean_velocities(amrex::Real ux, amrex::Real uy)
Definition ABLForcing.H:37
amrex::Vector< amrex::Real > m_time_table
Velocity forcing time table.
Definition ABLForcing.H:111
std::string m_force_timetable
File name for forcing time table output.
Definition ABLForcing.H:104
amrex::Real m_force_outstart
Output start time for force.
Definition ABLForcing.H:108
bool m_use_phase_ramp
Activated when water is present in domain.
Definition ABLForcing.H:90
amrex::Vector< amrex::Real > m_speed_table
Velocity forcing speed table.
Definition ABLForcing.H:114
amrex::Real m_water_level
Local storage of interface location.
Definition ABLForcing.H:134
amrex::RealArray abl_forcing() const
Definition ABLForcing.H:78
amrex::Real m_forcing_mphase0
Height from water interface where force is off.
Definition ABLForcing.H:129
const amrex::AmrCore & m_mesh
Definition ABLForcing.H:87
int m_force_outfreq
Output frequency for forces.
Definition ABLForcing.H:106
std::string m_vel_timetable
File name for velocity forcing time table.
Definition ABLForcing.H:99
bool m_write_force_timetable
Bool for writing forcing time table.
Definition ABLForcing.H:102
FieldState
Definition FieldDescTypes.H:16
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::iterator_traits< C2 >::value_type linear(const C1 xbegin, const C1 xend, const C2 yinp, const typename std::iterator_traits< C1 >::value_type &xout, const int ncomp=1, const int comp=0)
Definition linear_interpolation.H:130
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::iterator_traits< C2 >::value_type linear_angle(const C1 xbegin, const C1 xend, const C2 yinp, const typename std::iterator_traits< C1 >::value_type &xout, const typename std::iterator_traits< C1 >::value_type &upper_bound)
Definition linear_interpolation.H:219
Definition ABLForcing.cpp:14