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

A global linear system. More...

#include <GlobalLinSysPETScStaticCond.h>

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

Public Member Functions

 GlobalLinSysPETScStaticCond (const GlobalLinSysKey &mkey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &locToGloMap)
 Constructor for full direct matrix solve. More...
 
 GlobalLinSysPETScStaticCond (const GlobalLinSysKey &mkey, const std::weak_ptr< ExpList > &pExpList, const DNekScalBlkMatSharedPtr pSchurCompl, const DNekScalBlkMatSharedPtr pBinvD, const DNekScalBlkMatSharedPtr pC, const DNekScalBlkMatSharedPtr pInvD, const std::shared_ptr< AssemblyMap > &locToGloMap, const PreconditionerSharedPtr pPrecon=PreconditionerSharedPtr())
 Constructor for full direct matrix solve. More...
 
 ~GlobalLinSysPETScStaticCond () override
 
- 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...
 
- Public Member Functions inherited from Nektar::MultiRegions::GlobalLinSysStaticCond
 GlobalLinSysStaticCond (const GlobalLinSysKey &mkey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &locToGloMap)
 Constructor for full direct matrix solve. More...
 
 ~GlobalLinSysStaticCond () override
 

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...
 
static std::string className2
 

Protected Member Functions

void v_InitObject () override
 
void v_AssembleSchurComplement (std::shared_ptr< AssemblyMap > locToGloMap) override
 Assemble the Schur complement matrix. 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...
 
DNekScalBlkMatSharedPtr v_GetStaticCondBlock (unsigned int n) override
 Retrieves a the static condensation block matrices from n-th expansion using the matrix key provided by the m_linSysKey. More...
 
void v_PreSolve (int scLevel, Array< OneD, NekDouble > &F_bBnd) override
 
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...
 
void v_BasisFwdTransform (Array< OneD, NekDouble > &pInOut) override
 
void v_CoeffsBwdTransform (Array< OneD, NekDouble > &pInOut) override
 
void v_CoeffsFwdTransform (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput) override
 
GlobalLinSysStaticCondSharedPtr v_Recurse (const GlobalLinSysKey &mkey, const std::weak_ptr< ExpList > &pExpList, const DNekScalBlkMatSharedPtr pSchurCompl, const DNekScalBlkMatSharedPtr pBinvD, const DNekScalBlkMatSharedPtr pC, const DNekScalBlkMatSharedPtr pInvD, const std::shared_ptr< AssemblyMap > &locToGloMap) override
 
- 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...
 
- Protected Member Functions inherited from Nektar::MultiRegions::GlobalLinSysStaticCond
virtual void v_PreSolve (int scLevel, Array< OneD, NekDouble > &F_bnd)
 
virtual void v_BasisFwdTransform (Array< OneD, NekDouble > &pInOut)
 
virtual void v_CoeffsBwdTransform (Array< OneD, NekDouble > &pInOut)
 
virtual void v_CoeffsFwdTransform (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput)
 
virtual void v_AssembleSchurComplement (std::shared_ptr< AssemblyMap > pLoctoGloMap)
 
int v_GetNumBlocks () override
 Get the number of blocks in this system. More...
 
virtual GlobalLinSysStaticCondSharedPtr v_Recurse (const GlobalLinSysKey &mkey, const std::weak_ptr< ExpList > &pExpList, const DNekScalBlkMatSharedPtr pSchurCompl, const DNekScalBlkMatSharedPtr pBinvD, const DNekScalBlkMatSharedPtr pC, const DNekScalBlkMatSharedPtr pInvD, const std::shared_ptr< AssemblyMap > &locToGloMap)=0
 
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_InitObject () override
 
void v_Initialise (const std::shared_ptr< AssemblyMap > &locToGloMap) override
 Initialise this object. More...
 
void SetupTopLevel (const std::shared_ptr< AssemblyMap > &locToGloMap)
 Set up the storage for the Schur complement or the top level of the multi-level Schur complement. More...
 
