Merge commit 'd3b269b7c6ffa0cd68845adfecdfb849316dba71' into nextRelease
[foam-extend-3.2.git] / src / engine / engineTopoChangerMesh / twoStrokeEngine / twoStrokeEngineCheckMotionFluxes.C
bloba52333cda4c6b7bddbb307f9c806c5188c43d086
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     |
5     \\  /    A nd           | For copyright notice see file Copyright
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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/>.
24 \*---------------------------------------------------------------------------*/
27 #include "twoStrokeEngine.H"
28 #include "slidingInterface.H"
29 #include "layerAdditionRemoval.H"
30 #include "surfaceFields.H"
31 #include "regionSplit.H"
32 #include "componentMixedTetPolyPatchVectorField.H"
33 #include "mapPolyMesh.H"
35 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
36 void Foam::twoStrokeEngine::checkMotionFluxes()
40     //checking the motion fluxes for the cutFaceZone
42     Info << "Checking the motion fluxes in the cut-face zone" << endl;
44     const labelList& cutFaceZoneAddressing =
45         faceZones()[faceZones().findZoneID("cutFaceZone")];
47     boolList calculatedMeshPhi(V().size(), false);
48     scalarField sumMeshPhi(V().size(), 0.0);
50     forAll(cutFaceZoneAddressing, i)
51     {
52         label facei = cutFaceZoneAddressing[i];
54         calculatedMeshPhi[owner()[facei]] = true;
55         calculatedMeshPhi[neighbour()[facei]] = true;
56     }
58     Info << "Checking the motion fluxes in the liner zone" << endl;
60     const labelList& linerAddressing =
61         faceZones()[faceZones().findZoneID(scavInCylPatchName_ + "Zone")];
63     forAll(linerAddressing, i)
64     {
65         label facei = linerAddressing[i];
67         calculatedMeshPhi[owner()[facei]] = true;
68         calculatedMeshPhi[neighbour()[facei]] = true;
69     }
71     const polyPatch& wallPatch =
72         boundaryMesh()[boundaryMesh().findPatchID("wall")];
74     labelList wallLabels(wallPatch.size());
76     forAll (wallLabels, i)
77     {
78         wallLabels[i] = wallPatch.start() + i;
79     }
81     forAll(wallLabels, i)
82     {
83         label facei = wallLabels[i];
85         calculatedMeshPhi[owner()[facei]] = true;
86         calculatedMeshPhi[neighbour()[facei]] = true;
87     }
89     forAll(owner(), facei)
90     {
91         sumMeshPhi[owner()[facei]] += phi()[facei];
92         sumMeshPhi[neighbour()[facei]] -= phi()[facei];
93     }
95     forAll(boundary(), patchi)
96     {
97         const unallocLabelList& pFaceCells =
98             boundary()[patchi].faceCells();
100         const fvsPatchField<scalar>& pssf = phi().boundaryField()[patchi];
102         forAll(boundary()[patchi], facei)
103         {
104             sumMeshPhi[pFaceCells[facei]] += pssf[facei];
105         }
106     }
108     sumMeshPhi /= V();
110     DynamicList<label> checkMeshPhi;
111     label checkMeshPhiSize = 0;
113     forAll(calculatedMeshPhi, i)
114     {
115         if(calculatedMeshPhi[i] == true)
116         {
117             checkMeshPhi.append(i);
118             checkMeshPhiSize++;
119         }
120     }
122     Info << "checkMeshPhiSize = " << checkMeshPhiSize << endl;
124     checkMeshPhi.setSize(checkMeshPhiSize);
126     scalarField dVdt(checkMeshPhiSize, 0.0);
128     forAll(dVdt, i)
129     {
130         label celli = checkMeshPhi[i];
132         dVdt[i] = (1.0 - V0()[celli]/V()[celli])/engTime().deltaT().value();
133     }
135     Info << "checking mesh flux in the cutFaces" << endl;
137     label nOutCheck = 0;
139     forAll(checkMeshPhi, i)
140     {
141         scalar sumCheck = dVdt[i] - sumMeshPhi[checkMeshPhi[i]];
142         if(mag(sumCheck) > 1)
143         {
144             Info<< "LOCAL sumCheck[" << checkMeshPhi[i] <<  "] = "
145                 << sumCheck << endl;
146             nOutCheck++;
147         }
148     }
150     Info<< "found " << nOutCheck << " cells with inconsistent motion fluxes"
151         << endl;
152     Info << "end " <<  endl;
155     {
157         scalarField dVdt = (1.0 - V0()/V())/engTime().deltaT();
159         scalarField sumMeshPhi(V().size(), 0.0);
161         forAll(owner(), facei)
162         {
163             sumMeshPhi[owner()[facei]] += phi()[facei];
164             sumMeshPhi[neighbour()[facei]] -= phi()[facei];
165         }
167         forAll(boundary(), patchi)
168         {
169             const unallocLabelList& pFaceCells =
170                 boundary()[patchi].faceCells();
172             const fvsPatchField<scalar>& pssf = phi().boundaryField()[patchi];
174             forAll(boundary()[patchi], facei)
175             {
176                 sumMeshPhi[pFaceCells[facei]] += pssf[facei];
177             }
178         }
180         sumMeshPhi /= V();
182         scalarField sumCheck = dVdt - sumMeshPhi;
184         label nOutCheck = 0;
186         forAll(sumCheck, celli)
187         {
188             if(mag(sumCheck[celli]) > 1)
189             {
190                 Info<< "sumCheck GLOBAL[" << celli << "] = "
191                     << sumCheck[celli] << endl;
192                 nOutCheck++;
193             }
194         }
196         Info<< "found " << nOutCheck
197             << " cells with inconsistent motion fluxes GLOBAL" << endl;
199     }