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

#include <PreconditionerDiagonal.h>

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

Public Member Functions

 PreconditionerJacobi (const std::shared_ptr< GlobalLinSys > &plinsys, const AssemblyMapSharedPtr &pLocToGloMap)
 
 ~PreconditionerJacobi () override
 
- Public Member Functions inherited from Nektar::MultiRegions::PreconditionerDiagonal
 PreconditionerDiagonal (const std::shared_ptr< GlobalLinSys > &plinsys, const AssemblyMapSharedPtr &pLocToGloMap)
 
 ~PreconditionerDiagonal () override
 
- Public Member Functions inherited from Nektar::MultiRegions::Preconditioner
 Preconditioner (const std::shared_ptr< GlobalLinSys > &plinsys, const AssemblyMapSharedPtr &pLocToGloMap)
 
virtual ~Preconditioner ()
 
void DoPreconditioner (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const bool &IsLocal=false)
 
void DoAssembleLoc (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const bool &ZeroDir)
 Apply an assembly and scatter back to lcoal array. More...
 
void DoPreconditionerWithNonVertOutput (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const Array< OneD, NekDouble > &pNonVertOutput, Array< OneD, NekDouble > &pVertForce=NullNekDouble1DArray)
 
void DoTransformBasisToLowEnergy (Array< OneD, NekDouble > &pInOut)
 
void DoTransformCoeffsFromLowEnergy (Array< OneD, NekDouble > &pInOut)
 
void DoTransformCoeffsToLowEnergy (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput)
 
void DoTransformBasisFromLowEnergy (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, int bndoffset, const std::shared_ptr< DNekScalMat > &loc_mat)
 

Static Public Member Functions

