Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / lagrangian / intermediate / clouds / Templates / CollidingCloud / CollidingCloud.C
blob6554dda83b266f1a4b52b836dfb9e6cae953a818
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011-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 "CollidingCloud.H"
27 #include "CollisionModel.H"
29 // * * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * //
31 template<class CloudType>
32 void Foam::CollidingCloud<CloudType>::setModels()
34     collisionModel_.reset
35     (
36         CollisionModel<CollidingCloud<CloudType> >::New
37         (
38             this->subModelProperties(),
39             *this
40         ).ptr()
41     );
45 template<class CloudType>
46 template<class TrackData>
47 void  Foam::CollidingCloud<CloudType>::moveCollide
49     TrackData& td,
50     const scalar deltaT
53     td.part() = TrackData::tpVelocityHalfStep;
54     CloudType::move(td,  deltaT);
56     td.part() = TrackData::tpLinearTrack;
57     CloudType::move(td,  deltaT);
59     // td.part() = TrackData::tpRotationalTrack;
60     // CloudType::move(td);
62     this->updateCellOccupancy();
64     this->collision().collide();
66     td.part() = TrackData::tpVelocityHalfStep;
67     CloudType::move(td,  deltaT);
72 template<class CloudType>
73 void Foam::CollidingCloud<CloudType>::cloudReset(CollidingCloud<CloudType>& c)
75     CloudType::cloudReset(c);
77     collisionModel_.reset(c.collisionModel_.ptr());
81 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
83 template<class CloudType>
84 Foam::CollidingCloud<CloudType>::CollidingCloud
86     const word& cloudName,
87     const volScalarField& rho,
88     const volVectorField& U,
89     const volScalarField& mu,
90     const dimensionedVector& g,
91     bool readFields
94     CloudType(cloudName, rho, U, mu, g, false),
95     collisionModel_(NULL)
97     if (this->solution().steadyState())
98     {
99         FatalErrorIn
100         (
101             "Foam::CollidingCloud<CloudType>::CollidingCloud"
102             "("
103                 "const word&, "
104                 "const volScalarField&, "
105                 "const volVectorField&, "
106                 "const volScalarField&, "
107                 "const dimensionedVector&, "
108                 "bool"
109             ")"
110         )   << "Collision modelling not currently available for steady state "
111             << "calculations" << exit(FatalError);
112     }
114     if (this->solution().active())
115     {
116         setModels();
118         if (readFields)
119         {
120             parcelType::readFields(*this);
121         }
122     }
126 template<class CloudType>
127 Foam::CollidingCloud<CloudType>::CollidingCloud
129     CollidingCloud<CloudType>& c,
130     const word& name
133     CloudType(c, name),
134     collisionModel_(c.collisionModel_->clone())
138 template<class CloudType>
139 Foam::CollidingCloud<CloudType>::CollidingCloud
141     const fvMesh& mesh,
142     const word& name,
143     const CollidingCloud<CloudType>& c
146     CloudType(mesh, name, c),
147     collisionModel_(NULL)
151 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
153 template<class CloudType>
154 Foam::CollidingCloud<CloudType>::~CollidingCloud()
158 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
160 template<class CloudType>
161 bool Foam::CollidingCloud<CloudType>::hasWallImpactDistance() const
163     return !collision().controlsWallInteraction();
167 template<class CloudType>
168 void Foam::CollidingCloud<CloudType>::storeState()
170     cloudCopyPtr_.reset
171     (
172         static_cast<CollidingCloud<CloudType>*>
173         (
174             clone(this->name() + "Copy").ptr()
175         )
176     );
180 template<class CloudType>
181 void Foam::CollidingCloud<CloudType>::restoreState()
183     cloudReset(cloudCopyPtr_());
184     cloudCopyPtr_.clear();
188 template<class CloudType>
189 void Foam::CollidingCloud<CloudType>::evolve()
191     if (this->solution().canEvolve())
192     {
193         typename parcelType::template
194             TrackingData<CollidingCloud<CloudType> > td(*this);
196         this->solve(td);
197     }
201 template<class CloudType>
202 template<class TrackData>
203 void  Foam::CollidingCloud<CloudType>::motion(TrackData& td)
205     // Sympletic leapfrog integration of particle forces:
206     // + apply half deltaV with stored force
207     // + move positions with new velocity
208     // + calculate forces in new position
209     // + apply half deltaV with new force
211     label nSubCycles = collision().nSubCycles();
213     if (nSubCycles > 1)
214     {
215         Info<< "    " << nSubCycles << " move-collide subCycles" << endl;
217         subCycleTime moveCollideSubCycle
218         (
219             const_cast<Time&>(this->db().time()),
220             nSubCycles
221         );
223         while(!(++moveCollideSubCycle).end())
224         {
225             moveCollide(td, this->db().time().deltaTValue());
226         }
228         moveCollideSubCycle.endSubCycle();
229     }
230     else
231     {
232         moveCollide(td, this->db().time().deltaTValue());
233     }
237 // ************************************************************************* //