void ConstructNextLevelCondensedSystem (const std::shared_ptr< AssemblyMap > &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
 
- Protected Attributes inherited from Nektar::MultiRegions::GlobalLinSysStaticCond
GlobalLinSysStaticCondSharedPtr m_recursiveSchurCompl
 Schur complement for Direct Static Condensation. More...
 
DNekScalBlkMatSharedPtr m_schurCompl
 Block Schur complement matrix. More...
 
DNekScalBlkMatSharedPtr m_BinvD
 Block \( BD^{-1} \) matrix. More...
 
DNekScalBlkMatSharedPtr m_C
 Block \( C \) matrix. More...
 
DNekScalBlkMatSharedPtr m_invD
 Block \( D^{-1} \) matrix. More...
 
std::weak_ptr< AssemblyMapm_locToGloMap
 Local to global map. More...
 
Array< OneD, NekDoublem_wsp
 Workspace array for matrix multiplication. More...
 
Array< OneD, const NekDoublem_sign
 

Detailed Description

A global linear system.

Definition at line 52 of file GlobalLinSysPETScStaticCond.h.

Constructor & Destructor Documentation

◆ GlobalLinSysPETScStaticCond() [1/2]

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

Constructor for full direct matrix solve.

For a matrix system of the form

\[ \left[ \begin{array}{cc} \boldsymbol{A} & \boldsymbol{B}\\ \boldsymbol{C} & \boldsymbol{D} \end{array} \right] \left[ \begin{array}{c} \boldsymbol{x_1}\\ \boldsymbol{x_2} \end{array}\right] = \left[ \begin{array}{c} \boldsymbol{y_1}\\ \boldsymbol{y_2} \end{array}\right], \]

where \(\boldsymbol{D}\) and \((\boldsymbol{A-BD^{-1}C})\) are invertible, store and assemble a static condensation system, according to a given local to global mapping. #m_linSys is constructed by AssembleSchurComplement().

Parameters
mKeyAssociated matrix key.
pLocMatSysLocalMatrixSystem
locToGloMapLocal to global mapping.

Definition at line 84 of file GlobalLinSysPETScStaticCond.cpp.

87 : GlobalLinSys(pKey, pExpList, pLocToGloMap),
88 GlobalLinSysPETSc(pKey, pExpList, pLocToGloMap),
89 GlobalLinSysStaticCond(pKey, pExpList, pLocToGloMap)
90{
91 ASSERTL1((pKey.GetGlobalSysSolnType() == ePETScStaticCond) ||
92 (pKey.GetGlobalSysSolnType() == ePETScMultiLevelStaticCond),
93 "This constructor is only valid when using static "
94 "condensation");
95 ASSERTL1(pKey.GetGlobalSysSolnType() ==
96 pLocToGloMap->GetGlobalSysSolnType(),
97 "The local to global map is not set up for the requested "
98 "solution type");
99}
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242
GlobalLinSys(const GlobalLinSysKey &pKey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Constructor for full direct matrix solve.
GlobalLinSysPETSc(const GlobalLinSysKey &pKey, const std::weak_ptr< ExpList > &pExp, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Constructor for full direct matrix solve.
GlobalLinSysStaticCond(const GlobalLinSysKey &mkey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &locToGloMap)
Constructor for full direct matrix solve.

References ASSERTL1, Nektar::MultiRegions::ePETScMultiLevelStaticCond, Nektar::MultiRegions::ePETScStaticCond, and Nektar::MultiRegions::GlobalLinSysKey::GetGlobalSysSolnType().

◆ GlobalLinSysPETScStaticCond() [2/2]

Nektar::MultiRegions::GlobalLinSysPETScStaticCond::GlobalLinSysPETScStaticCond ( const GlobalLinSysKey mkey,
const std::weak_ptr< ExpList > &  pExpList,
const DNekScalBlkMatSharedPtr  pSchurCompl,
const DNekScalBlkMatSharedPtr  pBinvD,
const DNekScalBlkMatSharedPtr  pC,
const DNekScalBlkMatSharedPtr  pInvD,
const std::shared_ptr< AssemblyMap > &  locToGloMap,
const PreconditionerSharedPtr  pPrecon = PreconditionerSharedPtr() 
)

Constructor for full direct matrix solve.

Definition at line 104 of file GlobalLinSysPETScStaticCond.cpp.

111 : GlobalLinSys(pKey, pExpList, pLocToGloMap),
112 GlobalLinSysPETSc(pKey, pExpList, pLocToGloMap),
113 GlobalLinSysStaticCond(pKey, pExpList, pLocToGloMap)
114{
115 m_schurCompl = pSchurCompl;
116 m_BinvD = pBinvD;
117 m_C = pC;
118 m_invD = pInvD;
119 m_precon = pPrecon;
120}
DNekScalBlkMatSharedPtr m_schurCompl
Block Schur complement matrix.
DNekScalBlkMatSharedPtr m_BinvD
Block matrix.
DNekScalBlkMatSharedPtr m_C
Block matrix.
DNekScalBlkMatSharedPtr m_invD
Block matrix.

References Nektar::MultiRegions::GlobalLinSysStaticCond::m_BinvD, Nektar::MultiRegions::GlobalLinSysStaticCond::m_C, Nektar::MultiRegions::GlobalLinSysStaticCond::m_invD, Nektar::MultiRegions::GlobalLinSysPETSc::m_precon, and Nektar::MultiRegions::GlobalLinSysStaticCond::m_schurCompl.

◆ ~GlobalLinSysPETScStaticCond()

Nektar::MultiRegions::GlobalLinSysPETScStaticCond::~GlobalLinSysPETScStaticCond ( )
override

Definition at line 125 of file GlobalLinSysPETScStaticCond.cpp.

126{
127}

Member Function Documentation

◆ create()

static GlobalLinSysSharedPtr Nektar::MultiRegions::GlobalLinSysPETScStaticCond::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 57 of file GlobalLinSysPETScStaticCond.h.

61 {
64 pLinSysKey, pExpList, pLocToGloMap);
65 p->InitObject();
66 return p;
67 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< GlobalLinSys > GlobalLinSysSharedPtr
Pointer to a GlobalLinSys object.
Definition: GlobalLinSys.h:51

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), and CellMLToNektar.cellml_metadata::p.

◆ v_AssembleSchurComplement()

void Nektar::MultiRegions::GlobalLinSysPETScStaticCond::v_AssembleSchurComplement ( std::shared_ptr< AssemblyMap locToGloMap)
overrideprotectedvirtual

Assemble the Schur complement matrix.

Assemble the schur complement matrix from the block matrices stored in #m_blkMatrices and the given local to global mapping information.

Parameters
locToGloMapLocal to global mapping information.

Reimplemented from Nektar::MultiRegions::GlobalLinSysStaticCond.

Definition at line 167 of file GlobalLinSysPETScStaticCond.cpp.

169{
170 int i, j, n, cnt, gid1, gid2, loc_lda;
171 NekDouble sign1, sign2, value;
172
173 const int nDirDofs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
174
179 DNekScalMatSharedPtr loc_mat;
180
181 // Build precon again if we in multi-level static condensation (a
182 // bit of a hack)
184 {
186 m_precon->BuildPreconditioner();
187 }
188
189 // CALCULATE REORDERING MAPPING
190 CalculateReordering(pLocToGloMap->GetGlobalToUniversalBndMap(),
191 pLocToGloMap->GetGlobalToUniversalBndMapUnique(),
192 pLocToGloMap);
193
194 // SET UP VECTORS AND MATRIX
195 SetUpMatVec(pLocToGloMap->GetNumGlobalBndCoeffs(), nDirDofs);
196
197 // SET UP SCATTER OBJECTS
198 SetUpScatter();
199
200 // CONSTRUCT KSP OBJECT
202 m_expList.lock()->GetSession();
203 string variable = pLocToGloMap->GetVariable();
204 NekDouble IterativeSolverTolerance = NekConstants::kNekIterativeTol;
205 if (pSession->DefinesGlobalSysSolnInfo(variable,
206 "IterativeSolverTolerance"))
207 {
208 IterativeSolverTolerance = boost::lexical_cast<double>(
209 pSession->GetGlobalSysSolnInfo(variable, "IterativeSolverTolerance")
210 .c_str());
211 }
212 else if (pSession->DefinesParameter("IterativeSolverTolerance"))
213 {
214 IterativeSolverTolerance =
215 pSession->GetParameter("IterativeSolverTolerance");
216 }
217 SetUpSolver(IterativeSolverTolerance);
218
219 // If we are using the matrix multiplication shell don't try to
220 // populate the matrix.
222 {
223 return;
224 }
225
226 // POPULATE MATRIX
227 for (n = cnt = 0; n < m_schurCompl->GetNumberOfBlockRows(); ++n)
228 {
229 loc_mat = m_schurCompl->GetBlock(n, n);
230 loc_lda = loc_mat->GetRows();
231
232 for (i = 0; i < loc_lda; ++i)
233 {
234 gid1 = pLocToGloMap->GetLocalToGlobalBndMap(cnt + i) - nDirDofs;
235 sign1 = pLocToGloMap->GetLocalToGlobalBndSign(cnt + i);
236 if (gid1 >= 0)
237 {
238 int gid1ro = m_reorderedMap[gid1];
239 for (j = 0; j < loc_lda; ++j)
240 {
241 gid2 = pLocToGloMap->GetLocalToGlobalBndMap(cnt + j) -
242 nDirDofs;
243 sign2 = pLocToGloMap->GetLocalToGlobalBndSign(cnt + j);
244 if (gid2 >= 0)
245 {
246 int gid2ro = m_reorderedMap[gid2];
247 value = sign1 * sign2 * (*loc_mat)(i, j);
248 MatSetValue(m_matrix, gid1ro, gid2ro, value,
249 ADD_VALUES);
250 }
251 }
252 }
253 }
254 cnt += loc_lda;
255 }
256
257 // ASSEMBLE MATRIX
258 MatAssemblyBegin(m_matrix, MAT_FINAL_ASSEMBLY);
259 MatAssemblyEnd(m_matrix, MAT_FINAL_ASSEMBLY);
260}
const std::weak_ptr< ExpList > m_expList
Local Matrix System.
Definition: GlobalLinSys.h:122
const GlobalLinSysKey m_linSysKey
Key associated with this linear system.
Definition: GlobalLinSys.h:120
PreconditionerSharedPtr CreatePrecon(AssemblyMapSharedPtr asmMap)
Create a preconditioner object from the parameters defined in the supplied assembly map.
GlobalSysSolnType GetGlobalSysSolnType() const
Return the associated solution type.
PETScMatMult m_matMult
Enumerator to select matrix multiplication type.
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.
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::weak_ptr< AssemblyMap > m_locToGloMap
Local to global map.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
static const NekDouble kNekIterativeTol
std::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
std::shared_ptr< DNekScalBlkMat > DNekScalBlkMatSharedPtr
Definition: NekTypeDefs.hpp:79
double NekDouble

References Nektar::MultiRegions::GlobalLinSysPETSc::CalculateReordering(), Nektar::MultiRegions::GlobalLinSys::CreatePrecon(), Nektar::MultiRegions::ePETScMatMultShell, Nektar::MultiRegions::ePETScMultiLevelStaticCond, Nektar::MultiRegions::GlobalLinSysKey::GetGlobalSysSolnType(), Nektar::NekConstants::kNekIterativeTol, Nektar::MultiRegions::GlobalLinSysStaticCond::m_BinvD, Nektar::MultiRegions::GlobalLinSysStaticCond::m_C, Nektar::MultiRegions::GlobalLinSys::m_expList, Nektar::MultiRegions::GlobalLinSysStaticCond::m_invD, Nektar::MultiRegions::GlobalLinSys::m_linSysKey, Nektar::MultiRegions::GlobalLinSysStaticCond::m_locToGloMap, Nektar::MultiRegions::GlobalLinSysPETSc::m_matMult, Nektar::MultiRegions::GlobalLinSysPETSc::m_matrix, Nektar::MultiRegions::GlobalLinSysPETSc::m_precon, Nektar::MultiRegions::GlobalLinSysPETSc::m_reorderedMap, Nektar::MultiRegions::GlobalLinSysStaticCond::m_schurCompl, Nektar::MultiRegions::GlobalLinSysPETSc::SetUpMatVec(), Nektar::MultiRegions::GlobalLinSysPETSc::SetUpScatter(), and Nektar::MultiRegions::GlobalLinSysPETSc::SetUpSolver().

◆ v_BasisFwdTransform()

void Nektar::MultiRegions::GlobalLinSysPETScStaticCond::v_BasisFwdTransform ( Array< OneD, NekDouble > &  pInOut)
overrideprotectedvirtual

Reimplemented from Nektar::MultiRegions::GlobalLinSysStaticCond.

Definition at line 348 of file GlobalLinSysPETScStaticCond.cpp.

350{
351 m_precon->DoTransformBasisToLowEnergy(pInOut);
352}

References Nektar::MultiRegions::GlobalLinSysPETSc::m_precon.

◆ v_CoeffsBwdTransform()

void Nektar::MultiRegions::GlobalLinSysPETScStaticCond::v_CoeffsBwdTransform ( Array< OneD, NekDouble > &  pInOut)
overrideprotectedvirtual

Reimplemented from Nektar::MultiRegions::GlobalLinSysStaticCond.

Definition at line 354 of file GlobalLinSysPETScStaticCond.cpp.

356{
357 m_precon->DoTransformCoeffsFromLowEnergy(pInOut);
358}

References Nektar::MultiRegions::GlobalLinSysPETSc::m_precon.

◆ v_CoeffsFwdTransform()

void Nektar::MultiRegions::GlobalLinSysPETScStaticCond::v_CoeffsFwdTransform ( const Array< OneD, NekDouble > &  pInput,
Array< OneD, NekDouble > &  pOutput 
)
overrideprotectedvirtual

Reimplemented from Nektar::MultiRegions::GlobalLinSysStaticCond.

Definition at line 360 of file GlobalLinSysPETScStaticCond.cpp.

362{
363 m_precon->DoTransformCoeffsToLowEnergy(pInput, pOutput);
364}

References Nektar::MultiRegions::GlobalLinSysPETSc::m_precon.

◆ v_DoMatrixMultiply()

void Nektar::MultiRegions::GlobalLinSysPETScStaticCond::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.
Todo:
This can possibly be made faster by using the sparse block-matrix multiplication code from the iterative elastic systems.

Implements Nektar::MultiRegions::GlobalLinSysPETSc.

Definition at line 377 of file GlobalLinSysPETScStaticCond.cpp.

379{
380 auto asmMap = m_locToGloMap.lock();
381
382 int nLocBndDofs = asmMap->GetNumLocalBndCoeffs();
383 int nDirDofs = asmMap->GetNumGlobalDirBndCoeffs();
384
385 NekVector<NekDouble> in(nLocBndDofs), out(nLocBndDofs);
386 asmMap->GlobalToLocalBnd(input, in.GetPtr(), nDirDofs);
387 out = (*m_schurCompl) * in;
388 asmMap->AssembleBnd(out.GetPtr(), output, nDirDofs);
389}

References Nektar::NekVector< DataType >::GetPtr(), and Nektar::MultiRegions::GlobalLinSysStaticCond::m_locToGloMap.

◆ v_GetStaticCondBlock()

DNekScalBlkMatSharedPtr Nektar::MultiRegions::GlobalLinSysPETScStaticCond::v_GetStaticCondBlock ( unsigned int  n)
overrideprotectedvirtual

Retrieves a the static condensation block matrices from n-th expansion using the matrix key provided by the m_linSysKey.

Parameters
nNumber of the expansion
Returns
2x2 Block matrix holding the static condensation matrices for the n-th expansion.

Reimplemented from Nektar::MultiRegions::GlobalLinSys.

Definition at line 262 of file GlobalLinSysPETScStaticCond.cpp.

264{
265 DNekScalBlkMatSharedPtr schurComplBlock;
266 DNekScalMatSharedPtr localMat = m_schurCompl->GetBlock(n, n);
267 unsigned int nbdry = localMat->GetRows();
268 unsigned int nblks = 1;
269 unsigned int esize[1] = {nbdry};
270
272 nblks, nblks, esize, esize);
273 schurComplBlock->SetBlock(0, 0, localMat);
274
275 return schurComplBlock;
276}

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), and Nektar::MultiRegions::GlobalLinSysStaticCond::m_schurCompl.

