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