Nektar++
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  stdVelocity = v_GetMaxStdVelocity();
121 
122  Array<OneD, NekDouble> cfl(nelmt, 0.0);
123  NekDouble order;
124  for(int el = 0; el < nelmt; ++el)
125  {
126  order = std::max(expOrder[el]-1, 1);
127  cfl[el] = m_timestep*(stdVelocity[el] * cLambda * order * order);
128  }
129 
130  return cfl;
131 }
132 
133 /**
134  *
135  */
137 {
138  int n_element = m_fields[0]->GetExpSize();
139 
141 
142  elmtid = Vmath::Imax(n_element,cfl,1);
143 
144  NekDouble CFL,CFL_loc;
145  CFL = CFL_loc = cfl[elmtid];
146  m_comm->AllReduce(CFL,LibUtilities::ReduceMax);
147 
148  // unshuffle elmt id if data is not stored in consecutive order.
149  elmtid = m_fields[0]->GetExp(elmtid)->GetGeom()->GetGlobalID();
150  if(CFL != CFL_loc)
151  {
152  elmtid = -1;
153  }
154 
155  m_comm->AllReduce(elmtid,LibUtilities::ReduceMax);
156 
157  // express element id with respect to plane
159  {
160  elmtid = elmtid%m_fields[0]->GetPlane(0)->GetExpSize();
161  }
162  return CFL;
163 }
164 
165 }
166 }
SOLVER_UTILS_EXPORT Array< OneD, NekDouble > GetElmtCFLVals(void)
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:163
NekDouble m_timestep
Time step size.
SOLVER_UTILS_EXPORT const Array< OneD, int > GetNumExpModesPerExp()
SOLVER_UTILS_EXPORT NekDouble GetCFLEstimate(int &elmtid)
std::string m_sessionName
Name of the session.
int Imax(int n, const T *x, const int incx)
Return the index of the maximum element in x.
Definition: Vmath.cpp:758
LibUtilities::CommSharedPtr m_comm
Communicator.
virtual SOLVER_UTILS_EXPORT Array< OneD, NekDouble > v_GetMaxStdVelocity()
int m_cflWriteFldWaitSteps
Number of timesteps after which IO_CFLWriteFld is activated.
virtual SOLVER_UTILS_EXPORT bool v_PostIntegrate(int step)
NekDouble m_cflWriteFld
Write field if cfl is higher than IO_CFLWriteFld treshold.
virtual SOLVER_UTILS_EXPORT bool v_PostIntegrate(int step)
Base class for unsteady solvers.
double NekDouble
virtual SOLVER_UTILS_EXPORT void v_InitObject()
Init object for UnsteadySystem class.
SOLVER_UTILS_EXPORT void WriteFld(const std::string &outname)
Write field data to the given filename.
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array holding all dependent variables.
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
virtual SOLVER_UTILS_EXPORT void v_InitObject()
Init object for UnsteadySystem class.
SOLVER_UTILS_EXPORT AdvectionSystem(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
virtual SOLVER_UTILS_EXPORT ~AdvectionSystem()
std::shared_ptr< SessionReader > SessionReaderSharedPtr
enum HomogeneousType m_HomogeneousType