69 m_equ[0]->PrintSummary(out);
72 if (
m_comm->GetRank() == 0)
74 out <<
"\tArnoldi solver type : Modified Arnoldi" << endl;
79 for (
int i = 0; i <
m_nequ; ++i)
81 m_equ[i]->DoInitialise();
95 int nq =
m_equ[0]->UpdateFields()[0]->GetNcoeffs();
100 std::string evlFile =
m_session->GetSessionName() +
".evl";
102 if (
m_comm->GetRank() == 0)
104 evlout.open(evlFile.c_str());
119 for (i = 0; i <
m_kdim + 1; ++i)
128 Kseqcopy[i] = Kseq[i];
134 if (
m_session->DefinesFunction(
"InitialConditions"))
136 if (
m_comm->GetRank() == 0)
138 out <<
"\tInital vector : specified in input file " << endl;
140 m_equ[0]->SetInitialConditions(0.0,
false);
146 if (
m_comm->GetRank() == 0)
148 out <<
"\tInital vector : random " << endl;
162 if (
m_comm->GetRank() == 0)
164 out <<
"Iteration: " << 0 << endl;
172 alpha[0] =
Blas::Ddot(ntot, &Kseqcopy[0][0], 1, &Kseqcopy[0][0], 1);
175 Vmath::Smul(ntot, 1.0 / alpha[0], Kseq[0], 1, Kseq[0], 1);
179 for (i = 1; !converged && i <=
m_kdim; ++i)
189 alpha[i] =
Blas::Ddot(ntot, &Kseqcopy[i][0], 1, &Kseqcopy[i][0], 1);
194 Vmath::Smul(ntot, 1.0 / alpha[i], Kseq[i], 1, Kseq[i], 1);
197 for (
int k = 0; k < i + 1; ++k)
212 EV_small(Tseq, Kseqcopy, ntot, alpha, i, zvec, wr, wi, resnorm);
215 converged =
EV_test(i, i, zvec, wr, wi, resnorm, std::min(i,
m_nvec),
219 converged = max(converged, 0);
226 if (
m_comm->GetRank() == 0)
228 out <<
"Iteration: " << i <<
" (residual : " << resid0 <<
")"
240 for (
int j = 1; j <=
m_kdim; ++j)
242 alpha[j - 1] = alpha[j];
263 for (
int k = 0; k <
m_kdim + 1; ++k)
285 if (
m_comm->GetRank() == 0)
287 out <<
"Iteration: " << i <<
" (residual : " << resid0 <<
")"
299 for (j = 0; j <
m_equ[0]->GetNvariables(); ++j)
303 if (
m_comm->GetRank() == 0)
305 out <<
"L 2 error (variable " <<
m_equ[0]->GetVariable(j)
306 <<
") : " << vL2Error << endl;
307 out <<
"L inf error (variable " <<
m_equ[0]->GetVariable(j)
308 <<
") : " << vLinfError << endl;
318 "Need to implement Ritz re-evaluation of"
319 "eigenvalue. Only one half of complex "
320 "value will be correct");
327 if (
m_comm->GetRank() == 0)
341 m_equ[0]->TransCoeffToPhys();
343 m_equ[0]->SetTime(0.);
349 fields =
m_equ[0]->UpdateFields();
353 m_equ[1]->TransCoeffToPhys();
355 m_equ[1]->SetTime(0.);
374 int kdimp = kdim + 1;
375 int lwork = 10 * kdim;
382 for (
int i = 0; i < kdimp; ++i)
387 ASSERTL0(gsc != 0.0,
"Vectors are linearly independent.");
389 R[i * kdimp + i] = gsc;
390 Vmath::Smul(ntot, 1.0 / gsc, Kseq[i], 1, Kseq[i], 1);
393 Vmath::Smul(ntot, 1.0 / gsc, Kseqcopy[i], 1, Kseqcopy[i], 1);
396 for (
int j = i + 1; j < kdimp; ++j)
398 gsc =
Blas::Ddot(ntot, &Kseq[i][0], 1, &Kseq[j][0], 1);
400 Vmath::Svtvp(ntot, -gsc, Kseq[i], 1, Kseq[j], 1, Kseq[j], 1);
403 Vmath::Svtvp(ntot, -gsc, Kseqcopy[i], 1, Kseqcopy[j], 1,
406 R[j * kdimp + i] = gsc;
411 for (
int i = 0; i < kdim; ++i)
413 for (
int j = 0; j < kdim; ++j)
416 alpha[j + 1] * R[(j + 1) * kdimp + i] -
417 Vmath::Dot(j, &H[0] + i, kdim, &R[0] + j * kdimp, 1);
418 H[j * kdim + i] /= R[j * kdimp + j];
422 H[(kdim - 1) * kdim + kdim] =
424 std::fabs(R[kdim * kdimp + kdim] / R[(kdim - 1) * kdimp + kdim - 1]);
426 Lapack::dgeev_(
'N',
'V', kdim, &H[0], kdim, &wr[0], &wi[0],
nullptr, 1,
427 &zvec[0], kdim, &rwork[0], lwork, ier);
431 resnorm = H[(kdim - 1) * kdim + kdim];
448 for (
int i = 0; i < kdim; ++i)
451 Vmath::Dot(kdim, &zvec[0] + i * kdim, 1, &zvec[0] + i * kdim, 1));
452 resid[i] = resnorm * std::fabs(zvec[kdim - 1 + i * kdim]) / tmp;
455 resid[i - 1] = resid[i] = hypot(resid[i - 1], resid[i]);
459 EV_sort(zvec, wr, wi, resid, kdim);
461 while (nvec <= kdim && resid[nvec - 1] <
m_evtol)
468 if (
m_comm->GetRank() == 0)
470 evlout <<
"-- Iteration = " << itrn <<
", H(k+1, k) = " << resnorm
473 evlout.setf(ios::scientific, ios::floatfield);
476 evlout <<
" Magnitude Angle Growth "
477 <<
"Frequency Residual" << endl;
481 evlout <<
" Real Imaginary inverse real "
482 <<
"inverse imag Residual" << endl;
485 for (
int i = 0; i < kdim; i++)
487 WriteEvs(evlout, i, wr[i], wi[i], resid[i]);
491 resid0 = resid[nvec - 1];
505 for (
int j = 1; j < dim; ++j)
512 while (i >= 0 &&
test[i] > te_tmp)
517 Vmath::Vcopy(dim, &evec[0] + i * dim, 1, &evec[0] + (i + 1) * dim,
523 test[i + 1] = te_tmp;
524 Vmath::Vcopy(dim, &z_tmp[0], 1, &evec[0] + (i + 1) * dim, 1);
535 const int ntot,
const int kdim,
544 ASSERTL0(
false,
"Convergence was not achieved within the "
545 "prescribed number of iterations.");
550 ASSERTL0(
false,
"Minimum residual reached.");
552 else if (icon == nvec)
555 EV_big(Tseq, Kseq, ntot, kdim, icon, zvec, wr, wi);
557 m_equ[0]->UpdateFields();
559 for (
int j = 0; j < icon; ++j)
561 std::string file =
m_session->GetSessionName() +
"_eig_" +
562 std::to_string(j) +
".fld";
564 if (
m_comm->GetRank() == 0)
571 std::string fileunmask =
m_session->GetSessionName() +
572 "_eig_masked_" + std::to_string(j) +
581 ASSERTL0(
false,
"Unrecognised value.");
590 const int ntot,
const int kdim,
598 for (
int i = 0; i < nvec; ++i)
612 for (
int j = 0; j < nvec; ++j)
619 for (
int i = 0; i < kdim; ++i)
621 wgt = zvec[i + j * kdim];
622 Vmath::Svtvp(ntot, wgt, bvecs[i], 1, btmp[j], 1, btmp[j], 1);
625 Vmath::Svtvp(ntot, wgt, evecs[i], 1, etmp[j], 1, etmp[j], 1);
631 for (
int i = 0; i < nvec; ++i)
635 if (
m_session->GetComm()->GetRank() == 0)
637 cout <<
"eigenvalue " << i <<
": real mode" << endl;
639 norm =
Blas::Ddot(ntot, &btmp[i][0], 1, &btmp[i][0], 1);
644 Vmath::Smul(ntot, 1.0 / norm, btmp[i], 1, bvecs[i], 1);
645 Vmath::Smul(ntot, 1.0 / norm, etmp[i], 1, evecs[i], 1);
649 Vmath::Smul(ntot, 1.0 / norm, btmp[i], 1, evecs[i], 1);
654 if (
m_session->GetComm()->GetRank() == 0)
656 cout <<
"eigenvalues " << i <<
", " << i + 1
657 <<
": complex modes" << endl;
659 norm =
Blas::Ddot(ntot, &btmp[i][0], 1, &btmp[i][0], 1);
660 norm +=
Blas::Ddot(ntot, &btmp[i + 1][0], 1, &btmp[i + 1][0], 1);
666 Vmath::Smul(ntot, 1.0 / norm, btmp[i], 1, bvecs[i], 1);
667 Vmath::Smul(ntot, 1.0 / norm, btmp[i + 1], 1, bvecs[i + 1], 1);
668 Vmath::Smul(ntot, 1.0 / norm, etmp[i], 1, evecs[i], 1);
669 Vmath::Smul(ntot, 1.0 / norm, etmp[i + 1], 1, evecs[i + 1], 1);
673 Vmath::Smul(ntot, 1.0 / norm, btmp[i], 1, evecs[i], 1);
674 Vmath::Smul(ntot, 1.0 / norm, btmp[i + 1], 1, evecs[i + 1], 1);
#define ASSERTL0(condition, msg)
#define WARNINGL0(condition, msg)
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
static std::string RegisterEnumValue(std::string pEnum, std::string pString, int pEnumValue)
Registers an enumeration value.
Base class for the development of solvers.
void CopyFwdToAdj()
Copy the forward field to the adjoint system in transient growth calculations.
void v_InitObject(std::ostream &out=std::cout) override
Virtual function for initialisation implementation.
void WriteFld(std::string file, std::vector< Array< OneD, NekDouble > > coeffs)
Write coefficients to file.
Array< OneD, NekDouble > m_maskCoeffs
void CopyFieldToArnoldiArray(Array< OneD, NekDouble > &array)
Copy fields to Arnoldi storage.
int m_nvec
Dimension of Krylov subspace.
bool m_timeSteppingAlgorithm
Period of time stepping algorithm.
int m_nits
Number of vectors to test.
Array< OneD, NekDouble > m_imag_evl
void CopyArnoldiArrayToField(Array< OneD, NekDouble > &array)
Copy Arnoldi storage to fields.
NekDouble m_evtol
Maxmum number of iterations.
int m_nfields
interval to dump information if required.
SOLVER_UTILS_EXPORT void ArnoldiSummary(std::ostream &out)
Array< OneD, NekDouble > m_real_evl
Operator in solve call is negated.
void WriteEvs(std::ostream &evlout, const int k, const NekDouble real, const NekDouble imag, NekDouble resid=NekConstants::kNekUnsetDouble, bool DumpInverse=true)
LibUtilities::SessionReaderSharedPtr m_session
Session reader object.
LibUtilities::CommSharedPtr m_comm
Communication object.
enum EvolutionOperatorType m_EvolutionOperator
Evolution Operator.
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
int m_nequ
number of equations
void EV_update(Array< OneD, NekDouble > &src, Array< OneD, NekDouble > &tgt)
Generates a new vector in the sequence by applying the linear operator.
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)
int EV_test(const int itrn, const int kdim, Array< OneD, NekDouble > &zvec, Array< OneD, NekDouble > &wr, Array< OneD, NekDouble > &wi, const NekDouble resnorm, int nvec, std::ofstream &evlout, NekDouble &resid0)
Tests for convergence of eigenvalues of H.
void EV_small(Array< OneD, Array< OneD, NekDouble > > &Kseq, Array< OneD, Array< OneD, NekDouble > > &Kseqcopy, 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 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.
static std::string driverLookupId
static DriverSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
Creates an instance of this class.
DriverModifiedArnoldi(const LibUtilities::SessionReaderSharedPtr pSession, const SpatialDomains::MeshGraphSharedPtr pGraph)
Constructor.
void v_InitObject(std::ostream &out=std::cout) override
Virtual function for initialisation implementation.
static std::string className
Name of the class.
void v_Execute(std::ostream &out=std::cout) override
Virtual function for solve implementation.
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)
static double Ddot(const int &n, const double *x, const int &incx, const double *y, const int &incy)
BLAS level 1: output = .
std::shared_ptr< SessionReader > SessionReaderSharedPtr
DriverFactory & GetDriverFactory()
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
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.
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.
T Dot(int n, const T *w, const T *x)
dot product
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
void Zero(int n, T *x, const int incx)
Zero vector.
void FillWhiteNoise(int n, const T eps, T *x, const int incx, int outseed)
Fills a vector with white noise.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
scalarT< T > sqrt(scalarT< T > in)