00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <PETScMatrix.hpp>
00021
00022 void PETScMatrix::
00023 timesX(const BaseVector& X,
00024 BaseVector& Z) const
00025 {
00026 throw ErrorHandler(__FILE__, __LINE__,
00027 "not implemented",
00028 ErrorHandler::unexpected);
00029 }
00030
00031 PETScMatrix::
00032 PETScMatrix(const DoubleHashedMatrix& A)
00033 : BaseMatrix(BaseMatrix::petscMatrix, A.numberOfLines()),
00034 __petscMatrix(new Mat)
00035 {
00036 Mat& petscMatrix = *__petscMatrix;
00037 int argc = 1;
00038 char* myArgv[] = { "ff3d" };
00039 char** argv = myArgv;
00040 PetscInitialize(&argc, &argv, 0, 0);
00041
00042 size_t nz = 0;
00043 for (int i=0; i<int(__size); ++i) {
00044 nz = std::max(A.numberOfLineNonNull(i),nz);
00045 }
00046
00047 MatCreateSeqAIJ(PETSC_COMM_WORLD,
00048 A.numberOfLines(),
00049 A.numberOfColumns(),
00050 nz,
00051 0,
00052 &petscMatrix);
00053
00054 MatAssemblyBegin(petscMatrix, MAT_FINAL_ASSEMBLY);
00055
00056 std::vector<int> columns;
00057 std::vector<real_t> values;
00058 for (int i=0; i<int(__size); ++i) {
00059 for (DoubleHashedMatrix::const_iterator browsLine = A.beginOfLine(i);
00060 browsLine != A.endOfLine(i); ++browsLine) {
00061 const int j = browsLine.first();
00062 const real_t value = browsLine.second();
00063 columns.push_back(j);
00064 values.push_back(value);
00065 }
00066 MatSetValues(petscMatrix,
00067 1, &i, columns.size(), &columns[0],
00068 &values[0], INSERT_VALUES);
00069 columns.clear();
00070 values.clear();
00071 }
00072
00073 MatAssemblyEnd(petscMatrix, MAT_FINAL_ASSEMBLY);
00074 }
00075
00076 PETScMatrix::
00077 ~PETScMatrix()
00078 {
00079 MatDestroy(*__petscMatrix);
00080 delete __petscMatrix;
00081 }