Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / applications / utilities / postProcessing / stressField / solidStress / solidStress.C
blob31ac650e07dea6acf7b0b26e0b85664dd6fb78ad
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
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 Application
25     solidStress
27 Description
28     Calculates and writes the scalar fields of the six components of the stress
29     tensor sigma for each time for linear stress analysis calculations.
31 \*---------------------------------------------------------------------------*/
33 #include "fvCFD.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 int main(int argc, char *argv[])
39 #   include "addTimeOptions.H"
40 #   include "setRootCase.H"
42 #   include "createTime.H"
44     // Get times list
45     instantList Times = runTime.times();
47     // set startTime and endTime depending on -time and -latestTime options
48 #   include "checkTimeOptions.H"
50     runTime.setTime(Times[startTime], startTime);
52 #   include "createMesh.H"
53 #   include "readMechanicalProperties.H"
55     for (label i = startTime; i < endTime; i++)
56     {
57         runTime.setTime(Times[i], i);
59         Info<< "Time = " << runTime.timeName() << endl;
61         mesh.readUpdate();
63         IOobject Uheader
64         (
65             "U",
66             runTime.timeName(),
67             mesh,
68             IOobject::MUST_READ
69         );
71         // Check U exists
72         if (Uheader.headerOk())
73         {
74             mesh.readUpdate();
76             Info<< "    Reading U" << endl;
77             volVectorField U(Uheader, mesh);
79             volTensorField gradU = fvc::grad(U);
81             volSymmTensorField sigma =
82                 rho*(2.0*mu*symm(gradU) + lambda*I*tr(gradU));
84             volScalarField sigmaEq
85             (
86                 IOobject
87                 (
88                     "sigmaEq",
89                     runTime.timeName(),
90                     mesh,
91                     IOobject::NO_READ,
92                     IOobject::AUTO_WRITE
93                 ),
94                 sqrt((3.0/2.0)*magSqr(dev(sigma)))
95             );
97             Info<< "Max sigmaEq = " << max(sigmaEq).value()
98                 << endl;
99             sigmaEq.write();
101             volScalarField sigmaxx
102             (
103                 IOobject
104                 (
105                     "sigmaxx",
106                     runTime.timeName(),
107                     mesh,
108                     IOobject::NO_READ,
109                     IOobject::AUTO_WRITE
110                 ),
111                 sigma.component(symmTensor::XX)
112             );
113             sigmaxx.write();
115             volScalarField sigmayy
116             (
117                 IOobject
118                 (
119                     "sigmayy",
120                     runTime.timeName(),
121                     mesh,
122                     IOobject::NO_READ,
123                     IOobject::AUTO_WRITE
124                 ),
125                 sigma.component(symmTensor::YY)
126             );
127             sigmayy.write();
129             volScalarField sigmazz
130             (
131                 IOobject
132                 (
133                     "sigmazz",
134                     runTime.timeName(),
135                     mesh,
136                     IOobject::NO_READ,
137                     IOobject::AUTO_WRITE
138                 ),
139                 sigma.component(symmTensor::ZZ)
140             );
141             sigmazz.write();
143             volScalarField sigmaxy
144             (
145                 IOobject
146                 (
147                     "sigmaxy",
148                     runTime.timeName(),
149                     mesh,
150                     IOobject::NO_READ,
151                     IOobject::AUTO_WRITE
152                 ),
153                 sigma.component(symmTensor::XY)
154             );
155             sigmaxy.write();
157             volScalarField sigmaxz
158             (
159                 IOobject
160                 (
161                     "sigmaxz",
162                     runTime.timeName(),
163                     mesh,
164                     IOobject::NO_READ,
165                     IOobject::AUTO_WRITE
166                 ),
167                 sigma.component(symmTensor::XZ)
168             );
169             sigmaxz.write();
171             volScalarField sigmayz
172             (
173                 IOobject
174                 (
175                     "sigmayz",
176                     runTime.timeName(),
177                     mesh,
178                     IOobject::NO_READ,
179                     IOobject::AUTO_WRITE
180                 ),
181                 sigma.component(symmTensor::YZ)
182             );
183             sigmayz.write();
184        }
185         else
186         {
187             Info<< "    No U" << endl;
188         }
190         Info<< endl;
191     }
193     Info<< "End" << endl;
195     return(0);
199 // ************************************************************************* //