FreeFOAM The Cross-Platform CFD Toolkit
FieldActivatedInjection.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) 2008-2010 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 
27 #include <finiteVolume/volFields.H>
29 
30 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
31 
32 template<class CloudType>
34 (
35  const scalar time0,
36  const scalar time1
37 ) const
38 {
39  if (sum(nParcelsInjected_) < nParcelsPerInjector_*positions_.size())
40  {
41  return positions_.size();
42  }
43  else
44  {
45  return 0;
46  }
47 }
48 
49 
50 template<class CloudType>
52 (
53  const scalar time0,
54  const scalar time1
55 ) const
56 {
57  if (sum(nParcelsInjected_) < nParcelsPerInjector_*positions_.size())
58  {
59  return this->volumeTotal_/nParcelsPerInjector_;
60  }
61  else
62  {
63  return 0;
64  }
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
69 
70 template<class CloudType>
72 (
73  const dictionary& dict,
74  CloudType& owner
75 )
76 :
77  InjectionModel<CloudType>(dict, owner, typeName),
78  factor_(readScalar(this->coeffDict().lookup("factor"))),
79  referenceField_
80  (
81  owner.db().objectRegistry::lookupObject<volScalarField>
82  (
83  this->coeffDict().lookup("referenceField")
84  )
85  ),
86  thresholdField_
87  (
88  owner.db().objectRegistry::lookupObject<volScalarField>
89  (
90  this->coeffDict().lookup("thresholdField")
91  )
92  ),
93  positionsFile_(this->coeffDict().lookup("positionsFile")),
94  positions_
95  (
96  IOobject
97  (
98  positionsFile_,
99  owner.db().time().constant(),
100  owner.mesh(),
101  IOobject::MUST_READ,
102  IOobject::NO_WRITE
103  )
104  ),
105  injectorCells_(positions_.size()),
106  nParcelsPerInjector_
107  (
108  readLabel(this->coeffDict().lookup("parcelsPerInjector"))
109  ),
110  nParcelsInjected_(positions_.size(), 0),
111  U0_(this->coeffDict().lookup("U0")),
112  diameters_(positions_.size()),
113  parcelPDF_
114  (
115  pdfs::pdf::New
116  (
117  this->coeffDict().subDict("parcelPDF"),
118  owner.rndGen()
119  )
120  )
121 {
122  // Construct parcel diameters - one per injector cell
123  forAll(diameters_, i)
124  {
125  diameters_[i] = parcelPDF_->sample();
126  }
127 
128  // Determine total volume of particles to inject
129  this->volumeTotal_ =
130  nParcelsPerInjector_*sum(pow3(diameters_))*mathematicalConstant::pi/6.0;
131 
132  // Set/cache the injector cells
133  forAll(positions_, i)
134  {
135  this->findCellAtPosition
136  (
137  injectorCells_[i],
138  positions_[i]
139  );
140  }
141 }
142 
143 
144 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
145 
146 template<class CloudType>
148 {}
149 
150 
151 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
152 
153 template<class CloudType>
155 {
156  return true;
157 }
158 
159 
160 template<class CloudType>
162 {
163  return GREAT;
164 }
165 
166 
167 template<class CloudType>
169 (
170  const label parcelI,
171  const label,
172  const scalar,
173  vector& position,
174  label& cellOwner
175 )
176 {
177  position = positions_[parcelI];
178  cellOwner = injectorCells_[parcelI];
179 }
180 
181 
182 template<class CloudType>
184 (
185  const label parcelI,
186  const label,
187  const scalar,
188  typename CloudType::parcelType& parcel
189 )
190 {
191  // set particle velocity
192  parcel.U() = U0_;
193 
194  // set particle diameter
195  parcel.d() = diameters_[parcelI];
196 }
197 
198 
199 template<class CloudType>
201 {
202  return false;
203 }
204 
205 
206 template<class CloudType>
208 (
209  const label parcelI
210 )
211 {
212  const label cellI = injectorCells_[parcelI];
213 
214  if
215  (
216  nParcelsInjected_[parcelI] < nParcelsPerInjector_
217  && factor_*referenceField_[cellI] > thresholdField_[cellI]
218  )
219  {
220  nParcelsInjected_[parcelI]++;
221  return true;
222  }
223 
224  return false;
225 }
226 
227 
228 // ************************ vim: set sw=4 sts=4 et: ************************ //