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
39#include <boost/core/ignore_unused.hpp>
40
42
43namespace Nektar
44{
45namespace SolverUtils
46{
47std::string Diffusion3DHomogeneous1D::type[] = {
49 "LDG3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
51 "LFRDG3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
53 "LFRSD3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
55 "LFRHU3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
57 "LFRcmin3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
59 "LFRcinf3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
61 "LDGNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
63 "LFRDGNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
65 "LFRSDNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
67 "LFRHUNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
69 "LFRcminNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
71 "LFRcinfNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create)};
72
73/**
74 * @brief Diffusion3DHomogeneous1D uses the 2D WeakDG approach
75 * to compute the diffusion term looping on the planes in the z
76 * direction and adding the flux in z direction at the end.
77 */
79{
80 // Strip trailing string "3DHomogeneous1D" to determine 2D diffusion
81 // type, and create a diffusion object for the plane.
82 m_diffType = diffType.substr(0, diffType.length() - 15);
84}
85
86/**
87 * @brief Initiliase Diffusion3DHomogeneous1D objects and store
88 * them before starting the time-stepping.
89 *
90 * @param pSession Pointer to session reader.
91 * @param pFields Pointer to fields.
92 */
96{
97 int nConvectiveFields = pFields.size();
98
100 nConvectiveFields);
101
102 // Initialise the plane advection object.
103 for (int i = 0; i < nConvectiveFields; ++i)
104 {
105 pFields_plane0[i] = pFields[i]->GetPlane(0);
106 }
107 m_planeDiff->InitObject(pSession, pFields_plane0);
108
109 m_numPoints = pFields[0]->GetTotPoints();
110 m_numPlanes = pFields[0]->GetZIDs().size();
112 m_homoLen = pFields[0]->GetHomoLen();
113 m_trans = pFields[0]->GetTransposition();
114 m_planeCounter = 0;
115
116 if (m_diffType == "LDG")
117 {
118 // Set viscous flux for LDG
119 m_planeDiff->SetFluxVector(m_fluxVector);
120 }
121 else if (m_diffType == "LDGNS")
122 {
123 // Set viscous flux for LDGNS
124 m_planeDiff->SetFluxVectorNS(m_fluxVectorNS);
125 // Set penalty flux
126 m_planeDiff->SetFluxPenaltyNS(m_fluxPenaltyNS);
127 }
128 else if (m_diffType == "LFRDGNS" || m_diffType == "LFRHUNS" ||
129 m_diffType == "LFRSDNS")
130 {
131 // Set viscous flux for FR cases
132 m_planeDiff->SetFluxVectorNS(m_fluxVectorNS);
133 }
134
137
138 if (m_fluxVectorNS)
139 {
141 Array<OneD, Array<OneD, NekDouble>>(nConvectiveFields - 1);
142 }
143 else
144 {
146 }
149
150 for (int i = 0; i < m_numPlanes; ++i)
151 {
153 }
154
155 if (m_fluxVectorNS)
156 {
158 Array<OneD, Array<OneD, NekDouble>>(nConvectiveFields);
161
162 for (int i = 0; i < nConvectiveFields; ++i)
163 {
165 }
166
167 for (int i = 0; i < m_numPlanes; ++i)
168 {
170 Array<OneD, Array<OneD, NekDouble>>(nConvectiveFields);
171
172 for (int j = 0; j < nConvectiveFields; ++j)
173 {
176 }
177 }
178 }
179}
180
181/**
182 * @brief Calculate WeakDG Diffusion for the linear problems
183 * using an LDG interface flux and the the flux in the third direction.
184 */
186 const std::size_t nConvectiveFields,
188 const Array<OneD, Array<OneD, NekDouble>> &inarray,
190 const Array<OneD, Array<OneD, NekDouble>> &pFwd,
191 const Array<OneD, Array<OneD, NekDouble>> &pBwd)
192{
193 boost::ignore_unused(pFwd, pBwd);
194
197 const int nPointsTot = fields[0]->GetNpoints();
199
200 if (m_fluxVectorNS)
201 {
202 viscHComp = Array<OneD, Array<OneD, NekDouble>>(nConvectiveFields);
203 for (int i = 0; i < nConvectiveFields - 1; ++i)
204 {
205 fields[0]->PhysDeriv(2, inarray[i], m_homoDerivStore[i]);
206 viscHComp[i] = Array<OneD, NekDouble>(m_numPoints);
207 }
208 }
209
210 for (int i = 0; i < m_numPlanes; ++i)
211 {
212 // Set up memory references for fields, inarray and outarray for
213 // this plane.
214 for (int j = 0; j < inarray.size(); ++j)
215 {
217 m_numPointsPlane, tmp2 = inarray[j] + m_planePos[i]);
218 }
219
220 for (int j = 0; j < nConvectiveFields; ++j)
221 {
222 m_fieldsPlane[j] = fields[j]->GetPlane(i);
224 m_numPointsPlane, tmp2 = outarray[j] + m_planePos[i]);
225 }
226
227 if (m_fluxVectorNS)
228 {
229 m_planeDiff->SetHomoDerivs(m_homoDerivPlane[i]);
230 }
231
232 if (m_diffType == "LDGNS")
233 {
234 // Store plane Fwd/Bwd traces
235 std::size_t nTracePts =
236 m_fieldsPlane[0]->GetTrace()->GetTotPoints();
237 std::size_t nScalar = m_inarrayPlane.size();
240 {
241 for (std::size_t k = 0; k < nScalar; ++k)
242 {
243 Fwd[k] = Array<OneD, NekDouble>(nTracePts, 0.0);
244 Bwd[k] = Array<OneD, NekDouble>(nTracePts, 0.0);
245 m_fieldsPlane[k]->GetFwdBwdTracePhys(m_inarrayPlane[k],
246 Fwd[k], Bwd[k]);
247 }
248 }
249
250 m_planeDiff->Diffuse(nConvectiveFields, m_fieldsPlane,
252 }
253 else
254 {
255 m_planeDiff->Diffuse(nConvectiveFields, m_fieldsPlane,
257 }
258
259 if (m_fluxVectorNS)
260 {
262 m_planeDiff->GetFluxTensor();
263
264 // Extract H (viscTensor[2])
265 for (int j = 0; j < nConvectiveFields - 1; ++j)
266 {
267 Vmath::Vcopy(m_numPointsPlane, viscTensor[2][j + 1], 1,
268 tmp2 = viscHComp[j] + m_planePos[i], 1);
269 }
270 }
271 }
272
273 if (m_fluxVectorNS)
274 {
275 for (int j = 0; j < nConvectiveFields - 1; ++j)
276 {
277 fields[j + 1]->PhysDeriv(2, viscHComp[j], tmp);
278 Vmath::Vadd(nPointsTot, outarray[j + 1], 1, tmp, 1, outarray[j + 1],
279 1);
280 }
281 }
282 else
283 {
284 for (int j = 0; j < nConvectiveFields; ++j)
285 {
286 fields[j]->HomogeneousFwdTrans(m_numPoints, inarray[j], tmp);
287
288 for (int i = 0; i < m_numPlanes; ++i)
289 {
290 beta = 2 * M_PI * m_trans->GetK(i) / m_homoLen;
291 beta *= beta;
292
294 &tmp[0] + i * m_numPointsPlane, 1,
295 &tmp[0] + i * m_numPointsPlane, 1);
296 }
297
298 fields[0]->HomogeneousBwdTrans(m_numPoints, tmp, tmp);
299
300 Vmath::Vsub(nPointsTot, outarray[j], 1, tmp, 1, outarray[j], 1);
301 }
302 }
303}
304} // namespace SolverUtils
305} // 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
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)
virtual 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
virtual 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:351
DiffusionFluxPenaltyNS m_fluxPenaltyNS
Definition: Diffusion.h:352
DiffusionFluxVecCB m_fluxVector
Definition: Diffusion.h:350
std::shared_ptr< SessionReader > SessionReaderSharedPtr
@ beta
Gauss Radau pinned at x=-1,.
Definition: PointsType.h:61
DiffusionFactory & GetDiffusionFactory()
Definition: Diffusion.cpp:41
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
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.cpp:245
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1191
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.cpp:414