/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
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
11namespace amr_wind::forestdrag {
12
13struct Forest
14{
15 int m_id{-1};
16 amrex::Real m_type_forest;
17 amrex::Real m_x_forest;
18 amrex::Real m_y_forest;
19 amrex::Real m_height_forest;
20 amrex::Real m_diameter_forest;
21 amrex::Real m_cd_forest;
22 amrex::Real m_lai_forest;
23 amrex::Real m_laimax_forest;
24
25 AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real lm() const
26 {
27 amrex::Real treelaimax = 0.0;
28 if (m_type_forest == 2) {
29 const amrex::Real treeZm = m_laimax_forest * m_height_forest;
30 const int n = 100;
31 const amrex::Real int_0_fh = amr_wind::utils::trapz(
33 [=](const amrex::Real x) noexcept {
34 const amrex::Real ratio =
35 (m_height_forest - treeZm) / (m_height_forest - x);
36 const auto exponent = (x < treeZm) ? 6.0 : 0.5;
37 return std::pow(ratio, exponent) *
38 std::exp(exponent * (1 - ratio));
39 });
40 treelaimax = m_lai_forest / int_0_fh;
41 }
42 return treelaimax;
43 }
44
45 AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real
46 area_fraction(const amrex::Real z, const amrex::Real treelaimax) const
47 {
48 amrex::Real af = 0.0;
49 if (m_type_forest == 1) {
51 } else if (m_type_forest == 2) {
52 const auto treeZm = m_laimax_forest * m_height_forest;
53 const auto ratio =
54 (m_height_forest - treeZm) / (m_height_forest - z);
55 const auto exponent = (z < treeZm) ? 6.0 : 0.5;
56 af = treelaimax * std::pow(ratio, exponent) *
57 std::exp(exponent * (1 - ratio));
58 }
59 return af;
60 }
61
62 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::RealBox real_bounding_box(
63 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& prob_lo) const
64 {
65 const amrex::Real search_tol = 1.1;
66 const amrex::Real search_radius = 0.5 * search_tol * m_diameter_forest;
67 const auto x0 = m_x_forest - search_radius;
68 const auto y0 = m_y_forest - search_radius;
69 const auto z0 = prob_lo[2];
70 const auto x1 = m_x_forest + search_radius;
71 const auto y1 = m_y_forest + search_radius;
72 const auto z1 = m_height_forest;
73 return {x0, y0, z0, x1, y1, z1};
74 }
75
76 amrex::Box bounding_box(const amrex::Geometry& geom) const
77 {
79 real_bounding_box(geom.ProbLoArray()), geom);
80 }
81};
82
87class ForestDrag : public Physics::Register<ForestDrag>
88{
89public:
90 static std::string identifier() { return "ForestDrag"; }
91
92 explicit ForestDrag(CFDSim& sim);
93
94 ~ForestDrag() override = default;
95
96 void
97 initialize_fields(int /*level*/, const amrex::Geometry& /*geom*/) override;
98
99 void pre_init_actions() override {}
100
101 void post_init_actions() override {}
102
103 void post_regrid_actions() override;
104
105 void pre_advance_work() override {}
106
107 void post_advance_work() override {}
108
109 amrex::Vector<Forest> read_forest(const int level) const;
110
111private:
115 std::string m_forest_file{"forest.amrwind"};
116};
117} // namespace amr_wind::forestdrag
118
119#endif
Definition CFDSim.H:51
Definition Field.H:116
Definition ForestDrag.H:88
Field & m_forest_id
Definition ForestDrag.H:114
std::string m_forest_file
Definition ForestDrag.H:115
CFDSim & m_sim
Definition ForestDrag.H:112
amrex::Vector< Forest > read_forest(const int level) const
Definition ForestDrag.cpp:88
void initialize_fields(int, const amrex::Geometry &) override
Definition ForestDrag.cpp:30
static std::string identifier()
Definition ForestDrag.H:90
void pre_advance_work() override
Definition ForestDrag.H:105
ForestDrag(CFDSim &sim)
Definition ForestDrag.cpp:12
void post_init_actions() override
Definition ForestDrag.H:101
void post_advance_work() override
Definition ForestDrag.H:107
void pre_init_actions() override
Definition ForestDrag.H:99
~ForestDrag() override=default
Field & m_forest_drag
Definition ForestDrag.H:113
void post_regrid_actions() override
Definition ForestDrag.cpp:80
static constexpr amrex::Real TIGHT_TOL
A tight tolerance.
Definition constants.H:19
Definition ForestDrag.cpp:10
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:12
amrex::Box realbox_to_box(const amrex::RealBox &rbx, const amrex::Geometry &geom)
Definition index_operations.cpp:5
Definition ForestDrag.H:14
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:62
amrex::Real m_y_forest
Definition ForestDrag.H:18
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real lm() const
Definition ForestDrag.H:25
amrex::Box bounding_box(const amrex::Geometry &geom) const
Definition ForestDrag.H:76
int m_id
Definition ForestDrag.H:15
amrex::Real m_x_forest
Definition ForestDrag.H:17
amrex::Real m_diameter_forest
Definition ForestDrag.H:20
amrex::Real m_laimax_forest
Definition ForestDrag.H:23
amrex::Real m_type_forest
Definition ForestDrag.H:16
amrex::Real m_cd_forest
Definition ForestDrag.H:21
amrex::Real m_lai_forest
Definition ForestDrag.H:22
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real area_fraction(const amrex::Real z, const amrex::Real treelaimax) const
Definition ForestDrag.H:46
amrex::Real m_height_forest
Definition ForestDrag.H:19