Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
FldAddFld.cpp File Reference
#include <cstdio>
#include <cstdlib>
#include <LibUtilities/BasicUtils/ErrorUtil.hpp>
#include <SpatialDomains/MeshGraph.h>
Include dependency graph for FldAddFld.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 10 of file FldAddFld.cpp.

References ASSERTL0, Nektar::LibUtilities::Import(), and Nektar::LibUtilities::Write().

11 {
12  NekDouble scal1,scal2;
13 
14  if(argc != 6)
15  {
16  fprintf(stderr,"Usage: FldAddFld scal1 scal2 fieldfile1 fieldfile2 outfield\n"
17  "\t produces scal1*fieldfiel1 + scal2*fieldfile2 in outfield\n" );
18  exit(1);
19  }
20 
21  scal1 = boost::lexical_cast<double>(argv[argc-5]);
22  scal2 = boost::lexical_cast<double>(argv[argc-4]);
23 
24  //default meshgraph
26 
27  //----------------------------------------------
28  // Import fieldfile1.
29  string fieldfile1(argv[argc-3]);
30  vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef1;
31  vector<vector<NekDouble> > fielddata1;
32  LibUtilities::Import(fieldfile1,fielddef1,fielddata1);
33  //----------------------------------------------
34 
35  //----------------------------------------------
36  // Import fieldfile2.
37  string fieldfile2(argv[argc-2]);
38  vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef2;
39  vector<vector<NekDouble> > fielddata2;
40  LibUtilities::Import(fieldfile2,fielddef2,fielddata2);
41  //----------------------------------------------
42 
43 
44  ASSERTL0(fielddata1.size() == fielddata2.size(),"Inner has different size");
45 
46  //----------------------------------------------
47  // Add fielddata2 to fielddata1 using m_fields definition to align data.
48 
49 
50  for(int i = 0; i < fielddata1.size(); ++i)
51  {
52  int j;
53  int datalen1 = fielddata1[i].size()/fielddef1[i]->m_fields.size();
54  int datalen2 = fielddata2[i].size()/fielddef2[i]->m_fields.size();
55 
56  ASSERTL0(datalen1 == datalen2,"Data per field is of different length");
57 
58  for(int k = 0; k < fielddef1[i]->m_fields.size(); ++k)
59  {
60  int offset = 0;
61  for(j = 0; j < fielddef2[i]->m_fields.size(); ++j)
62  {
63  if(fielddef1[i]->m_fields[k] == fielddef2[i]->m_fields[j])
64  {
65  break;
66  }
67  offset += datalen1;
68  }
69 
70  if(j == fielddef2[i]->m_fields.size())
71  {
72  for(j = 0; j < datalen1; ++j)
73  {
74  fielddata1[i][datalen1*k+j] *= scal1;
75  }
76  }
77  else // add fields
78  {
79  for(j = 0; j < datalen1; ++j)
80  {
81  fielddata1[i][datalen1*k+j] *= scal1;
82  fielddata1[i][datalen1*k+j] += scal2*fielddata2[i][offset + j];
83  }
84  }
85 
86  }
87 
88  // now check to see if any field in fielddef2[i]->m_fields is
89  // not defined in fielddef1[i]->m_fields
90  for(int k = 0; k < fielddef2[i]->m_fields.size(); ++k)
91  {
92  for(j = 0; j < fielddef1[i]->m_fields.size(); ++j)
93  {
94  if(fielddef2[i]->m_fields[k] == fielddef1[i]->m_fields[j])
95  {
96  break;
97  }
98  }
99 
100  if(j == fielddef1[i]->m_fields.size())
101  {
102  for(j = 0; j < datalen2; ++j)
103  {
104  fielddata2[i][datalen2*k+j] *= scal2;
105  }
106 
107  // add this field to fielddata1
108  fielddef1[i]->m_fields.push_back(fielddef2[i]->m_fields[k]);
109  fielddata1[i].insert(fielddata1[i].end(),&(fielddata2[i][k*datalen2]),
110  &(fielddata2[i][k*datalen2])+datalen1);
111  }
112 
113  }
114 
115  }
116  //----------------------------------------------
117 
118  //-----------------------------------------------
119  // Write out datafile.
120  LibUtilities::Write(argv[argc-1], fielddef1, fielddata1);
121  //-----------------------------------------------
122 
123  return 0;
124 }
#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
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
Base class for a spectral/hp element mesh.
Definition: MeshGraph.h:186