fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / lagrangian / intermediate / submodels / Kinematic / PatchInteractionModel / LocalInteraction / LocalInteraction.C
blob6874cf0b57f3705d1097222941ba9e1dd218f592
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 "LocalInteraction.H"
29 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
31 template <class CloudType>
32 Foam::label Foam::LocalInteraction<CloudType>::applyToPatch
34     const label globalPatchI
35 ) const
37     forAll(patchIds_, patchI)
38     {
39         if (patchIds_[patchI] == globalPatchI)
40         {
41             return patchI;
42         }
43     }
45     return -1;
49 // * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * * //
51 template <class CloudType>
52 Foam::LocalInteraction<CloudType>::LocalInteraction
54     const dictionary& dict,
55     CloudType& cloud
58     PatchInteractionModel<CloudType>(dict, cloud, typeName),
59     patchData_(this->coeffDict().lookup("patches")),
60     patchIds_(patchData_.size())
62     const polyMesh& mesh = cloud.mesh();
63     const polyBoundaryMesh& bMesh = mesh.boundaryMesh();
65     // check that user patches are valid region patches
66     forAll(patchData_, patchI)
67     {
68         const word& patchName = patchData_[patchI].patchName();
69         patchIds_[patchI] = bMesh.findPatchID(patchName);
70         if (patchIds_[patchI] < 0)
71         {
72             FatalErrorIn("LocalInteraction(const dictionary&, CloudType&)")
73                 << "Patch " << patchName << " not found. Available patches "
74                 << "are: " << bMesh.names() << nl << exit(FatalError);
75         }
76     }
78     // check that all walls are specified
79     DynamicList<word> badWalls;
80     forAll(bMesh, patchI)
81     {
82         if
83         (
84             bMesh[patchI].isWall()
85          && applyToPatch(bMesh[patchI].index()) < 0
86         )
87         {
88             badWalls.append(bMesh[patchI].name());
89         }
90     }
92     if (badWalls.size() > 0)
93     {
94         FatalErrorIn("LocalInteraction(const dictionary&, CloudType&)")
95             << "All wall patches must be specified when employing local patch "
96             << "interaction. Please specify data for patches:" << nl
97             << badWalls << nl << exit(FatalError);
98     }
100     // check that interactions are valid/specified
101     forAll(patchData_, patchI)
102     {
103         const word& interactionTypeName =
104             patchData_[patchI].interactionTypeName();
105         const typename PatchInteractionModel<CloudType>::interactionType& it =
106             this->wordToInteractionType(interactionTypeName);
108         if (it == PatchInteractionModel<CloudType>::itOther)
109         {
110             const word& patchName = patchData_[patchI].patchName();
111             FatalErrorIn("LocalInteraction(const dictionary&, CloudType&)")
112                 << "Unknown patch interaction type "
113                 << interactionTypeName << " for patch " << patchName
114                 << ". Valid selections are:"
115                 << this->PatchInteractionModel<CloudType>::interactionTypeNames_
116                 << nl << exit(FatalError);
117         }
118     }
122 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
124 template <class CloudType>
125 Foam::LocalInteraction<CloudType>::~LocalInteraction()
129 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
131 template<class CloudType>
132 bool Foam::LocalInteraction<CloudType>::active() const
134     return true;
138 template <class CloudType>
139 bool Foam::LocalInteraction<CloudType>::correct
141     const polyPatch& pp,
142     const label faceId,
143     bool& keepParticle,
144     vector& U
145 ) const
147     label patchI = applyToPatch(pp.index());
149     if (patchI >= 0)
150     {
151         typename PatchInteractionModel<CloudType>::interactionType it =
152             this->wordToInteractionType
153             (
154                 patchData_[patchI].interactionTypeName()
155             );
157         switch (it)
158         {
159             case PatchInteractionModel<CloudType>::itEscape:
160             {
161                 keepParticle = false;
162                 U = vector::zero;
163                 break;
164             }
165             case PatchInteractionModel<CloudType>::itStick:
166             {
167                 keepParticle = true;
168                 U = vector::zero;
169                 break;
170             }
171             case PatchInteractionModel<CloudType>::itRebound:
172             {
173                 keepParticle = true;
175                 vector nw = pp.faceAreas()[pp.whichFace(faceId)];
176                 nw /= mag(nw);
178                 scalar Un = U & nw;
179                 vector Ut = U - Un*nw;
181                 if (Un > 0)
182                 {
183                     U -= (1.0 + patchData_[patchI].e())*Un*nw;
184                 }
186                 U -= patchData_[patchI].mu()*Ut;
188                 break;
189             }
190             default:
191             {
192                 FatalErrorIn
193                 (
194                     "bool LocalInteraction<CloudType>::correct"
195                     "("
196                         "const polyPatch&, "
197                         "const label, "
198                         "bool&, "
199                         "vector&"
200                     ") const"
201                 )   << "Unknown interaction type "
202                     << patchData_[patchI].interactionTypeName()
203                     << "(" << it << ") for patch "
204                     << patchData_[patchI].patchName()
205                     << ". Valid selections are:" << this->interactionTypeNames_
206                     << endl << abort(FatalError);
207             }
208         }
210         return true;
211     }
213     return false;
217 // ************************************************************************* //