Fixing indentation in applications/solvers/solidMechanics
[foam-extend-3.2.git] / applications / solvers / solidMechanics / elasticPlasticSolidFoam / elasticPlasticSolidFoam.C
blobcda9f25ef26b5c69c7764ce1fcc807249e9c5980
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     elasticPlasticSolidFoam
27 Description
28     Transient/steady-state segregated finite-volume solver for small strain
29     elastic plastic solid bodies.
31     Displacement increment field DU is solved for using a total Lagrangian
32     approach, also generating the strain tensor field epsilon, the plastic
33     strain field epsilonP and stress tensor field sigma.
35 Author
36     A. Karac UCD/Zenica
37     P. Cardiff UCD
38     Aitken relaxation by T. Tang DTU
40 \*---------------------------------------------------------------------------*/
42 #include "fvCFD.H"
43 #include "constitutiveModel.H"
44 #include "solidContactFvPatchVectorField.H"
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 int main(int argc, char *argv[])
50 #   include "setRootCase.H"
51 #   include "createTime.H"
52 #   include "createMesh.H"
53 #   include "createFields.H"
54 #   include "createHistory.H"
55 #   include "readDivDSigmaExpMethod.H"
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59     Info<< "\nStarting time loop\n" << endl;
61     while(runTime.loop())
62     {
63         Info<< "Time = " << runTime.timeName() << nl << endl;
65 #       include "readSolidMechanicsControls.H"
67         int iCorr = 0;
68         lduMatrix::solverPerformance solverPerf;
69         scalar initialResidual = 1.0;
70         scalar relativeResidual = 1.0;
71         scalar plasticResidual = 1.0;
72         lduMatrix::debug = 0;
74         do
75         {
76             DU.storePrevIter();
78 #           include "calculateDivDSigmaExp.H"
80             fvVectorMatrix DUEqn
81             (
82                 rho*fvm::d2dt2(DU)
83              ==
84                 fvm::laplacian(2*muf + lambdaf, DU, "laplacian(DDU,DU)")
85               + divDSigmaExp
86               - fvc::div(2*muf*(mesh.Sf() & fvc::interpolate(DEpsilonP)))
87             );
89             solverPerf = DUEqn.solve();
91             if (iCorr == 0)
92             {
93                 initialResidual = solverPerf.initialResidual();
94             }
96             if (aitkenRelax)
97             {
98 #               include "aitkenRelaxation.H"
99             }
100             else
101             {
102                 DU.relax();
103             }
105             gradDU = fvc::grad(DU);
107 #           include "calculateRelativeResidual.H"
108 #           include "calculateDEpsilonDSigma.H"
110             // correct plastic strain increment
111             rheology.correct();
113 #           include "calculatePlasticResidual.H"
115             if (iCorr % infoFrequency == 0)
116             {
117                 Info<< "\tTime " << runTime.value()
118                     << ", Corr " << iCorr
119                     //<< ", Solving for " << DU.name()
120                     // << " using " << solverPerf.solverName()
121                     << ", res = " << solverPerf.initialResidual()
122                     << ", rel res = " << relativeResidual
123                     << ", plastic res = " << plasticResidual;
124                 if (aitkenRelax)
125                 {
126                     Info<< ", aitken = " << aitkenTheta;
127                 }
128                 Info<< ", inner iters = " << solverPerf.nIterations() << endl;
129             }
130         }
131         while
132         (
133             iCorr++ < 2
134             ||
135             (
136                 //solverPerf.initialResidual() > convergenceTolerance
137                 relativeResidual > convergenceTolerance
138              && iCorr < nCorr
139             )
140         );
142         Info<< nl << "Time " << runTime.value() << ", Solving for " << DU.name()
143             << ", Initial residual = " << initialResidual
144             << ", Final residual = " << solverPerf.initialResidual()
145             << ", Final rel residual = " << relativeResidual
146             << ", No outer iterations " << iCorr << endl;
148         // Update total quantities
149         U += DU;
150         epsilon += DEpsilon;
151         epsilonP += rheology.DEpsilonP();
152         sigma += DSigma;
154         // Update yields stresses
155         rheology.updateYieldStress();
157 #       include "writeFields.H"
158 #       include "writeHistory.H"
160         Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
161             << "  ClockTime = " << runTime.elapsedClockTime() << " s"
162             << nl << endl;
163     }
165   Info<< "End\n" << endl;
167   return(0);
171 // ************************************************************************* //