◆ v_InitObject()

void Nektar::MultiRegions::GlobalLinSysPETScStaticCond::v_InitObject ( )
overrideprotectedvirtual

Reimplemented from Nektar::MultiRegions::GlobalLinSys.

Definition at line 129 of file GlobalLinSysPETScStaticCond.cpp.

130{
131 auto asmMap = m_locToGloMap.lock();
132
133 m_precon = CreatePrecon(asmMap);
134
135 // Allocate memory for top-level structure
136 SetupTopLevel(asmMap);
137
138 // Setup Block Matrix systems
139 int n, n_exp = m_expList.lock()->GetNumElmts();
140
141 // Build preconditioner
142 m_precon->BuildPreconditioner();
143
144 // Do transform of Schur complement matrix
145 int cnt = 0;
146 for (n = 0; n < n_exp; ++n)
147 {
149 {
150 DNekScalMatSharedPtr mat = m_schurCompl->GetBlock(n, n);
152 m_precon->TransformedSchurCompl(n, cnt, mat);
153 m_schurCompl->SetBlock(n, n, t);
154 cnt += mat->GetRows();
155 }
156 }
157
158 // Construct this level
159 Initialise(asmMap);
160}
void Initialise(const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Definition: GlobalLinSys.h:203
void SetupTopLevel(const std::shared_ptr< AssemblyMap > &locToGloMap)
Set up the storage for the Schur complement or the top level of the multi-level Schur complement.
StdRegions::MatrixType GetMatrixType() const
Return the matrix type.

References Nektar::MultiRegions::GlobalLinSys::CreatePrecon(), Nektar::StdRegions::eHybridDGHelmBndLam, Nektar::MultiRegions::GlobalMatrixKey::GetMatrixType(), Nektar::MultiRegions::GlobalLinSys::Initialise(), Nektar::MultiRegions::GlobalLinSys::m_expList, Nektar::MultiRegions::GlobalLinSys::m_linSysKey, Nektar::MultiRegions::GlobalLinSysStaticCond::m_locToGloMap, Nektar::MultiRegions::GlobalLinSysPETSc::m_precon, Nektar::MultiRegions::GlobalLinSysStaticCond::m_schurCompl, and Nektar::MultiRegions::GlobalLinSysStaticCond::SetupTopLevel().

◆ v_PreSolve()

void Nektar::MultiRegions::GlobalLinSysPETScStaticCond::v_PreSolve ( int  scLevel,
Array< OneD, NekDouble > &  F_bBnd 
)
overrideprotectedvirtual

Reimplemented from Nektar::MultiRegions::GlobalLinSysStaticCond.

Definition at line 278 of file GlobalLinSysPETScStaticCond.cpp.

280{
281 if (scLevel == 0)
282 {
283 // When matrices are supplied to the constructor at the top
284 // level, the preconditioner is never set up.
285 if (!m_precon)
286 {
288 m_precon->BuildPreconditioner();
289 }
290 }
291}

References Nektar::MultiRegions::GlobalLinSys::CreatePrecon(), Nektar::MultiRegions::GlobalLinSysStaticCond::m_locToGloMap, and Nektar::MultiRegions::GlobalLinSysPETSc::m_precon.

◆ v_Recurse()

GlobalLinSysStaticCondSharedPtr Nektar::MultiRegions::GlobalLinSysPETScStaticCond::v_Recurse ( const GlobalLinSysKey mkey,
const std::weak_ptr< ExpList > &  pExpList,
const DNekScalBlkMatSharedPtr  pSchurCompl,
const DNekScalBlkMatSharedPtr  pBinvD,
const DNekScalBlkMatSharedPtr  pC,
const DNekScalBlkMatSharedPtr  pInvD,
const std::shared_ptr< AssemblyMap > &  locToGloMap 
)
overrideprotectedvirtual

Implements Nektar::MultiRegions::GlobalLinSysStaticCond.

Definition at line 391 of file GlobalLinSysPETScStaticCond.cpp.

397{
400 mkey, pExpList, pSchurCompl, pBinvD, pC, pInvD, l2gMap, m_precon);
401 sys->Initialise(l2gMap);
402 return sys;
403}
std::shared_ptr< GlobalLinSysPETScStaticCond > GlobalLinSysPETScStaticCondSharedPtr

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), and Nektar::MultiRegions::GlobalLinSysPETSc::m_precon.

