SIMPR.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "SIBS.H"
29
30// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31
32void Foam::SIBS::SIMPR
33(
34 const scalar xStart,
35 const scalarField& y,
36 const scalarField& dydx,
37 const scalarField& dfdx,
38 const scalarSquareMatrix& dfdy,
39 const scalar deltaX,
40 const label nSteps,
41 scalarField& yEnd
42) const
43{
44 scalar h = deltaX/nSteps;
45
47 for (label i=0; i<n_; i++)
48 {
49 for (label j=0; j<n_; j++)
50 {
51 a(i, j) = -h*dfdy(i, j);
52 }
53 ++a(i, i);
54 }
55
56 labelList pivotIndices(n_);
57 LUDecompose(a, pivotIndices);
58
59 for (label i=0; i<n_; i++)
60 {
61 yEnd[i] = h*(dydx[i] + h*dfdx[i]);
62 }
63
64 LUBacksubstitute(a, pivotIndices, yEnd);
65
66 scalarField del(yEnd);
67 scalarField ytemp(n_);
68
69 for (label i=0; i<n_; i++)
70 {
71 ytemp[i] = y[i] + del[i];
72 }
73
74 scalar x = xStart + h;
75
76 odes_.derivatives(x, ytemp, yEnd);
77
78 for (label nn=2; nn<=nSteps; nn++)
79 {
80 for (label i=0; i<n_; i++)
81 {
82 yEnd[i] = h*yEnd[i] - del[i];
83 }
84
85 LUBacksubstitute(a, pivotIndices, yEnd);
86
87 for (label i=0; i<n_; i++)
88 {
89 ytemp[i] += (del[i] += 2.0*yEnd[i]);
90 }
91
92 x += h;
93
94 odes_.derivatives(x, ytemp, yEnd);
95 }
96 for (label i=0; i<n_; i++)
97 {
98 yEnd[i] = h*yEnd[i] - del[i];
99 }
100
101 LUBacksubstitute(a, pivotIndices, yEnd);
102
103 for (label i=0; i<n_; i++)
104 {
105 yEnd[i] += ytemp[i];
106 }
107}
108
109
110// ************************************************************************* //
scalar y
label n_
Size of the ODESystem (adjustable)
Definition: ODESolver.H:70
const ODESystem & odes_
Reference to ODESystem.
Definition: ODESolver.H:64
virtual void derivatives(const scalar x, const scalarField &y, scalarField &dydx) const =0
Calculate the derivatives in dydx.
List< label > labelList
A List of labels.
Definition: List.H:66
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
SquareMatrix< scalar > scalarSquareMatrix
volScalarField & h