17 using namespace Nektar;
19 int main(
int argc,
char *argv[])
25 fprintf(stderr,
"Usage: ./CalcGrad ifield file.xml file.fld\n");
33 int ifield = atoi(argv[argc-3]);
37 string meshfile(argv[argc-2]);
43 string fieldfile(argv[argc-1]);
44 vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef;
45 vector<vector<NekDouble> > fielddata;
48 bool dealiasing =
false;
53 int expdim = graphShPt->GetMeshDimension();
54 int nfields = fielddef[0]->m_fields.size();
58 if(fielddef[0]->m_numHomogeneousDir == 2)
69 if(fielddef[0]->m_numHomogeneousDir == 1)
85 Array<OneD, MultiRegions::ExpListSharedPtr> Exp(nfields + graddim);
91 ASSERTL0(fielddef[0]->m_numHomogeneousDir <= 2,
"Quasi-3D approach is only set up for 1 or 2 homogeneous directions");
93 if(fielddef[0]->m_numHomogeneousDir == 1)
98 int nplanes = fielddef[0]->m_numModes[1];
103 NekDouble ly = fielddef[0]->m_homogeneousLengths[0];
108 for(i = 1; i < nfields + graddim; ++i)
113 else if(fielddef[0]->m_numHomogeneousDir == 2)
118 int nylines = fielddef[0]->m_numModes[1];
119 int nzlines = fielddef[0]->m_numModes[2];
128 NekDouble ly = fielddef[0]->m_homogeneousLengths[0];
129 NekDouble lz = fielddef[0]->m_homogeneousLengths[1];
134 for(i = 1; i < nfields + graddim; ++i)
145 for(i = 1; i < nfields + graddim; ++i)
155 ASSERTL0(fielddef[0]->m_numHomogeneousDir <= 1,
"NumHomogeneousDir is only set up for 1");
157 if(fielddef[0]->m_numHomogeneousDir == 1)
162 int nplanes = fielddef[0]->m_numModes[2];
168 NekDouble lz = fielddef[0]->m_homogeneousLengths[0];
173 for(i = 1; i < nfields + graddim; ++i)
185 for(i = 1; i < nfields + graddim; ++i)
200 for(i = 1; i < nfields + graddim; ++i)
208 ASSERTL0(
false,
"Expansion dimension not recognised");
214 for(j = 0; j < nfields; ++j)
216 for(
unsigned int i = 0; i < fielddata.size(); ++i)
218 Exp[j]->ExtractDataToCoeffs(fielddef [i],
220 fielddef [i]->m_fields[j],
221 Exp[j]->UpdateCoeffs());
223 Exp[j]->BwdTrans(Exp[j]->GetCoeffs(),Exp[j]->UpdatePhys());
227 int nq = Exp[0]->GetNpoints();
229 Array<OneD, NekDouble> Dy(nq);
230 Array<OneD, NekDouble> Dz(nq);
231 Array<OneD, NekDouble> Dx(nq);
237 if(fielddef[0]->m_numHomogeneousDir == 1)
239 ASSERTL0(
false,
"Not implemented yet");
241 else if(fielddef[0]->m_numHomogeneousDir == 2)
244 Exp[ifield]->GetPhys(),Dx);
246 Exp[ifield]->GetPhys(),Dy);
248 Exp[ifield]->GetPhys(),Dz);
249 Exp[nfields ]->FwdTrans(Dx,Exp[nfields ]->UpdateCoeffs());
250 Exp[nfields+1]->FwdTrans(Dy,Exp[nfields+1]->UpdateCoeffs());
251 Exp[nfields+2]->FwdTrans(Dz,Exp[nfields+2]->UpdateCoeffs());
256 ASSERTL0(
false,
"Not implemented yet");
262 if(fielddef[0]->m_numHomogeneousDir == 1)
267 Exp[nfields ]->FwdTrans(Dx,Exp[nfields ]->UpdateCoeffs());
268 Exp[nfields+1]->FwdTrans(Dy,Exp[nfields+1]->UpdateCoeffs());
269 Exp[nfields+2]->FwdTrans(Dz,Exp[nfields+2]->UpdateCoeffs());
275 Exp[nfields ]->FwdTrans(Dx,Exp[nfields ]->UpdateCoeffs());
276 Exp[nfields+1]->FwdTrans(Dy,Exp[nfields+1]->UpdateCoeffs());
285 Exp[nfields ]->FwdTrans(Dx,Exp[nfields ]->UpdateCoeffs());
286 Exp[nfields+1]->FwdTrans(Dy,Exp[nfields+1]->UpdateCoeffs());
287 Exp[nfields+2]->FwdTrans(Dz,Exp[nfields+2]->UpdateCoeffs());
292 ASSERTL0(
false,
"Expansion dimension not recognised");
299 string fldfilename(argv[2]);
300 string out = fldfilename.substr(0, fldfilename.find_last_of(
"."));
301 string endfile(
"_with_grad.fld");
303 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
304 = Exp[0]->GetFieldDefinitions();
305 std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
307 for(j = 0; j < nfields + graddim; ++j)
309 for(i = 0; i < FieldDef.size(); ++i)
315 std::string val = FieldDef[i]->m_fields[ifield] +
"_x";
316 FieldDef[i]->m_fields.push_back(val.c_str());
318 else if(j == nfields+1)
320 std::string val = FieldDef[i]->m_fields[ifield] +
"_y";
321 FieldDef[i]->m_fields.push_back(val.c_str());
325 std::string val = FieldDef[i]->m_fields[ifield] +
"_z";
326 FieldDef[i]->m_fields.push_back(val.c_str());
331 FieldDef[i]->m_fields.push_back(fielddef[i]->m_fields[j]);
333 Exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);