canopySource.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24  Copyright is held by the author.
25 
26 Class
27  Foam::fv::canopySource
28 
29 Group
30  grpFvOptionsSources
31 
32 Author
33  David Segersson, Swedish Meteorological and Hydrological Institute
34  david.segersson@smhi.se
35 
36 Description
37  Base class for momentum and turbulence source/sink-terms for tree canopy.
38 
39 
40 Usage
41  Example usage:
42  \verbatim
43  canopy
44  {
45  type canopySource;
46  active on; // toggle the option
47  writeFields on; // write to disk
48  readFromDisk off; // if present, read fields landuse, z0, LAD from disk
49  readLanduseFromRaster off; // read landuse from raster
50  readCanopyHeightFromRaster off; // read canopy height from raster
51  sourcePatches (ground forest); // for which patches to set landuse
52  patchLanduse (0 1); // landuse code per patch (if not read from raster)
53 
54  translateRaster (0 0 0); // translate raster to mesh coordinate sys.
55 
56  LADProfile ( 0.05 0.1 0.15 0.35 1.1 0.9 0.5 0.2 0.15 0.05 0.01 ); // default LAD profile
57 
58  landuse
59  {
60 
61  low_birch // name of landuse class
62  {
63  code 1; // code of landuse class
64  Cd 0.2; // drag coefficient of trees
65  LAI 2.15; // Leaf Area Index (used if LADmax is not specified)
66  LADmax 1.2; // Maximum Leaf Area Density [m ^-1]
67  z0 0.06; // roughness length [m]
68  height 7.5; // tree canopy height (if not read from raster)
69 
70  // Vertical profile of Leaf Area Density
71  // first value is closest to ground
72  // each value represents an equal share of the tree height
73  // e.g. for a 4 m tree and 4 values, each value will represent 1 m
74  // values are scaled so that the highest will correspond to LADMax
75 
76  LADProfile ( 0.05 0.1 0.15 0.35 1.1 0.9 0.5 0.2 0.15 0.05 0.01 );
77  };
78 
79  grass
80  {
81  code 0;
82  Cd 0.2;
83  LAI 0;
84  z0 0.06;
85  height 0;
86  };
87 
88  };
89  }
90  \endverbatim
91 
92 SourceFiles
93  canopySource.C
94 
95 \*---------------------------------------------------------------------------*/
96 
97 #ifndef canopySource_H
98 #define canopySource_H
99 
100 #include "fvOption.H"
101 #include "dimensionedTypes.H"
102 #include "DynamicList.H"
103 #include "landuseClass.H"
104 #include "Raster.H"
106 #include "groundDist.H"
107 #include "wallFvPatch.H"
108 
109 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
110 
111 namespace Foam
112 {
113 namespace fv
114 {
115 
116 /*---------------------------------------------------------------------------*\
117  Class canopySource Declaration
118 \*---------------------------------------------------------------------------*/
119 
120 class canopySource
121 :
122  public option
123 {
124 
125 protected:
126 
127  // member data for landuse
130 
133 
134  // read landuse, z0 and LAD from disk if they are present
136 
137  // read landuse from raster instead of specifying per patch
140 
141  // read canopy height from raster instead of specifying per landuse class
144 
145  // translation vector from coordiantes in raster to coordinates in mesh
147 
149 
150  // if variables are present on disk, they are read instead of calculated
151  // this allows setting the data with external programs
154  bool z0_from_disk_;
155 
156  //- Source terms to momentum equation (for solvers with and without explicit density)
157  void addSup
158  (
159  const volScalarField& rho,
160  fvMatrix<vector>& eqn,
161  const label fieldi
162  );
163 
164  void addSup
165  (
166  fvMatrix<vector>& eqn,
167  const label fieldi
168  );
169 
170 
171  //- Disallow default bitwise copy construct
172  canopySource(const canopySource&);
173 
174  //- Disallow default bitwise assignment
175  void operator=(const canopySource&);
176 
177  void checkData() const;
178 
179  // Member Functions
180  Raster readRaster(fileName rasterPath);
182  void setPatchLanduse(label patch, volScalarField &landuse,
183  volScalarField &LAD, volScalarField &z0,
185  void calculateCanopy();
186  void readLanduseClasses();
187 
188 
189 public:
190 
191 
192  //- Runtime type information
193  TypeName("canopySource");
194 
195 
196  // Constructors
197 
198  //- Construct from components
200  (
201  const word& name,
202  const word& modelType,
203  const dictionary& dict,
204  const fvMesh& mesh
205  );
206 
207 
208  //- Destructor
209  virtual ~canopySource()
210  {}
211 
212 
213  // Member Functions
214  //- Read dictionary
215  bool read(const dictionary& dict);
216 
217 };
218 
219 
220 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 
222 } // End namespace fv
223 } // End namespace Foam
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 #endif
228 
229 // ************************************************************************* //
Raster
Definition: Raster.H:13
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:60
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
nutkAtmRoughWallFunctionFvPatchScalarField.H
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::fv::canopySource::operator=
void operator=(const canopySource &)
Disallow default bitwise assignment.
Foam::fv::canopySource::calculateCanopy
void calculateCanopy()
Definition: canopySource.C:352
Foam::fv::canopySource::readCanopyHeightFromRaster_
Switch readCanopyHeightFromRaster_
Definition: canopySource.H:141
Foam::fv::canopySource::calculatePatchDistance
void calculatePatchDistance(label patch, volScalarField &d)
Definition: canopySource.C:341
Foam::fv::option::name
const word & name() const
Return const access to the source name.
Definition: fvOptionI.H:28
groundDist.H
Foam::fv::canopySource::read
bool read(const dictionary &dict)
Read dictionary.
Definition: canopySource.C:192
landuseClass.H
Foam::fv::canopySource::z0_from_disk_
bool z0_from_disk_
Definition: canopySource.H:153
Foam::fv::canopySource::writeFields_
Switch writeFields_
Definition: canopySource.H:147
Foam::fv::canopySource::~canopySource
virtual ~canopySource()
Destructor.
Definition: canopySource.H:208
Foam::fv::canopySource::LAD_from_disk_
bool LAD_from_disk_
Definition: canopySource.H:151
wallFvPatch.H
Foam::fv::canopySource::readLanduseFromRaster_
Switch readLanduseFromRaster_
Definition: canopySource.H:137
Foam::fv::canopySource::setPatchLanduse
void setPatchLanduse(label patch, volScalarField &landuse, volScalarField &LAD, volScalarField &z0, volScalarField &nut, volScalarField &d)
Definition: canopySource.C:253
Foam::fv::canopySource::canopySource
canopySource(const canopySource &)
Disallow default bitwise copy construct.
Foam::fv::canopySource::sourcePatches_
wordList sourcePatches_
Definition: canopySource.H:127
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::fv::option
Finite volume options abtract base class. Provides a base set of controls, e.g.
Definition: fvOption.H:65
Foam::fv::canopySource
Base class for momentum and turbulence source/sink-terms for tree canopy.
Definition: canopySource.H:119
Foam::fv::canopySource::translateRaster
vector translateRaster
Definition: canopySource.H:145
nut
nut
Definition: createTDFields.H:71
Foam::fv::canopySource::patchLanduseTable_
HashTable< landuseClass, label > patchLanduseTable_
Definition: canopySource.H:131
Foam::fv::canopySource::landuseRaster_
Raster landuseRaster_
Definition: canopySource.H:138
Foam::fv::canopySource::checkData
void checkData() const
Definition: canopySource.C:131
Foam::fv::canopySource::canopy_
autoPtr< volScalarField > canopy_
Definition: canopySource.H:128
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::fv::canopySource::TypeName
TypeName("canopySource")
Runtime type information.
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
rho
rho
Definition: pEqn.H:3
Foam::HashTable
An STL-conforming hash table.
Definition: HashTable.H:61
fv
labelList fv(nPoints)
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::fv::canopySource::readRaster
Raster readRaster(fileName rasterPath)
Definition: canopySource.C:145
Foam::fv::canopySource::readFromDisk_
Switch readFromDisk_
Definition: canopySource.H:134
Foam::Vector< scalar >
fvOption.H
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Raster.H
Foam::fv::canopySource::addSup
void addSup(const volScalarField &rho, fvMatrix< vector > &eqn, const label fieldi)
Source terms to momentum equation (for solvers with and without explicit density)
Definition: canopySource.C:107
Foam::fv::option::mesh
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvOptionI.H:34
dimensionedTypes.H
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:68
DynamicList.H
Foam::fv::canopySource::landuseTable_
HashTable< landuseClass, label > landuseTable_
Definition: canopySource.H:130
Foam::fv::canopySource::canopyHeightRaster_
Raster canopyHeightRaster_
Definition: canopySource.H:142
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::fv::canopySource::landuse_from_disk_
bool landuse_from_disk_
Definition: canopySource.H:152
Foam::fv::canopySource::readLanduseClasses
void readLanduseClasses()
Definition: canopySource.C:170