Nektar++
DisContField3DHomogeneous2D.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // File DisContField3DHomogeneous2D.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: Field definition for 3D domain with boundary
32 // conditions using LDG flux and a 2D homogeneous directions
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #include <boost/core/ignore_unused.hpp>
37 
41 
42 namespace Nektar
43 {
44  namespace MultiRegions
45  {
46 
49  m_bndCondExpansions(),
50  m_bndCondBndWeight(),
51  m_bndConditions()
52  {
53  }
54 
57  const LibUtilities::BasisKey &HomoBasis_y,
58  const LibUtilities::BasisKey &HomoBasis_z,
59  const NekDouble lhom_y,
60  const NekDouble lhom_z,
61  const bool useFFT,
62  const bool dealiasing,
63  const Collections::ImplementationType ImpType):
64  ExpList3DHomogeneous2D(pSession,HomoBasis_y,HomoBasis_z,lhom_y,lhom_z,useFFT,dealiasing,ImpType),
65  m_bndCondExpansions(),
66  m_bndCondBndWeight(),
67  m_bndConditions()
68  {
69  }
70 
72  ExpList3DHomogeneous2D (In,false),
73  m_bndCondExpansions (In.m_bndCondExpansions),
74  m_bndCondBndWeight (In.m_bndCondBndWeight),
75  m_bndConditions (In.m_bndConditions)
76  {
77  if(DeclareLinesSetCoeffPhys)
78  {
79  DisContFieldSharedPtr zero_line = std::dynamic_pointer_cast<DisContField> (In.m_lines[0]);
80 
81  for(int n = 0; n < m_lines.size(); ++n)
82  {
84  }
85 
86  SetCoeffPhys();
87  }
88  }
89 
92  const LibUtilities::BasisKey &HomoBasis_y,
93  const LibUtilities::BasisKey &HomoBasis_z,
94  const NekDouble lhom_y,
95  const NekDouble lhom_z,
96  const bool useFFT,
97  const bool dealiasing,
99  const std::string &variable,
100  const Collections::ImplementationType ImpType):
101  ExpList3DHomogeneous2D(pSession,HomoBasis_y,HomoBasis_z,lhom_y,lhom_z,useFFT,dealiasing,ImpType),
102  m_bndCondExpansions(),
103  m_bndCondBndWeight(),
104  m_bndConditions()
105  {
106  int i,n,nel;
107  DisContFieldSharedPtr line_zero;
108  SpatialDomains::BoundaryConditions bcs(pSession, graph1D);
109 
110  //
111  m_lines[0] = line_zero = MemoryManager<DisContField>::AllocateSharedPtr(pSession,graph1D,variable,ImpType);
112 
114  nel = m_lines[0]->GetExpSize();
115 
116  for(i = 0; i < nel; ++i)
117  {
118  (*m_exp).push_back(m_lines[0]->GetExp(i));
119  }
120 
121  int nylines = m_homogeneousBasis_y->GetNumPoints();
122  int nzlines = m_homogeneousBasis_z->GetNumPoints();
123 
124  for(n = 1; n < nylines*nzlines; ++n)
125  {
126  m_lines[n] = MemoryManager<DisContField>::AllocateSharedPtr(pSession,graph1D,variable,ImpType);
127  for(i = 0; i < nel; ++i)
128  {
129  (*m_exp).push_back((*m_exp)[i]);
130  }
131  }
132 
133  // Setup Default optimisation information.
134  nel = GetExpSize();
135 
136  SetCoeffPhys();
137 
138  SetupBoundaryConditions(HomoBasis_y,HomoBasis_z,lhom_y,lhom_z,bcs);
139  }
140 
142  {
143  }
144 
145 
147  const LibUtilities::BasisKey &HomoBasis_z,
148  const NekDouble lhom_y,
149  const NekDouble lhom_z,
151  {
152  // Setup an ExpList1DHomogeneous2D expansion for boundary
153  // conditions and link to class declared in m_lines.
154 
155  size_t nlines = m_lines.size();
156 
158 
159  size_t nbnd = bregions.size();
160 
163 
164  Array<OneD, MultiRegions::ExpListSharedPtr> LinesBndCondExp(nlines);
165 
166  m_bndConditions = m_lines[0]->UpdateBndConditions();
167 
168  for(int i = 0; i < nbnd; ++i)
169  {
170  for(int n = 0; n < nlines; ++n)
171  {
172  LinesBndCondExp[n] = m_lines[n]->UpdateBndCondExpansion(i);
173  }
174 
175  m_bndCondExpansions[i] = MemoryManager<ExpList1DHomogeneous2D>::AllocateSharedPtr(m_session,HomoBasis_y,HomoBasis_z,lhom_y,lhom_z,m_useFFT,false,LinesBndCondExp);
176 
177  }
178 
180  }
181 
183  const NekDouble time,
184  const std::string varName)
185  {
186  int n, m;
189 
190  for (n = 0; n < m_nz; ++n)
191  {
192  for (m = 0; m < m_ny; ++m)
193  {
195  time, varName, 0.5*m_lhom_y*(1.0+y[m]),
196  0.5*m_lhom_z*(1.0+z[n]));
197  }
198  }
199 
200  // Fourier transform coefficient space boundary values
201  for (n = 0; n < m_bndCondExpansions.size(); ++n)
202  {
203  if (time == 0.0 || m_bndConditions[n]->IsTimeDependent())
204  {
205  m_bndCondBndWeight[n] = 1.0;
206  m_bndCondExpansions[n]->HomogeneousFwdTrans(
209  }
210  }
211  }
212 
214  const Array<OneD, const NekDouble> &inarray,
215  Array<OneD, NekDouble> &outarray,
216  const StdRegions::ConstFactorMap &factors,
217  const StdRegions::VarCoeffMap &varcoeff,
218  const MultiRegions::VarFactorsMap &varfactors,
219  const Array<OneD, const NekDouble> &dirForcing,
220  const bool PhysSpaceForcing)
221  {
222  int n,m;
223  int cnt = 0;
224  int cnt1 = 0;
225  int nhom_modes_y = m_homogeneousBasis_y->GetNumModes();
226  int nhom_modes_z = m_homogeneousBasis_z->GetNumModes();
227  NekDouble beta_y;
228  NekDouble beta_z;
229  StdRegions::ConstFactorMap new_factors;
230 
232  Array<OneD, NekDouble> fce(inarray.size());
234 
235  // Fourier transform forcing function
236  if(m_WaveSpace)
237  {
238  fce = inarray;
239  }
240  else
241  {
242  HomogeneousFwdTrans(inarray,fce);
243  }
244 
245  for(n = 0; n < nhom_modes_z; ++n)
246  {
247  for(m = 0; m < nhom_modes_y; ++m)
248  {
249  beta_z = 2*M_PI*(n/2)/m_lhom_z;
250  beta_y = 2*M_PI*(m/2)/m_lhom_y;
251  new_factors = factors;
252  new_factors[StdRegions::eFactorLambda] +=
253  beta_y*beta_y + beta_z*beta_z;
254 
255  wfce = (PhysSpaceForcing)? fce+cnt:fce+cnt1;
256  m_lines[n]->HelmSolve(wfce,
257  e_out = outarray + cnt1,
258  new_factors,
259  varcoeff, varfactors,dirForcing,
260  PhysSpaceForcing);
261 
262  cnt += m_lines[n]->GetTotPoints();
263  cnt1 += m_lines[n]->GetNcoeffs();
264  }
265  }
266  }
267 
269  const NekDouble time,
270  const std::string varName,
271  const NekDouble x2_in,
272  const NekDouble x3_in)
273  {
274  boost::ignore_unused(x2_in, x3_in);
275  EvaluateBoundaryConditions(time, varName);
276  }
277 
279  {
280  return GetBndCondExpansions();
281  }
282 
284  {
285  return GetBndConditions();
286  }
287 
289  {
290  return UpdateBndCondExpansion(i);
291  }
292 
294  {
295  return UpdateBndConditions();
296  }
297 
299  {
300  if(m_BCtoElmMap.size() == 0)
301  {
302  Array<OneD, int> ElmtID_tmp;
303  Array<OneD, int> EdgeID_tmp;
304 
305  m_lines[0]->GetBoundaryToElmtMap(ElmtID_tmp,EdgeID_tmp);
306  int nel_per_lines = m_lines[0]->GetExpSize();
307  int nlines = m_lines.size();
308 
309  int MapSize = ElmtID_tmp.size();
310 
311  m_BCtoElmMap = Array<OneD, int>(nlines*MapSize);
312  m_BCtoEdgMap = Array<OneD, int>(nlines*MapSize);
313  if (MapSize > 0)
314  {
315  int i ,j, n, cnt;
316  int cntLine = 0;
317  for (cnt=n=0; n < m_bndCondExpansions.size(); ++n)
318  {
319  int lineExpSize = m_lines[0]
320  ->GetBndCondExpansions()[n]
321  ->GetExpSize();
322  for (i = 0; i < lineExpSize ; ++i, ++cntLine)
323  {
324  for(j = 0; j < nlines; j++)
325  {
326  m_BCtoElmMap[cnt+i+j*lineExpSize] =
327  ElmtID_tmp[cntLine]+j*nel_per_lines;
328  m_BCtoEdgMap[cnt+i+j*lineExpSize] =
329  EdgeID_tmp[cntLine];
330  }
331  }
332  cnt += m_bndCondExpansions[n]->GetExpSize();
333  }
334  }
335  }
336  ElmtID = m_BCtoElmMap;
337  EdgeID = m_BCtoEdgMap;
338  }
339 
341  std::shared_ptr<ExpList> &result,
342  const bool DeclareCoeffPhysArrays)
343  {
344  int n, cnt, nq;
345  int offsetOld, offsetNew;
346 
347  std::vector<unsigned int> eIDs;
348  Array<OneD, int> ElmtID,EdgeID;
349  GetBoundaryToElmtMap(ElmtID,EdgeID);
350 
351  // Skip other boundary regions
352  for (cnt = n = 0; n < i; ++n)
353  {
354  cnt += m_bndCondExpansions[n]->GetExpSize();
355  }
356 
357  // Populate eIDs with information from BoundaryToElmtMap
358  for (n = 0; n < m_bndCondExpansions[i]->GetExpSize(); ++n)
359  {
360  eIDs.push_back(ElmtID[cnt+n]);
361  }
362 
363  // Create expansion list
364  result =
366  (*this, eIDs);
367 
368  // Copy phys and coeffs to new explist
369  if ( DeclareCoeffPhysArrays)
370  {
371  Array<OneD, NekDouble> tmp1, tmp2;
372  for (n = 0; n < result->GetExpSize(); ++n)
373  {
374  nq = GetExp(ElmtID[cnt+n])->GetTotPoints();
375  offsetOld = GetPhys_Offset(ElmtID[cnt+n]);
376  offsetNew = result->GetPhys_Offset(n);
377  Vmath::Vcopy(nq, tmp1 = GetPhys()+ offsetOld, 1,
378  tmp2 = result->UpdatePhys()+ offsetNew, 1);
379 
380  nq = GetExp(ElmtID[cnt+n])->GetNcoeffs();
381  offsetOld = GetCoeff_Offset(ElmtID[cnt+n]);
382  offsetNew = result->GetCoeff_Offset(n);
383  Vmath::Vcopy(nq, tmp1 = GetCoeffs()+ offsetOld, 1,
384  tmp2 = result->UpdateCoeffs()+ offsetNew, 1);
385  }
386  }
387 
388  // Set wavespace value
389  result->SetWaveSpace(GetWaveSpace());
390  }
391 
392  } // end of namespace
393 } //end of namespace
Describes the specification for a Basis.
Definition: Basis.h:50
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
void EvaluateBoundaryConditions(const NekDouble time=0.0, const std::string varName="")
Array< OneD, int > m_BCtoElmMap
Storage space for the boundary to element and boundary to trace map. This member variable is really a...
virtual Array< OneD, SpatialDomains::BoundaryConditionShPtr > & v_UpdateBndConditions()
void GetBoundaryToElmtMap(Array< OneD, int > &ElmtID, Array< OneD, int > &EdgeID)
Set up a list of element ids and edge ids the link to the boundary conditions.
virtual const Array< OneD, const SpatialDomains::BoundaryConditionShPtr > & v_GetBndConditions()
virtual void v_GetBndElmtExpansion(int i, std::shared_ptr< ExpList > &result, const bool DeclareCoeffPhysArrays)
virtual const Array< OneD, const std::shared_ptr< ExpList > > & v_GetBndCondExpansions(void)
virtual void v_HelmSolve(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const StdRegions::ConstFactorMap &factors, const StdRegions::VarCoeffMap &varcoeff, const MultiRegions::VarFactorsMap &varfactors, const Array< OneD, const NekDouble > &dirForcing, const bool PhysSpaceForcing)
virtual void v_EvaluateBoundaryConditions(const NekDouble time=0.0, const std::string varName="", const NekDouble x2_in=NekConstants::kNekUnsetDouble, const NekDouble x3_in=NekConstants::kNekUnsetDouble)
const Array< OneD, const MultiRegions::ExpListSharedPtr > & GetBndCondExpansions()
const Array< OneD, const SpatialDomains::BoundaryConditionShPtr > & GetBndConditions()
Array< OneD, SpatialDomains::BoundaryConditionShPtr > & UpdateBndConditions()
Array< OneD, SpatialDomains::BoundaryConditionShPtr > m_bndConditions
void SetupBoundaryConditions(const LibUtilities::BasisKey &HomoBasis_y, const LibUtilities::BasisKey &HomoBasis_z, const NekDouble lhom_y, const NekDouble lhom_z, SpatialDomains::BoundaryConditions &bcs)
virtual std::shared_ptr< ExpList > & v_UpdateBndCondExpansion(int i)
Array< OneD, MultiRegions::ExpListSharedPtr > m_bndCondExpansions
Abstraction of a one-dimensional multi-elemental expansion which is merely a collection of local expa...
void SetCoeffPhys(void)
Definition of the total number of degrees of freedom and quadrature points. Sets up the storage for m...
int m_nz
Number of modes = number of poitns in z direction.
LibUtilities::BasisSharedPtr m_homogeneousBasis_y
Definition of the total number of degrees of freedom and quadrature points. Sets up the storage for m...
NekDouble m_lhom_z
Width of homogeneous direction z.
int m_ny
Number of modes = number of poitns in y direction.
Array< OneD, ExpListSharedPtr > m_lines
Vector of ExpList, will be filled with ExpList1D.
LibUtilities::BasisSharedPtr m_homogeneousBasis_z
Base expansion in z direction.
NekDouble m_lhom_y
Width of homogeneous direction y.
void HomogeneousFwdTrans(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, bool Shuff=true, bool UnShuff=true)
Array< OneD, NekDouble > & UpdateCoeffs()
This function returns (a reference to) the array (implemented as m_coeffs) containing all local expa...
Definition: ExpList.h:2450
const Array< OneD, const NekDouble > & GetCoeffs() const
This function returns (a reference to) the array (implemented as m_coeffs) containing all local expa...
Definition: ExpList.h:2293
const Array< OneD, const NekDouble > & GetPhys() const
This function returns (a reference to) the array (implemented as m_phys) containing the function ev...
Definition: ExpList.h:2392
int GetCoeff_Offset(int n) const
Get the start offset position for a global list of m_coeffs correspoinding to element n.
Definition: ExpList.h:2431
int GetExpSize(void)
This function returns the number of elements in the expansion.
Definition: ExpList.h:2401
std::shared_ptr< LocalRegions::ExpansionVector > m_exp
The list of local expansions.
Definition: ExpList.h:1290
const std::shared_ptr< LocalRegions::ExpansionVector > GetExp() const
This function returns the vector of elements in the expansion.
Definition: ExpList.h:2422
LibUtilities::SessionReaderSharedPtr m_session
Session.
Definition: ExpList.h:1223
bool GetWaveSpace(void) const
This function returns the third direction expansion condition, which can be in wave space (coefficien...
Definition: ExpList.h:1899
int GetPhys_Offset(int n) const
Get the start offset position for a global list of m_phys correspoinding to element n.
Definition: ExpList.h:2439
const BoundaryRegionCollection & GetBoundaryRegions(void) const
Definition: Conditions.h:238
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< DisContField > DisContFieldSharedPtr
Definition: DisContField.h:385
std::map< StdRegions::ConstFactorType, Array< OneD, NekDouble > > VarFactorsMap
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
Definition: Conditions.h:217
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174
std::map< StdRegions::VarCoeffType, Array< OneD, NekDouble > > VarCoeffMap
Definition: StdRegions.hpp:272
std::map< ConstFactorType, NekDouble > ConstFactorMap
Definition: StdRegions.hpp:314
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
double NekDouble
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1199