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_requireBoundaryExpansion(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 
92 
94 
95  bool m_useFFT;
96 
102  map<string, vector<string> > m_inputfiles;
103 
105  vector<unsigned int> m_bndRegionsToWrite;
108 
110 
112 
114 
116 
118  bool fldfilegiven = false)
119  {
120 
122 
123  // Set up expansion list
124  int expdim = m_graph->GetMeshDimension();
125  bool dealiasing = false;
126 
127  m_session->MatchSolverInfo("USEFFT", "FFTW", m_useFFT, false);
128 
129  switch (expdim)
130  {
131  case 1:
132  {
133  ASSERTL0(NumHomogeneousDir <= 2,
134  "Quasi-3D approach is only set up for 1 or 2 "
135  "homogeneous directions");
136 
137  if (NumHomogeneousDir == 1)
138  {
140 
141  // Define Homogeneous expansion
142  int nplanes;
143  NekDouble ly;
145 
146  if(fldfilegiven)
147  {
148  nplanes = m_fielddef[0]->m_numModes[1];
149  ly = m_fielddef[0]->m_homogeneousLengths[0];
150  btype = m_fielddef[0]->m_basis[1];
151  }
152  else
153  {
154  m_session->LoadParameter("HomModesZ", nplanes);
155  m_session->LoadParameter("LY",ly);
156  btype = LibUtilities::eFourier;
157  }
158 
159  // Choose points to be at evenly spaced points at
160  // nplanes points
162  Pkey(nplanes, LibUtilities::eFourierEvenlySpaced);
163 
164  const LibUtilities::BasisKey Bkey(btype, nplanes, Pkey);
165 
166 
167 
168  if(m_declareExpansionAsContField||
169  m_declareExpansionAsDisContField)
170  {
171  ASSERTL0(false,"ContField2DHomogeneous1D or "
172  "DisContField2DHomogenenous1D has "
173  "not been implemented");
174  }
175 
176  Exp2DH1 = MemoryManager<MultiRegions::
178  AllocateSharedPtr(m_session, Bkey, ly,
179  m_useFFT, dealiasing,
180  m_graph);
181  exp = Exp2DH1;
182  }
183  else if (NumHomogeneousDir == 2)
184  {
186 
187  int nylines,nzlines;
188  NekDouble ly,lz;
189  LibUtilities::BasisType btype1,btype2;
190 
191  if(fldfilegiven)
192  {
193  nylines = m_fielddef[0]->m_numModes[1];
194  nzlines = m_fielddef[0]->m_numModes[2];
195  ly = m_fielddef[0]->m_homogeneousLengths[0];
196  lz = m_fielddef[0]->m_homogeneousLengths[1];
197  btype1 = m_fielddef[0]->m_basis[1];
198  btype2 = m_fielddef[0]->m_basis[2];
199  }
200  else
201  {
202  m_session->LoadParameter("HomModesY", nylines);
203  m_session->LoadParameter("HomModesZ", nzlines);
204  m_session->LoadParameter("LY",ly);
205  m_session->LoadParameter("LZ",lz);
206  btype1 = LibUtilities::eFourier;
207  btype2 = LibUtilities::eFourier;
208  }
209 
210  // Choose points to be at evenly spaced points at
211  // nplanes points
213  PkeyY(nylines, LibUtilities::eFourierEvenlySpaced);
214  const LibUtilities::BasisKey BkeyY(btype1, nylines, PkeyY);
215 
217  PkeyZ(nzlines, LibUtilities::eFourierEvenlySpaced);
218  const LibUtilities::BasisKey BkeyZ(btype2, nzlines, PkeyZ);
219 
220  if(m_declareExpansionAsContField)
221  {
222  Exp3DH2 = MemoryManager<MultiRegions::
224  AllocateSharedPtr(m_session, BkeyY, BkeyZ,
225  ly, lz, m_useFFT, dealiasing,
226  m_graph,
227  m_session->GetVariable(0));
228  }
229  else if(m_declareExpansionAsDisContField)
230  {
231  Exp3DH2 = MemoryManager<MultiRegions::
233  AllocateSharedPtr(m_session, BkeyY, BkeyZ,
234  ly, lz, m_useFFT, dealiasing,
235  m_graph,
236  m_session->GetVariable(0));
237  }
238  else
239  {
240  Exp3DH2 = MemoryManager<MultiRegions::
242  AllocateSharedPtr(m_session, BkeyY, BkeyZ,
243  ly, lz, m_useFFT, dealiasing,
244  m_graph);
245  }
246 
247  exp = Exp3DH2;
248  }
249  else
250  {
252 
253  if(m_declareExpansionAsContField)
254  {
256  ::AllocateSharedPtr(m_session, m_graph,
257  m_session->GetVariable(0));
258  }
259  else if(m_declareExpansionAsDisContField)
260  {
262  ::AllocateSharedPtr(m_session, m_graph,
263  m_session->GetVariable(0));
264  }
265  else
266  {
268  ::AllocateSharedPtr(m_session, m_graph);
269  }
270 
271  exp = Exp1D;
272  }
273  }
274  break;
275  case 2:
276  {
277  ASSERTL0(NumHomogeneousDir <= 1,
278  "NumHomogeneousDir is only set up for 1");
279 
280  if (NumHomogeneousDir == 1)
281  {
283 
284  // Define Homogeneous expansion
285  int nplanes;
286  NekDouble lz;
288 
289  if(fldfilegiven)
290  {
291  nplanes = m_fielddef[0]->m_numModes[2];
292  lz = m_fielddef[0]->m_homogeneousLengths[0];
293  btype = m_fielddef[0]->m_basis[2];
294 
296  {
297  btype = LibUtilities::eFourier;
298  m_fielddef[0]->m_basis[2] = LibUtilities::eFourierSingleMode;
299  if (nplanes <= 2)
300  {
301  nplanes = 4;
302  }
303  }
304  }
305  else
306  {
307  m_session->LoadParameter("HomModesZ", nplanes);
308  m_session->LoadParameter("LZ",lz);
309  btype = LibUtilities::eFourier;
310  }
311 
312  // Choose points to be at evenly spaced points at
313  // nplanes points
315  Pkey(nplanes, LibUtilities::eFourierEvenlySpaced);
316 
317  const LibUtilities::BasisKey Bkey(btype, nplanes, Pkey);
318 
319  if(m_declareExpansionAsContField)
320  {
321  Exp3DH1 = MemoryManager<MultiRegions::
323  AllocateSharedPtr(m_session, Bkey, lz, m_useFFT,
324  dealiasing, m_graph,
325  m_session->GetVariable(0));
326  }
327  else if (m_declareExpansionAsDisContField)
328  {
329  Exp3DH1 = MemoryManager<MultiRegions::
331  AllocateSharedPtr(m_session,
332  Bkey, lz, m_useFFT,
333  dealiasing, m_graph,
334  m_session->GetVariable(0));
335  }
336  else
337  {
338  Exp3DH1 = MemoryManager<MultiRegions::
340  AllocateSharedPtr(m_session, Bkey, lz, m_useFFT,
341  dealiasing, m_graph);
342  }
343  exp = Exp3DH1;
344  }
345  else
346  {
348 
349  if(m_declareExpansionAsContField)
350  {
352  ::AllocateSharedPtr(m_session,m_graph,
353  m_session->GetVariable(0));
354  }
355  else if(m_declareExpansionAsDisContField)
356  {
358  ::AllocateSharedPtr(m_session,m_graph,
359  m_session->GetVariable(0));
360  }
361  else
362  {
364  ::AllocateSharedPtr(m_session,m_graph);
365  }
366 
367  exp = Exp2D;
368  }
369  }
370  break;
371  case 3:
372  {
374 
375  if(m_declareExpansionAsContField)
376  {
378  ::AllocateSharedPtr(m_session,m_graph,
379  m_session->GetVariable(0));
380  }
381  else if(m_declareExpansionAsDisContField)
382  {
384  ::AllocateSharedPtr(m_session,m_graph,
385  m_session->GetVariable(0));
386  }
387  else
388  {
390  ::AllocateSharedPtr(m_session, m_graph);
391  }
392 
393  exp = Exp3D;
394  }
395  break;
396  default:
397  ASSERTL0(false, "Expansion dimension not recognised");
398  break;
399  }
400 
401  return exp;
402  };
403 
405  string var = "DefaultVar",
406  bool NewField = false)
407  {
408  if(var.compare("DefaultVar") == 0 && m_requireBoundaryExpansion)
409  {
410  if (m_session->GetVariables().size())
411  {
412  var = m_session->GetVariables()[0];
413  }
414  }
416  switch (m_graph->GetMeshDimension())
417  {
418  case 1:
419  {
420  if (NumHomogeneousDir == 1)
421  {
422  ASSERTL0( !(m_declareExpansionAsContField ||
423  m_declareExpansionAsDisContField),
424  "ContField2DHomogeneous1D or "
425  "DisContField2DHomogenenous1D has not been "
426  "implemented");
427 
429  boost::dynamic_pointer_cast<MultiRegions::
430  ExpList2DHomogeneous1D>(m_exp[0]);
431 
434  AllocateSharedPtr(*tmp2);
435 
436  }
437  else if (NumHomogeneousDir == 2)
438  {
439  if(m_declareExpansionAsContField)
440  {
442  boost::dynamic_pointer_cast<MultiRegions::
443  ContField3DHomogeneous2D>(m_exp[0]);
444 
447  AllocateSharedPtr(*tmp2);
448  }
449  else if(m_declareExpansionAsDisContField)
450  {
452  boost::dynamic_pointer_cast<MultiRegions::
454 
457  AllocateSharedPtr(*tmp2);
458  }
459  else
460  {
462  boost::dynamic_pointer_cast<MultiRegions::
463  ExpList3DHomogeneous2D>(m_exp[0]);
464 
467  AllocateSharedPtr(*tmp2);
468  }
469 
470 
471  }
472  else
473  {
474  if(m_declareExpansionAsContField)
475  {
477  boost::dynamic_pointer_cast<MultiRegions::
478  ContField1D>(m_exp[0]);
479 
481  AllocateSharedPtr(m_session,m_graph,var);
482  }
483  else if(m_declareExpansionAsDisContField)
484  {
486  boost::dynamic_pointer_cast<MultiRegions::
487  DisContField1D>(m_exp[0]);
488 
490  AllocateSharedPtr(m_session,m_graph,var);
491  }
492  else
493  {
495  boost::dynamic_pointer_cast<MultiRegions::
496  ExpList1D>(m_exp[0]);
497 
499  AllocateSharedPtr(*tmp2);
500  }
501 
502  }
503  }
504  break;
505  case 2:
506  {
507  if (NumHomogeneousDir == 1)
508  {
509  if(m_declareExpansionAsContField)
510  {
511  if(NewField)
512  {
513  bool dealiasing = false;
514 
516  ContField3DHomogeneous1D>::AllocateSharedPtr(
517  m_session,
518  m_exp[0]->GetHomogeneousBasis()
519  ->GetBasisKey(),
520  m_exp[0]->GetHomoLen(),
521  m_useFFT, dealiasing, m_graph, var);
522  }
523  else
524  {
526  boost::dynamic_pointer_cast<MultiRegions::
527  ContField3DHomogeneous1D>(m_exp[0]);
528 
529  ASSERTL0(tmp2,"Failed to type cast m_exp[0]");
532  AllocateSharedPtr(*tmp2, m_graph, var);
533  }
534  }
535  else if(m_declareExpansionAsDisContField)
536  {
537  if(NewField)
538  {
539  bool dealiasing = false;
540 
542  DisContField3DHomogeneous1D>::AllocateSharedPtr(
543  m_session,
544  m_exp[0]->GetHomogeneousBasis()
545  ->GetBasisKey(),
546  m_exp[0]->GetHomoLen(),
547  m_useFFT, dealiasing, m_graph,var);
548  }
549  else
550  {
552  boost::dynamic_pointer_cast<MultiRegions::
554  ASSERTL0(tmp2,"Failed to type cast m_exp[0]");
555 
558  AllocateSharedPtr(*tmp2);
559  }
560  }
561  else
562  {
563  if(NewField)
564  {
565  bool dealiasing = false;
566 
568  ExpList3DHomogeneous1D>::AllocateSharedPtr(
569  m_session,
570  m_exp[0]->GetHomogeneousBasis()
571  ->GetBasisKey(),
572  m_exp[0]->GetHomoLen(),
573  m_useFFT, dealiasing, m_graph);
574  }
575  else
576  {
578  boost::dynamic_pointer_cast<MultiRegions::
579  ExpList3DHomogeneous1D>(m_exp[0]);
580  ASSERTL0(tmp2,"Failed to type cast m_exp[0]");
581 
584  AllocateSharedPtr(*tmp2);
585  }
586  }
587 
588  }
589  else
590  {
591  if(m_declareExpansionAsContField)
592  {
593  if(NewField)
594  {
596  AllocateSharedPtr(m_session,m_graph,var);
597  }
598  else // call copy constructor
599  {
600 
602  boost::dynamic_pointer_cast<MultiRegions::
603  ContField2D>(m_exp[0]);
604 
606  AllocateSharedPtr(*tmp2,m_graph,var);
607  }
608  }
609  else if(m_declareExpansionAsDisContField)
610  {
611  if(NewField)
612  {
614  AllocateSharedPtr(m_session,m_graph,var);
615  }
616  else // call copy constructor
617  {
619  boost::dynamic_pointer_cast<MultiRegions::
620  DisContField2D>(m_exp[0]);
621 
623  AllocateSharedPtr(*tmp2,m_graph,var);
624  }
625  }
626  else
627  {
629  boost::dynamic_pointer_cast<MultiRegions::
630  ExpList2D>(m_exp[0]);
631 
633  AllocateSharedPtr(*tmp2);
634  }
635  }
636  }
637  break;
638  case 3:
639  {
640  if(m_declareExpansionAsContField)
641  {
642  if(NewField)
643  {
645  AllocateSharedPtr(m_session,m_graph,var);
646 
647  }
648  else
649  {
651  boost::dynamic_pointer_cast<MultiRegions::
652  ContField3D>(m_exp[0]);
653 
655  AllocateSharedPtr(*tmp2,m_graph,var);
656 
657  m_locToGlobalMap = tmp2->GetLocalToGlobalMap();
658  }
659  }
660  else if(m_declareExpansionAsDisContField)
661  {
662  if(NewField)
663  {
665  AllocateSharedPtr(m_session,m_graph,var);
666  }
667  else
668  {
670  boost::dynamic_pointer_cast<MultiRegions::
671  DisContField3D>(m_exp[0]);
672 
674  AllocateSharedPtr(*tmp2,m_graph,var);
675  }
676  }
677  else
678  {
680  boost::dynamic_pointer_cast<MultiRegions::
681  ExpList3D>(m_exp[0]);
682 
684  AllocateSharedPtr(*tmp2);
685  }
686  }
687  break;
688  default:
689  ASSERTL0(false, "Expansion dimension not recognised");
690  break;
691  }
692 
693  return tmp;
694  }
695 
696 };
697 
698 typedef boost::shared_ptr<Field> FieldSharedPtr;
699 
700 }
701 }
702 
vector< MultiRegions::ExpListSharedPtr > m_exp
Definition: Field.hpp:88
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
boost::shared_ptr< ContField1D > ContField1DSharedPtr
Definition: ContField1D.h:237
LibUtilities::PtsIOSharedPtr m_ptsIO
Definition: Field.hpp:101
boost::shared_ptr< ContField3DHomogeneous1D > ContField3DHomogeneous1DSharedPtr
bool m_requireBoundaryExpansion
Definition: Field.hpp:93
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
MultiRegions::AssemblyMapCGSharedPtr m_locToGlobalMap
Definition: Field.hpp:113
boost::shared_ptr< DisContField3DHomogeneous1D > DisContField3DHomogeneous1DSharedPtr
MultiRegions::ExpListSharedPtr AppendExpList(int NumHomogeneousDir, string var="DefaultVar", bool NewField=false)
Definition: Field.hpp:404
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:97
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:117
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:111
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:100
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:99
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:698
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:105
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:90
map< string, vector< string > > m_inputfiles
Definition: Field.hpp:102
LibUtilities::SessionReaderSharedPtr m_session
Definition: Field.hpp:98
boost::shared_ptr< ContField3D > ContField3DSharedPtr
Definition: ContField3D.h:191
LibUtilities::FieldMetaDataMap m_fieldMetaDataMap
Definition: Field.hpp:115
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