/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 const int lev,
30 const amrex::MFIter& mfi,
31 const amrex::Box& bx,
32 const FieldState fstate,
33 const amrex::Array4<amrex::Real>& src_term) const override;
34
35 inline 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 inline 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 * static_cast<amrex::Real>(M_PI));
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 << std::endl;
79 }
80 }
81
82 amrex::RealArray abl_forcing() const { return m_abl_forcing; }
83
84 amrex::Real forcing_height() const { return m_forcing_height; }
85
86private:
88 const amrex::AmrCore& m_mesh;
89
91 bool m_use_phase_ramp{false};
92
94 int m_n_band{2};
95
97 amrex::RealArray m_abl_forcing{0.0_rt};
98
100 std::string m_vel_timetable;
101
105 std::string m_force_timetable;
109 amrex::Real m_force_outstart{0.0_rt};
110
112 amrex::Vector<amrex::Real> m_time_table;
113
115 amrex::Vector<amrex::Real> m_speed_table;
116
118 amrex::Vector<amrex::Real> m_direction_table;
119
121 amrex::Vector<amrex::Real> m_target_vel{0.0_rt, 0.0_rt, 0.0_rt};
122
124 amrex::RealArray m_mean_vel{0.0_rt};
125
127 amrex::Real m_forcing_height;
128
130 amrex::Real m_forcing_mphase0;
132 amrex::Real m_forcing_mphase1;
133
135 amrex::Real m_water_level;
136
138 const Field* m_vof;
139};
140
141} // namespace amr_wind::pde::icns
142
143#endif /* ABLFORCING_H */
Definition CFDSim.H:54
Definition Field.H:116
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:130
amrex::Vector< amrex::Real > m_time_table
Velocity forcing time table.
Definition ABLForcing.H:112
amrex::Real m_forcing_mphase1
Height from water interface over which force is ramped.
Definition ABLForcing.H:132
const Field * m_vof
VOF field, to avoid forcing on liquid above force-off height.
Definition ABLForcing.H:138
amrex::RealArray m_mean_vel
Current mean vel.
Definition ABLForcing.H:124
ABLForcing(const CFDSim &sim)
Definition ABLForcing.cpp:16
bool m_use_phase_ramp
Activated when water is present in domain.
Definition ABLForcing.H:91
bool m_write_force_timetable
Bool for writing forcing time table.
Definition ABLForcing.H:103
int m_n_band
Number of cells in band to prevent forcing near liquid.
Definition ABLForcing.H:94
void set_mean_velocities(amrex::Real ux, amrex::Real uy)
Definition ABLForcing.H:41
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:90
amrex::Vector< amrex::Real > m_speed_table
Velocity forcing speed table.
Definition ABLForcing.H:115
amrex::Real m_force_outstart
Output start time for force.
Definition ABLForcing.H:109
amrex::Real m_forcing_height
Height at which the velocities are forcing.
Definition ABLForcing.H:127
amrex::RealArray abl_forcing() const
Definition ABLForcing.H:82
amrex::Vector< amrex::Real > m_direction_table
Velocity forcing direction table.
Definition ABLForcing.H:118
const SimTime & m_time
Definition ABLForcing.H:87
const amrex::AmrCore & m_mesh
Definition ABLForcing.H:88
static std::string identifier()
Definition ABLForcing.H:22
int m_force_outfreq
Output frequency for forces.
Definition ABLForcing.H:107
amrex::Real m_water_level
Local storage of interface location.
Definition ABLForcing.H:135
std::string m_vel_timetable
File name for velocity forcing time table.
Definition ABLForcing.H:100
amrex::RealArray m_abl_forcing
ABL forcing terms.
Definition ABLForcing.H:97
std::string m_force_timetable
File name for forcing time table output.
Definition ABLForcing.H:105
amrex::Vector< amrex::Real > m_target_vel
Target velocity.
Definition ABLForcing.H:121
amrex::Real forcing_height() const
Definition ABLForcing.H:84
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:218
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:129
Definition ABLForcing.cpp:14