Nektar++
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Nektar::LibUtilities::NekLinSysIter Class Reference

#include <NekLinSysIter.h>

Inheritance diagram for Nektar::LibUtilities::NekLinSysIter:
[legend]

Public Member Functions

 NekLinSysIter (const LibUtilities::SessionReaderSharedPtr &pSession, const LibUtilities::CommSharedPtr &vRowComm, const int nDimen, const NekSysKey &pKey)
 
virtual ~NekLinSysIter ()
 
void setUniversalUniqueMap (Array< OneD, int > &map)
 
void setRhsMagnitude (const NekDouble mag)
 
void SetNekLinSysTolerance (const NekDouble in)
 
void SetNekLinSysMaxIterations (const unsigned int in)
 
void SetLinSysMaxStorage (const unsigned int in)
 
bool IsLocal ()
 
- Public Member Functions inherited from Nektar::LibUtilities::NekSys
 NekSys (const LibUtilities::SessionReaderSharedPtr &pSession, const LibUtilities::CommSharedPtr &vRowComm, const int nDimen, const NekSysKey &pKey)
 
void InitObject ()
 
virtual ~NekSys ()
 
void SetSysOperators (const NekSysOperators &in)
 
const NekSysOperatorsGetSysOperators ()
 
int SolveSystem (const int nGlobal, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const int nDir, const NekDouble tol=1.0E-7, const NekDouble factor=1.0)
 
bool ConvergenceCheck (const int nIteration, const Array< OneD, const NekDouble > &Residual, const NekDouble tol=1.0E-7)
 
void SetFlagWarnings (bool in)
 

Static Public Member Functions

static NekLinSysIterSharedPtr CreateInstance (const LibUtilities::SessionReaderSharedPtr &pSession, const LibUtilities::CommSharedPtr &vRowComm, const int nDimen, const NekSysKey &pKey)
 
- Static Public Member Functions inherited from Nektar::LibUtilities::NekSys
static NekSysSharedPtr CreateInstance (const LibUtilities::SessionReaderSharedPtr &pSession, const LibUtilities::CommSharedPtr &vRowComm, const int nDimen, const NekSysKey &pKey)
 

Protected Member Functions

void Set_Rhs_Magnitude (const NekVector< NekDouble > &pIn)
 
void Set_Rhs_Magnitude (const Array< OneD, NekDouble > &pIn)
 
void setUniversalUniqueMap ()
 
virtual void v_InitObject () override
 
- Protected Member Functions inherited from Nektar::LibUtilities::NekSys
virtual void v_InitObject ()
 
virtual int v_SolveSystem (const int nGlobal, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const int nDir, const NekDouble tol, const NekDouble factor)
 
virtual bool v_ConvergenceCheck (const int nIteration, const Array< OneD, const NekDouble > &Residual, const NekDouble tol)
 
virtual void v_NekSysInitialGuess (const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pguess)
 

Protected Attributes

Array< OneD, int > m_map
 Global to universal unique map. More...
 
NekDouble m_rhs_magnitude = NekConstants::kNekUnsetDouble
 Dot product of rhs to normalise stopping criterion. More...
 
int m_totalIterations = 0
 
NekDouble m_rhs_mag_sm = 0.9
 
NekDouble m_prec_factor = 1.0
 
int m_LinSysMaxStorage
 
bool m_isLocal
 
- Protected Attributes inherited from Nektar::LibUtilities::NekSys
int m_maxiter
 Maximum iterations. More...
 
NekDouble m_tolerance
 Tolerance of iterative solver. More...
 
LibUtilities::CommSharedPtr m_rowComm
 Communicate. More...
 
bool m_converged
 Whether the iteration has been converged. More...
 
bool m_root
 Root if parallel. More...
 
bool m_verbose
 Verbose. More...
 
bool m_FlagWarnings
 
NekSysOperators m_operator
 Operators. More...
 
int m_SysDimen
 The dimension of the system. More...
 

Friends

