Nektar++
Loading...
Searching...
No Matches
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
40namespace Nektar::SolverUtils
41{
42std::string Advection3DHomogeneous1D::type[] = {
44 "WeakDG3DHomogeneous1D", Advection3DHomogeneous1D::create),
46 "FRDG3DHomogeneous1D", Advection3DHomogeneous1D::create),
48 "FRDG3DHomogeneous1D", Advection3DHomogeneous1D::create),
50 "FRSD3DHomogeneous1D", Advection3DHomogeneous1D::create),
52 "FRHU3DHomogeneous1D", Advection3DHomogeneous1D::create),
54 "FRcmin3DHomogeneous1D", Advection3DHomogeneous1D::create),
56 "FRcinf3DHomogeneous1D", Advection3DHomogeneous1D::create)};
57
58/**
59 *
60 * \todo Extension to triangles, tetrahedra and other shapes.
61 * (Long term objective)
62 */
64 : m_advType(advType)
65{
66 // Strip trailing string "3DHomogeneous1D" to determine 2D advection
67 // type, and create an advection object for the plane.
68 std::string advName = advType.substr(0, advType.length() - 15);
69 m_planeAdv = GetAdvectionFactory().CreateInstance(advName, advName);
70}
71
72/**
73 * @brief Initiliase Advection3DHomogeneous1D objects and store them
74 * before starting the time-stepping.
75 *
76 * @param pSession Pointer to session reader.
77 * @param pFields Pointer to fields.
78 */
82{
83 int nConvectiveFields = pFields.size();
84
86 nConvectiveFields);
87
88 // Initialise the plane advection object.
89 for (int i = 0; i < nConvectiveFields; ++i)
90 {
91 pFields_plane0[i] = pFields[i]->GetPlane(0);
92 }
93 m_planeAdv->InitObject(pSession, pFields_plane0);
94
95 m_numPoints = pFields[0]->GetTotPoints();
96 m_planes = pFields[0]->GetZIDs();
97 m_numPlanes = m_planes.size();
99
100 // Set Riemann solver and flux vector callback for this plane.
101 m_planeAdv->SetRiemannSolver(m_riemann);
103 this);
104 m_planeCounter = 0;
105
106 // Override Riemann solver scalar and vector callbacks.
107 std::map<std::string, RSScalarFuncType> scalars = m_riemann->GetScalars();
108 std::map<std::string, RSVecFuncType> vectors = m_riemann->GetVectors();
109
110 for (auto &it1 : scalars)
111 {
112 std::shared_ptr<HomoRSScalar> tmp =
115 m_riemann->SetScalar(it1.first, &HomoRSScalar::Exec, tmp);
116 }
117
118 for (auto &it2 : vectors)
119 {
120 std::shared_ptr<HomoRSVector> tmp =
122 it2.second, m_numPlanes, it2.first);
123 m_riemann->SetVector(it2.first, &HomoRSVector::Exec, tmp);
124 }
125
128
129 // Set up storage for flux vector.
130 for (int i = 0; i < nConvectiveFields; ++i)
131 {
133 for (int j = 0; j < 3; ++j)
134 {
136 }
137 }
138
148
149 // Set up memory reference which links fluxVecPlane to fluxVecStore.
150 for (int i = 0; i < m_numPlanes; ++i)
151 {
153 m_fluxVecPlane[i] =
155
156 for (int j = 0; j < nConvectiveFields; ++j)
157 {
159 for (int k = 0; k < 3; ++k)
160 {
163 }
164 }
165 }
166}
167
168/**
169 * @brief Compute the advection operator for a given input @a inarray
170 * and put the result in @a outarray.
171 *
172 * @param nConvectiveFields Number of fields to advect.
173 * @param fields Pointer to fields.
174 * @param advVel Advection velocities.
175 * @param inarray Input which will be advected.
176 * @param outarray Computed advection.
177 */
179 const int nConvectiveFields,
181 const Array<OneD, Array<OneD, NekDouble>> &advVel,
182 const Array<OneD, Array<OneD, NekDouble>> &inarray,
183 Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble &time,
184 [[maybe_unused]] const Array<OneD, Array<OneD, NekDouble>> &pFwd,
185 [[maybe_unused]] const Array<OneD, Array<OneD, NekDouble>> &pBwd)
186{
188 int nVel = advVel.size();
189
190 // Call solver's flux vector function to compute the flux vector on
191 // the entire domain.
193
194 // Loop over each plane.
195 for (int i = 0; i < m_numPlanes; ++i)
196 {
197 // Set up memory references for fields, inarray and outarray for
198 // this plane.
199 for (int j = 0; j < nConvectiveFields; ++j)
200 {
201 m_fieldsPlane[j] = fields[j]->GetPlane(i);
203 m_numPointsPlane, tmp2 = inarray[j] + m_planePos[i]);
205 m_numPointsPlane, tmp2 = outarray[j] + m_planePos[i]);
206 }
207
208 for (int j = 0; j < nVel; ++j)
209 {
210 if (advVel[j].size() != 0)
211 {
213 m_numPointsPlane, tmp2 = advVel[j] + m_planePos[i]);
214 }
215 }
216
217 // Compute advection term for this plane.
218 m_planeAdv->Advect(nConvectiveFields, m_fieldsPlane, m_advVelPlane,
220 }
221
222 // Calculate Fourier derivative and add to final result.
223 for (int i = 0; i < nConvectiveFields; ++i)
224 {
225 fields[0]->PhysDeriv(2, m_fluxVecStore[i][2], tmp);
226
227 Vmath::Vadd(m_numPoints, outarray[i], 1, tmp, 1, outarray[i], 1);
228 }
229}
230
231/**
232 *
233 */
235 [[maybe_unused]] const Array<OneD, Array<OneD, NekDouble>> &inarray,
237{
238 // Return section of flux vector for this plane.
239 outarray = m_fluxVecPlane[m_planeCounter];
240
241 // Increment the plane counter.
243}
244} // namespace Nektar::SolverUtils
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
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
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:175
RiemannSolverSharedPtr m_riemann
Riemann solver for DG-type schemes.
Definition Advection.h:177
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
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