Nektar++
Loading...
Searching...
No Matches
NekLinSysIterEvsDirect.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: NekLinSysIterEvsDirect.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// License for the specific language governing rights and limitations under
14// Permission is hereby granted, free of charge, to any person obtaining a
15// copy of this software and associated documentation files (the "Software"),
16// to deal in the Software without restriction, including without limitation
17// the rights to use, copy, modify, merge, publish, distribute, sublicense,
18// and/or sell copies of the Software, and to permit persons to whom the
19// Software is furnished to do so, subject to the following conditions:
20//
21// The above copyright notice and this permission notice shall be included
22// in all copies or substantial portions of the Software.
23//
24// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30// DEALINGS IN THE SOFTWARE.
31//
32// Description: NekLinSysIterEvsDirect definition
33//
34///////////////////////////////////////////////////////////////////////////////
35
36#include <fstream>
37
40
42{
43/**
44 * @class NekLinSysIterEvsDirect
45 *
46 * Solves a linear system using iterative methods.
47 */
51 "NekLinSysIterEvsDirect solver.");
52
55 const LibUtilities::CommSharedPtr &vComm, const int nDimen,
56 const NekSysKey &pKey)
57 : NekLinSysIter(pSession, vComm, nDimen, pKey)
58{
59}
60
65
69
70/**
71 *
72 */
74 const int nGlobal,
75 [[maybe_unused]] const Array<OneD, const NekDouble> &pInput,
76 [[maybe_unused]] Array<OneD, NekDouble> &pOutput, const int nDir)
77{
78 int nNonDir = nGlobal - nDir;
79
80 Array<OneD, NekDouble> Mat(nNonDir * nNonDir);
81 Array<OneD, NekDouble> wk1(nGlobal), wk2(nGlobal), tmp;
82
83 for (int i = 0; i < nNonDir; ++i)
84 {
85 // need to zero global array since in LhsEval have a global to
86 // local call
87 Vmath::Zero(nGlobal, wk1, 1);
88 wk1[nDir + i] = 1.0;
89
91 m_operator.DoNekSysPrecon(wk2 + nDir, tmp = wk1 + nDir);
92
93 Vmath::Vcopy(nNonDir, wk1 + nDir, 1, tmp = Mat + i, nNonDir);
94 }
95
96 ////////////////////////////////////////////////////////
97 // Print Matrix
98 std::ofstream mFile("Matrix.txt");
99
100 for (int j = 0; j < nNonDir; j++)
101 {
102 for (int k = 0; k < nNonDir; k++)
103 {
104 if (fabs(Mat[j * nNonDir + k]) < 1e-15)
105 {
106 Mat[j * nNonDir + k] = 0.0;
107 }
108 mFile << Mat[j * nNonDir + k];
109 }
110 mFile << std::endl;
111 }
112 mFile.close();
113
114 char jobvl = 'N', jobvr = 'N';
115 int info = 0, lwork = 3 * nNonDir;
116 NekDouble dum;
117
118 Array<OneD, NekDouble> EIG_R(nNonDir), EIG_I(nNonDir), work(lwork);
119
120 Lapack::Dgeev(jobvl, jobvr, nNonDir, Mat.data(), nNonDir, EIG_R.data(),
121 EIG_I.data(), &dum, 1, &dum, 1, &work[0], lwork, info);
122
123 ////////////////////////////////////////////////////////
124 // Output of the EigenValues
125 std::ofstream pFile("Eigenvalues.txt");
126
127 for (int j = 0; j < nNonDir; j++)
128 {
129 pFile << EIG_R[j] << " " << EIG_I[j] << std::endl;
130 }
131 pFile.close();
132
133 std::cout << std::endl << "Eigenvalues : " << std::endl;
134 for (int j = 0; j < nNonDir; j++)
135 {
136 std::cout << EIG_R[j] << "\t" << EIG_I[j] << std::endl;
137 }
138 std::cout << std::endl;
139
140 return 0;
141}
142} // namespace Nektar::LibUtilities
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
NekLinSysIterEvsDirect(const LibUtilities::SessionReaderSharedPtr &pSession, const LibUtilities::CommSharedPtr &vComm, const int nDimen, const NekSysKey &pKey)
Constructor for full direct matrix solve.
int v_SolveSystem(const int nGlobal, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const int nDir) override
static NekLinSysIterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const LibUtilities::CommSharedPtr &vComm, const int nDimen, const NekSysKey &pKey)
NekSysOperators m_operator
Definition NekSys.h:306
void DoNekSysPrecon(InArrayType &inarray, OutArrayType &outarray, const bool &flag=false) const
Definition NekSys.h:155
void DoNekSysLhsEval(InArrayType &inarray, OutArrayType &outarray, const bool &flag=false) const
Definition NekSys.h:148
static void Dgeev(const char &uplo, const char &lrev, const int &n, const double *a, const int &lda, double *wr, double *wi, double *rev, const int &ldr, double *lev, const int &ldv, double *work, const int &lwork, int &info)
Solve general real matrix eigenproblem.
Definition Lapack.hpp:357
std::shared_ptr< SessionReader > SessionReaderSharedPtr
NekLinSysIterFactory & GetNekLinSysIterFactory()
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition Comm.h:55
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