Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | List of all members
Nektar::MultiRegions::GlobalLinSysPETScFull Class Reference

A global linear system. More...

#include <GlobalLinSysPETScFull.h>

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

Public Member Functions

 GlobalLinSysPETScFull (const GlobalLinSysKey &pLinSysKey, const boost::weak_ptr< ExpList > &pExpList, const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
 Constructor for full direct matrix solve. More...
 
virtual ~GlobalLinSysPETScFull ()
 
- Public Member Functions inherited from Nektar::MultiRegions::GlobalLinSysPETSc
 GlobalLinSysPETSc (const GlobalLinSysKey &pKey, const boost::weak_ptr< ExpList > &pExp, const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
 Constructor for full direct matrix solve. More...
 
virtual ~GlobalLinSysPETSc ()
 Clean up PETSc objects. More...
 
virtual void v_SolveLinearSystem (const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const AssemblyMapSharedPtr &locToGloMap, const int pNumDir)
 Solve linear system using PETSc. More...
 
- Public Member Functions inherited from Nektar::MultiRegions::GlobalLinSys
 GlobalLinSys (const GlobalLinSysKey &pKey, const boost::weak_ptr< ExpList > &pExpList, const boost::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 boost::weak_ptr< ExpList > & GetLocMat (void) const
 
void InitObject ()
 
void Initialise (const boost::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...
 
boost::shared_ptr< GlobalLinSysGetSharedThisPtr ()
 Returns a shared pointer to the current object. More...
 
int GetNumBlocks ()
 
DNekScalMatSharedPtr GetBlock (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 boost::weak_ptr< ExpList > &pExpList, const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
 Creates an instance of this class. More...
 

Static Public Attributes

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

Private Member Functions

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. More...
 
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. More...
 

Additional Inherited Members

- 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...
 
- Protected Member Functions inherited from Nektar::MultiRegions::GlobalLinSys
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 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 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...
 
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 boost::weak_ptr< ExpListm_expList
 Local Matrix System. More...
 
const map< int,
RobinBCInfoSharedPtr
m_robinBCInfo
 Robin boundary info. More...
 

Detailed Description

A global linear system.

Definition at line 53 of file GlobalLinSysPETScFull.h.

Constructor & Destructor Documentation

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

Constructor for full direct matrix solve.

Definition at line 61 of file GlobalLinSysPETScFull.cpp.

References Nektar::MultiRegions::GlobalLinSysPETSc::CalculateReordering(), Nektar::MultiRegions::GlobalLinSys::GetBlock(), 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().

65  : GlobalLinSys (pLinSysKey, pExp, pLocToGloMap),
66  GlobalLinSysPETSc(pLinSysKey, pExp, pLocToGloMap)
67  {
68  const int nDirDofs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
69 
70  int i, j, n, cnt, gid1, gid2, loc_lda;
71  NekDouble sign1, sign2, value;
72  DNekScalMatSharedPtr loc_mat;
73 
74  // CALCULATE REORDERING MAPPING
75  CalculateReordering(pLocToGloMap->GetGlobalToUniversalMap(),
76  pLocToGloMap->GetGlobalToUniversalMapUnique(),
77  pLocToGloMap);
78 
79  // SET UP VECTORS AND MATRIX
80  SetUpMatVec(pLocToGloMap->GetNumGlobalCoeffs(), nDirDofs);
81 
82  // SET UP SCATTER OBJECTS
83  SetUpScatter();
84 
85  // CONSTRUCT KSP OBJECT
86  SetUpSolver(pLocToGloMap->GetIterativeTolerance());
87 
88  // POPULATE MATRIX
89  for(n = cnt = 0; n < m_expList.lock()->GetNumElmts(); ++n)
90  {
91  loc_mat = GetBlock(m_expList.lock()->GetOffset_Elmt_Id(n));
92  loc_lda = loc_mat->GetRows();
93 
94  for(i = 0; i < loc_lda; ++i)
95  {
96  gid1 = pLocToGloMap->GetLocalToGlobalMap(cnt+i) - nDirDofs;
97  sign1 = pLocToGloMap->GetLocalToGlobalSign(cnt + i);
98  if(gid1 >= 0)
99  {
100  int gid1ro = m_reorderedMap[gid1];
101  for(j = 0; j < loc_lda; ++j)
102  {
103  gid2 = pLocToGloMap->GetLocalToGlobalMap(cnt + j)
104  - nDirDofs;
105  sign2 = pLocToGloMap->GetLocalToGlobalSign(cnt + j);
106  if(gid2 >= 0)
107  {
108  int gid2ro = m_reorderedMap[gid2];
109  value = sign1*sign2*(*loc_mat)(i,j);
110  MatSetValue(
111  m_matrix, gid1ro, gid2ro, value, ADD_VALUES);
112  }
113  }
114  }
115  }
116  cnt += loc_lda;
117  }
118 
119  // ASSEMBLE MATRIX
120  MatAssemblyBegin(m_matrix, MAT_FINAL_ASSEMBLY);
121  MatAssemblyEnd (m_matrix, MAT_FINAL_ASSEMBLY);
122  }
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.
void SetUpSolver(NekDouble tolerance)
Set up KSP solver object.
vector< int > m_reorderedMap
Reordering that takes universal IDs to a unique row in the PETSc matrix.
boost::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
DNekScalMatSharedPtr GetBlock(unsigned int n)
Definition: GlobalLinSys.h:220
GlobalLinSysPETSc(const GlobalLinSysKey &pKey, const boost::weak_ptr< ExpList > &pExp, const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
Constructor for full direct matrix solve.
double NekDouble
GlobalLinSys(const GlobalLinSysKey &pKey, const boost::weak_ptr< ExpList > &pExpList, const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
Constructor for full direct matrix solve.
void SetUpScatter()
Set up PETSc local (equivalent to Nektar++ global) and global (equivalent to universal) scatter maps...
void SetUpMatVec(int nGlobal, int nDir)
Construct PETSc matrix and vector handles.
const boost::weak_ptr< ExpList > m_expList
Local Matrix System.
Definition: GlobalLinSys.h:129
Nektar::MultiRegions::GlobalLinSysPETScFull::~GlobalLinSysPETScFull ( )
virtual

Definition at line 125 of file GlobalLinSysPETScFull.cpp.

126  {
127 
128  }

Member Function Documentation

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

Creates an instance of this class.

Definition at line 58 of file GlobalLinSysPETScFull.h.

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

62  {
64  ::AllocateSharedPtr(pLinSysKey, pExpList, pLocToGloMap);
65  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
void Nektar::MultiRegions::GlobalLinSysPETScFull::v_DoMatrixMultiply ( const Array< OneD, const NekDouble > &  input,
Array< OneD, NekDouble > &  output 
)
privatevirtual

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

Parameters
inputVector input.
outputResult of multiplication.

Implements Nektar::MultiRegions::GlobalLinSysPETSc.

Definition at line 190 of file GlobalLinSysPETScFull.cpp.

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

193  {
194  boost::shared_ptr<MultiRegions::ExpList> expList = m_expList.lock();
195 
196  // Perform matrix-vector operation A*d_i
197  expList->GeneralMatrixOp(
198  m_linSysKey, input, output, eGlobal);
199  }
Global coefficients.
const GlobalLinSysKey m_linSysKey
Key associated with this linear system.
Definition: GlobalLinSys.h:127
const boost::weak_ptr< ExpList > m_expList
Local Matrix System.
Definition: GlobalLinSys.h:129
void Nektar::MultiRegions::GlobalLinSysPETScFull::v_Solve ( const Array< OneD, const NekDouble > &  pInput,
Array< OneD, NekDouble > &  pOutput,
const AssemblyMapSharedPtr pLocToGloMap,
const Array< OneD, const NekDouble > &  pDirForcing = NullNekDouble1DArray 
)
privatevirtual

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 134 of file GlobalLinSysPETScFull.cpp.

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

139  {
140  bool dirForcCalculated = (bool) pDirForcing.num_elements();
141  int nDirDofs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
142  int nGlobDofs = pLocToGloMap->GetNumGlobalCoeffs();
143  Array<OneD, NekDouble> tmp(nGlobDofs), tmp2;
144 
145  int nDirTotal = nDirDofs;
146  m_expList.lock()->GetComm()->GetRowComm()->AllReduce(
147  nDirTotal, LibUtilities::ReduceSum);
148 
149  if(nDirTotal)
150  {
151  // calculate the dirichlet forcing
152  if(dirForcCalculated)
153  {
154  Vmath::Vsub(nGlobDofs,
155  pInput.get(), 1,
156  pDirForcing.get(), 1,
157  tmp.get(), 1);
158  }
159  else
160  {
161  // Calculate the dirichlet forcing and substract it
162  // from the rhs
163  m_expList.lock()->GeneralMatrixOp(
164  m_linSysKey, pOutput, tmp, eGlobal);
165 
166  Vmath::Vsub(nGlobDofs,
167  pInput.get(), 1,
168  tmp.get(), 1,
169  tmp.get(), 1);
170  }
171 
172  Array<OneD, NekDouble> out(nGlobDofs,0.0);
173  SolveLinearSystem(nGlobDofs, tmp, out, pLocToGloMap, nDirDofs);
174  Vmath::Vadd(nGlobDofs-nDirDofs, &out [nDirDofs], 1,
175  &pOutput[nDirDofs], 1, &pOutput[nDirDofs], 1);
176  }
177  else
178  {
179  SolveLinearSystem(nDirDofs, pInput, pOutput, pLocToGloMap);
180  }
181  }
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:199
Global coefficients.
const GlobalLinSysKey m_linSysKey
Key associated with this linear system.
Definition: GlobalLinSys.h:127
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.cpp:329
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.cpp:285
const boost::weak_ptr< ExpList > m_expList
Local Matrix System.
Definition: GlobalLinSys.h:129

Member Data Documentation

string Nektar::MultiRegions::GlobalLinSysPETScFull::className
static
Initial value:

Name of class.

Registers the class with the Factory.

Definition at line 68 of file GlobalLinSysPETScFull.h.