1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "cudaSolver.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 defineTypeNameAndDebug(cudaSolver, 0);
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 Foam::cudaSolver::cudaSolver
41 const word& fieldName,
42 const lduMatrix& matrix,
43 const FieldField<Field, scalar>& coupleBouCoeffs,
44 const FieldField<Field, scalar>& coupleIntCoeffs,
45 const lduInterfaceFieldPtrsList& interfaces,
46 const dictionary& dict
61 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
63 cuspEquationSystem Foam::cudaSolver::createSymCuspMatrix
65 const lduMatrix& matrix,
70 cuspEquationSystem ces;
71 ces.nCells = x.size();
72 ces.nFaces = matrix.lower().size();
74 ces.A = cusp::coo_matrix<IndexType, ValueType, hostMemorySpace>
78 ces.nCells+2*ces.nFaces
80 ces.X = cusp::array1d< ValueType, hostMemorySpace>(ces.nCells);
81 ces.B = cusp::array1d< ValueType, hostMemorySpace>(ces.nCells);
83 // Copy values of lduMatrix diag to A COO matrix
86 matrix.diag().begin(),
91 // Copy values of lduMatrix lower to A COO matrix
94 matrix.lower().begin(),
96 ces.A.values.begin()+ces.nCells
99 // Since matrix is symmetric, do not copy upper values to save time
100 // -> performed on GPU
101 // Copy row indices of lower into A COO matrix
104 matrix.lduAddr().upperAddr().begin(),
105 matrix.lduAddr().upperAddr().end(),
106 ces.A.row_indices.begin()+ces.nCells
108 // Copy column indices of lower into A COO matrix
111 matrix.lduAddr().lowerAddr().begin(),
112 matrix.lduAddr().lowerAddr().end(),
113 ces.A.column_indices.begin()+ces.nCells
116 // Do not initialize the row and column values of diag to save time
117 // -> performed on GPU
118 // Copy x of lower into x vector
119 thrust::copy(x.begin(), x.end(), ces.X.begin());
120 // Copy b of lower into b vector
121 thrust::copy(b.begin(), b.end(), ces.B.begin());
126 cuspEquationSystem Foam::cudaSolver::createAsymCuspMatrix
128 const lduMatrix& matrix,
129 const scalarField& x,
133 cuspEquationSystem ces;
134 ces.nCells = x.size();
135 ces.nFaces = matrix.lower().size();
137 ces.A = cusp::coo_matrix<IndexType, ValueType, hostMemorySpace>
141 ces.nCells + 2*ces.nFaces
143 ces.X = cusp::array1d< ValueType, hostMemorySpace>(ces.nCells);
144 ces.B = cusp::array1d< ValueType, hostMemorySpace>(ces.nCells);
146 // Copy values from the lduMatrix to our equation system
147 // Copy values of lduMatrix diag to A COO matrix
150 matrix.diag().begin(),
155 // Copy values of lduMatrix lower to A COO matrix
158 matrix.lower().begin(),
159 matrix.lower().end(),
160 ces.A.values.begin() + ces.nCells
163 // Copy values of lduMatrix upper to A COO matrix
166 matrix.upper().begin(),
167 matrix.upper().end(),
168 ces.A.values.begin() + ces.nCells + ces.nFaces
171 // Copy row and column indices of lower and upper to our equations system
172 // do not initialize the row and column values of diag to save time
173 // -> performed on GPU
175 // Copy row indices of lower into A COO matrix
178 matrix.lduAddr().upperAddr().begin(),
179 matrix.lduAddr().upperAddr().end(),
180 ces.A.row_indices.begin() + ces.nCells
183 // Copy column indices of lower into A COO matrix
186 matrix.lduAddr().lowerAddr().begin(),
187 matrix.lduAddr().lowerAddr().end(),
188 ces.A.column_indices.begin() + ces.nCells
191 // Copy row indices of upper into A COO matrix
194 matrix.lduAddr().lowerAddr().begin(),
195 matrix.lduAddr().lowerAddr().end(),
196 ces.A.row_indices.begin() + ces.nCells + ces.nFaces
199 // Copy column indices of upper into A COO matrix
202 matrix.lduAddr().upperAddr().begin(),
203 matrix.lduAddr().upperAddr().end(),
204 ces.A.column_indices.begin() + ces.nCells + ces.nFaces
207 // Copy x of lower into x vector
208 thrust::copy(x.begin(), x.end(), ces.X.begin());
209 // Copy b of lower into b vector
210 thrust::copy(b.begin(), b.end(), ces.B.begin());
214 cudaSolverPerformance Foam::cudaSolver::cudaSolverPerformanceDefault() const
216 cudaSolverPerformance csp;
226 csp.converged = false;
227 csp.singular = false;
229 csp.debugCusp = false;
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238 // ************************************************************************* //