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_bndConditions()
51  {
52  }
53 
56  const LibUtilities::BasisKey &HomoBasis_y,
57  const LibUtilities::BasisKey &HomoBasis_z,
58  const NekDouble lhom_y,
59  const NekDouble lhom_z,
60  const bool useFFT,
61  const bool dealiasing,
62  const Collections::ImplementationType ImpType):
63  ExpList3DHomogeneous2D(pSession,HomoBasis_y,HomoBasis_z,lhom_y,lhom_z,useFFT,dealiasing,ImpType),
66  {
67  }
68 
70  ExpList3DHomogeneous2D (In,false),
73  {
74  if(DeclareLinesSetCoeffPhys)
75  {
76  DisContField1DSharedPtr zero_line = std::dynamic_pointer_cast<DisContField1D> (In.m_lines[0]);
77 
78  for(int n = 0; n < m_lines.num_elements(); ++n)
79  {
81  }
82 
83  SetCoeffPhys();
84  }
85  }
86 
89  const LibUtilities::BasisKey &HomoBasis_y,
90  const LibUtilities::BasisKey &HomoBasis_z,
91  const NekDouble lhom_y,
92  const NekDouble lhom_z,
93  const bool useFFT,
94  const bool dealiasing,
96  const std::string &variable,
97  const Collections::ImplementationType ImpType):
98  ExpList3DHomogeneous2D(pSession,HomoBasis_y,HomoBasis_z,lhom_y,lhom_z,useFFT,dealiasing,ImpType),
101  {
102  int i,n,nel;
103  DisContField1DSharedPtr line_zero;
104  SpatialDomains::BoundaryConditions bcs(pSession, graph1D);
105 
106  //
107  m_lines[0] = line_zero = MemoryManager<DisContField1D>::AllocateSharedPtr(pSession,graph1D,variable,ImpType);
108 
110  nel = m_lines[0]->GetExpSize();
111 
112  for(i = 0; i < nel; ++i)
113  {
114  (*m_exp).push_back(m_lines[0]->GetExp(i));
115  }
116 
117  int nylines = m_homogeneousBasis_y->GetNumPoints();
118  int nzlines = m_homogeneousBasis_z->GetNumPoints();
119 
120  for(n = 1; n < nylines*nzlines; ++n)
121  {
122  m_lines[n] = MemoryManager<DisContField1D>::AllocateSharedPtr(pSession,graph1D,variable,ImpType);
123  for(i = 0; i < nel; ++i)
124  {
125  (*m_exp).push_back((*m_exp)[i]);
126  }
127  }
128 
129  // Setup Default optimisation information.
130  nel = GetExpSize();
131 
134 
135  SetCoeffPhys();
136 
137  SetupBoundaryConditions(HomoBasis_y,HomoBasis_z,lhom_y,lhom_z,bcs);
138  }
139 
141  {
142  }
143 
144 
146  const LibUtilities::BasisKey &HomoBasis_z,
147  const NekDouble lhom_y,
148  const NekDouble lhom_z,
150  {
151  int i,n;
152 
153  // Setup an ExpList1DHomogeneous2D expansion for boundary
154  // conditions and link to class declared in m_lines.
155 
156  int nlines = m_lines.num_elements();
157 
159 
160  int nbnd = bregions.size();
161 
162 
164 
165  Array<OneD, MultiRegions::ExpListSharedPtr> LinesBndCondExp(nlines);
166 
167  m_bndConditions = m_lines[0]->UpdateBndConditions();
168 
169  for(i = 0; i < nbnd; ++i)
170  {
171  for(n = 0; n < nlines; ++n)
172  {
173  LinesBndCondExp[n] = m_lines[n]->UpdateBndCondExpansion(i);
174  }
175 
176  m_bndCondExpansions[i] = MemoryManager<ExpList1DHomogeneous2D>::AllocateSharedPtr(m_session,HomoBasis_y,HomoBasis_z,lhom_y,lhom_z,m_useFFT,false,LinesBndCondExp);
177 
178  }
179 
181  }
182 
184  const NekDouble time,
185  const std::string varName)
186  {
187  int n, m;
190 
191  for (n = 0; n < m_nz; ++n)
192  {
193  for (m = 0; m < m_ny; ++m)
194  {
196  time, varName, 0.5*m_lhom_y*(1.0+y[m]),
197  0.5*m_lhom_z*(1.0+z[n]));
198  }
199  }
200 
201  // Fourier transform coefficient space boundary values
202  for (n = 0; n < m_bndCondExpansions.num_elements(); ++n)
203  {
204  if (time == 0.0 || m_bndConditions[n]->IsTimeDependent())
205  {
206  m_bndCondExpansions[n]->HomogeneousFwdTrans(
209  }
210  }
211  }
212 
214  const Array<OneD, const NekDouble> &inarray,
215  Array<OneD, NekDouble> &outarray,
216  const FlagList &flags,
217  const StdRegions::ConstFactorMap &factors,
218  const StdRegions::VarCoeffMap &varcoeff,
219  const MultiRegions::VarFactorsMap &varfactors,
220  const Array<OneD, const NekDouble> &dirForcing,
221  const bool PhysSpaceForcing)
222  {
223  int n,m;
224  int cnt = 0;
225  int cnt1 = 0;
226  int nhom_modes_y = m_homogeneousBasis_y->GetNumModes();
227  int nhom_modes_z = m_homogeneousBasis_z->GetNumModes();
228  NekDouble beta_y;
229  NekDouble beta_z;
230  StdRegions::ConstFactorMap new_factors;
231 
233  Array<OneD, NekDouble> fce(inarray.num_elements());
235 
236  // Fourier transform forcing function
237  if(m_WaveSpace)
238  {
239  fce = inarray;
240  }
241  else
242  {
243  HomogeneousFwdTrans(inarray,fce);
244  }
245 
246  for(n = 0; n < nhom_modes_z; ++n)
247  {
248  for(m = 0; m < nhom_modes_y; ++m)
249  {
250  beta_z = 2*M_PI*(n/2)/m_lhom_z;
251  beta_y = 2*M_PI*(m/2)/m_lhom_y;
252  new_factors = factors;
253  new_factors[StdRegions::eFactorLambda] +=
254  beta_y*beta_y + beta_z*beta_z;
255 
256  wfce = (PhysSpaceForcing)? fce+cnt:fce+cnt1;
257  m_lines[n]->HelmSolve(wfce,
258  e_out = outarray + cnt1,
259  flags, new_factors,
260  varcoeff, varfactors,dirForcing,
261  PhysSpaceForcing);
262 
263  cnt += m_lines[n]->GetTotPoints();
264  cnt1 += m_lines[n]->GetNcoeffs();
265  }
266  }
267  }
268 
270  const NekDouble time,
271  const std::string varName,
272  const NekDouble x2_in,
273  const NekDouble x3_in)
274  {
275  boost::ignore_unused(x2_in, x3_in);
276  EvaluateBoundaryConditions(time, varName);
277  }
278 
280  {
281  return GetBndCondExpansions();
282  }
283 
285  {
286  return GetBndConditions();
287  }
288 
290  {
291  return UpdateBndCondExpansion(i);
292  }
293 
295  {
296  return UpdateBndConditions();
297  }
298 
300  {
301  if(m_BCtoElmMap.num_elements() == 0)
302  {
303  Array<OneD, int> ElmtID_tmp;
304  Array<OneD, int> EdgeID_tmp;
305 
306  m_lines[0]->GetBoundaryToElmtMap(ElmtID_tmp,EdgeID_tmp);
307  int nel_per_lines = m_lines[0]->GetExpSize();
308  int nlines = m_lines.num_elements();
309 
310  int MapSize = ElmtID_tmp.num_elements();
311 
312  m_BCtoElmMap = Array<OneD, int>(nlines*MapSize);
313  m_BCtoEdgMap = Array<OneD, int>(nlines*MapSize);
314  if (MapSize > 0)
315  {
316  int i ,j, n, cnt;
317  int cntLine = 0;
318  for (cnt=n=0; n < m_bndCondExpansions.num_elements(); ++n)
319  {
320  int lineExpSize = m_lines[0]
321  ->GetBndCondExpansions()[n]
322  ->GetExpSize();
323  for (i = 0; i < lineExpSize ; ++i, ++cntLine)
324  {
325  for(j = 0; j < nlines; j++)
326  {
327  m_BCtoElmMap[cnt+i+j*lineExpSize] =
328  ElmtID_tmp[cntLine]+j*nel_per_lines;
329  m_BCtoEdgMap[cnt+i+j*lineExpSize] =
330  EdgeID_tmp[cntLine];
331  }
332  }
333  cnt += m_bndCondExpansions[n]->GetExpSize();
334  }
335  }
336  }
337  ElmtID = m_BCtoElmMap;
338  EdgeID = m_BCtoEdgMap;
339  }
340 
342  std::shared_ptr<ExpList> &result,
343  const bool DeclareCoeffPhysArrays)
344  {
345  int n, cnt, nq;
346  int offsetOld, offsetNew;
347 
348  std::vector<unsigned int> eIDs;
349  Array<OneD, int> ElmtID,EdgeID;
350  GetBoundaryToElmtMap(ElmtID,EdgeID);
351 
352  // Skip other boundary regions
353  for (cnt = n = 0; n < i; ++n)
354  {
355  cnt += m_bndCondExpansions[n]->GetExpSize();
356  }
357 
358  // Populate eIDs with information from BoundaryToElmtMap
359  for (n = 0; n < m_bndCondExpansions[i]->GetExpSize(); ++n)
360  {
361  eIDs.push_back(ElmtID[cnt+n]);
362  }
363 
364  // Create expansion list
365  result =
367  (*this, eIDs);
368 
369  // Copy phys and coeffs to new explist
370  if ( DeclareCoeffPhysArrays)
371  {
372  Array<OneD, NekDouble> tmp1, tmp2;
373  for (n = 0; n < result->GetExpSize(); ++n)
374  {
375  nq = GetExp(ElmtID[cnt+n])->GetTotPoints();
376  offsetOld = GetPhys_Offset(ElmtID[cnt+n]);
377  offsetNew = result->GetPhys_Offset(n);
378  Vmath::Vcopy(nq, tmp1 = GetPhys()+ offsetOld, 1,
379  tmp2 = result->UpdatePhys()+ offsetNew, 1);
380 
381  nq = GetExp(ElmtID[cnt+n])->GetNcoeffs();
382  offsetOld = GetCoeff_Offset(ElmtID[cnt+n]);
383  offsetNew = result->GetCoeff_Offset(n);
384  Vmath::Vcopy(nq, tmp1 = GetCoeffs()+ offsetOld, 1,
385  tmp2 = result->UpdateCoeffs()+ offsetNew, 1);
386  }
387  }
388 
389  // Set wavespace value
390  result->SetWaveSpace(GetWaveSpace());
391  }
392 
393  } // end of namespace
394 } //end of namespace
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:2161
Array< OneD, SpatialDomains::BoundaryConditionShPtr > m_bndConditions
Array< OneD, SpatialDomains::BoundaryConditionShPtr > & UpdateBndConditions()
void HomogeneousFwdTrans(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, CoeffState coeffstate=eLocal, bool Shuff=true, bool UnShuff=true)
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:163
void EvaluateBoundaryConditions(const NekDouble time=0.0, const std::string varName="")
std::shared_ptr< LocalRegions::ExpansionVector > m_exp
The list of local expansions.
Definition: ExpList.h:1090
const Array< OneD, const MultiRegions::ExpListSharedPtr > & GetBndCondExpansions()
NekOptimize::GlobalOptParamSharedPtr m_globalOptParam
Definition: ExpList.h:1106
virtual const Array< OneD, const SpatialDomains::BoundaryConditionShPtr > & v_GetBndConditions()
Array< OneD, NekDouble > & UpdateCoeffs()
This function returns (a reference to) the array (implemented as m_coeffs) containing all local expa...
Definition: ExpList.h:2219
virtual const Array< OneD, const std::shared_ptr< ExpList > > & v_GetBndCondExpansions(void)
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:2062
virtual Array< OneD, SpatialDomains::BoundaryConditionShPtr > & v_UpdateBndConditions()
void SetupBoundaryConditions(const LibUtilities::BasisKey &HomoBasis_y, const LibUtilities::BasisKey &HomoBasis_z, const NekDouble lhom_y, const NekDouble lhom_z, SpatialDomains::BoundaryConditions &bcs)
std::map< ConstFactorType, NekDouble > ConstFactorMap
Definition: StdRegions.hpp:294
NekDouble m_lhom_z
Width of homogeneous direction z.
Array< OneD, MultiRegions::ExpListSharedPtr > m_bndCondExpansions
int GetExpSize(void)
This function returns the number of elements in the expansion.
Definition: ExpList.h:2170
const std::shared_ptr< LocalRegions::ExpansionVector > GetExp() const
This function returns the vector of elements in the expansion.
Definition: ExpList.h:2191
bool GetWaveSpace(void) const
This function returns the third direction expansion condition, which can be in wave space (coefficien...
Definition: ExpList.h:1657
Array< OneD, ExpListSharedPtr > m_lines
Vector of ExpList, will be filled with ExpList1D.
Array< OneD, int > m_BCtoElmMap
Storage space for the boundary to element and boundary to trace map. This member variable is really a...
LibUtilities::BasisSharedPtr m_homogeneousBasis_z
Base expansion in z direction.
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)
std::map< StdRegions::VarCoeffType, Array< OneD, NekDouble > > VarCoeffMap
Definition: StdRegions.hpp:264
void SetCoeffPhys(void)
Definition of the total number of degrees of freedom and quadrature points. Sets up the storage for m...
NekDouble m_lhom_y
Width of homogeneous direction y.
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
Definition: Conditions.h:217
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
This class is the abstraction of a global discontinuous two- dimensional spectral/hp element expansio...
virtual void v_HelmSolve(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const FlagList &flags, const StdRegions::ConstFactorMap &factors, const StdRegions::VarCoeffMap &varcoeff, const MultiRegions::VarFactorsMap &varfactors, const Array< OneD, const NekDouble > &dirForcing, const bool PhysSpaceForcing)
LibUtilities::SessionReaderSharedPtr m_session
Session.
Definition: ExpList.h:1023
double NekDouble
const Array< OneD, const SpatialDomains::BoundaryConditionShPtr > & GetBndConditions()
Defines a list of flags.
int m_ny
Number of modes = number of poitns in y direction.
LibUtilities::BasisSharedPtr m_homogeneousBasis_y
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.
std::shared_ptr< DisContField1D > DisContField1DSharedPtr
virtual std::shared_ptr< ExpList > & v_UpdateBndCondExpansion(int i)
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 void v_GetBndElmtExpansion(int i, std::shared_ptr< ExpList > &result, const bool DeclareCoeffPhysArrays)
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:2200
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:2208
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1064
Abstraction of a one-dimensional multi-elemental expansion which is merely a collection of local expa...
Describes the specification for a Basis.
Definition: Basis.h:49
std::shared_ptr< SessionReader > SessionReaderSharedPtr
const BoundaryRegionCollection & GetBoundaryRegions(void) const
Definition: Conditions.h:238
std::map< StdRegions::ConstFactorType, Array< OneD, NekDouble > > VarFactorsMap