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
35#include <boost/core/ignore_unused.hpp>
36
39#include <iomanip>
40#include <iostream>
41
42using namespace std;
43
44namespace Nektar
45{
46namespace SolverUtils
47{
48std::string Advection3DHomogeneous1D::type[] = {
50 "WeakDG3DHomogeneous1D", Advection3DHomogeneous1D::create),
52 "FRDG3DHomogeneous1D", Advection3DHomogeneous1D::create),
54 "FRDG3DHomogeneous1D", Advection3DHomogeneous1D::create),
56 "FRSD3DHomogeneous1D", Advection3DHomogeneous1D::create),
58 "FRHU3DHomogeneous1D", Advection3DHomogeneous1D::create),
60 "FRcmin3DHomogeneous1D", Advection3DHomogeneous1D::create),
62 "FRcinf3DHomogeneous1D", Advection3DHomogeneous1D::create)};
63
64/**
65 * @brief AdvectionFR uses the Flux Reconstruction (FR) approach to
66 * compute the advection term. The implementation is only for segments,
67 * quadrilaterals and hexahedra at the moment.
68 *
69 * \todo Extension to triangles, tetrahedra and other shapes.
70 * (Long term objective)
71 */
73 : m_advType(advType)
74{
75 // Strip trailing string "3DHomogeneous1D" to determine 2D advection
76 // type, and create an advection object for the plane.
77 string advName = advType.substr(0, advType.length() - 15);
78 m_planeAdv = GetAdvectionFactory().CreateInstance(advName, advName);
79}
80
81/**
82 * @brief Initiliase Advection3DHomogeneous1D objects and store them
83 * before starting the time-stepping.
84 *
85 * @param pSession Pointer to session reader.
86 * @param pFields Pointer to fields.
87 */
91{
92 int nConvectiveFields = pFields.size();
93
95 nConvectiveFields);
96
97 // Initialise the plane advection object.
98 for (int i = 0; i < nConvectiveFields; ++i)
99 {
100 pFields_plane0[i] = pFields[i]->GetPlane(0);
101 }
102 m_planeAdv->InitObject(pSession, pFields_plane0);
103
104 m_numPoints = pFields[0]->GetTotPoints();
105 m_planes = pFields[0]->GetZIDs();
106 m_numPlanes = m_planes.size();
108
109 // Set Riemann solver and flux vector callback for this plane.
110 m_planeAdv->SetRiemannSolver(m_riemann);
112 this);
113 m_planeCounter = 0;
114
115 // Override Riemann solver scalar and vector callbacks.
116 map<string, RSScalarFuncType> scalars = m_riemann->GetScalars();
117 map<string, RSVecFuncType> vectors = m_riemann->GetVectors();
118
119 for (auto &it1 : scalars)
120 {
121 std::shared_ptr<HomoRSScalar> tmp =
124 m_riemann->SetScalar(it1.first, &HomoRSScalar::Exec, tmp);
125 }
126
127 for (auto &it2 : vectors)
128 {
129 std::shared_ptr<HomoRSVector> tmp =
131 it2.second, m_numPlanes, it2.first);
132 m_riemann->SetVector(it2.first, &HomoRSVector::Exec, tmp);
133 }
134
137
138 // Set up storage for flux vector.
139 for (int i = 0; i < nConvectiveFields; ++i)
140 {
142 for (int j = 0; j < 3; ++j)
143 {
145 }
146 }
147
157
158 // Set up memory reference which links fluxVecPlane to fluxVecStore.
159 for (int i = 0; i < m_numPlanes; ++i)
160 {
162 m_fluxVecPlane[i] =
164
165 for (int j = 0; j < nConvectiveFields; ++j)
166 {
168 for (int k = 0; k < 3; ++k)
169 {
172 }
173 }
174 }
175}
176
177/**
178 * @brief Compute the advection operator for a given input @a inarray
179 * and put the result in @a outarray.
180 *
181 * @param nConvectiveFields Number of fields to advect.
182 * @param fields Pointer to fields.
183 * @param advVel Advection velocities.
184 * @param inarray Input which will be advected.
185 * @param outarray Computed advection.
186 */
188 const int nConvectiveFields,
190 const Array<OneD, Array<OneD, NekDouble>> &advVel,
191 const Array<OneD, Array<OneD, NekDouble>> &inarray,
192 Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble &time,
193 const Array<OneD, Array<OneD, NekDouble>> &pFwd,
194 const Array<OneD, Array<OneD, NekDouble>> &pBwd)
195{
196 boost::ignore_unused(pFwd, pBwd);
197
199 int nVel = advVel.size();
200
201 // Call solver's flux vector function to compute the flux vector on
202 // the entire domain.
204
205 // Loop over each plane.
206 for (int i = 0; i < m_numPlanes; ++i)
207 {
208 // Set up memory references for fields, inarray and outarray for
209 // this plane.
210 for (int j = 0; j < nConvectiveFields; ++j)
211 {
212 m_fieldsPlane[j] = fields[j]->GetPlane(i);
214 m_numPointsPlane, tmp2 = inarray[j] + m_planePos[i]);
216 m_numPointsPlane, tmp2 = outarray[j] + m_planePos[i]);
217 }
218
219 for (int j = 0; j < nVel; ++j)
220 {
221 if (advVel[j].size() != 0)
222 {
224 m_numPointsPlane, tmp2 = advVel[j] + m_planePos[i]);
225 }
226 }
227
228 // Compute advection term for this plane.
229 m_planeAdv->Advect(nConvectiveFields, m_fieldsPlane, m_advVelPlane,
231 }
232
233 // Calculate Fourier derivative and add to final result.
234 for (int i = 0; i < nConvectiveFields; ++i)
235 {
236 fields[0]->PhysDeriv(2, m_fluxVecStore[i][2], tmp);
237
238 Vmath::Vadd(m_numPoints, outarray[i], 1, tmp, 1, outarray[i], 1);
239 }
240}
241
242/**
243 *
244 */
246 const Array<OneD, Array<OneD, NekDouble>> &inarray,
248{
249 boost::ignore_unused(inarray);
250
251 // Return section of flux vector for this plane.
252 outarray = m_fluxVecPlane[m_planeCounter];
253
254 // Increment the plane counter.
256}
257} // namespace SolverUtils
258} // namespace Nektar
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
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
virtual 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
virtual 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:170
RiemannSolverSharedPtr m_riemann
Riemann solver for DG-type schemes.
Definition: Advection.h:172
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:47
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
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.cpp:354