PCGgpu.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  Copyright : (C) 2011 Symscape
3  Website : www.symscape.com
4 -------------------------------------------------------------------------------
5 License
6  This file is part of OpenFOAM.
7 
8  OpenFOAM is free software: you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
14  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16  for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
20 
21 \*---------------------------------------------------------------------------*/
22 
23 #include "ofgpu/pcg.h"
24 #include "ofgpu/sparsematrixargs.h"
25 
26 #include "PCGgpu.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32  defineTypeNameAndDebug(PCGgpu, 0);
33 
34  lduMatrix::solver::addsymMatrixConstructorToTable<PCGgpu>
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 (
43  const word& fieldName,
44  const lduMatrix& matrix,
45  const FieldField<Field, scalar>& interfaceBouCoeffs,
46  const FieldField<Field, scalar>& interfaceIntCoeffs,
47  const lduInterfaceFieldPtrsList& interfaces,
48  const dictionary& solverControls
49 )
50 :
51  PCG
52  (
53  fieldName,
54  matrix,
55  interfaceBouCoeffs,
56  interfaceIntCoeffs,
57  interfaces,
58  solverControls
59  )
60 {}
61 
62 
63 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
64 
66 (
68  const scalarField& source,
69  const direction cmpt
70 ) const
71 {
72  scalar initialResidual(0.);
73  scalar finalResidual(0.);
74  label iterationsPerformed(0);
75  bool converged(false);
76 
77  lduAddressing const & lduAddr = matrix_.lduAddr();
78  word const preconditionerName = lduMatrix::preconditioner::getName(controlDict_);
79 
80  ofgpuPCGsolve(ofgpu::SparseMatrixArgs(preconditionerName.c_str(),
81  psi.size(), lduAddr.lowerAddr().size(),
82  lduAddr.losortStartAddr().begin(), lduAddr.losortAddr().begin(), lduAddr.lowerAddr().begin(), matrix_.lower().begin(),
83  matrix_.diag().begin(),
84  lduAddr.ownerStartAddr().begin(), lduAddr.upperAddr().begin(), matrix_.upper().begin(),
85  psi.begin(),
86  source.begin(),
87  maxIter_, tolerance_, relTol_,
88  initialResidual, finalResidual, iterationsPerformed, converged));
89 
90  // --- Setup class containing solver performance data
91  solverPerformance solverPerf
92  (
93  preconditionerName + typeName,
94  fieldName_,
95  initialResidual,
96  finalResidual,
97  iterationsPerformed,
98  converged
99  );
100 
101  return solverPerf;
102 }
103 
104 // ************************************************************************* //
Foam::lduAddressing
The class contains the addressing required by the lduMatrix: upper, lower and losort.
Definition: lduAddressing.H:111
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::FieldField
Generic field type.
Definition: FieldField.H:51
Foam::PCG
Preconditioned conjugate gradient solver for symmetric lduMatrices using a run-time selectable precon...
Definition: PCG.H:49
Foam::lduMatrix
lduMatrix is a general matrix class in which the coefficients are stored as three arrays,...
Definition: lduMatrix.H:77
Foam::PCGgpu::PCGgpu
PCGgpu(const PCGgpu &)
Disallow default bitwise copy construct.
PCGgpu.H
Foam::lduAddressing::losortStartAddr
const labelUList & losortStartAddr() const
Return losort start addressing.
Definition: lduAddressing.C:207
Foam::lduAddressing::ownerStartAddr
const labelUList & ownerStartAddr() const
Return owner start addressing.
Definition: lduAddressing.C:196
Foam::lduAddressing::upperAddr
virtual const labelUList & upperAddr() const =0
Return upper addressing.
Foam::UList::begin
iterator begin()
Return an iterator to begin traversing the UList.
Definition: UListI.H:216
Foam::lduAddressing::losortAddr
const labelUList & losortAddr() const
Return losort addressing.
Definition: lduAddressing.C:185
Foam::addPCGgpuAsymMatrixConstructorToTable_
lduMatrix::solver::addsymMatrixConstructorToTable< PCGgpu > addPCGgpuAsymMatrixConstructorToTable_
Definition: PCGgpu.C:35
Foam::label
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
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::PCGgpu::solve
virtual solverPerformance solve(scalarField &psi, const scalarField &source, const direction cmpt=0) const
Solve the matrix with this solver.
Definition: PCGgpu.C:66
Foam::UPtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:53
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
psi
const volScalarField & psi
Definition: setRegionFluidFields.H:13
Foam::lduAddressing::lowerAddr
virtual const labelUList & lowerAddr() const =0
Return lower addressing.
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::UList::size
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
Foam::SolverPerformance
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics.
Definition: SolverPerformance.H:49
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)