Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Computes Q Criterion field.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <iostream>
37 #include <string>
38 using namespace std;
39 
40 #include "ProcessQCriterion.h"
41 
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  if (m_f->m_verbose)
67  {
68  if (m_f->m_comm->TreatAsRankZero())
69  {
70  cout << "ProcessQCriterion: Calculating Q Criterion..." << endl;
71  }
72  }
73 
74  int i, j, s;
75  int expdim = m_f->m_graph->GetMeshDimension();
76  int spacedim = expdim;
77  if ((m_f->m_fielddef[0]->m_numHomogeneousDir) == 1 ||
78  (m_f->m_fielddef[0]->m_numHomogeneousDir) == 2)
79  {
80  spacedim = 3;
81  }
82  int nfields = m_f->m_fielddef[0]->m_fields.size();
83  if (spacedim == 1 || spacedim == 2)
84  {
85  cerr << "\n Error: ProcessQCriterion must be computed for a 3D"
86  " (or quasi-3D) case. \n"
87  << endl;
88  }
89 
90  // For calculating Q-Criterion only 1 field must be added
91  int addfields = 1;
92 
93  int npoints = m_f->m_exp[0]->GetNpoints();
94 
95  Array<OneD, Array<OneD, NekDouble> > grad(nfields * nfields);
96 
97  Array<OneD, Array<OneD, NekDouble> > omega(nfields * nfields);
98  Array<OneD, Array<OneD, NekDouble> > S(nfields * nfields);
99 
100  Array<OneD, Array<OneD, NekDouble> > outfield(addfields);
101  Array<OneD, Array<OneD, NekDouble> > outfield1(addfields);
102  Array<OneD, Array<OneD, NekDouble> > outfield2(addfields);
103  Array<OneD, Array<OneD, NekDouble> > outfield3(addfields);
104 
105  int nstrips;
106 
107  m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
108 
109  m_f->m_exp.resize(nfields * nstrips);
110 
111  for (i = 0; i < nfields * nfields; ++i)
112  {
113  grad[i] = Array<OneD, NekDouble>(npoints);
114  }
115 
116  for (i = 0; i < addfields; ++i)
117  {
118  // Will store the Q-Criterion
119  outfield[i] = Array<OneD, NekDouble>(npoints);
120  outfield1[i] = Array<OneD, NekDouble>(npoints);
121  outfield2[i] = Array<OneD, NekDouble>(npoints);
122  outfield3[i] = Array<OneD, NekDouble>(npoints);
123 
124  omega[i] = Array<OneD, NekDouble>(npoints);
125  S[i] = Array<OneD, NekDouble>(npoints);
126  }
127 
128  vector<MultiRegions::ExpListSharedPtr> Exp(nstrips * addfields);
129 
130  for (s = 0; s < nstrips; ++s) // homogeneous strip varient
131  {
132  for (i = 0; i < nfields; ++i)
133  {
134  m_f->m_exp[s * nfields + i]->PhysDeriv(
135  m_f->m_exp[s * nfields + i]->GetPhys(), grad[i * nfields],
136  grad[i * nfields + 1], grad[i * nfields + 2]);
137  }
138 
139  // W_x = Wy - Vz
140  Vmath::Vsub(npoints, grad[2 * nfields + 1], 1, grad[1 * nfields + 2], 1,
141  outfield1[0], 1);
142  // W_x^2
143  Vmath::Vmul(npoints, outfield1[0], 1, outfield1[0], 1, outfield1[0], 1);
144 
145  // W_y = Uz - Wx
146  Vmath::Vsub(npoints, grad[0 * nfields + 2], 1, grad[2 * nfields + 0], 1,
147  outfield2[0], 1);
148  // W_y^2
149  Vmath::Vmul(npoints, outfield2[0], 1, outfield2[0], 1, outfield2[0], 1);
150 
151  // W_z = Vx - Uy
152  Vmath::Vsub(npoints, grad[1 * nfields + 0], 1, grad[0 * nfields + 1], 1,
153  outfield3[0], 1);
154  // W_z^2
155  Vmath::Vmul(npoints, outfield3[0], 1, outfield3[0], 1, outfield3[0], 1);
156 
157  // add fields omega = 0.5*(W_x^2 + W_y^2 + W_z^2)
158 
159  NekDouble fac = 0.5;
160  Vmath::Vadd(npoints, &outfield1[0][0], 1, &outfield2[0][0], 1,
161  &omega[0][0], 1);
162  Vmath::Vadd(npoints, &omega[0][0], 1, &outfield3[0][0], 1, &omega[0][0],
163  1);
164 
165  for (int k = 0; k < addfields; ++k)
166  {
167  Vmath::Smul(npoints, fac, &omega[k][0], 1, &omega[k][0], 1);
168  }
169 
170  Vmath::Zero(npoints, &outfield1[0][0], 1);
171  Vmath::Zero(npoints, &outfield2[0][0], 1);
172  Vmath::Zero(npoints, &outfield3[0][0], 1);
173 
174  Vmath::Vmul(npoints, grad[0 * nfields + 0], 1, grad[0 * nfields + 0], 1,
175  outfield1[0], 1);
176  Vmath::Vmul(npoints, grad[1 * nfields + 1], 1, grad[1 * nfields + 1], 1,
177  outfield2[0], 1);
178  Vmath::Vmul(npoints, grad[2 * nfields + 2], 1, grad[2 * nfields + 2], 1,
179  outfield3[0], 1);
180 
181  Vmath::Vadd(npoints, &outfield1[0][0], 1, &outfield2[0][0], 1, &S[0][0],
182  1);
183  Vmath::Vadd(npoints, &S[0][0], 1, &outfield3[0][0], 1, &S[0][0], 1);
184 
185  // W_y + V_z
186  Vmath::Vadd(npoints, grad[2 * nfields + 1], 1, grad[1 * nfields + 2], 1,
187  outfield1[0], 1);
188  Vmath::Vmul(npoints, &outfield1[0][0], 1, &outfield1[0][0], 1,
189  &outfield1[0][0], 1);
190 
191  // U_z + W_x
192  Vmath::Vadd(npoints, grad[0 * nfields + 2], 1, grad[2 * nfields + 0], 1,
193  outfield2[0], 1);
194  Vmath::Vmul(npoints, &outfield2[0][0], 1, &outfield2[0][0], 1,
195  &outfield2[0][0], 1);
196 
197  // V_x + U_y
198  Vmath::Vadd(npoints, grad[1 * nfields + 0], 1, grad[0 * nfields + 1], 1,
199  outfield3[0], 1);
200  Vmath::Vmul(npoints, &outfield3[0][0], 1, &outfield3[0][0], 1,
201  &outfield3[0][0], 1);
202 
203  Vmath::Vadd(npoints, &outfield1[0][0], 1, &outfield2[0][0], 1,
204  &outfield2[0][0], 1);
205  Vmath::Vadd(npoints, &outfield2[0][0], 1, &outfield3[0][0], 1,
206  &outfield3[0][0], 1);
207 
208  for (int k = 0; k < addfields; ++k)
209  {
210  Vmath::Smul(npoints, fac, &outfield3[k][0], 1, &outfield3[k][0], 1);
211  }
212 
213  Vmath::Vadd(npoints, &outfield3[0][0], 1, &S[0][0], 1, &S[0][0], 1);
214  Vmath::Vsub(npoints, omega[0], 1, S[0], 1, outfield[0], 1);
215 
216  for (int k = 0; k < addfields; ++k)
217  {
218  Vmath::Smul(npoints, fac, &outfield[k][0], 1, &outfield[k][0], 1);
219  }
220 
221  for (i = 0; i < addfields; ++i)
222  {
223  int n = s * addfields + i;
224  Exp[n] =
225  m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir);
226  Exp[n]->UpdatePhys() = outfield[i];
227  Exp[n]->FwdTrans(outfield[i], Exp[n]->UpdateCoeffs());
228  }
229  }
230 
232 
233  for (s = 0; s < nstrips; ++s)
234  {
235  for (i = 0; i < addfields; ++i)
236  {
237  it = m_f->m_exp.begin() + s * (nfields + addfields) + nfields + i;
238  m_f->m_exp.insert(it, Exp[s * addfields + i]);
239  }
240  }
241 
242  vector<string> outname;
243  outname.push_back("Q");
244 
245  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
246  m_f->m_exp[0]->GetFieldDefinitions();
247  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
248 
249  for (s = 0; s < nstrips; ++s) // homogeneous strip varient
250  {
251  for (j = 0; j < nfields + addfields; ++j)
252  {
253  for (i = 0; i < FieldDef.size() / nstrips; ++i)
254  {
255  int n = s * FieldDef.size() / nstrips + i;
256 
257  if (j >= nfields)
258  {
259  FieldDef[n]->m_fields.push_back(outname[j - nfields]);
260  }
261  else
262  {
263  FieldDef[n]->m_fields.push_back(
264  m_f->m_fielddef[0]->m_fields[j]);
265  }
266  m_f->m_exp[s * (nfields + addfields) + j]->AppendFieldData(
267  FieldDef[n], FieldData[n]);
268  }
269  }
270  }
271 
272  m_f->m_fielddef = FieldDef;
273  m_f->m_data = FieldData;
274 }
275 }
276 }
STL namespace.
pair< ModuleType, string > ModuleKey
virtual void Process(po::variables_map &vm)
Write mesh to output file.
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:213
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:740
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:343
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:373
Abstract base class for processing modules.
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:299
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:183
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215