class MemoryManager< NekLinSysIter >
 Support creation through MemoryManager. More...
 

Detailed Description

Solves a linear system using iterative methods.

Definition at line 56 of file NekLinSysIter.h.

Constructor & Destructor Documentation

◆ NekLinSysIter()

Nektar::LibUtilities::NekLinSysIter::NekLinSysIter ( const LibUtilities::SessionReaderSharedPtr pSession,
const LibUtilities::CommSharedPtr vRowComm,
const int  nDimen,
const NekSysKey pKey 
)

Definition at line 56 of file NekLinSysIter.cpp.

60 : NekSys(pSession, vRowComm, nDimen, pKey)
61{
62 std::vector<std::string> variables(1);
63 variables[0] = pSession->GetVariable(0);
64 string variable = variables[0];
65
66 if (pSession->DefinesGlobalSysSolnInfo(variable, "NekLinSysTolerance"))
67 {
68 m_tolerance = boost::lexical_cast<NekDouble>(
69 pSession->GetGlobalSysSolnInfo(variable, "NekLinSysTolerance")
70 .c_str());
71 }
72 else
73 {
74 pSession->LoadParameter("NekLinSysTolerance", m_tolerance,
75 pKey.m_NekLinSysTolerance);
76 }
77
78 if (pSession->DefinesGlobalSysSolnInfo(variable, "NekLinSysMaxIterations"))
79 {
80 m_maxiter = boost::lexical_cast<int>(
81 pSession->GetGlobalSysSolnInfo(variable, "NekLinSysMaxIterations")
82 .c_str());
83 }
84 else
85 {
86 pSession->LoadParameter("NekLinSysMaxIterations", m_maxiter,
87 pKey.m_NekLinSysMaxIterations);
88 }
89
90 if (pSession->DefinesGlobalSysSolnInfo(variable, "LinSysMaxStorage"))
91 {
92 m_LinSysMaxStorage = boost::lexical_cast<int>(
93 pSession->GetGlobalSysSolnInfo(variable, "LinSysMaxStorage")
94 .c_str());
95 }
96 else
97 {
98 pSession->LoadParameter("LinSysMaxStorage", m_LinSysMaxStorage,
99 pKey.m_LinSysMaxStorage);
100 }
101
102 m_isLocal = false;
103}
NekDouble m_tolerance
Tolerance of iterative solver.
Definition: NekSys.h:300
NekSys(const LibUtilities::SessionReaderSharedPtr &pSession, const LibUtilities::CommSharedPtr &vRowComm, const int nDimen, const NekSysKey &pKey)
Definition: NekSys.cpp:50
int m_maxiter
Maximum iterations.
Definition: NekSys.h:298

References m_isLocal, m_LinSysMaxStorage, Nektar::LibUtilities::NekSysKey::m_LinSysMaxStorage, Nektar::LibUtilities::NekSys::m_maxiter, Nektar::LibUtilities::NekSysKey::m_NekLinSysMaxIterations, Nektar::LibUtilities::NekSysKey::m_NekLinSysTolerance, and Nektar::LibUtilities::NekSys::m_tolerance.

◆ ~NekLinSysIter()

Nektar::LibUtilities::NekLinSysIter::~NekLinSysIter ( )
virtual

Definition at line 111 of file NekLinSysIter.cpp.

112{
113}

Member Function Documentation

◆ CreateInstance()

static NekLinSysIterSharedPtr Nektar::LibUtilities::NekLinSysIter::CreateInstance ( const LibUtilities::SessionReaderSharedPtr pSession,
const LibUtilities::CommSharedPtr vRowComm,
const int  nDimen,
const NekSysKey pKey 
)
inlinestatic

Definition at line 62 of file NekLinSysIter.h.

66 {
69 nDimen, pKey);
70 return p;
71 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< NekLinSysIter > NekLinSysIterSharedPtr
Definition: NekLinSysIter.h:48

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

◆ IsLocal()

bool Nektar::LibUtilities::NekLinSysIter::IsLocal ( )
inline

