BUGFIX: Illegal use of uninitialised value (backport)
[foam-extend-3.2.git] / applications / utilities / postProcessing / stressField / stressComponents / stressComponents.C
blobbcd9e9b1dcd6a7dad769ac19cd2b7694a1ca5590
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 Application
26     stressComponents
28 Description
29     Calculates and writes the scalar fields of the six components of the stress
30     tensor sigma for each time.
32 \*---------------------------------------------------------------------------*/
34 #include "fvCFD.H"
35 #include "incompressible/singlePhaseTransportModel/singlePhaseTransportModel.H"
36 #include "zeroGradientFvPatchFields.H"
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 int main(int argc, char *argv[])
42     timeSelector::addOptions();
44 #   include "setRootCase.H"
45 #   include "createTime.H"
47     instantList timeDirs = timeSelector::select0(runTime, args);
49 #   include "createMesh.H"
51     forAll(timeDirs, timeI)
52     {
53         runTime.setTime(timeDirs[timeI], timeI);
55         Info<< "Time = " << runTime.timeName() << endl;
57         IOobject Uheader
58         (
59             "U",
60             runTime.timeName(),
61             mesh,
62             IOobject::MUST_READ
63         );
65         // Check U exists
66         if (Uheader.headerOk())
67         {
68             mesh.readUpdate();
70             Info<< "    Reading U" << endl;
71             volVectorField U(Uheader, mesh);
73 #           include "createPhi.H"
75             singlePhaseTransportModel laminarTransport(U, phi);
77             volSymmTensorField sigma
78             (
79                 IOobject
80                 (
81                     "sigma",
82                     runTime.timeName(),
83                     mesh,
84                     IOobject::NO_READ,
85                     IOobject::AUTO_WRITE
86                 ),
87                 laminarTransport.nu()*2*dev(symm(fvc::grad(U)))
88             );
91             volScalarField sigmaxx
92             (
93                 IOobject
94                 (
95                     "sigmaxx",
96                     runTime.timeName(),
97                     mesh,
98                     IOobject::NO_READ
99                 ),
100                 sigma.component(symmTensor::XX)
101             );
102             sigmaxx.write();
104             volScalarField sigmayy
105             (
106                 IOobject
107                 (
108                     "sigmayy",
109                     runTime.timeName(),
110                     mesh,
111                     IOobject::NO_READ
112                 ),
113                 sigma.component(symmTensor::YY)
114             );
115             sigmayy.write();
117             volScalarField sigmazz
118             (
119                 IOobject
120                 (
121                     "sigmazz",
122                     runTime.timeName(),
123                     mesh,
124                     IOobject::NO_READ
125                 ),
126                 sigma.component(symmTensor::ZZ)
127             );
128             sigmazz.write();
130             volScalarField sigmaxy
131             (
132                 IOobject
133                 (
134                     "sigmaxy",
135                     runTime.timeName(),
136                     mesh,
137                     IOobject::NO_READ
138                 ),
139                 sigma.component(symmTensor::XY)
140             );
141             sigmaxy.write();
143             volScalarField sigmaxz
144             (
145                 IOobject
146                 (
147                     "sigmaxz",
148                     runTime.timeName(),
149                     mesh,
150                     IOobject::NO_READ
151                 ),
152                 sigma.component(symmTensor::XZ)
153             );
154             sigmaxz.write();
156             volScalarField sigmayz
157             (
158                 IOobject
159                 (
160                     "sigmayz",
161                     runTime.timeName(),
162                     mesh,
163                     IOobject::NO_READ
164                 ),
165                 sigma.component(symmTensor::YZ)
166             );
167             sigmayz.write();
169             volVectorField Ub
170             (
171                 IOobject
172                 (
173                     "Ub",
174                     runTime.timeName(),
175                     mesh,
176                     IOobject::NO_READ
177                 ),
178                 U,
179                 zeroGradientFvPatchVectorField::typeName
180             );
181             Ub.correctBoundaryConditions();
182             Ub.write();
184             volScalarField sigmaUn
185             (
186                 IOobject
187                 (
188                     "sigmaUn",
189                     runTime.timeName(),
190                     mesh,
191                     IOobject::NO_READ
192                 ),
193                 0.0*sigma.component(symmTensor::YZ)
194             );
196             forAll(sigmaUn.boundaryField(), patchI)
197             {
198                 sigmaUn.boundaryField()[patchI] =
199                 (
200                     mesh.boundary()[patchI].nf()
201                   & sigma.boundaryField()[patchI]
202                 )().component(vector::X);
203             }
205             sigmaUn.write();
206         }
207         else
208         {
209             Info<< "    No U" << endl;
210         }
212         Info<< endl;
213     }
215     Info<< "End" << endl;
217     return 0;
221 // ************************************************************************* //