Nektar++
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AdvectionSystem.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: AdvectionSystem.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: Base class for advection-based equation systems.
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
36 
37 namespace Nektar {
38 namespace SolverUtils {
39 
40 /**
41  *
42  */
46  : UnsteadySystem(pSession, pGraph)
47 {
48 }
49 
50 
51 /**
52  *
53  */
55 {
56 
57 }
58 
59 
60 /**
61  *
62  */
64 {
66  m_session->LoadParameter("IO_CFLSteps", m_cflsteps, 0);
67  m_session->LoadParameter("IO_CFLWriteFld", m_cflWriteFld, 0);
68  m_session->LoadParameter("IO_CFLWriteFldWaitSteps", m_cflWriteFldWaitSteps, 0);
69 }
70 
71 /**
72  *
73  */
75 {
76  bool result = UnsteadySystem::v_PostIntegrate(step);
77 
78  if((m_cflsteps && !((step+1)%m_cflsteps)) || m_cflWriteFld>0)
79  {
80  int elmtid;
81  NekDouble cfl = GetCFLEstimate(elmtid);
82 
83  if(m_cflsteps && !((step+1)%m_cflsteps) && m_comm->GetRank() == 0)
84  {
86  {
87  std::cout << "CFL: ";
88  }
89  else
90  {
91  std::cout << "CFL (zero plane): ";
92  }
93  std::cout << cfl << " (in elmt " << elmtid << ")" << std::endl;
94  }
95 
96  // At each timestep, if cflWriteFld is set check if cfl is above treshold
97  if(m_cflWriteFld>0 && cfl >= m_cflWriteFld && step >= m_cflWriteFldWaitSteps)
98  {
99  std::string outname = m_sessionName + "_CFLWriteFld";
100  WriteFld(outname + ".fld");
101  m_cflWriteFld = 0;
102  }
103  }
104 
105  return result;
106 }
107 
108 /**
109  *
110  */
112 {
113  int nelmt = m_fields[0]->GetExpSize();
114 
115  const Array<OneD, int> expOrder = GetNumExpModesPerExp();
116 
117  const NekDouble cLambda = 0.2; // Spencer book pag. 317
118 
119  Array<OneD, NekDouble> stdVelocity(nelmt, 0.0);
120  if(FlagAcousticCFL)
121  {
122  stdVelocity = v_GetMaxStdVelocity();
123  }
124  else
125  {
126  stdVelocity = v_GetMaxStdVelocity(0.0);
127  }
128 
129  Array<OneD, NekDouble> cfl(nelmt, 0.0);
130  NekDouble order;
131  for(int el = 0; el < nelmt; ++el)
132  {
133  order = std::max(expOrder[el]-1, 1);
134  cfl[el] = m_timestep*(stdVelocity[el] * cLambda * order * order);
135  }
136 
137  return cfl;
138 }
139 
140 /**
141  *
142  */
144 {
145  int n_element = m_fields[0]->GetExpSize();
146 
148 
149  elmtid = Vmath::Imax(n_element,cfl,1);
150 
151  NekDouble CFL,CFL_loc;
152  CFL = CFL_loc = cfl[elmtid];
153  m_comm->AllReduce(CFL,LibUtilities::ReduceMax);
154 
155  // unshuffle elmt id if data is not stored in consecutive order.
156  elmtid = m_fields[0]->GetExp(elmtid)->GetGeom()->GetGlobalID();
157  if(CFL != CFL_loc)
158  {
159  elmtid = -1;
160  }
161 
162  m_comm->AllReduce(elmtid,LibUtilities::ReduceMax);
163 
164  // express element id with respect to plane
166  {
167  elmtid = elmtid%m_fields[0]->GetPlane(0)->GetExpSize();
168  }
169  return CFL;
170 }
171 
172 }
173 }
virtual SOLVER_UTILS_EXPORT void v_InitObject()
Init object for UnsteadySystem class.
virtual SOLVER_UTILS_EXPORT Array< OneD, NekDouble > v_GetMaxStdVelocity(const NekDouble SpeedSoundFactor=1.0)
SOLVER_UTILS_EXPORT NekDouble GetCFLEstimate(int &elmtid)
SOLVER_UTILS_EXPORT Array< OneD, NekDouble > GetElmtCFLVals(const bool FlagAcousticCFL=true)
int m_cflWriteFldWaitSteps
Number of timesteps after which IO_CFLWriteFld is activated.
NekDouble m_cflWriteFld
Write field if cfl is higher than IO_CFLWriteFld treshold.
virtual SOLVER_UTILS_EXPORT bool v_PostIntegrate(int step)
SOLVER_UTILS_EXPORT AdvectionSystem(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
virtual SOLVER_UTILS_EXPORT ~AdvectionSystem()
LibUtilities::CommSharedPtr m_comm
Communicator.
NekDouble m_timestep
Time step size.
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array holding all dependent variables.
SOLVER_UTILS_EXPORT const Array< OneD, int > GetNumExpModesPerExp()
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.
enum HomogeneousType m_HomogeneousType
Base class for unsteady solvers.
virtual SOLVER_UTILS_EXPORT bool v_PostIntegrate(int step)
virtual SOLVER_UTILS_EXPORT void v_InitObject()
Init object for UnsteadySystem class.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
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
int Imax(int n, const T *x, const int incx)
Return the index of the maximum element in x.
Definition: Vmath.cpp:866