Nektar++
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 std;
7 using namespace Nektar;
8 
9 int main(int argc, char *argv[])
10 {
11  if(argc != 3)
12  {
13  fprintf(stderr,"Usage: ExtractmeanModeFromHomo1DFld fieldfile outfield\n");
14  exit(1);
15  }
16 
17  int i = 0;
18  int k = 0;
19  int n = 0;
20  int nz = 0;
21  int ncoeffs = 0;
22 
23  //----------------------------------------------
24  // Import fieldfile.
25  string fieldfile(argv[argc-2]);
26  vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef;
27  vector<vector<NekDouble> > fielddata;
28  LibUtilities::Import(fieldfile,fielddef,fielddata);
29  //----------------------------------------------
30 
31  vector<vector<NekDouble> > combineddata;
32  vector<LibUtilities::FieldDefinitionsSharedPtr> newfielddef;
33 
34  //----------------------------------------------
35  // put mean data consecutively
36  for(i = 0; i < fielddata.size(); ++i)
37  {
38  ASSERTL0(fielddef[i]->m_numHomogeneousDir == 1,
39  "Expected fieldfile to have one homogeneous direction");
40 
41  if(fielddef[i]->m_homogeneousZIDs[0] != 0)
42  {
43  continue;
44  }
45  else
46  {
47  nz = fielddef[i]->m_homogeneousZIDs.size();
48 
49  fielddef[i]->m_numHomogeneousDir = 0;
50  fielddef[i]->m_basis.resize(2);
51  newfielddef.push_back(fielddef[i]);
52 
53 
54  // Determine the number of coefficients per element
55  switch(fielddef[i]->m_shapeType)
56  {
59  fielddef[i]->m_numModes[0], fielddef[i]->m_numModes[1]);
60  break;
62  ncoeffs = fielddef[i]->m_numModes[0]*fielddef[i]->m_numModes[1];
63  break;
64  default:
65  ASSERTL0(false,"Shape not recognised");
66  break;
67  }
68 
69  vector<NekDouble> newdata;
70  auto vec_iter = fielddata[i].begin();
71 
72  for(k = 0; k < fielddef[i]->m_fields.size(); ++k)
73  {
74  // copy data from each field into consecutive order
75  for(n = 0; n < fielddef[i]->m_elementIDs.size(); ++n)
76  {
77  // put zero mode into newdata
78  newdata.insert(newdata.end(),vec_iter, vec_iter+ncoeffs);
79  vec_iter += nz*ncoeffs;
80  }
81  }
82  combineddata.push_back(newdata);
83  }
84  }
85  //----------------------------------------------
86 
87  //-----------------------------------------------
88  // Write out datafile.
89  LibUtilities::Write(argv[argc-1], newfielddef, combineddata);
90  //-----------------------------------------------
91 
92  return 0;
93 }
94 
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
int main(int argc, char *argv[])
void Import(const std::string &infilename, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, FieldMetaDataMap &fieldinfomap, const Array< OneD, int > &ElementIDs)
This function allows for data to be imported from an FLD file when a session and/or communicator is n...
Definition: FieldIO.cpp:293
void Write(const std::string &outFile, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, const FieldMetaDataMap &fieldinfomap, const bool backup)
This function allows for data to be written to an FLD file when a session and/or communicator is not ...
Definition: FieldIO.cpp:249
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1