Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // 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 vorticity field.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <string>
37 #include <iostream>
38 using namespace std;
39 
40 #include "ProcessVorticity.h"
41 
44 
45 namespace Nektar
46 {
47  namespace Utilities
48  {
49  ModuleKey ProcessVorticity::className =
51  ModuleKey(eProcessModule, "vorticity"),
52  ProcessVorticity::create, "Computes vorticity field.");
53 
54  ProcessVorticity::ProcessVorticity(FieldSharedPtr f) : ProcessModule(f)
55  {
56  }
57 
59  {
60  }
61 
62  void ProcessVorticity::Process(po::variables_map &vm)
63  {
64  if (m_f->m_verbose)
65  {
66  cout << "ProcessVorticity: Calculating vorticity..." << endl;
67  }
68 
69  int i, j;
70  int expdim = m_f->m_graph->GetMeshDimension();
71  int spacedim = expdim;
72  if ((m_f->m_fielddef[0]->m_numHomogeneousDir) == 1 ||
73  (m_f->m_fielddef[0]->m_numHomogeneousDir) == 2)
74  {
75  spacedim = 3;
76  }
77  int nfields = m_f->m_fielddef[0]->m_fields.size();
78  if (spacedim == 1)
79  {
80  ASSERTL0(false, "Error: Vorticity for a 1D problem cannot "
81  "be computed")
82  }
83  int addfields = (spacedim == 2)? 1:3;
84 
85  int npoints = m_f->m_exp[0]->GetNpoints();
86  Array<OneD, Array<OneD, NekDouble> > grad(nfields*nfields);
87  Array<OneD, Array<OneD, NekDouble> > outfield(addfields);
88  m_f->m_exp.resize(nfields+addfields);
89 
90 
91  for (i = 0; i < nfields*nfields; ++i)
92  {
93  grad[i] = Array<OneD, NekDouble>(npoints);
94  }
95 
96  for (i = 0; i < addfields; ++i)
97  {
98  outfield[i] = Array<OneD, NekDouble>(npoints);
99  }
100 
101  // Calculate Gradient & Vorticity
102  if (spacedim == 2)
103  {
104  for (i = 0; i < nfields; ++i)
105  {
106  m_f->m_exp[i]->PhysDeriv(m_f->m_exp[i]->GetPhys(),
107  grad[i*nfields],
108  grad[i*nfields+1]);
109  }
110  // W_z = Vx - Uy
111  Vmath::Vsub(npoints, grad[1*nfields+0], 1,
112  grad[0*nfields+1], 1,
113  outfield[0], 1);
114  }
115  else
116  {
117  for (i = 0; i < nfields; ++i)
118  {
119 
120  m_f->m_exp[i]->PhysDeriv(m_f->m_exp[i]->GetPhys(),
121  grad[i*nfields],
122  grad[i*nfields+1],
123  grad[i*nfields+2]);
124  }
125 
126  // W_x = Wy - Vz
127  Vmath::Vsub(npoints, grad[2*nfields+1], 1, grad[1*nfields+2], 1,
128  outfield[0],1);
129  // W_y = Uz - Wx
130  Vmath::Vsub(npoints, grad[0*nfields+2], 1, grad[2*nfields+0], 1,
131  outfield[1], 1);
132  // W_z = Vx - Uy
133  Vmath::Vsub(npoints, grad[1*nfields+0], 1, grad[0*nfields+1], 1,
134  outfield[2], 1);
135  }
136 
137  for (i = 0; i < addfields; ++i)
138  {
139  m_f->m_exp[nfields + i] = m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir);
140  m_f->m_exp[nfields + i]->UpdatePhys() = outfield[i];
141  m_f->m_exp[nfields + i]->FwdTrans_IterPerExp(outfield[i],
142  m_f->m_exp[nfields + i]->UpdateCoeffs());
143  }
144 
145  vector<string > outname;
146  if (addfields == 1)
147  {
148  outname.push_back("W_z");
149  }
150  else
151  {
152  outname.push_back("W_x");
153  outname.push_back("W_y");
154  outname.push_back("W_z");
155  }
156 
157  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
158  = m_f->m_exp[0]->GetFieldDefinitions();
159  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
160 
161  for (j = 0; j < nfields + addfields; ++j)
162  {
163  for (i = 0; i < FieldDef.size(); ++i)
164  {
165  if (j >= nfields)
166  {
167  FieldDef[i]->m_fields.push_back(outname[j-nfields]);
168  }
169  else
170  {
171  FieldDef[i]->m_fields.push_back(m_f->m_fielddef[0]->m_fields[j]);
172  }
173  m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
174  }
175  }
176 
177  m_f->m_fielddef = FieldDef;
178  m_f->m_data = FieldData;
179 
180 
181  }
182  }
183 }