Definition at line 98 of file NekLinSysIter.h.

99 {
100 return m_isLocal;
101 }

References m_isLocal.

◆ Set_Rhs_Magnitude() [1/2]

void Nektar::LibUtilities::NekLinSysIter::Set_Rhs_Magnitude ( const Array< OneD, NekDouble > &  pIn)
protected

Definition at line 157 of file NekLinSysIter.cpp.

158{
159 Array<OneD, NekDouble> vExchange(1, 0.0);
160
161 Array<OneD, NekDouble> wk(pIn.size());
162 m_operator.DoAssembleLoc(pIn, wk);
163 vExchange[0] = Vmath::Dot(pIn.size(), wk, pIn);
164 m_rowComm->AllReduce(vExchange, LibUtilities::ReduceSum);
165
166 // To ensure that very different rhs values are not being
167 // used in subsequent solvers such as the velocit solve in
168 // INC NS. If this works we then need to work out a better
169 // way to control this.
170 NekDouble new_rhs_mag = (vExchange[0] > 1e-6) ? vExchange[0] : 1.0;
171
173 {
174 m_rhs_magnitude = new_rhs_mag;
175 }
176 else
177 {
179 (1.0 - m_rhs_mag_sm) * new_rhs_mag);
180 }
181}
NekDouble m_rhs_magnitude
Dot product of rhs to normalise stopping criterion.
LibUtilities::CommSharedPtr m_rowComm
Communicate.
Definition: NekSys.h:302
NekSysOperators m_operator
Operators.
Definition: NekSys.h:311
void DoAssembleLoc(InArrayType &xn, OutArrayType &xn1, const bool &flag=false) const
Definition: NekSys.h:163
static const NekDouble kNekUnsetDouble
double NekDouble
T Dot(int n, const T *w, const T *x)
dot (vector times vector): z = w*x
Definition: Vmath.cpp:1095

References Nektar::LibUtilities::NekSysOperators::DoAssembleLoc(), Vmath::Dot(), Nektar::NekConstants::kNekUnsetDouble, Nektar::LibUtilities::NekSys::m_operator, m_rhs_mag_sm, m_rhs_magnitude, Nektar::LibUtilities::NekSys::m_rowComm, and Nektar::LibUtilities::ReduceSum.

◆ Set_Rhs_Magnitude() [2/2]

void Nektar::LibUtilities::NekLinSysIter::Set_Rhs_Magnitude ( const NekVector< NekDouble > &  pIn)
protected

Definition at line 130 of file NekLinSysIter.cpp.

131{
132 NekDouble vExchange(0.0);
133 if (m_map.size() > 0)
134 {
135 vExchange =
136 Vmath::Dot2(pIn.GetDimension(), &pIn[0], &pIn[0], &m_map[0]);
137 }
138 m_rowComm->AllReduce(vExchange, LibUtilities::ReduceSum);
139
140 // To ensure that very different rhs values are not being
141 // used in subsequent solvers such as the velocit solve in
142 // INC NS. If this works we then need to work out a better
143 // way to control this.
144 NekDouble new_rhs_mag = (vExchange > 1.0e-6) ? vExchange : 1.0;
145
147 {
148 m_rhs_magnitude = new_rhs_mag;
149 }
150 else
151 {
153 (1.0 - m_rhs_mag_sm) * new_rhs_mag);
154 }
155}
Array< OneD, int > m_map
Global to universal unique map.
unsigned int GetDimension() const
Returns the number of dimensions for the point.
Definition: NekVector.cpp:201
T Dot2(int n, const T *w, const T *x, const int *y)
dot2 (vector times vector times vector): z = w*x*y
Definition: Vmath.cpp:1142

References Vmath::Dot2(), Nektar::NekVector< DataType >::GetDimension(), Nektar::NekConstants::kNekUnsetDouble, m_map, m_rhs_mag_sm, m_rhs_magnitude, Nektar::LibUtilities::NekSys::m_rowComm, and Nektar::LibUtilities::ReduceSum.

