Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 <string>
37 #include <iostream>
38 using namespace std;
39 
40 #include "ProcessQCriterion.h"
41 
44 
45 namespace Nektar
46 {
47 namespace Utilities
48 {
49 
50 ModuleKey ProcessQCriterion::className =
52  ModuleKey(eProcessModule, "QCriterion"),
53  ProcessQCriterion::create, "Computes Q-Criterion.");
54 
55 ProcessQCriterion::ProcessQCriterion(FieldSharedPtr f)
56  : 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  cout << "ProcessQCriterion: Calculating Q Criterion..." << endl;
69  }
70 
71  int i, j, s;
72  int expdim = m_f->m_graph->GetMeshDimension();
73  int spacedim = expdim;
74  if ((m_f->m_fielddef[0]->m_numHomogeneousDir) == 1 ||
75  (m_f->m_fielddef[0]->m_numHomogeneousDir) == 2)
76  {
77  spacedim = 3;
78  }
79  int nfields = m_f->m_fielddef[0]->m_fields.size();
80  if (spacedim == 1 || spacedim == 2)
81  {
82  cerr << "\n Error: ProcessQCriterion must be computed for a 3D"
83  " (or quasi-3D) case. \n" << endl;
84  }
85 
86  //For calculating Q-Criterion only 1 field must be added
87  int addfields = 1;
88 
89  int npoints = m_f->m_exp[0]->GetNpoints();
90 
91  Array<OneD, Array<OneD, NekDouble> > grad(nfields * nfields);
92 
93  Array<OneD, Array<OneD, NekDouble> > omega(nfields * nfields);
94  Array<OneD, Array<OneD, NekDouble> > S (nfields * nfields);
95 
96  Array<OneD, Array<OneD, NekDouble> > outfield (addfields);
97  Array<OneD, Array<OneD, NekDouble> > outfield1(addfields);
98  Array<OneD, Array<OneD, NekDouble> > outfield2(addfields);
99  Array<OneD, Array<OneD, NekDouble> > outfield3(addfields);
100 
101  int nstrips;
102 
103  m_f->m_session->LoadParameter("Strip_Z",nstrips,1);
104 
105  m_f->m_exp.resize(nfields*nstrips);
106 
107  for (i = 0; i < nfields*nfields; ++i)
108  {
109  grad[i] = Array<OneD, NekDouble>(npoints);
110  }
111 
112  for (i = 0; i < addfields; ++i)
113  {
114  //Will store the Q-Criterion
115  outfield[i] = Array<OneD, NekDouble>(npoints);
116  outfield1[i] = Array<OneD, NekDouble>(npoints);
117  outfield2[i] = Array<OneD, NekDouble>(npoints);
118  outfield3[i] = Array<OneD, NekDouble>(npoints);
119 
120  omega[i] = Array<OneD, NekDouble>(npoints);
121  S[i] = Array<OneD, NekDouble>(npoints);
122  }
123 
124  vector<MultiRegions::ExpListSharedPtr> Exp(nstrips*addfields);
125 
126  for(s = 0; s < nstrips; ++s) //homogeneous strip varient
127  {
128  for (i = 0; i < nfields; ++i)
129  {
130  m_f->m_exp[s*nfields+i]->PhysDeriv(m_f->m_exp[s*nfields+i]->GetPhys(),
131  grad[i*nfields],
132  grad[i*nfields+1],
133  grad[i*nfields+2]);
134  }
135 
136  // W_x = Wy - Vz
137  Vmath::Vsub(npoints, grad[2 * nfields + 1], 1,
138  grad[1 * nfields + 2], 1,
139  outfield1[0], 1);
140  // W_x^2
141  Vmath::Vmul(npoints, outfield1[0], 1,
142  outfield1[0], 1,
143  outfield1[0], 1);
144 
145  // W_y = Uz - Wx
146  Vmath::Vsub(npoints, grad[0 * nfields + 2], 1,
147  grad[2 * nfields + 0], 1,
148  outfield2[0], 1);
149  // W_y^2
150  Vmath::Vmul(npoints, outfield2[0], 1,
151  outfield2[0], 1,
152  outfield2[0], 1);
153 
154  // W_z = Vx - Uy
155  Vmath::Vsub(npoints, grad[1 * nfields + 0], 1,
156  grad[0 * nfields + 1], 1,
157  outfield3[0], 1);
158  // W_z^2
159  Vmath::Vmul(npoints, outfield3[0], 1,
160  outfield3[0], 1,
161  outfield3[0], 1);
162 
163  // add fields omega = 0.5*(W_x^2 + W_y^2 + W_z^2)
164 
165  NekDouble fac = 0.5;
166  Vmath::Vadd(npoints, &outfield1[0][0], 1,
167  &outfield2[0][0], 1,
168  &omega[0][0], 1);
169  Vmath::Vadd(npoints, &omega[0][0], 1,
170  &outfield3[0][0], 1,
171  &omega[0][0], 1);
172 
173  for (int k = 0; k < addfields; ++k)
174  {
175  Vmath::Smul(npoints, fac, &omega[k][0], 1, &omega[k][0], 1);
176  }
177 
178  Vmath::Zero(npoints, &outfield1[0][0], 1);
179  Vmath::Zero(npoints, &outfield2[0][0], 1);
180  Vmath::Zero(npoints, &outfield3[0][0], 1);
181 
182  Vmath::Vmul(npoints, grad[0 * nfields + 0], 1,
183  grad[0 * nfields + 0], 1,
184  outfield1[0], 1);
185  Vmath::Vmul(npoints, grad[1 * nfields + 1], 1,
186  grad[1 * nfields + 1], 1,
187  outfield2[0], 1);
188  Vmath::Vmul(npoints, grad[2 * nfields + 2], 1,
189  grad[2 * nfields + 2], 1,
190  outfield3[0], 1);
191 
192  Vmath::Vadd(npoints, &outfield1[0][0], 1,
193  &outfield2[0][0], 1,
194  &S[0][0], 1);
195  Vmath::Vadd(npoints, &S[0][0], 1,
196  &outfield3[0][0], 1,
197  &S[0][0], 1);
198 
199  // W_y + V_z
200  Vmath::Vadd(npoints, grad[2 * nfields + 1], 1,
201  grad[1 * nfields + 2], 1,
202  outfield1[0], 1);
203  Vmath::Vmul(npoints, &outfield1[0][0], 1,
204  &outfield1[0][0], 1,
205  &outfield1[0][0], 1);
206 
207  // U_z + W_x
208  Vmath::Vadd(npoints, grad[0 * nfields + 2], 1,
209  grad[2 * nfields + 0], 1,
210  outfield2[0], 1);
211  Vmath::Vmul(npoints, &outfield2[0][0], 1,
212  &outfield2[0][0], 1,
213  &outfield2[0][0], 1);
214 
215  // V_x + U_y
216  Vmath::Vadd(npoints, grad[1 * nfields + 0], 1,
217  grad[0 * nfields + 1], 1,
218  outfield3[0], 1);
219  Vmath::Vmul(npoints, &outfield3[0][0], 1,
220  &outfield3[0][0], 1,
221  &outfield3[0][0], 1);
222 
223  Vmath::Vadd(npoints, &outfield1[0][0], 1,
224  &outfield2[0][0], 1,
225  &outfield2[0][0], 1);
226  Vmath::Vadd(npoints, &outfield2[0][0], 1,
227  &outfield3[0][0], 1,
228  &outfield3[0][0], 1);
229 
230  for (int k = 0; k < addfields; ++k)
231  {
232  Vmath::Smul(npoints, fac, &outfield3[k][0], 1,
233  &outfield3[k][0], 1);
234  }
235 
236  Vmath::Vadd(npoints, &outfield3[0][0], 1, &S[0][0], 1, &S[0][0], 1);
237  Vmath::Vsub(npoints, omega[0], 1, S[0], 1, outfield[0], 1);
238 
239  for (int k = 0; k < addfields; ++k)
240  {
241  Vmath::Smul(npoints, fac, &outfield[k][0], 1,
242  &outfield[k][0], 1);
243  }
244 
245 
246  for (i = 0; i < addfields; ++i)
247  {
248  int n = s*addfields + i;
249  Exp[n] = m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir);
250  Exp[n]->UpdatePhys() = outfield[i];
251  Exp[n]->FwdTrans(outfield[i],
252  Exp[n]->UpdateCoeffs());
253  }
254  }
255 
257 
258  for(s = 0; s < nstrips; ++s)
259  {
260  for(i = 0; i < addfields; ++i)
261  {
262  it = m_f->m_exp.begin()+s*(nfields+addfields)+nfields+i;
263  m_f->m_exp.insert(it, Exp[s*addfields+i]);
264  }
265  }
266 
267  vector<string> outname;
268  outname.push_back("Q");
269 
270  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
271  = m_f->m_exp[0]->GetFieldDefinitions();
272  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
273 
274  for(s = 0; s < nstrips; ++s) //homogeneous strip varient
275  {
276  for (j = 0; j < nfields + addfields; ++j)
277  {
278  for (i = 0; i < FieldDef.size()/nstrips; ++i)
279  {
280  int n = s * FieldDef.size()/nstrips + i;
281 
282  if (j >= nfields)
283  {
284  FieldDef[n]->m_fields.push_back(outname[j-nfields]);
285  }
286  else
287  {
288  FieldDef[n]->m_fields.push_back(
289  m_f->m_fielddef[0]->m_fields[j]);
290  }
291  m_f->m_exp[s*(nfields + addfields)+j]->AppendFieldData(FieldDef[n], FieldData[n]);
292  }
293  }
294  }
295 
296  m_f->m_fielddef = FieldDef;
297  m_f->m_data = FieldData;
298 }
299 
300 }
301 }
pair< ModuleType, string > ModuleKey
virtual void Process()=0
STL namespace.
FieldSharedPtr m_f
Field object.
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:199
double NekDouble
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:695
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:329
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:359
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:285
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:169
ModuleFactory & GetModuleFactory()
Abstract base class for processing modules.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215