/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 treeZm = m_laimax_forest * m_height_forest;
33 const int n = 100;
34 const amrex::Real int_0_fh = amr_wind::utils::trapz(
36 [=](const amrex::Real x) noexcept {
37 const amrex::Real ratio =
38 (m_height_forest - treeZm) / (m_height_forest - x);
39 const auto exponent = (x < treeZm) ? 6.0_rt : 0.5_rt;
40 return std::pow(ratio, exponent) *
41 std::exp(exponent * (1 - ratio));
42 });
43 treelaimax = m_lai_forest / int_0_fh;
44 }
45 return treelaimax;
46 }
47
48 AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real
49 area_fraction(const amrex::Real z, const amrex::Real treelaimax) const
50 {
51 amrex::Real af = 0.0_rt;
52 if (m_type_forest == 1) {
54 } else if (m_type_forest == 2) {
55 const auto treeZm = m_laimax_forest * m_height_forest;
56 const auto ratio =
57 (m_height_forest - treeZm) / (m_height_forest - z);
58 const auto exponent = (z < treeZm) ? 6.0_rt : 0.5_rt;
59 af = treelaimax * std::pow(ratio, exponent) *
60 std::exp(exponent * (1 - ratio));
61 }
62 return af;
63 }
64
65 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::RealBox real_bounding_box(
66 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& prob_lo) const
67 {
68 const amrex::Real search_tol = 1.1_rt;
69 const amrex::Real search_radius =
70 0.5_rt * search_tol * m_diameter_forest;
71 const auto x0 = m_x_forest - search_radius;
72 const auto y0 = m_y_forest - search_radius;
73 const auto z0 = prob_lo[2];
74 const auto x1 = m_x_forest + search_radius;
75 const auto y1 = m_y_forest + search_radius;
76 const auto z1 = m_height_forest;
77 return {x0, y0, z0, x1, y1, z1};
78 }
79
80 amrex::Box bounding_box(const amrex::Geometry& geom) const
81 {
83 real_bounding_box(geom.ProbLoArray()), geom);
84 }
85};
86
90
91class ForestDrag : public Physics::Register<ForestDrag>
92{
93public:
94 static std::string identifier() { return "ForestDrag"; }
95
96 explicit ForestDrag(CFDSim& sim);
97
98 ~ForestDrag() override = default;
99
100 void
101 initialize_fields(int /*level*/, const amrex::Geometry& /*geom*/) override;
102
103 void pre_init_actions() override {}
104
105 void post_init_actions() override {}
106
107 void post_regrid_actions() override;
108
109 void pre_advance_work() override {}
110
111 void post_advance_work() override {}
112
113 amrex::Vector<Forest> read_forest(const int level) const;
114
115private:
119 std::string m_forest_file{"forest.amrwind"};
120};
121} // namespace amr_wind::forestdrag
122
123#endif
Definition CFDSim.H:54
Definition Field.H:116
Field & m_forest_id
Definition ForestDrag.H:118
std::string m_forest_file
Definition ForestDrag.H:119
CFDSim & m_sim
Definition ForestDrag.H:116
amrex::Vector< Forest > read_forest(const int level) const
Definition ForestDrag.cpp:91
void initialize_fields(int, const amrex::Geometry &) override
Definition ForestDrag.cpp:33
static std::string identifier()
Definition ForestDrag.H:94
void pre_advance_work() override
Definition ForestDrag.H:109
ForestDrag(CFDSim &sim)
Definition ForestDrag.cpp:15
void post_init_actions() override
Definition ForestDrag.H:105
void post_advance_work() override
Definition ForestDrag.H:111
void pre_init_actions() override
Definition ForestDrag.H:103
~ForestDrag() override=default
Field & m_forest_drag
Definition ForestDrag.H:117
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:65
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:80
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:49
amrex::Real m_height_forest
Definition ForestDrag.H:22