Nektar++
ProcessQCriterion.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessQCriterion.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: Computes Q Criterion field.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <iostream>
36 #include <string>
37 using namespace std;
38 
39 #include <boost/core/ignore_unused.hpp>
40 
42 
43 #include "ProcessQCriterion.h"
44 
45 namespace Nektar
46 {
47 namespace FieldUtils
48 {
49 
50 ModuleKey ProcessQCriterion::className =
52  ModuleKey(eProcessModule, "QCriterion"),
53  ProcessQCriterion::create,
54  "Computes Q-Criterion.");
55 
56 ProcessQCriterion::ProcessQCriterion(FieldSharedPtr f) : ProcessModule(f)
57 {
58 }
59 
61 {
62 }
63 
64 void ProcessQCriterion::Process(po::variables_map &vm)
65 {
66  m_f->SetUpExp(vm);
67 
68  int nfields = m_f->m_variables.size();
69  m_f->m_variables.push_back("Q");
70  // Skip in case of empty partition
71  if (m_f->m_exp[0]->GetNumElmts() == 0)
72  {
73  return;
74  }
75 
76  int i, s;
77  int expdim = m_f->m_graph->GetMeshDimension();
78  int spacedim = expdim + (m_f->m_numHomogeneousDir);
79 
80  ASSERTL0(spacedim == 3 || spacedim == 2,
81  "ProcessQCriterion must be computed for a 2D, quasi-3D, or 3D case.");
82 
83  int npoints = m_f->m_exp[0]->GetNpoints();
84 
85  Array<OneD, Array<OneD, NekDouble> > grad(spacedim * spacedim);
86 
87  Array<OneD, NekDouble> omega(npoints, 0.);
88  Array<OneD, NekDouble> S(npoints, 0.);
89 
90  // Will store the Q-Criterion
91  Array<OneD, NekDouble> outfield (npoints);
92 
93  int nstrips;
94 
95  m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
96 
97  for (i = 0; i < spacedim * spacedim; ++i)
98  {
99  grad[i] = Array<OneD, NekDouble>(npoints);
100  }
101 
103 
104  NekDouble fac = 0.5;
105  if (spacedim == 2)
106  {
107  for (s = 0; s < nstrips; ++s) // homogeneous strip varient
108  {
109  for (i = 0; i < spacedim; ++i)
110  {
111  m_f->m_exp[s * nfields + i]->PhysDeriv(
112  m_f->m_exp[s * nfields + i]->GetPhys(), grad[i * spacedim],
113  grad[i * spacedim + 1]);
114  }
115 
116  // W_z = Vx - Uy
117  Vmath::Vsub(npoints, grad[1 * spacedim + 0], 1,
118  grad[0 * spacedim + 1], 1,
119  outfield, 1);
120  // W_z^2
121  Vmath::Vmul(npoints, outfield, 1, outfield, 1, omega, 1);
122 
123  // Ux^2
124  Vmath::Vmul(npoints, grad[0 * spacedim + 0], 1,
125  grad[0 * spacedim + 0], 1,
126  S, 1);
127  // Vy^2
128  Vmath::Vvtvp(npoints,grad[1 * spacedim + 1], 1,
129  grad[1 * spacedim + 1], 1,
130  S, 1, S, 1);
131 
132  // Vx + Uy
133  Vmath::Vadd(npoints, grad[1 * spacedim + 0], 1,
134  grad[0 * spacedim + 1], 1,
135  outfield, 1);
136  Vmath::Vmul(npoints, outfield, 1, outfield, 1, outfield, 1);
137  Vmath::Svtvp(npoints, fac, outfield, 1, S, 1, S, 1);
138 
139  Vmath::Svtvm(npoints, fac, omega, 1, S, 1, outfield, 1);
140  Vmath::Smul(npoints, fac, outfield, 1, outfield, 1);
141 
142  Exp = m_f->AppendExpList(m_f->m_numHomogeneousDir);
143  Vmath::Vcopy(npoints, outfield, 1, Exp->UpdatePhys(), 1);
144  Exp->FwdTrans_IterPerExp(outfield, Exp->UpdateCoeffs());
145 
146  auto it = m_f->m_exp.begin() + s * (nfields + 1) + nfields;
147  m_f->m_exp.insert(it, Exp);
148  }
149  }
150  else if (spacedim == 3)
151  {
152  Array<OneD, NekDouble> outfield1(npoints);
153  Array<OneD, NekDouble> outfield2(npoints);
154  Array<OneD, NekDouble> outfield3(npoints);
155  for (s = 0; s < nstrips; ++s) // homogeneous strip varient
156  {
157  for (i = 0; i < spacedim; ++i)
158  {
159  m_f->m_exp[s * nfields + i]->PhysDeriv(
160  m_f->m_exp[s * nfields + i]->GetPhys(), grad[i * spacedim],
161  grad[i * spacedim + 1], grad[i * spacedim + 2]);
162  }
163 
164  // W_x = Wy - Vz
165  Vmath::Vsub(npoints, grad[2 * spacedim + 1], 1,
166  grad[1 * spacedim + 2], 1,
167  outfield1, 1);
168  // W_x^2
169  Vmath::Vmul(npoints, outfield1, 1, outfield1, 1, outfield1, 1);
170 
171  // W_y = Uz - Wx
172  Vmath::Vsub(npoints, grad[0 * spacedim + 2], 1,
173  grad[2 * spacedim + 0], 1,
174  outfield2, 1);
175  // W_y^2
176  Vmath::Vmul(npoints, outfield2, 1, outfield2, 1, outfield2, 1);
177 
178  // W_z = Vx - Uy
179  Vmath::Vsub(npoints, grad[1 * spacedim + 0], 1,
180  grad[0 * spacedim + 1], 1,
181  outfield3, 1);
182  // W_z^2
183  Vmath::Vmul(npoints, outfield3, 1, outfield3, 1, outfield3, 1);
184 
185  // Omega = 0.5*(W_x^2 + W_y^2 + W_z^2)
186  Vmath::Vadd(npoints, outfield1, 1, outfield2, 1, omega, 1);
187  Vmath::Vadd(npoints, omega, 1, outfield3, 1, omega, 1);
188  Vmath::Smul(npoints, fac, omega, 1, omega, 1);
189 
190  // Ux^2
191  Vmath::Vmul(npoints, grad[0 * spacedim + 0], 1,
192  grad[0 * spacedim + 0], 1,
193  outfield1, 1);
194  // Vy^2
195  Vmath::Vmul(npoints, grad[1 * spacedim + 1], 1,
196  grad[1 * spacedim + 1], 1,
197  outfield2, 1);
198  // Wz^2
199  Vmath::Vmul(npoints, grad[2 * spacedim + 2], 1,
200  grad[2 * spacedim + 2], 1,
201  outfield3, 1);
202 
203  //
204  Vmath::Vadd(npoints, outfield1, 1, outfield2, 1, S, 1);
205  Vmath::Vadd(npoints, S, 1, outfield3, 1, S, 1);
206 
207  // Wy + Vz
208  Vmath::Vadd(npoints, grad[2 * spacedim + 1], 1,
209  grad[1 * spacedim + 2], 1,
210  outfield1, 1);
211  Vmath::Vmul(npoints, outfield1, 1, outfield1, 1, outfield1, 1);
212 
213  // Uz + Wx
214  Vmath::Vadd(npoints, grad[0 * spacedim + 2], 1,
215  grad[2 * spacedim + 0], 1,
216  outfield2, 1);
217  Vmath::Vmul(npoints, outfield2, 1, outfield2, 1, outfield2, 1);
218 
219  // Vx + Uy
220  Vmath::Vadd(npoints, grad[1 * spacedim + 0], 1,
221  grad[0 * spacedim + 1], 1,
222  outfield3, 1);
223  Vmath::Vmul(npoints, outfield3, 1, outfield3, 1, outfield3, 1);
224 
225  Vmath::Vadd(npoints, outfield1, 1, outfield2, 1, outfield2, 1);
226  Vmath::Vadd(npoints, outfield2, 1, outfield3, 1, outfield3, 1);
227 
228  Vmath::Smul(npoints, fac, outfield3, 1, outfield3, 1);
229 
230  Vmath::Vadd(npoints, outfield3, 1, S, 1, S, 1);
231  Vmath::Vsub(npoints, omega, 1, S, 1, outfield, 1);
232 
233  Vmath::Smul(npoints, fac, outfield, 1, outfield, 1);
234 
235  Exp = m_f->AppendExpList(m_f->m_numHomogeneousDir);
236  Vmath::Vcopy(npoints, outfield, 1, Exp->UpdatePhys(), 1);
237  Exp->FwdTrans_IterPerExp(outfield, Exp->UpdateCoeffs());
238 
239  auto it = m_f->m_exp.begin() + s * (nfields + 1) + nfields;
240  m_f->m_exp.insert(it, Exp);
241  }
242  }
243 }
244 
245 }
246 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
FieldSharedPtr m_f
Field object.
Definition: Module.h:230
Abstract base class for processing modules.
Definition: Module.h:265
virtual void Process(po::variables_map &vm)
Write mesh to output file.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:989
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:290
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
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:192
void Svtvp(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
svtvp (scalar times vector plus vector): z = alpha*x + y
Definition: Vmath.cpp:565
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:513
void Svtvm(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
svtvp (scalar times vector plus vector): z = alpha*x - y
Definition: Vmath.cpp:602
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:322
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:225
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1199
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:372