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