/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
9namespace amr_wind::pde::icns {
10
16class ABLForcing : public MomentumSource::Register<ABLForcing>
17{
18public:
19 static std::string identifier() { return "ABLForcing"; }
20
21 explicit ABLForcing(const CFDSim& sim);
22
23 ~ABLForcing() override;
24
25 void operator()(
26 const int lev,
27 const amrex::MFIter& mfi,
28 const amrex::Box& bx,
29 const FieldState fstate,
30 const amrex::Array4<amrex::Real>& src_term) const override;
31
32 inline void set_target_velocities(amrex::Real ux, amrex::Real uy)
33 {
34 m_target_vel[0] = ux;
35 m_target_vel[1] = uy;
36 }
37
38 inline void set_mean_velocities(amrex::Real ux, amrex::Real uy)
39 {
40 m_mean_vel[0] = ux;
41 m_mean_vel[1] = uy;
42
43 const auto& current_time = m_time.current_time();
44 const auto& new_time = m_time.new_time();
45 const auto& nph_time = 0.5 * (current_time + new_time);
46 const auto& dt = m_time.delta_t();
47 const auto& t_step = m_time.time_index();
48
49 if (!m_vel_timetable.empty()) {
50 // Forces should be applied at n+1/2. Because ABL forcing is a
51 // delta, the difference between the target velocity (at n+1) and
52 // the current velocity (at n) puts the force term at n+1/2
53 const amrex::Real new_spd = ::amr_wind::interp::linear(
54 m_time_table, m_speed_table, new_time);
55 const amrex::Real new_dir = ::amr_wind::interp::linear_angle(
56 m_time_table, m_direction_table, new_time, 2.0 * M_PI);
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 << std::endl;
75 }
76 }
77
78 amrex::RealArray abl_forcing() const { return m_abl_forcing; }
79
80 amrex::Real forcing_height() const { return m_forcing_height; }
81
82private:
84 const amrex::AmrCore& m_mesh;
85
87 bool m_use_phase_ramp{false};
88
90 int m_n_band{2};
91
93 amrex::RealArray m_abl_forcing{0.0};
94
96 std::string m_vel_timetable;
97
101 std::string m_force_timetable;
105 amrex::Real m_force_outstart{0.0};
106
108 amrex::Vector<amrex::Real> m_time_table;
109
111 amrex::Vector<amrex::Real> m_speed_table;
112
114 amrex::Vector<amrex::Real> m_direction_table;
115
117 amrex::Vector<amrex::Real> m_target_vel{0.0, 0.0, 0.0};
118
120 amrex::RealArray m_mean_vel{0.0};
121
123 amrex::Real m_forcing_height;
124
126 amrex::Real m_forcing_mphase0;
128 amrex::Real m_forcing_mphase1;
129
131 amrex::Real m_water_level;
132
134 const Field* m_vof;
135};
136
137} // namespace amr_wind::pde::icns
138
139#endif /* ABLFORCING_H */
Definition CFDSim.H:47
Definition Field.H:116
Definition SimTime.H:30
AMREX_FORCE_INLINE int time_index() const
Definition SimTime.H:114
AMREX_FORCE_INLINE amrex::Real new_time() const
Definition SimTime.H:108
AMREX_FORCE_INLINE amrex::Real delta_t() const
Definition SimTime.H:84
AMREX_FORCE_INLINE amrex::Real current_time() const
Definition SimTime.H:102
Definition ABLForcing.H:17
void set_target_velocities(amrex::Real ux, amrex::Real uy)
Definition ABLForcing.H:32
amrex::Real m_forcing_mphase0
Height from water interface where force is off.
Definition ABLForcing.H:126
amrex::Vector< amrex::Real > m_time_table
Velocity forcing time table.
Definition ABLForcing.H:108
amrex::Real m_forcing_mphase1
Height from water interface over which force is ramped.
Definition ABLForcing.H:128
const Field * m_vof
VOF field, to avoid forcing on liquid above force-off height.
Definition ABLForcing.H:134
amrex::RealArray m_mean_vel
Current mean vel.
Definition ABLForcing.H:120
ABLForcing(const CFDSim &sim)
Definition ABLForcing.cpp:13
bool m_use_phase_ramp
Activated when water is present in domain.
Definition ABLForcing.H:87
bool m_write_force_timetable
Bool for writing forcing time table.
Definition ABLForcing.H:99
int m_n_band
Number of cells in band to prevent forcing near liquid.
Definition ABLForcing.H:90
void set_mean_velocities(amrex::Real ux, amrex::Real uy)
Definition ABLForcing.H:38
void operator()(const int lev, const amrex::MFIter &mfi, const amrex::Box &bx, const FieldState fstate, const amrex::Array4< amrex::Real > &src_term) const override
Definition ABLForcing.cpp:87
amrex::Vector< amrex::Real > m_speed_table
Velocity forcing speed table.
Definition ABLForcing.H:111
amrex::Real m_force_outstart
Output start time for force.
Definition ABLForcing.H:105
amrex::Real m_forcing_height
Height at which the velocities are forcing.
Definition ABLForcing.H:123
amrex::RealArray abl_forcing() const
Definition ABLForcing.H:78
amrex::Vector< amrex::Real > m_direction_table
Velocity forcing direction table.
Definition ABLForcing.H:114
const SimTime & m_time
Definition ABLForcing.H:83
const amrex::AmrCore & m_mesh
Definition ABLForcing.H:84
static std::string identifier()
Definition ABLForcing.H:19
int m_force_outfreq
Output frequency for forces.
Definition ABLForcing.H:103
amrex::Real m_water_level
Local storage of interface location.
Definition ABLForcing.H:131
std::string m_vel_timetable
File name for velocity forcing time table.
Definition ABLForcing.H:96
amrex::RealArray m_abl_forcing
ABL forcing terms.
Definition ABLForcing.H:93
std::string m_force_timetable
File name for forcing time table output.
Definition ABLForcing.H:101
amrex::Vector< amrex::Real > m_target_vel
Target velocity.
Definition ABLForcing.H:117
amrex::Real forcing_height() const
Definition ABLForcing.H:80
FieldState
Definition FieldDescTypes.H:14
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:213
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:126
Definition ABLForcing.cpp:11