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