Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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_comm)
80  {
81  m_comm->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 
107 
109 
111 
113 
115  bool fldfilegiven = false)
116  {
117 
119 
120  // Set up expansion list
121  int expdim = m_graph->GetMeshDimension();
122  bool dealiasing = false;
123 
124  m_session->MatchSolverInfo("USEFFT", "FFTW", m_useFFT, false);
125 
126  switch (expdim)
127  {
128  case 1:
129  {
130  ASSERTL0(NumHomogeneousDir <= 2,
131  "Quasi-3D approach is only set up for 1 or 2 "
132  "homogeneous directions");
133 
134  if (NumHomogeneousDir == 1)
135  {
137 
138  // Define Homogeneous expansion
139  int nplanes;
140  NekDouble ly;
142 
143  if(fldfilegiven)
144  {
145  nplanes = m_fielddef[0]->m_numModes[1];
146  ly = m_fielddef[0]->m_homogeneousLengths[0];
147  btype = m_fielddef[0]->m_basis[1];
148  }
149  else
150  {
151  m_session->LoadParameter("HomModesZ", nplanes);
152  m_session->LoadParameter("LY",ly);
153  btype = LibUtilities::eFourier;
154  }
155 
156  // Choose points to be at evenly spaced points at
157  // nplanes points
159  Pkey(nplanes, LibUtilities::eFourierEvenlySpaced);
160 
161  const LibUtilities::BasisKey Bkey(btype, nplanes, Pkey);
162 
163 
164 
165  if(m_declareExpansionAsContField||
166  m_declareExpansionAsDisContField)
167  {
168  ASSERTL0(false,"ContField2DHomogeneous1D or "
169  "DisContField2DHomogenenous1D has "
170  "not been implemented");
171  }
172 
173  Exp2DH1 = MemoryManager<MultiRegions::
175  AllocateSharedPtr(m_session, Bkey, ly,
176  m_useFFT, dealiasing,
177  m_graph);
178  exp = Exp2DH1;
179  }
180  else if (NumHomogeneousDir == 2)
181  {
183 
184  int nylines,nzlines;
185  NekDouble ly,lz;
186  LibUtilities::BasisType btype1,btype2;
187 
188  if(fldfilegiven)
189  {
190  nylines = m_fielddef[0]->m_numModes[1];
191  nzlines = m_fielddef[0]->m_numModes[2];
192  ly = m_fielddef[0]->m_homogeneousLengths[0];
193  lz = m_fielddef[0]->m_homogeneousLengths[1];
194  btype1 = m_fielddef[0]->m_basis[1];
195  btype2 = m_fielddef[0]->m_basis[2];
196  }
197  else
198  {
199  m_session->LoadParameter("HomModesY", nylines);
200  m_session->LoadParameter("HomModesZ", nzlines);
201  m_session->LoadParameter("LY",ly);
202  m_session->LoadParameter("LZ",lz);
203  btype1 = LibUtilities::eFourier;
204  btype2 = LibUtilities::eFourier;
205  }
206 
207  // Choose points to be at evenly spaced points at
208  // nplanes points
210  PkeyY(nylines, LibUtilities::eFourierEvenlySpaced);
211  const LibUtilities::BasisKey BkeyY(btype1, nylines, PkeyY);
212 
214  PkeyZ(nzlines, LibUtilities::eFourierEvenlySpaced);
215  const LibUtilities::BasisKey BkeyZ(btype2, nzlines, PkeyZ);
216 
217  if(m_declareExpansionAsContField)
218  {
219  Exp3DH2 = MemoryManager<MultiRegions::
221  AllocateSharedPtr(m_session, BkeyY, BkeyZ,
222  ly, lz, m_useFFT, dealiasing,
223  m_graph,
224  m_session->GetVariable(0));
225  }
226  else if(m_declareExpansionAsDisContField)
227  {
228  Exp3DH2 = MemoryManager<MultiRegions::
230  AllocateSharedPtr(m_session, BkeyY, BkeyZ,
231  ly, lz, m_useFFT, dealiasing,
232  m_graph,
233  m_session->GetVariable(0));
234  }
235  else
236  {
237  Exp3DH2 = MemoryManager<MultiRegions::
239  AllocateSharedPtr(m_session, BkeyY, BkeyZ,
240  ly, lz, m_useFFT, dealiasing,
241  m_graph);
242  }
243 
244  exp = Exp3DH2;
245  }
246  else
247  {
249 
250  if(m_declareExpansionAsContField)
251  {
253  ::AllocateSharedPtr(m_session, m_graph,
254  m_session->GetVariable(0));
255  }
256  else if(m_declareExpansionAsDisContField)
257  {
259  ::AllocateSharedPtr(m_session, m_graph,
260  m_session->GetVariable(0));
261  }
262  else
263  {
265  ::AllocateSharedPtr(m_session, m_graph);
266  }
267 
268  exp = Exp1D;
269  }
270  }
271  break;
272  case 2:
273  {
274  ASSERTL0(NumHomogeneousDir <= 1,
275  "NumHomogeneousDir is only set up for 1");
276 
277  if (NumHomogeneousDir == 1)
278  {
280 
281  // Define Homogeneous expansion
282  int nplanes;
283  NekDouble lz;
285 
286  if(fldfilegiven)
287  {
288  nplanes = m_fielddef[0]->m_numModes[2];
289  lz = m_fielddef[0]->m_homogeneousLengths[0];
290  btype = m_fielddef[0]->m_basis[2];
291 
293  {
294  btype = LibUtilities::eFourier;
295  m_fielddef[0]->m_basis[2] = LibUtilities::eFourierSingleMode;
296  if (nplanes <= 2)
297  {
298  nplanes = 4;
299  }
300  }
301  }
302  else
303  {
304  m_session->LoadParameter("HomModesZ", nplanes);
305  m_session->LoadParameter("LZ",lz);
306  btype = LibUtilities::eFourier;
307  }
308 
309  // Choose points to be at evenly spaced points at
310  // nplanes points
312  Pkey(nplanes, LibUtilities::eFourierEvenlySpaced);
313 
314  const LibUtilities::BasisKey Bkey(btype, nplanes, Pkey);
315 
316  if(m_declareExpansionAsContField)
317  {
318  Exp3DH1 = MemoryManager<MultiRegions::
320  AllocateSharedPtr(m_session, Bkey, lz, m_useFFT,
321  dealiasing, m_graph,
322  m_session->GetVariable(0));
323  }
324  else if (m_declareExpansionAsDisContField)
325  {
326  Exp3DH1 = MemoryManager<MultiRegions::
328  AllocateSharedPtr(m_session,
329  Bkey, lz, m_useFFT,
330  dealiasing, m_graph,
331  m_session->GetVariable(0));
332  }
333  else
334  {
335  Exp3DH1 = MemoryManager<MultiRegions::
337  AllocateSharedPtr(m_session, Bkey, lz, m_useFFT,
338  dealiasing, m_graph);
339  }
340  exp = Exp3DH1;
341  }
342  else
343  {
345 
346  if(m_declareExpansionAsContField)
347  {
349  ::AllocateSharedPtr(m_session,m_graph,
350  m_session->GetVariable(0));
351  }
352  else if(m_declareExpansionAsDisContField)
353  {
355  ::AllocateSharedPtr(m_session,m_graph,
356  m_session->GetVariable(0));
357  }
358  else
359  {
361  ::AllocateSharedPtr(m_session,m_graph);
362  }
363 
364  exp = Exp2D;
365  }
366  }
367  break;
368  case 3:
369  {
371 
372  if(m_declareExpansionAsContField)
373  {
375  ::AllocateSharedPtr(m_session,m_graph,
376  m_session->GetVariable(0));
377  }
378  else if(m_declareExpansionAsDisContField)
379  {
381  ::AllocateSharedPtr(m_session,m_graph,
382  m_session->GetVariable(0));
383  }
384  else
385  {
387  ::AllocateSharedPtr(m_session, m_graph);
388  }
389 
390  exp = Exp3D;
391  }
392  break;
393  default:
394  ASSERTL0(false, "Expansion dimension not recognised");
395  break;
396  }
397 
398  return exp;
399  };
400 
402  string var = "DefaultVar",
403  bool NewField = false)
404  {
405  if(var.compare("DefaultVar") == 0 && m_declareExpansionAsContField)
406  {
407  if (m_session->GetVariables().size())
408  {
409  var = m_session->GetVariables()[0];
410  }
411  }
413  switch (m_graph->GetMeshDimension())
414  {
415  case 1:
416  {
417  if (NumHomogeneousDir == 1)
418  {
419  ASSERTL0( !(m_declareExpansionAsContField ||
420  m_declareExpansionAsDisContField),
421  "ContField2DHomogeneous1D or "
422  "DisContField2DHomogenenous1D has not been "
423  "implemented");
424 
426  boost::dynamic_pointer_cast<MultiRegions::
427  ExpList2DHomogeneous1D>(m_exp[0]);
428 
431  AllocateSharedPtr(*tmp2);
432 
433  }
434  else if (NumHomogeneousDir == 2)
435  {
436  if(m_declareExpansionAsContField)
437  {
439  boost::dynamic_pointer_cast<MultiRegions::
440  ContField3DHomogeneous2D>(m_exp[0]);
441 
444  AllocateSharedPtr(*tmp2);
445  }
446  else if(m_declareExpansionAsDisContField)
447  {
449  boost::dynamic_pointer_cast<MultiRegions::
451 
454  AllocateSharedPtr(*tmp2);
455  }
456  else
457  {
459  boost::dynamic_pointer_cast<MultiRegions::
460  ExpList3DHomogeneous2D>(m_exp[0]);
461 
464  AllocateSharedPtr(*tmp2);
465  }
466 
467 
468  }
469  else
470  {
471  if(m_declareExpansionAsContField)
472  {
474  boost::dynamic_pointer_cast<MultiRegions::
475  ContField1D>(m_exp[0]);
476 
478  AllocateSharedPtr(m_session,m_graph,var);
479  }
480  else if(m_declareExpansionAsDisContField)
481  {
483  boost::dynamic_pointer_cast<MultiRegions::
484  DisContField1D>(m_exp[0]);
485 
487  AllocateSharedPtr(m_session,m_graph,var);
488  }
489  else
490  {
492  boost::dynamic_pointer_cast<MultiRegions::
493  ExpList1D>(m_exp[0]);
494 
496  AllocateSharedPtr(*tmp2);
497  }
498 
499  }
500  }
501  break;
502  case 2:
503  {
504  if (NumHomogeneousDir == 1)
505  {
506  if(m_declareExpansionAsContField)
507  {
508  if(NewField)
509  {
510  bool dealiasing = false;
511 
513  ContField3DHomogeneous1D>::AllocateSharedPtr(
514  m_session,
515  m_exp[0]->GetHomogeneousBasis()
516  ->GetBasisKey(),
517  m_exp[0]->GetHomoLen(),
518  m_useFFT, dealiasing, m_graph, var);
519  }
520  else
521  {
523  boost::dynamic_pointer_cast<MultiRegions::
524  ContField3DHomogeneous1D>(m_exp[0]);
525 
526  ASSERTL0(tmp2,"Failed to type cast m_exp[0]");
529  AllocateSharedPtr(*tmp2, m_graph, var);
530  }
531  }
532  else if(m_declareExpansionAsDisContField)
533  {
534  if(NewField)
535  {
536  bool dealiasing = false;
537 
539  DisContField3DHomogeneous1D>::AllocateSharedPtr(
540  m_session,
541  m_exp[0]->GetHomogeneousBasis()
542  ->GetBasisKey(),
543  m_exp[0]->GetHomoLen(),
544  m_useFFT, dealiasing, m_graph,var);
545  }
546  else
547  {
549  boost::dynamic_pointer_cast<MultiRegions::
551  ASSERTL0(tmp2,"Failed to type cast m_exp[0]");
552 
555  AllocateSharedPtr(*tmp2);
556  }
557  }
558  else
559  {
560  if(NewField)
561  {
562  bool dealiasing = false;
563 
565  ExpList3DHomogeneous1D>::AllocateSharedPtr(
566  m_session,
567  m_exp[0]->GetHomogeneousBasis()
568  ->GetBasisKey(),
569  m_exp[0]->GetHomoLen(),
570  m_useFFT, dealiasing, m_graph);
571  }
572  else
573  {
575  boost::dynamic_pointer_cast<MultiRegions::
576  ExpList3DHomogeneous1D>(m_exp[0]);
577  ASSERTL0(tmp2,"Failed to type cast m_exp[0]");
578 
581  AllocateSharedPtr(*tmp2);
582  }
583  }
584 
585  }
586  else
587  {
588  if(m_declareExpansionAsContField)
589  {
590  if(NewField)
591  {
593  AllocateSharedPtr(m_session,m_graph,var);
594  }
595  else // call copy constructor
596  {
597 
599  boost::dynamic_pointer_cast<MultiRegions::
600  ContField2D>(m_exp[0]);
601 
603  AllocateSharedPtr(*tmp2,m_graph,var);
604  }
605  }
606  else if(m_declareExpansionAsDisContField)
607  {
608  if(NewField)
609  {
611  AllocateSharedPtr(m_session,m_graph,var);
612  }
613  else // call copy constructor
614  {
616  boost::dynamic_pointer_cast<MultiRegions::
617  DisContField2D>(m_exp[0]);
618 
620  AllocateSharedPtr(*tmp2,m_graph,var);
621  }
622  }
623  else
624  {
626  boost::dynamic_pointer_cast<MultiRegions::
627  ExpList2D>(m_exp[0]);
628 
630  AllocateSharedPtr(*tmp2);
631  }
632  }
633  }
634  break;
635  case 3:
636  {
637  if(m_declareExpansionAsContField)
638  {
639  if(NewField)
640  {
642  AllocateSharedPtr(m_session,m_graph,var);
643 
644  }
645  else
646  {
648  boost::dynamic_pointer_cast<MultiRegions::
649  ContField3D>(m_exp[0]);
650 
652  AllocateSharedPtr(*tmp2,m_graph,var);
653 
654  m_locToGlobalMap = tmp2->GetLocalToGlobalMap();
655  }
656  }
657  else if(m_declareExpansionAsDisContField)
658  {
659  if(NewField)
660  {
662  AllocateSharedPtr(m_session,m_graph,var);
663  }
664  else
665  {
667  boost::dynamic_pointer_cast<MultiRegions::
668  DisContField3D>(m_exp[0]);
669 
671  AllocateSharedPtr(*tmp2,m_graph,var);
672  }
673  }
674  else
675  {
677  boost::dynamic_pointer_cast<MultiRegions::
678  ExpList3D>(m_exp[0]);
679 
681  AllocateSharedPtr(*tmp2);
682  }
683  }
684  break;
685  default:
686  ASSERTL0(false, "Expansion dimension not recognised");
687  break;
688  }
689 
690  return tmp;
691  }
692 
693 };
694 
695 typedef boost::shared_ptr<Field> FieldSharedPtr;
696 
697 }
698 }
699 
vector< MultiRegions::ExpListSharedPtr > m_exp
Definition: Field.hpp:87
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
boost::shared_ptr< ContField1D > ContField1DSharedPtr
Definition: ContField1D.h:237
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:110
boost::shared_ptr< DisContField3DHomogeneous1D > DisContField3DHomogeneous1DSharedPtr
MultiRegions::ExpListSharedPtr AppendExpList(int NumHomogeneousDir, string var="DefaultVar", bool NewField=false)
Definition: Field.hpp:401
vector< LibUtilities::FieldDefinitionsSharedPtr > m_fielddef
Definition: Field.hpp:85
STL namespace.
boost::shared_ptr< ContField2D > ContField2DSharedPtr
Definition: ContField2D.h:293
Fourier Expansion .
Definition: BasisType.h:52
LibUtilities::CommSharedPtr m_comm
Definition: Field.hpp:94
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
std::map< std::string, std::string > FieldMetaDataMap
Definition: FieldIO.h:53
boost::shared_ptr< PtsField > PtsFieldSharedPtr
Definition: PtsField.h:262
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...
boost::shared_ptr< DisContField3DHomogeneous2D > DisContField3DHomogeneous2DSharedPtr
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
1D Evenly-spaced points using Fourier Fit
Definition: PointsType.h:64
MultiRegions::ExpListSharedPtr SetUpFirstExpList(int NumHomogeneousDir, bool fldfilegiven=false)
Definition: Field.hpp:114
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:108
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
vector< vector< double > > m_data
Definition: Field.hpp:86
bool m_declareExpansionAsDisContField
Definition: Field.hpp:90
boost::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
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:225
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:695
boost::shared_ptr< ExpList2DHomogeneous1D > ExpList2DHomogeneous1DSharedPtr
Shared pointer to an ExpList2DHomogeneous1D object.
boost::shared_ptr< PtsIO > PtsIOSharedPtr
Definition: PtsIO.h:96
vector< unsigned int > m_bndRegionsToWrite
Definition: Field.hpp:102
boost::shared_ptr< ExpList3D > ExpList3DSharedPtr
Shared pointer to an ExpList3D object.
Definition: ExpList3D.h:114
static PtsFieldSharedPtr NullPtsField
Definition: PtsField.h:263
Fourier ModifiedExpansion with just the first mode .
Definition: BasisType.h:58
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:191
LibUtilities::FieldMetaDataMap m_fieldMetaDataMap
Definition: Field.hpp:112
boost::shared_ptr< AssemblyMapCG > AssemblyMapCGSharedPtr
Definition: AssemblyMapCG.h:52
boost::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:442
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