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 */
54{
55}
56
57/**
58 *
59 */
60void AdvectionSystem::v_InitObject(bool DeclareField)
61{
62 UnsteadySystem::v_InitObject(DeclareField);
63 m_session->LoadParameter("IO_CFLSteps", m_cflsteps, 0);
64 m_session->LoadParameter("IO_CFLWriteFld", m_cflWriteFld, 0);
65 m_session->LoadParameter("IO_CFLWriteFldWaitSteps", m_cflWriteFldWaitSteps,
66 0);
67}
68
69/**
70 *
71 */
73{
74 bool result = UnsteadySystem::v_PostIntegrate(step);
75
76 if ((m_cflsteps && !((step + 1) % m_cflsteps)) || m_cflWriteFld > 0)
77 {
78 int elmtid;
79 NekDouble cfl = GetCFLEstimate(elmtid);
80
81 if (m_cflsteps && !((step + 1) % m_cflsteps) && m_comm->GetRank() == 0)
82 {
84 {
85 std::cout << "CFL: ";
86 }
87 else
88 {
89 std::cout << "CFL (zero plane): ";
90 }
91 std::cout << cfl << " (in elmt " << elmtid << ")" << std::endl;
92 }
93
94 // At each timestep, if cflWriteFld is set check if cfl is above
95 // treshold
96 if (m_cflWriteFld > 0 && cfl >= m_cflWriteFld &&
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 const bool FlagAcousticCFL)
113{
114 int nelmt = m_fields[0]->GetExpSize();
115
116 const Array<OneD, int> expOrder = GetNumExpModesPerExp();
117
118 const NekDouble cLambda = 0.2; // Spencer book pag. 317
119
120 Array<OneD, NekDouble> stdVelocity(nelmt, 0.0);
121 if (FlagAcousticCFL)
122 {
123 stdVelocity = v_GetMaxStdVelocity();
124 }
125 else
126 {
127 stdVelocity = v_GetMaxStdVelocity(0.0);
128 }
129
130 Array<OneD, NekDouble> cfl(nelmt, 0.0);
131 NekDouble order;
132 for (int el = 0; el < nelmt; ++el)
133 {
134 order = std::max(expOrder[el] - 1, 1);
135 cfl[el] = m_timestep * (stdVelocity[el] * cLambda * order * order);
136 }
137
138 return cfl;
139}
140
141/**
142 *
143 */
145{
146 int n_element = m_fields[0]->GetExpSize();
147
149
150 elmtid = Vmath::Imax(n_element, cfl, 1);
151
152 NekDouble CFL, CFL_loc;
153 CFL = CFL_loc = cfl[elmtid];
154 m_comm->AllReduce(CFL, LibUtilities::ReduceMax);
155
156 // unshuffle elmt id if data is not stored in consecutive order.
157 elmtid = m_fields[0]->GetExp(elmtid)->GetGeom()->GetGlobalID();
158 if (CFL != CFL_loc)
159 {
160 elmtid = -1;
161 }
162
163 m_comm->AllReduce(elmtid, LibUtilities::ReduceMax);
164
165 // express element id with respect to plane
167 {
168 elmtid = elmtid % m_fields[0]->GetPlane(0)->GetExpSize();
169 }
170 return CFL;
171}
172
173} // 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
SOLVER_UTILS_EXPORT ~AdvectionSystem() 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 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)
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