Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / lagrangian / intermediate / submodels / Kinematic / InjectionModel / ConeInjection / ConeInjection.C
blob70b0687feb11794ab03960c3633b95e964e548b6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "ConeInjection.H"
27 #include "DataEntry.H"
28 #include "mathematicalConstants.H"
30 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
32 template<class CloudType>
33 Foam::label Foam::ConeInjection<CloudType>::parcelsToInject
35     const scalar time0,
36     const scalar time1
37 ) const
39     if ((time0 >= 0.0) && (time0 < duration_))
40     {
41         return round((time1 - time0)*parcelsPerSecond_);
42     }
43     else
44     {
45         return 0;
46     }
50 template<class CloudType>
51 Foam::scalar Foam::ConeInjection<CloudType>::volumeToInject
53     const scalar time0,
54     const scalar time1
55 ) const
57     if ((time0 >= 0.0) && (time0 < duration_))
58     {
59         return volumeFlowRate_().integrate(time0, time1);
60     }
61     else
62     {
63         return 0.0;
64     }
68 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
70 template<class CloudType>
71 Foam::ConeInjection<CloudType>::ConeInjection
73     const dictionary& dict,
74     CloudType& owner
77     InjectionModel<CloudType>(dict, owner, typeName),
78     duration_(readScalar(this->coeffDict().lookup("duration"))),
79     position_(this->coeffDict().lookup("position")),
80     injectorCell_(-1),
81     direction_(this->coeffDict().lookup("direction")),
82     parcelsPerSecond_
83     (
84         readScalar(this->coeffDict().lookup("parcelsPerSecond"))
85     ),
86     volumeFlowRate_
87     (
88         DataEntry<scalar>::New
89         (
90             "volumeFlowRate",
91             this->coeffDict()
92         )
93     ),
94     Umag_
95     (
96         DataEntry<scalar>::New
97         (
98             "Umag",
99             this->coeffDict()
100         )
101     ),
102     thetaInner_
103     (
104         DataEntry<scalar>::New
105         (
106             "thetaInner",
107             this->coeffDict()
108         )
109     ),
110     thetaOuter_
111     (
112         DataEntry<scalar>::New
113         (
114             "thetaOuter",
115             this->coeffDict()
116         )
117     ),
118     parcelPDF_
119     (
120         pdf::New
121         (
122             this->coeffDict().subDict("parcelPDF"),
123             owner.rndGen()
124         )
125     ),
126     tanVec1_(vector::zero),
127     tanVec2_(vector::zero)
129     // Normalise direction vector
130     direction_ /= mag(direction_);
132     // Determine direction vectors tangential to direction
133     vector tangent = vector::zero;
134     scalar magTangent = 0.0;
136     while (magTangent < SMALL)
137     {
138         vector v = this->owner().rndGen().vector01();
140         tangent = v - (v & direction_)*direction_;
141         magTangent = mag(tangent);
142     }
144     tanVec1_ = tangent/magTangent;
145     tanVec2_ = direction_^tanVec1_;
147     // Set total volume to inject
148     this->volumeTotal_ = volumeFlowRate_().integrate(0.0, duration_);
150     // Set/cache the injector cell
151     this->findCellAtPosition(injectorCell_, position_);
155 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
157 template<class CloudType>
158 Foam::ConeInjection<CloudType>::~ConeInjection()
162 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
164 template<class CloudType>
165 bool Foam::ConeInjection<CloudType>::active() const
167     return true;
171 template<class CloudType>
172 Foam::scalar Foam::ConeInjection<CloudType>::timeEnd() const
174     return this->SOI_ + duration_;
178 template<class CloudType>
179 void Foam::ConeInjection<CloudType>::setPositionAndCell
181     const label,
182     const label,
183     const scalar,
184     vector& position,
185     label& cellOwner
188     position = position_;
189     cellOwner = injectorCell_;
193 template<class CloudType>
194 void Foam::ConeInjection<CloudType>::setProperties
196     const label parcelI,
197     const label,
198     const scalar time,
199     typename CloudType::parcelType& parcel
202     // set particle velocity
203     const scalar deg2Rad = mathematicalConstant::pi/180.0;
205     scalar t = time - this->SOI_;
206     scalar ti = thetaInner_().value(t);
207     scalar to = thetaOuter_().value(t);
208     scalar coneAngle = this->owner().rndGen().scalar01()*(to - ti) + ti;
210     coneAngle *= deg2Rad;
211     scalar alpha = sin(coneAngle);
212     scalar dcorr = cos(coneAngle);
213     scalar beta = mathematicalConstant::twoPi*this->owner().rndGen().scalar01();
215     vector normal = alpha*(tanVec1_*cos(beta) + tanVec2_*sin(beta));
216     vector dirVec = dcorr*direction_;
217     dirVec += normal;
218     dirVec /= mag(dirVec);
220     parcel.U() = Umag_().value(t)*dirVec;
222     // set particle diameter
223     parcel.d() = parcelPDF_().sample();
227 template<class CloudType>
228 bool Foam::ConeInjection<CloudType>::fullyDescribed() const
230     return false;
234 template<class CloudType>
235 bool Foam::ConeInjection<CloudType>::validInjection(const label)
237     return true;
241 // ************************************************************************* //