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 
39 using namespace std;
40 
41 namespace Nektar
42 {
43  string EigenValuesAdvection::className = GetEquationSystemFactory().RegisterCreatorFunction("EigenValuesAdvection", EigenValuesAdvection::create, "Eigenvalues of the weak advection operator.");
44 
45  EigenValuesAdvection::EigenValuesAdvection(
48  : EquationSystem(pSession, pGraph)
49  {
50  }
51 
53  {
55 
56  // Define Velocity fields
58  std::vector<std::string> vel;
59  vel.push_back("Vx");
60  vel.push_back("Vy");
61  vel.push_back("Vz");
62  vel.resize(m_spacedim);
63 
64  GetFunction( "AdvectionVelocity")->Evaluate(vel, m_velocity);
65 
66  // Type of advection class to be used
67  switch(m_projectionType)
68  {
69  // Discontinuous field
71  {
72  // Define the normal velocity fields
73  if (m_fields[0]->GetTrace())
74  {
76  }
77 
78  string advName;
79  string riemName;
80  m_session->LoadSolverInfo(
81  "AdvectionType", advName, "WeakDG");
83  GetAdvectionFactory().CreateInstance(advName, advName);
84  m_advObject->SetFluxVector(
86  m_session->LoadSolverInfo(
87  "UpwindType", riemName, "Upwind");
90  riemName, m_session);
91  m_riemannSolver->SetScalar(
93 
94  m_advObject->SetRiemannSolver(m_riemannSolver);
95  m_advObject->InitObject(m_session, m_fields);
96  break;
97  }
98  // Continuous field
101  {
102  string advName;
103  m_session->LoadSolverInfo(
104  "AdvectionType", advName, "NonConservative");
106  GetAdvectionFactory().CreateInstance(advName, advName);
107  m_advObject->SetFluxVector(
109  break;
110  }
111  default:
112  {
113  ASSERTL0(false, "Unsupported projection type.");
114  break;
115  }
116  }
117  }
118 
119  /**
120  * @brief Get the normal velocity
121  */
123  {
124  // Number of trace (interface) points
125  int nTracePts = GetTraceNpoints();
126 
127  // Auxiliary variable to compute the normal velocity
128  Array<OneD, NekDouble> tmp(nTracePts);
129 
130  // Reset the normal velocity
131  Vmath::Zero(nTracePts, m_traceVn, 1);
132 
133  for (int i = 0; i < m_velocity.size(); ++i)
134  {
135  m_fields[0]->ExtractTracePhys(m_velocity[i], tmp);
136 
137  Vmath::Vvtvp(nTracePts,
138  m_traceNormals[i], 1,
139  tmp, 1,
140  m_traceVn, 1,
141  m_traceVn, 1);
142  }
143 
144  return m_traceVn;
145  }
146 
148  {
149 
150  }
151 
153  {
154 
155  }
156 
158  {
159  int nvariables = 1;
160  int dofs = GetNcoeffs();
161  //bool UseContCoeffs = false;
162 
163  Array<OneD, Array<OneD, NekDouble> > inarray(nvariables);
164  Array<OneD, Array<OneD, NekDouble> > tmp(nvariables);
165  Array<OneD, Array<OneD, NekDouble> > outarray(nvariables);
166  Array<OneD, Array<OneD, NekDouble> > WeakAdv(nvariables);
167 
168  int npoints = GetNpoints();
169  int ncoeffs = GetNcoeffs();
170 
171  switch (m_projectionType)
172  {
174  {
175  dofs = ncoeffs;
176  break;
177  }
180  {
181  //dofs = GetContNcoeffs();
182  //UseContCoeffs = true;
183  break;
184  }
185  }
186 
187  cout << endl;
188  cout << "Num Phys Points = " << npoints << endl; // phisical points
189  cout << "Num Coeffs = " << ncoeffs << endl; //
190  cout << "Num Cont Coeffs = " << dofs << endl;
191 
192  inarray[0] = Array<OneD, NekDouble>(npoints,0.0);
193  outarray[0] = Array<OneD, NekDouble>(npoints,0.0);
194  tmp[0] = Array<OneD, NekDouble>(npoints,0.0);
195 
196  WeakAdv[0] = Array<OneD, NekDouble>(ncoeffs,0.0);
197  Array<OneD, NekDouble> MATRIX(npoints*npoints,0.0);
198 
199  for (int j = 0; j < npoints; j++)
200  {
201 
202  inarray[0][j] = 1.0;
203 
204  /// Feeding the weak Advection oprator with a vector (inarray)
205  /// Looping on inarray and changing the position of the only non-zero entry
206  /// we simulate the multiplication by the identity matrix.
207  /// The results stored in outarray is one of the columns of the weak advection oprators
208  /// which are then stored in MATRIX for the futher eigenvalues calculation.
209  m_advObject->Advect(nvariables, m_fields, m_velocity, inarray,
210  outarray, 0.0);
211  Vmath::Neg(npoints,outarray[0],1);
212  switch (m_projectionType)
213  {
215  {
216  break;
217  }
220  {
221  for(int i = 0; i < nvariables; ++i)
222  {
223  //m_fields[i]->MultiplyByInvMassMatrix(WeakAdv[i],WeakAdv[i]);
224  //Projection
225  m_fields[i]->FwdTrans(outarray[i],WeakAdv[i]);
226 
227  m_fields[i]->BwdTrans_IterPerExp(WeakAdv[i],outarray[i]);
228  }
229  break;
230  }
231  }
232 
233  /// The result is stored in outarray (is the j-th columns of the weak advection operator).
234  /// We now store it in MATRIX(j)
235  Vmath::Vcopy(npoints,&(outarray[0][0]),1,&(MATRIX[j]),npoints);
236 
237  /// Set the j-th entry of inarray back to zero
238  inarray[0][j] = 0.0;
239  }
240 
241  ////////////////////////////////////////////////////////////////////////////////
242  /// Calulating the eigenvalues of the weak advection operator stored in (MATRIX)
243  /// using Lapack routines
244 
245  char jobvl = 'N';
246  char jobvr = 'N';
247  int info = 0, lwork = 3*npoints;
248  NekDouble dum;
249 
250  Array<OneD, NekDouble> EIG_R(npoints);
251  Array<OneD, NekDouble> EIG_I(npoints);
252 
253  Array<OneD, NekDouble> work(lwork);
254 
255  Lapack::Dgeev(jobvl,jobvr,npoints,MATRIX.get(),npoints,EIG_R.get(),EIG_I.get(),&dum,1,&dum,1,&work[0],lwork,info);
256 
257  ////////////////////////////////////////////////////////
258  //Print Matrix
259  FILE *mFile;
260 
261  mFile = fopen ("WeakAdvMatrix.txt","w");
262  for(int j = 0; j<npoints; j++)
263  {
264  for(int k = 0; k<npoints; k++)
265  {
266  fprintf(mFile,"%e ",MATRIX[j*npoints+k]);
267  }
268  fprintf(mFile,"\n");
269  }
270  fclose (mFile);
271 
272  ////////////////////////////////////////////////////////
273  //Output of the EigenValues
274  FILE *pFile;
275 
276  pFile = fopen ("Eigenvalues.txt","w");
277  for(int j = 0; j<npoints; j++)
278  {
279  fprintf(pFile,"%e %e\n",EIG_R[j],EIG_I[j]);
280  }
281  fclose (pFile);
282 
283  cout << "\nEigenvalues : " << endl;
284  for(int j = 0; j<npoints; j++)
285  {
286  cout << EIG_R[j] << "\t" << EIG_I[j] << endl;
287  }
288  cout << endl;
289  }
290 
292  const Array<OneD, Array<OneD, NekDouble> > &physfield,
294  {
295  ASSERTL1(flux[0].size() == m_velocity.size(),
296  "Dimension of flux array and velocity array do not match");
297 
298  int nq = physfield[0].size();
299 
300  for (int i = 0; i < flux.size(); ++i)
301  {
302  for (int j = 0; j < flux[0].size(); ++j)
303  {
304  Vmath::Vmul(nq, physfield[i], 1, m_velocity[j], 1,
305  flux[i][j], 1);
306  }
307  }
308  }
309 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:250
virtual void v_InitObject()
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
virtual void v_DoSolve()
Virtual function for solve implementation.
Array< OneD, NekDouble > & GetNormalVelocity()
Get the normal velocity.
Array< OneD, Array< OneD, NekDouble > > m_velocity
SolverUtils::AdvectionSharedPtr m_advObject
Array< OneD, NekDouble > m_traceVn
virtual void v_DoInitialise()
Virtual function for initialisation implementation.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:145
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.
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.
virtual SOLVER_UTILS_EXPORT void v_InitObject()
Initialisation object for EquationSystem.
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:370
std::shared_ptr< SessionReader > SessionReaderSharedPtr
AdvectionFactory & GetAdvectionFactory()
Gets the factory for initialising advection objects.
Definition: Advection.cpp:47
EquationSystemFactory & GetEquationSystemFactory()
RiemannSolverFactory & GetRiemannSolverFactory()
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
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.cpp:192
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.cpp:461
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.cpp:513
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:436
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1199