GAMGSolverScale.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-2017 OpenFOAM Foundation
9  Copyright (C) 2017-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "GAMGSolver.H"
30 #include "vector2D.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 void Foam::GAMGSolver::scale
35 (
37  solveScalarField& Acf,
38  const lduMatrix& A,
39  const FieldField<Field, scalar>& interfaceLevelBouCoeffs,
40  const lduInterfaceFieldPtrsList& interfaceLevel,
41  const solveScalarField& source,
42  const direction cmpt
43 ) const
44 {
45  A.Amul
46  (
47  Acf,
48  field,
49  interfaceLevelBouCoeffs,
50  interfaceLevel,
51  cmpt
52  );
53 
54 
55  const label nCells = field.size();
56  solveScalar* __restrict__ fieldPtr = field.begin();
57  const solveScalar* const __restrict__ sourcePtr = source.begin();
58  const solveScalar* const __restrict__ AcfPtr = Acf.begin();
59 
60 
61  solveScalar scalingFactorNum = 0.0;
62  solveScalar scalingFactorDenom = 0.0;
63 
64  for (label i=0; i<nCells; i++)
65  {
66  scalingFactorNum += sourcePtr[i]*fieldPtr[i];
67  scalingFactorDenom += AcfPtr[i]*fieldPtr[i];
68  }
69 
70  Vector2D<solveScalar> scalingVector(scalingFactorNum, scalingFactorDenom);
71  A.mesh().reduce(scalingVector, sumOp<Vector2D<solveScalar>>());
72 
73  const solveScalar sf =
74  scalingVector.x()
75  /stabilise(scalingVector.y(), pTraits<solveScalar>::vsmall);
76 
77  if (debug >= 2)
78  {
79  Pout<< sf << " ";
80  }
81 
82  const scalarField& D = A.diag();
83  const scalar* const __restrict__ DPtr = D.begin();
84 
85  for (label i=0; i<nCells; i++)
86  {
87  fieldPtr[i] = sf*fieldPtr[i] + (sourcePtr[i] - sf*AcfPtr[i])/DPtr[i];
88  }
89 }
90 
91 
92 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
A
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
Foam::Pout
prefixOSstream Pout
An Ostream wrapper for parallel output to std::cout.
Foam::lduInterfaceFieldPtrsList
UPtrList< const lduInterfaceField > lduInterfaceFieldPtrsList
List of coupled interface fields to be used in coupling.
Definition: lduInterfaceFieldPtrsList.H:44
Foam::stabilise
tmp< DimensionedField< scalar, GeoMesh > > stabilise(const DimensionedField< scalar, GeoMesh > &dsf, const dimensioned< scalar > &ds)
Definition: DimensionedScalarField.C:43
field
rDeltaTY field()
vector2D.H
Foam::solveScalarField
Field< solveScalar > solveScalarField
Definition: primitiveFieldsFwd.H:53
D
const dimensionedScalar & D
Definition: solveBulkSurfactant.H:4
Foam::direction
uint8_t direction
Definition: direction.H:47
GAMGSolver.H