static PreconditionerSharedPtr create (const std::shared_ptr< GlobalLinSys > &plinsys, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
 Creates an instance of this class. More...
 
- Static Public Member Functions inherited from Nektar::MultiRegions::PreconditionerDiagonal
static PreconditionerSharedPtr create (const std::shared_ptr< GlobalLinSys > &plinsys, 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 Public Attributes inherited from Nektar::MultiRegions::PreconditionerDiagonal
static std::string className
 Name of class. More...
 

Protected Member Functions

void v_InitObject () override
 
void v_BuildPreconditioner () override
 
void v_DoPreconditioner (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const bool &IsLocal=false) override
 Apply a preconditioner to the conjugate gradient method. More...
 
void v_InitObject () override
 
void v_DoPreconditioner (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const bool &IsLocal=false) override
 Apply a preconditioner to the conjugate gradient method. More...
 
void v_BuildPreconditioner () override
 
- Protected Member Functions inherited from Nektar::MultiRegions::Preconditioner
virtual DNekScalMatSharedPtr v_TransformedSchurCompl (int offset, int bndoffset, const std::shared_ptr< DNekScalMat > &loc_mat)
 Get block elemental transposed transformation matrix \(\mathbf{R}^{T}\). More...
 
virtual void v_InitObject ()
 
virtual void v_DoPreconditioner (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const bool &isLocal=false)
 Apply a preconditioner to the conjugate gradient method. More...
 
virtual void v_DoPreconditionerWithNonVertOutput (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const Array< OneD, NekDouble > &pNonVertOutput, Array< OneD, NekDouble > &pVertForce)
 Apply a preconditioner to the conjugate gradient method with an output for non-vertex degrees of freedom. More...
 
virtual void v_DoTransformBasisToLowEnergy (Array< OneD, NekDouble > &pInOut)
 Transform from original basis to low energy basis. More...
 
virtual void v_DoTransformCoeffsFromLowEnergy (Array< OneD, NekDouble > &pInOut)
 Transform from low energy coeffs to orignal basis. More...
 
virtual void v_DoTransformCoeffsToLowEnergy (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput)
 Multiply by the block inverse transformation matrix. More...
 
virtual void v_DoTransformBasisFromLowEnergy (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput)
 Multiply by the block transposed inverse transformation matrix. More...
 
virtual void v_BuildPreconditioner ()
 

Private Attributes

int m_niter
 

Static Private Attributes

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

Additional Inherited Members

- Protected Attributes inherited from Nektar::MultiRegions::PreconditionerDiagonal
Array< OneD, NekDoublem_diagonals
 
- Protected Attributes inherited from Nektar::MultiRegions::Preconditioner
const std::weak_ptr< GlobalLinSysm_linsys
 
std::string m_preconType
 
DNekMatSharedPtr m_preconditioner
 
std::weak_ptr< AssemblyMapm_locToGloMap
 

Detailed Description

This class implements jacobi preconditioning building on diagonal version above

Definition at line 140 of file PreconditionerDiagonal.h.

Constructor & Destructor Documentation

◆ PreconditionerJacobi()

Nektar::MultiRegions::PreconditionerJacobi::PreconditionerJacobi ( const std::shared_ptr< GlobalLinSys > &  plinsys,
const AssemblyMapSharedPtr pLocToGloMap 
)

Definition at line 265 of file PreconditionerDiagonal.cpp.

268 : PreconditionerDiagonal(plinsys, pLocToGloMap)
269{
270}
PreconditionerDiagonal(const std::shared_ptr< GlobalLinSys > &plinsys, const AssemblyMapSharedPtr &pLocToGloMap)

◆ ~PreconditionerJacobi()

Nektar::MultiRegions::PreconditionerJacobi::~PreconditionerJacobi ( )
inlineoverride

Definition at line 164 of file PreconditionerDiagonal.h.

165 {
166 }

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 144 of file PreconditionerDiagonal.h.

147 {
150 plinsys, pLocToGloMap);
151 p->InitObject();
152 return p;
153 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< Preconditioner > PreconditionerSharedPtr
Definition: GlobalLinSys.h:58

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

◆ v_BuildPreconditioner()

void Nektar::MultiRegions::PreconditionerJacobi::v_BuildPreconditioner ( )
overrideprotectedvirtual

Reimplemented from Nektar::MultiRegions::PreconditionerDiagonal.

Definition at line 276 of file PreconditionerDiagonal.cpp.

277{
279
280 auto expList = ((m_linsys.lock())->GetLocMat()).lock();
281 std::shared_ptr<LibUtilities::SessionReader> session =
282 expList->GetSession();
283
284 std::string var = m_locToGloMap.lock()->GetVariable();
285
286 if (session->DefinesGlobalSysSolnInfo(var, "JacobiIterations"))
287 {
288 m_niter = boost::lexical_cast<int>(
289 session->GetGlobalSysSolnInfo(var, "JacobiIterations").c_str());
290 }
291 else
292 {
293 m_niter = 3;
294 }
295}
const std::weak_ptr< GlobalLinSys > m_linsys
std::weak_ptr< AssemblyMap > m_locToGloMap

References Nektar::MultiRegions::Preconditioner::m_linsys, Nektar::MultiRegions::Preconditioner::m_locToGloMap, m_niter, and Nektar::MultiRegions::PreconditionerDiagonal::v_BuildPreconditioner().

◆ v_DoPreconditioner()

void Nektar::MultiRegions::PreconditionerJacobi::v_DoPreconditioner ( const Array< OneD, NekDouble > &  pInput,
Array< OneD, NekDouble > &  pOutput,
const bool &  isLocal = false 
)
overrideprotectedvirtual

Apply a preconditioner to the conjugate gradient method.

Reimplemented from Nektar::MultiRegions::PreconditionerDiagonal.

Definition at line 300 of file PreconditionerDiagonal.cpp.

303{
304 auto asmMap = m_locToGloMap.lock();
305
306 GlobalSysSolnType solvertype = asmMap->GetGlobalSysSolnType();
307
308 int nGlobal = solvertype == eIterativeFull
309 ? asmMap->GetNumGlobalCoeffs()
310 : asmMap->GetNumGlobalBndCoeffs();
311 int nDir = asmMap->GetNumGlobalDirBndCoeffs();
312 int nNonDir = nGlobal - nDir;
313 Array<OneD, NekDouble> wk(nGlobal);
314
315 if (IsLocal)
316 {
317 int nLocal = solvertype == eIterativeFull
318 ? asmMap->GetNumLocalCoeffs()
319 : asmMap->GetNumLocalBndCoeffs();
320
321 Array<OneD, NekDouble> wk1(nLocal);
322 asmMap->Assemble(pInput, wk);
323 Vmath::Vmul(nNonDir, wk.data() + nDir, 1, m_diagonals.data(), 1,
324 wk.data() + nDir, 1);
325 Vmath::Zero(nDir, wk, 1);
326
327 for (int n = 1; n < m_niter; ++n)
328 {
329 asmMap->GlobalToLocal(wk, pOutput);
330
331 // do Ax operator
332 std::dynamic_pointer_cast<GlobalLinSysIterative>(m_linsys.lock())
333 ->DoMatrixMultiply(pOutput, wk1);
334
335 Vmath::Vsub(nLocal, pInput, 1, wk1, 1, wk1, 1);
336
337 asmMap->Assemble(wk1, pOutput);
338 Vmath::Vvtvp(nNonDir, pOutput.data() + nDir, 1, m_diagonals.data(),
339 1, wk.data() + nDir, 1, wk.data() + nDir, 1);
340 }
341
342 asmMap->GlobalToLocal(wk, pOutput);
343 }
344 else
345 {
346 Array<OneD, NekDouble> wk1(nGlobal);
347 Vmath::Vmul(nNonDir, pInput.data(), 1, m_diagonals.data(), 1,
348 wk.data() + nDir, 1);
349 Vmath::Zero(nDir, wk, 1);
350
351 for (int n = 1; n < m_niter; ++n)
352 {
353 // do Ax operator
354 std::dynamic_pointer_cast<GlobalLinSysIterative>(m_linsys.lock())
355 ->DoMatrixMultiply(wk, wk1);
356
357 // b - Ax
358 Vmath::Vsub(nNonDir, pInput.data(), 1, wk1.data() + nDir, 1,
359 wk1.data() + nDir, 1);
360
361 // new sol = 1/diag (b-Ax) + old sol
362 Vmath::Vvtvp(nNonDir, wk1.data() + nDir, 1, m_diagonals.data(), 1,
363 wk.data() + nDir, 1, wk.data() + nDir, 1);
364 }
365
366 Vmath::Vcopy(nNonDir, wk.data() + nDir, 1, pOutput.data(), 1);
367 }
368}
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.hpp:72
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
Definition: Vmath.hpp:366
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
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 Nektar::MultiRegions::eIterativeFull, Nektar::MultiRegions::PreconditionerDiagonal::m_diagonals, Nektar::MultiRegions::Preconditioner::m_linsys, Nektar::MultiRegions::Preconditioner::m_locToGloMap, m_niter, Vmath::Vcopy(), Vmath::Vmul(), Vmath::Vsub(), Vmath::Vvtvp(), and Vmath::Zero().

◆ v_InitObject()

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

Reimplemented from Nektar::MultiRegions::PreconditionerDiagonal.

Definition at line 272 of file PreconditionerDiagonal.cpp.

273{
274}

Member Data Documentation

◆ className

string Nektar::MultiRegions::PreconditionerJacobi::className
static
Initial value:
=
"Jacobi", PreconditionerJacobi::create, "Jacobi Preconditioning")
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
static PreconditionerSharedPtr create(const std::shared_ptr< GlobalLinSys > &plinsys, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Creates an instance of this class.
PreconFactory & GetPreconFactory()

Name of class.

Registers the class with the Factory.

Definition at line 156 of file PreconditionerDiagonal.h.

◆ def

std::string Nektar::MultiRegions::PreconditionerJacobi::def
staticprivate

Definition at line 181 of file PreconditionerDiagonal.h.

◆ lookupIds

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

Definition at line 180 of file PreconditionerDiagonal.h.

◆ m_niter

int Nektar::MultiRegions::PreconditionerJacobi::m_niter
private

Definition at line 178 of file PreconditionerDiagonal.h.

Referenced by v_BuildPreconditioner(), and v_DoPreconditioner().