Nektar++
ProcessMultiShear.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessMultiShear.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 tawss, osi, transwss, afi, cfi fields.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <iostream>
36 #include <sstream>
37 #include <string>
38 using namespace std;
39 
40 #include <boost/core/ignore_unused.hpp>
41 
43 #include <MultiRegions/ExpList.h>
44 
45 #include "ProcessMultiShear.h"
46 
47 namespace Nektar
48 {
49 namespace FieldUtils
50 {
51 
52 ModuleKey ProcessMultiShear::className =
54  ModuleKey(eProcessModule, "shear"),
55  ProcessMultiShear::create,
56  "Computes shear stress metrics.");
57 
58 ProcessMultiShear::ProcessMultiShear(FieldSharedPtr f) : ProcessModule(f)
59 {
60  m_config["N"] = ConfigOption(false, "1", "Number of chk or fld files");
61  m_config["fromfld"] = ConfigOption(
62  false, "NotSet",
63  "First fld file. First underscore flags position of id in name.");
64 }
65 
67 {
68 }
69 
70 void ProcessMultiShear::Process(po::variables_map &vm)
71 {
72  m_f->SetUpExp(vm);
73 
74  // Skip in case of empty partition
75  if (m_f->m_exp[0]->GetNumElmts() == 0)
76  {
77  return;
78  }
79 
80  ASSERTL0(m_config["fromfld"].as<string>().compare("NotSet") != 0,
81  "Need to specify fromfld=file.fld ");
82 
83  int nstart, i, j, nfields=0;
84  bool wssg = false;
85  NekDouble nfld = m_config["N"].as<NekDouble>();
86  string fromfld, basename, endname, nstartStr;
87  stringstream filename;
88  vector<string> infiles(nfld);
89  vector<std::shared_ptr<Field> > fromField(nfld);
90 
91  // Set up list of input fld files.
92  fromfld = m_config["fromfld"].as<string>();
93  basename = fromfld.substr(0, fromfld.find_first_of("_") + 1);
94  filename << fromfld.substr(fromfld.find_first_of("_") + 1, fromfld.size());
95  filename >> nstart;
96  filename.str("");
97  filename << nstart;
98  filename >> nstartStr;
99  filename.str("");
100  endname = fromfld.substr(fromfld.find(nstartStr) + nstartStr.size(),
101  fromfld.size());
102 
103  for (i = 0; i < nfld; ++i)
104  {
105  stringstream filename;
106  filename << basename << i + nstart << endname;
107  filename >> infiles[i];
108  cout << infiles[i] << endl;
109  }
110 
111  for (i = 0; i < nfld; ++i)
112  {
113  fromField[i] = std::shared_ptr<Field>(new Field());
114  fromField[i]->m_session = m_f->m_session;
115  fromField[i]->m_graph = m_f->m_graph;
116  }
117 
118  // Import all fld files.
119  for (i = 0; i < nfld; ++i)
120  {
121  if (m_f->m_exp.size())
122  {
123  // Set up ElementGIDs in case of parallel processing
124  Array<OneD, int> ElementGIDs(m_f->m_exp[0]->GetExpSize());
125  for (j = 0; j < m_f->m_exp[0]->GetExpSize(); ++j)
126  {
127  ElementGIDs[j] =
128  m_f->m_exp[0]->GetExp(j)->GetGeom()->GetGlobalID();
129  }
130  m_f->FieldIOForFile(infiles[i])->Import(
131  infiles[i], fromField[i]->m_fielddef, fromField[i]->m_data,
133  }
134  else
135  {
136  m_f->FieldIOForFile(infiles[i])->Import(
137  infiles[i], fromField[i]->m_fielddef, fromField[i]->m_data,
139  }
140 
141  nfields = fromField[i]->m_fielddef[0]->m_fields.size();
142  int NumHomogeneousDir =
143  fromField[i]->m_fielddef[0]->m_numHomogeneousDir;
144 
145  if (nfields == 5 || nfields == 7)
146  {
147  wssg = true;
148  }
149 
150  // Set up Expansion information to use mode order from field
151  fromField[i]->m_graph->SetExpansionInfo(fromField[i]->m_fielddef);
152 
153  // Set up expansions, and extract data.
154  fromField[i]->m_exp.resize(nfields);
155  fromField[i]->m_exp[0] =
156  fromField[i]->SetUpFirstExpList(NumHomogeneousDir, true);
157 
158  for (j = 1; j < nfields; ++j)
159  {
160  fromField[i]->m_exp[j] = m_f->AppendExpList(NumHomogeneousDir);
161  }
162 
163  for (j = 0; j < nfields; ++j)
164  {
165  for (int k = 0; k < fromField[i]->m_data.size(); ++k)
166  {
167  fromField[i]->m_exp[j]->ExtractDataToCoeffs(
168  fromField[i]->m_fielddef[k], fromField[i]->m_data[k],
169  fromField[i]->m_fielddef[k]->m_fields[j],
170  fromField[i]->m_exp[j]->UpdateCoeffs());
171  }
172  fromField[i]->m_exp[j]->BwdTrans(
173  fromField[i]->m_exp[j]->GetCoeffs(),
174  fromField[i]->m_exp[j]->UpdatePhys());
175  }
176  }
177 
178  int spacedim = m_f->m_graph->GetSpaceDimension();
179  if ((fromField[0]->m_fielddef[0]->m_numHomogeneousDir) == 1 ||
180  (fromField[0]->m_fielddef[0]->m_numHomogeneousDir) == 2)
181  {
182  spacedim = 3;
183  }
184 
185  int nout = 5; // TAWSS, OSI, transWSS, AFI, CFI (optional WSSG)
186  if (wssg)
187  {
188  nout = 6;
189  }
190 
191  int npoints = fromField[0]->m_exp[0]->GetNpoints();
192  Array<OneD, Array<OneD, NekDouble> > normTemporalMeanVec(spacedim),
193  normCrossDir(spacedim), outfield(nout), dtemp(spacedim);
194  Array<OneD, NekDouble> TemporalMeanMag(npoints, 0.0),
195  DotProduct(npoints, 0.0), temp(npoints, 0.0);
196 
197  for (i = 0; i < spacedim; ++i)
198  {
199  normTemporalMeanVec[i] = Array<OneD, NekDouble>(npoints);
200  normCrossDir[i] = Array<OneD, NekDouble>(npoints);
201  dtemp[i] = Array<OneD, NekDouble>(npoints);
202  Vmath::Zero(npoints, normTemporalMeanVec[i], 1);
203  Vmath::Zero(npoints, normCrossDir[i], 1);
204  }
205 
206  for (i = 0; i < nout; ++i)
207  {
208  outfield[i] = Array<OneD, NekDouble>(npoints, 0.0);
209  }
210 
211  // -----------------------------------------------------
212  // Compute temporal average wall shear stress vector,
213  // it's spatial average, and normalise it.
214  for (i = 0; i < nfld; ++i)
215  {
216  for (j = 0; j < spacedim; ++j)
217  {
218  Vmath::Vadd(npoints, fromField[i]->m_exp[j]->GetPhys(), 1,
219  normTemporalMeanVec[j], 1, normTemporalMeanVec[j], 1);
220  }
221  }
222 
223  for (i = 0; i < spacedim; ++i)
224  {
225  Vmath::Smul(npoints, 1.0 / nfld, normTemporalMeanVec[i], 1,
226  normTemporalMeanVec[i], 1);
227  Vmath::Vvtvp(npoints, normTemporalMeanVec[i], 1, normTemporalMeanVec[i],
228  1, TemporalMeanMag, 1, TemporalMeanMag, 1);
229  }
230 
231  Vmath::Vsqrt(npoints, TemporalMeanMag, 1, TemporalMeanMag, 1);
232 
233  for (i = 0; i < spacedim; ++i)
234  {
235  Vmath::Vdiv(npoints, normTemporalMeanVec[i], 1, TemporalMeanMag, 1,
236  normTemporalMeanVec[i], 1);
237  }
238  //---------------------------------------------------
239 
240  if (wssg) // cross product with normals to obtain direction parallel to
241  // temporal mean vector.
242  {
243  Vmath::Vmul(npoints, fromField[0]->m_exp[nfields - 1]->GetPhys(), 1,
244  normTemporalMeanVec[1], 1, normCrossDir[0], 1);
245  Vmath::Vvtvm(npoints, fromField[0]->m_exp[nfields - 2]->GetPhys(), 1,
246  normTemporalMeanVec[2], 1, normCrossDir[0], 1,
247  normCrossDir[0], 1);
248 
249  Vmath::Vmul(npoints, fromField[0]->m_exp[nfields - 3]->GetPhys(), 1,
250  normTemporalMeanVec[2], 1, normCrossDir[1], 1);
251  Vmath::Vvtvm(npoints, fromField[0]->m_exp[nfields - 1]->GetPhys(), 1,
252  normTemporalMeanVec[0], 1, normCrossDir[1], 1,
253  normCrossDir[1], 1);
254 
255  Vmath::Vmul(npoints, fromField[0]->m_exp[nfields - 2]->GetPhys(), 1,
256  normTemporalMeanVec[0], 1, normCrossDir[2], 1);
257  Vmath::Vvtvm(npoints, fromField[0]->m_exp[nfields - 3]->GetPhys(), 1,
258  normTemporalMeanVec[1], 1, normCrossDir[2], 1,
259  normCrossDir[2], 1);
260  }
261 
262  // Compute tawss, trs, osi, taafi, tacfi, WSSG.
263  for (i = 0; i < nfld; ++i)
264  {
265  for (j = 0; j < spacedim; ++j)
266  {
267  Vmath::Vvtvp(npoints, fromField[i]->m_exp[j]->GetPhys(), 1,
268  normTemporalMeanVec[j], 1, DotProduct, 1, DotProduct,
269  1);
270  }
271 
272  // TAWSS
273  Vmath::Vadd(npoints, fromField[i]->m_exp[spacedim]->GetPhys(), 1,
274  outfield[0], 1, outfield[0], 1);
275 
276  // transWSS
277  Vmath::Vmul(npoints, DotProduct, 1, DotProduct, 1, temp, 1);
278  Vmath::Vvtvm(npoints, fromField[i]->m_exp[spacedim]->GetPhys(), 1,
279  fromField[i]->m_exp[spacedim]->GetPhys(), 1, temp, 1,
280  temp, 1);
281 
282  for (j = 0; j < npoints; ++j)
283  {
284  if (temp[j] > 0.0)
285  {
286  outfield[1][j] = outfield[1][j] + sqrt(temp[j]);
287  }
288  }
289 
290  // TAAFI
291  Vmath::Vdiv(npoints, DotProduct, 1,
292  fromField[i]->m_exp[spacedim]->GetPhys(), 1, temp, 1);
293  Vmath::Vadd(npoints, temp, 1, outfield[3], 1, outfield[3], 1);
294 
295  // TACFI
296  for (j = 0; j < npoints; ++j)
297  {
298  temp[j] = 1 - temp[j] * temp[j];
299  if (temp[j] > 0.0)
300  {
301  outfield[4][j] = outfield[4][j] + sqrt(temp[j]);
302  }
303  }
304 
305  // WSSG
306  if (wssg)
307  {
308  // parallel component:
309  Vmath::Zero(npoints, temp, 1);
310 
311  fromField[i]->m_exp[0]->PhysDeriv(DotProduct, dtemp[0], dtemp[1],
312  dtemp[2]);
313  for (j = 0; j < spacedim; j++)
314  {
315  Vmath::Vvtvp(npoints, dtemp[j], 1, normTemporalMeanVec[j], 1,
316  temp, 1, temp, 1);
317  }
318  Vmath::Vmul(npoints, temp, 1, temp, 1, temp, 1);
319 
320  // perpendicular component:
321  Vmath::Zero(npoints, DotProduct, 1);
322 
323  for (j = 0; j < spacedim; ++j)
324  {
325  Vmath::Vvtvp(npoints, fromField[i]->m_exp[j]->GetPhys(), 1,
326  normCrossDir[j], 1, DotProduct, 1, DotProduct, 1);
327  }
328  fromField[i]->m_exp[0]->PhysDeriv(DotProduct, dtemp[0], dtemp[1],
329  dtemp[2]);
330  Vmath::Zero(npoints, DotProduct, 1);
331 
332  for (j = 0; j < spacedim; j++)
333  {
334  Vmath::Vvtvp(npoints, dtemp[j], 1, normCrossDir[j], 1,
335  DotProduct, 1, DotProduct, 1);
336  }
337  Vmath::Vvtvp(npoints, DotProduct, 1, DotProduct, 1, temp, 1, temp,
338  1);
339 
340  // Final wssg computation
341  Vmath::Vsqrt(npoints, temp, 1, temp, 1);
342  Vmath::Vadd(npoints, temp, 1, outfield[5], 1, outfield[5], 1);
343  }
344 
345  Vmath::Zero(npoints, DotProduct, 1);
346  }
347 
348  // Divide by nfld
349  Vmath::Smul(npoints, 1.0 / nfld, outfield[0], 1, outfield[0], 1);
350  Vmath::Smul(npoints, 1.0 / nfld, outfield[1], 1, outfield[1], 1);
351  Vmath::Smul(npoints, 1.0 / nfld, outfield[3], 1, outfield[3], 1);
352  Vmath::Smul(npoints, 1.0 / nfld, outfield[4], 1, outfield[4], 1);
353 
354  // OSI
355  for (i = 0; i < npoints; ++i)
356  {
357  outfield[2][i] = 0.5 * (1 - TemporalMeanMag[i] / outfield[0][i]);
358  }
359 
360  /* TAWSS = sum(wss)/nfld
361  * transWSS = sum( sqrt( wss^2 - (wss . normTempMean)^2) )/nfld.
362  * OSI = 0.5*(1-TemporalMeanMag/TAWSS)
363  * TAAFI = sum(cos)/nfld
364  * TACFI = sum(sin)/nfld = sum( sqrt(1-cos^2) )/nfld.
365  */
366 
367  m_f->m_exp.resize(nout);
368  m_f->m_fielddef = fromField[0]->m_fielddef;
369  m_f->m_exp[0] =
370  m_f->SetUpFirstExpList(m_f->m_fielddef[0]->m_numHomogeneousDir, true);
371 
372  for (i = 1; i < nout; ++i)
373  {
374  m_f->m_exp[i] =
375  m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir);
376  }
377 
378  m_f->m_fielddef[0]->m_fields.resize(nout);
379  m_f->m_fielddef[0]->m_fields[0] = "TAWSS";
380  m_f->m_fielddef[0]->m_fields[1] = "transWSS";
381  m_f->m_fielddef[0]->m_fields[2] = "OSI";
382  m_f->m_fielddef[0]->m_fields[3] = "TAAFI";
383  m_f->m_fielddef[0]->m_fields[4] = "TACFI";
384 
385  if (wssg)
386  {
387  m_f->m_fielddef[0]->m_fields[5] = "|WSSG|";
388  Vmath::Smul(npoints, 1.0 / nfld, outfield[5], 1, outfield[5], 1);
389  }
390 
391  m_f->m_variables = m_f->m_fielddef[0]->m_fields;
392 
393  for (i = 0; i < nout; ++i)
394  {
395  m_f->m_exp[i]->FwdTrans(outfield[i], m_f->m_exp[i]->UpdateCoeffs());
396  m_f->m_exp[i]->BwdTrans(m_f->m_exp[i]->GetCoeffs(),
397  m_f->m_exp[i]->UpdatePhys());
398  }
399 }
400 }
401 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
FieldSharedPtr m_f
Field object.
Definition: Module.h:230
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:233
Abstract base class for processing modules.
Definition: Module.h:265
virtual void Process(po::variables_map &vm)
Write mesh to output file.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:989
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:290
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49
static FieldMetaDataMap NullFieldMetaDataMap
Definition: FieldIO.h:53
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
double NekDouble
void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
sqrt y = sqrt(x)
Definition: Vmath.cpp:475
void Vmul(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:192
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:513
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:322
void Vvtvm(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)
vvtvm (vector times vector plus vector): z = w*x - y
Definition: Vmath.cpp:541
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition: Vmath.cpp:225
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:257
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:436
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:267
Represents a command-line configuration option.
Definition: Module.h:134