Nektar++
AdvectionWeakDG.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: AdvectionWeakDG.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: Weak DG advection class.
32//
33///////////////////////////////////////////////////////////////////////////////
34
36#include <iomanip>
37#include <iostream>
38
40
41namespace Nektar::SolverUtils
42{
43std::string AdvectionWeakDG::type =
45 "WeakDG", AdvectionWeakDG::create, "Weak DG");
46
48{
49}
50
51/**
52 * @brief Initialise AdvectionWeakDG objects and store them before
53 * starting the time-stepping.
54 *
55 * @param pSession Pointer to session reader.
56 * @param pFields Pointer to fields.
57 */
61{
62 Advection::v_InitObject(pSession, pFields);
63}
64
65/**
66 * @brief Compute the advection term at each time-step using the
67 * Discontinuous Galerkin approach (DG).
68 *
69 * @param nConvectiveFields Number of fields.
70 * @param fields Pointer to fields.
71 * @param advVel Advection velocities.
72 * @param inarray Solution at the previous time-step.
73 * @param outarray Advection term to be passed at the
74 * time integration class.
75 */
77 const int nConvectiveFields,
79 [[maybe_unused]] const Array<OneD, Array<OneD, NekDouble>> &advVel,
80 const Array<OneD, Array<OneD, NekDouble>> &inarray,
82 [[maybe_unused]] const NekDouble &time,
83 const Array<OneD, Array<OneD, NekDouble>> &pFwd,
84 const Array<OneD, Array<OneD, NekDouble>> &pBwd)
85{
87 timer1.Start();
88
89 size_t nCoeffs = fields[0]->GetNcoeffs();
90
91 Array<OneD, Array<OneD, NekDouble>> tmp{size_t(nConvectiveFields)};
92 for (int i = 0; i < nConvectiveFields; ++i)
93 {
94 tmp[i] = Array<OneD, NekDouble>{nCoeffs, 0.0};
95 }
97 timer.Start();
98 AdvectCoeffs(nConvectiveFields, fields, advVel, inarray, tmp, time, pFwd,
99 pBwd);
100 timer.Stop();
101 timer.AccumulateRegion("AdvectCoeffs", 2);
102
103 timer.Start();
104 for (int i = 0; i < nConvectiveFields; ++i)
105 {
106 fields[i]->BwdTrans(tmp[i], outarray[i]);
107 }
108 timer.Stop();
109 timer.AccumulateRegion("AdvWeakDG:_BwdTrans", 10);
110 timer1.Stop();
111 timer1.AccumulateRegion("AdvWeakDG:All", 10);
112}
113
114/**
115 *
116 */
118 const int nConvectiveFields,
120 const Array<OneD, Array<OneD, NekDouble>> &advVel,
121 const Array<OneD, Array<OneD, NekDouble>> &inarray,
122 Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble &time,
123 const Array<OneD, Array<OneD, NekDouble>> &pFwd,
124 const Array<OneD, Array<OneD, NekDouble>> &pBwd)
125{
126 size_t nPointsTot = fields[0]->GetTotPoints();
127 size_t nCoeffs = fields[0]->GetNcoeffs();
128 size_t nTracePointsTot = fields[0]->GetTrace()->GetTotPoints();
129
131 nConvectiveFields);
132 // Allocate storage for flux vector F(u).
133 for (int i = 0; i < nConvectiveFields; ++i)
134 {
135 fluxvector[i] = Array<OneD, Array<OneD, NekDouble>>{size_t(m_spaceDim)};
136 for (int j = 0; j < m_spaceDim; ++j)
137 {
138 fluxvector[i][j] = Array<OneD, NekDouble>(nPointsTot, 0.0);
139 }
140 }
141
143 timer.Start();
144 AdvectVolumeFlux(inarray, fluxvector);
145 timer.Stop();
146 timer.AccumulateRegion("AdvWeakDG:_fluxVector", 3);
147
148 timer.Start();
149 // Get the advection part (without numerical flux)
150 for (int i = 0; i < nConvectiveFields; ++i)
151 {
152 Vmath::Fill(outarray[i].size(), 0.0, outarray[i], 1);
153 fields[i]->IProductWRTDerivBase(fluxvector[i], outarray[i]);
154 }
155 timer.Stop();
156 timer.AccumulateRegion("AdvWeakDG:_IProductWRTDerivBase", 10);
157
158 Array<OneD, Array<OneD, NekDouble>> numflux{size_t(nConvectiveFields)};
159
160 for (int i = 0; i < nConvectiveFields; ++i)
161 {
162 numflux[i] = Array<OneD, NekDouble>{nTracePointsTot, 0.0};
163 }
164
165 AdvectTraceFlux(nConvectiveFields, fields, advVel, inarray, numflux, time,
166 pFwd, pBwd);
167
168 // Evaulate <\phi, \hat{F}\cdot n> - OutField[i]
169 for (int i = 0; i < nConvectiveFields; ++i)
170 {
171 Vmath::Neg(nCoeffs, outarray[i], 1);
172
173 timer.Start();
174 fields[i]->AddTraceIntegral(numflux[i], outarray[i]);
175 timer.Stop();
176 timer.AccumulateRegion("AdvWeakDG:_AddTraceIntegral", 10);
177
178 timer.Start();
179 fields[i]->MultiplyByElmtInvMass(outarray[i], outarray[i]);
180 timer.Stop();
181 timer.AccumulateRegion("AdvWeakDG:_MultiplyByElmtInvMass", 10);
182 }
183}
184
185/**
186 *
187 */
189 const int nConvectiveFields,
191 [[maybe_unused]] const Array<OneD, Array<OneD, NekDouble>> &advVel,
192 const Array<OneD, Array<OneD, NekDouble>> &inarray,
193 Array<OneD, Array<OneD, NekDouble>> &TraceFlux,
194 [[maybe_unused]] const NekDouble &time,
195 const Array<OneD, Array<OneD, NekDouble>> &pFwd,
196 const Array<OneD, Array<OneD, NekDouble>> &pBwd)
197{
198 int nTracePointsTot = fields[0]->GetTrace()->GetTotPoints();
199
200 ASSERTL1(m_riemann, "Riemann solver must be provided for AdvectionWeakDG.");
201
202 // Store forwards/backwards space along trace space
203 Array<OneD, Array<OneD, NekDouble>> Fwd(nConvectiveFields);
204 Array<OneD, Array<OneD, NekDouble>> Bwd(nConvectiveFields);
205
207 {
208 for (int i = 0; i < nConvectiveFields; ++i)
209 {
210 Fwd[i] = Array<OneD, NekDouble>(nTracePointsTot, 0.0);
211 Bwd[i] = Array<OneD, NekDouble>(nTracePointsTot, 0.0);
212 fields[i]->GetFwdBwdTracePhys(inarray[i], Fwd[i], Bwd[i]);
213 }
214 }
215 else
216 {
217 for (int i = 0; i < nConvectiveFields; ++i)
218 {
219 Fwd[i] = pFwd[i];
220 Bwd[i] = pBwd[i];
221 }
222 }
223
225 timer.Start();
226 m_riemann->Solve(m_spaceDim, Fwd, Bwd, TraceFlux);
227 timer.Stop();
228 timer.AccumulateRegion("AdvWeakDG:_Riemann", 10);
229}
230
231} // namespace Nektar::SolverUtils
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
void AccumulateRegion(std::string, int iolevel=0)
Accumulate elapsed time for a region.
Definition: Timer.cpp:70
int m_spaceDim
Storage for space dimension. Used for homogeneous extension.
Definition: Advection.h:172
virtual SOLVER_UTILS_EXPORT void v_InitObject(LibUtilities::SessionReaderSharedPtr pSession, Array< OneD, MultiRegions::ExpListSharedPtr > pFields)
Initialises the advection object.
Definition: Advection.cpp:295
RiemannSolverSharedPtr m_riemann
Riemann solver for DG-type schemes.
Definition: Advection.h:170
SOLVER_UTILS_EXPORT void AdvectVolumeFlux(const Array< OneD, Array< OneD, NekDouble > > &inarray, TensorOfArray3D< NekDouble > &VolumeFlux)
void v_InitObject(LibUtilities::SessionReaderSharedPtr pSession, Array< OneD, MultiRegions::ExpListSharedPtr > pFields) override
Initialise AdvectionWeakDG objects and store them before starting the time-stepping.
SOLVER_UTILS_EXPORT void AdvectTraceFlux(const int nConvective, const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &advVel, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &TraceFlux, const NekDouble &time, const Array< OneD, Array< OneD, NekDouble > > &pFwd=NullNekDoubleArrayOfArray, const Array< OneD, Array< OneD, NekDouble > > &pBwd=NullNekDoubleArrayOfArray)
static AdvectionSharedPtr create(std::string advType)
void v_Advect(const int nConvective, const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &advVel, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time, const Array< OneD, Array< OneD, NekDouble > > &pFwd=NullNekDoubleArrayOfArray, const Array< OneD, Array< OneD, NekDouble > > &pBwd=NullNekDoubleArrayOfArray) override
Compute the advection term at each time-step using the Discontinuous Galerkin approach (DG).
SOLVER_UTILS_EXPORT void AdvectCoeffs(const int nConvective, const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &advVel, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time, const Array< OneD, Array< OneD, NekDouble > > &pFwd=NullNekDoubleArrayOfArray, const Array< OneD, Array< OneD, NekDouble > > &pBwd=NullNekDoubleArrayOfArray)
std::shared_ptr< SessionReader > SessionReaderSharedPtr
AdvectionFactory & GetAdvectionFactory()
Gets the factory for initialising advection objects.
Definition: Advection.cpp:43
static Array< OneD, Array< OneD, NekDouble > > NullNekDoubleArrayOfArray
double NekDouble
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.hpp:292
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.hpp:54