Nektar++
Field.hpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Field.hpp
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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Field converter module base classes.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <boost/shared_ptr.hpp>
37 
44 
45 #include <MultiRegions/ExpList.h>
52 
58 
59 
60 using namespace std;
61 
62 namespace Nektar
63 {
64 namespace Utilities
65 {
66 
67 struct Field {
68  Field() : m_verbose(false),
69  m_declareExpansionAsContField(false),
70  m_declareExpansionAsDisContField(false),
71  m_writeBndFld(false),
72  m_fldToBnd(false),
73  m_addNormals(false),
74  m_setUpEquiSpacedFields(false),
75  m_fieldPts(LibUtilities::NullPtsField){}
76 
78  {
79  if (m_session)
80  {
81  m_session->Finalise();
82  }
83  }
84  bool m_verbose;
85  vector<LibUtilities::FieldDefinitionsSharedPtr> m_fielddef;
86  vector<vector<double> > m_data;
87  vector<MultiRegions::ExpListSharedPtr> m_exp;
88 
91 
92  bool m_useFFT;
93 
99  map<string, vector<string> > m_inputfiles;
100 
102  vector<unsigned int> m_bndRegionsToWrite;
105 
108 
110 
112 
114  bool fldfilegiven = false)
115  {
116 
118 
119  // Set up expansion list
120  int expdim = m_graph->GetMeshDimension();
121  bool dealiasing = false;
122 
123  m_session->MatchSolverInfo("USEFFT", "FFTW", m_useFFT, false);
124 
125  switch (expdim)
126  {
127  case 1:
128  {
129  ASSERTL0(NumHomogeneousDir <= 2,
130  "Quasi-3D approach is only set up for 1 or 2 "
131  "homogeneous directions");
132 
133  if (NumHomogeneousDir == 1)
134  {
136 
137  // Define Homogeneous expansion
138  int nplanes;
139  NekDouble ly;
141 
142  if(fldfilegiven)
143  {
144  nplanes = m_fielddef[0]->m_numModes[1];
145  ly = m_fielddef[0]->m_homogeneousLengths[0];
146  btype = m_fielddef[0]->m_basis[1];
147  }
148  else
149  {
150  m_session->LoadParameter("HomModesZ", nplanes);
151  m_session->LoadParameter("LY",ly);
152  btype = LibUtilities::eFourier;
153  }
154 
155  // Choose points to be at evenly spaced points at
156  // nplanes points
158  Pkey(nplanes, LibUtilities::ePolyEvenlySpaced);
159 
160  const LibUtilities::BasisKey Bkey(btype, nplanes, Pkey);
161 
162 
163 
164  if(m_declareExpansionAsContField||
165  m_declareExpansionAsDisContField)
166  {
167  ASSERTL0(false,"ContField2DHomogeneous1D or "
168  "DisContField2DHomogenenous1D has "
169  "not been implemented");
170  }
171 
172  Exp2DH1 = MemoryManager<MultiRegions::
174  AllocateSharedPtr(m_session, Bkey, ly,
175  m_useFFT, dealiasing,
176  m_graph);
177  exp = Exp2DH1;
178  }
179  else if (NumHomogeneousDir == 2)
180  {
182 
183  int nylines,nzlines;
184  NekDouble ly,lz;
185  LibUtilities::BasisType btype1,btype2;
186 
187  if(fldfilegiven)
188  {
189  nylines = m_fielddef[0]->m_numModes[1];
190  nzlines = m_fielddef[0]->m_numModes[2];
191  ly = m_fielddef[0]->m_homogeneousLengths[0];
192  lz = m_fielddef[0]->m_homogeneousLengths[1];
193  btype1 = m_fielddef[0]->m_basis[1];
194  btype2 = m_fielddef[0]->m_basis[2];
195  }
196  else
197  {
198  m_session->LoadParameter("HomModesY", nylines);
199  m_session->LoadParameter("HomModesZ", nzlines);
200  m_session->LoadParameter("LY",ly);
201  m_session->LoadParameter("LZ",lz);
202  btype1 = LibUtilities::eFourier;
203  btype2 = LibUtilities::eFourier;
204  }
205 
206  // Choose points to be at evenly spaced points at
207  // nplanes points
209  PkeyY(nylines, LibUtilities::ePolyEvenlySpaced);
210  const LibUtilities::BasisKey BkeyY(btype1, nylines, PkeyY);
211 
213  PkeyZ(nzlines, LibUtilities::ePolyEvenlySpaced);
214  const LibUtilities::BasisKey BkeyZ(btype2, nzlines, PkeyZ);
215 
216  if(m_declareExpansionAsContField)
217  {
218  Exp3DH2 = MemoryManager<MultiRegions::
220  AllocateSharedPtr(m_session, BkeyY, BkeyZ,
221  ly, lz, m_useFFT, dealiasing,
222  m_graph,
223  m_session->GetVariable(0));
224  }
225  else if(m_declareExpansionAsDisContField)
226  {
227  Exp3DH2 = MemoryManager<MultiRegions::
229  AllocateSharedPtr(m_session, BkeyY, BkeyZ,
230  ly, lz, m_useFFT, dealiasing,
231  m_graph,
232  m_session->GetVariable(0));
233  }
234  else
235  {
236  Exp3DH2 = MemoryManager<MultiRegions::
238  AllocateSharedPtr(m_session, BkeyY, BkeyZ,
239  ly, lz, m_useFFT, dealiasing,
240  m_graph);
241  }
242 
243  exp = Exp3DH2;
244  }
245  else
246  {
248 
249  if(m_declareExpansionAsContField)
250  {
252  ::AllocateSharedPtr(m_session, m_graph,
253  m_session->GetVariable(0));
254  }
255  else if(m_declareExpansionAsDisContField)
256  {
258  ::AllocateSharedPtr(m_session, m_graph,
259  m_session->GetVariable(0));
260  }
261  else
262  {
264  ::AllocateSharedPtr(m_session, m_graph);
265  }
266 
267  exp = Exp1D;
268  }
269  }
270  break;
271  case 2:
272  {
273  ASSERTL0(NumHomogeneousDir <= 1,
274  "NumHomogeneousDir is only set up for 1");
275 
276  if (NumHomogeneousDir == 1)
277  {
279 
280  // Define Homogeneous expansion
281  int nplanes;
282  NekDouble lz;
284 
285  if(fldfilegiven)
286  {
287  nplanes = m_fielddef[0]->m_numModes[2];
288  lz = m_fielddef[0]->m_homogeneousLengths[0];
289  btype = m_fielddef[0]->m_basis[2];
290  }
291  else
292  {
293  m_session->LoadParameter("HomModesZ", nplanes);
294  m_session->LoadParameter("LZ",lz);
295  btype = LibUtilities::eFourier;
296  }
297 
298  // Choose points to be at evenly spaced points at
299  // nplanes points
301  Pkey(nplanes, LibUtilities::ePolyEvenlySpaced);
302 
303  const LibUtilities::BasisKey Bkey(btype, nplanes, Pkey);
304 
305  if(m_declareExpansionAsContField)
306  {
307  Exp3DH1 = MemoryManager<MultiRegions::
309  AllocateSharedPtr(m_session, Bkey, lz, m_useFFT,
310  dealiasing, m_graph,
311  m_session->GetVariable(0));
312  }
313  else if (m_declareExpansionAsDisContField)
314  {
315  Exp3DH1 = MemoryManager<MultiRegions::
317  AllocateSharedPtr(m_session,
318  Bkey, lz, m_useFFT,
319  dealiasing, m_graph,
320  m_session->GetVariable(0));
321  }
322  else
323  {
324  Exp3DH1 = MemoryManager<MultiRegions::
326  AllocateSharedPtr(m_session, Bkey, lz, m_useFFT,
327  dealiasing, m_graph);
328  }
329  exp = Exp3DH1;
330  }
331  else
332  {
334 
335  if(m_declareExpansionAsContField)
336  {
338  ::AllocateSharedPtr(m_session,m_graph,
339  m_session->GetVariable(0));
340  }
341  else if(m_declareExpansionAsDisContField)
342  {
344  ::AllocateSharedPtr(m_session,m_graph,
345  m_session->GetVariable(0));
346  }
347  else
348  {
350  ::AllocateSharedPtr(m_session,m_graph);
351  }
352 
353  exp = Exp2D;
354  }
355  }
356  break;
357  case 3:
358  {
360 
361  if(m_declareExpansionAsContField)
362  {
364  ::AllocateSharedPtr(m_session,m_graph,
365  m_session->GetVariable(0));
366  }
367  else if(m_declareExpansionAsDisContField)
368  {
370  ::AllocateSharedPtr(m_session,m_graph,
371  m_session->GetVariable(0));
372  }
373  else
374  {
376  ::AllocateSharedPtr(m_session, m_graph);
377  }
378 
379  exp = Exp3D;
380  }
381  break;
382  default:
383  ASSERTL0(false, "Expansion dimension not recognised");
384  break;
385  }
386 
387  return exp;
388  };
389 
391  string var = "DefaultVar",
392  bool NewField = false)
393  {
395  switch (m_graph->GetMeshDimension())
396  {
397  case 1:
398  {
399  if (NumHomogeneousDir == 1)
400  {
401  ASSERTL0(m_declareExpansionAsContField ||
402  m_declareExpansionAsDisContField,
403  "ContField2DHomogeneous1D or "
404  "DisContField2DHomogenenous1D has not been "
405  "implemented");
406 
408  boost::dynamic_pointer_cast<MultiRegions::
409  ExpList2DHomogeneous1D>(m_exp[0]);
410 
413  AllocateSharedPtr(*tmp2);
414 
415  }
416  else if (NumHomogeneousDir == 2)
417  {
418  if(m_declareExpansionAsContField)
419  {
421  boost::dynamic_pointer_cast<MultiRegions::
422  ContField3DHomogeneous2D>(m_exp[0]);
423 
426  AllocateSharedPtr(*tmp2);
427  }
428  else if(m_declareExpansionAsDisContField)
429  {
431  boost::dynamic_pointer_cast<MultiRegions::
433 
436  AllocateSharedPtr(*tmp2);
437  }
438  else
439  {
441  boost::dynamic_pointer_cast<MultiRegions::
442  ExpList3DHomogeneous2D>(m_exp[0]);
443 
446  AllocateSharedPtr(*tmp2);
447  }
448 
449 
450  }
451  else
452  {
453  if(m_declareExpansionAsContField)
454  {
456  boost::dynamic_pointer_cast<MultiRegions::
457  ContField1D>(m_exp[0]);
458 
460  AllocateSharedPtr(m_session,m_graph,var);
461  }
462  else if(m_declareExpansionAsDisContField)
463  {
465  boost::dynamic_pointer_cast<MultiRegions::
466  DisContField1D>(m_exp[0]);
467 
469  AllocateSharedPtr(m_session,m_graph,var);
470  }
471  else
472  {
474  boost::dynamic_pointer_cast<MultiRegions::
475  ExpList1D>(m_exp[0]);
476 
478  AllocateSharedPtr(*tmp2);
479  }
480 
481  }
482  }
483  break;
484  case 2:
485  {
486  if (NumHomogeneousDir == 1)
487  {
488  if(m_declareExpansionAsContField)
489  {
490  if(NewField)
491  {
492  bool dealiasing = false;
493 
495  ContField3DHomogeneous1D>::AllocateSharedPtr(
496  m_session,
497  m_exp[0]->GetHomogeneousBasis()
498  ->GetBasisKey(),
499  m_exp[0]->GetHomoLen(),
500  m_useFFT, dealiasing, m_graph, var);
501  }
502  else
503  {
505  boost::dynamic_pointer_cast<MultiRegions::
506  ContField3DHomogeneous1D>(m_exp[0]);
507 
508  ASSERTL0(tmp2,"Failed to type cast m_exp[0]");
511  AllocateSharedPtr(*tmp2);
512  }
513  }
514  else if(m_declareExpansionAsDisContField)
515  {
516  if(NewField)
517  {
518  bool dealiasing = false;
519 
521  DisContField3DHomogeneous1D>::AllocateSharedPtr(
522  m_session,
523  m_exp[0]->GetHomogeneousBasis()
524  ->GetBasisKey(),
525  m_exp[0]->GetHomoLen(),
526  m_useFFT, dealiasing, m_graph,var);
527  }
528  else
529  {
531  boost::dynamic_pointer_cast<MultiRegions::
533  ASSERTL0(tmp2,"Failed to type cast m_exp[0]");
534 
537  AllocateSharedPtr(*tmp2);
538  }
539  }
540  else
541  {
542  if(NewField)
543  {
544  bool dealiasing = false;
545 
547  ExpList3DHomogeneous1D>::AllocateSharedPtr(
548  m_session,
549  m_exp[0]->GetHomogeneousBasis()
550  ->GetBasisKey(),
551  m_exp[0]->GetHomoLen(),
552  m_useFFT, dealiasing, m_graph);
553  }
554  else
555  {
557  boost::dynamic_pointer_cast<MultiRegions::
558  ExpList3DHomogeneous1D>(m_exp[0]);
559  ASSERTL0(tmp2,"Failed to type cast m_exp[0]");
560 
563  AllocateSharedPtr(*tmp2);
564  }
565  }
566 
567  }
568  else
569  {
570  if(m_declareExpansionAsContField)
571  {
572  if(NewField)
573  {
575  AllocateSharedPtr(m_session,m_graph,var);
576  }
577  else // call copy constructor
578  {
579 
581  boost::dynamic_pointer_cast<MultiRegions::
582  ContField2D>(m_exp[0]);
583 
585  AllocateSharedPtr(*tmp2,m_graph,var);
586  }
587  }
588  else if(m_declareExpansionAsDisContField)
589  {
590  if(NewField)
591  {
593  AllocateSharedPtr(m_session,m_graph,var);
594  }
595  else // call copy constructor
596  {
598  boost::dynamic_pointer_cast<MultiRegions::
599  DisContField2D>(m_exp[0]);
600 
602  AllocateSharedPtr(*tmp2,m_graph,var);
603  }
604  }
605  else
606  {
608  boost::dynamic_pointer_cast<MultiRegions::
609  ExpList2D>(m_exp[0]);
610 
612  AllocateSharedPtr(*tmp2);
613  }
614  }
615  }
616  break;
617  case 3:
618  {
619  if(m_declareExpansionAsContField)
620  {
621  if(NewField)
622  {
624  AllocateSharedPtr(m_session,m_graph,var);
625 
626  }
627  else
628  {
630  boost::dynamic_pointer_cast<MultiRegions::
631  ContField3D>(m_exp[0]);
632 
634  AllocateSharedPtr(*tmp2,m_graph,var);
635 
636  m_locToGlobalMap = tmp2->GetLocalToGlobalMap();
637  }
638  }
639  else if(m_declareExpansionAsDisContField)
640  {
641  if(NewField)
642  {
644  AllocateSharedPtr(m_session,m_graph,var);
645  }
646  else
647  {
649  boost::dynamic_pointer_cast<MultiRegions::
650  DisContField3D>(m_exp[0]);
651 
653  AllocateSharedPtr(*tmp2,m_graph,var);
654  }
655  }
656  else
657  {
659  boost::dynamic_pointer_cast<MultiRegions::
660  ExpList3D>(m_exp[0]);
661 
663  AllocateSharedPtr(*tmp2);
664  }
665  }
666  break;
667  default:
668  ASSERTL0(false, "Expansion dimension not recognised");
669  break;
670  }
671 
672  return tmp;
673  }
674 
675 };
676 
677 typedef boost::shared_ptr<Field> FieldSharedPtr;
678 
679 }
680 }
681 
vector< MultiRegions::ExpListSharedPtr > m_exp
Definition: Field.hpp:87
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
boost::shared_ptr< ContField1D > ContField1DSharedPtr
Definition: ContField1D.h:235
LibUtilities::PtsIOSharedPtr m_ptsIO
Definition: Field.hpp:98
boost::shared_ptr< ContField3DHomogeneous1D > ContField3DHomogeneous1DSharedPtr
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
MultiRegions::AssemblyMapCGSharedPtr m_locToGlobalMap
Definition: Field.hpp:109
boost::shared_ptr< DisContField3DHomogeneous1D > DisContField3DHomogeneous1DSharedPtr
MultiRegions::ExpListSharedPtr AppendExpList(int NumHomogeneousDir, string var="DefaultVar", bool NewField=false)
Definition: Field.hpp:390
vector< LibUtilities::FieldDefinitionsSharedPtr > m_fielddef
Definition: Field.hpp:85
STL namespace.
boost::shared_ptr< ContField2D > ContField2DSharedPtr
Definition: ContField2D.h:291
Fourier Expansion .
Definition: BasisType.h:52
LibUtilities::CommSharedPtr m_comm
Definition: Field.hpp:94
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:50
std::map< std::string, std::string > FieldMetaDataMap
Definition: FieldIO.h:65
boost::shared_ptr< PtsField > PtsFieldSharedPtr
Definition: PtsField.h:248
boost::shared_ptr< ExpList3DHomogeneous2D > ExpList3DHomogeneous2DSharedPtr
Shared pointer to an ExpList3DHomogeneous2D object.
Abstraction of a two-dimensional multi-elemental expansion which is merely a collection of local expa...
1D Evenly-spaced points using Lagrange polynomial
Definition: PointsType.h:63
boost::shared_ptr< DisContField3DHomogeneous2D > DisContField3DHomogeneous2DSharedPtr
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
MultiRegions::ExpListSharedPtr SetUpFirstExpList(int NumHomogeneousDir, bool fldfilegiven=false)
Definition: Field.hpp:113
This class is the abstraction of a global continuous two- dimensional spectral/hp element expansion w...
Definition: ContField2D.h:56
LibUtilities::PtsFieldSharedPtr m_fieldPts
Definition: Field.hpp:107
Abstraction of a global continuous one-dimensional spectral/hp element expansion which approximates t...
Definition: ContField1D.h:56
boost::shared_ptr< ContField3DHomogeneous2D > ContField3DHomogeneous2DSharedPtr
boost::shared_ptr< ExpList1D > ExpList1DSharedPtr
Shared pointer to an ExpList1D object.
Definition: ExpList1D.h:50
boost::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
Definition: ExpList.h:1340
vector< vector< double > > m_data
Definition: Field.hpp:86
bool m_declareExpansionAsDisContField
Definition: Field.hpp:90
boost::shared_ptr< DisContField2D > DisContField2DSharedPtr
This class is the abstraction of a global discontinuous two- dimensional spectral/hp element expansio...
LibUtilities::FieldIOSharedPtr m_fld
Definition: Field.hpp:97
Defines a specification for a set of points.
Definition: Points.h:58
boost::shared_ptr< FieldIO > FieldIOSharedPtr
Definition: FieldIO.h:236
double NekDouble
SpatialDomains::MeshGraphSharedPtr m_graph
Definition: Field.hpp:96
boost::shared_ptr< DisContField1D > DisContField1DSharedPtr
boost::shared_ptr< ExpList2D > ExpList2DSharedPtr
Shared pointer to an ExpList2D object.
Definition: ExpList2D.h:49
boost::shared_ptr< DisContField3D > DisContField3DSharedPtr
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:677
boost::shared_ptr< ExpList2DHomogeneous1D > ExpList2DHomogeneous1DSharedPtr
Shared pointer to an ExpList2DHomogeneous1D object.
boost::shared_ptr< PtsIO > PtsIOSharedPtr
Definition: PtsIO.h:80
vector< unsigned int > m_bndRegionsToWrite
Definition: Field.hpp:102
boost::shared_ptr< ExpList3D > ExpList3DSharedPtr
Shared pointer to an ExpList3D object.
Definition: ExpList3D.h:110
static PtsFieldSharedPtr NullPtsField
Definition: PtsField.h:249
This class is the abstraction of a one-dimensional multi-elemental expansions which is merely a colle...
Definition: ExpList1D.h:61
Abstraction of a two-dimensional multi-elemental expansion which is merely a collection of local expa...
Definition: ExpList2D.h:60
Abstraction of a three-dimensional multi-elemental expansion which is merely a collection of local ex...
Definition: ExpList3D.h:49
boost::shared_ptr< ExpList3DHomogeneous1D > ExpList3DHomogeneous1DSharedPtr
Shared pointer to an ExpList3DHomogeneous1D object.
bool m_declareExpansionAsContField
Definition: Field.hpp:89
map< string, vector< string > > m_inputfiles
Definition: Field.hpp:99
LibUtilities::SessionReaderSharedPtr m_session
Definition: Field.hpp:95
boost::shared_ptr< ContField3D > ContField3DSharedPtr
Definition: ContField3D.h:190
LibUtilities::FieldMetaDataMap m_fieldMetaDataMap
Definition: Field.hpp:111
boost::shared_ptr< AssemblyMapCG > AssemblyMapCGSharedPtr
Definition: AssemblyMapCG.h:52
boost::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:432
Abstraction of a one-dimensional multi-elemental expansion which is merely a collection of local expa...
Abstraction of a two-dimensional multi-elemental expansion which is merely a collection of local expa...
Describes the specification for a Basis.
Definition: Basis.h:50