ManualInjection.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2015-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "ManualInjection.H"
30 #include "mathematicalConstants.H"
31 #include "bitSet.H"
32 
33 using namespace Foam::constant::mathematical;
34 
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 
37 template<class CloudType>
39 (
40  const dictionary& dict,
41  CloudType& owner,
42  const word& modelName
43 )
44 :
45  InjectionModel<CloudType>(dict, owner, modelName, typeName),
46  positionsFile_(this->coeffDict().lookup("positionsFile")),
47  positions_
48  (
49  IOobject
50  (
51  positionsFile_,
52  owner.db().time().constant(),
53  owner.mesh(),
56  )
57  ),
58  diameters_(positions_.size()),
59  injectorCells_(positions_.size(), -1),
60  injectorTetFaces_(positions_.size(), -1),
61  injectorTetPts_(positions_.size(), -1),
62  U0_(this->coeffDict().lookup("U0")),
63  sizeDistribution_
64  (
66  (
67  this->coeffDict().subDict("sizeDistribution"),
68  owner.rndGen()
69  )
70  ),
71  ignoreOutOfBounds_
72  (
73  this->coeffDict().getOrDefault("ignoreOutOfBounds", false)
74  )
75 {
76  updateMesh();
77 
78  // Construct parcel diameters
79  forAll(diameters_, i)
80  {
81  diameters_[i] = sizeDistribution_->sample();
82  }
83 
84  // Determine volume of particles to inject
85  this->volumeTotal_ = sum(pow3(diameters_))*pi/6.0;
86 }
87 
88 
89 template<class CloudType>
91 (
93 )
94 :
96  positionsFile_(im.positionsFile_),
97  positions_(im.positions_),
98  diameters_(im.diameters_),
99  injectorCells_(im.injectorCells_),
100  injectorTetFaces_(im.injectorTetFaces_),
101  injectorTetPts_(im.injectorTetPts_),
102  U0_(im.U0_),
103  sizeDistribution_(im.sizeDistribution_.clone()),
104  ignoreOutOfBounds_(im.ignoreOutOfBounds_)
105 {}
106 
107 
108 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
109 
110 template<class CloudType>
112 {}
113 
114 
115 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
116 
117 template<class CloudType>
119 {
120  label nRejected = 0;
121 
122  bitSet keep(positions_.size(), true);
123 
124  forAll(positions_, pI)
125  {
126  if
127  (
128  !this->findCellAtPosition
129  (
130  injectorCells_[pI],
131  injectorTetFaces_[pI],
132  injectorTetPts_[pI],
133  positions_[pI],
134  !ignoreOutOfBounds_
135  )
136  )
137  {
138  keep.unset(pI);
139  nRejected++;
140  }
141  }
142 
143  if (nRejected > 0)
144  {
145  inplaceSubset(keep, positions_);
146  inplaceSubset(keep, diameters_);
147  inplaceSubset(keep, injectorCells_);
148  inplaceSubset(keep, injectorTetFaces_);
149  inplaceSubset(keep, injectorTetPts_);
150 
151  Info<< " " << nRejected
152  << " particles ignored, out of bounds" << endl;
153  }
154 }
155 
156 
157 template<class CloudType>
159 {
160  // Injection is instantaneous - but allow for a finite interval to
161  // avoid numerical issues when interval is zero
162  return ROOTVSMALL;
163 }
164 
165 
166 template<class CloudType>
168 (
169  const scalar time0,
170  const scalar time1
171 )
172 {
173  if ((0.0 >= time0) && (0.0 < time1))
174  {
175  return positions_.size();
176  }
177 
178  return 0;
179 }
180 
181 
182 template<class CloudType>
184 (
185  const scalar time0,
186  const scalar time1
187 )
188 {
189  // All parcels introduced at SOI
190  if ((0.0 >= time0) && (0.0 < time1))
191  {
192  return this->volumeTotal_;
193  }
194 
195  return 0.0;
196 }
197 
198 
199 template<class CloudType>
201 (
202  const label parcelI,
203  const label,
204  const scalar,
205  vector& position,
206  label& cellOwner,
207  label& tetFacei,
208  label& tetPti
209 )
210 {
211  position = positions_[parcelI];
212  cellOwner = injectorCells_[parcelI];
213  tetFacei = injectorTetFaces_[parcelI];
214  tetPti = injectorTetPts_[parcelI];
215 }
216 
217 
218 template<class CloudType>
220 (
221  const label parcelI,
222  const label,
223  const scalar,
224  typename CloudType::parcelType& parcel
225 )
226 {
227  // set particle velocity
228  parcel.U() = U0_;
229 
230  // set particle diameter
231  parcel.d() = diameters_[parcelI];
232 }
233 
234 
235 template<class CloudType>
237 {
238  return false;
239 }
240 
241 
242 template<class CloudType>
244 {
245  return true;
246 }
247 
248 
249 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
mathematicalConstants.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::ManualInjection::updateMesh
virtual void updateMesh()
Set injector locations when mesh is updated.
Definition: ManualInjection.C:118
Foam::ManualInjection::setProperties
virtual void setProperties(const label parcelI, const label nParcels, const scalar time, typename CloudType::parcelType &parcel)
Set the parcel properties.
Definition: ManualInjection.C:220
Foam::ManualInjection::validInjection
virtual bool validInjection(const label parcelI)
Return flag to identify whether or not injection of parcelI is.
Definition: ManualInjection.C:243
Foam::InjectionModel
Templated injection model class.
Definition: InjectionModel.H:73
Foam::ManualInjection::parcelsToInject
virtual label parcelsToInject(const scalar time0, const scalar time1)
Number of parcels to introduce relative to SOI.
Definition: ManualInjection.C:168
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
bitSet.H
Foam::DSMCCloud::rndGen
Random & rndGen()
Return reference to the random object.
Definition: DSMCCloudI.H:124
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::ManualInjection
Manual injection.
Definition: ManualInjection.H:66
Foam::ManualInjection::fullyDescribed
virtual bool fullyDescribed() const
Flag to identify whether model fully describes the parcel.
Definition: ManualInjection.C:236
Foam::pow3
dimensionedScalar pow3(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:89
Foam::DSMCCloud::mesh
const fvMesh & mesh() const
Return reference to the mesh.
Definition: DSMCCloudI.H:44
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::ManualInjection::volumeToInject
virtual scalar volumeToInject(const scalar time0, const scalar time1)
Volume of parcels to introduce relative to SOI.
Definition: ManualInjection.C:184
Foam::radiation::lookup
Lookup type of boundary radiation properties.
Definition: lookup.H:63
Foam::DSMCCloud
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:71
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::inplaceSubset
void inplaceSubset(const BoolListType &select, ListType &input, const bool invert=false)
Inplace extract elements of the input list when select is true.
Definition: ListOpsTemplates.C:583
Foam::ManualInjection::setPositionAndCell
virtual void setPositionAndCell(const label parcelI, const label nParcels, const scalar time, vector &position, label &cellOwner, label &tetFacei, label &tetPti)
Set the injection position and owner cell, tetFace and tetPt.
Definition: ManualInjection.C:201
Foam::distributionModel::New
static autoPtr< distributionModel > New(const dictionary &dict, Random &rndGen)
Selector.
Definition: distributionModelNew.C:34
Foam::constant::mathematical
Mathematical constants.
Foam::constant::mathematical::pi
constexpr scalar pi(M_PI)
Foam::Vector< scalar >
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:327
Foam::ManualInjection::timeEnd
scalar timeEnd() const
Return the end-of-injection time.
Definition: ManualInjection.C:158
Foam::DSMCCloud::parcelType
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:220
ManualInjection.H
Foam::ManualInjection::ManualInjection
ManualInjection(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
Definition: ManualInjection.C:39
Foam::ManualInjection::~ManualInjection
virtual ~ManualInjection()
Destructor.
Definition: ManualInjection.C:111
Foam::IOobject::MUST_READ
Definition: IOobject.H:185