Nektar++
EigenValuesAdvection.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: EigenValuesAdvection.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// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description:
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#include <iostream>
36
38
39using namespace std;
40
41namespace Nektar
42{
45 "EigenValuesAdvection", EigenValuesAdvection::create,
46 "Eigenvalues of the weak advection operator.");
47
51 : EquationSystem(pSession, pGraph)
52{
53}
54
55void EigenValuesAdvection::v_InitObject(bool DeclareFields)
56{
57 EquationSystem::v_InitObject(DeclareFields);
58
59 // Define Velocity fields
61 std::vector<std::string> vel;
62 vel.push_back("Vx");
63 vel.push_back("Vy");
64 vel.push_back("Vz");
65 vel.resize(m_spacedim);
66
67 GetFunction("AdvectionVelocity")->Evaluate(vel, m_velocity);
68
69 // Type of advection class to be used
70 switch (m_projectionType)
71 {
72 // Discontinuous field
74 {
75 // Define the normal velocity fields
76 if (m_fields[0]->GetTrace())
77 {
79 }
80
81 string advName;
82 string riemName;
83 m_session->LoadSolverInfo("AdvectionType", advName, "WeakDG");
85 advName, advName);
87 this);
88 m_session->LoadSolverInfo("UpwindType", riemName, "Upwind");
91 riemName, m_session);
92 m_riemannSolver->SetScalar(
94
95 m_advObject->SetRiemannSolver(m_riemannSolver);
96 m_advObject->InitObject(m_session, m_fields);
97 break;
98 }
99 // Continuous field
102 {
103 string advName;
104 m_session->LoadSolverInfo("AdvectionType", advName,
105 "NonConservative");
107 advName, advName);
109 this);
110 break;
111 }
112 default:
113 {
114 ASSERTL0(false, "Unsupported projection type.");
115 break;
116 }
117 }
118}
119
120/**
121 * @brief Get the normal velocity
122 */
124{
125 // Number of trace (interface) points
126 int nTracePts = GetTraceNpoints();
127
128 // Auxiliary variable to compute the normal velocity
129 Array<OneD, NekDouble> tmp(nTracePts);
130
131 // Reset the normal velocity
132 Vmath::Zero(nTracePts, m_traceVn, 1);
133
134 for (int i = 0; i < m_velocity.size(); ++i)
135 {
136 m_fields[0]->ExtractTracePhys(m_velocity[i], tmp);
137
138 Vmath::Vvtvp(nTracePts, m_traceNormals[i], 1, tmp, 1, m_traceVn, 1,
139 m_traceVn, 1);
140 }
141
142 return m_traceVn;
143}
144
146 [[maybe_unused]] bool dumpInitialConditions)
147{
148}
149
151{
152 int nvariables = 1;
153 int dofs = GetNcoeffs();
154 // bool UseContCoeffs = false;
155
156 Array<OneD, Array<OneD, NekDouble>> inarray(nvariables);
157 Array<OneD, Array<OneD, NekDouble>> tmp(nvariables);
158 Array<OneD, Array<OneD, NekDouble>> outarray(nvariables);
159 Array<OneD, Array<OneD, NekDouble>> WeakAdv(nvariables);
160
161 int npoints = GetNpoints();
162 int ncoeffs = GetNcoeffs();
163
164 switch (m_projectionType)
165 {
167 {
168 dofs = ncoeffs;
169 break;
170 }
173 {
174 // dofs = GetContNcoeffs();
175 // UseContCoeffs = true;
176 break;
177 }
178 }
179
180 cout << endl;
181 cout << "Num Phys Points = " << npoints << endl; // phisical points
182 cout << "Num Coeffs = " << ncoeffs << endl; //
183 cout << "Num Cont Coeffs = " << dofs << endl;
184
185 inarray[0] = Array<OneD, NekDouble>(npoints, 0.0);
186 outarray[0] = Array<OneD, NekDouble>(npoints, 0.0);
187 tmp[0] = Array<OneD, NekDouble>(npoints, 0.0);
188
189 WeakAdv[0] = Array<OneD, NekDouble>(ncoeffs, 0.0);
190 Array<OneD, NekDouble> MATRIX(npoints * npoints, 0.0);
191
192 for (int j = 0; j < npoints; j++)
193 {
194
195 inarray[0][j] = 1.0;
196
197 /// Feeding the weak Advection oprator with a vector (inarray)
198 /// Looping on inarray and changing the position of the only non-zero
199 /// entry we simulate the multiplication by the identity matrix. The
200 /// results stored in outarray is one of the columns of the weak
201 /// advection oprators which are then stored in MATRIX for the futher
202 /// eigenvalues calculation.
203 m_advObject->Advect(nvariables, m_fields, m_velocity, inarray, outarray,
204 0.0);
205 Vmath::Neg(npoints, outarray[0], 1);
206 switch (m_projectionType)
207 {
209 {
210 break;
211 }
214 {
215 for (int i = 0; i < nvariables; ++i)
216 {
217 // Projection
218 m_fields[i]->FwdTrans(outarray[i], WeakAdv[i]);
219
220 m_fields[i]->BwdTrans(WeakAdv[i], outarray[i]);
221 }
222 break;
223 }
224 }
225
226 /// The result is stored in outarray (is the j-th columns of the weak
227 /// advection operator). We now store it in MATRIX(j)
228 Vmath::Vcopy(npoints, &(outarray[0][0]), 1, &(MATRIX[j]), npoints);
229
230 /// Set the j-th entry of inarray back to zero
231 inarray[0][j] = 0.0;
232 }
233
234 ////////////////////////////////////////////////////////////////////////////////
235 /// Calulating the eigenvalues of the weak advection operator stored in
236 /// (MATRIX) using Lapack routines
237
238 char jobvl = 'N';
239 char jobvr = 'N';
240 int info = 0, lwork = 3 * npoints;
241 NekDouble dum;
242
243 Array<OneD, NekDouble> EIG_R(npoints);
244 Array<OneD, NekDouble> EIG_I(npoints);
245
246 Array<OneD, NekDouble> work(lwork);
247
248 Lapack::Dgeev(jobvl, jobvr, npoints, MATRIX.get(), npoints, EIG_R.get(),
249 EIG_I.get(), &dum, 1, &dum, 1, &work[0], lwork, info);
250
251 ////////////////////////////////////////////////////////
252 // Print Matrix
253 FILE *mFile;
254
255 mFile = fopen("WeakAdvMatrix.txt", "w");
256 for (int j = 0; j < npoints; j++)
257 {
258 for (int k = 0; k < npoints; k++)
259 {
260 fprintf(mFile, "%e ", MATRIX[j * npoints + k]);
261 }
262 fprintf(mFile, "\n");
263 }
264 fclose(mFile);
265
266 ////////////////////////////////////////////////////////
267 // Output of the EigenValues
268 FILE *pFile;
269
270 pFile = fopen("Eigenvalues.txt", "w");
271 for (int j = 0; j < npoints; j++)
272 {
273 fprintf(pFile, "%e %e\n", EIG_R[j], EIG_I[j]);
274 }
275 fclose(pFile);
276
277 cout << "\nEigenvalues : " << endl;
278 for (int j = 0; j < npoints; j++)
279 {
280 cout << EIG_R[j] << "\t" << EIG_I[j] << endl;
281 }
282 cout << endl;
283}
284
286 const Array<OneD, Array<OneD, NekDouble>> &physfield,
288{
289 ASSERTL1(flux[0].size() == m_velocity.size(),
290 "Dimension of flux array and velocity array do not match");
291
292 int nq = physfield[0].size();
293
294 for (int i = 0; i < flux.size(); ++i)
295 {
296 for (int j = 0; j < flux[0].size(); ++j)
297 {
298 Vmath::Vmul(nq, physfield[i], 1, m_velocity[j], 1, flux[i][j], 1);
299 }
300 }
301}
302} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242
void v_InitObject(bool DeclareFields=true) override
Initialisation object for EquationSystem.
void GetFluxVector(const Array< OneD, Array< OneD, NekDouble > > &physfield, Array< OneD, Array< OneD, Array< OneD, NekDouble > > > &flux)
SolverUtils::RiemannSolverSharedPtr m_riemannSolver
Array< OneD, NekDouble > & GetNormalVelocity()
Get the normal velocity.
void v_DoInitialise(bool dumpInitialConditions=false) override
Virtual function for initialisation implementation.
EigenValuesAdvection(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
Array< OneD, Array< OneD, NekDouble > > m_velocity
SolverUtils::AdvectionSharedPtr m_advObject
Array< OneD, NekDouble > m_traceVn
void v_DoSolve() override
Virtual function for solve implementation.
static EquationSystemSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
Creates an instance of this class.
static std::string className
Name of class.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
A base class for describing how to solve specific equations.
int m_spacedim
Spatial dimension (>= expansion dim).
SOLVER_UTILS_EXPORT int GetTraceNpoints()
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array holding all dependent variables.
virtual SOLVER_UTILS_EXPORT void v_InitObject(bool DeclareFeld=true)
Initialisation object for EquationSystem.
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
Array< OneD, Array< OneD, NekDouble > > m_traceNormals
Array holding trace normals for DG simulations in the forwards direction.
SOLVER_UTILS_EXPORT int GetNpoints()
SOLVER_UTILS_EXPORT int GetNcoeffs()
enum MultiRegions::ProjectionType m_projectionType
Type of projection; e.g continuous or discontinuous.
SOLVER_UTILS_EXPORT SessionFunctionSharedPtr GetFunction(std::string name, const MultiRegions::ExpListSharedPtr &field=MultiRegions::NullExpListSharedPtr, bool cache=false)
Get a SessionFunction by name.
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:329
std::shared_ptr< SessionReader > SessionReaderSharedPtr
AdvectionFactory & GetAdvectionFactory()
Gets the factory for initialising advection objects.
Definition: Advection.cpp:43
EquationSystemFactory & GetEquationSystemFactory()
RiemannSolverFactory & GetRiemannSolverFactory()
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174
double NekDouble
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.
Definition: Vmath.hpp:72
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.hpp:292
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
Definition: Vmath.hpp:366
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
STL namespace.