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 #include "ProcessMapping.h"
42 #include <GlobalMapping/Mapping.h>
43 
46 
47 namespace Nektar
48 {
49 namespace Utilities
50 {
51 
52 ModuleKey ProcessVorticity::className =
54  ModuleKey(eProcessModule, "vorticity"),
55  ProcessVorticity::create, "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  if (m_f->m_verbose)
68  {
69  cout << "ProcessVorticity: Calculating vorticity..." << endl;
70  }
71 
72  int i, j, s;
73  int expdim = m_f->m_graph->GetMeshDimension();
74  int spacedim = expdim;
75  if ((m_f->m_fielddef[0]->m_numHomogeneousDir) == 1 ||
76  (m_f->m_fielddef[0]->m_numHomogeneousDir) == 2)
77  {
78  spacedim = 3;
79  }
80  int nfields = m_f->m_fielddef[0]->m_fields.size();
81  if (spacedim == 1)
82  {
83  ASSERTL0(false, "Error: Vorticity for a 1D problem cannot "
84  "be computed")
85  }
86  int addfields = (spacedim == 2)? 1:3;
87 
88  int npoints = m_f->m_exp[0]->GetNpoints();
89  Array<OneD, Array<OneD, NekDouble> > grad(spacedim*spacedim);
90  Array<OneD, Array<OneD, NekDouble> > outfield(addfields);
91 
92  int nstrips;
93 
94  m_f->m_session->LoadParameter("Strip_Z",nstrips,1);
95 
96  m_f->m_exp.resize(nfields*nstrips);
97 
98  for (i = 0; i < spacedim*spacedim; ++i)
99  {
100  grad[i] = Array<OneD, NekDouble>(npoints);
101  }
102 
103  for (i = 0; i < addfields; ++i)
104  {
105  outfield[i] = Array<OneD, NekDouble>(npoints);
106  }
107 
108  Array<OneD, Array<OneD, NekDouble> > tmp(spacedim);
109  for( int i = 0; i<spacedim; i++)
110  {
111  tmp[i] = Array<OneD, NekDouble> (npoints);
112  }
113 
114  vector<MultiRegions::ExpListSharedPtr> Exp(nstrips*addfields);
115 
116  // Get mapping
119 
120  for(s = 0; s < nstrips; ++s) //homogeneous strip varient
121  {
122  // Get velocity and convert to Cartesian system,
123  // if it is still in transformed system
124  Array<OneD, Array<OneD, NekDouble> > vel (spacedim);
125  if (m_f->m_fieldMetaDataMap.count("MappingCartesianVel"))
126  {
127  if(m_f->m_fieldMetaDataMap["MappingCartesianVel"] == "False")
128  {
129  // Initialize arrays and copy velocity
130  for ( int i =0; i<spacedim; ++i )
131  {
132  vel[i] = Array<OneD, NekDouble> (npoints);
133  if (m_f->m_exp[0]->GetWaveSpace())
134  {
135  m_f->m_exp[0]->HomogeneousBwdTrans(
136  m_f->m_exp[s*nfields+i]->GetPhys(),
137  vel[i]);
138  }
139  else
140  {
141  Vmath::Vcopy(npoints, m_f->m_exp[s*nfields+i]->GetPhys(),1,
142  vel[i],1);
143  }
144 
145  }
146  // Convert velocity to cartesian system
147  mapping->ContravarToCartesian(vel, vel);
148  // Convert back to wavespace if necessary
149  if (m_f->m_exp[0]->GetWaveSpace())
150  {
151  for ( int i =0; i<spacedim; ++i )
152  {
153  m_f->m_exp[0]->HomogeneousFwdTrans(vel[i], vel[i]);
154  }
155  }
156  }
157  else
158  {
159  for ( int i =0; i<spacedim; ++i )
160  {
161  vel[i] = Array<OneD, NekDouble> (npoints);
162  Vmath::Vcopy(npoints, m_f->m_exp[s*nfields+i]->GetPhys(), 1,
163  vel[i], 1);
164  }
165  }
166  }
167  else
168  {
169  for ( int i =0; i<spacedim; ++i )
170  {
171  vel[i] = Array<OneD, NekDouble> (npoints);
172  Vmath::Vcopy(npoints, m_f->m_exp[s*nfields+i]->GetPhys(), 1,
173  vel[i], 1);
174  }
175  }
176 
177  // Calculate Gradient & Vorticity
178  if (spacedim == 2)
179  {
180  for (i = 0; i < spacedim; ++i)
181  {
182  m_f->m_exp[s*nfields+i]->PhysDeriv(vel[i],
183  tmp[0],
184  tmp[1]);
185  mapping->CovarToCartesian(tmp, tmp);
186  for( int j = 0; j<spacedim; j++)
187  {
188  Vmath::Vcopy(npoints, tmp[j], 1, grad[i*spacedim+j], 1 );
189  }
190  }
191  // W_z = Vx - Uy
192  Vmath::Vsub(npoints, grad[1*spacedim+0], 1,
193  grad[0*spacedim+1], 1,
194  outfield[0], 1);
195  }
196  else
197  {
198  for (i = 0; i < spacedim; ++i)
199  {
200  m_f->m_exp[s*nfields+i]->PhysDeriv(vel[i],
201  tmp[0],
202  tmp[1],
203  tmp[2]);
204  mapping->CovarToCartesian(tmp, tmp);
205  for( int j = 0; j<spacedim; j++)
206  {
207  Vmath::Vcopy(npoints, tmp[j], 1, grad[i*spacedim+j], 1 );
208  }
209  }
210 
211  // W_x = Wy - Vz
212  Vmath::Vsub(npoints, grad[2*spacedim+1], 1, grad[1*spacedim+2], 1,
213  outfield[0],1);
214  // W_y = Uz - Wx
215  Vmath::Vsub(npoints, grad[0*spacedim+2], 1, grad[2*spacedim+0], 1,
216  outfield[1], 1);
217  // W_z = Vx - Uy
218  Vmath::Vsub(npoints, grad[1*spacedim+0], 1, grad[0*spacedim+1], 1,
219  outfield[2], 1);
220  }
221 
222  for (i = 0; i < addfields; ++i)
223  {
224  int n = s*addfields + i;
225  Exp[n] = m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir);
226  Exp[n]->UpdatePhys() = outfield[i];
227  Exp[n]->FwdTrans_IterPerExp(outfield[i],
228  Exp[n]->UpdateCoeffs());
229  }
230  }
231 
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  if (addfields == 1)
244  {
245  outname.push_back("W_z");
246  }
247  else
248  {
249  outname.push_back("W_x");
250  outname.push_back("W_y");
251  outname.push_back("W_z");
252  }
253 
254  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
255  = m_f->m_exp[0]->GetFieldDefinitions();
256  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
257 
258  for(s = 0; s < nstrips; ++s) //homogeneous strip varient
259  {
260  for (j = 0; j < nfields + addfields; ++j)
261  {
262  for (i = 0; i < FieldDef.size()/nstrips; ++i)
263  {
264  int n = s * FieldDef.size()/nstrips + i;
265 
266  if (j >= nfields)
267  {
268  FieldDef[n]->m_fields.push_back(outname[j-nfields]);
269  }
270  else
271  {
272  FieldDef[n]->m_fields.push_back(m_f->m_fielddef[0]->m_fields[j]);
273  }
274  m_f->m_exp[s*(nfields + addfields)+j]->AppendFieldData(FieldDef[n], FieldData[n]);
275  }
276  }
277  }
278 
279  m_f->m_fielddef = FieldDef;
280  m_f->m_data = FieldData;
281 }
282 
283 }
284 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
pair< ModuleType, string > ModuleKey
virtual void Process()=0
STL namespace.
FieldSharedPtr m_f
Field object.
static GlobalMapping::MappingSharedPtr GetMapping(FieldSharedPtr f)
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:695
GLOBAL_MAPPING_EXPORT typedef boost::shared_ptr< Mapping > MappingSharedPtr
A shared pointer to a Mapping object.
Definition: Mapping.h:51
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 Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1047
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