Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ExtractMeanModeFromHomo1DFld.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <cstdlib>
3 #include <SpatialDomains/MeshGraph.h> // for FieldDefinitions, etc
4 #include <StdRegions/StdTriExp.h>
5 
6 using namespace Nektar;
7 
8 int main(int argc, char *argv[])
9 {
10  if(argc != 3)
11  {
12  fprintf(stderr,"Usage: ExtractmeanModeFromHomo1DFld fieldfile outfield\n");
13  exit(1);
14  }
15 
16  //default meshgraph
18 
19  //----------------------------------------------
20  // Import fieldfile.
21  string fieldfile(argv[argc-2]);
22  vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef;
23  vector<vector<NekDouble> > fielddata;
24  LibUtilities::Import(fieldfile,fielddef,fielddata);
25  //----------------------------------------------
26 
27 
28  vector<vector<NekDouble> > combineddata;
29  vector<LibUtilities::FieldDefinitionsSharedPtr> newfielddef;
30 
31  //----------------------------------------------
32  // put mean data consecutively
33  for(int i = 0; i < fielddata.size(); ++i)
34  {
35  ASSERTL0(fielddef[i]->m_numHomogeneousDir == 1,"Expected fieldfile to have one homogeneous direction");
36 
37  if(fielddef[i]->m_homogeneousZIDs[0] != 0)
38  {
39  continue;
40  }
41  else
42  {
43  int nz = fielddef[i]->m_homogeneousZIDs.size();
44 
45  fielddef[i]->m_numHomogeneousDir = 0;
46  fielddef[i]->m_basis.resize(2);
47  newfielddef.push_back(fielddef[i]);
48 
49 
50  // Determine the number of coefficients per element
51  int ncoeffs;
52  switch(fielddef[i]->m_shapeType)
53  {
55  ncoeffs = LibUtilities::StdTriData::getNumberOfCoefficients(fielddef[i]->m_numModes[0], fielddef[i]->m_numModes[1]);
56  break;
58  ncoeffs = fielddef[i]->m_numModes[0]*fielddef[i]->m_numModes[1];
59  break;
60  default:
61  ASSERTL0(false,"Shape not recognised");
62  break;
63  }
64 
66 
67  vector<NekDouble> newdata;
68  vec_iter = fielddata[i].begin();
69 
70  for(int k = 0; k < fielddef[i]->m_fields.size(); ++k)
71  {
72  // copy data from each field into consecutive order
73  for(int n = 0; n < fielddef[i]->m_elementIDs.size(); ++n)
74  {
75  // put zero mode into newdata
76  newdata.insert(newdata.end(),vec_iter, vec_iter+ncoeffs);
77  vec_iter += nz*ncoeffs;
78  }
79  }
80  combineddata.push_back(newdata);
81  }
82  }
83  //----------------------------------------------
84 
85  //-----------------------------------------------
86  // Write out datafile.
87  LibUtilities::Write(argv[argc-1], newfielddef, combineddata);
88  //-----------------------------------------------
89 
90  return 0;
91 }
92