Nektar++
Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Static Private Attributes | Friends | List of all members
Nektar::SolverUtils::DriverArpack Class Reference

Base class for the development of solvers. More...

#include <DriverArpack.h>

Inheritance diagram for Nektar::SolverUtils::DriverArpack:
Inheritance graph
[legend]
Collaboration diagram for Nektar::SolverUtils::DriverArpack:
Collaboration graph
[legend]

Static Public Member Functions

static DriverSharedPtr create (const LibUtilities::SessionReaderSharedPtr &pSession)
 Creates an instance of this class. More...
 

Static Public Attributes

static std::string className = GetDriverFactory().RegisterCreatorFunction("Arpack", DriverArpack::create)
 Name of the class. More...
 

Protected Member Functions

 DriverArpack (const LibUtilities::SessionReaderSharedPtr pSession)
 Constructor. More...
 
virtual ~DriverArpack ()
 Destructor. More...
 
virtual void v_InitObject (ostream &out=cout)
 Virtual function for initialisation implementation. More...
 
virtual void v_Execute (ostream &out=cout)
 Virtual function for solve implementation. More...
 
- Protected Member Functions inherited from Nektar::SolverUtils::DriverArnoldi
 DriverArnoldi (const LibUtilities::SessionReaderSharedPtr pSession)
 Constructor. More...
 
virtual ~DriverArnoldi ()
 Destructor. More...
 
void CopyArnoldiArrayToField (Array< OneD, NekDouble > &array)
 Copy Arnoldi storage to fields. More...
 
void CopyFieldToArnoldiArray (Array< OneD, NekDouble > &array)
 Copy fields to Arnoldi storage. More...
 
void CopyFwdToAdj ()
 Copy the forward field to the adjoint system in transient growth calculations. More...
 
void WriteFld (std::string file, std::vector< Array< OneD, NekDouble > > coeffs)
 
void WriteFld (std::string file, Array< OneD, NekDouble > coeffs)
 
void WriteEvs (ostream &evlout, const int k, const NekDouble real, const NekDouble imag, NekDouble resid=NekConstants::kNekUnsetDouble)
 
virtual Array< OneD, NekDoublev_GetRealEvl (void)
 
virtual Array< OneD, NekDoublev_GetImagEvl (void)
 
- Protected Member Functions inherited from Nektar::SolverUtils::Driver
 Driver (const LibUtilities::SessionReaderSharedPtr pSession)
 Initialises EquationSystem class members. More...
 

Protected Attributes

int m_maxn
 
int m_maxnev
 
int m_maxncv
 
- Protected Attributes inherited from Nektar::SolverUtils::DriverArnoldi
int m_kdim
 
int m_nvec
 Dimension of Krylov subspace. More...
 
int m_nits
 Number of vectors to test. More...
 
NekDouble m_evtol
 Maxmum number of iterations. More...
 
NekDouble m_period
 Tolerance of iteratiosn. More...
 
bool m_timeSteppingAlgorithm
 Period of time stepping algorithm. More...
 
int m_infosteps
 underlying operator is time stepping More...
 
int m_nfields
 interval to dump information if required. More...
 
NekDouble m_realShift
 
NekDouble m_imagShift
 
Array< OneD, NekDoublem_real_evl
 
Array< OneD, NekDoublem_imag_evl
 
- Protected Attributes inherited from Nektar::SolverUtils::Driver
LibUtilities::CommSharedPtr m_comm
 Communication object. More...
 
LibUtilities::SessionReaderSharedPtr m_session
 Session reader object. More...
 
LibUtilities::SessionReaderSharedPtr session_LinNS
 I the Coupling between SFD and arnoldi. More...
 
Array< OneD, EquationSystemSharedPtrm_equ
 Equation system to solve. More...
 
int m_nequ
 number of equations More...
 
enum EvolutionOperatorType m_EvolutionOperator
 Evolution Operator. More...
 

Static Protected Attributes

static std::string arpackProblemTypeLookupIds []
 