◆ v_SolveLinearSystem()

void Nektar::MultiRegions::GlobalLinSysPETScStaticCond::v_SolveLinearSystem ( const int  pNumRows,
const Array< OneD, const NekDouble > &  pInput,
Array< OneD, NekDouble > &  pOutput,
const AssemblyMapSharedPtr locToGloMap,
const int  pNumDir 
)
overrideprotectedvirtual

Solve linear system using PETSc.

The general strategy being a PETSc solve is to:

  • Copy values into the PETSc vector m_b
  • Solve the system m_ksp and place result into m_x.
  • Scatter results back into m_locVec using m_ctx scatter object.
  • Copy from m_locVec to output array #pOutput.

Reimplemented from Nektar::MultiRegions::GlobalLinSysPETSc.

Definition at line 303 of file GlobalLinSysPETScStaticCond.cpp.

307{
308 const int nHomDofs = pNumRows - pNumDir;
309
311 {
312 m_precon = CreatePrecon(locToGloMap);
313 m_precon->BuildPreconditioner();
314 }
315
316 Array<OneD, NekDouble> Glo(pNumRows);
317 locToGloMap->AssembleBnd(pInput, Glo);
318
319 // Populate RHS vector from input
320 VecSetValues(m_b, nHomDofs, &m_reorderedMap[0], &Glo[pNumDir],
321 INSERT_VALUES);
322
323 // Assemble RHS vector
324 VecAssemblyBegin(m_b);
325 VecAssemblyEnd(m_b);
326
327 // Do system solve
328 KSPSolve(m_ksp, m_b, m_x);
329
330 KSPConvergedReason reason;
331 KSPGetConvergedReason(m_ksp, &reason);
332 ASSERTL0(reason > 0, "PETSc solver diverged, reason is: " +
333 std::string(KSPConvergedReasons[reason]));
334
335 // Scatter results to local vector
336 VecScatterBegin(m_ctx, m_x, m_locVec, INSERT_VALUES, SCATTER_FORWARD);
337 VecScatterEnd(m_ctx, m_x, m_locVec, INSERT_VALUES, SCATTER_FORWARD);
338
339 // Copy results into output vector
340 PetscScalar *tmp;
341 VecGetArray(m_locVec, &tmp);
342 Vmath::Vcopy(nHomDofs, tmp, 1, &Glo[pNumDir], 1);
343 Vmath::Zero(pNumDir, Glo, 1);
344 locToGloMap->GlobalToLocalBnd(Glo, pOutput);
345 VecRestoreArray(m_locVec, &tmp);
346}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
Vec m_x
PETSc vector objects used for local storage.
VecScatter m_ctx
PETSc scatter context that takes us between Nektar++ global ordering and PETSc vector ordering.
KSP m_ksp
KSP object that represents solver system.
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.hpp:273
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825

