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