initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / applications / utilities / postProcessing / miscellaneous / postChannel / channelIndex.C
blob74315de31a44e057b2c64017cf9d2c343081048d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
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 "channelIndex.H"
29 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
31 channelIndex::channelIndex(const fvMesh& m)
33     indexingDict_
34     (
35         IOobject
36         (
37             "postChannelDict",
38             m.time().constant(),
39             m,
40             IOobject::MUST_READ,
41             IOobject::NO_WRITE
42         )
43     ),
44     nx_(readLabel(indexingDict_.lookup("Nx"))),
45     ny_(indexingDict_.lookup("Ny")),
46     nz_(readLabel(indexingDict_.lookup("Nz"))),
47     symmetric_
48     (
49         readBool(indexingDict_.lookup("symmetric"))
50     ),
51     cumNy_(ny_.size()),
52     nLayers_(ny_[0])
54     // initialise the layers
55     cumNy_[0] = ny_[0];
57     for (label j=1; j<ny_.size(); j++)
58     {
59         nLayers_ += ny_[j];
60         cumNy_[j] = ny_[j]+cumNy_[j-1];
61     }
65 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
67 channelIndex::~channelIndex()
71 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
73 scalarField channelIndex::collapse
75     const volScalarField& vsf,
76     const bool asymmetric
77 ) const
79     scalarField cs(nLayers(), 0.0);
81     forAll(cs, j)
82     {
83         // sweep over all cells in this layer
84         for (label i=0; i<nx(); i++)
85         {
86             for (label k=0; k<nz(); k++)
87             {
88                 cs[j] += vsf[operator()(i,j,k)];
89             }
90         }
92         // and divide by the number of cells in the layer
93         cs[j] /= scalar(nx()*nz());
94     }
96     if (symmetric_)
97     {
98         label nlb2 = nLayers()/2;
100         if (asymmetric)
101         {
102             for (label j=0; j<nlb2; j++)
103             {
104                 cs[j] = 0.5*(cs[j] - cs[nLayers() - j - 1]);
105             }
106         }
107         else
108         {
109             for (label j=0; j<nlb2; j++)
110             {
111                 cs[j] = 0.5*(cs[j] + cs[nLayers() - j - 1]);
112             }
113         }
115         cs.setSize(nlb2);
116     }
118     return cs;
122 scalarField channelIndex::y
124     const volVectorField& cellCentres
125 ) const
127     if (symmetric_)
128     {
129         scalarField Y(nLayers()/2);
131         for (label j=0; j<nLayers()/2; j++)
132         {
133             Y[j] = cellCentres[operator()(0, j, 0)].y();
134         }
136         return Y;
137     }
138     else
139     {
140         scalarField Y(nLayers());
142         for (label j=0; j<nLayers(); j++)
143         {
144             Y[j] = cellCentres[operator()(0, j, 0)].y();
145         }
147         return Y;
148     }
152 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
154 label channelIndex::operator()
156     const label Jx,
157     const label Jy,
158     const label Jz
159 ) const
161     label index(0);
163     // count up `full' layers in the mesh
164     label j(0);
165     label tmpJy(Jy);
167     while(Jy >= cumNy_[j])
168     {
169         index += nx_*ny_[j]*nz_;
170         tmpJy -= ny_[j];
171         j++;
172     }
174     index += Jx + nx_*tmpJy + nx_*ny_[j]*Jz;
176     return index;
180 // ************************************************************************* //