Nektar++
Extrapolate.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Extrapolate.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: Abstract base class for Extrapolate.
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
37 
38 using namespace std;
39 
40 namespace Nektar
41 {
42 NekDouble Extrapolate::StifflyStable_Betaq_Coeffs[3][3] = {
43  {1.0, 0.0, 0.0}, {2.0, -1.0, 0.0}, {3.0, -3.0, 1.0}};
44 NekDouble Extrapolate::StifflyStable_Alpha_Coeffs[3][3] = {
45  {1.0, 0.0, 0.0}, {2.0, -0.5, 0.0}, {3.0, -1.5, 1.0 / 3.0}};
46 NekDouble Extrapolate::StifflyStable_Gamma0_Coeffs[3] = {1.0, 1.5, 11.0 / 6.0};
47 
49 {
50  static ExtrapolateFactory instance;
51  return instance;
52 }
53 
54 Extrapolate::Extrapolate(const LibUtilities::SessionReaderSharedPtr pSession,
57  const Array<OneD, int> pVel,
58  const SolverUtils::AdvectionSharedPtr advObject)
59  : m_session(pSession), m_fields(pFields), m_pressure(pPressure),
60  m_velocity(pVel), m_advObject(advObject)
61 {
62  m_session->LoadParameter("TimeStep", m_timestep, 0.01);
63  m_comm = m_session->GetComm();
64 }
65 
67 {
68 }
69 
70 std::string Extrapolate::def =
72  "StandardExtrapolate", "StandardExtrapolate");
73 
74 /**
75  *
76  */
78 {
79  if (m_numHBCDof)
80  {
81  // Update velocity BF at n+1 (actually only needs doing if
82  // velocity is time dependent on HBCs)
84 
85  // Calculate acceleration term at level n based on previous steps
87 
88  // Subtract acceleration term off m_pressureHBCs[nlevels-1]
90  1, m_pressureHBCs[m_intSteps - 1], 1,
91  m_pressureHBCs[m_intSteps - 1], 1);
92  }
93 }
94 
95 /**
96  *
97  */
99 {
100  if (m_numHBCDof)
101  {
102  int order = std::min(m_pressureCalls, m_intSteps);
103 
104  // Update velocity BF at n+1 (actually only needs doing if
105  // velocity is time dependent on HBCs)
107 
108  // Subtract acceleration term off m_pressureHBCs[nlevels-1]
110  -1.0 * StifflyStable_Gamma0_Coeffs[order - 1] / m_timestep,
112  m_pressureHBCs[m_intSteps - 1], 1);
113  }
114 }
115 
116 /**
117  * Unified routine for calculation high-oder terms
118  */
120  const Array<OneD, const Array<OneD, NekDouble>> &fields,
121  const Array<OneD, const Array<OneD, NekDouble>> &N, NekDouble kinvis)
122 {
123  size_t n, cnt;
124 
126 
129 
132 
134  for (n = cnt = 0; n < m_PBndConds.size(); ++n)
135  {
136  // High order boundary condition;
137  if ((m_hbcType[n] == eHBCNeumann) || (m_hbcType[n] == eConvectiveOBC))
138  {
139  m_fields[0]->GetBndElmtExpansion(n, BndElmtExp, false);
140  int nqb = m_PBndExp[n]->GetTotPoints();
141  int nq = BndElmtExp->GetTotPoints();
142 
143  for (int i = 0; i < m_bnd_dim; i++)
144  {
145  BndValues[i] = Array<OneD, NekDouble>(nqb, 0.0);
146  }
147 
148  for (int i = 0; i < m_curl_dim; i++)
149  {
150  Q[i] = Array<OneD, NekDouble>(nq, 0.0);
151  }
152 
153  // Obtaining fields on BndElmtExp
154  for (int i = 0; i < m_curl_dim; i++)
155  {
156  m_fields[0]->ExtractPhysToBndElmt(n, fields[i], Velocity[i]);
157  }
158 
159  if (N.size()) // not required for some extrapolation
160  {
161  for (int i = 0; i < m_bnd_dim; i++)
162  {
163  m_fields[0]->ExtractPhysToBndElmt(n, N[i], Advection[i]);
164  }
165  }
166 
167  // CurlCurl
168  BndElmtExp->CurlCurl(Velocity, Q);
169 
170  // Mounting advection component into the high-order condition
171  for (int i = 0; i < m_bnd_dim; i++)
172  {
173  MountHOPBCs(nq, kinvis, Q[i], Advection[i]);
174  }
175 
176  Pvals = (m_pressureHBCs[m_intSteps - 1]) + cnt;
177 
178  // Getting values on the boundary and filling the pressure bnd
179  // expansion. Multiplication by the normal is required
180  for (int i = 0; i < m_bnd_dim; i++)
181  {
182  m_fields[0]->ExtractElmtToBndPhys(n, Q[i], BndValues[i]);
183  }
184 
185  m_PBndExp[n]->NormVectorIProductWRTBase(BndValues, Pvals);
186 
187  // Get offset for next terms
188  cnt += m_PBndExp[n]->GetNcoeffs();
189  }
190  }
191 }
192 
193 // do nothing unless otherwise defined.
195 {
196  boost::ignore_unused(pressure);
197 }
198 
199 // do nothing unless otherwise defined.
200 void Extrapolate::v_AddNormVelOnOBC(const int nbcoeffs, const int nreg,
202 {
203  boost::ignore_unused(nbcoeffs, nreg, u);
204 }
205 
207  const Array<OneD, const Array<OneD, NekDouble>> &fields, NekDouble kinvis)
208 {
209  if (!m_houtflow.get())
210  {
211  return;
212  }
213 
215 
217  size_t cnt = 0;
218 
219  // Evaluate robin primitive coefficient here so they can be
220  // updated whem m_int > 1 Currently not using this update
221  // since we only using u^n at outflow instead of BDF rule.
223 
224  for (size_t n = 0; n < m_PBndConds.size(); ++n)
225  {
226  if ((m_hbcType[n] == eOBC) || (m_hbcType[n] == eConvectiveOBC))
227  {
228  // Get expansion with element on this boundary
229  m_fields[0]->GetBndElmtExpansion(n, BndElmtExp, false);
230  int nqb = m_PBndExp[n]->GetTotPoints();
231  int nq = BndElmtExp->GetTotPoints();
232 
233  // Get velocity and extrapolate
234  for (int i = 0; i < m_curl_dim; i++)
235  {
236  m_fields[0]->ExtractPhysToBndElmt(
237  n, fields[i],
238  m_houtflow->m_outflowVel[cnt][i][m_intSteps - 1]);
239  ExtrapolateArray(m_houtflow->m_outflowVel[cnt][i]);
240  Velocity[i] = m_houtflow->m_outflowVel[cnt][i][m_intSteps - 1];
241  }
242 
243  // Homogeneous case needs conversion to physical space
244  if (m_fields[0]->GetWaveSpace())
245  {
246  for (int i = 0; i < m_curl_dim; i++)
247  {
248  BndElmtExp->HomogeneousBwdTrans(Velocity[i].size(),
249  Velocity[i], Velocity[i]);
250  }
251  BndElmtExp->SetWaveSpace(false);
252  }
253 
254  // Get normal vector
256  m_fields[0]->GetBoundaryNormals(n, normals);
257 
258  // Calculate n.gradU.n, div(U)
259  Array<OneD, NekDouble> nGradUn(nqb, 0.0);
260  Array<OneD, NekDouble> divU(nqb, 0.0);
262  Array<OneD, NekDouble> bndVal(nqb, 0.0);
263  for (int i = 0; i < m_curl_dim; i++)
264  {
265  grad[i] = Array<OneD, NekDouble>(nq, 0.0);
266  }
267  for (int i = 0; i < m_curl_dim; i++)
268  {
269  if (m_curl_dim == 2)
270  {
271  BndElmtExp->PhysDeriv(Velocity[i], grad[0], grad[1]);
272  }
273  else
274  {
275  BndElmtExp->PhysDeriv(Velocity[i], grad[0], grad[1],
276  grad[2]);
277  }
278 
279  for (int j = 0; j < m_curl_dim; j++)
280  {
281  m_fields[0]->ExtractElmtToBndPhys(n, grad[j], bndVal);
282  // div(U) = gradU_ii
283  if (i == j)
284  {
285  Vmath::Vadd(nqb, divU, 1, bndVal, 1, divU, 1);
286  }
287  // n.gradU.n = gradU_ij n_i n_j
288  Vmath::Vmul(nqb, normals[i], 1, bndVal, 1, bndVal, 1);
289  Vmath::Vvtvp(nqb, normals[j], 1, bndVal, 1, nGradUn, 1,
290  nGradUn, 1);
291  }
292  }
293 
294  // Obtain u at the boundary
296  for (int i = 0; i < m_curl_dim; i++)
297  {
298  u[i] = Array<OneD, NekDouble>(nqb, 0.0);
299  m_fields[0]->ExtractElmtToBndPhys(n, Velocity[i], u[i]);
300  }
301 
302  // Calculate u.n and u^2
303  Array<OneD, NekDouble> un(nqb, 0.0);
304  Array<OneD, NekDouble> u2(nqb, 0.0);
305  for (int i = 0; i < m_curl_dim; i++)
306  {
307  Vmath::Vvtvp(nqb, normals[i], 1, u[i], 1, un, 1, un, 1);
308  Vmath::Vvtvp(nqb, u[i], 1, u[i], 1, u2, 1, u2, 1);
309  }
310 
311  // Calculate S_0(u.n) = 0.5*(1-tanh(u.n/*U0*delta))
312  Array<OneD, NekDouble> S0(nqb, 0.0);
313  for (int i = 0; i < nqb; i++)
314  {
315  S0[i] = 0.5 * (1.0 - tanh(un[i] / (m_houtflow->m_U0 *
316  m_houtflow->m_delta)));
317  }
318 
319  // Calculate E(n,u) = ((theta+alpha2)*0.5*(u^2)n +
320  // (1-theta+alpha1)*0.5*(n.u)u ) * S_0(u.n)
321  NekDouble k1 =
322  0.5 * (m_houtflow->m_obcTheta + m_houtflow->m_obcAlpha2);
323  NekDouble k2 =
324  0.5 * (1 - m_houtflow->m_obcTheta + m_houtflow->m_obcAlpha1);
325 
327  for (int i = 0; i < m_curl_dim; i++)
328  {
329  E[i] = Array<OneD, NekDouble>(nqb, 0.0);
330 
331  Vmath::Smul(nqb, k1, u2, 1, E[i], 1);
332  Vmath::Vmul(nqb, E[i], 1, normals[i], 1, E[i], 1);
333  // Use bndVal as a temporary storage
334  Vmath::Smul(nqb, k2, un, 1, bndVal, 1);
335  Vmath::Vvtvp(nqb, u[i], 1, bndVal, 1, E[i], 1, E[i], 1);
336  Vmath::Vmul(nqb, E[i], 1, S0, 1, E[i], 1);
337  }
338 
339  // if non-zero forcing is provided we want to subtract
340  // value if we want to interpret values as being the
341  // desired pressure value. This is now precribed from
342  // the velocity forcing to be consistent with the
343  // paper except f_b = -f_b
344 
345  // Calculate (E(n,u) + f_b).n
346  Array<OneD, NekDouble> En(nqb, 0.0);
347  for (int i = 0; i < m_bnd_dim; i++)
348  {
349  // Use bndVal as temporary
350  Vmath::Vsub(nqb, E[i], 1,
351  m_houtflow->m_UBndExp[i][n]->GetPhys(), 1, bndVal,
352  1);
353 
354  Vmath::Vvtvp(nqb, normals[i], 1, bndVal, 1, En, 1, En, 1);
355  }
356 
357  // Calculate pressure bc = kinvis*n.gradU.n - E.n + f_b.n
358  Array<OneD, NekDouble> pbc(nqb, 0.0);
359  Vmath::Svtvm(nqb, kinvis, nGradUn, 1, En, 1, pbc, 1);
360 
361  if (m_hbcType[n] == eOBC)
362  {
363 
364  if (m_PBndExp[n]->GetWaveSpace())
365  {
366  m_PBndExp[n]->HomogeneousFwdTrans(nqb, pbc, bndVal);
367  m_PBndExp[n]->FwdTrans(bndVal,
368  m_PBndExp[n]->UpdateCoeffs());
369  }
370  else
371  {
372  m_PBndExp[n]->FwdTrans(pbc, m_PBndExp[n]->UpdateCoeffs());
373  }
374  }
375  else if (m_hbcType[n] == eConvectiveOBC) // add outflow values to
376  // calculation from HBC
377  {
378  int nbcoeffs = m_PBndExp[n]->GetNcoeffs();
379  Array<OneD, NekDouble> bndCoeffs(nbcoeffs, 0.0);
380  if (m_PBndExp[n]->GetWaveSpace())
381  {
382  m_PBndExp[n]->HomogeneousFwdTrans(nqb, pbc, bndVal);
383  m_PBndExp[n]->IProductWRTBase(bndVal, bndCoeffs);
384  }
385  else
386  {
387  m_PBndExp[n]->IProductWRTBase(pbc, bndCoeffs);
388  }
389  // Note we have the negative of what is in the Dong paper in
390  // bndVal
391  Vmath::Svtvp(nbcoeffs, m_houtflow->m_pressurePrimCoeff[n],
392  bndCoeffs, 1, m_PBndExp[n]->UpdateCoeffs(), 1,
393  m_PBndExp[n]->UpdateCoeffs(), 1);
394 
395  // evaluate u^n at outflow boundary for velocity BC
396  for (int i = 0; i < m_curl_dim; i++)
397  {
398  m_fields[0]->ExtractElmtToBndPhys(
399  n, m_houtflow->m_outflowVel[cnt][i][0],
400  m_houtflow->m_outflowVelBnd[cnt][i][m_intSteps - 1]);
401 
402  EvaluateBDFArray(m_houtflow->m_outflowVelBnd[cnt][i]);
403 
404  // point u[i] to BDF evalauted value \hat{u}
405  u[i] = m_houtflow->m_outflowVelBnd[cnt][i][m_intSteps - 1];
406  }
407 
408  // Add normal velocity if weak pressure
409  // formulation. In this case there is an
410  // additional \int \hat{u}.n ds on the outflow
411  // boundary since we use the inner product wrt
412  // deriv of basis in pressure solve.
413  AddNormVelOnOBC(cnt, n, u);
414  }
415 
416  // Calculate velocity boundary conditions
417  if (m_hbcType[n] == eOBC)
418  {
419  // = (pbc n - kinvis divU n)
420  Vmath::Smul(nqb, kinvis, divU, 1, divU, 1);
421  Vmath::Vsub(nqb, pbc, 1, divU, 1, bndVal, 1);
422  }
423  else if (m_hbcType[n] == eConvectiveOBC)
424  {
425  // = (-kinvis divU n)
426  Vmath::Smul(nqb, -1.0 * kinvis, divU, 1, bndVal, 1);
427 
428  // pbc needs to be added after pressure solve
429  }
430 
431  for (int i = 0; i < m_curl_dim; ++i)
432  {
433  // Reuse divU -> En
434  Vmath::Vvtvp(nqb, normals[i], 1, bndVal, 1, E[i], 1, divU, 1);
435  // - f_b
436  Vmath::Vsub(nqb, divU, 1,
437  m_houtflow->m_UBndExp[i][n]->GetPhys(), 1, divU, 1);
438  // * 1/kinvis
439  Vmath::Smul(nqb, 1.0 / kinvis, divU, 1, divU, 1);
440 
441  if (m_hbcType[n] == eConvectiveOBC)
442  {
443  Vmath::Svtvp(nqb, m_houtflow->m_velocityPrimCoeff[i][n],
444  u[i], 1, divU, 1, divU, 1);
445  }
446 
447  if (m_houtflow->m_UBndExp[i][n]->GetWaveSpace())
448  {
449  m_houtflow->m_UBndExp[i][n]->HomogeneousFwdTrans(nqb, divU,
450  divU);
451  }
452 
453  m_houtflow->m_UBndExp[i][n]->IProductWRTBase(
454  divU, m_houtflow->m_UBndExp[i][n]->UpdateCoeffs());
455  }
456 
457  // Get offset for next terms
458  cnt++;
459  }
460  }
461 }
462 
464 {
465  if (!m_houtflow.get())
466  {
467  return;
468  }
469 
470  for (size_t n = 0; n < m_PBndConds.size(); ++n)
471  {
472  if (m_hbcType[n] == eConvectiveOBC)
473  {
474  int nqb = m_PBndExp[n]->GetTotPoints();
475  int ncb = m_PBndExp[n]->GetNcoeffs();
476 
477  m_pressure->FillBndCondFromField(n, m_pressure->GetCoeffs());
478  Array<OneD, NekDouble> pbc(nqb);
479 
480  m_PBndExp[n]->BwdTrans(m_PBndExp[n]->GetCoeffs(), pbc);
481 
482  if (m_PBndExp[n]->GetWaveSpace())
483  {
484  m_PBndExp[n]->HomogeneousBwdTrans(nqb, pbc, pbc);
485  }
486 
487  Array<OneD, NekDouble> wk(nqb);
488  Array<OneD, NekDouble> wk1(ncb);
489 
490  // Get normal vector
492  m_fields[0]->GetBoundaryNormals(n, normals);
493 
494  // Add 1/kinvis * (pbc n )
495  for (int i = 0; i < m_curl_dim; ++i)
496  {
497  Vmath::Vmul(nqb, normals[i], 1, pbc, 1, wk, 1);
498 
499  Vmath::Smul(nqb, 1.0 / kinvis, wk, 1, wk, 1);
500 
501  if (m_houtflow->m_UBndExp[i][n]->GetWaveSpace())
502  {
503  m_houtflow->m_UBndExp[i][n]->HomogeneousFwdTrans(nqb, wk,
504  wk);
505  }
506  m_houtflow->m_UBndExp[i][n]->IProductWRTBase(wk, wk1);
507 
508  Vmath::Vadd(ncb, wk1, 1,
509  m_houtflow->m_UBndExp[i][n]->GetCoeffs(), 1,
510  m_houtflow->m_UBndExp[i][n]->UpdateCoeffs(), 1);
511  }
512  }
513  }
514 }
515 
517  const Array<OneD, const Array<OneD, NekDouble>> &Vel,
518  Array<OneD, NekDouble> &IProdVn)
519 {
520  int i;
521  size_t n, cnt;
522  Array<OneD, NekDouble> IProdVnTmp;
524 
525  for (n = cnt = 0; n < m_PBndConds.size(); ++n)
526  {
527  // High order boundary condition;
528  if (m_hbcType[n] == eHBCNeumann)
529  {
530  for (i = 0; i < m_bnd_dim; ++i)
531  {
532  m_fields[0]->ExtractPhysToBnd(n, Vel[i], velbc[i]);
533  }
534  IProdVnTmp = IProdVn + cnt;
535  m_PBndExp[n]->NormVectorIProductWRTBase(velbc, IProdVnTmp);
536  cnt += m_PBndExp[n]->GetNcoeffs();
537  }
538  else if (m_hbcType[n] == eConvectiveOBC) // skip over conective OBC
539  {
540  cnt += m_PBndExp[n]->GetNcoeffs();
541  }
542  }
543 }
544 
546 {
547 
548  if (!m_HBCnumber)
549  {
550  return;
551  }
552  int i;
553  size_t n, cnt;
554  Array<OneD, NekDouble> IProdVnTmp;
557  m_bnd_dim);
558  for (i = 0; i < m_bnd_dim; ++i)
559  {
560  VelBndExp[i] = m_fields[m_velocity[i]]->GetBndCondExpansions();
561  }
562 
563  for (n = cnt = 0; n < m_PBndConds.size(); ++n)
564  {
565  // High order boundary condition;
566  if (m_hbcType[n] == eHBCNeumann)
567  {
568  for (i = 0; i < m_bnd_dim; ++i)
569  {
570  velbc[i] = Array<OneD, NekDouble>(
571  VelBndExp[i][n]->GetTotPoints(), 0.0);
572  VelBndExp[i][n]->SetWaveSpace(
573  m_fields[m_velocity[i]]->GetWaveSpace());
574  VelBndExp[i][n]->BwdTrans(VelBndExp[i][n]->GetCoeffs(),
575  velbc[i]);
576  }
577  IProdVnTmp = IProdVn + cnt;
578  m_PBndExp[n]->NormVectorIProductWRTBase(velbc, IProdVnTmp);
579  cnt += m_PBndExp[n]->GetNcoeffs();
580  }
581  else if (m_hbcType[n] == eConvectiveOBC)
582  {
583  // skip over convective OBC
584  cnt += m_PBndExp[n]->GetNcoeffs();
585  }
586  }
587 }
588 
589 /**
590  * Function to roll time-level storages to the next step layout.
591  * The stored data associated with the oldest time-level
592  * (not required anymore) are moved to the top, where they will
593  * be overwritten as the solution process progresses.
594  */
596 {
597  int nlevels = input.size();
598 
600 
601  tmp = input[nlevels - 1];
602 
603  for (int n = nlevels - 1; n > 0; --n)
604  {
605  input[n] = input[n - 1];
606  }
607 
608  input[0] = tmp;
609 }
610 
611 /**
612  * Initialize HOBCs
613  */
615  const LibUtilities::SessionReaderSharedPtr &pSession)
616 {
617  m_PBndConds = m_pressure->GetBndConditions();
618  m_PBndExp = m_pressure->GetBndCondExpansions();
619 
620  size_t cnt, n;
621 
622  // Storage array for high order pressure BCs
625 
626  // Get useful values for HOBCs
627  m_HBCnumber = 0;
628  m_numHBCDof = 0;
629 
630  int outHBCnumber = 0;
631  int numOutHBCPts = 0;
632 
634  for (n = 0; n < m_PBndConds.size(); ++n)
635  {
636  // High order boundary Neumann Condiiton
637  if (boost::iequals(m_PBndConds[n]->GetUserDefined(), "H"))
638  {
639  m_hbcType[n] = eHBCNeumann;
640  m_numHBCDof += m_PBndExp[n]->GetNcoeffs();
641  m_HBCnumber += m_PBndExp[n]->GetExpSize();
642  }
643 
644  // High order outflow convective condition
645  if (m_PBndConds[n]->GetBoundaryConditionType() ==
647  boost::iequals(m_PBndConds[n]->GetUserDefined(), "HOutflow"))
648  {
650  m_numHBCDof += m_PBndExp[n]->GetNcoeffs();
651  m_HBCnumber += m_PBndExp[n]->GetExpSize();
652  numOutHBCPts += m_PBndExp[n]->GetTotPoints();
653  outHBCnumber++;
654  }
655  // High order outflow boundary condition;
656  else if (boost::iequals(m_PBndConds[n]->GetUserDefined(), "HOutflow"))
657  {
658  m_hbcType[n] = eOBC;
659  numOutHBCPts += m_PBndExp[n]->GetTotPoints();
660  outHBCnumber++;
661  }
662  }
663 
665  for (int n = 0; n < m_intSteps; ++n)
666  {
669  }
670 
671  m_pressureCalls = 0;
672 
673  switch (m_pressure->GetExpType())
674  {
675  case MultiRegions::e2D:
676  {
677  m_curl_dim = 2;
678  m_bnd_dim = 2;
679  }
680  break;
682  {
683  m_curl_dim = 3;
684  m_bnd_dim = 2;
685  }
686  break;
688  {
689  m_curl_dim = 3;
690  m_bnd_dim = 1;
691  }
692  break;
693  case MultiRegions::e3D:
694  {
695  m_curl_dim = 3;
696  m_bnd_dim = 3;
697  }
698  break;
699  default:
700  ASSERTL0(0, "Dimension not supported");
701  break;
702  }
703 
704  // Initialise storage for outflow HOBCs
705  if (numOutHBCPts > 0)
706  {
708  numOutHBCPts, outHBCnumber, m_curl_dim, pSession);
709 
711 
712  // set up boundary expansions link
713  for (int i = 0; i < m_curl_dim; ++i)
714  {
715  m_houtflow->m_UBndExp[i] =
716  m_fields[m_velocity[i]]->GetBndCondExpansions();
717  }
718 
719  for (n = 0, cnt = 0; n < m_PBndConds.size(); ++n)
720  {
721  if (boost::iequals(m_PBndConds[n]->GetUserDefined(), "HOutflow"))
722  {
723  m_houtflow->m_outflowVel[cnt] =
725  m_curl_dim);
726 
727  m_houtflow->m_outflowVelBnd[cnt] =
729  m_curl_dim);
730 
731  m_fields[0]->GetBndElmtExpansion(n, BndElmtExp, false);
732  int nqb = m_PBndExp[n]->GetTotPoints();
733  int nq = BndElmtExp->GetTotPoints();
734  for (int j = 0; j < m_curl_dim; ++j)
735  {
736  m_houtflow->m_outflowVel[cnt][j] =
738 
739  m_houtflow->m_outflowVelBnd[cnt][j] =
741 
742  for (int k = 0; k < m_intSteps; ++k)
743  {
744  m_houtflow->m_outflowVel[cnt][j][k] =
745  Array<OneD, NekDouble>(nq, 0.0);
746  m_houtflow->m_outflowVelBnd[cnt][j][k] =
747  Array<OneD, NekDouble>(nqb, 0.0);
748  }
749  }
750  cnt++;
751  }
752 
753  // evaluate convective primitive coefficient if
754  // convective OBCs are used
755  if (m_hbcType[n] == eConvectiveOBC)
756  {
757  // initialise convective members of
758  // HighOrderOutflow struct
759  if (m_houtflow->m_pressurePrimCoeff.size() == 0)
760  {
761  m_houtflow->m_pressurePrimCoeff =
762  Array<OneD, NekDouble>(m_PBndConds.size(), 0.0);
763  m_houtflow->m_velocityPrimCoeff =
765 
766  for (int i = 0; i < m_curl_dim; ++i)
767  {
768  m_houtflow->m_velocityPrimCoeff[i] =
769  Array<OneD, NekDouble>(m_PBndConds.size(), 0.0);
770  }
771  }
772 
773  LibUtilities::Equation coeff =
774  std::static_pointer_cast<
776  ->m_robinPrimitiveCoeff;
777 
778  // checkout equation evaluation options!!
779  m_houtflow->m_pressurePrimCoeff[n] = coeff.Evaluate();
780 
781  for (int i = 0; i < m_curl_dim; ++i)
782  {
784  UBndConds = m_fields[m_velocity[i]]->GetBndConditions();
785 
786  LibUtilities::Equation coeff1 =
787  std::static_pointer_cast<
789  UBndConds[n])
790  ->m_robinPrimitiveCoeff;
791 
792  m_houtflow->m_defVelPrimCoeff[i] = coeff1.GetExpression();
793 
794  ASSERTL1(UBndConds[n]->GetBoundaryConditionType() ==
796  "Require Velocity "
797  "conditions to be of Robin type when pressure"
798  "outflow is specticied as Robin Boundary type");
799 
800  // checkout equation evaluation options!!
801  m_houtflow->m_velocityPrimCoeff[i][n] = coeff1.Evaluate();
802  }
803  }
804  }
805  }
806 }
807 
809 {
810 
811  if ((m_pressureCalls == 1) || (m_pressureCalls > m_intSteps))
812  {
813  return;
814  }
815 
816  for (size_t n = 0; n < m_PBndConds.size(); ++n)
817  {
818  // Get expansion with element on this boundary
819  if (m_hbcType[n] == eConvectiveOBC)
820  {
821  for (int i = 0; i < m_curl_dim; ++i)
822  {
824  m_fields[m_velocity[i]]->UpdateBndConditions();
825 
826  std::string primcoeff =
827  m_houtflow->m_defVelPrimCoeff[i] + "*" +
828  boost::lexical_cast<std::string>(
830 
831  SpatialDomains::RobinBCShPtr rcond = std::dynamic_pointer_cast<
833 
837  m_session, rcond->m_robinFunction.GetExpression(),
838  primcoeff, rcond->GetUserDefined(),
839  rcond->m_filename);
840 
841  UBndConds[n] = bcond;
842  }
843  }
844  }
845 }
846 
847 /**
848  *
849  */
851  const Array<OneD, Array<OneD, NekDouble>> inarray)
852 {
853  // Checking if the problem is 2D
854  ASSERTL0(m_curl_dim >= 2, "Method not implemented for 1D");
855 
856  size_t n_points_0 = m_fields[0]->GetExp(0)->GetTotPoints();
857  size_t n_element = m_fields[0]->GetExpSize();
858  size_t nvel = inarray.size();
859  size_t cnt;
860 
861  NekDouble pntVelocity;
862 
863  // Getting the standard velocity vector
864  Array<OneD, Array<OneD, NekDouble>> stdVelocity(nvel);
866  Array<OneD, NekDouble> maxV(n_element, 0.0);
868 
869  for (size_t i = 0; i < nvel; ++i)
870  {
871  stdVelocity[i] = Array<OneD, NekDouble>(n_points_0);
872  }
873 
874  cnt = 0.0;
875  for (size_t el = 0; el < n_element; ++el)
876  {
877  size_t n_points = m_fields[0]->GetExp(el)->GetTotPoints();
878  ptsKeys = m_fields[0]->GetExp(el)->GetPointsKeys();
879 
880  // reset local space
881  if (n_points != n_points_0)
882  {
883  for (size_t j = 0; j < nvel; ++j)
884  {
885  stdVelocity[j] = Array<OneD, NekDouble>(n_points, 0.0);
886  }
887  n_points_0 = n_points;
888  }
889  else
890  {
891  for (size_t j = 0; j < nvel; ++j)
892  {
893  Vmath::Zero(n_points, stdVelocity[j], 1);
894  }
895  }
896 
898  ->GetExp(el)
899  ->GetGeom()
900  ->GetMetricInfo()
901  ->GetDerivFactors(ptsKeys);
902 
903  if (m_fields[0]->GetExp(el)->GetGeom()->GetMetricInfo()->GetGtype() ==
905  {
906  for (size_t j = 0; j < nvel; ++j)
907  {
908  for (size_t k = 0; k < nvel; ++k)
909  {
910  Vmath::Vvtvp(n_points, gmat[k * nvel + j], 1,
911  tmp = inarray[k] + cnt, 1, stdVelocity[j], 1,
912  stdVelocity[j], 1);
913  }
914  }
915  }
916  else
917  {
918  for (size_t j = 0; j < nvel; ++j)
919  {
920  for (size_t k = 0; k < nvel; ++k)
921  {
922  Vmath::Svtvp(n_points, gmat[k * nvel + j][0],
923  tmp = inarray[k] + cnt, 1, stdVelocity[j], 1,
924  stdVelocity[j], 1);
925  }
926  }
927  }
928  cnt += n_points;
929 
930  // Calculate total velocity in stdVelocity[0]
931  Vmath::Vmul(n_points, stdVelocity[0], 1, stdVelocity[0], 1,
932  stdVelocity[0], 1);
933  for (size_t k = 1; k < nvel; ++k)
934  {
935  Vmath::Vvtvp(n_points, stdVelocity[k], 1, stdVelocity[k], 1,
936  stdVelocity[0], 1, stdVelocity[0], 1);
937  }
938  pntVelocity = Vmath::Vmax(n_points, stdVelocity[0], 1);
939  maxV[el] = sqrt(pntVelocity);
940  }
941 
942  return maxV;
943 }
944 
946 {
947  return "";
948 }
949 
950 /**
951  * At the start, the newest value is stored in array[nlevels-1]
952  * and the previous values in the first positions
953  * At the end, the extrapolated value is stored in array[nlevels-1]
954  * and the storage has been updated to included the new value
955  */
957 {
958  int nint = min(m_pressureCalls, m_intSteps);
959  int nlevels = array.size();
960  int nPts = array[0].size();
961 
962  // Update array
963  RollOver(array);
964 
965  // Extrapolate to outarray
966  Vmath::Smul(nPts, StifflyStable_Betaq_Coeffs[nint - 1][nint - 1],
967  array[nint - 1], 1, array[nlevels - 1], 1);
968 
969  for (int n = 0; n < nint - 1; ++n)
970  {
971  Vmath::Svtvp(nPts, StifflyStable_Betaq_Coeffs[nint - 1][n], array[n], 1,
972  array[nlevels - 1], 1, array[nlevels - 1], 1);
973  }
974 }
975 
976 /**
977  * At the start, the newest value is stored in array[nlevels-1]
978  * and the previous values in the first positions
979  * At the end, the value of the bdf explicit part is stored in
980  * array[nlevels-1] and the storage has been updated to included the new value
981  */
983 {
984  int nint = min(m_pressureCalls, m_intSteps);
985  int nlevels = array.size();
986  int nPts = array[0].size();
987 
988  // Update array
989  RollOver(array);
990 
991  // Extrapolate to outarray
992  Vmath::Smul(nPts, StifflyStable_Alpha_Coeffs[nint - 1][nint - 1],
993  array[nint - 1], 1, array[nlevels - 1], 1);
994 
995  for (int n = 0; n < nint - 1; ++n)
996  {
997  Vmath::Svtvp(nPts, StifflyStable_Alpha_Coeffs[nint - 1][n], array[n], 1,
998  array[nlevels - 1], 1, array[nlevels - 1], 1);
999  }
1000 }
1001 
1002 /**
1003  * At the start, the newest value is stored in array[nlevels-1]
1004  * and the previous values in the first positions
1005  * At the end, the acceleration from BDF is stored in array[nlevels-1]
1006  * and the storage has been updated to included the new value
1007  */
1009 {
1010  int nlevels = array.size();
1011  int nPts = array[0].size();
1012 
1013  if (nPts)
1014  {
1015  // Update array
1016  RollOver(array);
1017 
1018  // Calculate acceleration using Backward Differentiation Formula
1019  Array<OneD, NekDouble> accelerationTerm(nPts, 0.0);
1020  if (m_pressureCalls > 2)
1021  {
1022  int acc_order = min(m_pressureCalls - 2, m_intSteps);
1023  Vmath::Smul(nPts, StifflyStable_Gamma0_Coeffs[acc_order - 1],
1024  array[0], 1, accelerationTerm, 1);
1025 
1026  for (int i = 0; i < acc_order; i++)
1027  {
1028  Vmath::Svtvp(
1029  nPts, -1 * StifflyStable_Alpha_Coeffs[acc_order - 1][i],
1030  array[i + 1], 1, accelerationTerm, 1, accelerationTerm, 1);
1031  }
1032  }
1033  array[nlevels - 1] = accelerationTerm;
1034  }
1035 }
1036 
1038 {
1039  size_t n, cnt;
1040  for (cnt = n = 0; n < m_PBndConds.size(); ++n)
1041  {
1042  if ((m_hbcType[n] == eHBCNeumann) || (m_hbcType[n] == eConvectiveOBC))
1043  {
1044  int nq = m_PBndExp[n]->GetNcoeffs();
1045  Vmath::Vcopy(nq, &(m_pressureHBCs[m_intSteps - 1])[cnt], 1,
1046  &(m_PBndExp[n]->UpdateCoeffs()[0]), 1);
1047  cnt += nq;
1048  }
1049  }
1050 }
1051 } // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:249
virtual void v_AccelerationBDF(Array< OneD, Array< OneD, NekDouble >> &array)
virtual void v_AddNormVelOnOBC(const int nbcoeffs, const int nreg, Array< OneD, Array< OneD, NekDouble >> &u)
Array< OneD, Array< OneD, NekDouble > > m_pressureHBCs
Storage for current and previous levels of high order pressure boundary conditions.
Definition: Extrapolate.h:241
int m_bnd_dim
bounday dimensionality
Definition: Extrapolate.h:217
Array< OneD, NekDouble > GetMaxStdVelocity(const Array< OneD, Array< OneD, NekDouble >> inarray)
int m_curl_dim
Curl-curl dimensionality.
Definition: Extrapolate.h:214
MultiRegions::ExpListSharedPtr m_pressure
Pointer to field holding pressure field.
Definition: Extrapolate.h:201
void AddNormVelOnOBC(const int nbcoeffs, const int nreg, Array< OneD, Array< OneD, NekDouble >> &u)
Definition: Extrapolate.h:404
void EvaluateBDFArray(Array< OneD, Array< OneD, NekDouble >> &array)
static std::string def
Definition: Extrapolate.h:258
void RollOver(Array< OneD, Array< OneD, NekDouble >> &input)
static NekDouble StifflyStable_Betaq_Coeffs[3][3]
Definition: Extrapolate.h:250
void CopyPressureHBCsToPbndExp(void)
virtual void v_CorrectPressureBCs(const Array< OneD, NekDouble > &pressure)
void IProductNormVelocityBCOnHBC(Array< OneD, NekDouble > &IprodVn)
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Velocity fields.
Definition: Extrapolate.h:198
Array< OneD, Array< OneD, NekDouble > > m_iprodnormvel
Storage for current and previous levels of the inner product of normal velocity.
Definition: Extrapolate.h:245
void ExtrapolateArray(Array< OneD, Array< OneD, NekDouble >> &array)
virtual void v_CalcNeumannPressureBCs(const Array< OneD, const Array< OneD, NekDouble >> &fields, const Array< OneD, const Array< OneD, NekDouble >> &N, NekDouble kinvis)
int m_intSteps
Maximum points used in pressure BC evaluation.
Definition: Extrapolate.h:235
void CalcOutflowBCs(const Array< OneD, const Array< OneD, NekDouble >> &fields, NekDouble kinvis)
void GenerateHOPBCMap(const LibUtilities::SessionReaderSharedPtr &pSsession)
Array< OneD, HBCType > m_hbcType
Array of type of high order BCs for splitting shemes.
Definition: Extrapolate.h:195
HighOrderOutflowSharedPtr m_houtflow
Definition: Extrapolate.h:255
NekDouble m_timestep
Definition: Extrapolate.h:237
Array< OneD, MultiRegions::ExpListSharedPtr > m_PBndExp
pressure boundary conditions expansion container
Definition: Extrapolate.h:223
void MountHOPBCs(int HBCdata, NekDouble kinvis, Array< OneD, NekDouble > &Q, Array< OneD, const NekDouble > &Advection)
Definition: Extrapolate.h:377
Array< OneD, int > m_velocity
int which identifies which components of m_fields contains the velocity (u,v,w);
Definition: Extrapolate.h:205
static NekDouble StifflyStable_Alpha_Coeffs[3][3]
Definition: Extrapolate.h:251
Array< OneD, const SpatialDomains::BoundaryConditionShPtr > m_PBndConds
pressure boundary conditions container
Definition: Extrapolate.h:220
int m_pressureCalls
number of times the high-order pressure BCs have been called
Definition: Extrapolate.h:226
LibUtilities::SessionReaderSharedPtr m_session
Definition: Extrapolate.h:190
void UpdateRobinPrimCoeff(void)
void IProductNormVelocityOnHBC(const Array< OneD, const Array< OneD, NekDouble >> &Vel, Array< OneD, NekDouble > &IprodVn)
void AddPressureToOutflowBCs(NekDouble kinvis)
LibUtilities::CommSharedPtr m_comm
Definition: Extrapolate.h:192
static NekDouble StifflyStable_Gamma0_Coeffs[3]
Definition: Extrapolate.h:252
virtual ~Extrapolate()
Definition: Extrapolate.cpp:66
virtual std::string v_GetSubStepName(void)
std::string GetExpression(void) const
Provides a generic Factory class.
Definition: NekFactory.hpp:105
static std::string RegisterDefaultSolverInfo(const std::string &pName, const std::string &pValue)
Registers the default string value of a solver info property.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
An abstract base class encapsulating the concept of advection of a vector field.
Definition: Advection.h:70
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::vector< PointsKey > PointsKeyVector
Definition: Points.h:250
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::shared_ptr< Advection > AdvectionSharedPtr
A shared pointer to an Advection object.
Definition: Advection.h:278
std::shared_ptr< BoundaryConditionBase > BoundaryConditionShPtr
Definition: Conditions.h:212
@ eDeformed
Geometry is curved or has non-constant factors.
std::shared_ptr< RobinBoundaryCondition > RobinBCShPtr
Definition: Conditions.h:215
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
@ eNOHBC
Definition: Extrapolate.h:52
@ eConvectiveOBC
Definition: Extrapolate.h:55
@ eHBCNeumann
Definition: Extrapolate.h:53
ExtrapolateFactory & GetExtrapolateFactory()
Definition: Extrapolate.cpp:48
double NekDouble
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:209
void Svtvp(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
svtvp (scalar times vector plus vector): z = alpha*x + y
Definition: Vmath.cpp:622
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:574
void Svtvm(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
svtvp (scalar times vector minus vector): z = alpha*x - y
Definition: Vmath.cpp:664
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:359
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:248
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:492
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
Definition: Vmath.cpp:945
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1255
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:419
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:294