Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fld2DTo2D5.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <cstdlib>
3 #include <iomanip>
4 #include <vector>
5 
6 #include <MultiRegions/ExpList.h>
12 
13 using namespace std;
14 using namespace Nektar;
15 
16 int main(int argc, char *argv[])
17 {
18  int i,j,k;
19 
20  if(argc != 6)
21  {
22  fprintf(stderr,
23  "Usage: Fld2DTo2D5 2dmeshfile 2dfieldfile 3dmeshfile 3dfieldfile outfield\n");
24  exit(1);
25  }
26  string datasave(argv[5]);
27 
28  string mesh2d(argv[1]);
29  string mesh3d(argv[3]);
30 
31  //create 2d session
33  = LibUtilities::SessionReader::CreateInstance(2, argv);
34  std::vector<std::string> filenames;
35  filenames.push_back(mesh3d);
36  //create 3D session
38  = LibUtilities::SessionReader::CreateInstance(2, argv, filenames, vSession2d->GetComm());
39 
40  SpatialDomains::MeshGraphSharedPtr graphShPt2d = SpatialDomains::MeshGraph::Read(vSession2d);
41  SpatialDomains::MeshGraphSharedPtr graphShPt3d = SpatialDomains::MeshGraph::Read(vSession3d);
42  //2D
43  string field2dfile(argv[2]);
44  vector<LibUtilities::FieldDefinitionsSharedPtr> field2ddef;
45  vector<vector<NekDouble> > field2ddata;
46  LibUtilities::Import(field2dfile,field2ddef,field2ddata);
47  //3D
48  string field3dfile(argv[4]);
49  vector<LibUtilities::FieldDefinitionsSharedPtr> field3ddef;
50  vector<vector<NekDouble> > field3ddata;
51  LibUtilities::Import(field3dfile,field3ddef,field3ddata);
52  vector<vector<NekDouble> > field3ddatanew(field3ddef.size());
53  // Set up Expansion information
54  vector< vector<LibUtilities::PointsType> > pointstype2d;
55  vector< vector<LibUtilities::PointsType> > pointstype3d;
56  for(i = 0; i < field2ddef.size(); ++i)
57  {
58  vector<LibUtilities::PointsType> ptype2d;
59  for(j = 0; j < 2; ++j)
60  {
61  ptype2d.push_back(LibUtilities::ePolyEvenlySpaced);
62  }
63  pointstype2d.push_back(ptype2d);
64  }
65  graphShPt2d->SetExpansions(field2ddef,pointstype2d);
66  for(i = 0; i < field3ddef.size(); ++i)
67  {
68  vector<LibUtilities::PointsType> ptype3d;
69  for(j = 0; j < 2; ++j)
70  {
71  ptype3d.push_back(LibUtilities::ePolyEvenlySpaced);
72  }
73  pointstype3d.push_back(ptype3d);
74  }
75  graphShPt3d->SetExpansions(field3ddef,pointstype3d);
76  bool useFFT = false;
77  bool dealiasing = false;
78  // Define Expansion
79  //int expdim2d = graphShPt2d->GetMeshDimension();
80  int nfields2d = field2ddef[0]->m_fields.size();
81  //int expdim3d = graphShPt3d->GetMeshDimension();
82  int nfields3d = field3ddef[0]->m_fields.size();
83  //Gen 2d
86  Exp2D = MemoryManager<MultiRegions::ExpList2D>::AllocateSharedPtr(vSession2d,graphShPt2d);
87  Exp2d[0] = Exp2D;
88  for(i = 1; i < nfields2d; ++i)
89  {
91  }
92  //Gen 3d
95  // Define Homogeneous expansion
96  int nplanes;
97  //vSession3d->LoadParameter("HomModesZ",nplanes,field3ddef[0]->m_numModes[2]);
98  nplanes = field3ddef[0]->m_numModes[2];
99  cout<< nplanes << endl;
100  // nplanes + 1 points
102  const LibUtilities::BasisKey Bkey(field3ddef[0]->m_basis[2],nplanes,Pkey);
103  NekDouble lz = field3ddef[0]->m_homogeneousLengths[0];
104  Exp3DH1 = MemoryManager<MultiRegions::ExpList3DHomogeneous1D>::AllocateSharedPtr(vSession3d,Bkey,lz,useFFT,dealiasing,graphShPt3d);
105  Exp3d[0] = Exp3DH1;
106  for(j = 1; j < nfields3d; ++j)
107  {
109  }
110 
111  k=0;
112  for(j = 0; j < nfields2d; ++j)
113  {
114  if (j< nfields2d-1)
115  {
116  for(int i = 0; i < field2ddata.size(); ++i)
117  {
118  Exp2d[j]->ExtractDataToCoeffs(
119  field2ddef[i],
120  field2ddata[i],
121  field2ddef[i]->m_fields[j],
122  Exp3d[j]->GetPlane(k)->UpdateCoeffs());
123  }
124  }
125  if (j==nfields2d-1)
126  {
127  for(int i = 0; i < field2ddata.size(); ++i)
128  {
129  Exp2d[j]->ExtractDataToCoeffs(
130  field2ddef[i],
131  field2ddata[i],
132  field2ddef[i]->m_fields[j],
133  Exp3d[j+1]->GetPlane(k)->UpdateCoeffs());
134  }
135  }
136  }
137  Array<OneD, Array<OneD, NekDouble> > fieldcoeffs(vSession3d->GetVariables().size());
138  for(j = 0; j < fieldcoeffs.num_elements(); ++j)
139  {
140  fieldcoeffs[j] = Exp3d[j]->UpdateCoeffs();
141  for(int i = 0; i < field3ddef.size(); ++i)
142  {
143  Exp3d[0]->AppendFieldData(field3ddef[i], field3ddatanew[i],fieldcoeffs[j]);
144  }
145  }
146  LibUtilities::Write(datasave,field3ddef,field3ddatanew);
147  return 0;
148 }
149 // Only for 2d to 2d5 Hui Xu 23 Aug 2013
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
STL namespace.
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
void Import(const std::string &infilename, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, FieldMetaDataMap &fieldinfomap, const Array< OneD, int > ElementiDs)
Imports an FLD file.
Definition: FieldIO.cpp:115
1D Evenly-spaced points using Lagrange polynomial
Definition: PointsType.h:63
Defines a specification for a set of points.
Definition: Points.h:58
double NekDouble
boost::shared_ptr< ExpList2D > ExpList2DSharedPtr
Shared pointer to an ExpList2D object.
Definition: ExpList2D.h:49
int main(int argc, char *argv[])
Definition: Fld2DTo2D5.cpp:16
boost::shared_ptr< ExpList3DHomogeneous1D > ExpList3DHomogeneous1DSharedPtr
Shared pointer to an ExpList3DHomogeneous1D object.
void Write(const std::string &outFile, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, const FieldMetaDataMap &fieldinfomap)
Write a field file in serial only.
Definition: FieldIO.cpp:81
boost::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:442
Describes the specification for a Basis.
Definition: Basis.h:50