static std::string arpackProblemTypeDefault = LibUtilities::SessionReader::RegisterDefaultSolverInfo("ArpackProblemType","LargestMag")
 
static std::string driverLookupId = LibUtilities::SessionReader::RegisterEnumValue("Driver","Arpack",0)
 
- Static Protected Attributes inherited from Nektar::SolverUtils::Driver
static std::string evolutionOperatorLookupIds []
 
static std::string evolutionOperatorDef
 
static std::string driverDefault
 

Static Private Attributes

static std::string ArpackProblemTypeTrans []
 

Friends

class MemoryManager< DriverArpack >
 

Additional Inherited Members

- Public Member Functions inherited from Nektar::SolverUtils::DriverArnoldi
SOLVER_UTILS_EXPORT void ArnoldiSummary (std::ostream &out)
 
- Public Member Functions inherited from Nektar::SolverUtils::Driver
virtual ~Driver ()
 Destructor. More...
 
SOLVER_UTILS_EXPORT void InitObject (ostream &out=cout)
 Initialise Object. More...
 
SOLVER_UTILS_EXPORT void Execute (ostream &out=cout)
 Execute driver. More...
 
SOLVER_UTILS_EXPORT Array< OneD, EquationSystemSharedPtrGetEqu ()
 
SOLVER_UTILS_EXPORT Array< OneD, NekDoubleGetRealEvl (void)
 
SOLVER_UTILS_EXPORT Array< OneD, NekDoubleGetImagEvl (void)
 

Detailed Description

Base class for the development of solvers.

Definition at line 48 of file DriverArpack.h.

Constructor & Destructor Documentation

Nektar::SolverUtils::DriverArpack::DriverArpack ( const LibUtilities::SessionReaderSharedPtr  pSession)
protected

Constructor.

Definition at line 62 of file DriverArpack.cpp.

63  : DriverArnoldi(pSession)
64  {
65  }
DriverArnoldi(const LibUtilities::SessionReaderSharedPtr pSession)
Constructor.
Nektar::SolverUtils::DriverArpack::~DriverArpack ( )
protectedvirtual

Destructor.

Definition at line 71 of file DriverArpack.cpp.

72  {
73  }

Member Function Documentation

static DriverSharedPtr Nektar::SolverUtils::DriverArpack::create ( const LibUtilities::SessionReaderSharedPtr pSession)
inlinestatic

Creates an instance of this class.

Definition at line 54 of file DriverArpack.h.

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

54  {
56  p->InitObject();
57  return p;
58  }
boost::shared_ptr< Driver > DriverSharedPtr
A shared pointer to a Driver object.
Definition: Driver.h:52
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
void Nektar::SolverUtils::DriverArpack::v_Execute ( ostream &  out = cout)
protectedvirtual

Virtual function for solve implementation.

Implements Nektar::SolverUtils::Driver.

Definition at line 109 of file DriverArpack.cpp.

References ArpackProblemTypeTrans, ASSERTL0, Nektar::SolverUtils::DriverArnoldi::CopyArnoldiArrayToField(), Nektar::SolverUtils::DriverArnoldi::CopyFieldToArnoldiArray(), Nektar::SolverUtils::DriverArnoldi::CopyFwdToAdj(), Arpack::Dnaupd(), Arpack::Dneupd(), Nektar::SolverUtils::eTransientGrowth, Nektar::NekConstants::kNekZeroTol, Nektar::SolverUtils::Driver::m_comm, Nektar::SolverUtils::Driver::m_equ, Nektar::SolverUtils::Driver::m_EvolutionOperator, Nektar::SolverUtils::DriverArnoldi::m_evtol, Nektar::SolverUtils::DriverArnoldi::m_imag_evl, Nektar::SolverUtils::DriverArnoldi::m_imagShift, Nektar::SolverUtils::DriverArnoldi::m_infosteps, Nektar::SolverUtils::DriverArnoldi::m_kdim, m_maxn, Nektar::SolverUtils::DriverArnoldi::m_nfields, Nektar::SolverUtils::DriverArnoldi::m_nits, Nektar::SolverUtils::DriverArnoldi::m_nvec, Nektar::SolverUtils::DriverArnoldi::m_real_evl, Nektar::SolverUtils::DriverArnoldi::m_realShift, Nektar::SolverUtils::Driver::m_session, Nektar::SolverUtils::DriverArnoldi::m_timeSteppingAlgorithm, Nektar::SolverUtils::DriverArnoldi::WriteEvs(), and Nektar::SolverUtils::DriverArnoldi::WriteFld().

