Nektar++
ProcessVorticity.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessVorticity.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 vorticity field.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <iostream>
36 #include <string>
37 using namespace std;
38 
39 #include <boost/core/ignore_unused.hpp>
40 
41 #include <GlobalMapping/Mapping.h>
43 
44 #include "ProcessMapping.h"
45 #include "ProcessVorticity.h"
46 
47 namespace Nektar
48 {
49 namespace FieldUtils
50 {
51 
52 ModuleKey ProcessVorticity::className =
54  ModuleKey(eProcessModule, "vorticity"), ProcessVorticity::create,
55  "Computes vorticity field.");
56 
57 ProcessVorticity::ProcessVorticity(FieldSharedPtr f) : ProcessModule(f)
58 {
59 }
60 
62 {
63 }
64 
65 void ProcessVorticity::Process(po::variables_map &vm)
66 {
67  m_f->SetUpExp(vm);
68 
69  int i, s;
70  int expdim = m_f->m_graph->GetMeshDimension();
71  m_spacedim = expdim;
72  if ((m_f->m_numHomogeneousDir) == 1 || (m_f->m_numHomogeneousDir) == 2)
73  {
74  m_spacedim = 3;
75  }
76  int nfields = m_f->m_variables.size();
77  ASSERTL0(m_spacedim != 1,
78  "Error: Vorticity for a 1D problem cannot be computed");
79  int addfields = (m_spacedim == 2) ? 1 : 3;
80 
81  // Append field names
82  if (addfields == 1)
83  {
84  m_f->m_variables.push_back("W_z");
85  }
86  else
87  {
88  m_f->m_variables.push_back("W_x");
89  m_f->m_variables.push_back("W_y");
90  m_f->m_variables.push_back("W_z");
91  }
92 
93  // Skip in case of empty partition
94  if (m_f->m_exp[0]->GetNumElmts() == 0)
95  {
96  return;
97  }
98  int npoints = m_f->m_exp[0]->GetNpoints();
100  Array<OneD, Array<OneD, NekDouble>> outfield(addfields);
101 
102  int nstrips;
103 
104  m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
105 
106  for (i = 0; i < m_spacedim * m_spacedim; ++i)
107  {
108  grad[i] = Array<OneD, NekDouble>(npoints);
109  }
110 
111  for (i = 0; i < addfields; ++i)
112  {
113  outfield[i] = Array<OneD, NekDouble>(npoints);
114  }
115 
117  for (int i = 0; i < m_spacedim; i++)
118  {
119  tmp[i] = Array<OneD, NekDouble>(npoints);
120  }
121 
122  vector<MultiRegions::ExpListSharedPtr> Exp(nstrips * addfields);
123 
124  // Get mapping
126 
127  for (s = 0; s < nstrips; ++s) // homogeneous strip varient
128  {
129  // Get velocity and convert to Cartesian system,
130  // if it is still in transformed system
132  GetVelocity(vel, s);
133  if (m_f->m_fieldMetaDataMap.count("MappingCartesianVel"))
134  {
135  if (m_f->m_fieldMetaDataMap["MappingCartesianVel"] == "False")
136  {
137  // Initialize arrays and copy velocity
138  if (m_f->m_exp[0]->GetWaveSpace())
139  {
140  for (int i = 0; i < m_spacedim; ++i)
141  {
142  m_f->m_exp[0]->HomogeneousBwdTrans(vel[i], vel[i]);
143  }
144  }
145  // Convert velocity to cartesian system
146  mapping->ContravarToCartesian(vel, vel);
147  // Convert back to wavespace if necessary
148  if (m_f->m_exp[0]->GetWaveSpace())
149  {
150  for (int i = 0; i < m_spacedim; ++i)
151  {
152  m_f->m_exp[0]->HomogeneousFwdTrans(vel[i], vel[i]);
153  }
154  }
155  }
156  }
157 
158  // Calculate Gradient & Vorticity
159  if (m_spacedim == 2)
160  {
161  for (i = 0; i < m_spacedim; ++i)
162  {
163  m_f->m_exp[s * nfields + i]->PhysDeriv(vel[i], tmp[0], tmp[1]);
164  mapping->CovarToCartesian(tmp, tmp);
165  for (int j = 0; j < m_spacedim; j++)
166  {
167  Vmath::Vcopy(npoints, tmp[j], 1, grad[i * m_spacedim + j],
168  1);
169  }
170  }
171  // W_z = Vx - Uy
172  Vmath::Vsub(npoints, grad[1 * m_spacedim + 0], 1,
173  grad[0 * m_spacedim + 1], 1, outfield[0], 1);
174  }
175  else
176  {
177  for (i = 0; i < m_spacedim; ++i)
178  {
179  m_f->m_exp[s * nfields + i]->PhysDeriv(vel[i], tmp[0], tmp[1],
180  tmp[2]);
181  mapping->CovarToCartesian(tmp, tmp);
182  for (int j = 0; j < m_spacedim; j++)
183  {
184  Vmath::Vcopy(npoints, tmp[j], 1, grad[i * m_spacedim + j],
185  1);
186  }
187  }
188 
189  // W_x = Wy - Vz
190  Vmath::Vsub(npoints, grad[2 * m_spacedim + 1], 1,
191  grad[1 * m_spacedim + 2], 1, outfield[0], 1);
192  // W_y = Uz - Wx
193  Vmath::Vsub(npoints, grad[0 * m_spacedim + 2], 1,
194  grad[2 * m_spacedim + 0], 1, outfield[1], 1);
195  // W_z = Vx - Uy
196  Vmath::Vsub(npoints, grad[1 * m_spacedim + 0], 1,
197  grad[0 * m_spacedim + 1], 1, outfield[2], 1);
198  }
199 
200  for (i = 0; i < addfields; ++i)
201  {
202  int n = s * addfields + i;
203  Exp[n] = m_f->AppendExpList(m_f->m_numHomogeneousDir);
204  Vmath::Vcopy(npoints, outfield[i], 1, Exp[n]->UpdatePhys(), 1);
205  Exp[n]->FwdTransLocalElmt(outfield[i], Exp[n]->UpdateCoeffs());
206  }
207  }
208 
209  for (s = 0; s < nstrips; ++s)
210  {
211  for (i = 0; i < addfields; ++i)
212  {
213  m_f->m_exp.insert(m_f->m_exp.begin() + s * (nfields + addfields) +
214  nfields + i,
215  Exp[s * addfields + i]);
216  }
217  }
218 }
219 
221  int strip)
222 {
223  int nfields = m_f->m_variables.size();
224  int npoints = m_f->m_exp[0]->GetNpoints();
225  if (boost::iequals(m_f->m_variables[0], "u"))
226  {
227  // IncNavierStokesSolver
228  for (int i = 0; i < m_spacedim; ++i)
229  {
230  vel[i] = Array<OneD, NekDouble>(npoints);
231  Vmath::Vcopy(npoints, m_f->m_exp[strip * nfields + i]->GetPhys(), 1,
232  vel[i], 1);
233  }
234  }
235  else if (boost::iequals(m_f->m_variables[0], "rho") &&
236  boost::iequals(m_f->m_variables[1], "rhou"))
237  {
238  // CompressibleFlowSolver
239  for (int i = 0; i < m_spacedim; ++i)
240  {
241  vel[i] = Array<OneD, NekDouble>(npoints);
242  Vmath::Vdiv(npoints, m_f->m_exp[strip * nfields + i + 1]->GetPhys(),
243  1, m_f->m_exp[strip * nfields + 0]->GetPhys(), 1,
244  vel[i], 1);
245  }
246  }
247  else
248  {
249  // Unknown
250  ASSERTL0(false, "Could not identify velocity for ProcessVorticity");
251  }
252 }
253 
254 } // namespace FieldUtils
255 } // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
FieldSharedPtr m_f
Field object.
Definition: Module.h:225
static GlobalMapping::MappingSharedPtr GetMapping(FieldSharedPtr f)
Abstract base class for processing modules.
Definition: Module.h:260
virtual void Process(po::variables_map &vm)
Write mesh to output file.
void GetVelocity(Array< OneD, Array< OneD, NekDouble >> &vel, int strip=0)
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:989
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:285
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49
GLOBAL_MAPPING_EXPORT typedef std::shared_ptr< Mapping > MappingSharedPtr
A shared pointer to a Mapping object.
Definition: Mapping.h:50
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
void Vdiv(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:284
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1255
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:419