Nektar++
IsentropicVortex.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: IsentropicVortex.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: Euler equations for isentropic vortex
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <boost/core/ignore_unused.hpp>
36 
38 
39 using namespace std;
40 
41 namespace Nektar
42 {
43 string IsentropicVortex::className =
45  "IsentropicVortex", IsentropicVortex::create,
46  "Euler equations for the isentropic vortex test case.");
47 
48 IsentropicVortex::IsentropicVortex(
51  : UnsteadySystem(pSession, pGraph), EulerCFE(pSession, pGraph)
52 {
53  m_session->LoadParameter("IsentropicBeta", m_beta, 5.0);
54  m_session->LoadParameter("IsentropicU0", m_u0, 1.0);
55  m_session->LoadParameter("IsentropicV0", m_v0, 0.5);
56  m_session->LoadParameter("IsentropicX0", m_x0, 5.0);
57  m_session->LoadParameter("IsentropicY0", m_y0, 0.0);
58 }
59 
60 /**
61  * @brief Destructor for EulerCFE class.
62  */
64 {
65 }
66 
67 /**
68  * @brief Print out a summary with some relevant information.
69  */
71 {
73  SolverUtils::AddSummaryItem(s, "Problem Type", "Isentropic Vortex");
74 }
75 
76 /**
77  * @brief Set the initial conditions.
78  */
80  bool dumpInitialConditions,
81  const int domain)
82 {
83  boost::ignore_unused(domain);
84 
85  int nTotQuadPoints = GetTotPoints();
86  Array<OneD, NekDouble> x(nTotQuadPoints);
87  Array<OneD, NekDouble> y(nTotQuadPoints);
88  Array<OneD, NekDouble> z(nTotQuadPoints);
90 
91  m_fields[0]->GetCoords(x, y, z);
92 
93  for (int i = 0; i < m_spacedim + 2; ++i)
94  {
95  u[i] = Array<OneD, NekDouble>(nTotQuadPoints);
96  }
97 
98  EvaluateIsentropicVortex(x, y, z, u, initialtime);
99 
100  // Forward transform to fill the coefficient space
101  for (int i = 0; i < m_fields.size(); ++i)
102  {
103  Vmath::Vcopy(nTotQuadPoints, u[i], 1, m_fields[i]->UpdatePhys(), 1);
104  m_fields[i]->SetPhysState(true);
105  m_fields[i]->FwdTrans(m_fields[i]->GetPhys(),
106  m_fields[i]->UpdateCoeffs());
107  }
108 
109  if (dumpInitialConditions && m_checksteps && !ParallelInTime())
110  {
111  // Dump initial conditions to file
113  m_nchk++;
114  }
115  else if (dumpInitialConditions && m_useInitialCondition && m_nchk == 0 &&
116  ParallelInTime())
117  {
118  std::string newdir = m_sessionName + ".pit";
119  if (!fs::is_directory(newdir))
120  {
121  fs::create_directory(newdir);
122  }
123  if (m_comm->GetTimeComm()->GetRank() == 0)
124  {
125  WriteFld(newdir + "/" + m_sessionName + "_0.fld");
126  }
127  }
128  m_nchk++;
129 }
130 
131 /**
132  * @brief Get the exact solutions for isentropic vortex and Ringleb
133  * flow problems.
134  */
136  Array<OneD, NekDouble> &outfield,
137  const NekDouble time)
138 {
139  int nTotQuadPoints = GetTotPoints();
140  Array<OneD, NekDouble> x(nTotQuadPoints);
141  Array<OneD, NekDouble> y(nTotQuadPoints);
142  Array<OneD, NekDouble> z(nTotQuadPoints);
144 
145  m_fields[0]->GetCoords(x, y, z);
146 
147  for (int i = 0; i < m_spacedim + 2; ++i)
148  {
149  u[i] = Array<OneD, NekDouble>(nTotQuadPoints);
150  }
151 
152  EvaluateIsentropicVortex(x, y, z, u, time);
153 
154  Vmath::Vcopy(nTotQuadPoints, u[field], 1, outfield, 1);
155 }
156 
160  NekDouble time, const int o)
161 {
162  boost::ignore_unused(z);
163 
164  int nq = x.size();
165 
166  // Flow parameters
167  NekDouble r, xbar, ybar, tmp;
168  NekDouble fac = 1.0 / (16.0 * m_gamma * M_PI * M_PI);
169 
170  // In 3D zero rhow field.
171  if (m_spacedim == 3)
172  {
173  Vmath::Zero(nq, &u[3][o], 1);
174  }
175 
176  // Fill storage
177  for (int i = 0; i < nq; ++i)
178  {
179  xbar = x[i] - m_u0 * time - m_x0;
180  ybar = y[i] - m_v0 * time - m_y0;
181  r = sqrt(xbar * xbar + ybar * ybar);
182  tmp = m_beta * exp(1 - r * r);
183  u[0][i + o] =
184  pow(1.0 - (m_gamma - 1.0) * tmp * tmp * fac, 1.0 / (m_gamma - 1.0));
185  u[1][i + o] = u[0][i + o] * (m_u0 - tmp * ybar / (2 * M_PI));
186  u[2][i + o] = u[0][i + o] * (m_v0 + tmp * xbar / (2 * M_PI));
187  u[m_spacedim + 1][i + o] =
188  pow(u[0][i + o], m_gamma) / (m_gamma - 1.0) +
189  0.5 * (u[1][i + o] * u[1][i + o] + u[2][i + o] * u[2][i + o]) /
190  u[0][i + o];
191  }
192 }
193 
194 } // namespace Nektar
virtual void v_SetInitialConditions(NekDouble initialtime=0.0, bool dumpInitialConditions=true, const int domain=0) override
Set the initial conditions.
virtual void v_GenerateSummary(SolverUtils::SummaryList &s) override
Print a summary of time stepping parameters.
NekDouble m_beta
Maximum strength of the perturbation.
virtual ~IsentropicVortex()
Destructor for EulerCFE class.
NekDouble m_y0
Origin in y-direction.
NekDouble m_v0
Velocity in y-direction.
void EvaluateIsentropicVortex(const Array< OneD, NekDouble > &x, const Array< OneD, NekDouble > &y, const Array< OneD, NekDouble > &z, Array< OneD, Array< OneD, NekDouble >> &u, NekDouble time, const int o=0)
Isentropic Vortex Test Case.
NekDouble m_x0
Origin in x-direction.
NekDouble m_u0
Velocity in x-direction.
virtual void v_EvaluateExactSolution(unsigned int field, Array< OneD, NekDouble > &outfield, const NekDouble time=0.0) override
Get the exact solutions for isentropic vortex and Ringleb flow problems.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
int m_spacedim
Spatial dimension (>= expansion dim).
SOLVER_UTILS_EXPORT bool ParallelInTime()
Check if solver use Parallel-in-Time.
LibUtilities::CommSharedPtr m_comm
Communicator.
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array holding all dependent variables.
SOLVER_UTILS_EXPORT void Checkpoint_Output(const int n)
Write checkpoint file of m_fields.
bool m_useInitialCondition
Flag to determine if IC are used.
SOLVER_UTILS_EXPORT void WriteFld(const std::string &outname)
Write field data to the given filename.
std::string m_sessionName
Name of the session.
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
int m_nchk
Number of checkpoints written so far.
int m_checksteps
Number of steps between checkpoints.
SOLVER_UTILS_EXPORT int GetTotPoints()
Base class for unsteady solvers.
virtual SOLVER_UTILS_EXPORT void v_GenerateSummary(SummaryList &s) override
Print a summary of time stepping parameters.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::vector< std::pair< std::string, std::string > > SummaryList
Definition: Misc.h:48
EquationSystemFactory & GetEquationSystemFactory()
void AddSummaryItem(SummaryList &l, const std::string &name, const std::string &value)
Adds a summary item to the summary info list.
Definition: Misc.cpp:49
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:172
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:492
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1255
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:294