Nektar++
Diffusion3DHomogeneous1D.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: Diffusion3DHomogeneous1D.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: LDG diffusion 3DHomogeneous1D class.
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#include <iomanip>
36#include <iostream>
37using namespace std;
38
40
41namespace Nektar::SolverUtils
42{
43std::string Diffusion3DHomogeneous1D::type[] = {
45 "LDG3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
47 "LFRDG3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
49 "LFRSD3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
51 "LFRHU3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
53 "LFRcmin3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
55 "LFRcinf3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
57 "LDGNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
59 "LFRDGNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
61 "LFRSDNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
63 "LFRHUNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
65 "LFRcminNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
67 "LFRcinfNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create)};
68
69/**
70 * @brief Diffusion3DHomogeneous1D uses the 2D WeakDG approach
71 * to compute the diffusion term looping on the planes in the z
72 * direction and adding the flux in z direction at the end.
73 */
75{
76 // Strip trailing string "3DHomogeneous1D" to determine 2D diffusion
77 // type, and create a diffusion object for the plane.
78 m_diffType = diffType.substr(0, diffType.length() - 15);
80}
81
82/**
83 * @brief Initiliase Diffusion3DHomogeneous1D objects and store
84 * them before starting the time-stepping.
85 *
86 * @param pSession Pointer to session reader.
87 * @param pFields Pointer to fields.
88 */
92{
93 int nConvectiveFields = pFields.size();
94
96 nConvectiveFields);
97
98 // Initialise the plane advection object.
99 for (int i = 0; i < nConvectiveFields; ++i)
100 {
101 pFields_plane0[i] = pFields[i]->GetPlane(0);
102 }
103 m_planeDiff->InitObject(pSession, pFields_plane0);
104
105 m_numPoints = pFields[0]->GetTotPoints();
106 m_numPlanes = pFields[0]->GetZIDs().size();
108 m_homoLen = pFields[0]->GetHomoLen();
109 m_trans = pFields[0]->GetTransposition();
110 m_planeCounter = 0;
111
112 if (m_diffType == "LDG")
113 {
114 // Set viscous flux for LDG
115 m_planeDiff->SetFluxVector(m_fluxVector);
116 }
117 else if (m_diffType == "LDGNS")
118 {
119 // Set viscous flux for LDGNS
120 m_planeDiff->SetFluxVectorNS(m_fluxVectorNS);
121 // Set penalty flux
122 m_planeDiff->SetFluxPenaltyNS(m_fluxPenaltyNS);
123 }
124 else if (m_diffType == "LFRDGNS" || m_diffType == "LFRHUNS" ||
125 m_diffType == "LFRSDNS")
126 {
127 // Set viscous flux for FR cases
128 m_planeDiff->SetFluxVectorNS(m_fluxVectorNS);
129 }
130
133
134 if (m_fluxVectorNS)
135 {
137 Array<OneD, Array<OneD, NekDouble>>(nConvectiveFields - 1);
138 }
139 else
140 {
142 }
145
146 for (int i = 0; i < m_numPlanes; ++i)
147 {
149 }
150
151 if (m_fluxVectorNS)
152 {
154 Array<OneD, Array<OneD, NekDouble>>(nConvectiveFields);
157
158 for (int i = 0; i < nConvectiveFields; ++i)
159 {
161 }
162
163 for (int i = 0; i < m_numPlanes; ++i)
164 {
166 Array<OneD, Array<OneD, NekDouble>>(nConvectiveFields);
167
168 for (int j = 0; j < nConvectiveFields; ++j)
169 {
172 }
173 }
174 }
175}
176
177/**
178 * @brief Calculate WeakDG Diffusion for the linear problems
179 * using an LDG interface flux and the the flux in the third direction.
180 */
182 const std::size_t nConvectiveFields,
184 const Array<OneD, Array<OneD, NekDouble>> &inarray,
186 [[maybe_unused]] const Array<OneD, Array<OneD, NekDouble>> &pFwd,
187 [[maybe_unused]] const Array<OneD, Array<OneD, NekDouble>> &pBwd)
188{
191 const int nPointsTot = fields[0]->GetNpoints();
193
194 if (m_fluxVectorNS)
195 {
196 viscHComp = Array<OneD, Array<OneD, NekDouble>>(nConvectiveFields);
197 for (int i = 0; i < nConvectiveFields - 1; ++i)
198 {
199 fields[0]->PhysDeriv(2, inarray[i], m_homoDerivStore[i]);
200 viscHComp[i] = Array<OneD, NekDouble>(m_numPoints);
201 }
202 }
203
204 for (int i = 0; i < m_numPlanes; ++i)
205 {
206 // Set up memory references for fields, inarray and outarray for
207 // this plane.
208 for (int j = 0; j < inarray.size(); ++j)
209 {
211 m_numPointsPlane, tmp2 = inarray[j] + m_planePos[i]);
212 }
213
214 for (int j = 0; j < nConvectiveFields; ++j)
215 {
216 m_fieldsPlane[j] = fields[j]->GetPlane(i);
218 m_numPointsPlane, tmp2 = outarray[j] + m_planePos[i]);
219 }
220
221 if (m_fluxVectorNS)
222 {
223 m_planeDiff->SetHomoDerivs(m_homoDerivPlane[i]);
224 }
225
226 if (m_diffType == "LDGNS")
227 {
228 // Store plane Fwd/Bwd traces
229 std::size_t nTracePts =
230 m_fieldsPlane[0]->GetTrace()->GetTotPoints();
231 std::size_t nScalar = m_inarrayPlane.size();
234 {
235 for (std::size_t k = 0; k < nScalar; ++k)
236 {
237 Fwd[k] = Array<OneD, NekDouble>(nTracePts, 0.0);
238 Bwd[k] = Array<OneD, NekDouble>(nTracePts, 0.0);
239 m_fieldsPlane[k]->GetFwdBwdTracePhys(m_inarrayPlane[k],
240 Fwd[k], Bwd[k]);
241 }
242 }
243
244 m_planeDiff->Diffuse(nConvectiveFields, m_fieldsPlane,
246 }
247 else
248 {
249 m_planeDiff->Diffuse(nConvectiveFields, m_fieldsPlane,
251 }
252
253 if (m_fluxVectorNS)
254 {
256 m_planeDiff->GetFluxTensor();
257
258 // Extract H (viscTensor[2])
259 for (int j = 0; j < nConvectiveFields - 1; ++j)
260 {
261 Vmath::Vcopy(m_numPointsPlane, viscTensor[2][j + 1], 1,
262 tmp2 = viscHComp[j] + m_planePos[i], 1);
263 }
264 }
265 }
266
267 if (m_fluxVectorNS)
268 {
269 for (int j = 0; j < nConvectiveFields - 1; ++j)
270 {
271 fields[j + 1]->PhysDeriv(2, viscHComp[j], tmp);
272 Vmath::Vadd(nPointsTot, outarray[j + 1], 1, tmp, 1, outarray[j + 1],
273 1);
274 }
275 }
276 else
277 {
278 for (int j = 0; j < nConvectiveFields; ++j)
279 {
280 fields[j]->HomogeneousFwdTrans(m_numPoints, inarray[j], tmp);
281
282 for (int i = 0; i < m_numPlanes; ++i)
283 {
284 beta = 2 * M_PI * m_trans->GetK(i) / m_homoLen;
285 beta *= beta;
286
288 &tmp[0] + i * m_numPointsPlane, 1,
289 &tmp[0] + i * m_numPointsPlane, 1);
290 }
291
292 fields[0]->HomogeneousBwdTrans(m_numPoints, tmp, tmp);
293
294 Vmath::Vsub(nPointsTot, outarray[j], 1, tmp, 1, outarray[j], 1);
295 }
296 }
297}
298} // 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.
Diffusion3DHomogeneous1D(std::string diffType)
Diffusion3DHomogeneous1D uses the 2D WeakDG approach to compute the diffusion term looping on the pla...
LibUtilities::TranspositionSharedPtr m_trans
Array< OneD, MultiRegions::ExpListSharedPtr > m_fieldsPlane
static DiffusionSharedPtr create(std::string diffType)
void v_InitObject(LibUtilities::SessionReaderSharedPtr pSession, Array< OneD, MultiRegions::ExpListSharedPtr > pFields) override
Initiliase Diffusion3DHomogeneous1D objects and store them before starting the time-stepping.
Array< OneD, Array< OneD, Array< OneD, NekDouble > > > m_homoDerivPlane
Array< OneD, Array< OneD, NekDouble > > m_outarrayPlane
Array< OneD, Array< OneD, NekDouble > > m_homoDerivStore
Array< OneD, Array< OneD, NekDouble > > m_inarrayPlane
void v_Diffuse(const size_t nConvective, const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const Array< OneD, Array< OneD, NekDouble > > &pFwd=NullNekDoubleArrayOfArray, const Array< OneD, Array< OneD, NekDouble > > &pBwd=NullNekDoubleArrayOfArray) override
Calculate WeakDG Diffusion for the linear problems using an LDG interface flux and the the flux in th...
DiffusionFluxVecCBNS m_fluxVectorNS
Definition: Diffusion.h:354
DiffusionFluxPenaltyNS m_fluxPenaltyNS
Definition: Diffusion.h:355
DiffusionFluxVecCB m_fluxVector
Definition: Diffusion.h:353
std::shared_ptr< SessionReader > SessionReaderSharedPtr
@ beta
Gauss Radau pinned at x=-1,.
Definition: PointsType.h:59
DiffusionFactory & GetDiffusionFactory()
Definition: Diffusion.cpp:39
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
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition: Vmath.hpp:100
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
Definition: Vmath.hpp:220
STL namespace.