45 namespace MultiRegions
54 string GlobalLinSysPETScFull::className
57 GlobalLinSysPETScFull::create,
58 "PETSc Full Matrix.");
62 GlobalLinSysPETScFull::GlobalLinSysPETScFull(
64 const std::weak_ptr<ExpList> &pExp,
65 const std::shared_ptr<AssemblyMap> &pLocToGloMap)
69 const int nDirDofs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
71 int i, j, n, cnt, gid1, gid2, loc_lda;
77 pLocToGloMap->GetGlobalToUniversalMapUnique(),
81 SetUpMatVec(pLocToGloMap->GetNumGlobalCoeffs(), nDirDofs);
90 for(n = cnt = 0; n <
m_expList.lock()->GetNumElmts(); ++n)
93 loc_lda = loc_mat->GetRows();
95 for(i = 0; i < loc_lda; ++i)
97 gid1 = pLocToGloMap->GetLocalToGlobalMap(cnt+i) - nDirDofs;
98 sign1 = pLocToGloMap->GetLocalToGlobalSign(cnt + i);
102 for(j = 0; j < loc_lda; ++j)
104 gid2 = pLocToGloMap->GetLocalToGlobalMap(cnt + j)
106 sign2 = pLocToGloMap->GetLocalToGlobalSign(cnt + j);
110 value = sign1*sign2*(*loc_mat)(i,j);
112 m_matrix, gid1ro, gid2ro, value, ADD_VALUES);
121 MatAssemblyBegin(
m_matrix, MAT_FINAL_ASSEMBLY);
122 MatAssemblyEnd (
m_matrix, MAT_FINAL_ASSEMBLY);
141 std::shared_ptr<MultiRegions::ExpList> expList =
m_expList.lock();
142 bool dirForcCalculated = (bool) pDirForcing.size();
143 int nDirDofs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
144 int nGlobDofs = pLocToGloMap->GetNumGlobalCoeffs();
145 int nLocDofs = pLocToGloMap->GetNumLocalCoeffs();
153 expList->GetComm()->GetRowComm()->AllReduce(
159 if(dirForcCalculated)
162 ASSERTL0(pDirForcing.size() >= nLocDofs,
163 "DirForcing is not of sufficient size. Is it in local space?");
165 pDirForcing, 1,tmp1, 1);
171 expList->GeneralMatrixOp(
182 int offset = expList->GetCoeff_Offset(n);
186 for(rBC = r.second;rBC; rBC = rBC->next)
188 vExp->AddRobinTraceContribution(rBC->m_robinID,
189 rBC->m_robinPrimitiveCoeffs,
191 tmploc = tmp + offset);
195 Vmath::Vsub(nLocDofs, pLocInput, 1, tmp, 1, tmp1, 1);
198 pLocToGloMap->Assemble(tmp1,tmp);
202 pLocToGloMap->GlobalToLocal(global,tmp);
205 Vmath::Vadd(nLocDofs, tmp, 1, pLocOutput, 1, pLocOutput, 1);
209 pLocToGloMap->Assemble(pLocInput,tmp);
211 pLocToGloMap->GlobalToLocal(global,pLocOutput);
226 std::shared_ptr<MultiRegions::ExpList> expList =
m_expList.lock();
#define ASSERTL0(condition, msg)
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
const std::weak_ptr< ExpList > m_expList
Local Matrix System.
const std::map< int, RobinBCInfoSharedPtr > m_robinBCInfo
Robin boundary info.
void SolveLinearSystem(const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const AssemblyMapSharedPtr &locToGloMap, const int pNumDir=0)
Solve the linear system for given input and output vectors.
const GlobalLinSysKey m_linSysKey
Key associated with this linear system.
DNekScalMatSharedPtr GetBlock(unsigned int n)
Describe a linear system.
virtual ~GlobalLinSysPETScFull()
virtual void v_Solve(const Array< OneD, const NekDouble > &in, Array< OneD, NekDouble > &out, const AssemblyMapSharedPtr &locToGloMap, const Array< OneD, const NekDouble > &dirForcing=NullNekDouble1DArray)
Solve the linear system for given input and output vectors using a specified local to global map.
std::shared_ptr< AssemblyMap > m_locToGloMap
virtual void v_DoMatrixMultiply(const Array< OneD, const NekDouble > &input, Array< OneD, NekDouble > &output)
Apply matrix-vector multiplication using local approach and the assembly map.
A PETSc global linear system.
std::vector< int > m_reorderedMap
Reordering that takes universal IDs to a unique row in the PETSc matrix.
void SetUpScatter()
Set up PETSc local (equivalent to Nektar++ global) and global (equivalent to universal) scatter maps.
Mat m_matrix
PETSc matrix object.
void SetUpSolver(NekDouble tolerance)
Set up KSP solver object.
void SetUpMatVec(int nGlobal, int nDir)
Construct PETSc matrix and vector handles.
void CalculateReordering(const Array< OneD, const int > &glo2uniMap, const Array< OneD, const int > &glo2unique, const AssemblyMapSharedPtr &pLocToGloMap)
Calculate a reordering of universal IDs for PETSc.
std::shared_ptr< Expansion > ExpansionSharedPtr
std::shared_ptr< RobinBCInfo > RobinBCInfoSharedPtr
GlobalLinSysFactory & GetGlobalLinSysFactory()
std::shared_ptr< AssemblyMap > AssemblyMapSharedPtr
The above copyright notice and this permission notice shall be included.
std::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.