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