Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SplitModes.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <cstdlib>
3 
4 #include <StdRegions/StdTriExp.h>
5 #include <SpatialDomains/MeshGraph.h> // for FieldDefinitions, etc
6 
7 using namespace std;
8 using namespace Nektar;
9 
10 int main(int argc, char *argv[])
11 {
12  if(argc != 2)
13  {
14  fprintf(stderr,"Usage: Splitmodes fieldfile \n");
15  exit(1);
16  }
17 
18  //default meshgraph
20 
21 
22  //----------------------------------------------
23  // Import fieldfile2.
24  string fieldfile(argv[argc-1]);
25  vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef;
26  vector<vector<NekDouble> > fielddata;
27  LibUtilities::Import(fieldfile,fielddef,fielddata);
28  //----------------------------------------------
29 
30 
31  ASSERTL0(fielddef[0]->m_numModes[2] > 1,"Expected Fourier field to have at least 2 modes");
32 
33  ASSERTL0(fielddef[0]->m_numHomogeneousDir == 1,"Expected second fld to have one homogeneous direction");
34 
35  int nmodes = fielddef[0]->m_numModes[2];
36 
37  // take off modes from fielddef
38  vector<unsigned int> newNumModes;
39  newNumModes.push_back(fielddef[0]->m_numModes[0]);
40  newNumModes.push_back(fielddef[0]->m_numModes[1]);
41  vector<LibUtilities::BasisType> newBasis;
42  newBasis.push_back(fielddef[0]->m_basis[0]);
43  newBasis.push_back(fielddef[0]->m_basis[1]);
44  for(int i = 0; i < fielddata.size(); ++i)
45  {
46  fielddef[i]->m_numModes = newNumModes;
47  fielddef[i]->m_basis = newBasis;
48  fielddef[i]->m_numHomogeneousDir = 0;
49  }
50 
51 
52  for(int m = 0; m < nmodes; ++m)
53  {
54  vector<vector<NekDouble> > writedata;
55 
56  // outfile
57  string outfile(argv[argc-1]);
58  string out = outfile.substr(0, outfile.find_last_of("."));
59  char num[16] ="";
60  sprintf(num,"%d",(m/2));
61 
62  if(m%2 == 0)
63  {
64  out = out + "_mode_" + num + "_real.fld";
65  }
66  else
67  {
68  out = out + "_mode_" + num + "_imag.fld";
69  }
70 
71  for(int i = 0; i < fielddata.size(); ++i)
72  {
73  vector<NekDouble> newdata;
74 
75  // Determine the number of coefficients per element
76  int ncoeffs;
77  switch(fielddef[i]->m_shapeType)
78  {
80  ncoeffs = LibUtilities::StdTriData::getNumberOfCoefficients(fielddef[i]->m_numModes[0], fielddef[i]->m_numModes[1]);
81  break;
83  ncoeffs = fielddef[i]->m_numModes[0]*fielddef[i]->m_numModes[1];
84  break;
85  default:
86  ASSERTL0(false,"Shape not recognised");
87  break;
88  }
89 
91  vec_iter = fielddata[i].begin();
92 
93  for(int k = 0; k < fielddef[i]->m_fields.size(); ++k)
94  {
95  for(int n = 0; n < fielddef[i]->m_elementIDs.size(); ++n)
96  {
97  // Put orginal mode in here.
98  vec_iter += m*ncoeffs;
99  newdata.insert(newdata.end(),vec_iter,vec_iter+ncoeffs);
100  vec_iter += (nmodes-m)*ncoeffs;
101  }
102  }
103  writedata.push_back(newdata);
104  }
105 
106  //-----------------------------------------------
107  // Write out datafile.
108  LibUtilities::Write(out.c_str(), fielddef, writedata);
109  //-----------------------------------------------
110 
111  }
112  //----------------------------------------------
113 
114 
115  return 0;
116 }
117 
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
STL namespace.
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
int main(int argc, char *argv[])
Definition: SplitModes.cpp:10
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
Base class for a spectral/hp element mesh.
Definition: MeshGraph.h:186
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