landuseClass.C
Go to the documentation of this file.
1 #include "landuseClass.H"
2 
3 
4 namespace Foam
5 {
6 
8  {
9  }
10 
12 
13  code_ = -1;
14  name_ = word("default");
15  Cd_=0;
16  LAI_=0;
17  z0_=0;
18  height_=0;
19  LADmax_=0;
20  }
21 
22 
24 
25  dictionary landuseClassDict(dict.subDict(name));
26 
27  landuseClassDict.lookup("code") >> code_;
28 
29  name_ = name;
30 
31  Cd_ = landuseClassDict.lookupOrDefault("Cd", 0.2, false, false);
32  height_ = landuseClassDict.lookupOrDefault("height", 0.0, false, false);
33  z0_ = landuseClassDict.lookupOrDefault("z0", 0.001, false, false);
34  LAI_ = landuseClassDict.lookupOrDefault("LAI", 0.0, false, false);
35  LADmax_ = landuseClassDict.lookupOrDefault("LADmax", -1.0, false, false);
36 
37  if (landuseClassDict.found("LADProfile"))
38  landuseClassDict.lookup("LADProfile", false, false) >> LADProfile_;
39 
40  if (LADmax_ == -1.0) {
41  LADmaxFromLAI();
42  }
43  }
44 
46  {
47  //uses simpsons rule to integrate between the points
48  scalar LAItmp=0;
49  for(label fi=1;fi<LADProfile_.size();fi++)
50  {
51  if(LADProfile_[fi]==0 or LADProfile_[fi-1]==0)
52  LAItmp += 1/2.0*abs(LADProfile_[1]-LADProfile_[0])*LADmax_*0.1*height_;
53  else
54  LAItmp += min(LADProfile_[fi],LADProfile_[fi-1])*LADmax_*0.1*height_
55  +1/2.0*abs(LADProfile_[fi]-LADProfile_[fi-1])*0.1*height_;
56  }
57  return LAItmp;
58  }
59 
61  {
62  LADmax_ = 0;
63  scalar LAItmp = 0;
64  while(LAItmp < LAI_)
65  {
67  LADmax_ += 0.01;
68  }
69  }
70 
71 
72  scalar landuseClass::LAD(scalar z, scalar treeHeight=-1)
73  {
74 
75  // If tree height is not specified, the value of the landuse class is used
76  if (treeHeight == -1)
77  treeHeight = height_;
78 
79  if (treeHeight <= 0)
80  return 0;
81 
82  if (z > treeHeight)
83  return 0;
84 
85  // calculate vertical distance represented by each value in LADProfile
86  scalar deltaz = treeHeight / scalar(LADProfile_.size());
87 
88  // Calculate which index in the LADProfile that should be used at height z
89 //Info << "z = " << z<< endl;
90 //Info << "deltaz = " << deltaz << endl;
91 //Info << "sround z/deltaz = " << label(round(z / deltaz)) << endl;
92  label profileIndex = label(round(z / deltaz));
93 
94  // find index in LADProfile with max LAD
95  label LADMaxIndex = 0;
96  scalar tmpLAD = -1;
97  for(label i=0; i < LADProfile_.size(); i++)
98  {
99  if (LADProfile_[i] > tmpLAD)
100  {
101  LADMaxIndex = i;
102  tmpLAD = LADProfile_[LADMaxIndex];
103  // Info << "tmpLAD" << tmpLAD << endl;
104  }
105 // Info << "i = " << i <<endl;
106  }
107 // Info << "profileIndex" << profileIndex << endl;
108 // Info << "LADMaxIndex" << LADMaxIndex << endl;
109  if (profileIndex >= LADProfile_.size())
110  {
111  profileIndex = profileIndex -1;
112  }
113 
114  // return LAD at height z
115  return LADProfile_[profileIndex] / LADProfile_[LADMaxIndex] * LADmax_;
116  }
117 }
Foam::landuseClass::height_
scalar height_
Definition: landuseClass.H:65
Foam::landuseClass::landuseClass
landuseClass()
Definition: landuseClass.C:11
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::landuseClass::name
const word & name()
Definition: landuseClass.H:88
landuseClass.H
Foam::landuseClass::LAD
scalar LAD(scalar z, scalar treeHeight)
Definition: landuseClass.C:72
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::dictionary::lookupOrDefault
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Definition: dictionaryTemplates.C:33
Foam::landuseClass::LAI_
scalar LAI_
Definition: landuseClass.H:63
Foam::landuseClass::z0_
scalar z0_
Definition: landuseClass.H:64
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::landuseClass::LADProfile_
scalarList LADProfile_
Definition: landuseClass.H:67
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::landuseClass::LADmax_
scalar LADmax_
Definition: landuseClass.H:66
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::landuseClass::integrateLAD
scalar integrateLAD()
Definition: landuseClass.C:45
Foam::landuseClass::Cd_
scalar Cd_
Definition: landuseClass.H:62
Foam::landuseClass::~landuseClass
~landuseClass()
Definition: landuseClass.C:7
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::landuseClass::LADmaxFromLAI
void LADmaxFromLAI()
Definition: landuseClass.C:60
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::landuseClass::name_
word name_
Definition: landuseClass.H:61
Foam::landuseClass::code_
label code_
Definition: landuseClass.H:60