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_declareAsNewField(false),
72  m_writeBndFld(false),
73  m_fldToBnd(false),
74  m_addNormals(false),
75  m_setUpEquiSpacedFields(false),
76  m_fieldPts(LibUtilities::NullPtsField){}
77 
79  {
80  if (m_comm)
81  {
82  m_comm->Finalise();
83  }
84  }
85  bool m_verbose;
86  vector<LibUtilities::FieldDefinitionsSharedPtr> m_fielddef;
87  vector<vector<double> > m_data;
88  vector<MultiRegions::ExpListSharedPtr> m_exp;
89 
93 
94  bool m_useFFT;
95 
101  map<string, vector<string> > m_inputfiles;
102 
104  vector<unsigned int> m_bndRegionsToWrite;
107 
109 
111 
113 
115 
117  bool fldfilegiven = false)
118  {
119 
121 
122  // Set up expansion list
123  int expdim = m_graph->GetMeshDimension();
124  bool dealiasing = false;
125 
126  m_session->MatchSolverInfo("USEFFT", "FFTW", m_useFFT, false);
127 
128  switch (expdim)
129  {
130  case 1:
131  {
132  ASSERTL0(NumHomogeneousDir <= 2,
133  "Quasi-3D approach is only set up for 1 or 2 "
134  "homogeneous directions");
135 
136  if (NumHomogeneousDir == 1)
137  {
139 
140  // Define Homogeneous expansion
141  int nplanes;
142  NekDouble ly;
144 
145  if(fldfilegiven)
146  {
147  nplanes = m_fielddef[0]->m_numModes[1];
148  ly = m_fielddef[0]->m_homogeneousLengths[0];
149  btype = m_fielddef[0]->m_basis[1];
150  }
151  else
152  {
153  m_session->LoadParameter("HomModesZ", nplanes);
154  m_session->LoadParameter("LY",ly);
155  btype = LibUtilities::eFourier;
156  }
157 
158  // Choose points to be at evenly spaced points at
159  // nplanes points
161  Pkey(nplanes, LibUtilities::ePolyEvenlySpaced);
162 
163  const LibUtilities::BasisKey Bkey(btype, nplanes, Pkey);
164 
165 
166 
167  if(m_declareExpansionAsContField||
168  m_declareExpansionAsDisContField)
169  {
170  ASSERTL0(false,"ContField2DHomogeneous1D or "
171  "DisContField2DHomogenenous1D has "
172  "not been implemented");
173  }
174 
175  Exp2DH1 = MemoryManager<MultiRegions::
177  AllocateSharedPtr(m_session, Bkey, ly,
178  m_useFFT, dealiasing,
179  m_graph);
180  exp = Exp2DH1;
181  }
182  else if (NumHomogeneousDir == 2)
183  {
185 
186  int nylines,nzlines;
187  NekDouble ly,lz;
188  LibUtilities::BasisType btype1,btype2;
189 
190  if(fldfilegiven)
191  {
192  nylines = m_fielddef[0]->m_numModes[1];
193  nzlines = m_fielddef[0]->m_numModes[2];
194  ly = m_fielddef[0]->m_homogeneousLengths[0];
195  lz = m_fielddef[0]->m_homogeneousLengths[1];
196  btype1 = m_fielddef[0]->m_basis[1];
197  btype2 = m_fielddef[0]->m_basis[2];
198  }
199  else
200  {
201  m_session->LoadParameter("HomModesY", nylines);
202  m_session->LoadParameter("HomModesZ", nzlines);
203  m_session->LoadParameter("LY",ly);
204  m_session->LoadParameter("LZ",lz);
205  btype1 = LibUtilities::eFourier;
206  btype2 = LibUtilities::eFourier;
207  }
208 
209  // Choose points to be at evenly spaced points at
210  // nplanes points
212  PkeyY(nylines, LibUtilities::ePolyEvenlySpaced);
213  const LibUtilities::BasisKey BkeyY(btype1, nylines, PkeyY);
214 
216  PkeyZ(nzlines, LibUtilities::ePolyEvenlySpaced);
217  const LibUtilities::BasisKey BkeyZ(btype2, nzlines, PkeyZ);
218 
219  if(m_declareExpansionAsContField)
220  {
221  Exp3DH2 = MemoryManager<MultiRegions::
223  AllocateSharedPtr(m_session, BkeyY, BkeyZ,
224  ly, lz, m_useFFT, dealiasing,
225  m_graph,
226  m_session->GetVariable(0));
227  }
228  else if(m_declareExpansionAsDisContField)
229  {
230  Exp3DH2 = MemoryManager<MultiRegions::
232  AllocateSharedPtr(m_session, BkeyY, BkeyZ,
233  ly, lz, m_useFFT, dealiasing,
234  m_graph,
235  m_session->GetVariable(0));
236  }
237  else
238  {
239  Exp3DH2 = MemoryManager<MultiRegions::
241  AllocateSharedPtr(m_session, BkeyY, BkeyZ,
242  ly, lz, m_useFFT, dealiasing,
243  m_graph);
244  }
245 
246  exp = Exp3DH2;
247  }
248  else
249  {
251 
252  if(m_declareExpansionAsContField)
253  {
255  ::AllocateSharedPtr(m_session, m_graph,
256  m_session->GetVariable(0));
257  }
258  else if(m_declareExpansionAsDisContField)
259  {
261  ::AllocateSharedPtr(m_session, m_graph,
262  m_session->GetVariable(0));
263  }
264  else
265  {
267  ::AllocateSharedPtr(m_session, m_graph);
268  }
269 
270  exp = Exp1D;
271  }
272  }
273  break;
274  case 2:
275  {
276  ASSERTL0(NumHomogeneousDir <= 1,
277  "NumHomogeneousDir is only set up for 1");
278 
279  if (NumHomogeneousDir == 1)
280  {
282 
283  // Define Homogeneous expansion
284  int nplanes;
285  NekDouble lz;
287 
288  if(fldfilegiven)
289  {
290  nplanes = m_fielddef[0]->m_numModes[2];
291  lz = m_fielddef[0]->m_homogeneousLengths[0];
292  btype = m_fielddef[0]->m_basis[2];
293 
295  {
296  btype = LibUtilities::eFourier;
297  m_fielddef[0]->m_basis[2] = LibUtilities::eFourierSingleMode;
298  if (nplanes <= 2)
299  {
300  nplanes = 4;
301  }
302  }
303  }
304  else
305  {
306  m_session->LoadParameter("HomModesZ", nplanes);
307  m_session->LoadParameter("LZ",lz);
308  btype = LibUtilities::eFourier;
309  }
310 
311  // Choose points to be at evenly spaced points at
312  // nplanes points
314  Pkey(nplanes, LibUtilities::ePolyEvenlySpaced);
315 
316  const LibUtilities::BasisKey Bkey(btype, nplanes, Pkey);
317 
318  if(m_declareExpansionAsContField)
319  {
320  Exp3DH1 = MemoryManager<MultiRegions::
322  AllocateSharedPtr(m_session, Bkey, lz, m_useFFT,
323  dealiasing, m_graph,
324  m_session->GetVariable(0));
325  }
326  else if (m_declareExpansionAsDisContField)
327  {
328  Exp3DH1 = MemoryManager<MultiRegions::
330  AllocateSharedPtr(m_session,
331  Bkey, lz, m_useFFT,
332  dealiasing, m_graph,
333  m_session->GetVariable(0));
334  }
335  else
336  {
337  Exp3DH1 = MemoryManager<MultiRegions::
339  AllocateSharedPtr(m_session, Bkey, lz, m_useFFT,
340  dealiasing, m_graph);
341  }
342  exp = Exp3DH1;
343  }
344  else
345  {
347 
348  if(m_declareExpansionAsContField)
349  {
351  ::AllocateSharedPtr(m_session,m_graph,
352  m_session->GetVariable(0));
353  }
354  else if(m_declareExpansionAsDisContField)
355  {
357  ::AllocateSharedPtr(m_session,m_graph,
358  m_session->GetVariable(0));
359  }
360  else
361  {
363  ::AllocateSharedPtr(m_session,m_graph);
364  }
365 
366  exp = Exp2D;
367  }
368  }
369  break;
370  case 3:
371  {
373 
374  if(m_declareExpansionAsContField)
375  {
377  ::AllocateSharedPtr(m_session,m_graph,
378  m_session->GetVariable(0));
379  }
380  else if(m_declareExpansionAsDisContField)
381  {
383  ::AllocateSharedPtr(m_session,m_graph,
384  m_session->GetVariable(0));
385  }
386  else
387  {
389  ::AllocateSharedPtr(m_session, m_graph);
390  }
391 
392  exp = Exp3D;
393  }
394  break;
395  default:
396  ASSERTL0(false, "Expansion dimension not recognised");
397  break;
398  }
399 
400  return exp;
401  };
402 
404  string var = "DefaultVar",
405  bool NewField = false)
406  {
407  if (m_declareAsNewField)
408  {
409  NewField = true;
410  var = m_session->GetVariables()[0];
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);
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:88
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
boost::shared_ptr< ContField1D > ContField1DSharedPtr
Definition: ContField1D.h:237
LibUtilities::PtsIOSharedPtr m_ptsIO
Definition: Field.hpp:100
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:112
boost::shared_ptr< DisContField3DHomogeneous1D > DisContField3DHomogeneous1DSharedPtr
MultiRegions::ExpListSharedPtr AppendExpList(int NumHomogeneousDir, string var="DefaultVar", bool NewField=false)
Definition: Field.hpp:403
vector< LibUtilities::FieldDefinitionsSharedPtr > m_fielddef
Definition: Field.hpp:86
STL namespace.
boost::shared_ptr< ContField2D > ContField2DSharedPtr
Definition: ContField2D.h:293
Fourier Expansion .
Definition: BasisType.h:52
LibUtilities::CommSharedPtr m_comm
Definition: Field.hpp:96
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:263
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:116
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:110
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:87
bool m_declareExpansionAsDisContField
Definition: Field.hpp:91
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:99
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:98
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:104
boost::shared_ptr< ExpList3D > ExpList3DSharedPtr
Shared pointer to an ExpList3D object.
Definition: ExpList3D.h:114
static PtsFieldSharedPtr NullPtsField
Definition: PtsField.h:264
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:90
map< string, vector< string > > m_inputfiles
Definition: Field.hpp:101
LibUtilities::SessionReaderSharedPtr m_session
Definition: Field.hpp:97
boost::shared_ptr< ContField3D > ContField3DSharedPtr
Definition: ContField3D.h:191
LibUtilities::FieldMetaDataMap m_fieldMetaDataMap
Definition: Field.hpp:114
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