FreeFOAM The Cross-Platform CFD Toolkit
LocalInteraction.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "LocalInteraction.H"
27 
28 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
29 
30 template <class CloudType>
32 (
33  const label globalPatchI
34 ) const
35 {
36  forAll(patchIds_, patchI)
37  {
38  if (patchIds_[patchI] == globalPatchI)
39  {
40  return patchI;
41  }
42  }
43 
44  return -1;
45 }
46 
47 
48 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
49 
50 template <class CloudType>
52 (
53  const dictionary& dict,
54  CloudType& cloud
55 )
56 :
57  PatchInteractionModel<CloudType>(dict, cloud, typeName),
58  patchData_(this->coeffDict().lookup("patches")),
59  patchIds_(patchData_.size())
60 {
61  const polyMesh& mesh = cloud.mesh();
62  const polyBoundaryMesh& bMesh = mesh.boundaryMesh();
63 
64  // check that user patches are valid region patches
65  forAll(patchData_, patchI)
66  {
67  const word& patchName = patchData_[patchI].patchName();
68  patchIds_[patchI] = bMesh.findPatchID(patchName);
69  if (patchIds_[patchI] < 0)
70  {
71  FatalErrorIn("LocalInteraction(const dictionary&, CloudType&)")
72  << "Patch " << patchName << " not found. Available patches "
73  << "are: " << bMesh.names() << nl << exit(FatalError);
74  }
75  }
76 
77  // check that all walls are specified
78  DynamicList<word> badWalls;
79  forAll(bMesh, patchI)
80  {
81  if
82  (
83  isA<wallPolyPatch>(bMesh[patchI])
84  && applyToPatch(bMesh[patchI].index()) < 0
85  )
86  {
87  badWalls.append(bMesh[patchI].name());
88  }
89  }
90 
91  if (badWalls.size() > 0)
92  {
93  FatalErrorIn("LocalInteraction(const dictionary&, CloudType&)")
94  << "All wall patches must be specified when employing local patch "
95  << "interaction. Please specify data for patches:" << nl
96  << badWalls << nl << exit(FatalError);
97  }
98 
99  // check that interactions are valid/specified
100  forAll(patchData_, patchI)
101  {
102  const word& interactionTypeName =
103  patchData_[patchI].interactionTypeName();
105  this->wordToInteractionType(interactionTypeName);
106 
108  {
109  const word& patchName = patchData_[patchI].patchName();
110  FatalErrorIn("LocalInteraction(const dictionary&, CloudType&)")
111  << "Unknown patch interaction type "
112  << interactionTypeName << " for patch " << patchName
113  << ". Valid selections are:"
115  << nl << exit(FatalError);
116  }
117  }
118 }
119 
120 
121 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
122 
123 template <class CloudType>
125 {}
126 
127 
128 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
129 
130 template<class CloudType>
132 {
133  return true;
134 }
135 
136 
137 template <class CloudType>
139 (
140  const polyPatch& pp,
141  const label faceId,
142  bool& keepParticle,
143  bool& active,
144  vector& U
145 ) const
146 {
147  label patchI = applyToPatch(pp.index());
148 
149  if (patchI >= 0)
150  {
152  this->wordToInteractionType
153  (
154  patchData_[patchI].interactionTypeName()
155  );
156 
157  switch (it)
158  {
160  {
161  keepParticle = false;
162  active = false;
163  U = vector::zero;
164  break;
165  }
167  {
168  keepParticle = true;
169  active = false;
170  U = vector::zero;
171  break;
172  }
174  {
175  keepParticle = true;
176  active = true;
177 
178  vector nw = pp.faceAreas()[pp.whichFace(faceId)];
179  nw /= mag(nw);
180 
181  scalar Un = U & nw;
182  vector Ut = U - Un*nw;
183 
184  if (Un > 0)
185  {
186  U -= (1.0 + patchData_[patchI].e())*Un*nw;
187  }
188 
189  U -= patchData_[patchI].mu()*Ut;
190 
191  break;
192  }
193  default:
194  {
196  (
197  "bool LocalInteraction<CloudType>::correct"
198  "("
199  "const polyPatch&, "
200  "const label, "
201  "bool&, "
202  "vector&"
203  ") const"
204  ) << "Unknown interaction type "
205  << patchData_[patchI].interactionTypeName()
206  << "(" << it << ") for patch "
207  << patchData_[patchI].patchName()
208  << ". Valid selections are:" << this->interactionTypeNames_
209  << endl << abort(FatalError);
210  }
211  }
212 
213  return true;
214  }
215 
216  return false;
217 }
218 
219 
220 // ************************ vim: set sw=4 sts=4 et: ************************ //