initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / lagrangian / intermediate / submodels / Kinematic / InjectionModel / PatchInjection / PatchInjection.C
blobb79a8a1af1052c65079478035175df424ae2e24b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2009-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "PatchInjection.H"
28 #include "DataEntry.H"
29 #include "pdf.H"
31 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
33 template<class CloudType>
34 Foam::label Foam::PatchInjection<CloudType>::parcelsToInject
36     const scalar time0,
37     const scalar time1
38 ) const
40     if ((time0 >= 0.0) && (time0 < duration_))
41     {
42         return round(fraction_*(time1 - time0)*parcelsPerSecond_);
43     }
44     else
45     {
46         return 0;
47     }
51 template<class CloudType>
52 Foam::scalar Foam::PatchInjection<CloudType>::volumeToInject
54     const scalar time0,
55     const scalar time1
56 ) const
58     if ((time0 >= 0.0) && (time0 < duration_))
59     {
60         return fraction_*volumeFlowRate_().integrate(time0, time1);
61     }
62     else
63     {
64         return 0.0;
65     }
69 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
71 template<class CloudType>
72 Foam::PatchInjection<CloudType>::PatchInjection
74     const dictionary& dict,
75     CloudType& owner
78     InjectionModel<CloudType>(dict, owner, typeName),
79     patchName_(this->coeffDict().lookup("patchName")),
80     duration_(readScalar(this->coeffDict().lookup("duration"))),
81     parcelsPerSecond_
82     (
83         readScalar(this->coeffDict().lookup("parcelsPerSecond"))
84     ),
85     U0_(this->coeffDict().lookup("U0")),
86     volumeFlowRate_
87     (
88         DataEntry<scalar>::New
89         (
90             "volumeFlowRate",
91             this->coeffDict()
92         )
93     ),
94     parcelPDF_
95     (
96         pdf::New
97         (
98             this->coeffDict().subDict("parcelPDF"),
99             owner.rndGen()
100         )
101     ),
102     cellOwners_(),
103     fraction_(1.0)
105     label patchId = owner.mesh().boundaryMesh().findPatchID(patchName_);
107     if (patchId < 0)
108     {
109         FatalErrorIn
110         (
111             "PatchInjection<CloudType>::PatchInjection"
112             "("
113                 "const dictionary&, "
114                 "CloudType&"
115             ")"
116         )   << "Requested patch " << patchName_ << " not found" << nl
117             << "Available patches are: " << owner.mesh().boundaryMesh().names()
118             << nl << exit(FatalError);
119     }
121     const polyPatch& patch = owner.mesh().boundaryMesh()[patchId];
123     cellOwners_ = patch.faceCells();
125     label patchSize = cellOwners_.size();
126     label totalPatchSize = patchSize;
127     reduce(totalPatchSize, sumOp<scalar>());
128     fraction_ = patchSize/totalPatchSize;
130     // Set total volume to inject
131     this->volumeTotal_ = fraction_*volumeFlowRate_().integrate(0.0, duration_);
135 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
137 template<class CloudType>
138 Foam::PatchInjection<CloudType>::~PatchInjection()
142 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
144 template<class CloudType>
145 bool Foam::PatchInjection<CloudType>::active() const
147     return true;
151 template<class CloudType>
152 Foam::scalar Foam::PatchInjection<CloudType>::timeEnd() const
154     return this->SOI_ + duration_;
158 template<class CloudType>
159 void Foam::PatchInjection<CloudType>::setPositionAndCell
161     const label,
162     const label,
163     const scalar,
164     vector& position,
165     label& cellOwner
168     label cellI = this->owner().rndGen().integer(0, cellOwners_.size() - 1);
170     cellOwner = cellOwners_[cellI];
171     position = this->owner().mesh().C()[cellOwner];
175 template<class CloudType>
176 void Foam::PatchInjection<CloudType>::setProperties
178     const label,
179     const label,
180     const scalar,
181     typename CloudType::parcelType& parcel
184     // set particle velocity
185     parcel.U() = U0_;
187     // set particle diameter
188     parcel.d() = parcelPDF_->sample();
192 template<class CloudType>
193 bool Foam::PatchInjection<CloudType>::fullyDescribed() const
195     return false;
199 template<class CloudType>
200 bool Foam::PatchInjection<CloudType>::validInjection(const label)
202     return true;
206 // ************************************************************************* //