4#if defined(PETSC_Z) || defined(PETSC_D)
6#ifndef DISTRIBUTEDLINEARSYSTEM_H
7#define DISTRIBUTEDLINEARSYSTEM_H
19 template <
typename _Type>
20 class DistributedLinearSystem {
27 DistributedLinearSystem(DistributedMatrix<_Type>* pA, DistributedVector<_Type>* pB ) {
30 KSPCreate(PETSC_COMM_WORLD,&m_ksp);
36 ~DistributedLinearSystem(){
44 KSPSetOperators(m_ksp,*(m_pA->get_pMat()),*(m_pA->get_pMat()));
62 KSPSetFromOptions(m_ksp);
65 KSPSolve(m_ksp,*(m_pB->get_pVec()),*(m_pB->get_pVec()));
66 KSPView(m_ksp, PETSC_VIEWER_STDOUT_WORLD);
70 KSPView(m_ksp, PETSC_VIEWER_STDOUT_WORLD);
76 Vec get_seq_solution() {
81 VecScatterCreateToAll(*(m_pB->get_pVec()), &ctx, &v_seq);
83 VecScatterBegin(ctx, *(m_pB->get_pVec()), v_seq, INSERT_VALUES, SCATTER_FORWARD);
84 VecScatterEnd(ctx, *(m_pB->get_pVec()), v_seq, INSERT_VALUES, SCATTER_FORWARD);
86 VecScatterDestroy(&ctx);
92 DenseVector<_Type> get_solution() {
94 Vec seq_soln = get_seq_solution();
97 VecGetArray(seq_soln,&array);
100 VecGetSize(seq_soln,&size);
101 DenseVector<_Type> soln(size,array);
108 // construct using the PETSc matrix
109 KSPSetOperators(m_ksp,*(m_pA->get_pMat()),*(m_pA->get_pMat()));
111 KSPSetType(m_ksp,KSPPREONLY);
113 KSPGetPC(m_ksp,&m_pc);
114 // hardwire a DIRECT SOLVER via MUMPS
115 PCSetType(m_pc,PCLU);
116 PCFactorSetMatSolverType(m_pc,MATSOLVERMUMPS);
117 PCFactorSetUpMatSolverType(m_pc);
118 //call MatGetFactor() to create F
119 PCFactorGetMatrix(m_pc,&m_F);
120 // allow override using command line options?
121 KSPSetFromOptions(m_ksp);
126 void solve_using_factorisation();
131 DistributedMatrix<_Type>* m_pA;
133 DistributedVector<_Type>* m_pB;
A matrix class that constructs a SPARSE/DISTRIBUTED matrix using PETSc.
A class that constructs a SPARSE/DISTRIBUTED vector using PETSc.
The collection of CppNoddy exceptions.
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...