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 
66 {
67 }
68 
69 void ProcessWSS::Process(po::variables_map &vm)
70 {
71  if (m_f->m_verbose)
72  {
73  if(m_f->m_comm->GetRank() == 0)
74  {
75  cout << "ProcessWSS: Calculating wall shear stress..." << endl;
76  }
77  }
78 
79  m_f->m_addNormals = m_config["addnormals"].m_beenSet;
80 
81  // Set up Field options to output boundary fld
82  string bvalues = m_config["bnd"].as<string>();
83 
84  if(bvalues.compare("All") == 0)
85  {
87  BndExp = m_f->m_exp[0]->GetBndCondExpansions();
88 
89  for(int i = 0; i < BndExp.num_elements(); ++i)
90  {
91  m_f->m_bndRegionsToWrite.push_back(i);
92  }
93  }
94  else
95  {
97  m_f->m_bndRegionsToWrite),"Failed to interpret range string");
98  }
99 
100  NekDouble kinvis = m_f->m_session->GetParameter("Kinvis");
101 
102  int i, j;
103  int spacedim = m_f->m_graph->GetSpaceDimension();
104  if ((m_f->m_fielddef[0]->m_numHomogeneousDir) == 1 ||
105  (m_f->m_fielddef[0]->m_numHomogeneousDir) == 2)
106  {
107  spacedim += m_f->m_fielddef[0]->m_numHomogeneousDir;
108  }
109 
110  int nfields = m_f->m_fielddef[0]->m_fields.size();
111  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)");
112 
113  if (spacedim == 1)
114  {
115  ASSERTL0(false, "Error: wss for a 1D problem cannot "
116  "be computed");
117  }
118 
119  int newfields = spacedim + 1;
120  int nshear = spacedim + 1;
121  int nstress = spacedim*spacedim;
122  int ngrad = spacedim*spacedim;
123 
124  Array<OneD, Array<OneD, NekDouble> > velocity(nfields), grad(ngrad), fgrad(ngrad);
125  Array<OneD, Array<OneD, NekDouble> > stress(nstress), fstress(nstress);
126  Array<OneD, Array<OneD, NekDouble> > fshear(nshear);
127 
129  Array<OneD, MultiRegions::ExpListSharedPtr> BndElmtExp(spacedim);
130 
131  // Extract original fields to boundary (for output)
132  for (int i = 0; i < m_f->m_exp.size(); ++i)
133  {
134  m_f->m_exp[i]->FillBndCondFromField();
135  }
136 
137  m_f->m_exp.resize(nfields + newfields);
138  string var = "u";
139  for(i = 0; i < newfields; ++i)
140  {
141  m_f->m_exp[nfields + i] = m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir, var);
142  }
143 
144  if(spacedim == 2)
145  {
146  m_f->m_fielddef[0]->m_fields.push_back("Shear_x");
147  m_f->m_fielddef[0]->m_fields.push_back("Shear_y");
148  m_f->m_fielddef[0]->m_fields.push_back("Shear_mag");
149  }
150  else
151  {
152  m_f->m_fielddef[0]->m_fields.push_back("Shear_x");
153  m_f->m_fielddef[0]->m_fields.push_back("Shear_y");
154  m_f->m_fielddef[0]->m_fields.push_back("Shear_z");
155  m_f->m_fielddef[0]->m_fields.push_back("Shear_mag");
156  }
157 
158  // Create map of boundary ids for partitioned domains
160  m_f->m_exp[0]->GetGraph());
162  bcs.GetBoundaryRegions();
163  SpatialDomains::BoundaryRegionCollection::const_iterator breg_it;
164  map<int,int> BndRegionMap;
165  int cnt =0;
166  for(breg_it = bregions.begin(); breg_it != bregions.end();
167  ++breg_it, ++cnt)
168  {
169  BndRegionMap[breg_it->first] = cnt;
170  }
171  // Loop over boundaries to Write
172  for(int b = 0; b < m_f->m_bndRegionsToWrite.size(); ++b)
173  {
174  if(BndRegionMap.count(m_f->m_bndRegionsToWrite[b]) == 1)
175  {
176  int bnd = BndRegionMap[m_f->m_bndRegionsToWrite[b]];
177  // Get expansion list for boundary and for elements containing this bnd
178  for(i = 0; i < newfields; i++)
179  {
180  BndExp[i] = m_f->m_exp[nfields + i]->UpdateBndCondExpansion(bnd);
181  }
182  for(i = 0; i < spacedim; i++)
183  {
184  m_f->m_exp[i]->GetBndElmtExpansion(bnd, BndElmtExp[i]);
185  }
186 
187  // Get number of points in expansions
188  int nqb = BndExp[0]->GetTotPoints();
189  int nqe = BndElmtExp[0]->GetTotPoints();
190 
191  // Initialise local arrays for the velocity gradients, and stress components
192  // size of total number of quadrature points for elements in this bnd
193  for(i = 0; i < ngrad; ++i)
194  {
195  grad[i] = Array<OneD, NekDouble>(nqe);
196  }
197 
198  for(i = 0; i < nstress; ++i)
199  {
200  stress[i] = Array<OneD, NekDouble>(nqe);
201  }
202 
203  // initialise arrays in the boundary
204  for(i = 0; i < nstress; ++i)
205  {
206  fstress[i] = Array<OneD, NekDouble>(nqb);
207  }
208 
209  for(i = 0; i < ngrad; ++i)
210  {
211  fgrad[i] = Array<OneD, NekDouble>(nqb);
212  }
213 
214  for(i = 0; i < nshear; ++i)
215  {
216  fshear[i] = Array<OneD, NekDouble>(nqb, 0.0);
217  }
218 
219  //Extract Velocities
220  for(i = 0; i < spacedim; ++i)
221  {
222  velocity[i] = BndElmtExp[i]->GetPhys();
223  }
224 
225  //Compute gradients (velocity correction scheme method)
226  for(i = 0; i < spacedim; ++i)
227  {
228  if (spacedim == 2)
229  {
230  BndElmtExp[i]->PhysDeriv(velocity[i],grad[i*spacedim+0],
231  grad[i*spacedim+1]);
232  }
233  else
234  {
235  BndElmtExp[i]->PhysDeriv(velocity[i],grad[i*spacedim+0],
236  grad[i*spacedim+1],
237  grad[i*spacedim+2]);
238  }
239  }
240 
241  //Compute stress component terms tau_ij = mu*(u_i,j + u_j,i)
242  for(i = 0; i < spacedim; ++i)
243  {
244  for(j = 0; j < spacedim; ++j)
245  {
246  Vmath::Vadd(nqe, grad[i*spacedim+j], 1,
247  grad[j*spacedim+i], 1,
248  stress[i*spacedim+j], 1);
249 
250  Vmath::Smul(nqe, kinvis, stress[i*spacedim+j], 1,
251  stress[i*spacedim+j], 1);
252  }
253  }
254 
255  // Get boundary stress values.
256  for(j = 0; j < nstress; ++j)
257  {
258  m_f->m_exp[0]->ExtractElmtToBndPhys(bnd, stress[j],fstress[j]);
259  }
260 
261  //Get normals
263  m_f->m_exp[0]->GetBoundaryNormals(bnd, normals);
264  // Reverse normals, to get correct orientation for the body
265  for(i = 0; i < spacedim; ++i)
266  {
267  Vmath::Neg(nqb, normals[i], 1);
268  }
269 
270  //calculate wss, and update coeffs in the boundary expansion
271  // S = tau_ij * n_j
272  for(i = 0; i < spacedim; ++i)
273  {
274  for(j = 0; j < spacedim; ++j)
275  {
276  Vmath::Vvtvp(nqb,normals[j],1,fstress[i*spacedim+j],1,
277  fshear[i],1,
278  fshear[i],1);
279  }
280  }
281 
282  // T = S - (S.n)n
283  for(i = 0; i < spacedim; ++i)
284  {
285  Vmath::Vvtvp(nqb,normals[i],1,fshear[i],1,
286  fshear[nshear-1],1,
287  fshear[nshear-1],1);
288  }
289  Vmath::Smul(nqb, -1.0, fshear[nshear-1], 1, fshear[nshear-1], 1);
290 
291  for (i = 0; i < spacedim; i++)
292  {
293  Vmath::Vvtvp(nqb,normals[i], 1, fshear[nshear-1], 1,
294  fshear[i], 1,
295  fshear[i], 1);
296  BndExp[i]->FwdTrans(fshear[i],
297  BndExp[i]->UpdateCoeffs());
298  }
299 
300  // Tw
301  Vmath::Zero(nqb, fshear[nshear-1], 1);
302  for(i = 0; i < spacedim; ++i)
303  {
304  Vmath::Vvtvp(nqb,fshear[i],1,fshear[i],1,
305  fshear[nshear-1],1,
306  fshear[nshear-1],1);
307  }
308  Vmath::Vsqrt(nqb, fshear[nshear-1], 1, fshear[nshear-1], 1);
309  BndExp[nshear-1]->FwdTrans(fshear[nshear-1],
310  BndExp[nshear-1]->UpdateCoeffs());
311  }
312  }
313 }
314 
315 }
316 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
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
map< string, ConfigOption > m_config
List of configuration values.
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
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
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
Definition: Conditions.h:206
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.
const BoundaryRegionCollection & GetBoundaryRegions(void) const
Definition: Conditions.h:227
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