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  boost::ignore_unused(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,
81  "ProcessQCriterion must be computed for a 3D (or quasi-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);
88  Array<OneD, NekDouble> S(npoints);
89 
90  // Will store the Q-Criterion
91  Array<OneD, NekDouble> outfield (npoints);
92  Array<OneD, NekDouble> outfield1(npoints);
93  Array<OneD, NekDouble> outfield2(npoints);
94  Array<OneD, NekDouble> outfield3(npoints);
95 
96  int nstrips;
97 
98  m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
99 
100  for (i = 0; i < spacedim * spacedim; ++i)
101  {
102  grad[i] = Array<OneD, NekDouble>(npoints);
103  }
104 
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], grad[i * spacedim + 2]);
114  }
115 
116  // W_x = Wy - Vz
117  Vmath::Vsub(npoints, grad[2 * spacedim + 1], 1,
118  grad[1 * spacedim + 2], 1,
119  outfield1, 1);
120  // W_x^2
121  Vmath::Vmul(npoints, outfield1, 1, outfield1, 1, outfield1, 1);
122 
123  // W_y = Uz - Wx
124  Vmath::Vsub(npoints, grad[0 * spacedim + 2], 1,
125  grad[2 * spacedim + 0], 1,
126  outfield2, 1);
127  // W_y^2
128  Vmath::Vmul(npoints, outfield2, 1, outfield2, 1, outfield2, 1);
129 
130  // W_z = Vx - Uy
131  Vmath::Vsub(npoints, grad[1 * spacedim + 0], 1,
132  grad[0 * spacedim + 1], 1,
133  outfield3, 1);
134  // W_z^2
135  Vmath::Vmul(npoints, outfield3, 1, outfield3, 1, outfield3, 1);
136 
137  // Omega = 0.5*(W_x^2 + W_y^2 + W_z^2)
138  NekDouble fac = 0.5;
139  Vmath::Vadd(npoints, outfield1, 1, outfield2, 1, omega, 1);
140  Vmath::Vadd(npoints, omega, 1, outfield3, 1, omega, 1);
141  Vmath::Smul(npoints, fac, omega, 1, omega, 1);
142 
143  // Ux^2
144  Vmath::Vmul(npoints, grad[0 * spacedim + 0], 1,
145  grad[0 * spacedim + 0], 1,
146  outfield1, 1);
147  // Vy^2
148  Vmath::Vmul(npoints, grad[1 * spacedim + 1], 1,
149  grad[1 * spacedim + 1], 1,
150  outfield2, 1);
151  // Wz^2
152  Vmath::Vmul(npoints, grad[2 * spacedim + 2], 1,
153  grad[2 * spacedim + 2], 1,
154  outfield3, 1);
155 
156  //
157  Vmath::Vadd(npoints, outfield1, 1, outfield2, 1, S, 1);
158  Vmath::Vadd(npoints, S, 1, outfield3, 1, S, 1);
159 
160  // Wy + Vz
161  Vmath::Vadd(npoints, grad[2 * spacedim + 1], 1,
162  grad[1 * spacedim + 2], 1,
163  outfield1, 1);
164  Vmath::Vmul(npoints, outfield1, 1, outfield1, 1, outfield1, 1);
165 
166  // Uz + Wx
167  Vmath::Vadd(npoints, grad[0 * spacedim + 2], 1,
168  grad[2 * spacedim + 0], 1,
169  outfield2, 1);
170  Vmath::Vmul(npoints, outfield2, 1, outfield2, 1, outfield2, 1);
171 
172  // Vx + Uy
173  Vmath::Vadd(npoints, grad[1 * spacedim + 0], 1,
174  grad[0 * spacedim + 1], 1,
175  outfield3, 1);
176  Vmath::Vmul(npoints, outfield3, 1, outfield3, 1, outfield3, 1);
177 
178  Vmath::Vadd(npoints, outfield1, 1, outfield2, 1, outfield2, 1);
179  Vmath::Vadd(npoints, outfield2, 1, outfield3, 1, outfield3, 1);
180 
181  Vmath::Smul(npoints, fac, outfield3, 1, outfield3, 1);
182 
183  Vmath::Vadd(npoints, outfield3, 1, S, 1, S, 1);
184  Vmath::Vsub(npoints, omega, 1, S, 1, outfield, 1);
185 
186  Vmath::Smul(npoints, fac, outfield, 1, outfield, 1);
187 
188  Exp = m_f->AppendExpList(m_f->m_numHomogeneousDir);
189  Vmath::Vcopy(npoints, outfield, 1, Exp->UpdatePhys(), 1);
190  Exp->FwdTrans_IterPerExp(outfield, Exp->UpdateCoeffs());
191 
192  auto it = m_f->m_exp.begin() + s * (nfields + 1) + nfields;
193  m_f->m_exp.insert(it, Exp);
194  }
195 }
196 
197 }
198 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
STL namespace.
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:762
virtual void Process(po::variables_map &vm)
Write mesh to output file.
std::pair< ModuleType, std::string > ModuleKey
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*y.
Definition: Vmath.cpp:216
double NekDouble
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:346
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
Abstract base class for processing modules.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1064
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:302
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:186
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.