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