1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "cudaSolver.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 defineTypeNameAndDebug(cudaSolver, 0);
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 Foam::cudaSolver::cudaSolver
42 const word& fieldName,
43 const lduMatrix& matrix,
44 const FieldField<Field, scalar>& coupleBouCoeffs,
45 const FieldField<Field, scalar>& coupleIntCoeffs,
46 const lduInterfaceFieldPtrsList& interfaces,
47 const dictionary& dict
62 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
64 cuspEquationSystem Foam::cudaSolver::createSymCuspMatrix
66 const lduMatrix& matrix,
71 cuspEquationSystem ces;
72 ces.nCells = x.size();
73 ces.nFaces = matrix.lower().size();
75 ces.A = cusp::coo_matrix<IndexType, ValueType, hostMemorySpace>
79 ces.nCells+2*ces.nFaces
81 ces.X = cusp::array1d< ValueType, hostMemorySpace>(ces.nCells);
82 ces.B = cusp::array1d< ValueType, hostMemorySpace>(ces.nCells);
84 // Copy values of lduMatrix diag to A COO matrix
87 matrix.diag().begin(),
92 // Copy values of lduMatrix lower to A COO matrix
95 matrix.lower().begin(),
97 ces.A.values.begin()+ces.nCells
100 // Since matrix is symmetric, do not copy upper values to save time
101 // -> performed on GPU
102 // Copy row indices of lower into A COO matrix
105 matrix.lduAddr().upperAddr().begin(),
106 matrix.lduAddr().upperAddr().end(),
107 ces.A.row_indices.begin()+ces.nCells
109 // Copy column indices of lower into A COO matrix
112 matrix.lduAddr().lowerAddr().begin(),
113 matrix.lduAddr().lowerAddr().end(),
114 ces.A.column_indices.begin()+ces.nCells
117 // Do not initialize the row and column values of diag to save time
118 // -> performed on GPU
119 // Copy x of lower into x vector
120 thrust::copy(x.begin(), x.end(), ces.X.begin());
121 // Copy b of lower into b vector
122 thrust::copy(b.begin(), b.end(), ces.B.begin());
127 cuspEquationSystem Foam::cudaSolver::createAsymCuspMatrix
129 const lduMatrix& matrix,
130 const scalarField& x,
134 cuspEquationSystem ces;
135 ces.nCells = x.size();
136 ces.nFaces = matrix.lower().size();
138 ces.A = cusp::coo_matrix<IndexType, ValueType, hostMemorySpace>
142 ces.nCells + 2*ces.nFaces
144 ces.X = cusp::array1d< ValueType, hostMemorySpace>(ces.nCells);
145 ces.B = cusp::array1d< ValueType, hostMemorySpace>(ces.nCells);
147 // Copy values from the lduMatrix to our equation system
148 // Copy values of lduMatrix diag to A COO matrix
151 matrix.diag().begin(),
156 // Copy values of lduMatrix lower to A COO matrix
159 matrix.lower().begin(),
160 matrix.lower().end(),
161 ces.A.values.begin() + ces.nCells
164 // Copy values of lduMatrix upper to A COO matrix
167 matrix.upper().begin(),
168 matrix.upper().end(),
169 ces.A.values.begin() + ces.nCells + ces.nFaces
172 // Copy row and column indices of lower and upper to our equations system
173 // do not initialize the row and column values of diag to save time
174 // -> performed on GPU
176 // Copy row indices of lower into A COO matrix
179 matrix.lduAddr().upperAddr().begin(),
180 matrix.lduAddr().upperAddr().end(),
181 ces.A.row_indices.begin() + ces.nCells
184 // Copy column indices of lower into A COO matrix
187 matrix.lduAddr().lowerAddr().begin(),
188 matrix.lduAddr().lowerAddr().end(),
189 ces.A.column_indices.begin() + ces.nCells
192 // Copy row indices of upper into A COO matrix
195 matrix.lduAddr().lowerAddr().begin(),
196 matrix.lduAddr().lowerAddr().end(),
197 ces.A.row_indices.begin() + ces.nCells + ces.nFaces
200 // Copy column indices of upper into A COO matrix
203 matrix.lduAddr().upperAddr().begin(),
204 matrix.lduAddr().upperAddr().end(),
205 ces.A.column_indices.begin() + ces.nCells + ces.nFaces
208 // Copy x of lower into x vector
209 thrust::copy(x.begin(), x.end(), ces.X.begin());
210 // Copy b of lower into b vector
211 thrust::copy(b.begin(), b.end(), ces.B.begin());
215 cudaSolverPerformance Foam::cudaSolver::cudaSolverPerformanceDefault() const
217 cudaSolverPerformance csp;
227 csp.converged = false;
228 csp.singular = false;
230 csp.debugCusp = false;
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 // ************************************************************************* //