/home/runner/work/amr-wind/amr-wind/amr-wind/wind_energy/actuator/ActSrcLineOp.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/wind_energy/actuator/ActSrcLineOp.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
ActSrcLineOp.H
Go to the documentation of this file.
1#ifndef ACTSRCLINEOP_H_
2#define ACTSRCLINEOP_H_
3
8
10
11template <typename ActTrait>
12class ActSrcOp<ActTrait, ActSrcLine>
13{
14private:
15 typename ActTrait::DataType& m_data;
17
23
24 bool m_init_old{false};
25
26 void copy_to_device();
27
28public:
29 explicit ActSrcOp(typename ActTrait::DataType& data)
30 : m_data(data)
31 , m_act_src(m_data.sim().repo().get_field("actuator_src_term"))
32 {}
33
34 void initialize();
35
36 void setup_op() { copy_to_device(); }
37
38 void operator()(
39 const int lev, const amrex::MFIter& mfi, const amrex::Geometry& geom);
40};
41
42template <typename ActTrait>
44{
45 const auto& grid = m_data.grid();
46 m_pos.resize(grid.pos.size());
47 m_pos_old.resize(grid.pos.size());
48 m_force.resize(grid.force.size());
49 m_epsilon.resize(grid.epsilon.size());
50 m_orientation.resize(grid.orientation.size());
51}
52
53template <typename ActTrait>
55{
56 const auto& grid = m_data.grid();
57
58 // Populate old positions before new positions are updated
59 if (m_init_old) {
60 amrex::Gpu::copy(
61 amrex::Gpu::deviceToDevice, m_pos.begin(), m_pos.end(),
62 m_pos_old.begin());
63 }
64
65 amrex::Gpu::copy(
66 amrex::Gpu::hostToDevice, grid.pos.begin(), grid.pos.end(),
67 m_pos.begin());
68 amrex::Gpu::copy(
69 amrex::Gpu::hostToDevice, grid.force.begin(), grid.force.end(),
70 m_force.begin());
71 amrex::Gpu::copy(
72 amrex::Gpu::hostToDevice, grid.epsilon.begin(), grid.epsilon.end(),
73 m_epsilon.begin());
74 amrex::Gpu::copy(
75 amrex::Gpu::hostToDevice, grid.orientation.begin(),
76 grid.orientation.end(), m_orientation.begin());
77
78 if (!m_init_old) {
79 amrex::Gpu::copy(
80 amrex::Gpu::hostToDevice, grid.pos.begin(), grid.pos.end(),
81 m_pos_old.begin());
82 m_init_old = true;
83 }
84}
85
86template <typename ActTrait>
88 const int lev, const amrex::MFIter& mfi, const amrex::Geometry& geom)
89{
90 BL_PROFILE(
91 "amr-wind::ActSrcOp<" + ActTrait::identifier() +
93
94 const auto& bx = mfi.tilebox();
95
96 const auto bxa =
97 amr_wind::utils::realbox_to_box(m_data.info().bound_box, geom);
98 const auto& bxi = bx & bxa;
99 if (bxi.isEmpty()) {
100 return;
101 }
102
103 const auto& sarr = m_act_src(lev).array(mfi);
104 const auto& problo = geom.ProbLoArray();
105 const auto& dx = geom.CellSizeArray();
106
107 const int npts = m_pos.size();
108 const auto* pos = m_pos.data();
109 const auto* opos = m_pos_old.data();
110 const auto* force = m_force.data();
111 const auto* eps = m_epsilon.data();
112 const auto* tmat = m_orientation.data();
113
114 const auto dcoord_flags = m_data.grid().dcoord_flags;
115
116 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
117 const vs::Vector cc{
118 problo[0] + (i + 0.5) * dx[0],
119 problo[1] + (j + 0.5) * dx[1],
120 problo[2] + (k + 0.5) * dx[2],
121 };
122
123 amrex::RealArray src_force = {0.0};
124 for (int ip = 0; ip < npts; ++ip) {
125 // Put force at n+1/2 location for Godunov
126 constexpr amrex::Real wt = 0.5;
127 const auto pos_ip = wt * pos[ip] + (1.0 - wt) * opos[ip];
128 const auto dist = cc - pos_ip;
129 // Convert to local (chord, span, thickness) coords
130 const auto dist_local_3D = tmat[ip] & dist;
131 // In local coords, zero disabled distances (e.g., for 2D)
132 const auto dist_local = dist_local_3D * dcoord_flags;
133 const auto gauss_fac = utils::gaussian3d(dist_local, eps[ip]);
134 const auto& pforce = force[ip];
135
136 src_force[0] += gauss_fac * pforce.x();
137 src_force[1] += gauss_fac * pforce.y();
138 src_force[2] += gauss_fac * pforce.z();
139 }
140
141 sarr(i, j, k, 0) += src_force[0];
142 sarr(i, j, k, 1) += src_force[1];
143 sarr(i, j, k, 2) += src_force[2];
144 });
145}
146} // namespace amr_wind::actuator::ops
147
148#endif /* ACTSRCLINEOP_H_ */
Definition Field.H:116
ActTrait::DataType & m_data
Definition ActSrcLineOp.H:15
DeviceVecList m_force
Definition ActSrcLineOp.H:20
DeviceVecList m_epsilon
Definition ActSrcLineOp.H:21
DeviceVecList m_pos
Definition ActSrcLineOp.H:18
ActSrcOp(typename ActTrait::DataType &data)
Definition ActSrcLineOp.H:29
DeviceVecList m_pos_old
Definition ActSrcLineOp.H:19
DeviceTensorList m_orientation
Definition ActSrcLineOp.H:22
Definition actuator_ops.H:68
Definition ActSrcLineOp.H:9
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real gaussian3d(const vs::Vector &dist, const vs::Vector &eps)
Definition actuator_utils.H:43
amrex::Gpu::DeviceVector< amr_wind::vs::Tensor > DeviceTensorList
Definition actuator_types.H:67
amrex::Gpu::DeviceVector< amr_wind::vs::Vector > DeviceVecList
Definition actuator_types.H:66
amrex::Box realbox_to_box(const amrex::RealBox &rbx, const amrex::Geometry &geom)
Definition index_operations.cpp:5
Definition actuator_types.H:38
static std::string identifier()
Definition actuator_types.H:39
Definition vector.H:13