Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
AddModeTo2DFld.cpp File Reference
#include <cstdio>
#include <cstdlib>
#include <SpatialDomains/MeshGraph.h>
#include <StdRegions/StdTriExp.h>
Include dependency graph for AddModeTo2DFld.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 9 of file AddModeTo2DFld.cpp.

References ASSERTL0, Nektar::LibUtilities::eQuadrilateral, Nektar::LibUtilities::eTriangle, Nektar::LibUtilities::StdSegData::getNumberOfCoefficients(), Nektar::LibUtilities::Import(), Nektar::iterator, Vmath::Smul(), Nektar::LibUtilities::Write(), and Vmath::Zero().

10 {
11  NekDouble scal1,scal2;
12 
13  if(argc != 6)
14  {
15  fprintf(stderr,"Usage: AddModeTo2DFld scal1 scal2 2Dfieldfile1 fieldfile2 outfield\n"
16  "\t produces scal1*2Dfieldfiel1 + scal2*fieldfile2 in outfield\n" );
17  exit(1);
18  }
19 
20  scal1 = boost::lexical_cast<double>(argv[argc-5]);
21  scal2 = boost::lexical_cast<double>(argv[argc-4]);
22 
23  //default meshgraph
25 
26  //----------------------------------------------
27  // Import fieldfile1.
28  string fieldfile1(argv[argc-3]);
29  vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef1;
30  vector<vector<NekDouble> > fielddata1;
31  LibUtilities::Import(fieldfile1,fielddef1,fielddata1);
32  //----------------------------------------------
33 
34  //----------------------------------------------
35  // Import fieldfile2.
36  string fieldfile2(argv[argc-2]);
37  vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef2;
38  vector<vector<NekDouble> > fielddata2;
39  LibUtilities::Import(fieldfile2,fielddef2,fielddata2);
40  //----------------------------------------------
41 
42  vector<vector<NekDouble> > combineddata;
43 
44  ASSERTL0(fielddata1.size() == fielddata2.size(),"Inner has different size");
45  //----------------------------------------------
46  // Add fielddata2 to fielddata1 using m_fields definition to align data.
47 
48  int i = 0;
49  int j = 0;
50  int k = 0;
51  int n = 0;
52 
53  for(i = 0; i < fielddata2.size(); ++i)
54  {
55  ASSERTL0(fielddef2[i]->m_numHomogeneousDir == 1,"Expected second fld to have one homogeneous direction");
56  ASSERTL0(fielddef2[i]->m_numModes[2] == 2,"Expected Fourier field to have 2 modes");
57 
58  int datalen1 = fielddata1[i].size()/fielddef1[i]->m_fields.size();
59  int datalen2 = fielddata2[i].size()/fielddef2[i]->m_fields.size();
60 
61  ASSERTL0(datalen1*2 == datalen2,"Data per fields is note compatible");
62 
63  // Determine the number of coefficients per element
64  int ncoeffs = 0;
65  switch(fielddef2[i]->m_shapeType)
66  {
68  ncoeffs = LibUtilities::StdTriData::getNumberOfCoefficients(fielddef2[i]->m_numModes[0], fielddef2[i]->m_numModes[1]);
69  break;
71  ncoeffs = fielddef2[i]->m_numModes[0]*fielddef2[i]->m_numModes[1];
72  break;
73  default:
74  ASSERTL0(false,"Shape not recognised");
75  break;
76  }
77 
78  // array for zero packing
79  Array<OneD,NekDouble> Zero(ncoeffs,0.0);
80 
81  // scale first and second fields
82  Vmath::Smul(fielddata1[i].size(), scal1, &fielddata1[i][0], 1,
83  &fielddata1[i][0], 1);
84  Vmath::Smul(fielddata2[i].size(), scal2, &fielddata2[i][0], 1,
85  &fielddata2[i][0], 1);
86 
88 
89  vector<NekDouble> newdata;
90  vec_iter = fielddata2[i].begin();
91 
92  for(k = 0; k < fielddef2[i]->m_fields.size(); ++k)
93  {
94  // get location of 2D field information in order of field2 ordering
95  int offset = 0;
96  for(j = 0; j < fielddef1[i]->m_fields.size(); ++j)
97  {
98  if(fielddef1[i]->m_fields[j] == fielddef2[i]->m_fields[k])
99  {
100  break;
101  }
102  offset += datalen1;
103  }
104 
105  if(j != fielddef1[i]->m_fields.size())
106  {
107  for(n = 0; n < fielddef2[i]->m_elementIDs.size(); ++n)
108  {
109  // Real zero component
110  newdata.insert(newdata.end(),
111  &(fielddata1[i][offset+n*ncoeffs]),
112  &(fielddata1[i][offset+n*ncoeffs])
113  + ncoeffs);
114 
115  // Imaginary zero component;
116  newdata.insert(newdata.end(),&Zero[0],&Zero[0] + ncoeffs);
117 
118  // Put orginal mode in here.
119  newdata.insert(newdata.end(),vec_iter, vec_iter+2*ncoeffs);
120  vec_iter += 2*ncoeffs;
121  }
122  }
123  else
124  {
125 
126  for(n = 0; n < fielddef2[i]->m_elementIDs.size(); ++n)
127  {
128  // Real & Imag zero component
129  newdata.insert(newdata.end(),&Zero[0],&Zero[0] + ncoeffs);
130  newdata.insert(newdata.end(),&Zero[0],&Zero[0] + ncoeffs);
131 
132  // Put orginal mode in here.
133  newdata.insert(newdata.end(),vec_iter, vec_iter+2*ncoeffs);
134  vec_iter += 2*ncoeffs;
135  }
136  }
137  }
138  combineddata.push_back(newdata);
139  fielddef2[i]->m_numModes[2] += 2;
140  fielddef2[i]->m_homogeneousZIDs.push_back(2);
141  fielddef2[i]->m_homogeneousZIDs.push_back(3);
142 
143  // check to see if any field in fielddef1[i]->m_fields is
144  // not defined in fielddef2[i]->m_fields
145  for(k = 0; k < fielddef1[i]->m_fields.size(); ++k)
146  {
147  for(j = 0; j < fielddef2[i]->m_fields.size(); ++j)
148  {
149  if(fielddef1[i]->m_fields[k] == fielddef2[i]->m_fields[j])
150  {
151  break;
152  }
153  }
154 
155  if(j == fielddef2[i]->m_fields.size())
156  {
157  cout << "Warning: Field \'" << fielddef1[i]->m_fields[k]
158  << "\' was not included in output " << endl;
159  }
160 
161  }
162 
163  }
164  //----------------------------------------------
165 
166  //-----------------------------------------------
167  // Write out datafile.
168  LibUtilities::Write(argv[argc-1], fielddef2, combineddata);
169  //-----------------------------------------------
170 
171  return 0;
172 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
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:279
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*y.
Definition: Vmath.cpp:213
double NekDouble
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:235
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 Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:373