References ASSERTL0, Nektar::MultiRegions::GlobalLinSys::CreatePrecon(), Nektar::MultiRegions::ePETScMatMultShell, Nektar::MultiRegions::GlobalLinSysPETSc::m_b, Nektar::MultiRegions::GlobalLinSysPETSc::m_ctx, Nektar::MultiRegions::GlobalLinSysPETSc::m_ksp, Nektar::MultiRegions::GlobalLinSysPETSc::m_locVec, Nektar::MultiRegions::GlobalLinSysPETSc::m_matMult, Nektar::MultiRegions::GlobalLinSysPETSc::m_precon, Nektar::MultiRegions::GlobalLinSysPETSc::m_reorderedMap, Nektar::MultiRegions::GlobalLinSysPETSc::m_x, Vmath::Vcopy(), and Vmath::Zero().

Member Data Documentation

◆ className

string Nektar::MultiRegions::GlobalLinSysPETScStaticCond::className
static
Initial value:
=
"PETSc static condensation.")
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 70 of file GlobalLinSysPETScStaticCond.h.

◆ className2

string Nektar::MultiRegions::GlobalLinSysPETScStaticCond::className2
static
Initial value:
=
"PETScMultiLevelStaticCond", GlobalLinSysPETScStaticCond::create,
"PETSc multi-level static condensation.")

Definition at line 71 of file GlobalLinSysPETScStaticCond.h.