solarCalculator.C
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 OpenCFD Ltd
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 \*---------------------------------------------------------------------------*/
25 
26 #include "solarCalculator.H"
27 #include "Time.H"
28 #include "unitConversion.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(solarCalculator, 0);
35 
36  template<>
37  const char* NamedEnum
38  <
40  2
41  >::names[] =
42  {
43  "sunDirConstant",
44  "sunDirTraking"
45  };
46 
47  template<>
48  const char* NamedEnum
49  <
51  3
52  >::names[] =
53  {
54  "sunLoadConstant",
55  "sunLoadFairWeatherConditions",
56  "sunLoadTheoreticalMaximum"
57  };
58 }
59 
62 
65 
66 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
67 
69 {
70  scalar runTime = 0.0;
71  switch (sunDirectionModel_)
72  {
73  case mSunDirTraking:
74  {
75  runTime = mesh_.time().value();
76  break;
77  }
78  case mSunDirConstant:
79  {
80  break;
81  }
82  }
83 
84  scalar LSM = 15.0*(readScalar(dict_.lookup("localStandardMeridian")));
85 
86  scalar D = readScalar(dict_.lookup("startDay")) + runTime/86400.0;
87  scalar M = 6.24004 + 0.0172*D;
88  scalar EOT = -7.659*sin(M) + 9.863*sin(2*M + 3.5932);
89 
90  startTime_ = readScalar(dict_.lookup("startTime"));
91  scalar LST = startTime_ + runTime/3600.0;
92 
93  scalar LON = readScalar(dict_.lookup("longitude"));
94 
95  scalar AST = LST + EOT/60.0 + (LON - LSM)/15;
96 
97  scalar delta = 23.45*sin(degToRad((360*(284 + D))/365));
98 
99  scalar H = degToRad(15*(AST - 12));
100 
101  scalar L = degToRad(readScalar(dict_.lookup("latitude")));
102 
103  scalar deltaRad = degToRad(delta);
104  beta_ = max(asin(cos(L)*cos(deltaRad)*cos(H) + sin(L)*sin(deltaRad)), 1e-3);
105  tetha_ = acos((sin(beta_)*sin(L) - sin(deltaRad))/(cos(beta_)*cos(L)));
106  //tetha_ = acos(sin(L)*cos(deltaRad)*cos(H) - sin(deltaRad)*cos(L))/(cos(beta_));
107 
108  // theta is the angle between the SOUTH axis and the Sun
109  // If the hour angle is lower than zero (morning) the Sun is positioned
110  // on the East side.
111  if (H < 0)
112  {
114  }
115 
116  if (debug)
117  {
118  Info << "本地时间: " <<LST<< endl;
119  Info << "显式太阳时间是:" << AST << endl;
120  //Info << "AST ,swatch time is " << AST << endl;
121  Info << "当前太阳时角H的角度degree is " << 15*(AST-12) << endl;
122  //Info << "H is :" << H << endl;
123  Info <<"当前太阳时角H的弧度值是: " << H << endl;
124  Info << "纬度L 是 :" << readScalar(dict_.lookup("latitude")) << endl;
125  Info << "纬度L 弧度是is :" << L << endl;
126  Info << "deltaRad is : " << deltaRad << endl;
127  Info << " dddd " <<cos(L)*cos(deltaRad)*cos(H) + sin(L)*sin(deltaRad) << endl;
128  Info << "max beta with 0.001 is " << beta_ << endl;
129  Info << tab << "altitude : " << radToDeg(beta_) << endl;
130  Info << tab << "azimuth : " << radToDeg(tetha_) << endl;
131  Info << "太阳高度角 beta is :" << beta_ <<endl;
132  Info << "太阳方位角 tetha is :" << tetha_ <<endl;
133  Info << tab << "太阳高度角 弧度altitude : " << radToDeg(beta_) << endl;
134  Info << tab << "太阳方位角 弧度azimuth : " << radToDeg(tetha_) << endl;
135  }
136 }
137 
138 
140 {
141 
142  dict_.lookup("gridUp") >> gridUp_;
143  gridUp_ /= mag(gridUp_);
144 
145  dict_.lookup("gridEast") >> eastDir_;
146  eastDir_ /= mag(eastDir_);
147 
148  coord_.reset
149  (
150  new coordinateSystem("grid", vector::zero, gridUp_, eastDir_)
151  );
152 
153  direction_.z() = -sin(beta_);
154  direction_.y() = cos(beta_)*cos(tetha_); //North
155  direction_.x() = cos(beta_)*sin(tetha_); //East
156 
157  direction_ /= mag(direction_);
158 
159  if (debug)
160  {
161  Info<< "Sun direction in absolute coordinates : " << direction_ <<endl;
162  }
163 
164  direction_ = coord_->R().transform(direction_);
165 
166  if (debug)
167  {
168  Info<< "Sun direction in the Grid coordinates : " << direction_ <<endl;
169  }
170 }
171 
172 
174 {
175  switch (sunDirectionModel_)
176  {
177  case mSunDirConstant:
178  {
179  if (dict_.found("sunDirection"))
180  {
181  dict_.lookup("sunDirection") >> direction_;
182  direction_ /= mag(direction_);
183  }
184  else
185  {
186  calculateBetaTetha();
187  calculateSunDirection();
188  }
189 
190  break;
191  }
192  case mSunDirTraking:
193  {
194  if (word(mesh_.ddtScheme("default")) == "steadyState")
195  {
197  << " Sun direction model can not be sunDirtracking if the "
198  << " case is steady " << nl << exit(FatalError);
199  }
200 
201  dict_.lookup("sunTrackingUpdateInterval") >>
202  sunTrackingUpdateInterval_;
203 
204  calculateBetaTetha();
205  calculateSunDirection();
206  break;
207  }
208  }
209 
210  switch (sunLoadModel_)
211  {
212  case mSunLoadConstant:
213  {
214 //Info << "dict is :" << dict_ << endl;
215  dict_.lookup("directSolarRad") >> directSolarRad_;
216  dict_.lookup("diffuseSolarRad") >> diffuseSolarRad_;
217  break;
218  }
219  case mSunLoadFairWeatherConditions:
220  {
221  A_ = readScalar(dict_.lookup("A"));
222  B_ = readScalar(dict_.lookup("B"));
223 
224  if (dict_.found("beta"))
225  {
226  dict_.lookup("beta") >> beta_;
227  }
228  else
229  {
230  calculateBetaTetha();
231  }
232 
233  directSolarRad_ = A_/exp(B_/sin(beta_));
234 
235  groundReflectivity_ =
236  readScalar(dict_.lookup("groundReflectivity"));
237 
238  break;
239  }
240  case mSunLoadTheoreticalMaximum:
241  {
242  Setrn_ = readScalar(dict_.lookup("Setrn"));
243  SunPrime_ = readScalar(dict_.lookup("SunPrime"));
244  directSolarRad_ = Setrn_*SunPrime_;
245 
246  groundReflectivity_ =
247  readScalar(dict_.lookup("groundReflectivity"));
248  break;
249  }
250  }
251 }
252 
253 
254 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
255 
257 (
258  const dictionary& dict,
259  const fvMesh& mesh
260 )
261 :
262  mesh_(mesh),
263  dict_(dict),
264  direction_(vector::zero),
265  directSolarRad_(0.0),
266  diffuseSolarRad_(0.0),
267  groundReflectivity_(0.0),
268  A_(0.0),
269  B_(0.0),
270  beta_(0.0),
271  tetha_(0.0),
272  Setrn_(0.0),
273  SunPrime_(0.0),
274  C_(readScalar(dict.lookup("C"))),
275  sunDirectionModel_
276  (
277  sunDirectionModelTypeNames_.read(dict.lookup("sunDirectionModel"))
278  ),
279  sunLoadModel_
280  (
281  sunLoadModelTypeNames_.read(dict.lookup("sunLoadModel"))
282  ),
283  coord_()
284 {
285  init();
286 }
287 
288 
289 
290 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
291 
293 {}
294 
295 
296 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
297 
299 {
300  switch (sunDirectionModel_)
301  {
302  case mSunDirConstant:
303  {
304 //Info << "now directSolarRad_ is " << directSolarRad_ << endl <<endl;
305  break;
306  }
307  case mSunDirTraking:
308  {
309  calculateBetaTetha();
310  calculateSunDirection();
311  directSolarRad_ = A_/exp(B_/sin(max(beta_, ROOTVSMALL)));
312 //Info << "A is " << A_<< endl;
313 //Info << "B is " << B_<< endl;
314 //Info << " dirTraking now directSolarRad_ is " << directSolarRad_ << endl <<endl;
315  break;
316  }
317  }
318 }
319 
320 
321 // ************************************************************************* //
Foam::solarCalculator::init
void init()
Init.
Definition: solarCalculator.C:173
Foam::solarCalculator::dict_
dictionary dict_
Dictionary.
Definition: solarCalculator.H:140
Foam::solarCalculator::sunDirectionModelTypeNames_
static const NamedEnum< sunDirModel, 2 > sunDirectionModelTypeNames_
Sun direction models.
Definition: solarCalculator.H:126
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::solarCalculator::mSunDirTraking
@ mSunDirTraking
Definition: solarCalculator.H:111
Foam::sin
dimensionedScalar sin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:255
Foam::solarCalculator::calculateBetaTetha
void calculateBetaTetha()
Calculate beta and tetha angles.
Definition: solarCalculator.C:68
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
unitConversion.H
Unit conversion functions.
Foam::solarCalculator::calculateSunDirection
void calculateSunDirection()
Calculate Sun direction.
Definition: solarCalculator.C:139
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:261
Foam::exp
dimensionedScalar exp(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:252
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::solarCalculator::sunLModel
sunLModel
Direct sun load models.
Definition: solarCalculator.H:115
Foam::solarCalculator::mesh_
const fvMesh & mesh_
Reference to mesh.
Definition: solarCalculator.H:137
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
delta
scalar delta
Definition: LISASMDCalcMethod2.H:8
Foam::solarCalculator::sunDirectionModel_
sunDirModel sunDirectionModel_
Sun direction model.
Definition: solarCalculator.H:170
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::solarCalculator::mSunDirConstant
@ mSunDirConstant
Definition: solarCalculator.H:110
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::solarCalculator::~solarCalculator
~solarCalculator()
Destructor.
Definition: solarCalculator.C:292
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::solarCalculator::correctSunDirection
void correctSunDirection()
Recalculate.
Definition: solarCalculator.C:298
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::tab
static const char tab
Definition: Ostream.H:259
Foam::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
Foam::solarCalculator::tetha_
scalar tetha_
Definition: solarCalculator.H:158
Foam::acos
dimensionedScalar acos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:259
M
#define M(I)
solarCalculator.H
Foam::solarCalculator::sunLoadModelTypeNames_
static const NamedEnum< sunLModel, 3 > sunLoadModelTypeNames_
Sun load models.
Definition: solarCalculator.H:129
Foam::radToDeg
scalar radToDeg(const scalar rad)
Conversion from radians to degrees.
Definition: unitConversion.H:51
Foam::constant::mathematical::pi
const scalar pi(M_PI)
Foam::solarCalculator::beta_
scalar beta_
Definition: solarCalculator.H:157
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
Foam::solarCalculator::startTime_
scalar startTime_
Start time for the Sun position (decimal hours)
Definition: solarCalculator.H:188
Foam::solarCalculator::solarCalculator
solarCalculator(const solarCalculator &)
Disallow default bitwise copy construct.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::solarCalculator::sunDirModel
sunDirModel
Sun direction models.
Definition: solarCalculator.H:108
Foam::asin
dimensionedScalar asin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:258
Foam::NamedEnum
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
Foam::coordinateSystem
Base class for other coordinate system specifications.
Definition: coordinateSystem.H:85
Foam::degToRad
scalar degToRad(const scalar deg)
Conversion from degrees to radians.
Definition: unitConversion.H:45
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:256