1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 \*---------------------------------------------------------------------------*/
28 #include "volFields.H"
29 #include "surfaceFields.H"
30 #include "fvMatrices.H"
31 #include "syncTools.H"
33 #include "geometricOneField.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(Foam::MRFZone, 0);
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 void Foam::MRFZone::setMRFFaces()
44 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
48 // 1:moving with frame
50 labelList faceType(mesh_.nFaces(), 0);
52 // Determine faces in cell zone
53 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54 // (without constructing cells)
56 const labelList& own = mesh_.faceOwner();
57 const labelList& nei = mesh_.faceNeighbour();
60 boolList zoneCell(mesh_.nCells(), false);
62 if (cellZoneID_ != -1)
64 const labelList& cellLabels = mesh_.cellZones()[cellZoneID_];
67 zoneCell[cellLabels[i]] = true;
74 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
76 if (zoneCell[own[faceI]] || zoneCell[nei[faceI]])
84 labelHashSet excludedPatches(excludedPatchLabels_);
86 forAll(patches, patchI)
88 const polyPatch& pp = patches[patchI];
90 if (pp.coupled() || excludedPatches.found(patchI))
94 label faceI = pp.start()+i;
96 if (zoneCell[own[faceI]])
103 else if (!isA<emptyPolyPatch>(pp))
107 label faceI = pp.start()+i;
109 if (zoneCell[own[faceI]])
118 // Now we have for faceType:
119 // 0 : face not in cellZone
120 // 1 : internal face or normal patch face
121 // 2 : coupled patch face or excluded patch face
123 // Sort into lists per patch.
125 internalFaces_.setSize(mesh_.nFaces());
128 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
130 if (faceType[faceI] == 1)
132 internalFaces_[nInternal++] = faceI;
135 internalFaces_.setSize(nInternal);
137 labelList nIncludedFaces(patches.size(), 0);
138 labelList nExcludedFaces(patches.size(), 0);
140 forAll(patches, patchi)
142 const polyPatch& pp = patches[patchi];
144 forAll(pp, patchFacei)
146 label faceI = pp.start()+patchFacei;
148 if (faceType[faceI] == 1)
150 nIncludedFaces[patchi]++;
152 else if (faceType[faceI] == 2)
154 nExcludedFaces[patchi]++;
159 includedFaces_.setSize(patches.size());
160 excludedFaces_.setSize(patches.size());
161 forAll(nIncludedFaces, patchi)
163 includedFaces_[patchi].setSize(nIncludedFaces[patchi]);
164 excludedFaces_[patchi].setSize(nExcludedFaces[patchi]);
169 forAll(patches, patchi)
171 const polyPatch& pp = patches[patchi];
173 forAll(pp, patchFacei)
175 label faceI = pp.start()+patchFacei;
177 if (faceType[faceI] == 1)
179 includedFaces_[patchi][nIncludedFaces[patchi]++] = patchFacei;
181 else if (faceType[faceI] == 2)
183 excludedFaces_[patchi][nExcludedFaces[patchi]++] = patchFacei;
191 faceSet internalFaces(mesh_, "internalFaces", internalFaces_);
192 Pout<< "Writing " << internalFaces.size()
193 << " internal faces in MRF zone to faceSet "
194 << internalFaces.name() << endl;
195 internalFaces.write();
197 faceSet MRFFaces(mesh_, "includedFaces", 100);
198 forAll(includedFaces_, patchi)
200 forAll(includedFaces_[patchi], i)
202 label patchFacei = includedFaces_[patchi][i];
203 MRFFaces.insert(patches[patchi].start()+patchFacei);
206 Pout<< "Writing " << MRFFaces.size()
207 << " patch faces in MRF zone to faceSet "
208 << MRFFaces.name() << endl;
211 faceSet excludedFaces(mesh_, "excludedFaces", 100);
212 forAll(excludedFaces_, patchi)
214 forAll(excludedFaces_[patchi], i)
216 label patchFacei = excludedFaces_[patchi][i];
217 excludedFaces.insert(patches[patchi].start()+patchFacei);
220 Pout<< "Writing " << excludedFaces.size()
221 << " faces in MRF zone with special handling to faceSet "
222 << excludedFaces.name() << endl;
223 excludedFaces.write();
228 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
230 Foam::MRFZone::MRFZone(const fvMesh& mesh, Istream& is)
235 cellZoneID_(mesh_.cellZones().findZoneID(name_)),
238 dict_.lookupOrDefault("nonRotatingPatches", wordList(0))
240 origin_(dict_.lookup("origin")),
241 axis_(dict_.lookup("axis")),
242 omega_(dict_.lookup("omega")),
243 Omega_("Omega", omega_*axis_)
245 if (dict_.found("patches"))
247 WarningIn("MRFZone(const fvMesh&, Istream&)")
248 << "Ignoring entry 'patches'\n"
249 << " By default all patches within the rotating region rotate.\n"
250 << " Optionally supply excluded patches "
251 << "using 'nonRotatingPatches'."
255 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
257 axis_ = axis_/mag(axis_);
258 Omega_ = omega_*axis_;
260 excludedPatchLabels_.setSize(excludedPatchNames_.size());
262 forAll(excludedPatchNames_, i)
264 excludedPatchLabels_[i] = patches.findPatchID(excludedPatchNames_[i]);
266 if (excludedPatchLabels_[i] == -1)
270 "Foam::MRFZone::MRFZone(const fvMesh&, Istream&)"
271 ) << "cannot find MRF patch " << excludedPatchNames_[i]
277 bool cellZoneFound = (cellZoneID_ != -1);
278 reduce(cellZoneFound, orOp<bool>());
284 "Foam::MRFZone::MRFZone(const fvMesh&, Istream&)"
285 ) << "cannot find MRF cellZone " << name_
293 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
295 void Foam::MRFZone::addCoriolis(fvVectorMatrix& UEqn) const
297 if (cellZoneID_ == -1)
302 const labelList& cells = mesh_.cellZones()[cellZoneID_];
303 const scalarField& V = mesh_.V();
304 vectorField& Usource = UEqn.source();
305 const vectorField& U = UEqn.psi();
306 const vector& Omega = Omega_.value();
310 label celli = cells[i];
311 Usource[celli] -= V[celli]*(Omega ^ U[celli]);
316 void Foam::MRFZone::addCoriolis
318 const volScalarField& rho,
322 if (cellZoneID_ == -1)
327 const labelList& cells = mesh_.cellZones()[cellZoneID_];
328 const scalarField& V = mesh_.V();
329 vectorField& Usource = UEqn.source();
330 const vectorField& U = UEqn.psi();
331 const vector& Omega = Omega_.value();
335 label celli = cells[i];
336 Usource[celli] -= V[celli]*rho[celli]*(Omega ^ U[celli]);
341 void Foam::MRFZone::relativeVelocity(volVectorField& U) const
343 const volVectorField& C = mesh_.C();
345 const vector& origin = origin_.value();
346 const vector& Omega = Omega_.value();
348 const labelList& cells = mesh_.cellZones()[cellZoneID_];
352 label celli = cells[i];
353 U[celli] -= (Omega ^ (C[celli] - origin));
357 forAll(includedFaces_, patchi)
359 forAll(includedFaces_[patchi], i)
361 label patchFacei = includedFaces_[patchi][i];
362 U.boundaryField()[patchi][patchFacei] = vector::zero;
367 forAll(excludedFaces_, patchi)
369 forAll(excludedFaces_[patchi], i)
371 label patchFacei = excludedFaces_[patchi][i];
372 U.boundaryField()[patchi][patchFacei] -=
373 (Omega ^ (C.boundaryField()[patchi][patchFacei] - origin));
379 void Foam::MRFZone::absoluteVelocity(volVectorField& U) const
381 const volVectorField& C = mesh_.C();
383 const vector& origin = origin_.value();
384 const vector& Omega = Omega_.value();
386 const labelList& cells = mesh_.cellZones()[cellZoneID_];
390 label celli = cells[i];
391 U[celli] += (Omega ^ (C[celli] - origin));
395 forAll(includedFaces_, patchi)
397 forAll(includedFaces_[patchi], i)
399 label patchFacei = includedFaces_[patchi][i];
400 U.boundaryField()[patchi][patchFacei] =
401 (Omega ^ (C.boundaryField()[patchi][patchFacei] - origin));
406 forAll(excludedFaces_, patchi)
408 forAll(excludedFaces_[patchi], i)
410 label patchFacei = excludedFaces_[patchi][i];
411 U.boundaryField()[patchi][patchFacei] +=
412 (Omega ^ (C.boundaryField()[patchi][patchFacei] - origin));
418 void Foam::MRFZone::relativeFlux(surfaceScalarField& phi) const
420 relativeRhoFlux(geometricOneField(), phi);
424 void Foam::MRFZone::relativeFlux
426 const surfaceScalarField& rho,
427 surfaceScalarField& phi
430 relativeRhoFlux(rho, phi);
434 void Foam::MRFZone::absoluteFlux(surfaceScalarField& phi) const
436 absoluteRhoFlux(geometricOneField(), phi);
440 void Foam::MRFZone::absoluteFlux
442 const surfaceScalarField& rho,
443 surfaceScalarField& phi
446 absoluteRhoFlux(rho, phi);
450 void Foam::MRFZone::correctBoundaryVelocity(volVectorField& U) const
452 const vector& origin = origin_.value();
453 const vector& Omega = Omega_.value();
456 forAll(includedFaces_, patchi)
458 const vectorField& patchC = mesh_.Cf().boundaryField()[patchi];
460 vectorField pfld(U.boundaryField()[patchi]);
462 forAll(includedFaces_[patchi], i)
464 label patchFacei = includedFaces_[patchi][i];
466 pfld[patchFacei] = (Omega ^ (patchC[patchFacei] - origin));
469 U.boundaryField()[patchi] == pfld;
474 // ************************************************************************* //