/home/runner/work/amr-wind/amr-wind/amr-wind/equation_systems/icns/source_terms/ABLForcing.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/equation_systems/icns/source_terms/ABLForcing.H Source File
AMR-Wind 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
8#include "AMReX_REAL.H"
9
10using namespace amrex::literals;
11
12namespace amr_wind::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,
30 const amrex::MFIter& mfi,
31 const amrex::Box& bx,
32 FieldState fstate,
33 const amrex::Array4<amrex::Real>& src_term) const override;
34
35 void set_target_velocities(amrex::Real ux, amrex::Real uy)
36 {
37 m_target_vel[0] = ux;
38 m_target_vel[1] = uy;
39 }
40
41 void set_mean_velocities(amrex::Real ux, amrex::Real uy)
42 {
43 m_mean_vel[0] = ux;
44 m_mean_vel[1] = uy;
45
46 const auto& current_time = m_time.current_time();
47 const auto& new_time = m_time.new_time();
48 const auto& nph_time = 0.5_rt * (current_time + new_time);
49 const auto& dt = m_time.delta_t();
50 const auto& t_step = m_time.time_index();
51
52 if (!m_vel_timetable.empty()) {
53 // Forces should be applied at n+1/2. Because ABL forcing is a
54 // delta, the difference between the target velocity (at n+1) and
55 // the current velocity (at n) puts the force term at n+1/2
56 const amrex::Real new_spd = ::amr_wind::interp::linear(
57 m_time_table, m_speed_table, new_time);
58 const amrex::Real new_dir = ::amr_wind::interp::linear_angle(
60 2.0_rt * std::numbers::pi_v<amrex::Real>);
61
62 m_target_vel[0] = new_spd * std::cos(new_dir);
63 m_target_vel[1] = new_spd * std::sin(new_dir);
64 }
65
66 m_abl_forcing[0] = (m_target_vel[0] - m_mean_vel[0]) / dt;
67 m_abl_forcing[1] = (m_target_vel[1] - m_mean_vel[1]) / dt;
68
70 amrex::ParallelDescriptor::IOProcessor() &&
71 (t_step % m_force_outfreq == 0) &&
72 (current_time >= m_force_outstart)) {
73 std::ofstream outfile;
74 // Forces are recorded at n+1/2
75 outfile.open(m_force_timetable, std::ios::out | std::ios::app);
76 outfile << std::setprecision(17) << nph_time << "\t"
77 << m_abl_forcing[0] << "\t" << m_abl_forcing[1] << "\t"
78 << 0.0_rt << '\n';
79 }
80 }
81
82 [[nodiscard]] amrex::RealArray abl_forcing() const { return m_abl_forcing; }
83
84 [[nodiscard]] amrex::Real forcing_height() const
85 {
86 return m_forcing_height;
87 }
88
89private:
91 const amrex::AmrCore& m_mesh;
92
94 bool m_use_phase_ramp{false};
95
97 int m_n_band{2};
98
100 amrex::RealArray m_abl_forcing{0.0_rt};
101
103 std::string m_vel_timetable;
104
108 std::string m_force_timetable;
112 amrex::Real m_force_outstart{0.0_rt};
113
115 amrex::Vector<amrex::Real> m_time_table;
116
118 amrex::Vector<amrex::Real> m_speed_table;
119
121 amrex::Vector<amrex::Real> m_direction_table;
122
124 amrex::Vector<amrex::Real> m_target_vel{0.0_rt, 0.0_rt, 0.0_rt};
125
127 amrex::RealArray m_mean_vel{0.0_rt};
128
130 amrex::Real m_forcing_height;
131
133 amrex::Real m_forcing_mphase0;
135 amrex::Real m_forcing_mphase1;
136
138 amrex::Real m_water_level;
139
141 const Field* m_vof;
142};
143
144} // namespace amr_wind::pde::icns
145
146#endif /* ABLFORCING_H */
Definition CFDSim.H:54
Definition Field.H:112
Definition SimTime.H:33
void set_target_velocities(amrex::Real ux, amrex::Real uy)
Definition ABLForcing.H:35
amrex::Real m_forcing_mphase0
Height from water interface where force is off.
Definition ABLForcing.H:133
amrex::Vector< amrex::Real > m_time_table
Velocity forcing time table.
Definition ABLForcing.H:115
amrex::Real m_forcing_mphase1
Height from water interface over which force is ramped.
Definition ABLForcing.H:135
const Field * m_vof
VOF field, to avoid forcing on liquid above force-off height.
Definition ABLForcing.H:141
amrex::RealArray m_mean_vel
Current mean vel.
Definition ABLForcing.H:127
ABLForcing(const CFDSim &sim)
Definition ABLForcing.cpp:16
bool m_use_phase_ramp
Activated when water is present in domain.
Definition ABLForcing.H:94
bool m_write_force_timetable
Bool for writing forcing time table.
Definition ABLForcing.H:106
int m_n_band
Number of cells in band to prevent forcing near liquid.
Definition ABLForcing.H:97
void set_mean_velocities(amrex::Real ux, amrex::Real uy)
Definition ABLForcing.H:41
amrex::Vector< amrex::Real > m_speed_table
Velocity forcing speed table.
Definition ABLForcing.H:118
amrex::Real m_force_outstart
Output start time for force.
Definition ABLForcing.H:112
amrex::Real m_forcing_height
Height at which the velocities are forcing.
Definition ABLForcing.H:130
amrex::RealArray abl_forcing() const
Definition ABLForcing.H:82
amrex::Vector< amrex::Real > m_direction_table
Velocity forcing direction table.
Definition ABLForcing.H:121
const SimTime & m_time
Definition ABLForcing.H:90
const amrex::AmrCore & m_mesh
Definition ABLForcing.H:91
static std::string identifier()
Definition ABLForcing.H:22
int m_force_outfreq
Output frequency for forces.
Definition ABLForcing.H:110
void operator()(int lev, const amrex::MFIter &mfi, const amrex::Box &bx, FieldState fstate, const amrex::Array4< amrex::Real > &src_term) const override
Definition ABLForcing.cpp:90
amrex::Real m_water_level
Local storage of interface location.
Definition ABLForcing.H:138
std::string m_vel_timetable
File name for velocity forcing time table.
Definition ABLForcing.H:103
amrex::RealArray m_abl_forcing
ABL forcing terms.
Definition ABLForcing.H:100
std::string m_force_timetable
File name for forcing time table output.
Definition ABLForcing.H:108
amrex::Vector< amrex::Real > m_target_vel
Target velocity.
Definition ABLForcing.H:124
amrex::Real forcing_height() const
Definition ABLForcing.H:84
FieldState
Definition FieldDescTypes.H:16
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
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
Definition ABLForcing.cpp:14