1 /**********************************************************************\
2 ______ __ __ _______ _______ __ __ __ __ __ ___
3 / || | | | | ____|| ____|| | | | | \ | | | |/ /
4 | ,----'| | | | | |__ | |__ | | | | | \| | | ' /
5 | | | | | | | __| | __| | | | | | . ` | | <
6 | `----.| `--' | | | | | | `----.| | | |\ | | . \
7 \______| \______/ |__| |__| |_______||__| |__| \__| |__|\__\
11 cufflink is a library for linking numerical methods based on Nvidia's
12 Compute Unified Device Architecture (CUDA™) C/C++ programming language
15 Please note that cufflink is not approved or endorsed by ESI-OpenCFD®
16 Limited, the owner of the OpenFOAM® and OpenCFD® trademarks and
17 producer of OpenFOAM® software.
19 The official web-site of OpenCFD® Limited is www.openfoam.com .
21 ------------------------------------------------------------------------
22 This file is part of cufflink.
24 cufflink is free software: you can redistribute it and/or modify
25 it under the terms of the GNU General Public License as published by
26 the Free Software Foundation, either version 3 of the License, or
27 (at your option) any later version.
29 cufflink is distributed in the hope that it will be useful,
30 but WITHOUT ANY WARRANTY; without even the implied warranty of
31 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 GNU General Public License for more details.
34 You should have received a copy of the GNU General Public License
35 along with cufflink. If not, see <http://www.gnu.org/licenses/>.
38 Daniel P. Combest. All rights reserved.
39 Modifications by Dominik Christ, Wikki Ltd.
42 diagonal preconditioned conjugate gradient
43 solver for symmetric Matrices using a CUSP CUDA™ based solver.
45 \**********************************************************************/
48 // Build the normfactor as foam-extend does in file
49 // ($FOAM_SRC/foam/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C)
51 //all variables will be deleted once out of scope
54 //compute average of x vector
55 ValueType xRef = thrust::reduce
58 X.begin() + A.num_rows
59 )/ValueType(A.num_rows);
61 //vector of average X values
62 cusp::array1d<ValueType,MemorySpace> xBar(N,xRef);
65 cusp::array1d<ValueType,MemorySpace> yBar(N);
67 //compute ybar<-A*xBar
68 cusp::multiply(A, xBar, yBar);
70 cusp::array1d<ValueType,MemorySpace> ymyBar(N); // holds y - yBar
71 cusp::array1d<ValueType,MemorySpace> bmyBar(N); // holds b - yBar
73 // Calculate: ymyBar <- y - yBar
74 cusp::blas::axpby(y, yBar, ymyBar, ValueType(1), ValueType(-1));
75 // Calculate: bmyBar <- b - yBar
76 cusp::blas::axpby(B, yBar, bmyBar, ValueType(1), ValueType(-1));
78 //compute norm factor exactly as OpenFOAM does
79 normFactor = cusp::blas::nrm2(ymyBar) + cusp::blas::nrm2(bmyBar) + SMALL;
81 if (solverPerf->debugCusp)
83 std::cout<<" Normalisation factor = "<<normFactor<<"\n";