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

#include <PreconditionerDiagonal.h>

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

Public Member Functions

 PreconditionerDiagonal (const boost::shared_ptr< GlobalLinSys > &plinsys, const AssemblyMapSharedPtr &pLocToGloMap)
 
virtual ~PreconditionerDiagonal ()
 
- Public Member Functions inherited from Nektar::MultiRegions::Preconditioner
 Preconditioner (const boost::shared_ptr< GlobalLinSys > &plinsys, const AssemblyMapSharedPtr &pLocToGloMap)
 
virtual ~Preconditioner ()
 
void DoPreconditioner (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput)
 
void DoPreconditionerWithNonVertOutput (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const Array< OneD, NekDouble > &pNonVertOutput, Array< OneD, NekDouble > &pVertForce=NullNekDouble1DArray)
 
void DoTransformToLowEnergy (Array< OneD, NekDouble > &pInOut, int offset)
 
void DoTransformToLowEnergy (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput)
 
void DoTransformFromLowEnergy (Array< OneD, NekDouble > &pInOut)
 
void DoMultiplybyInverseTransformationMatrix (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput)
 
void DoMultiplybyInverseTransposedTransformationMatrix (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput)
 
void BuildPreconditioner ()
 
void InitObject ()
 
Array< OneD, NekDoubleAssembleStaticCondGlobalDiagonals ()
 Performs global assembly of diagonal entries to global Schur complement matrix. More...
 
const DNekScalBlkMatSharedPtrGetBlockTransformedSchurCompl () const
 
const DNekScalBlkMatSharedPtrGetBlockCMatrix () const
 
const DNekScalBlkMatSharedPtrGetBlockInvDMatrix () const
 
const DNekScalBlkMatSharedPtrGetBlockSchurCompl () const
 
const DNekScalBlkMatSharedPtrGetBlockTransformationMatrix () const
 
const DNekScalBlkMatSharedPtrGetBlockTransposedTransformationMatrix () const
 
DNekScalMatSharedPtr TransformedSchurCompl (int offset, const boost::shared_ptr< DNekScalMat > &loc_mat)
 

Static Public Member Functions

