Nektar++
SkewSymmetricAdvection.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: SkewSymmetricAdvection.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: Evaluation of the Navier Stokes advective term
32//
33///////////////////////////////////////////////////////////////////////////////
34
36
37using namespace std;
38
39namespace Nektar
40{
43 "SkewSymmetric", SkewSymmetricAdvection::create, "Skew Symmetric");
44
45/**
46 *
47 */
49
50{
51}
52
53/**
54 *
55 */
57{
58}
59
60/**
61 *
62 */
66{
67 Advection::v_InitObject(pSession, pFields);
68
69 m_homogen_dealiasing = pSession->DefinesSolverInfo("dealiasing");
70 pSession->MatchSolverInfo("ModeType", "SingleMode", m_SingleMode, false);
71 pSession->MatchSolverInfo("ModeType", "HalfMode", m_HalfMode, false);
72}
73
74/**
75 *
76 */
78 const int nConvectiveFields,
80 const Array<OneD, Array<OneD, NekDouble>> &advVel,
81 const Array<OneD, Array<OneD, NekDouble>> &inarray,
82 Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble &time,
83 const Array<OneD, Array<OneD, NekDouble>> &pFwd,
84 const Array<OneD, Array<OneD, NekDouble>> &pBwd)
85{
86 boost::ignore_unused(time, pFwd, pBwd);
87
88 // use dimension of Velocity vector to dictate dimension of operation
89 int ndim = advVel.size();
90 int nqtot = fields[0]->GetTotPoints();
91 ASSERTL1(nConvectiveFields == inarray.size(),
92 "Number of convective fields and Inarray are not compatible");
93
95 for (int i = 0; i < ndim; ++i)
96 {
97 if (fields[i]->GetWaveSpace() && !m_SingleMode && !m_HalfMode)
98 {
99 velocity[i] = Array<OneD, NekDouble>(nqtot, 0.0);
100 fields[i]->HomogeneousBwdTrans(nqtot, advVel[i], velocity[i]);
101 }
102 else
103 {
104 velocity[i] = advVel[i];
105 }
106 }
107
108 for (int n = 0; n < nConvectiveFields; ++n)
109 {
110 // ToDo: here we should add a check that V has right dimension
111
112 int nPointsTot = fields[0]->GetNpoints();
113 Array<OneD, NekDouble> gradV0, gradV1, gradV2, tmp, Up;
114
115 gradV0 = Array<OneD, NekDouble>(nPointsTot);
116 tmp = Array<OneD, NekDouble>(nPointsTot);
117
118 // Evaluate V\cdot Grad(u)
119 switch (ndim)
120 {
121 case 1:
122 fields[0]->PhysDeriv(inarray[n], gradV0);
123 Vmath::Vmul(nPointsTot, gradV0, 1, velocity[0], 1, outarray[n],
124 1);
125 Vmath::Vmul(nPointsTot, inarray[n], 1, velocity[0], 1, gradV0,
126 1);
127 fields[0]->PhysDeriv(gradV0, tmp);
128 Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n], 1);
129 Vmath::Smul(nPointsTot, 0.5, outarray[n], 1, outarray[n], 1);
130 break;
131 case 2:
132 gradV1 = Array<OneD, NekDouble>(nPointsTot);
133 fields[0]->PhysDeriv(inarray[n], gradV0, gradV1);
134 Vmath::Vmul(nPointsTot, gradV0, 1, velocity[0], 1, outarray[n],
135 1);
136 Vmath::Vvtvp(nPointsTot, gradV1, 1, velocity[1], 1, outarray[n],
137 1, outarray[n], 1);
138 Vmath::Vmul(nPointsTot, inarray[n], 1, velocity[0], 1, gradV0,
139 1);
140 Vmath::Vmul(nPointsTot, inarray[n], 1, velocity[1], 1, gradV1,
141 1);
142 fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0], gradV0,
143 tmp);
144 Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n], 1);
145 fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[1], gradV1,
146 tmp);
147 Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n], 1);
148 Vmath::Smul(nPointsTot, 0.5, outarray[n], 1, outarray[n], 1);
149 break;
150 case 3:
151 gradV1 = Array<OneD, NekDouble>(nPointsTot);
152 gradV2 = Array<OneD, NekDouble>(nPointsTot);
153
154 fields[0]->PhysDeriv(inarray[n], gradV0, gradV1, gradV2);
155
156 // outarray[n] = 1/2(u*du/dx + v*du/dy + w*du/dz + duu/dx +
157 // duv/dy + duw/dz)
158
159 if (m_homogen_dealiasing == true &&
160 fields[0]->GetWaveSpace() == false)
161 {
162 fields[0]->DealiasedProd(nPointsTot, velocity[0], gradV0,
163 gradV0);
164 fields[0]->DealiasedProd(nPointsTot, velocity[1], gradV1,
165 gradV1);
166 fields[0]->DealiasedProd(nPointsTot, velocity[2], gradV2,
167 gradV2);
168 Vmath::Vadd(nPointsTot, gradV0, 1, gradV1, 1, outarray[n],
169 1);
170 Vmath::Vadd(nPointsTot, gradV2, 1, outarray[n], 1,
171 outarray[n], 1);
172 fields[0]->DealiasedProd(nPointsTot, inarray[n],
173 velocity[0], gradV0);
174 fields[0]->DealiasedProd(nPointsTot, inarray[n],
175 velocity[1], gradV1);
176 fields[0]->DealiasedProd(nPointsTot, inarray[n],
177 velocity[2], gradV2);
178 fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0],
179 gradV0, tmp);
180 Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
181 1);
182 fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[1],
183 gradV1, tmp);
184 Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
185 1);
186 fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],
187 gradV2, tmp);
188 Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
189 1);
190 Vmath::Smul(nPointsTot, 0.5, outarray[n], 1, outarray[n],
191 1);
192 }
193 else if (fields[0]->GetWaveSpace() == true &&
194 m_homogen_dealiasing == false)
195 {
196 Up = Array<OneD, NekDouble>(nPointsTot);
197 // vector reused to avoid even more memory requirements
198 // names may be misleading
199 fields[0]->HomogeneousBwdTrans(nPointsTot, gradV0, tmp);
200 Vmath::Vmul(nPointsTot, tmp, 1, velocity[0], 1, outarray[n],
201 1); // + u*du/dx
202 fields[0]->HomogeneousBwdTrans(nPointsTot, gradV1, tmp);
203 Vmath::Vvtvp(nPointsTot, tmp, 1, velocity[1], 1,
204 outarray[n], 1, outarray[n], 1); // + v*du/dy
205 fields[0]->HomogeneousBwdTrans(nPointsTot, gradV2, tmp);
206 Vmath::Vvtvp(nPointsTot, tmp, 1, velocity[2], 1,
207 outarray[n], 1, outarray[n], 1); // + w*du/dz
208
209 fields[0]->HomogeneousBwdTrans(nPointsTot, inarray[n], Up);
210 Vmath::Vmul(nPointsTot, Up, 1, velocity[0], 1, gradV0, 1);
211 Vmath::Vmul(nPointsTot, Up, 1, velocity[1], 1, gradV1, 1);
212 Vmath::Vmul(nPointsTot, Up, 1, velocity[2], 1, gradV2, 1);
213
214 fields[0]->SetWaveSpace(false);
215 fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0],
216 gradV0, tmp); // duu/dx
217 Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
218 1);
219 fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[1],
220 gradV1, tmp); // duv/dy
221 Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
222 1);
223 fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],
224 gradV2, tmp); // duw/dz
225 Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
226 1);
227 fields[0]->SetWaveSpace(true);
228
229 Vmath::Smul(nPointsTot, 0.5, outarray[n], 1, tmp, 1);
230 fields[0]->HomogeneousFwdTrans(nPointsTot, tmp,
231 outarray[n]);
232 }
233 else if (fields[0]->GetWaveSpace() == false &&
234 m_homogen_dealiasing == false)
235 {
236 Vmath::Vmul(nPointsTot, gradV0, 1, velocity[0], 1,
237 outarray[n], 1);
238 Vmath::Vvtvp(nPointsTot, gradV1, 1, velocity[1], 1,
239 outarray[n], 1, outarray[n], 1);
240 Vmath::Vvtvp(nPointsTot, gradV2, 1, velocity[2], 1,
241 outarray[n], 1, outarray[n], 1);
242 Vmath::Vmul(nPointsTot, inarray[n], 1, velocity[0], 1,
243 gradV0, 1);
244 Vmath::Vmul(nPointsTot, inarray[n], 1, velocity[1], 1,
245 gradV1, 1);
246 Vmath::Vmul(nPointsTot, inarray[n], 1, velocity[2], 1,
247 gradV2, 1);
248 fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0],
249 gradV0, tmp);
250 Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
251 1);
252 fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[1],
253 gradV1, tmp);
254 Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
255 1);
256 fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],
257 gradV2, tmp);
258 Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
259 1);
260 Vmath::Smul(nPointsTot, 0.5, outarray[n], 1, outarray[n],
261 1);
262 }
263 else
264 {
265 ASSERTL0(false,
266 "Dealiasing is not allowed in combination "
267 "with the Skew-Symmetric advection form for "
268 "efficiency reasons.");
269 }
270 break;
271 default:
272 ASSERTL0(false, "dimension unknown");
273 }
274
275 Vmath::Neg(nqtot, outarray[n], 1);
276 }
277}
278
279} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:249
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
static SolverUtils::AdvectionSharedPtr create(std::string)
Creates an instance of this class.
static std::string className
Name of class.
virtual void v_Advect(const int nConvectiveFields, 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
Advects a vector field.
virtual void v_InitObject(LibUtilities::SessionReaderSharedPtr pSession, Array< OneD, MultiRegions::ExpListSharedPtr > pFields) override
Initialises the advection object.
An abstract base class encapsulating the concept of advection of a vector field.
Definition: Advection.h:83
virtual SOLVER_UTILS_EXPORT void v_InitObject(LibUtilities::SessionReaderSharedPtr pSession, Array< OneD, MultiRegions::ExpListSharedPtr > pFields)
Initialises the advection object.
Definition: Advection.cpp:299
std::shared_ptr< SessionReader > SessionReaderSharedPtr
MultiRegions::Direction const DirCartesianMap[]
Definition: ExpList.h:90
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 Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
Definition: Vmath.cpp:207
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.cpp:513
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
Definition: Vmath.cpp:569
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