ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / lagrangian / intermediate / submodels / Kinematic / PatchInteractionModel / StandardWallInteraction / StandardWallInteraction.C
blob7443c2fcc2b870f0c98c68e433f6fccee1b76f28
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 "StandardWallInteraction.H"
28 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
30 template<class CloudType>
31 void Foam::StandardWallInteraction<CloudType>::readProps()
33     if (!this->owner().solution().transient())
34     {
35         return;
36     }
38     IOobject propsDictHeader
39     (
40         "standardWallInteractionProperties",
41         this->owner().db().time().timeName(),
42         "uniform"/cloud::prefix/this->owner().name(),
43         this->owner().db(),
44         IOobject::MUST_READ_IF_MODIFIED,
45         IOobject::NO_WRITE,
46         false
47     );
49     if (propsDictHeader.headerOk())
50     {
51         const IOdictionary propsDict(propsDictHeader);
52         propsDict.readIfPresent("nEscape", nEscape0_);
53         propsDict.readIfPresent("massEscape", massEscape0_);
54         propsDict.readIfPresent("nStick", nStick0_);
55         propsDict.readIfPresent("massStick", massStick0_);
56     }
60 template<class CloudType>
61 void Foam::StandardWallInteraction<CloudType>::writeProps
63     const label nEscape,
64     const scalar massEscape,
65     const label nStick,
66     const scalar massStick
67 ) const
69     if (!this->owner().solution().transient())
70     {
71         return;
72     }
74     if (this->owner().db().time().outputTime())
75     {
76         IOdictionary propsDict
77         (
78             IOobject
79             (
80                 "standardWallInteractionProperties",
81                 this->owner().db().time().timeName(),
82                 "uniform"/cloud::prefix/this->owner().name(),
83                 this->owner().db(),
84                 IOobject::NO_READ,
85                 IOobject::NO_WRITE,
86                 false
87             )
88         );
90         propsDict.add("nEscape", nEscape);
91         propsDict.add("massEscape", massEscape);
92         propsDict.add("nStick", nStick);
93         propsDict.add("massStick", massStick);
95         propsDict.writeObject
96         (
97             IOstream::ASCII,
98             IOstream::currentVersion,
99             this->owner().db().time().writeCompression()
100         );
101     }
105 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
107 template<class CloudType>
108 Foam::StandardWallInteraction<CloudType>::StandardWallInteraction
110     const dictionary& dict,
111     CloudType& cloud
114     PatchInteractionModel<CloudType>(dict, cloud, typeName),
115     interactionType_
116     (
117         this->wordToInteractionType(this->coeffDict().lookup("type"))
118     ),
119     e_(0.0),
120     mu_(0.0),
121     nEscape0_(0),
122     massEscape0_(0.0),
123     nStick0_(0),
124     massStick0_(0.0),
125     nEscape_(0),
126     massEscape_(0.0),
127     nStick_(0),
128     massStick_(0.0)
130     switch (interactionType_)
131     {
132         case PatchInteractionModel<CloudType>::itOther:
133         {
134             const word interactionTypeName(this->coeffDict().lookup("type"));
136             FatalErrorIn
137             (
138                 "StandardWallInteraction<CloudType>::StandardWallInteraction"
139                 "("
140                     "const dictionary&, "
141                     "CloudType& cloud"
142                 ")"
143             )   << "Unknown interaction result type "
144                 << interactionTypeName
145                 << ". Valid selections are:" << this->interactionTypeNames_
146                 << endl << exit(FatalError);
148             break;
149         }
150         case PatchInteractionModel<CloudType>::itRebound:
151         {
152             e_ = this->coeffDict().lookupOrDefault("e", 1.0);
153             mu_ = this->coeffDict().lookupOrDefault("mu", 0.0);
154             break;
155         }
156         default:
157         {
158             // do nothing
159         }
160     }
164 template<class CloudType>
165 Foam::StandardWallInteraction<CloudType>::StandardWallInteraction
167     const StandardWallInteraction<CloudType>& pim
170     PatchInteractionModel<CloudType>(pim),
171     interactionType_(pim.interactionType_),
172     e_(pim.e_),
173     mu_(pim.mu_),
174     nEscape0_(pim.nEscape0_),
175     massEscape0_(pim.massEscape0_),
176     nStick0_(pim.nStick0_),
177     massStick0_(pim.massStick0_),
178     nEscape_(pim.nEscape_),
179     massEscape_(pim.massEscape_),
180     nStick_(pim.nStick_),
181     massStick_(pim.massStick_)
185 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
187 template<class CloudType>
188 Foam::StandardWallInteraction<CloudType>::~StandardWallInteraction()
192 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
194 template<class CloudType>
195 bool Foam::StandardWallInteraction<CloudType>::correct
197     typename CloudType::parcelType& p,
198     const polyPatch& pp,
199     bool& keepParticle,
200     const scalar trackFraction,
201     const tetIndices& tetIs
204     vector& U = p.U();
206     bool& active = p.active();
208     if (isA<wallPolyPatch>(pp))
209     {
210         switch (interactionType_)
211         {
212             case PatchInteractionModel<CloudType>::itEscape:
213             {
214                 keepParticle = false;
215                 active = false;
216                 U = vector::zero;
217                 nEscape_++;
218                 break;
219             }
220             case PatchInteractionModel<CloudType>::itStick:
221             {
222                 keepParticle = true;
223                 active = false;
224                 U = vector::zero;
225                 nStick_++;
226                 break;
227             }
228             case PatchInteractionModel<CloudType>::itRebound:
229             {
230                 keepParticle = true;
231                 active = true;
233                 vector nw;
234                 vector Up;
236                 this->patchData(p, pp, trackFraction, tetIs, nw, Up);
238                 // Calculate motion relative to patch velocity
239                 U -= Up;
241                 scalar Un = U & nw;
242                 vector Ut = U - Un*nw;
244                 if (Un > 0)
245                 {
246                     U -= (1.0 + e_)*Un*nw;
247                 }
249                 U -= mu_*Ut;
251                 // Return velocity to global space
252                 U += Up;
254                 break;
255             }
256             default:
257             {
258                 FatalErrorIn
259                 (
260                     "bool StandardWallInteraction<CloudType>::correct"
261                     "("
262                         "const polyPatch&, "
263                         "const label, "
264                         "bool&, "
265                         "vector&"
266                     ") const"
267                 )   << "Unknown interaction type "
268                     << this->interactionTypeToWord(interactionType_)
269                     << "(" << interactionType_ << ")" << endl
270                     << abort(FatalError);
271             }
272         }
274         return true;
275     }
277     return false;
281 template<class CloudType>
282 void Foam::StandardWallInteraction<CloudType>::info(Ostream& os) const
284     label npe = returnReduce(nEscape_, sumOp<label>()) + nEscape0_;
285     scalar mpe = returnReduce(massEscape_, sumOp<scalar>()) + massEscape0_;
287     label nps = returnReduce(nStick_, sumOp<label>()) + nStick0_;
288     scalar mps = returnReduce(massStick_, sumOp<scalar>()) + massStick0_;
290     os  << "    Parcel fates:" << nl
291         << "      - escape                      = " << npe << ", " << mpe << nl
292         << "      - stick                       = " << nps << ", " << mps << nl;
294     writeProps(npe, mpe, nps, mps);
298 // ************************************************************************* //