static PreconditionerSharedPtr create (const boost::shared_ptr< GlobalLinSys > &plinsys, const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
 Creates an instance of this class. More...
 

Static Public Attributes

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

Protected Attributes

Array< OneD, NekDoublem_diagonals
 
PreconditionerType m_preconType
 
- Protected Attributes inherited from Nektar::MultiRegions::Preconditioner
const boost::weak_ptr
< GlobalLinSys
m_linsys
 
PreconditionerType m_preconType
 
DNekMatSharedPtr m_preconditioner
 
boost::shared_ptr< AssemblyMapm_locToGloMap
 
LibUtilities::CommSharedPtr m_comm
 

Private Member Functions

void DiagonalPreconditionerSum (void)
 
void StaticCondDiagonalPreconditionerSum (void)
 
virtual void v_InitObject ()
 
virtual void v_DoPreconditioner (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput)
 Apply a preconditioner to the conjugate gradient method. More...
 
virtual void v_BuildPreconditioner ()
 

Static Private Attributes

static std::string lookupIds []
 
static std::string def
 

Additional Inherited Members

- Protected Member Functions inherited from Nektar::MultiRegions::Preconditioner
virtual DNekScalMatSharedPtr v_TransformedSchurCompl (int offset, const boost::shared_ptr< DNekScalMat > &loc_mat)
 Get block elemental transposed transformation matrix $\mathbf{R}^{T}$. More...
 

Detailed Description

Definition at line 50 of file PreconditionerDiagonal.h.

Constructor & Destructor Documentation

Nektar::MultiRegions::PreconditionerDiagonal::PreconditionerDiagonal ( const boost::shared_ptr< GlobalLinSys > &  plinsys,
const AssemblyMapSharedPtr pLocToGloMap 
)

Definition at line 63 of file PreconditionerDiagonal.cpp.

66  : Preconditioner(plinsys, pLocToGloMap),
67  m_preconType(pLocToGloMap->GetPreconType())
68  {
69  }
Preconditioner(const boost::shared_ptr< GlobalLinSys > &plinsys, const AssemblyMapSharedPtr &pLocToGloMap)
virtual Nektar::MultiRegions::PreconditionerDiagonal::~PreconditionerDiagonal ( )
inlinevirtual

Definition at line 73 of file PreconditionerDiagonal.h.

73 {}

Member Function Documentation

static PreconditionerSharedPtr Nektar::MultiRegions::PreconditionerDiagonal::create ( const boost::shared_ptr< GlobalLinSys > &  plinsys,
const boost::shared_ptr< AssemblyMap > &  pLocToGloMap 
)
inlinestatic

Creates an instance of this class.

Definition at line 54 of file PreconditionerDiagonal.h.

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

58  {
60  p->InitObject();
61  return p;
62  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
boost::shared_ptr< Preconditioner > PreconditionerSharedPtr
Definition: GlobalLinSys.h:62
void Nektar::MultiRegions::PreconditionerDiagonal::DiagonalPreconditionerSum ( void  )
private

Diagonal preconditioner computed by summing the relevant elements of the local matrix system.

Definition at line 100 of file PreconditionerDiagonal.cpp.

References m_diagonals, Nektar::MultiRegions::Preconditioner::m_linsys, Nektar::MultiRegions::Preconditioner::m_locToGloMap, and Vmath::Sdiv().

Referenced by v_BuildPreconditioner().

101  {
102  boost::shared_ptr<MultiRegions::ExpList> expList =
103  ((m_linsys.lock())->GetLocMat()).lock();
104 
106 
107  int i,j,n,cnt,gid1,gid2;
108  NekDouble sign1,sign2,value;
109  int nGlobal = m_locToGloMap->GetNumGlobalCoeffs();
110  int nDir = m_locToGloMap->GetNumGlobalDirBndCoeffs();
111  int nInt = nGlobal - nDir;
112 
113  // fill global matrix
114  DNekScalMatSharedPtr loc_mat;
115  Array<OneD, NekDouble> vOutput(nGlobal,0.0);
116 
117  int loc_row;
118  int nElmt = expList->GetNumElmts();
119  for(n = cnt = 0; n < nElmt; ++n)
120  {
121  loc_mat = (m_linsys.lock())->GetBlock(expList->GetOffset_Elmt_Id(n));
122  loc_row = loc_mat->GetRows();
123 
124  for(i = 0; i < loc_row; ++i)
125  {
126  gid1 = m_locToGloMap->GetLocalToGlobalMap(cnt + i) - nDir;
127  sign1 = m_locToGloMap->GetLocalToGlobalSign(cnt + i);
128  if(gid1 >= 0)
129  {
130  for(j = 0; j < loc_row; ++j)
131  {
132  gid2 = m_locToGloMap->GetLocalToGlobalMap(cnt + j)
133  - nDir;
134  sign2 = m_locToGloMap->GetLocalToGlobalSign(cnt + j);
135  if(gid2 == gid1)
136  {
137  // When global matrix is symmetric,
138  // only add the value for the upper
139  // triangular part in order to avoid
140  // entries to be entered twice
141  value = vOutput[gid1 + nDir]
142  + sign1*sign2*(*loc_mat)(i,j);
143  vOutput[gid1 + nDir] = value;
144  }
145  }
146  }
147  }
148  cnt += loc_row;
149  }
150 
151  // Assemble diagonal contributions across processes
152  m_locToGloMap->UniversalAssemble(vOutput);
153 
154  m_diagonals = Array<OneD, NekDouble> (nInt);
155  Vmath::Sdiv(nInt, 1.0, &vOutput[nDir], 1, &m_diagonals[0], 1);
156  }
boost::shared_ptr< AssemblyMap > m_locToGloMap
void Sdiv(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha/y.
Definition: Vmath.cpp:271
boost::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
const boost::weak_ptr< GlobalLinSys > m_linsys
double NekDouble
boost::shared_ptr< StdExpansion > StdExpansionSharedPtr
void Nektar::MultiRegions::PreconditionerDiagonal::StaticCondDiagonalPreconditionerSum ( void  )
private

Diagonal preconditioner defined as the inverse of the main diagonal of the Schur complement

Definition at line 163 of file PreconditionerDiagonal.cpp.

References Nektar::MultiRegions::Preconditioner::AssembleStaticCondGlobalDiagonals(), m_diagonals, Nektar::MultiRegions::Preconditioner::m_locToGloMap, and Vmath::Sdiv().

Referenced by v_BuildPreconditioner().

164  {
165  int nGlobalBnd = m_locToGloMap->GetNumGlobalBndCoeffs();
166  int nDirBnd = m_locToGloMap->GetNumGlobalDirBndCoeffs();
167  int rows = nGlobalBnd - nDirBnd;
168 
169  Array<OneD, NekDouble> vOutput(nGlobalBnd,0.0);
170 
171  // Extract diagonal contributions
172  Array<OneD, NekDouble> diagonals = AssembleStaticCondGlobalDiagonals();
173  for (unsigned int i = 0; i < rows; ++i)
174  {
175  vOutput[nDirBnd + i] = diagonals[i];
176  }
177 
178  // Assemble diagonal contributions across processes
179  m_locToGloMap->UniversalAssembleBnd(vOutput);
180 
181  m_diagonals = Array<OneD, NekDouble> (rows);
182  Vmath::Sdiv(rows, 1.0, &vOutput[nDirBnd], 1, &m_diagonals[0], 1);
183  }
boost::shared_ptr< AssemblyMap > m_locToGloMap
void Sdiv(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha/y.
Definition: Vmath.cpp:271
Array< OneD, NekDouble > AssembleStaticCondGlobalDiagonals()
Performs global assembly of diagonal entries to global Schur complement matrix.
void Nektar::MultiRegions::PreconditionerDiagonal::v_BuildPreconditioner ( )
privatevirtual

Reimplemented from Nektar::MultiRegions::Preconditioner.

Definition at line 75 of file PreconditionerDiagonal.cpp.

References ASSERTL0, DiagonalPreconditionerSum(), Nektar::MultiRegions::eIterativeFull, Nektar::MultiRegions::eIterativeMultiLevelStaticCond, Nektar::MultiRegions::eIterativeStaticCond, Nektar::MultiRegions::ePETScMultiLevelStaticCond, Nektar::MultiRegions::ePETScStaticCond, Nektar::MultiRegions::Preconditioner::m_locToGloMap, and StaticCondDiagonalPreconditionerSum().

76  {
77  GlobalSysSolnType solvertype =
78  m_locToGloMap->GetGlobalSysSolnType();
79  if (solvertype == eIterativeFull)
80  {
82  }
83  else if(solvertype == eIterativeStaticCond ||
84  solvertype == eIterativeMultiLevelStaticCond ||
85  solvertype == ePETScStaticCond ||
86  solvertype == ePETScMultiLevelStaticCond)
87  {
89  }
90  else
91  {
92  ASSERTL0(0,"Unsupported solver type");
93  }
94  }
boost::shared_ptr< AssemblyMap > m_locToGloMap
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
void Nektar::MultiRegions::PreconditionerDiagonal::v_DoPreconditioner ( const Array< OneD, NekDouble > &  pInput,
Array< OneD, NekDouble > &  pOutput 
)
privatevirtual

Apply a preconditioner to the conjugate gradient method.

Reimplemented from Nektar::MultiRegions::Preconditioner.

Definition at line 188 of file PreconditionerDiagonal.cpp.

References Nektar::MultiRegions::eIterativeFull, m_diagonals, Nektar::MultiRegions::Preconditioner::m_locToGloMap, and Vmath::Vmul().

191  {
192  GlobalSysSolnType solvertype =
193  m_locToGloMap->GetGlobalSysSolnType();
194 
195  int nGlobal = solvertype == eIterativeFull ?
196  m_locToGloMap->GetNumGlobalCoeffs() :
197  m_locToGloMap->GetNumGlobalBndCoeffs();
198  int nDir = m_locToGloMap->GetNumGlobalDirBndCoeffs();
199  int nNonDir = nGlobal-nDir;
200  Vmath::Vmul(nNonDir, &pInput[0], 1, &m_diagonals[0], 1, &pOutput[0], 1);
201  }
boost::shared_ptr< AssemblyMap > m_locToGloMap
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
Definition: Vmath.cpp:183
void Nektar::MultiRegions::PreconditionerDiagonal::v_InitObject ( )
privatevirtual

Reimplemented from Nektar::MultiRegions::Preconditioner.

Definition at line 71 of file PreconditionerDiagonal.cpp.

72  {
73  }

Member Data Documentation

string Nektar::MultiRegions::PreconditionerDiagonal::className
static
Initial value:
"Diagonal",
"Diagonal Preconditioning")

Name of class.

Registers the class with the Factory.

Definition at line 65 of file PreconditionerDiagonal.h.

std::string Nektar::MultiRegions::PreconditionerDiagonal::def
staticprivate

Definition at line 96 of file PreconditionerDiagonal.h.

std::string Nektar::MultiRegions::PreconditionerDiagonal::lookupIds[]
staticprivate

Definition at line 95 of file PreconditionerDiagonal.h.

Array<OneD, NekDouble> Nektar::MultiRegions::PreconditionerDiagonal::m_diagonals
protected
PreconditionerType Nektar::MultiRegions::PreconditionerDiagonal::m_preconType
protected

Definition at line 79 of file PreconditionerDiagonal.h.