1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Calculates and writes the stream function of velocity field U at each time
30 \*---------------------------------------------------------------------------*/
33 #include "pointFields.H"
34 #include "emptyPolyPatch.H"
35 #include "symmetryPolyPatch.H"
36 #include "wedgePolyPatch.H"
37 #include "OSspecific.H"
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 int main(int argc, char *argv[])
44 timeSelector::addOptions();
46 # include "setRootCase.H"
47 # include "createTime.H"
49 instantList timeDirs = timeSelector::select0(runTime, args);
51 # include "createMeshNoClear.H"
53 pointMesh pMesh(mesh);
55 forAll(timeDirs, timeI)
57 runTime.setTime(timeDirs[timeI], timeI);
59 Info<< nl << "Time: " << runTime.timeName() << endl;
69 if (phiHeader.headerOk())
73 Info<< nl << "Reading field phi" << endl;
75 surfaceScalarField phi
88 pointScalarField streamFunction
99 dimensionedScalar("zero", phi.dimensions(), 0.0)
102 labelList visitedPoint(mesh.nPoints());
103 forAll (visitedPoint, pointI)
105 visitedPoint[pointI] = 0;
108 label nVisitedOld = 0;
110 const unallocFaceList& faces = mesh.faces();
111 const pointField& points = mesh.points();
113 label nInternalFaces = mesh.nInternalFaces();
115 vectorField unitAreas = mesh.faceAreas();
116 unitAreas /= mag(unitAreas);
118 const polyPatchList& patches = mesh.boundaryMesh();
120 bool finished = true;
122 // Find the boundary face with zero flux. set the stream function
123 // to zero on that face
130 forAll (patches, patchI)
132 const primitivePatch& bouFaces = patches[patchI];
134 if (!isType<emptyPolyPatch>(patches[patchI]))
136 forAll (bouFaces, faceI)
140 magSqr(phi.boundaryField()[patchI][faceI])
144 const labelList& zeroPoints = bouFaces[faceI];
146 // Zero flux face found
149 forAll (zeroPoints, pointI)
151 if (visitedPoint[zeroPoints[pointI]] == 1)
160 Info<< "Zero face: patch: " << patchI
161 << " face: " << faceI << endl;
163 forAll (zeroPoints, pointI)
165 streamFunction[zeroPoints[pointI]] = 0;
166 visitedPoint[zeroPoints[pointI]] = 1;
181 Info<< "zero flux boundary face not found. "
182 << "Using cell as a reference."
185 const cellList& c = mesh.cells();
189 labelList zeroPoints = c[cI].labels(mesh.faces());
193 forAll (zeroPoints, pointI)
195 if (visitedPoint[zeroPoints[pointI]] == 1)
204 forAll (zeroPoints, pointI)
206 streamFunction[zeroPoints[pointI]] = 0.0;
207 visitedPoint[zeroPoints[pointI]] = 1;
215 FatalErrorIn(args.executable())
216 << "Cannot find initialisation face or a cell."
217 << abort(FatalError);
222 // Loop through all faces. If one of the points on
223 // the face has the streamfunction value different
224 // from -1, all points with -1 ont that face have the
225 // streamfunction value equal to the face flux in
226 // that point plus the value in the visited point
233 label faceI = nInternalFaces;
238 const labelList& curBPoints = faces[faceI];
239 bool bPointFound = false;
241 scalar currentBStream = 0.0;
242 vector currentBStreamPoint(0, 0, 0);
244 forAll (curBPoints, pointI)
246 // Check if the point has been visited
247 if (visitedPoint[curBPoints[pointI]] == 1)
249 // The point has been visited
251 streamFunction[curBPoints[pointI]];
252 currentBStreamPoint =
253 points[curBPoints[pointI]];
263 // Sort out other points on the face
264 forAll (curBPoints, pointI)
266 // Check if the point has been visited
267 if (visitedPoint[curBPoints[pointI]] == 0)
270 mesh.boundaryMesh().whichPatch(faceI);
274 !isType<emptyPolyPatch>
276 && !isType<symmetryPolyPatch>
278 && !isType<wedgePolyPatch>
283 mesh.boundaryMesh()[patchNo]
287 points[curBPoints[pointI]]
288 - currentBStreamPoint;
289 edgeHat.replace(vector::Z, 0);
290 edgeHat /= mag(edgeHat);
292 vector nHat = unitAreas[faceI];
294 if (edgeHat.y() > VSMALL)
296 visitedPoint[curBPoints[pointI]] =
300 streamFunction[curBPoints[pointI]]
303 + phi.boundaryField()
307 else if (edgeHat.y() < -VSMALL)
309 visitedPoint[curBPoints[pointI]] =
313 streamFunction[curBPoints[pointI]]
316 - phi.boundaryField()
322 if (edgeHat.x() > VSMALL)
325 [curBPoints[pointI]] = 1;
329 [curBPoints[pointI]] =
331 + phi.boundaryField()
335 else if (edgeHat.x() < -VSMALL)
338 [curBPoints[pointI]] = 1;
342 [curBPoints[pointI]] =
344 - phi.boundaryField()
359 for (label faceI=0; faceI<nInternalFaces; faceI++)
361 // Get the list of point labels for the face
362 const labelList& curPoints = faces[faceI];
364 bool pointFound = false;
366 scalar currentStream = 0.0;
367 point currentStreamPoint(0, 0, 0);
369 forAll (curPoints, pointI)
371 // Check if the point has been visited
372 if (visitedPoint[curPoints[pointI]] == 1)
374 // The point has been visited
376 streamFunction[curPoints[pointI]];
378 points[curPoints[pointI]];
387 // Sort out other points on the face
388 forAll (curPoints, pointI)
390 // Check if the point has been visited
391 if (visitedPoint[curPoints[pointI]] == 0)
394 points[curPoints[pointI]]
395 - currentStreamPoint;
397 edgeHat.replace(vector::Z, 0);
398 edgeHat /= mag(edgeHat);
400 vector nHat = unitAreas[faceI];
402 if (edgeHat.y() > VSMALL)
404 visitedPoint[curPoints[pointI]] = 1;
407 streamFunction[curPoints[pointI]] =
409 + phi[faceI]*sign(nHat.x());
411 else if (edgeHat.y() < -VSMALL)
413 visitedPoint[curPoints[pointI]] = 1;
416 streamFunction[curPoints[pointI]] =
418 - phi[faceI]*sign(nHat.x());
430 // Info<< "One pass, n visited = " << nVisited << endl;
432 if (nVisited == nVisitedOld)
434 // Find new seed. This must be a
435 // multiply connected domain
436 Info<< nl << "Exhausted a seed. Looking for new seed "
437 << "(this is correct for multiply connected "
444 nVisitedOld = nVisited;
451 streamFunction.boundaryField() = 0.0;
452 streamFunction.write();
456 WarningIn(args.executable())
457 << "Flux field does not exist."
458 << " Stream function not calculated" << endl;
462 Info<< "\nEnd\n" << endl;
468 // ************************************************************************* //