78 m_equ[0]->PrintSummary(out);
81 if (
m_comm->GetRank() == 0)
83 out <<
"\tArnoldi solver type : Modified Arnoldi" << endl;
103 int nq =
m_equ[0]->UpdateFields()[0]->GetNcoeffs();
108 std::string evlFile =
m_session->GetSessionName() +
".evl";
110 if (
m_comm->GetRank() == 0)
112 evlout.open(evlFile.c_str());
125 for (i = 0; i < m_kdim + 1; ++i)
132 if(
m_session->DefinesFunction(
"InitialConditions"))
134 if (
m_comm->GetRank() == 0)
136 out <<
"\tInital vector : specified in input file " << endl;
138 m_equ[0]->SetInitialConditions(0.0,
false);
144 if (
m_comm->GetRank() == 0)
146 out <<
"\tInital vector : random " << endl;
156 if (
m_comm->GetRank() == 0)
158 out <<
"Iteration: " << 0 << endl;
162 alpha[0] =
Blas::Ddot(ntot, &Kseq[0][0], 1, &Kseq[0][0], 1);
164 alpha[0] = std::sqrt(alpha[0]);
165 Vmath::Smul(ntot, 1.0/alpha[0], Kseq[0], 1, Kseq[0], 1);
169 for (i = 1; !converged && i <=
m_kdim; ++i)
175 alpha[i] =
Blas::Ddot(ntot, &Kseq[i][0], 1, &Kseq[i][0], 1);
177 alpha[i] = std::sqrt(alpha[i]);
180 Vmath::Smul(ntot, 1.0/alpha[i], Kseq[i], 1, Kseq[i], 1);
183 for (
int k = 0; k < i + 1; ++k)
189 EV_small(Tseq, ntot, alpha, i, zvec, wr, wi, resnorm);
192 converged =
EV_test(i, i, zvec, wr, wi, resnorm,
193 std::min(i,
m_nvec), evlout, resid0);
194 converged = max (converged, 0);
196 if (
m_comm->GetRank() == 0)
198 out <<
"Iteration: " << i <<
" (residual : " << resid0
206 for (i = m_kdim + 1; !converged && i <=
m_nits; ++i)
210 for (
int j = 1; j <=
m_kdim; ++j)
212 alpha[j-1] = alpha[j];
217 EV_update(Kseq[m_kdim - 1], Kseq[m_kdim]);
221 &Kseq[m_kdim][0], 1);
223 alpha[
m_kdim] = std::sqrt(alpha[m_kdim]);
224 Vmath::Smul(ntot, 1.0/alpha[m_kdim], Kseq[m_kdim], 1,
228 for (
int k = 0; k < m_kdim + 1; ++k)
234 EV_small(Tseq, ntot, alpha, m_kdim, zvec, wr, wi, resnorm);
237 converged =
EV_test(i, m_kdim, zvec, wr, wi, resnorm,
240 if (
m_comm->GetRank() == 0)
242 out <<
"Iteration: " << i <<
" (residual : "
243 << resid0 <<
")" <<endl;
254 for(j = 0; j <
m_equ[0]->GetNvariables(); ++j)
258 if (
m_comm->GetRank() == 0)
260 out <<
"L 2 error (variable " <<
m_equ[0]->GetVariable(j)
261 <<
") : " << vL2Error << endl;
262 out <<
"L inf error (variable " <<
m_equ[0]->GetVariable(j)
263 <<
") : " << vLinfError << endl;
268 EV_post(Tseq, Kseq, ntot, min(--i, m_kdim),
m_nvec, zvec, wr, wi,
272 "Need to implement Ritz re-evaluation of"
273 "eigenvalue. Only one half of complex "
274 "value will be correct");
281 if (
m_comm->GetRank() == 0)
297 m_equ[0]->TransCoeffToPhys();
304 fields =
m_equ[0]->UpdateFields();
308 m_equ[1]->TransCoeffToPhys();
332 int kdimp = kdim + 1;
340 for (
int i = 0; i < kdimp; ++i)
344 gsc = std::sqrt(gsc);
345 ASSERTL0(gsc != 0.0,
"Vectors are linearly independent.");
348 Vmath::Smul(ntot, 1.0/gsc, Kseq[i], 1, Kseq[i], 1);
350 for (
int j = i + 1; j < kdimp; ++j)
352 gsc =
Blas::Ddot(ntot, &Kseq[i][0], 1, &Kseq[j][0], 1);
354 Vmath::Svtvp(ntot, -gsc, Kseq[i], 1, Kseq[j], 1, Kseq[j], 1);
360 for (
int i = 0; i < kdim; ++i)
362 for (
int j = 0; j < kdim; ++j)
364 H[j*kdim+i] = alpha[j+1] * R[(j+1)*kdimp+i]
365 -
Vmath::Dot(j, &H[0] + i, kdim, &R[0] + j*kdimp, 1);
366 H[j*kdim+i] /= R[j*kdimp+j];
370 H[(kdim-1)*kdim+kdim] = alpha[kdim]
371 * std::fabs(R[kdim*kdimp+kdim] / R[(kdim-1)*kdimp + kdim-1]);
373 Lapack::dgeev_(
'N',
'V', kdim, &H[0], kdim, &wr[0], &wi[0], 0, 1,
374 &zvec[0], kdim, &rwork[0], lwork, ier);
378 resnorm = H[(kdim-1)*kdim + kdim];
400 for (
int i = 0; i < kdim; ++i)
403 &zvec[0] + i*kdim, 1));
404 resid[i] = resnorm * std::fabs(zvec[kdim - 1 + i*kdim]) / tmp;
407 resid[i-1] = resid[i] = hypot(resid[i-1], resid[i]);
411 EV_sort(zvec, wr, wi, resid, kdim);
418 if (
m_comm->GetRank() == 0)
420 evlout <<
"-- Iteration = " << itrn <<
", H(k+1, k) = "
423 evlout.setf(ios::scientific, ios::floatfield);
426 evlout <<
" Magnitude Angle Growth "
427 <<
"Frequency Residual" << endl;
431 evlout <<
" Real Imaginary inverse real "
432 <<
"inverse imag Residual" << endl;
435 for (
int i = 0; i < kdim; i++)
437 WriteEvs(evlout,i,wr[i],wi[i],resid[i]);
441 resid0 = resid[nvec-1];
458 for (
int j = 1; j < dim; ++j)
465 while (i >= 0 && test[i] > te_tmp)
470 Vmath::Vcopy(dim, &evec[0] + i*dim, 1, &evec[0] + (i+1)*dim, 1);
476 Vmath::Vcopy(dim, &z_tmp[0], 1, &evec[0] + (i+1)*dim, 1);
500 ASSERTL0(
false,
"Convergence was not achieved within the "
501 "prescribed number of iterations.");
506 ASSERTL0(
false,
"Minimum residual reached.");
508 else if (icon == nvec)
511 EV_big(Tseq, Kseq, ntot, kdim, icon, zvec, wr, wi);
513 =
m_equ[0]->UpdateFields();
515 for (
int j = 0; j < icon; ++j)
517 std::string file =
m_session->GetSessionName() +
"_eig_"
518 + boost::lexical_cast<std::string>(j)
528 ASSERTL0(
false,
"Unrecognised value.");
549 for (
int j = 0; j < nvec; ++j)
552 for (
int i = 0; i < kdim; ++i)
554 wgt = zvec[i + j*kdim];
555 Vmath::Svtvp(ntot, wgt, bvecs[i], 1, evecs[j], 1, evecs[j], 1);
560 for (
int i = 0; i < nvec; ++i)
564 norm =
Blas::Ddot(ntot, &evecs[i][0], 1, &evecs[i][0], 1);
566 norm = std::sqrt(norm);
567 Vmath::Smul(ntot, 1.0/norm, evecs[i], 1, evecs[i], 1);
571 norm =
Blas::Ddot(ntot, &evecs[i][0], 1, &evecs[i][0], 1);
572 norm +=
Blas::Ddot(ntot, &evecs[i+1][0], 1, &evecs[i+1][0], 1);
574 norm = std::sqrt(norm);
576 Vmath::Smul(ntot, 1.0/norm, evecs[i], 1, evecs[i], 1);
577 Vmath::Smul(ntot, 1.0/norm, evecs[i+1], 1, evecs[i+1], 1);
Array< OneD, NekDouble > m_imag_evl
virtual void v_InitObject(ostream &out=cout)
Virtual function for initialisation implementation.
#define ASSERTL0(condition, msg)
void CopyFwdToAdj()
Copy the forward field to the adjoint system in transient growth calculations.
NekDouble m_evtol
Maxmum number of iterations.
static std::string RegisterEnumValue(std::string pEnum, std::string pString, int pEnumValue)
Registers an enumeration value.
void CopyArnoldiArrayToField(Array< OneD, NekDouble > &array)
Copy Arnoldi storage to fields.
static std::string className
Name of the class.
static std::string driverLookupId
void Svtvp(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
svtvp (scalar times vector plus vector): z = alpha*x + y
SOLVER_UTILS_EXPORT void ArnoldiSummary(std::ostream &out)
void EV_small(Array< OneD, Array< OneD, NekDouble > > &Kseq, const int ntot, const Array< OneD, NekDouble > &alpha, const int kdim, Array< OneD, NekDouble > &zvec, Array< OneD, NekDouble > &wr, Array< OneD, NekDouble > &wi, NekDouble &resnorm)
Generates the upper Hessenberg matrix H and computes its eigenvalues.
void CopyFieldToArnoldiArray(Array< OneD, NekDouble > &array)
Copy fields to Arnoldi storage.
DriverModifiedArnoldi(const LibUtilities::SessionReaderSharedPtr pSession)
Constructor.
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
void WriteFld(std::string file, std::vector< Array< OneD, NekDouble > > coeffs)
Write coefficients to file.
void EV_sort(Array< OneD, NekDouble > &evec, Array< OneD, NekDouble > &wr, Array< OneD, NekDouble > &wi, Array< OneD, NekDouble > &test, const int dim)
Sorts a sequence of eigenvectors/eigenvalues by magnitude.
virtual ~DriverModifiedArnoldi()
Destructor.
void EV_update(Array< OneD, NekDouble > &src, Array< OneD, NekDouble > &tgt)
Generates a new vector in the sequence by applying the linear operator.
static DriverSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession)
Creates an instance of this class.
virtual void v_Execute(ostream &out=cout)
Virtual function for solve implementation.
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*y.
int m_nvec
Dimension of Krylov subspace.
Array< OneD, NekDouble > m_real_evl
Operator in solve call is negated.
#define WARNINGL0(condition, msg)
enum EvolutionOperatorType m_EvolutionOperator
Evolution Operator.
T Ddot(int n, const Array< OneD, const T > &w, const int incw, const Array< OneD, const T > &x, const int incx, const Array< OneD, const int > &y, const int incy)
int m_nfields
interval to dump information if required.
bool m_timeSteppingAlgorithm
Period of time stepping algorithm.
void WriteEvs(ostream &evlout, const int k, const NekDouble real, const NekDouble imag, NekDouble resid=NekConstants::kNekUnsetDouble, bool DumpInverse=true)
T Dot(int n, const T *w, const T *x)
vvtvp (vector times vector times vector): z = w*x*y
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
void EV_post(Array< OneD, Array< OneD, NekDouble > > &Tseq, Array< OneD, Array< OneD, NekDouble > > &Kseq, const int ntot, const int kdim, const int nvec, Array< OneD, NekDouble > &zvec, Array< OneD, NekDouble > &wr, Array< OneD, NekDouble > &wi, const int icon)
void EV_big(Array< OneD, Array< OneD, NekDouble > > &bvecs, Array< OneD, Array< OneD, NekDouble > > &evecs, const int ntot, const int kdim, const int nvec, Array< OneD, NekDouble > &zvec, Array< OneD, NekDouble > &wr, Array< OneD, NekDouble > &wi)
void FillWhiteNoise(int n, const T eps, T *x, const int incx, int outseed)
Fills a vector with white noise.
DriverFactory & GetDriverFactory()
LibUtilities::CommSharedPtr m_comm
Communication object.
Base class for the development of solvers.
void Zero(int n, T *x, const int incx)
Zero vector.
int EV_test(const int itrn, const int kdim, Array< OneD, NekDouble > &zvec, Array< OneD, NekDouble > &wr, Array< OneD, NekDouble > &wi, const NekDouble resnorm, const int nvec, ofstream &evlout, NekDouble &resid0)
Tests for convergence of eigenvalues of H.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
virtual void v_InitObject(ostream &out=cout)
LibUtilities::SessionReaderSharedPtr m_session
Session reader object.
int m_nequ
number of equations
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
int m_nits
Number of vectors to test.