Nektar++
MappingExtrapolate.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: MappingExtrapolate.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 MappingExtrapolate.
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
37 
38 namespace Nektar
39 {
40 /**
41  * Registers the class with the Factory.
42  */
45  "Mapping", MappingExtrapolate::create, "Mapping");
46 
51  const SolverUtils::AdvectionSharedPtr advObject)
52  : StandardExtrapolate(pSession, pFields, pPressure, pVel, advObject)
53 {
55 
56  // Load solve parameters related to the mapping
57  // Flags determining if pressure/viscous terms should be treated implicitly
58  m_session->MatchSolverInfo("MappingImplicitPressure", "True",
59  m_implicitPressure, false);
60  m_session->MatchSolverInfo("MappingImplicitViscous", "True",
61  m_implicitViscous, false);
62 
63  // Relaxation parameter for pressure system
64  m_session->LoadParameter("MappingPressureRelaxation", m_pressureRelaxation,
65  1.0);
66 }
67 
69 {
70 }
71 
72 /**
73  *
74  */
77 {
78  if (m_HBCnumber > 0)
79  {
80  size_t cnt, n;
81  size_t physTot = m_fields[0]->GetTotPoints();
82  size_t nvel = m_fields.size() - 1;
83 
85  // Remove previous correction
86  for (cnt = n = 0; n < m_PBndConds.size(); ++n)
87  {
88  if (m_PBndConds[n]->GetUserDefined() == "H")
89  {
90  size_t nq = m_PBndExp[n]->GetNcoeffs();
91  Vmath::Vsub(nq, &(m_PBndExp[n]->GetCoeffs()[0]), 1,
92  &(m_bcCorrection[cnt]), 1,
93  &(m_PBndExp[n]->UpdateCoeffs()[0]), 1);
94  cnt += nq;
95  }
96  }
97 
98  // Calculate new correction
99  Array<OneD, NekDouble> Jac(physTot, 0.0);
100  m_mapping->GetJacobian(Jac);
101 
102  Array<OneD, Array<OneD, NekDouble>> correction(nvel);
106  for (size_t i = 0; i < nvel; i++)
107  {
108  wk[i] = Array<OneD, NekDouble>(physTot, 0.0);
109  gradP[i] = Array<OneD, NekDouble>(physTot, 0.0);
110  correction[i] = Array<OneD, NekDouble>(physTot, 0.0);
111  }
112 
113  // Calculate G(p)
114  for (size_t i = 0; i < nvel; ++i)
115  {
117  gradP[i]);
118  if (m_fields[0]->GetWaveSpace())
119  {
120  m_fields[0]->HomogeneousBwdTrans(physTot, gradP[i], wk[i]);
121  }
122  else
123  {
124  Vmath::Vcopy(physTot, gradP[i], 1, wk[i], 1);
125  }
126  }
127  m_mapping->RaiseIndex(wk, correction); // G(p)
128 
129  // alpha*J*(G(p))
130  if (!m_mapping->HasConstantJacobian())
131  {
132  for (size_t i = 0; i < nvel; ++i)
133  {
134  Vmath::Vmul(physTot, correction[i], 1, Jac, 1, correction[i],
135  1);
136  }
137  }
138  for (size_t i = 0; i < nvel; ++i)
139  {
140  Vmath::Smul(physTot, m_pressureRelaxation, correction[i], 1,
141  correction[i], 1);
142  }
143 
144  if (m_pressure->GetWaveSpace())
145  {
146  for (size_t i = 0; i < nvel; ++i)
147  {
148  m_pressure->HomogeneousFwdTrans(physTot, correction[i],
149  correction[i]);
150  }
151  }
152  // p_i - alpha*J*div(G(p))
153  for (size_t i = 0; i < nvel; ++i)
154  {
155  Vmath::Vsub(physTot, gradP[i], 1, correction[i], 1, correction[i],
156  1);
157  }
158 
159  // Get value at boundary and calculate Inner product
163  for (n = cnt = 0; n < m_PBndConds.size(); ++n)
164  {
165  // High order boundary condition;
166  if (boost::iequals(m_PBndConds[n]->GetUserDefined(), "H"))
167  {
168  m_fields[0]->GetBndElmtExpansion(n, BndElmtExp);
169 
170  // Obtaining fields on BndElmtExp
171  for (int i = 0; i < m_bnd_dim; i++)
172  {
173  m_fields[0]->ExtractPhysToBndElmt(n, correction[i],
174  correctionElmt[i]);
175  }
176 
177  Vals = m_bcCorrection + cnt;
178  // Getting values on the edge and filling the correction
179  for (int i = 0; i < m_bnd_dim; i++)
180  {
181  m_fields[0]->ExtractElmtToBndPhys(n, correctionElmt[i],
182  BndValues[i]);
183  }
184  m_PBndExp[n]->NormVectorIProductWRTBase(BndValues, Vals);
185 
186  // Get offset for next terms
187  cnt += m_PBndExp[n]->GetNcoeffs();
188  }
189  }
190 
191  // Apply new correction
192  for (size_t cnt = n = 0; n < m_PBndConds.size(); ++n)
193  {
194  if (m_PBndConds[n]->GetUserDefined() == "H")
195  {
196  size_t nq = m_PBndExp[n]->GetNcoeffs();
197  Vmath::Vadd(nq, &(m_PBndExp[n]->GetCoeffs()[0]), 1,
198  &(m_bcCorrection[cnt]), 1,
199  &(m_PBndExp[n]->UpdateCoeffs()[0]), 1);
200  cnt += nq;
201  }
202  }
203  }
204 }
205 
207  const Array<OneD, const Array<OneD, NekDouble>> &fields,
208  const Array<OneD, const Array<OneD, NekDouble>> &N, NekDouble kinvis)
209 {
210  if (m_mapping->HasConstantJacobian() && !m_implicitViscous)
211  {
212  Extrapolate::v_CalcNeumannPressureBCs(fields, N, kinvis);
213  }
214  else
215  {
216  size_t physTot = m_fields[0]->GetTotPoints();
217  size_t nvel = m_fields.size() - 1;
218  size_t i, n, cnt;
219 
222 
225  // Get transformation Jacobian
226  Array<OneD, NekDouble> Jac(physTot, 0.0);
227  m_mapping->GetJacobian(Jac);
228  // Declare variables
231  Array<OneD, Array<OneD, NekDouble>> Q_field(nvel);
232  Array<OneD, Array<OneD, NekDouble>> fields_new(nvel);
234  // Temporary variables
235  Array<OneD, NekDouble> tmp(physTot, 0.0);
236  Array<OneD, NekDouble> tmp2(physTot, 0.0);
237  for (int i = 0; i < m_bnd_dim; i++)
238  {
239  N_new[i] = Array<OneD, NekDouble>(physTot, 0.0);
240  }
241  for (i = 0; i < nvel; i++)
242  {
243  Q_field[i] = Array<OneD, NekDouble>(physTot, 0.0);
244  fields_new[i] = Array<OneD, NekDouble>(physTot, 0.0);
245  }
246 
247  // Multiply convective terms by Jacobian
248  for (int i = 0; i < m_bnd_dim; i++)
249  {
250  if (m_fields[0]->GetWaveSpace())
251  {
252  m_fields[0]->HomogeneousBwdTrans(physTot, N[i], N_new[i]);
253  }
254  else
255  {
256  Vmath::Vcopy(physTot, N[i], 1, N_new[i], 1);
257  }
258  Vmath::Vmul(physTot, Jac, 1, N_new[i], 1, N_new[i], 1);
259  if (m_fields[0]->GetWaveSpace())
260  {
261  m_fields[0]->HomogeneousFwdTrans(physTot, N_new[i], N_new[i]);
262  }
263  }
264 
265  // Get velocity in physical space
266  for (i = 0; i < nvel; i++)
267  {
268  if (m_fields[0]->GetWaveSpace())
269  {
270  m_fields[0]->HomogeneousBwdTrans(physTot, fields[i],
271  fields_new[i]);
272  }
273  else
274  {
275  Vmath::Vcopy(physTot, fields[i], 1, fields_new[i], 1);
276  }
277  }
278 
279  // Calculate appropriate form of the CurlCurl operator
280  m_mapping->CurlCurlField(fields_new, Q_field, m_implicitViscous);
281 
282  // If viscous terms are treated explicitly,
283  // add grad(U/J \dot grad J) to CurlCurl
284  if (!m_implicitViscous)
285  {
286  m_mapping->DotGradJacobian(fields_new, tmp);
287  Vmath::Vdiv(physTot, tmp, 1, Jac, 1, tmp, 1);
288 
289  bool wavespace = m_fields[0]->GetWaveSpace();
290  m_fields[0]->SetWaveSpace(false);
291  for (int i = 0; i < m_bnd_dim; i++)
292  {
293  m_fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[i], tmp,
294  tmp2);
295  Vmath::Vadd(physTot, Q_field[i], 1, tmp2, 1, Q_field[i], 1);
296  }
297  m_fields[0]->SetWaveSpace(wavespace);
298  }
299 
300  // Multiply by Jacobian and convert to wavespace (if necessary)
301  for (int i = 0; i < m_bnd_dim; i++)
302  {
303  Vmath::Vmul(physTot, Jac, 1, fields_new[i], 1, fields_new[i], 1);
304  Vmath::Vmul(physTot, Jac, 1, Q_field[i], 1, Q_field[i], 1);
305  if (m_fields[0]->GetWaveSpace())
306  {
307  m_fields[0]->HomogeneousFwdTrans(physTot, fields_new[i],
308  fields_new[i]);
309  m_fields[0]->HomogeneousFwdTrans(physTot, Q_field[i],
310  Q_field[i]);
311  }
312  }
313 
315  for (n = cnt = 0; n < m_PBndConds.size(); ++n)
316  {
317  // High order boundary condition;
318  if (boost::iequals(m_PBndConds[n]->GetUserDefined(), "H"))
319  {
320  m_fields[0]->GetBndElmtExpansion(n, BndElmtExp);
321  size_t nq = BndElmtExp->GetTotPoints();
322 
323  // Obtaining fields on BndElmtExp
324  for (int i = 0; i < m_bnd_dim; i++)
325  {
326  m_fields[0]->ExtractPhysToBndElmt(n, fields_new[i],
327  Velocity[i]);
328  m_fields[0]->ExtractPhysToBndElmt(n, N_new[i],
329  Advection[i]);
330  m_fields[0]->ExtractPhysToBndElmt(n, Q_field[i], Q[i]);
331  }
332 
333  // Mounting advection component into the high-order condition
334  for (int i = 0; i < m_bnd_dim; i++)
335  {
336  MountHOPBCs(nq, kinvis, Q[i], Advection[i]);
337  }
338 
339  Pvals = (m_pressureHBCs[m_intSteps - 1]) + cnt;
340  Uvals = (m_iprodnormvel[m_intSteps]) + cnt;
341 
342  // Getting values on the edge and filling the pressure boundary
343  // expansion and the acceleration term. Multiplication by the
344  // normal is required
345  for (int i = 0; i < m_bnd_dim; i++)
346  {
347  m_fields[0]->ExtractElmtToBndPhys(n, Q[i], BndValues[i]);
348  }
349  m_PBndExp[n]->NormVectorIProductWRTBase(BndValues, Pvals);
350 
351  for (int i = 0; i < m_bnd_dim; i++)
352  {
353  m_fields[0]->ExtractElmtToBndPhys(n, Velocity[i],
354  BndValues[i]);
355  }
356  m_PBndExp[n]->NormVectorIProductWRTBase(BndValues, Uvals);
357 
358  // Get offset for next terms
359  cnt += m_PBndExp[n]->GetNcoeffs();
360  }
361  }
362  }
363  // If pressure terms are treated implicitly, we need to multiply
364  // by the relaxation parameter, and zero the correction term
365  if (m_implicitPressure)
366  {
368  m_pressureHBCs[m_intSteps - 1], 1,
369  m_pressureHBCs[m_intSteps - 1], 1);
370  }
372 }
373 } // namespace Nektar
Array< OneD, Array< OneD, NekDouble > > m_pressureHBCs
Storage for current and previous levels of high order pressure boundary conditions.
Definition: Extrapolate.h:241
int m_bnd_dim
bounday dimensionality
Definition: Extrapolate.h:217
MultiRegions::ExpListSharedPtr m_pressure
Pointer to field holding pressure field.
Definition: Extrapolate.h:201
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Velocity fields.
Definition: Extrapolate.h:198
Array< OneD, Array< OneD, NekDouble > > m_iprodnormvel
Storage for current and previous levels of the inner product of normal velocity.
Definition: Extrapolate.h:245
virtual void v_CalcNeumannPressureBCs(const Array< OneD, const Array< OneD, NekDouble >> &fields, const Array< OneD, const Array< OneD, NekDouble >> &N, NekDouble kinvis)
int m_intSteps
Maximum points used in pressure BC evaluation.
Definition: Extrapolate.h:235
Array< OneD, MultiRegions::ExpListSharedPtr > m_PBndExp
pressure boundary conditions expansion container
Definition: Extrapolate.h:223
void MountHOPBCs(int HBCdata, NekDouble kinvis, Array< OneD, NekDouble > &Q, Array< OneD, const NekDouble > &Advection)
Definition: Extrapolate.h:377
Array< OneD, const SpatialDomains::BoundaryConditionShPtr > m_PBndConds
pressure boundary conditions container
Definition: Extrapolate.h:220
LibUtilities::SessionReaderSharedPtr m_session
Definition: Extrapolate.h:190
static GLOBAL_MAPPING_EXPORT MappingSharedPtr Load(const LibUtilities::SessionReaderSharedPtr &pSession, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
Return a pointer to the mapping, creating it on first call.
Definition: Mapping.cpp:270
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
MappingExtrapolate(const LibUtilities::SessionReaderSharedPtr pSession, Array< OneD, MultiRegions::ExpListSharedPtr > pFields, MultiRegions::ExpListSharedPtr pPressure, const Array< OneD, int > pVel, const SolverUtils::AdvectionSharedPtr advObject)
Array< OneD, NekDouble > m_bcCorrection
static std::string className
Name of class.
GlobalMapping::MappingSharedPtr m_mapping
static ExtrapolateSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, MultiRegions::ExpListSharedPtr &pPressure, const Array< OneD, int > &pVel, const SolverUtils::AdvectionSharedPtr &advObject)
Creates an instance of this class.
virtual void v_CorrectPressureBCs(const Array< OneD, NekDouble > &pressure)
virtual void v_CalcNeumannPressureBCs(const Array< OneD, const Array< OneD, NekDouble >> &fields, const Array< OneD, const Array< OneD, NekDouble >> &N, NekDouble kinvis)
An abstract base class encapsulating the concept of advection of a vector field.
Definition: Advection.h:70
std::shared_ptr< SessionReader > SessionReaderSharedPtr
MultiRegions::Direction const DirCartesianMap[]
Definition: ExpList.h:91
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::shared_ptr< Advection > AdvectionSharedPtr
A shared pointer to an Advection object.
Definition: Advection.h:278
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
ExtrapolateFactory & GetExtrapolateFactory()
Definition: Extrapolate.cpp:48
double NekDouble
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
Definition: Vmath.cpp:209
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
Definition: Vmath.cpp:359
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition: Vmath.cpp:248
void Vdiv(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:284
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1255
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
Definition: Vmath.cpp:419