/home/runner/work/amr-wind/amr-wind/amr-wind/physics/ForestDrag.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/physics/ForestDrag.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
ForestDrag.H
Go to the documentation of this file.
1#ifndef FORESTDRAG_H
2#define FORESTDRAG_H
3
6#include "amr-wind/CFDSim.H"
10#include "AMReX_REAL.H"
11
12using namespace amrex::literals;
13
14namespace amr_wind::forestdrag {
15
16struct Forest
17{
18 int m_id{-1};
19 amrex::Real m_type_forest;
20 amrex::Real m_x_forest;
21 amrex::Real m_y_forest;
22 amrex::Real m_height_forest;
23 amrex::Real m_diameter_forest;
24 amrex::Real m_cd_forest;
25 amrex::Real m_lai_forest;
26 amrex::Real m_laimax_forest;
27
28 AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real lm() const
29 {
30 amrex::Real treelaimax = 0.0_rt;
31 if (m_type_forest == 2) {
32 const amrex::Real captured_height_forest = m_height_forest;
33 const amrex::Real treeZm = m_laimax_forest * captured_height_forest;
34 const int n = 100;
35 const amrex::Real int_0_fh = amr_wind::utils::trapz(
36 0, captured_height_forest - constants::TIGHT_TOL, n,
37 [=](const amrex::Real x) {
38 const amrex::Real ratio =
39 (captured_height_forest - treeZm) /
40 (captured_height_forest - x);
41 const auto exponent = (x < treeZm) ? 6.0_rt : 0.5_rt;
42 return std::pow(ratio, exponent) *
43 std::exp(exponent * (1 - ratio));
44 });
45 treelaimax = m_lai_forest / int_0_fh;
46 }
47 return treelaimax;
48 }
49
50 AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real
51 area_fraction(const amrex::Real z, const amrex::Real treelaimax) const
52 {
53 amrex::Real af = 0.0_rt;
54 if (m_type_forest == 1) {
56 } else if (m_type_forest == 2) {
57 const auto treeZm = m_laimax_forest * m_height_forest;
58 const auto ratio =
59 (m_height_forest - treeZm) / (m_height_forest - z);
60 const auto exponent = (z < treeZm) ? 6.0_rt : 0.5_rt;
61 af = treelaimax * std::pow(ratio, exponent) *
62 std::exp(exponent * (1 - ratio));
63 }
64 return af;
65 }
66
67 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::RealBox real_bounding_box(
68 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& prob_lo) const
69 {
70 const amrex::Real search_tol = 1.1_rt;
71 const amrex::Real search_radius =
72 0.5_rt * search_tol * m_diameter_forest;
73 const auto x0 = m_x_forest - search_radius;
74 const auto y0 = m_y_forest - search_radius;
75 const auto z0 = prob_lo[2];
76 const auto x1 = m_x_forest + search_radius;
77 const auto y1 = m_y_forest + search_radius;
78 const auto z1 = m_height_forest;
79 return {x0, y0, z0, x1, y1, z1};
80 }
81
82 [[nodiscard]] amrex::Box bounding_box(const amrex::Geometry& geom) const
83 {
85 real_bounding_box(geom.ProbLoArray()), geom);
86 }
87};
88
92
93class ForestDrag : public Physics::Register<ForestDrag>
94{
95public:
96 static std::string identifier() { return "ForestDrag"; }
97
98 explicit ForestDrag(CFDSim& sim);
99
100 ~ForestDrag() override = default;
101
102 void
103 initialize_fields(int /*level*/, const amrex::Geometry& /*geom*/) override;
104
105 void pre_init_actions() override {}
106
107 void post_init_actions() override {}
108
109 void post_regrid_actions() override;
110
111 void pre_advance_work() override {}
112
113 void post_advance_work() override {}
114
115 [[nodiscard]] amrex::Vector<Forest> read_forest(int level) const;
116
117private:
121 std::string m_forest_file{"forest.amrwind"};
122};
123} // namespace amr_wind::forestdrag
124
125#endif
Definition CFDSim.H:54
Definition Field.H:112
Field & m_forest_id
Definition ForestDrag.H:120
std::string m_forest_file
Definition ForestDrag.H:121
CFDSim & m_sim
Definition ForestDrag.H:118
void initialize_fields(int, const amrex::Geometry &) override
Definition ForestDrag.cpp:33
static std::string identifier()
Definition ForestDrag.H:96
void pre_advance_work() override
Definition ForestDrag.H:111
ForestDrag(CFDSim &sim)
Definition ForestDrag.cpp:15
void post_init_actions() override
Definition ForestDrag.H:107
void post_advance_work() override
Definition ForestDrag.H:113
void pre_init_actions() override
Definition ForestDrag.H:105
~ForestDrag() override=default
amrex::Vector< Forest > read_forest(int level) const
Definition ForestDrag.cpp:91
Field & m_forest_drag
Definition ForestDrag.H:119
void post_regrid_actions() override
Definition ForestDrag.cpp:83
static constexpr amrex::Real TIGHT_TOL
A tight tolerance.
Definition constants.H:17
Definition ForestDrag.cpp:13
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real trapz(const amrex::Real xa, const amrex::Real xb, const int n, const Function &f)
Definition integrals.H:14
amrex::Box realbox_to_box(const amrex::RealBox &rbx, const amrex::Geometry &geom)
Definition index_operations.cpp:5
Definition ForestDrag.H:17
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::RealBox real_bounding_box(const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &prob_lo) const
Definition ForestDrag.H:67
amrex::Real m_y_forest
Definition ForestDrag.H:21
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real lm() const
Definition ForestDrag.H:28
amrex::Box bounding_box(const amrex::Geometry &geom) const
Definition ForestDrag.H:82
int m_id
Definition ForestDrag.H:18
amrex::Real m_x_forest
Definition ForestDrag.H:20
amrex::Real m_diameter_forest
Definition ForestDrag.H:23
amrex::Real m_laimax_forest
Definition ForestDrag.H:26
amrex::Real m_type_forest
Definition ForestDrag.H:19
amrex::Real m_cd_forest
Definition ForestDrag.H:24
amrex::Real m_lai_forest
Definition ForestDrag.H:25
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real area_fraction(const amrex::Real z, const amrex::Real treelaimax) const
Definition ForestDrag.H:51
amrex::Real m_height_forest
Definition ForestDrag.H:22