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
37namespace Nektar::SolverUtils
38{
39
40/**
41 *
42 */
46 : UnsteadySystem(pSession, pGraph)
47{
48}
49
50/**
51 *
52 */
53void AdvectionSystem::v_InitObject(bool DeclareField)
54{
55 UnsteadySystem::v_InitObject(DeclareField);
56 m_session->LoadParameter("IO_CFLSteps", m_cflsteps, 0);
57 m_session->LoadParameter("IO_CFLWriteFld", m_cflWriteFld, 0);
58 m_session->LoadParameter("IO_CFLWriteFldWaitSteps", m_cflWriteFldWaitSteps,
59 0);
60}
61
62/**
63 *
64 */
66{
67 bool result = UnsteadySystem::v_PostIntegrate(step);
68
69 if ((m_cflsteps && !((step + 1) % m_cflsteps)) || m_cflWriteFld > 0)
70 {
71 int elmtid;
72 NekDouble cfl = GetCFLEstimate(elmtid);
73
74 if (m_cflsteps && !((step + 1) % m_cflsteps) && m_comm->GetRank() == 0)
75 {
77 {
78 std::cout << "CFL: ";
79 }
80 else
81 {
82 std::cout << "CFL (zero plane): ";
83 }
84 std::cout << cfl << " (in elmt " << elmtid << ")" << std::endl;
85 }
86
87 // At each timestep, if cflWriteFld is set check if cfl is above
88 // treshold
89 if (m_cflWriteFld > 0 && cfl >= m_cflWriteFld &&
91 {
92 std::string outname = m_sessionName + "_CFLWriteFld";
93 WriteFld(outname + ".fld");
94 m_cflWriteFld = 0;
95 }
96 }
97
98 return result;
99}
100
101/**
102 *
103 */
105 const bool FlagAcousticCFL)
106{
107 int nelmt = m_fields[0]->GetExpSize();
108
109 const Array<OneD, int> expOrder = GetNumExpModesPerExp();
110
111 const NekDouble cLambda = 0.2; // Spencer book pag. 317
112
113 Array<OneD, NekDouble> stdVelocity(nelmt, 0.0);
114 if (FlagAcousticCFL)
115 {
116 stdVelocity = v_GetMaxStdVelocity();
117 }
118 else
119 {
120 stdVelocity = v_GetMaxStdVelocity(0.0);
121 }
122
123 Array<OneD, NekDouble> cfl(nelmt, 0.0);
124 NekDouble order;
125 for (int el = 0; el < nelmt; ++el)
126 {
127 order = std::max(expOrder[el] - 1, 1);
128 cfl[el] = m_timestep * (stdVelocity[el] * cLambda * order * order);
129 }
130
131 return cfl;
132}
133
134/**
135 *
136 */
138{
139 int n_element = m_fields[0]->GetExpSize();
140
142
143 elmtid = Vmath::Imax(n_element, cfl, 1);
144
145 NekDouble CFL, CFL_loc;
146 CFL = CFL_loc = cfl[elmtid];
147 m_comm->GetSpaceComm()->AllReduce(CFL, LibUtilities::ReduceMax);
148
149 // unshuffle elmt id if data is not stored in consecutive order.
150 elmtid = m_fields[0]->GetExp(elmtid)->GetGeom()->GetGlobalID();
151 if (CFL != CFL_loc)
152 {
153 elmtid = -1;
154 }
155
156 m_comm->GetSpaceComm()->AllReduce(elmtid, LibUtilities::ReduceMax);
157
158 // express element id with respect to plane
160 {
161 elmtid = elmtid % m_fields[0]->GetPlane(0)->GetExpSize();
162 }
163 return CFL;
164}
165
166} // namespace Nektar::SolverUtils
SOLVER_UTILS_EXPORT NekDouble GetCFLEstimate(int &elmtid)
SOLVER_UTILS_EXPORT Array< OneD, NekDouble > GetElmtCFLVals(const bool FlagAcousticCFL=true)
virtual SOLVER_UTILS_EXPORT Array< OneD, NekDouble > v_GetMaxStdVelocity(const NekDouble SpeedSoundFactor=1.0)
SOLVER_UTILS_EXPORT void v_InitObject(bool DeclareField=true) override
Initialisation object for EquationSystem.
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.
SOLVER_UTILS_EXPORT AdvectionSystem(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
SOLVER_UTILS_EXPORT bool v_PostIntegrate(int step) override
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 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
SOLVER_UTILS_EXPORT const Array< OneD, int > GetNumExpModesPerExp()
Base class for unsteady solvers.
virtual SOLVER_UTILS_EXPORT bool v_PostIntegrate(int step)
SOLVER_UTILS_EXPORT void v_InitObject(bool DeclareField=true) override
Init object for UnsteadySystem class.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174
double NekDouble
int Imax(int n, const T *x, const int incx)
Return the index of the maximum element in x.
Definition: Vmath.hpp:623