6 using namespace Nektar;
8 int main(
int argc,
char *argv[])
14 fprintf(stderr,
"Usage: AddModeTo2DFld scal1 scal2 2Dfieldfile1 fieldfile2 outfield\n"
15 "\t produces scal1*2Dfieldfiel1 + scal2*fieldfile2 in outfield\n" );
19 scal1 = boost::lexical_cast<
double>(argv[argc-5]);
20 scal2 = boost::lexical_cast<
double>(argv[argc-4]);
27 string fieldfile1(argv[argc-3]);
28 vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef1;
29 vector<vector<NekDouble> > fielddata1;
35 string fieldfile2(argv[argc-2]);
36 vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef2;
37 vector<vector<NekDouble> > fielddata2;
41 vector<vector<NekDouble> > combineddata;
43 ASSERTL0(fielddata1.size() == fielddata2.size(),
"Inner has different size");
47 for(
int i = 0; i < fielddata2.size(); ++i)
49 ASSERTL0(fielddef2[i]->m_numHomogeneousDir == 1,
"Expected second fld to have one homogeneous direction");
50 ASSERTL0(fielddef2[i]->m_numModes[2] == 2,
"Expected Fourier field to have 2 modes");
53 int datalen1 = fielddata1[i].size()/fielddef1[i]->m_fields.size();
54 int datalen2 = fielddata2[i].size()/fielddef2[i]->m_fields.size();
56 ASSERTL0(datalen1*2 == datalen2,
"Data per fields is note compatible");
60 switch(fielddef2[i]->m_shapeType)
66 ncoeffs = fielddef2[i]->m_numModes[0]*fielddef2[i]->m_numModes[1];
69 ASSERTL0(
false,
"Shape not recognised");
74 Array<OneD,NekDouble>
Zero(ncoeffs,0.0);
78 for(j = 0; j < fielddata1[i].size(); ++j)
80 fielddata1[i][j] *= scal1;
85 for(j = 0; j < fielddata2[i].size(); ++j)
87 fielddata2[i][j] *= scal2;
93 vector<NekDouble> newdata;
94 vec_iter = fielddata2[i].begin();
96 for(
int k = 0; k < fielddef2[i]->m_fields.size(); ++k)
101 for(j = 0; j < fielddef1[i]->m_fields.size(); ++j)
103 if(fielddef1[i]->m_fields[j] == fielddef2[i]->m_fields[k])
110 if(j != fielddef1[i]->m_fields.size())
112 for(
int n = 0; n < fielddef2[i]->m_elementIDs.size(); ++n)
115 newdata.insert(newdata.end(),&(fielddata1[i][offset+n*ncoeffs]),
116 &(fielddata1[i][offset+n*ncoeffs]) + ncoeffs);
118 newdata.insert(newdata.end(),&Zero[0],&Zero[0] + ncoeffs);
121 newdata.insert(newdata.end(),vec_iter, vec_iter+2*ncoeffs);
122 vec_iter += 2*ncoeffs;
128 for(
int n = 0; n < fielddef2[i]->m_elementIDs.size(); ++n)
131 newdata.insert(newdata.end(),&Zero[0],&Zero[0] + ncoeffs);
132 newdata.insert(newdata.end(),&Zero[0],&Zero[0] + ncoeffs);
135 newdata.insert(newdata.end(),vec_iter, vec_iter+2*ncoeffs);
136 vec_iter += 2*ncoeffs;
140 combineddata.push_back(newdata);
141 fielddef2[i]->m_numModes[2] += 2;
142 fielddef2[i]->m_homogeneousZIDs.push_back(2);
143 fielddef2[i]->m_homogeneousZIDs.push_back(3);
147 for(
int k = 0; k < fielddef1[i]->m_fields.size(); ++k)
149 for(j = 0; j < fielddef2[i]->m_fields.size(); ++j)
151 if(fielddef1[i]->m_fields[k] == fielddef2[i]->m_fields[j])
157 if(j == fielddef2[i]->m_fields.size())
159 cout <<
"Warning: Field \'" << fielddef1[i]->m_fields[k] <<
"\' was not included in output " << endl;