Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Attributes | List of all members
Nektar::MultiRegions::GlobalLinSysPETScFull Class Reference

A global linear system. More...

#include <GlobalLinSysPETScFull.h>

Inheritance diagram for Nektar::MultiRegions::GlobalLinSysPETScFull:
[legend]

Public Member Functions

 GlobalLinSysPETScFull (const GlobalLinSysKey &pLinSysKey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
 Constructor for full direct matrix solve. More...
 
 ~GlobalLinSysPETScFull () override=default
 
- Public Member Functions inherited from Nektar::MultiRegions::GlobalLinSysPETSc
 GlobalLinSysPETSc (const GlobalLinSysKey &pKey, const std::weak_ptr< ExpList > &pExp, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
 Constructor for full direct matrix solve. More...
 
 ~GlobalLinSysPETSc () override
 Clean up PETSc objects. More...
 
- Public Member Functions inherited from Nektar::MultiRegions::GlobalLinSys
 GlobalLinSys (const GlobalLinSysKey &pKey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
 Constructor for full direct matrix solve. More...
 
virtual ~GlobalLinSys ()
 
const GlobalLinSysKeyGetKey (void) const
 Returns the key associated with the system. More...
 
const std::weak_ptr< ExpList > & GetLocMat (void) const
 
void InitObject ()
 
void Initialise (const std::shared_ptr< AssemblyMap > &pLocToGloMap)
 
void 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. More...
 
std::shared_ptr< GlobalLinSysGetSharedThisPtr ()
 Returns a shared pointer to the current object. More...
 
int GetNumBlocks ()
 
DNekScalMatSharedPtr GetBlock (unsigned int n)
 
void DropBlock (unsigned int n)
 
DNekScalBlkMatSharedPtr GetStaticCondBlock (unsigned int n)
 
void DropStaticCondBlock (unsigned int n)
 
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. More...
 

Static Public Member Functions

static GlobalLinSysSharedPtr create (const GlobalLinSysKey &pLinSysKey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
 Creates an instance of this class. More...
 

Static Public Attributes

static std::string className
 Name of class. More...
 

Protected Member Functions

void v_Solve (const Array< OneD, const NekDouble > &in, Array< OneD, NekDouble > &out, const AssemblyMapSharedPtr &locToGloMap, const Array< OneD, const NekDouble > &dirForcing=NullNekDouble1DArray) override
 Solve the linear system for given input and output vectors using a specified local to global map. More...
 
void v_DoMatrixMultiply (const Array< OneD, const NekDouble > &input, Array< OneD, NekDouble > &output) override
 Apply matrix-vector multiplication using local approach and the assembly map. More...
 
- Protected Member Functions inherited from Nektar::MultiRegions::GlobalLinSysPETSc
void SetUpScatter ()
 Set up PETSc local (equivalent to Nektar++ global) and global (equivalent to universal) scatter maps. More...
 
void SetUpMatVec (int nGlobal, int nDir)
 Construct PETSc matrix and vector handles. More...
 
void SetUpSolver (NekDouble tolerance)
 Set up KSP solver object. More...
 
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. More...
 
void v_SolveLinearSystem (const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const AssemblyMapSharedPtr &locToGloMap, const int pNumDir) override
 Solve linear system using PETSc. More...
 
virtual void v_DoMatrixMultiply (const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput)=0
 
- Protected Member Functions inherited from Nektar::MultiRegions::GlobalLinSys
virtual void v_Solve (const Array< OneD, const NekDouble > &in, Array< OneD, NekDouble > &out, const AssemblyMapSharedPtr &locToGloMap, const Array< OneD, const NekDouble > &dirForcing=NullNekDouble1DArray)=0
 Solve a linear system based on mapping. More...
 
virtual void v_SolveLinearSystem (const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const AssemblyMapSharedPtr &locToGloMap, const int pNumDir)=0
 Solve a basic matrix system. More...
 
virtual void v_InitObject ()
 
virtual void v_Initialise (const std::shared_ptr< AssemblyMap > &pLocToGloMap)
 
virtual int v_GetNumBlocks ()
 Get the number of blocks in this system. More...
 
virtual DNekScalMatSharedPtr v_GetBlock (unsigned int n)
 Retrieves the block matrix from n-th expansion using the matrix key provided by the m_linSysKey. More...
 
virtual void v_DropBlock (unsigned int n)
 Releases the local block matrix from NekManager of n-th expansion using the matrix key provided by the m_linSysKey. More...
 
virtual DNekScalBlkMatSharedPtr v_GetStaticCondBlock (unsigned int n)
 Retrieves a the static condensation block matrices from n-th expansion using the matrix key provided by the m_linSysKey. More...
 
virtual void v_DropStaticCondBlock (unsigned int n)
 Releases the static condensation block matrices from NekManager of n-th expansion using the matrix key provided by the m_linSysKey. More...
 
PreconditionerSharedPtr CreatePrecon (AssemblyMapSharedPtr asmMap)
 Create a preconditioner object from the parameters defined in the supplied assembly map. More...
 

Private Attributes

std::shared_ptr< AssemblyMapm_locToGloMap
 

Additional Inherited Members

- Protected Attributes inherited from Nektar::MultiRegions::GlobalLinSysPETSc
Mat m_matrix
 PETSc matrix object. More...
 
Vec m_x
 PETSc vector objects used for local storage. More...
 
Vec m_b
 
Vec m_locVec
 
KSP m_ksp
 KSP object that represents solver system. More...
 
PC m_pc
 PCShell for preconditioner. More...
 
PETScMatMult m_matMult
 Enumerator to select matrix multiplication type. More...
 
std::vector< int > m_reorderedMap
 Reordering that takes universal IDs to a unique row in the PETSc matrix. More...
 
VecScatter m_ctx
 PETSc scatter context that takes us between Nektar++ global ordering and PETSc vector ordering. More...
 
int m_nLocal
 Number of unique degrees of freedom on this process. More...
 
PreconditionerSharedPtr m_precon
 
- Protected Attributes inherited from Nektar::MultiRegions::GlobalLinSys
const GlobalLinSysKey m_linSysKey
 Key associated with this linear system. More...
 
const std::weak_ptr< ExpListm_expList
 Local Matrix System. More...
 
const std::map< int, RobinBCInfoSharedPtrm_robinBCInfo
 Robin boundary info. More...
 
bool m_verbose
 

Detailed Description

A global linear system.

Definition at line 50 of file GlobalLinSysPETScFull.h.

Constructor & Destructor Documentation

◆ GlobalLinSysPETScFull()

Nektar::MultiRegions::GlobalLinSysPETScFull::GlobalLinSysPETScFull ( const GlobalLinSysKey pLinSysKey,
const std::weak_ptr< ExpList > &  pExpList,
const std::shared_ptr< AssemblyMap > &  pLocToGloMap 
)

Constructor for full direct matrix solve.

Definition at line 57 of file GlobalLinSysPETScFull.cpp.

60 : GlobalLinSys(pLinSysKey, pExp, pLocToGloMap),
61 GlobalLinSysPETSc(pLinSysKey, pExp, pLocToGloMap)
62{
63 const int nDirDofs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
64
65 int i, j, n, cnt, gid1, gid2, loc_lda;
66 NekDouble sign1, sign2, value;
68
69 // CALCULATE REORDERING MAPPING
70 CalculateReordering(pLocToGloMap->GetGlobalToUniversalMap(),
71 pLocToGloMap->GetGlobalToUniversalMapUnique(),
72 pLocToGloMap);
73
74 // SET UP VECTORS AND MATRIX
75 SetUpMatVec(pLocToGloMap->GetNumGlobalCoeffs(), nDirDofs);
76
77 // SET UP SCATTER OBJECTS
79
80 // CONSTRUCT KSP OBJECT
82 m_expList.lock()->GetSession();
83 string variable = pLocToGloMap->GetVariable();
84 NekDouble IterativeSolverTolerance = NekConstants::kNekIterativeTol;
85 if (pSession->DefinesGlobalSysSolnInfo(variable,
86 "IterativeSolverTolerance"))
87 {
88 IterativeSolverTolerance = boost::lexical_cast<double>(
89 pSession->GetGlobalSysSolnInfo(variable, "IterativeSolverTolerance")
90 .c_str());
91 }
92 else if (pSession->DefinesParameter("IterativeSolverTolerance"))
93 {
94 IterativeSolverTolerance =
95 pSession->GetParameter("IterativeSolverTolerance");
96 }
97 SetUpSolver(IterativeSolverTolerance);
98
99 // POPULATE MATRIX
100 for (n = cnt = 0; n < m_expList.lock()->GetNumElmts(); ++n)
101 {
102 loc_mat = GetBlock(n);
103 loc_lda = loc_mat->GetRows();
104
105 for (i = 0; i < loc_lda; ++i)
106 {
107 gid1 = pLocToGloMap->GetLocalToGlobalMap(cnt + i) - nDirDofs;
108 sign1 = pLocToGloMap->GetLocalToGlobalSign(cnt + i);
109 if (gid1 >= 0)
110 {
111 int gid1ro = m_reorderedMap[gid1];
112 for (j = 0; j < loc_lda; ++j)
113 {
114 gid2 =
115 pLocToGloMap->GetLocalToGlobalMap(cnt + j) - nDirDofs;
116 sign2 = pLocToGloMap->GetLocalToGlobalSign(cnt + j);
117 if (gid2 >= 0)
118 {
119 int gid2ro = m_reorderedMap[gid2];
120 value = sign1 * sign2 * (*loc_mat)(i, j);
121 MatSetValue(m_matrix, gid1ro, gid2ro, value,
122 ADD_VALUES);
123 }
124 }
125 }
126 }
127 cnt += loc_lda;
128 }
129
130 // ASSEMBLE MATRIX
131 MatAssemblyBegin(m_matrix, MAT_FINAL_ASSEMBLY);
132 MatAssemblyEnd(m_matrix, MAT_FINAL_ASSEMBLY);
133}
const std::weak_ptr< ExpList > m_expList
Local Matrix System.
Definition: GlobalLinSys.h:122
GlobalLinSys(const GlobalLinSysKey &pKey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Constructor for full direct matrix solve.
DNekScalMatSharedPtr GetBlock(unsigned int n)
Definition: GlobalLinSys.h:209
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.
void SetUpSolver(NekDouble tolerance)
Set up KSP solver object.
GlobalLinSysPETSc(const GlobalLinSysKey &pKey, const std::weak_ptr< ExpList > &pExp, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Constructor for full direct matrix solve.
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< SessionReader > SessionReaderSharedPtr
static const NekDouble kNekIterativeTol
std::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
double NekDouble

References Nektar::MultiRegions::GlobalLinSysPETSc::CalculateReordering(), Nektar::MultiRegions::GlobalLinSys::GetBlock(), Nektar::NekConstants::kNekIterativeTol, Nektar::MultiRegions::GlobalLinSys::m_expList, Nektar::MultiRegions::GlobalLinSysPETSc::m_matrix, Nektar::MultiRegions::GlobalLinSysPETSc::m_reorderedMap, Nektar::MultiRegions::GlobalLinSysPETSc::SetUpMatVec(), Nektar::MultiRegions::GlobalLinSysPETSc::SetUpScatter(), and Nektar::MultiRegions::GlobalLinSysPETSc::SetUpSolver().

◆ ~GlobalLinSysPETScFull()

Nektar::MultiRegions::GlobalLinSysPETScFull::~GlobalLinSysPETScFull ( )
overridedefault

Member Function Documentation

◆ create()

static GlobalLinSysSharedPtr Nektar::MultiRegions::GlobalLinSysPETScFull::create ( const GlobalLinSysKey pLinSysKey,
const std::weak_ptr< ExpList > &  pExpList,
const std::shared_ptr< AssemblyMap > &  pLocToGloMap 
)
inlinestatic

Creates an instance of this class.

Definition at line 54 of file GlobalLinSysPETScFull.h.

58 {
60 pLinSysKey, pExpList, pLocToGloMap);
61 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

◆ v_DoMatrixMultiply()

void Nektar::MultiRegions::GlobalLinSysPETScFull::v_DoMatrixMultiply ( const Array< OneD, const NekDouble > &  input,
Array< OneD, NekDouble > &  output 
)
overrideprotectedvirtual

Apply matrix-vector multiplication using local approach and the assembly map.

Parameters
inputVector input.
outputResult of multiplication.

Implements Nektar::MultiRegions::GlobalLinSysPETSc.

Definition at line 219 of file GlobalLinSysPETScFull.cpp.

221{
222 std::shared_ptr<MultiRegions::ExpList> expList = m_expList.lock();
223
224 int nLocDofs = m_locToGloMap->GetNumLocalCoeffs();
225
226 Array<OneD, NekDouble> tmp(nLocDofs);
227 Array<OneD, NekDouble> tmp1(nLocDofs);
228
229 m_locToGloMap->GlobalToLocal(input, tmp);
230
231 // Perform matrix-vector operation A*d_i
232 expList->GeneralMatrixOp(m_linSysKey, tmp, tmp1);
233
234 m_locToGloMap->Assemble(tmp1, output);
235}
const GlobalLinSysKey m_linSysKey
Key associated with this linear system.
Definition: GlobalLinSys.h:120
std::shared_ptr< AssemblyMap > m_locToGloMap

References Nektar::MultiRegions::GlobalLinSys::m_expList, Nektar::MultiRegions::GlobalLinSys::m_linSysKey, and m_locToGloMap.

◆ v_Solve()

void Nektar::MultiRegions::GlobalLinSysPETScFull::v_Solve ( const Array< OneD, const NekDouble > &  pLocInput,
Array< OneD, NekDouble > &  pLocOutput,
const AssemblyMapSharedPtr pLocToGloMap,
const Array< OneD, const NekDouble > &  pDirForcing = NullNekDouble1DArray 
)
overrideprotectedvirtual

Solve the linear system for given input and output vectors using a specified local to global map.

Solve the linear system using a full global matrix system.

Implements Nektar::MultiRegions::GlobalLinSys.

Definition at line 138 of file GlobalLinSysPETScFull.cpp.

143{
144 m_locToGloMap = pLocToGloMap;
145
146 bool dirForcCalculated = (bool)pDirForcing.size();
147 int nDirDofs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
148 int nGlobDofs = pLocToGloMap->GetNumGlobalCoeffs();
149 int nLocDofs = pLocToGloMap->GetNumLocalCoeffs();
150
151 int nDirTotal = nDirDofs;
152 std::shared_ptr<MultiRegions::ExpList> expList = m_expList.lock();
153 expList->GetComm()->GetRowComm()->AllReduce(nDirTotal,
155
156 if (nDirTotal)
157 {
158 Array<OneD, NekDouble> rhs(nLocDofs);
159
160 // Calculate the Dirichlet forcing
161 if (dirForcCalculated)
162 {
163 // Assume pDirForcing is in local space
164 ASSERTL0(
165 pDirForcing.size() >= nLocDofs,
166 "DirForcing is not of sufficient size. Is it in local space?");
167 Vmath::Vsub(nLocDofs, pLocInput, 1, pDirForcing, 1, rhs, 1);
168 }
169 else
170 {
171 // Calculate initial condition and Dirichlet forcing and subtract it
172 // from the rhs
173 expList->GeneralMatrixOp(m_linSysKey, pLocOutput, rhs);
174
175 // Iterate over all the elements computing Robin BCs where
176 // necessary
177 for (auto &r : m_robinBCInfo) // add robin mass matrix
178 {
180 Array<OneD, NekDouble> rhsloc;
181
182 int n = r.first;
183 int offset = expList->GetCoeff_Offset(n);
184
185 LocalRegions::ExpansionSharedPtr vExp = expList->GetExp(n);
186 // Add local matrix contribution
187 for (rBC = r.second; rBC; rBC = rBC->next)
188 {
189 vExp->AddRobinTraceContribution(
190 rBC->m_robinID, rBC->m_robinPrimitiveCoeffs,
191 pLocOutput + offset, rhsloc = rhs + offset);
192 }
193 }
194 Vmath::Vsub(nLocDofs, pLocInput, 1, rhs, 1, rhs, 1);
195 }
196
197 Array<OneD, NekDouble> diff(nLocDofs);
198
199 // Solve for perturbation from initial guess in pOutput
200 SolveLinearSystem(nGlobDofs, rhs, diff, pLocToGloMap, nDirDofs);
201
202 // Add back initial and boundary condition
203 Vmath::Vadd(nLocDofs, diff, 1, pLocOutput, 1, pLocOutput, 1);
204 }
205 else
206 {
207 SolveLinearSystem(nGlobDofs, pLocInput, pLocOutput, pLocToGloMap,
208 nDirDofs);
209 }
210}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
const std::map< int, RobinBCInfoSharedPtr > m_robinBCInfo
Robin boundary info.
Definition: GlobalLinSys.h:124
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.
Definition: GlobalLinSys.h:190
std::shared_ptr< Expansion > ExpansionSharedPtr
Definition: Expansion.h:66
std::shared_ptr< RobinBCInfo > RobinBCInfoSharedPtr
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.
Definition: Vmath.hpp:180
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.
Definition: Vmath.hpp:220

References ASSERTL0, Nektar::MultiRegions::GlobalLinSys::m_expList, Nektar::MultiRegions::GlobalLinSys::m_linSysKey, m_locToGloMap, Nektar::MultiRegions::GlobalLinSys::m_robinBCInfo, Nektar::LibUtilities::ReduceSum, Nektar::MultiRegions::GlobalLinSys::SolveLinearSystem(), Vmath::Vadd(), and Vmath::Vsub().

Member Data Documentation

◆ className

string Nektar::MultiRegions::GlobalLinSysPETScFull::className
static
Initial value:
=
"PETScFull", GlobalLinSysPETScFull::create, "PETSc Full Matrix.")
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
static GlobalLinSysSharedPtr create(const GlobalLinSysKey &pLinSysKey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Creates an instance of this class.
GlobalLinSysFactory & GetGlobalLinSysFactory()

Name of class.

Registers the class with the Factory.

Definition at line 64 of file GlobalLinSysPETScFull.h.

◆ m_locToGloMap

std::shared_ptr<AssemblyMap> Nektar::MultiRegions::GlobalLinSysPETScFull::m_locToGloMap
private

Definition at line 87 of file GlobalLinSysPETScFull.h.

Referenced by v_DoMatrixMultiply(), and v_Solve().