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
38{
39namespace SolverUtils
40{
41
42/**
43 *
44 */
48 : UnsteadySystem(pSession, pGraph)
49{
50}
51
52/**
53 *
54 */
56{
57}
58
59/**
60 *
61 */
62void AdvectionSystem::v_InitObject(bool DeclareField)
63{
64 UnsteadySystem::v_InitObject(DeclareField);
65 m_session->LoadParameter("IO_CFLSteps", m_cflsteps, 0);
66 m_session->LoadParameter("IO_CFLWriteFld", m_cflWriteFld, 0);
67 m_session->LoadParameter("IO_CFLWriteFldWaitSteps", m_cflWriteFldWaitSteps,
68 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
97 // treshold
98 if (m_cflWriteFld > 0 && cfl >= m_cflWriteFld &&
100 {
101 std::string outname = m_sessionName + "_CFLWriteFld";
102 WriteFld(outname + ".fld");
103 m_cflWriteFld = 0;
104 }
105 }
106
107 return result;
108}
109
110/**
111 *
112 */
114 const bool FlagAcousticCFL)
115{
116 int nelmt = m_fields[0]->GetExpSize();
117
118 const Array<OneD, int> expOrder = GetNumExpModesPerExp();
119
120 const NekDouble cLambda = 0.2; // Spencer book pag. 317
121
122 Array<OneD, NekDouble> stdVelocity(nelmt, 0.0);
123 if (FlagAcousticCFL)
124 {
125 stdVelocity = v_GetMaxStdVelocity();
126 }
127 else
128 {
129 stdVelocity = v_GetMaxStdVelocity(0.0);
130 }
131
132 Array<OneD, NekDouble> cfl(nelmt, 0.0);
133 NekDouble order;
134 for (int el = 0; el < nelmt; ++el)
135 {
136 order = std::max(expOrder[el] - 1, 1);
137 cfl[el] = m_timestep * (stdVelocity[el] * cLambda * order * order);
138 }
139
140 return cfl;
141}
142
143/**
144 *
145 */
147{
148 int n_element = m_fields[0]->GetExpSize();
149
151
152 elmtid = Vmath::Imax(n_element, cfl, 1);
153
154 NekDouble CFL, CFL_loc;
155 CFL = CFL_loc = cfl[elmtid];
156 m_comm->AllReduce(CFL, LibUtilities::ReduceMax);
157
158 // unshuffle elmt id if data is not stored in consecutive order.
159 elmtid = m_fields[0]->GetExp(elmtid)->GetGeom()->GetGlobalID();
160 if (CFL != CFL_loc)
161 {
162 elmtid = -1;
163 }
164
165 m_comm->AllReduce(elmtid, LibUtilities::ReduceMax);
166
167 // express element id with respect to plane
169 {
170 elmtid = elmtid % m_fields[0]->GetPlane(0)->GetExpSize();
171 }
172 return CFL;
173}
174
175} // namespace SolverUtils
176} // namespace Nektar
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)
virtual SOLVER_UTILS_EXPORT void v_InitObject(bool DeclareField=true) override
Init object for UnsteadySystem class.
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)
virtual SOLVER_UTILS_EXPORT bool v_PostIntegrate(int step) override
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(bool DeclareField=true) override
Init object for UnsteadySystem class.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:176
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble
int Imax(int n, const T *x, const int incx)
Return the index of the maximum element in x.
Definition: Vmath.cpp:913