Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / lagrangian / intermediate / clouds / Templates / ReactingCloud / ReactingCloud.C
blob8d384b97bb7d938a1c2925e76a1057ca030c597f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2008-2011 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
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 "ReactingCloud.H"
28 #include "CompositionModel.H"
29 #include "PhaseChangeModel.H"
31 // * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * * //
33 template<class CloudType>
34 void Foam::ReactingCloud<CloudType>::setModels()
36     compositionModel_.reset
37     (
38         CompositionModel<ReactingCloud<CloudType> >::New
39         (
40             this->subModelProperties(),
41             *this
42         ).ptr()
43     );
45     phaseChangeModel_.reset
46     (
47         PhaseChangeModel<ReactingCloud<CloudType> >::New
48         (
49             this->subModelProperties(),
50             *this
51         ).ptr()
52     );
56 template<class CloudType>
57 void Foam::ReactingCloud<CloudType>::checkSuppliedComposition
59     const scalarField& YSupplied,
60     const scalarField& Y,
61     const word& YName
64     if (YSupplied.size() != Y.size())
65     {
66         FatalErrorIn
67         (
68             "ReactingCloud<CloudType>::checkSuppliedComposition"
69             "("
70                 "const scalarField&, "
71                 "const scalarField&, "
72                 "const word&"
73             ")"
74         )   << YName << " supplied, but size is not compatible with "
75             << "parcel composition: " << nl << "    "
76             << YName << "(" << YSupplied.size() << ") vs required composition "
77             << YName << "(" << Y.size() << ")" << nl
78             << abort(FatalError);
79     }
83 template<class CloudType>
84 void Foam::ReactingCloud<CloudType>::cloudReset(ReactingCloud<CloudType>& c)
86     CloudType::cloudReset(c);
88     compositionModel_.reset(c.compositionModel_.ptr());
89     phaseChangeModel_.reset(c.phaseChangeModel_.ptr());
91     dMassPhaseChange_ = c.dMassPhaseChange_;
95 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
97 template<class CloudType>
98 Foam::ReactingCloud<CloudType>::ReactingCloud
100     const word& cloudName,
101     const volScalarField& rho,
102     const volVectorField& U,
103     const dimensionedVector& g,
104     const SLGThermo& thermo,
105     bool readFields
108     CloudType(cloudName, rho, U, g, thermo, false),
109     reactingCloud(),
110     cloudCopyPtr_(NULL),
111     constProps_(this->particleProperties(), this->solution().active()),
112     compositionModel_(NULL),
113     phaseChangeModel_(NULL),
114     rhoTrans_(thermo.carrier().species().size()),
115     dMassPhaseChange_(0.0)
117     if (this->solution().active())
118     {
119         setModels();
121         if (readFields)
122         {
123             parcelType::readFields(*this, this->composition());
124         }
125     }
127     // Set storage for mass source fields and initialise to zero
128     forAll(rhoTrans_, i)
129     {
130         const word& specieName = thermo.carrier().species()[i];
131         rhoTrans_.set
132         (
133             i,
134             new DimensionedField<scalar, volMesh>
135             (
136                 IOobject
137                 (
138                     this->name() + "rhoTrans_" + specieName,
139                     this->db().time().timeName(),
140                     this->db(),
141                     IOobject::READ_IF_PRESENT,
142                     IOobject::AUTO_WRITE
143                 ),
144                 this->mesh(),
145                 dimensionedScalar("zero", dimMass, 0.0)
146             )
147         );
148     }
150     if (this->solution().resetSourcesOnStartup())
151     {
152         resetSourceTerms();
153     }
157 template<class CloudType>
158 Foam::ReactingCloud<CloudType>::ReactingCloud
160     ReactingCloud<CloudType>& c,
161     const word& name
164     CloudType(c, name),
165     reactingCloud(),
166     cloudCopyPtr_(NULL),
167     constProps_(c.constProps_),
168     compositionModel_(c.compositionModel_->clone()),
169     phaseChangeModel_(c.phaseChangeModel_->clone()),
170     rhoTrans_(c.rhoTrans_.size()),
171     dMassPhaseChange_(c.dMassPhaseChange_)
173     forAll(c.rhoTrans_, i)
174     {
175         const word& specieName = this->thermo().carrier().species()[i];
176         rhoTrans_.set
177         (
178             i,
179             new DimensionedField<scalar, volMesh>
180             (
181                 IOobject
182                 (
183                     this->name() + "rhoTrans_" + specieName,
184                     this->db().time().timeName(),
185                     this->db(),
186                     IOobject::NO_READ,
187                     IOobject::NO_WRITE,
188                     false
189                 ),
190                 c.rhoTrans_[i]
191             )
192         );
193     }
197 template<class CloudType>
198 Foam::ReactingCloud<CloudType>::ReactingCloud
200     const fvMesh& mesh,
201     const word& name,
202     const ReactingCloud<CloudType>& c
205     CloudType(mesh, name, c),
206     reactingCloud(),
207     cloudCopyPtr_(NULL),
208     constProps_(),
209     compositionModel_(c.compositionModel_->clone()),
210 //    compositionModel_(NULL),
211     phaseChangeModel_(NULL),
212     rhoTrans_(0),
213     dMassPhaseChange_(0.0)
217 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
219 template<class CloudType>
220 Foam::ReactingCloud<CloudType>::~ReactingCloud()
224 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
226 template<class CloudType>
227 void Foam::ReactingCloud<CloudType>::setParcelThermoProperties
229     parcelType& parcel,
230     const scalar lagrangianDt
233     CloudType::setParcelThermoProperties(parcel, lagrangianDt);
235     parcel.pc() = this->thermo().thermo().p()[parcel.cell()];
236     parcel.Y() = composition().YMixture0();
240 template<class CloudType>
241 void Foam::ReactingCloud<CloudType>::checkParcelProperties
243     parcelType& parcel,
244     const scalar lagrangianDt,
245     const bool fullyDescribed
248     CloudType::checkParcelProperties(parcel, lagrangianDt, fullyDescribed);
250     if (fullyDescribed)
251     {
252         checkSuppliedComposition
253         (
254             parcel.Y(),
255             composition().YMixture0(),
256             "YMixture"
257         );
258     }
260     // derived information - store initial mass
261     parcel.mass0() = parcel.mass();
265 template<class CloudType>
266 void Foam::ReactingCloud<CloudType>::storeState()
268     cloudCopyPtr_.reset
269     (
270         static_cast<ReactingCloud<CloudType>*>
271         (
272             clone(this->name() + "Copy").ptr()
273         )
274     );
278 template<class CloudType>
279 void Foam::ReactingCloud<CloudType>::restoreState()
281     cloudReset(cloudCopyPtr_());
282     cloudCopyPtr_.clear();
286 template<class CloudType>
287 void Foam::ReactingCloud<CloudType>::resetSourceTerms()
289     CloudType::resetSourceTerms();
290     forAll(rhoTrans_, i)
291     {
292         rhoTrans_[i].field() = 0.0;
293     }
297 template<class CloudType>
298 void Foam::ReactingCloud<CloudType>::relaxSources
300     const ReactingCloud<CloudType>& cloudOldTime
303     CloudType::relaxSources(cloudOldTime);
305     typedef DimensionedField<scalar, volMesh> dsfType;
307     forAll(rhoTrans_, fieldI)
308     {
309         dsfType& rhoT = rhoTrans_[fieldI];
310         const dsfType& rhoT0 = cloudOldTime.rhoTrans()[fieldI];
311         this->relax(rhoT, rhoT0, "rho");
312     }
316 template<class CloudType>
317 void Foam::ReactingCloud<CloudType>::scaleSources()
319     CloudType::scaleSources();
321     typedef DimensionedField<scalar, volMesh> dsfType;
323     forAll(rhoTrans_, fieldI)
324     {
325         dsfType& rhoT = rhoTrans_[fieldI];
326         this->scale(rhoT, "rho");
327     }
331 template<class CloudType>
332 void Foam::ReactingCloud<CloudType>::evolve()
334     if (this->solution().canEvolve())
335     {
336         typename parcelType::template
337             TrackingData<ReactingCloud<CloudType> > td(*this);
339         this->solve(td);
340     }
344 template<class CloudType>
345 void Foam::ReactingCloud<CloudType>::addToMassPhaseChange(const scalar dMass)
347     dMassPhaseChange_ += dMass;
351 template<class CloudType>
352 void Foam::ReactingCloud<CloudType>::info() const
354     CloudType::info();
356     Info<< "    Mass transfer phase change      = "
357         << returnReduce(dMassPhaseChange_, sumOp<scalar>()) << nl;
361 template<class CloudType>
362 void Foam::ReactingCloud<CloudType>::writeFields() const
364     if (this->size())
365     {
366         CloudType::particleType::writeFields(*this, this->composition());
367     }
371 // ************************************************************************* //