Nektar++
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 ()
 
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...
 

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 ()
 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...
 
- Protected Attributes inherited from Nektar::MultiRegions::GlobalLinSysPETSc
Mat m_matrix
 
Vec m_x
 
Vec m_b
 
Vec m_locVec
 
KSP m_ksp
 
vector< int > m_reorderedMap
 
VecScatter m_ctx
 
int m_nLocal
 
- 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, RobinBCInfoSharedPtrm_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();
81 
82  // POPULATE MATRIX
83  for(n = cnt = 0; n < m_expList.lock()->GetNumElmts(); ++n)
84  {
85  loc_mat = GetBlock(m_expList.lock()->GetOffset_Elmt_Id(n));
86  loc_lda = loc_mat->GetRows();
87 
88  for(i = 0; i < loc_lda; ++i)
89  {
90  gid1 = pLocToGloMap->GetLocalToGlobalMap(cnt+i) - nDirDofs;
91  sign1 = pLocToGloMap->GetLocalToGlobalSign(cnt + i);
92  if(gid1 >= 0)
93  {
94  int gid1ro = m_reorderedMap[gid1];
95  for(j = 0; j < loc_lda; ++j)
96  {
97  gid2 = pLocToGloMap->GetLocalToGlobalMap(cnt + j)
98  - nDirDofs;
99  sign2 = pLocToGloMap->GetLocalToGlobalSign(cnt + j);
100  if(gid2 >= 0)
101  {
102  int gid2ro = m_reorderedMap[gid2];
103  value = sign1*sign2*(*loc_mat)(i,j);
104  MatSetValue(
105  m_matrix, gid1ro, gid2ro, value, ADD_VALUES);
106  }
107  }
108  }
109  }
110  cnt += loc_lda;
111  }
112 
113  // ASSEMBLE MATRIX
114  MatAssemblyBegin(m_matrix, MAT_FINAL_ASSEMBLY);
115  MatAssemblyEnd (m_matrix, MAT_FINAL_ASSEMBLY);
116 
117  // SET UP SCATTER OBJECTS
118  SetUpScatter();
119 
120  // CONSTRUCT KSP OBJECT
121  SetUpSolver(pLocToGloMap->GetIterativeTolerance());
122  }
void SetUpMatVec()
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.
void SetUpSolver(NekDouble tolerance)
Set up KSP solver object.
boost::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
DNekScalMatSharedPtr GetBlock(unsigned int n)
Definition: GlobalLinSys.h:214
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...
const boost::weak_ptr< ExpList > m_expList
Local Matrix System.
Definition: GlobalLinSys.h:125
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_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:193
Global coefficients.
const GlobalLinSysKey m_linSysKey
Key associated with this linear system.
Definition: GlobalLinSys.h:123
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:125

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.