Nektar++
ExtractMeanModeFromHomo1DFld.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ExtractMeanModeFromHomo1DFld.cpp
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 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description:
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <SpatialDomains/MeshGraph.h> // for FieldDefinitions, etc
36 #include <StdRegions/StdTriExp.h>
37 #include <cstdio>
38 #include <cstdlib>
39 
40 using namespace std;
41 using namespace Nektar;
42 
43 int main(int argc, char *argv[])
44 {
45  if (argc != 3)
46  {
47  fprintf(stderr,
48  "Usage: ExtractmeanModeFromHomo1DFld fieldfile outfield\n");
49  exit(1);
50  }
51 
52  int i = 0;
53  int k = 0;
54  int n = 0;
55  int nz = 0;
56  int ncoeffs = 0;
57 
58  //----------------------------------------------
59  // Import fieldfile.
60  string fieldfile(argv[argc - 2]);
61  vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef;
62  vector<vector<NekDouble>> fielddata;
63  LibUtilities::Import(fieldfile, fielddef, fielddata);
64  //----------------------------------------------
65 
66  vector<vector<NekDouble>> combineddata;
67  vector<LibUtilities::FieldDefinitionsSharedPtr> newfielddef;
68 
69  //----------------------------------------------
70  // put mean data consecutively
71  for (i = 0; i < fielddata.size(); ++i)
72  {
73  ASSERTL0(fielddef[i]->m_numHomogeneousDir == 1,
74  "Expected fieldfile to have one homogeneous direction");
75 
76  if (fielddef[i]->m_homogeneousZIDs[0] != 0)
77  {
78  continue;
79  }
80  else
81  {
82  nz = fielddef[i]->m_homogeneousZIDs.size();
83 
84  fielddef[i]->m_numHomogeneousDir = 0;
85  fielddef[i]->m_basis.resize(2);
86  newfielddef.push_back(fielddef[i]);
87 
88  // Determine the number of coefficients per element
89  switch (fielddef[i]->m_shapeType)
90  {
93  fielddef[i]->m_numModes[0], fielddef[i]->m_numModes[1]);
94  break;
96  ncoeffs =
97  fielddef[i]->m_numModes[0] * fielddef[i]->m_numModes[1];
98  break;
99  default:
100  ASSERTL0(false, "Shape not recognised");
101  break;
102  }
103 
104  vector<NekDouble> newdata;
105  auto vec_iter = fielddata[i].begin();
106 
107  for (k = 0; k < fielddef[i]->m_fields.size(); ++k)
108  {
109  // copy data from each field into consecutive order
110  for (n = 0; n < fielddef[i]->m_elementIDs.size(); ++n)
111  {
112  // put zero mode into newdata
113  newdata.insert(newdata.end(), vec_iter, vec_iter + ncoeffs);
114  vec_iter += nz * ncoeffs;
115  }
116  }
117  combineddata.push_back(newdata);
118  }
119  }
120  //----------------------------------------------
121 
122  //-----------------------------------------------
123  // Write out datafile.
124  LibUtilities::Write(argv[argc - 1], newfielddef, combineddata);
125  //-----------------------------------------------
126 
127  return 0;
128 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
int main(int argc, char *argv[])
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:247
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:290
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2