Referenced by Nektar::LibUtilities::NekLinSysIterCGLoc::DoConjugateGradient(), and Nektar::LibUtilities::NekLinSysIterCG::DoConjugateGradient().

◆ SetLinSysMaxStorage()

void Nektar::LibUtilities::NekLinSysIter::SetLinSysMaxStorage ( const unsigned int  in)
inline

Definition at line 93 of file NekLinSysIter.h.

94 {
96 }

References m_LinSysMaxStorage.

◆ SetNekLinSysMaxIterations()

void Nektar::LibUtilities::NekLinSysIter::SetNekLinSysMaxIterations ( const unsigned int  in)
inline

Definition at line 88 of file NekLinSysIter.h.

89 {
90 m_maxiter = in;
91 }

References Nektar::LibUtilities::NekSys::m_maxiter.

◆ SetNekLinSysTolerance()

void Nektar::LibUtilities::NekLinSysIter::SetNekLinSysTolerance ( const NekDouble  in)
inline

Definition at line 83 of file NekLinSysIter.h.

84 {
85 m_tolerance = in;
86 }

References Nektar::LibUtilities::NekSys::m_tolerance.

◆ setRhsMagnitude()

void Nektar::LibUtilities::NekLinSysIter::setRhsMagnitude ( const NekDouble  mag)
inline

Definition at line 79 of file NekLinSysIter.h.

80 {
81 m_rhs_magnitude = mag;
82 }

References m_rhs_magnitude.

◆ setUniversalUniqueMap() [1/2]

void Nektar::LibUtilities::NekLinSysIter::setUniversalUniqueMap ( )
protected

Definition at line 125 of file NekLinSysIter.cpp.

126{
127 m_map = Array<OneD, int>(m_SysDimen, 1);
128}
int m_SysDimen
The dimension of the system.
Definition: NekSys.h:313

References m_map, and Nektar::LibUtilities::NekSys::m_SysDimen.

Referenced by v_InitObject().

◆ setUniversalUniqueMap() [2/2]

void Nektar::LibUtilities::NekLinSysIter::setUniversalUniqueMap ( Array< OneD, int > &  map)

Definition at line 115 of file NekLinSysIter.cpp.

116{
117 int nmap = map.size();
118 if (m_map.size() != nmap)
119 {
120 m_map = Array<OneD, int>(nmap, 0);
121 }
122 Vmath::Vcopy(nmap, map, 1, m_map, 1);
123}
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1191

References m_map, and Vmath::Vcopy().

◆ v_InitObject()

void Nektar::LibUtilities::NekLinSysIter::v_InitObject ( )
overrideprotectedvirtual

Friends And Related Function Documentation

◆ MemoryManager< NekLinSysIter >

friend class MemoryManager< NekLinSysIter >
friend

Support creation through MemoryManager.

Definition at line 54 of file NekLinSysIter.h.

Member Data Documentation

◆ m_isLocal

bool Nektar::LibUtilities::NekLinSysIter::m_isLocal
protected

◆ m_LinSysMaxStorage

int Nektar::LibUtilities::NekLinSysIter::m_LinSysMaxStorage
protected

◆ m_map

Array<OneD, int> Nektar::LibUtilities::NekLinSysIter::m_map
protected

◆ m_prec_factor

NekDouble Nektar::LibUtilities::NekLinSysIter::m_prec_factor = 1.0
protected

◆ m_rhs_mag_sm

NekDouble Nektar::LibUtilities::NekLinSysIter::m_rhs_mag_sm = 0.9
protected

Definition at line 111 of file NekLinSysIter.h.

Referenced by Set_Rhs_Magnitude().

◆ m_rhs_magnitude

NekDouble Nektar::LibUtilities::NekLinSysIter::m_rhs_magnitude = NekConstants::kNekUnsetDouble
protected

◆ m_totalIterations

int Nektar::LibUtilities::NekLinSysIter::m_totalIterations = 0
protected