Nektar++
Advection3DHomogeneous1D.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: Advection3DHomogeneous1D.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: FR advection 3DHomogeneous1D class.
32//
33///////////////////////////////////////////////////////////////////////////////
34
37#include <iomanip>
38#include <iostream>
39
40using namespace std;
41
42namespace Nektar::SolverUtils
43{
44std::string Advection3DHomogeneous1D::type[] = {
46 "WeakDG3DHomogeneous1D", Advection3DHomogeneous1D::create),
48 "FRDG3DHomogeneous1D", Advection3DHomogeneous1D::create),
50 "FRDG3DHomogeneous1D", Advection3DHomogeneous1D::create),
52 "FRSD3DHomogeneous1D", Advection3DHomogeneous1D::create),
54 "FRHU3DHomogeneous1D", Advection3DHomogeneous1D::create),
56 "FRcmin3DHomogeneous1D", Advection3DHomogeneous1D::create),
58 "FRcinf3DHomogeneous1D", Advection3DHomogeneous1D::create)};
59
60/**
61 * @brief AdvectionFR uses the Flux Reconstruction (FR) approach to
62 * compute the advection term. The implementation is only for segments,
63 * quadrilaterals and hexahedra at the moment.
64 *
65 * \todo Extension to triangles, tetrahedra and other shapes.
66 * (Long term objective)
67 */
69 : m_advType(advType)
70{
71 // Strip trailing string "3DHomogeneous1D" to determine 2D advection
72 // type, and create an advection object for the plane.
73 string advName = advType.substr(0, advType.length() - 15);
74 m_planeAdv = GetAdvectionFactory().CreateInstance(advName, advName);
75}
76
77/**
78 * @brief Initiliase Advection3DHomogeneous1D objects and store them
79 * before starting the time-stepping.
80 *
81 * @param pSession Pointer to session reader.
82 * @param pFields Pointer to fields.
83 */
87{
88 int nConvectiveFields = pFields.size();
89
91 nConvectiveFields);
92
93 // Initialise the plane advection object.
94 for (int i = 0; i < nConvectiveFields; ++i)
95 {
96 pFields_plane0[i] = pFields[i]->GetPlane(0);
97 }
98 m_planeAdv->InitObject(pSession, pFields_plane0);
99
100 m_numPoints = pFields[0]->GetTotPoints();
101 m_planes = pFields[0]->GetZIDs();
102 m_numPlanes = m_planes.size();
104
105 // Set Riemann solver and flux vector callback for this plane.
106 m_planeAdv->SetRiemannSolver(m_riemann);
108 this);
109 m_planeCounter = 0;
110
111 // Override Riemann solver scalar and vector callbacks.
112 map<string, RSScalarFuncType> scalars = m_riemann->GetScalars();
113 map<string, RSVecFuncType> vectors = m_riemann->GetVectors();
114
115 for (auto &it1 : scalars)
116 {
117 std::shared_ptr<HomoRSScalar> tmp =
120 m_riemann->SetScalar(it1.first, &HomoRSScalar::Exec, tmp);
121 }
122
123 for (auto &it2 : vectors)
124 {
125 std::shared_ptr<HomoRSVector> tmp =
127 it2.second, m_numPlanes, it2.first);
128 m_riemann->SetVector(it2.first, &HomoRSVector::Exec, tmp);
129 }
130
133
134 // Set up storage for flux vector.
135 for (int i = 0; i < nConvectiveFields; ++i)
136 {
138 for (int j = 0; j < 3; ++j)
139 {
141 }
142 }
143
153
154 // Set up memory reference which links fluxVecPlane to fluxVecStore.
155 for (int i = 0; i < m_numPlanes; ++i)
156 {
158 m_fluxVecPlane[i] =
160
161 for (int j = 0; j < nConvectiveFields; ++j)
162 {
164 for (int k = 0; k < 3; ++k)
165 {
168 }
169 }
170 }
171}
172
173/**
174 * @brief Compute the advection operator for a given input @a inarray
175 * and put the result in @a outarray.
176 *
177 * @param nConvectiveFields Number of fields to advect.
178 * @param fields Pointer to fields.
179 * @param advVel Advection velocities.
180 * @param inarray Input which will be advected.
181 * @param outarray Computed advection.
182 */
184 const int nConvectiveFields,
186 const Array<OneD, Array<OneD, NekDouble>> &advVel,
187 const Array<OneD, Array<OneD, NekDouble>> &inarray,
188 Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble &time,
189 [[maybe_unused]] const Array<OneD, Array<OneD, NekDouble>> &pFwd,
190 [[maybe_unused]] const Array<OneD, Array<OneD, NekDouble>> &pBwd)
191{
193 int nVel = advVel.size();
194
195 // Call solver's flux vector function to compute the flux vector on
196 // the entire domain.
198
199 // Loop over each plane.
200 for (int i = 0; i < m_numPlanes; ++i)
201 {
202 // Set up memory references for fields, inarray and outarray for
203 // this plane.
204 for (int j = 0; j < nConvectiveFields; ++j)
205 {
206 m_fieldsPlane[j] = fields[j]->GetPlane(i);
208 m_numPointsPlane, tmp2 = inarray[j] + m_planePos[i]);
210 m_numPointsPlane, tmp2 = outarray[j] + m_planePos[i]);
211 }
212
213 for (int j = 0; j < nVel; ++j)
214 {
215 if (advVel[j].size() != 0)
216 {
218 m_numPointsPlane, tmp2 = advVel[j] + m_planePos[i]);
219 }
220 }
221
222 // Compute advection term for this plane.
223 m_planeAdv->Advect(nConvectiveFields, m_fieldsPlane, m_advVelPlane,
225 }
226
227 // Calculate Fourier derivative and add to final result.
228 for (int i = 0; i < nConvectiveFields; ++i)
229 {
230 fields[0]->PhysDeriv(2, m_fluxVecStore[i][2], tmp);
231
232 Vmath::Vadd(m_numPoints, outarray[i], 1, tmp, 1, outarray[i], 1);
233 }
234}
235
236/**
237 *
238 */
240 [[maybe_unused]] const Array<OneD, Array<OneD, NekDouble>> &inarray,
242{
243 // Return section of flux vector for this plane.
244 outarray = m_fluxVecPlane[m_planeCounter];
245
246 // Increment the plane counter.
248}
249} // namespace Nektar::SolverUtils
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:143
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
Array< OneD, Array< OneD, Array< OneD, Array< OneD, NekDouble > > > > m_fluxVecPlane
void ModifiedFluxVector(const Array< OneD, Array< OneD, NekDouble > > &physfield, Array< OneD, Array< OneD, Array< OneD, NekDouble > > > &flux)
Array< OneD, Array< OneD, NekDouble > > m_outarrayPlane
void v_Advect(const int nConvField, 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 operator for a given input inarray and put the result in outarray.
Array< OneD, Array< OneD, NekDouble > > m_advVelPlane
Advection3DHomogeneous1D(std::string advType)
AdvectionFR uses the Flux Reconstruction (FR) approach to compute the advection term....
Array< OneD, Array< OneD, NekDouble > > m_inarrayPlane
static AdvectionSharedPtr create(std::string advType)
Array< OneD, MultiRegions::ExpListSharedPtr > m_fieldsPlane
Array< OneD, Array< OneD, Array< OneD, NekDouble > > > m_fluxVecStore
void v_InitObject(LibUtilities::SessionReaderSharedPtr pSession, Array< OneD, MultiRegions::ExpListSharedPtr > pFields) override
Initiliase Advection3DHomogeneous1D objects and store them before starting the time-stepping.
AdvectionFluxVecCB m_fluxVector
Callback function to the flux vector (set when advection is in conservative form).
Definition: Advection.h:168
RiemannSolverSharedPtr m_riemann
Riemann solver for DG-type schemes.
Definition: Advection.h:170
const Array< OneD, const NekDouble > & Exec()
const Array< OneD, const Array< OneD, NekDouble > > & Exec()
std::shared_ptr< SessionReader > SessionReaderSharedPtr
AdvectionFactory & GetAdvectionFactory()
Gets the factory for initialising advection objects.
Definition: Advection.cpp:43
double NekDouble
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
Definition: Vmath.hpp:180