111  {
112  Array<OneD, NekDouble> tmpworkd;
113 
114  int nq = m_equ[0]->UpdateFields()[0]->GetNcoeffs(); // Number of points in the mesh
115  int n = m_nfields*nq; // Number of points in eigenvalue calculation
116  int lworkl = 3*m_kdim*(m_kdim+2); // Size of work array
117  int ido ; //REVERSE COMMUNICATION parameter. At the first call must be initialised at 0
118  int info; // do not set initial vector (info=0 random initial vector, info=1 read initial vector from session file)
119 
120  int iparam[11];
121  int ipntr[14];
122 
123  Array<OneD, int> ritzSelect;
126  Array<OneD, NekDouble> workev;
128  NekDouble sigmar, sigmai;
129 
130  Array<OneD, NekDouble> resid(n);
132  Array<OneD, NekDouble> workl(lworkl);
133  Array<OneD, NekDouble> workd(3*n, 0.0);
134 
135  ASSERTL0(n <= m_maxn, "N is greater than MAXN");
136 
137  if(m_session->DefinesFunction("InitialConditions"))
138  {
139 
140  out << "\tInital vector : input file " << endl;
141  info = 1;
143 
144  }
145  else
146  {
147  out << "\tInital vector : random " << endl;
148  info = 0;
149  }
150 
151 
152  iparam[0] = 1; // strategy for shift-invert
153  iparam[1] = 0; // (deprecated)
154  iparam[2] = m_nits; // maximum number of iterations allowed/taken
155  iparam[3] = 1; // blocksize to be used for recurrence
156  iparam[4] = 0; // number of converged ritz eigenvalues
157  iparam[5] = 0; // (deprecated)
158  if((fabs(m_realShift) > NekConstants::kNekZeroTol)|| // use shift if m_realShift > 1e-12
160  {
161  iparam[6] = 3;
162  }
163  else
164  {
165  iparam[6] = 1; // computation mode 1=> matrix-vector prod
166  }
167  iparam[7] = 0; // (for shift-invert)
168  iparam[8] = 0; // number of MV operations
169  iparam[9] = 0; // number of BV operations
170  iparam[10]= 0; // number of reorthogonalisation steps
171 
172  int cycle = 0;
173  const char* problem = ArpackProblemTypeTrans[m_session->GetSolverInfoAsEnum<int>("ArpackProblemType")].c_str();
174 
175  std::string name = m_session->GetSessionName() + ".evl";
176  ofstream pFile(name.c_str());
177 
178  ido = 0; //At the first call must be initialisedat 0
179 
180  while(ido != 99)//ido==-1 || ido==1 || ido==0)
181  {
182  //Routine for eigenvalue evaluation for non-symmetric operators
183  Arpack::Dnaupd( ido, "I", // B='I' for std eval problem
184  n, problem, m_nvec,
185  m_evtol, &resid[0], m_kdim,
186  &v[0], n, iparam, ipntr, &workd[0],
187  &workl[0], lworkl, info);
188 
189  //Plotting of real and imaginary part of the eigenvalues from workl
190  out << "\rIteration " << cycle << ", output: " << info << ", ido=" << ido << " " << std::flush;
191 
192  if(!((cycle-1)%m_kdim)&&(cycle> m_kdim))
193  {
194  pFile << "Krylov spectrum at iteration: " << cycle << endl;
195 
197  {
198  pFile << "EV Magnitude Angle Growth Frequency Residual" << endl;
199  }
200  else
201  {
202  pFile << "EV Real Imaginary inverse real inverse imag Residual" << endl;
203  }
204 
205  out << endl;
206  for(int k=0; k<=m_kdim-1; ++k)
207  {
208  // write m_nvec eigs to screen
209  if(m_kdim-1-k < m_nvec)
210  {
211  WriteEvs(out,k, workl[ipntr[5]-1+k],workl[ipntr[6]-1+k]);
212  }
213  // write m_kdim eigs to screen
214  WriteEvs(pFile,k, workl[ipntr[5]-1+k],workl[ipntr[6]-1+k]);
215  }
216  }
217 
218  cycle++;
219 
220  if (ido == 99) break;
221 
222  ASSERTL0(ido == 1, "Unexpected reverse communication request.");
223 
224  //workd[inptr[0]-1] copied into operator fields
225  CopyArnoldiArrayToField(tmpworkd = workd + (ipntr[0]-1));
226 
227  m_equ[0]->TransCoeffToPhys();
228 
229  m_equ[0]->DoSolve();
230 
231  if(!(cycle%m_infosteps))
232  {
233  out << endl;
234  m_equ[0]->Output();
235  }
236 
238  {
239  //start Adjoint with latest fields of direct
240  CopyFwdToAdj();
241 
242  m_equ[1]->TransCoeffToPhys();
243  m_equ[1]->DoSolve();
244  }
245 
246  // operated fields are copied into workd[inptr[1]-1]
247  CopyFieldToArnoldiArray(tmpworkd = workd + (ipntr[1]-1));
248 
249  }
250 
251  out<< endl << "Converged in " << iparam[8] << " iterations" << endl;
252 
253  ASSERTL0(info >= 0," Error with Dnaupd");
254 
255  ritzSelect = Array<OneD, int> (m_kdim,0);
256  dr = Array<OneD, NekDouble> (m_nvec+1,0.0);
257  di = Array<OneD, NekDouble> (m_nvec+1,0.0);
258  workev = Array<OneD, NekDouble> (3*m_kdim);
259  z = Array<OneD, NekDouble> (n*(m_nvec+1));
260 
261  sigmar = m_realShift;
262  sigmai = m_imagShift;
263 
264  //Setting 'A', Ritz vectors are computed. 'S' for Shur vectors
265  Arpack::Dneupd(1, "A", ritzSelect.get(), dr.get(), di.get(), z.get(), n, sigmar, sigmai, workev.get(), "I", n, problem, m_nvec, m_evtol, resid.get(), m_kdim, v.get(), n, iparam, ipntr, workd.get(), workl.get(),lworkl,info);
266 
267  ASSERTL0(info == 0, " Error with Dneupd");
268  int nconv=iparam[4];
269  Array<OneD, MultiRegions::ExpListSharedPtr> fields = m_equ[0]->UpdateFields();
270 
271  out << "Converged Eigenvalues: " << nconv << endl;
272  pFile << "Converged Eigenvalues:"<< nconv << endl;
273 
275  {
276  pFile << "EV Magnitude Angle Growth Frequency" << endl;
277  }
278  else
279  {
280  pFile << "EV Real Imaginary inverse real inverse imag" << endl;
281  }
282 
283 
284  for(int i= 0; i< nconv; ++i)
285  {
286  WriteEvs(out,i,dr[i],di[i]);
287  WriteEvs(pFile,i,dr[i],di[i]);
288 
289  std::string file = m_session->GetSessionName() + "_eig_"
290  + boost::lexical_cast<std::string>(i);
291  WriteFld(file,z + i*nq);
292  }
293 
294  m_real_evl = dr;
295  m_imag_evl = di;
296 
297  pFile.close();
298 
299  for(int j = 0; j < m_equ[0]->GetNvariables(); ++j)
300  {
301  NekDouble vL2Error = m_equ[0]->L2Error(j,false);
302  NekDouble vLinfError = m_equ[0]->LinfError(j);
303  if (m_comm->GetRank() == 0)
304  {
305  out << "L 2 error (variable " << m_equ[0]->GetVariable(j) << ") : " << vL2Error << endl;
306  out << "L inf error (variable " << m_equ[0]->GetVariable(j) << ") : " << vLinfError << endl;
307  }
308  }
309  }
Array< OneD, NekDouble > m_imag_evl
Definition: DriverArnoldi.h:68
static void Dneupd(const int &rvec, const char *howmny, const int *select, double *dr, double *di, double *z, const int &ldz, const double &sigmar, const double &sigmai, double *workev, const char *bmat, const int &n, const char *which, const int &nev, const double &tol, double *resid, const int &ncv, double *v, const int &ldv, int *iparam, int *ipntr, double *workd, double *workl, const int &lworkl, int &info)
Post-processing routine to computed eigenvector of computed eigenvalues in Dnaupd.
Definition: Arpack.hpp:149
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:135
void CopyFwdToAdj()
Copy the forward field to the adjoint system in transient growth calculations.
NekDouble m_evtol
Maxmum number of iterations.
Definition: DriverArnoldi.h:57
void CopyArnoldiArrayToField(Array< OneD, NekDouble > &array)
Copy Arnoldi storage to fields.
void CopyFieldToArnoldiArray(Array< OneD, NekDouble > &array)
Copy fields to Arnoldi storage.
void WriteFld(std::string file, std::vector< Array< OneD, NekDouble > > coeffs)
void WriteEvs(ostream &evlout, const int k, const NekDouble real, const NekDouble imag, NekDouble resid=NekConstants::kNekUnsetDouble)
static const NekDouble kNekZeroTol
int m_nvec
Dimension of Krylov subspace.
Definition: DriverArnoldi.h:55
Array< OneD, NekDouble > m_real_evl
Definition: DriverArnoldi.h:67
static void Dnaupd(int &ido, const char *bmat, const int &n, const char *which, const int &nev, const double &tol, double *resid, const int &ncv, double *v, const int &ldv, int *iparam, int *ipntr, double *workd, double *workl, const int &lworkl, int &info)
Top level reverse communication interface to solve real double-precision non-symmetric problems...
Definition: Arpack.hpp:135
enum EvolutionOperatorType m_EvolutionOperator
Evolution Operator.
Definition: Driver.h:100
double NekDouble
int m_nfields
interval to dump information if required.
Definition: DriverArnoldi.h:63
bool m_timeSteppingAlgorithm
Period of time stepping algorithm.
Definition: DriverArnoldi.h:59
static std::string ArpackProblemTypeTrans[]
Definition: DriverArpack.h:89
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
Definition: Driver.h:94
int m_infosteps
underlying operator is time stepping
Definition: DriverArnoldi.h:61
LibUtilities::CommSharedPtr m_comm
Communication object.
Definition: Driver.h:85
LibUtilities::SessionReaderSharedPtr m_session
Session reader object.
Definition: Driver.h:88
int m_nits
Number of vectors to test.
Definition: DriverArnoldi.h:56
void Nektar::SolverUtils::DriverArpack::v_InitObject ( ostream &  out = cout)
protectedvirtual

Virtual function for initialisation implementation.

Reimplemented from Nektar::SolverUtils::DriverArnoldi.

Definition at line 78 of file DriverArpack.cpp.

References Nektar::SolverUtils::DriverArnoldi::ArnoldiSummary(), ArpackProblemTypeTrans, ASSERTL0, Nektar::SolverUtils::Driver::m_equ, Nektar::SolverUtils::DriverArnoldi::m_kdim, m_maxn, m_maxncv, m_maxnev, Nektar::SolverUtils::Driver::m_nequ, Nektar::SolverUtils::DriverArnoldi::m_nvec, Nektar::SolverUtils::Driver::m_session, and Nektar::SolverUtils::DriverArnoldi::v_InitObject().

79  {
81 
82  //Initialisation of Arnoldi parameters
83  m_maxn = 1000000; // Maximum size of the problem
84  m_maxnev = 200; // maximum number of eigenvalues requested
85  m_maxncv = 500; // Largest number of basis vector used in Implicitly Restarted Arnoldi
86 
87  // Error alerts
88  ASSERTL0(m_nvec <= m_maxnev,"NEV is greater than MAXNEV");
89  ASSERTL0(m_kdim <= m_maxncv,"NEV is greater than MAXNEV");
90  ASSERTL0(2 <= m_kdim-m_nvec,"NCV-NEV is less than 2");
91 
92  m_equ[0]->PrintSummary(out);
93 
94  // Print session parameters
95  out << "\tArnoldi solver type : Arpack" << endl;
96 
97  out << "\tArpack problem type : ";
98  out << ArpackProblemTypeTrans[m_session->GetSolverInfoAsEnum<int>("ArpackProblemType")] << endl;
100 
101  m_equ[m_nequ - 1]->DoInitialise();
102 
103  //FwdTrans Initial conditions to be in Coefficient Space
104  m_equ[m_nequ-1] ->TransPhysToCoeff();
105 
106  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:135
SOLVER_UTILS_EXPORT void ArnoldiSummary(std::ostream &out)
int m_nvec
Dimension of Krylov subspace.
Definition: DriverArnoldi.h:55
static std::string ArpackProblemTypeTrans[]
Definition: DriverArpack.h:89
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
Definition: Driver.h:94
virtual void v_InitObject(ostream &out=cout)
LibUtilities::SessionReaderSharedPtr m_session
Session reader object.
Definition: Driver.h:88
int m_nequ
number of equations
Definition: Driver.h:97

Friends And Related Function Documentation

friend class MemoryManager< DriverArpack >
friend

Definition at line 51 of file DriverArpack.h.

Member Data Documentation

std::string Nektar::SolverUtils::DriverArpack::arpackProblemTypeDefault = LibUtilities::SessionReader::RegisterDefaultSolverInfo("ArpackProblemType","LargestMag")
staticprotected

Definition at line 85 of file DriverArpack.h.

std::string Nektar::SolverUtils::DriverArpack::arpackProblemTypeLookupIds
staticprotected
Initial value:
= {
LibUtilities::SessionReader::RegisterEnumValue("ArpackProblemType","LargestReal" ,0),
LibUtilities::SessionReader::RegisterEnumValue("ArpackProblemType","SmallestReal" ,1),
LibUtilities::SessionReader::RegisterEnumValue("ArpackProblemType","LargestImag" ,2),
LibUtilities::SessionReader::RegisterEnumValue("ArpackProblemType","SmallestImag" ,3),
LibUtilities::SessionReader::RegisterEnumValue("ArpackProblemType","LargestMag" ,4),
LibUtilities::SessionReader::RegisterEnumValue("ArpackProblemType","SmallestMag" ,5),
}

Definition at line 84 of file DriverArpack.h.

std::string Nektar::SolverUtils::DriverArpack::ArpackProblemTypeTrans
staticprivate
Initial value:
=
{ "LR", "SR", "LI", "SI", "LM", "SM" }

Definition at line 89 of file DriverArpack.h.

Referenced by v_Execute(), and v_InitObject().

std::string Nektar::SolverUtils::DriverArpack::className = GetDriverFactory().RegisterCreatorFunction("Arpack", DriverArpack::create)
static

Name of the class.

Definition at line 61 of file DriverArpack.h.

std::string Nektar::SolverUtils::DriverArpack::driverLookupId = LibUtilities::SessionReader::RegisterEnumValue("Driver","Arpack",0)
staticprotected

Definition at line 86 of file DriverArpack.h.

int Nektar::SolverUtils::DriverArpack::m_maxn
protected

Definition at line 66 of file DriverArpack.h.

Referenced by v_Execute(), and v_InitObject().

int Nektar::SolverUtils::DriverArpack::m_maxncv
protected

Definition at line 68 of file DriverArpack.h.

Referenced by v_InitObject().

int Nektar::SolverUtils::DriverArpack::m_maxnev
protected

Definition at line 67 of file DriverArpack.h.

Referenced by v_InitObject().