initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / lagrangian / dieselSpray / spray / spray.C
blob3280fefdc93939812cb05681d24f480510b66fdf
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-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 "spray.H"
29 #include "atomizationModel.H"
30 #include "breakupModel.H"
31 #include "collisionModel.H"
32 #include "dispersionModel.H"
33 #include "dragModel.H"
34 #include "evaporationModel.H"
35 #include "heatTransferModel.H"
36 #include "injectorModel.H"
37 #include "wallModel.H"
39 #include "basicMultiComponentMixture.H"
41 #include "symmetryPolyPatch.H"
42 #include "wedgePolyPatch.H"
44 #include "mathematicalConstants.H"
46 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
48 defineTemplateTypeNameAndDebug(IOPtrList<injector>, 0);
50 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
52 // Construct from components
53 Foam::spray::spray
55     const volVectorField& U,
56     const volScalarField& rho,
57     const volScalarField& p,
58     const volScalarField& T,
59     const basicMultiComponentMixture& composition,
60     const PtrList<gasThermoPhysics>& gasProperties,
61     const dictionary&,
62     const dimensionedVector& g
65     Cloud<parcel>(U.mesh(), false), // suppress className checking on positions
66     runTime_(U.time()),
67     time0_(runTime_.value()),
68     mesh_(U.mesh()),
69     rndGen_(label(0)),
70     g_(g.value()),
72     U_(U),
73     rho_(rho),
74     p_(p),
75     T_(T),
77     sprayProperties_
78     (
79         IOobject
80         (
81             "sprayProperties",
82             U.time().constant(),
83             U.db(),
84             IOobject::MUST_READ,
85             IOobject::NO_WRITE
86         )
87     ),
89     ambientPressure_(p_.average().value()),
90     ambientTemperature_(T_.average().value()),
92     injectors_
93     (
94         IOobject
95         (
96             "injectorProperties",
97             U.time().constant(),
98             U.db(),
99             IOobject::MUST_READ,
100             IOobject::NO_WRITE
101         ),
102         injector::iNew(U.time())
103     ),
104     atomization_
105     (
106         atomizationModel::New
107         (
108             sprayProperties_,
109             *this
110         )
111     ),
112     drag_
113     (
114         dragModel::New
115         (
116             sprayProperties_
117         )
118     ),
119     evaporation_
120     (
121         evaporationModel::New
122         (
123             sprayProperties_
124         )
125     ),
126     heatTransfer_
127     (
128         heatTransferModel::New
129         (
130             sprayProperties_
131         )
132     ),
133     wall_
134     (
135         wallModel::New
136         (
137             sprayProperties_,
138             U,
139             *this
140         )
141     ),
142     breakupModel_
143     (
144         breakupModel::New
145         (
146             sprayProperties_,
147             *this
148         )
149     ),
150     collisionModel_
151     (
152         collisionModel::New
153         (
154             sprayProperties_,
155             *this,
156             rndGen_
157         )
158     ),
159     dispersionModel_
160     (
161         dispersionModel::New
162         (
163             sprayProperties_,
164             *this
165         )
166     ),
168     fuels_
169     (
170         liquidMixture::New
171         (
172             mesh_.lookupObject<dictionary>("thermophysicalProperties")
173         )
174     ),
175     injectorModel_
176     (
177         injectorModel::New
178         (
179             sprayProperties_,
180             *this
181         )
182     ),
184     subCycles_(readLabel(sprayProperties_.lookup("subCycles"))),
186     gasProperties_(gasProperties),
187     composition_(composition),
189     liquidToGasIndex_(fuels_->components().size(), -1),
190     gasToLiquidIndex_(composition.Y().size(), -1),
191     isLiquidFuel_(composition.Y().size(), false),
193     twoD_(0),
194     axisOfSymmetry_(vector::zero),
195     axisOfWedge_(vector(0,0,0)),
196     axisOfWedgeNormal_(vector(0,0,0)),
197     angleOfWedge_(0.0),
199     interpolationSchemes_(sprayProperties_.subDict("interpolationSchemes")),
200     UInterpolator_(NULL),
201     rhoInterpolator_(NULL),
202     pInterpolator_(NULL),
203     TInterpolator_(NULL),
205     sms_(mesh_.nCells(), vector::zero),
206     shs_(mesh_.nCells(), 0.0),
207     srhos_(fuels_->components().size()),
209     totalInjectedLiquidMass_(0.0),
210     injectedLiquidKE_(0.0)
213     // create the evaporation source fields
214     forAll(srhos_, i)
215     {
216         srhos_.set(i, new scalarField(mesh_.nCells(), 0.0));
217     }
219     // Write some information about injection parameters
220     forAll(injectors_, i)
221     {
222         const injectorType& it = injectors_[i].properties();
224         scalar v = injection().averageVelocity(i);
226         scalar ip = it.integrateTable(it.injectionPressureProfile());
227         scalar dt = it.teoi() - it.tsoi();
228         Info<< "Average Velocity for injector " << i << ": " << v << " m/s"
229             << ", injection pressure = "
230             << 1.0e-5*ip/dt << " bar"
231             << endl;
232     }
234     // Check if the case is 2D wedge
235     const polyBoundaryMesh& bMesh = mesh().boundaryMesh();
236     bool symPlaneExist = false;
237     bool wedgeExist = false;
238     label patches[2];
239     label n=0;
241     // check for the type of boundary condition
242     forAll(bMesh, patchi)
243     {
244         if (isType<symmetryPolyPatch>(bMesh[patchi]))
245         {
246             symPlaneExist = true;
247         }
248         else if (isType<wedgePolyPatch>(bMesh[patchi]))
249         {
250             wedgeExist = true;
251             patches[n++] = patchi;
252         }
253     }
255     // if wedge exist we assume that this is a 2D run.
256     twoD_ = wedgeExist;
258     if (twoD_)
259     {
260         if (n<2)
261         {
262             FatalErrorIn
263             (
264                 "spray::spray(const volVectorField& U, "
265                 "const volScalarField& rho, const volScalarField& p, "
266                 "const volScalarField& T, const combustionMixture& composition,"
267                 "const PtrList<gasThermoPhsyics>& gaseousFuelProperties, "
268                 "const dictionary& thermophysicalProperties, "
269                 "const dimensionedScalar& g)"
270             )   << "spray::(...) only one wedgePolyPatch found. "
271                    "Please check you BC-setup."
272                 << abort(FatalError);
273         }
275         Info<< "Constructing two dimensional spray injection.";
277         vector v1 = bMesh[patches[0]].faceAreas()[0];
278         vector v2 = bMesh[patches[1]].faceAreas()[0];
279         v1 /= mag(v1);
280         v2 /= mag(v2);
281         axisOfSymmetry_ = v1 ^ v2;
282         axisOfSymmetry_ /= mag(axisOfSymmetry_);
284         // assuming that 'v2' is the 'front' face
285         axisOfWedge_ = axisOfSymmetry_ ^ v2;
286         axisOfWedge_ /= mag(axisOfWedge_);
288         axisOfWedgeNormal_ = axisOfSymmetry_ ^ axisOfWedge_;
289         axisOfWedgeNormal_ /= mag(axisOfWedgeNormal_);
291         scalar arcCos = (v1 & v2)/mag(v1);
292         angleOfWedge_ = mathematicalConstant::pi - acos(arcCos);
294         Info<< "Calculated angle of wedge is "
295             << angleOfWedge_*180/mathematicalConstant::pi << " deg."
296             << endl;
297     }
298     else
299     {
300         if (symPlaneExist)
301         {
302             angleOfWedge_ = mathematicalConstant::pi;
303             Info<< "Constructing 180 deg three dimensional spray injection."
304                 << endl;
305         }
306         else
307         {
308             Info<< "Constructing three dimensional spray injection." << endl;
309         }
311     }
313     // find index mapping between liquid indeces and gas indeces
314     label Ns = composition_.Y().size();
316     forAll(fuels_->components(), i)
317     {
318         word liquidName(fuels_->components()[i]);
320         for (label j=0; j<Ns; j++)
321         {
322             word specieName(composition_.Y()[j].name());
324             if (specieName == liquidName)
325             {
326                 liquidToGasIndex_[i] = j;
327                 gasToLiquidIndex_[j] = i;
328                 isLiquidFuel_[j] = true;
329             }
330         }
331         if (liquidToGasIndex_[i] == -1)
332         {
333             Info << "In composition:" << endl;
334             for (label k=0; k<Ns; k++)
335             {
336                 word specieName(composition_.Y()[k].name());
337                 Info << specieName << endl;
338             }
340             FatalError<<
341                 "The liquid component " << liquidName
342                 << " does not exist in the species composition.Y() list.\n"
343                 << "(Probably not defined in <chem.inp>)"
344                 << abort(FatalError);
345         }
346     }
348     parcel::readFields(*this);
352 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
354 Foam::spray::~spray()
358 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
360 void Foam::spray::writeFields() const
362     parcel::writeFields(*this);
366 // ************************************************************************* //