Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProcessWSS.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessWSS.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 wss field.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <string>
37 #include <iostream>
38 using namespace std;
39 
40 #include "ProcessWSS.h"
41 
44 #include <MultiRegions/ExpList.h>
45 
46 namespace Nektar
47 {
48 namespace Utilities
49 {
50 
51 ModuleKey ProcessWSS::className =
53  ModuleKey(eProcessModule, "wss"),
54  ProcessWSS::create, "Computes wall shear stress field.");
55 
56 ProcessWSS::ProcessWSS(FieldSharedPtr f) : ProcessModule(f)
57 {
58  m_config["bnd"] = ConfigOption(false,"All","Boundary to be extracted");
59  m_config["addnormals"] = ConfigOption(true,"NotSet","Add normals to output");
60  f->m_writeBndFld = true;
61  f->m_declareExpansionAsContField = true;
62  m_f->m_fldToBnd = false;
63 
64  f->m_declareAsNewField = true;
65 }
66 
68 {
69 }
70 
71 void ProcessWSS::Process(po::variables_map &vm)
72 {
73  if (m_f->m_verbose)
74  {
75  cout << "ProcessWSS: Calculating wall shear stress..." << endl;
76  }
77 
78  m_f->m_addNormals = m_config["addnormals"].m_beenSet;
79 
80  // Set up Field options to output boundary fld
81  string bvalues = m_config["bnd"].as<string>();
82 
83  if(bvalues.compare("All") == 0)
84  {
86  BndExp = m_f->m_exp[0]->GetBndCondExpansions();
87 
88  for(int i = 0; i < BndExp.num_elements(); ++i)
89  {
90  m_f->m_bndRegionsToWrite.push_back(i);
91  }
92  }
93  else
94  {
96  m_f->m_bndRegionsToWrite),"Failed to interpret range string");
97  }
98 
99  NekDouble kinvis = m_f->m_session->GetParameter("Kinvis");
100 
101  int i, j;
102  int spacedim = m_f->m_graph->GetSpaceDimension();
103  if ((m_f->m_fielddef[0]->m_numHomogeneousDir) == 1 ||
104  (m_f->m_fielddef[0]->m_numHomogeneousDir) == 2)
105  {
106  spacedim += m_f->m_fielddef[0]->m_numHomogeneousDir;
107  }
108 
109  int nfields = m_f->m_fielddef[0]->m_fields.size();
110  ASSERTL0(m_f->m_fielddef[0]->m_fields[0] == "u","Implicit assumption that input is in incompressible format of (u,v,p) or (u,v,w,p)");
111 
112  if (spacedim == 1)
113  {
114  ASSERTL0(false, "Error: wss for a 1D problem cannot "
115  "be computed");
116  }
117 
118  int newfields = spacedim + 1;
119  int nshear = spacedim + 1;
120  int nstress = spacedim*spacedim;
121  int ngrad = spacedim*spacedim;
122 
123  Array<OneD, Array<OneD, NekDouble> > velocity(nfields), grad(ngrad), fgrad(ngrad);
124  Array<OneD, Array<OneD, NekDouble> > stress(nstress), fstress(nstress);
125  Array<OneD, Array<OneD, NekDouble> > fshear(nshear);
126 
129 
130  // Extract original fields to boundary (for output)
131  for (int i = 0; i < m_f->m_exp.size(); ++i)
132  {
133  m_f->m_exp[i]->FillBndCondFromField();
134  }
135 
136  m_f->m_exp.resize(nfields + newfields);
137  string var = "u";
138  for(i = 0; i < newfields; ++i)
139  {
140  m_f->m_exp[nfields + i] = m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir, var);
141  }
142 
143  if(spacedim == 2)
144  {
145  m_f->m_fielddef[0]->m_fields.push_back("Shear_x");
146  m_f->m_fielddef[0]->m_fields.push_back("Shear_y");
147  m_f->m_fielddef[0]->m_fields.push_back("Shear_mag");
148  }
149  else
150  {
151  m_f->m_fielddef[0]->m_fields.push_back("Shear_x");
152  m_f->m_fielddef[0]->m_fields.push_back("Shear_y");
153  m_f->m_fielddef[0]->m_fields.push_back("Shear_z");
154  m_f->m_fielddef[0]->m_fields.push_back("Shear_mag");
155  }
156 
157  // Loop over boundaries to Write
158  for(int b = 0; b < m_f->m_bndRegionsToWrite.size(); ++b)
159  {
160  int bnd = m_f->m_bndRegionsToWrite[b];
161  // Get expansion list for boundary and for elements containing this bnd
162  for(i = 0; i < newfields; i++)
163  {
164  BndExp[i] = m_f->m_exp[nfields + i]->UpdateBndCondExpansion(bnd);
165  }
166  for(i = 0; i < spacedim; i++)
167  {
168  m_f->m_exp[i]->GetBndElmtExpansion(bnd, BndElmtExp[i]);
169  }
170 
171  // Get number of points in expansions
172  int nqb = BndExp[0]->GetTotPoints();
173  int nqe = BndElmtExp[0]->GetTotPoints();
174 
175  // Initialise local arrays for the velocity gradients, and stress components
176  // size of total number of quadrature points for elements in this bnd
177  for(i = 0; i < ngrad; ++i)
178  {
179  grad[i] = Array<OneD, NekDouble>(nqe);
180  }
181 
182  for(i = 0; i < nstress; ++i)
183  {
184  stress[i] = Array<OneD, NekDouble>(nqe);
185  }
186 
187  // initialise arrays in the boundary
188  for(i = 0; i < nstress; ++i)
189  {
190  fstress[i] = Array<OneD, NekDouble>(nqb);
191  }
192 
193  for(i = 0; i < ngrad; ++i)
194  {
195  fgrad[i] = Array<OneD, NekDouble>(nqb);
196  }
197 
198  for(i = 0; i < nshear; ++i)
199  {
200  fshear[i] = Array<OneD, NekDouble>(nqb, 0.0);
201  }
202 
203  //Extract Velocities
204  for(i = 0; i < spacedim; ++i)
205  {
206  velocity[i] = BndElmtExp[i]->GetPhys();
207  }
208 
209  //Compute gradients (velocity correction scheme method)
210  for(i = 0; i < spacedim; ++i)
211  {
212  if (spacedim == 2)
213  {
214  BndElmtExp[i]->PhysDeriv(velocity[i],grad[i*spacedim+0],
215  grad[i*spacedim+1]);
216  }
217  else
218  {
219  BndElmtExp[i]->PhysDeriv(velocity[i],grad[i*spacedim+0],
220  grad[i*spacedim+1],
221  grad[i*spacedim+2]);
222  }
223  }
224 
225  //Compute stress component terms tau_ij = mu*(u_i,j + u_j,i)
226  for(i = 0; i < spacedim; ++i)
227  {
228  for(j = 0; j < spacedim; ++j)
229  {
230  Vmath::Vadd(nqe, grad[i*spacedim+j], 1,
231  grad[j*spacedim+i], 1,
232  stress[i*spacedim+j], 1);
233 
234  Vmath::Smul(nqe, kinvis, stress[i*spacedim+j], 1,
235  stress[i*spacedim+j], 1);
236  }
237  }
238 
239  // Get boundary stress values.
240  for(j = 0; j < nstress; ++j)
241  {
242  m_f->m_exp[0]->ExtractElmtToBndPhys(bnd, stress[j],fstress[j]);
243  }
244 
245  //Get normals
247  m_f->m_exp[0]->GetBoundaryNormals(bnd, normals);
248  // Reverse normals, to get correct orientation for the body
249  for(i = 0; i < spacedim; ++i)
250  {
251  Vmath::Neg(nqb, normals[i], 1);
252  }
253 
254  //calculate wss, and update coeffs in the boundary expansion
255  // S = tau_ij * n_j
256  for(i = 0; i < spacedim; ++i)
257  {
258  for(j = 0; j < spacedim; ++j)
259  {
260  Vmath::Vvtvp(nqb,normals[j],1,fstress[i*spacedim+j],1,
261  fshear[i],1,
262  fshear[i],1);
263  }
264  }
265 
266  // T = S - (S.n)n
267  for(i = 0; i < spacedim; ++i)
268  {
269  Vmath::Vvtvp(nqb,normals[i],1,fshear[i],1,
270  fshear[nshear-1],1,
271  fshear[nshear-1],1);
272  }
273  Vmath::Smul(nqb, -1.0, fshear[nshear-1], 1, fshear[nshear-1], 1);
274 
275  for (i = 0; i < spacedim; i++)
276  {
277  Vmath::Vvtvp(nqb,normals[i], 1, fshear[nshear-1], 1,
278  fshear[i], 1,
279  fshear[i], 1);
280  BndExp[i]->FwdTrans(fshear[i],
281  BndExp[i]->UpdateCoeffs());
282  }
283 
284  // Tw
285  Vmath::Zero(nqb, fshear[nshear-1], 1);
286  for(i = 0; i < spacedim; ++i)
287  {
288  Vmath::Vvtvp(nqb,fshear[i],1,fshear[i],1,
289  fshear[nshear-1],1,
290  fshear[nshear-1],1);
291  }
292  Vmath::Vsqrt(nqb, fshear[nshear-1], 1, fshear[nshear-1], 1);
293  BndExp[nshear-1]->FwdTrans(fshear[nshear-1],
294  BndExp[nshear-1]->UpdateCoeffs());
295  }
296 
297 }
298 
299 }
300 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
pair< ModuleType, string > ModuleKey
static bool GenerateOrderedVector(const char *const str, std::vector< unsigned int > &vec)
Definition: ParseUtils.hpp:97
void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
sqrt y = sqrt(x)
Definition: Vmath.cpp:394
virtual void Process()=0
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
Definition: Vmath.cpp:428
map< string, ConfigOption > m_config
List of configuration values.
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
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.cpp:382
double NekDouble
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:695
Represents a command-line configuration option.
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
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