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 | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "SIBS.H"
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 void Foam::SIBS::SIMPR
31 (
32  const scalar xStart,
33  const scalarField& y,
34  const scalarField& dydx,
35  const scalarField& dfdx,
36  const scalarSquareMatrix& dfdy,
37  const scalar deltaX,
38  const label nSteps,
39  scalarField& yEnd
40 ) const
41 {
42  scalar h = deltaX/nSteps;
43 
44  scalarSquareMatrix a(n_);
45  for (label i=0; i<n_; i++)
46  {
47  for (label j=0; j<n_; j++)
48  {
49  a(i, j) = -h*dfdy(i, j);
50  }
51  ++a(i, i);
52  }
53 
54  labelList pivotIndices(n_);
55  LUDecompose(a, pivotIndices);
56 
57  for (label i=0; i<n_; i++)
58  {
59  yEnd[i] = h*(dydx[i] + h*dfdx[i]);
60  }
61 
62  LUBacksubstitute(a, pivotIndices, yEnd);
63 
64  scalarField del(yEnd);
65  scalarField ytemp(n_);
66 
67  for (label i=0; i<n_; i++)
68  {
69  ytemp[i] = y[i] + del[i];
70  }
71 
72  scalar x = xStart + h;
73 
74  odes_.derivatives(x, ytemp, yEnd);
75 
76  for (label nn=2; nn<=nSteps; nn++)
77  {
78  for (label i=0; i<n_; i++)
79  {
80  yEnd[i] = h*yEnd[i] - del[i];
81  }
82 
83  LUBacksubstitute(a, pivotIndices, yEnd);
84 
85  for (label i=0; i<n_; i++)
86  {
87  ytemp[i] += (del[i] += 2.0*yEnd[i]);
88  }
89 
90  x += h;
91 
92  odes_.derivatives(x, ytemp, yEnd);
93  }
94  for (label i=0; i<n_; i++)
95  {
96  yEnd[i] = h*yEnd[i] - del[i];
97  }
98 
99  LUBacksubstitute(a, pivotIndices, yEnd);
100 
101  for (label i=0; i<n_; i++)
102  {
103  yEnd[i] += ytemp[i];
104  }
105 }
106 
107 
108 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
const ODESystem & odes_
Reference to ODESystem.
Definition: ODESolver.H:58
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
List< label > labelList
A List of labels.
Definition: labelList.H:56
volScalarField scalarField(fieldObject, mesh)
volScalarField & h
Planck constant.
label n_
Size of the ODESystem (adjustable)
Definition: ODESolver.H:64
SquareMatrix< scalar > scalarSquareMatrix
virtual void derivatives(const scalar x, const scalarField &y, scalarField &dydx) const =0
Calculate the derivatives in dydx.
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
LU back-substitution with given source, returning the solution.