47 using namespace Nektar;
49 int main(
int argc,
char *argv[])
55 fprintf(stderr,
"Usage: FldQCriterion meshfile infld outfld\n");
65 string meshfile(argv[argc - 3]);
72 string fieldfile(argv[argc - 2]);
73 vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef;
74 vector<vector<NekDouble> > fielddata;
77 bool dealiasing =
false;
82 int expdim = graphShPt->GetMeshDimension();
83 int nfields = fielddef[0]->m_fields.size();
85 Array<OneD, MultiRegions::ExpListSharedPtr> Exp(nfields + addfields);
91 ASSERTL0(fielddef[0]->m_numHomogeneousDir <= 2,
92 "Quasi-3D approach is only set up for 1 or 2 homogeneous "
95 if (fielddef[0]->m_numHomogeneousDir == 1)
101 vSession->LoadParameter(
102 "HomModesZ", nplanes, fielddef[0]->m_numModes[1]);
109 fielddef[0]->m_basis[1], nplanes, Pkey);
110 NekDouble ly = fielddef[0]->m_homogeneousLengths[0];
114 vSession, Bkey, ly, useFFT, dealiasing, graphShPt);
117 for (i = 1; i < nfields; ++i)
123 else if (fielddef[0]->m_numHomogeneousDir == 2)
133 vSession->LoadParameter(
134 "HomModesY", nylines, fielddef[0]->m_numModes[1]);
135 vSession->LoadParameter(
136 "HomModesZ", nzlines, fielddef[0]->m_numModes[2]);
143 fielddef[0]->m_basis[1], nylines, PkeyY);
148 fielddef[0]->m_basis[2], nzlines, PkeyZ);
150 NekDouble ly = fielddef[0]->m_homogeneousLengths[0];
151 NekDouble lz = fielddef[0]->m_homogeneousLengths[1];
155 useFFT, dealiasing, graphShPt);
157 for (i = 1; i < nfields; ++i)
169 for (i = 1; i < nfields + addfields; ++i)
180 ASSERTL0(fielddef[0]->m_numHomogeneousDir <= 1,
181 "NumHomogeneousDir is only set up for 1");
183 if (fielddef[0]->m_numHomogeneousDir == 1)
191 vSession->LoadParameter(
192 "HomModesZ", nplanes, fielddef[0]->m_numModes[2]);
199 fielddef[0]->m_basis[2], nplanes, Pkey);
200 NekDouble lz = fielddef[0]->m_homogeneousLengths[0];
204 dealiasing, graphShPt);
207 for (i = 1; i < nfields + addfields; ++i)
220 for (i = 1; i < nfields + addfields; ++i)
236 for (i = 1; i < nfields + addfields; ++i)
244 ASSERTL0(
false,
"Expansion dimension not recognised");
251 for (j = 0; j < nfields; ++j)
253 for (
int i = 0; i < fielddata.size(); ++i)
255 Exp[j]->ExtractDataToCoeffs(fielddef [i],
257 fielddef [i]->m_fields[j],
258 Exp[j]->UpdateCoeffs());
260 Exp[j]->BwdTrans(Exp[j]->GetCoeffs(), Exp[j]->UpdatePhys());
266 int nq = Exp[0]->GetNpoints();
267 Array<OneD, Array<OneD, NekDouble> > grad(nfields * nfields);
269 Array<OneD, Array<OneD, NekDouble> > omega(nfields * nfields);
270 Array<OneD, Array<OneD, NekDouble> > S (nfields * nfields);
271 Array<OneD, Array<OneD, NekDouble> > Q (nfields * nfields);
273 Array<OneD, Array<OneD, NekDouble> > outfield (addfields);
274 Array<OneD, Array<OneD, NekDouble> > outfield1(addfields);
275 Array<OneD, Array<OneD, NekDouble> > outfield2(addfields);
276 Array<OneD, Array<OneD, NekDouble> > outfield3(addfields);
278 for (i = 0; i < nfields * nfields; ++i)
280 grad[i] = Array<OneD, NekDouble>(nq);
283 for (i = 0; i < addfields; ++i)
285 outfield [i] = Array<OneD, NekDouble>(nq);
286 outfield1[i] = Array<OneD, NekDouble>(nq);
287 outfield2[i] = Array<OneD, NekDouble>(nq);
288 outfield3[i] = Array<OneD, NekDouble>(nq);
290 omega[i] = Array<OneD, NekDouble>(nq);
291 S[i] = Array<OneD, NekDouble>(nq);
292 Q[i] = Array<OneD, NekDouble>(nq);
296 for (i = 0; i < nfields; ++i)
299 Exp[i]->GetPhys(), grad[i * nfields], grad[i * nfields + 1],
300 grad[i * nfields + 2]);
304 Vmath::Vsub(nq, grad[2 * nfields + 1], 1, grad[1 * nfields + 2], 1,
307 Vmath::Vmul(nq, outfield1[0], 1, outfield1[0], 1, outfield1[0], 1);
310 Vmath::Vsub(nq, grad[0 * nfields + 2], 1, grad[2 * nfields + 0], 1,
313 Vmath::Vmul(nq, outfield2[0], 1, outfield2[0], 1, outfield2[0], 1);
316 Vmath::Vsub(nq, grad[1 * nfields + 0], 1, grad[0 * nfields + 1], 1,
319 Vmath::Vmul(nq, outfield3[0], 1, outfield3[0], 1, outfield3[0], 1);
324 Vmath::Vadd(nq, &outfield1[0][0], 1, &outfield2[0][0], 1, &omega[0][0], 1);
325 Vmath::Vadd(nq, &omega[0][0], 1, &outfield3[0][0], 1, &omega[0][0], 1);
327 for (
int k = 0; k < addfields; ++k)
329 Vmath::Smul(nq, fac, &omega[k][0], 1, &omega[k][0], 1);
336 Vmath::Vmul(nq, grad[0 * nfields + 0], 1, grad[0 * nfields + 0], 1,
338 Vmath::Vmul(nq, grad[1 * nfields + 1], 1, grad[1 * nfields + 1], 1,
340 Vmath::Vmul(nq, grad[2 * nfields + 2], 1, grad[2 * nfields + 2], 1,
343 Vmath::Vadd(nq, &outfield1[0][0], 1, &outfield2[0][0], 1, &S[0][0], 1);
344 Vmath::Vadd(nq, &S[0][0], 1, &outfield3[0][0], 1, &S[0][0], 1);
347 Vmath::Vadd(nq, grad[2 * nfields + 1], 1, grad[1 * nfields + 2], 1,
349 Vmath::Vmul(nq, &outfield1[0][0], 1, &outfield1[0][0], 1,
350 &outfield1[0][0], 1);
353 Vmath::Vadd(nq, grad[0 * nfields + 2], 1, grad[2 * nfields + 0], 1,
355 Vmath::Vmul(nq, &outfield2[0][0], 1, &outfield2[0][0], 1,
356 &outfield2[0][0], 1);
359 Vmath::Vadd(nq, grad[1 * nfields + 0], 1, grad[0 * nfields + 1], 1,
361 Vmath::Vmul(nq, &outfield3[0][0], 1, &outfield3[0][0], 1,
362 &outfield3[0][0], 1);
364 Vmath::Vadd(nq, &outfield1[0][0], 1, &outfield2[0][0], 1,
365 &outfield2[0][0], 1);
366 Vmath::Vadd(nq, &outfield2[0][0], 1, &outfield3[0][0], 1,
367 &outfield3[0][0], 1);
369 for (
int k = 0; k < addfields; ++k)
371 Vmath::Smul(nq, fac, &outfield3[k][0], 1, &outfield3[k][0], 1);
374 Vmath::Vadd(nq, &outfield3[0][0], 1, &S[0][0], 1, &S[0][0], 1);
377 for (
int k = 0; k < addfields; ++k)
382 for (i = 0; i < addfields; ++i)
384 Exp[nfields + i]->FwdTrans(Q[i], Exp[nfields + i]->UpdateCoeffs());
389 string out(argv[argc - 1]);
390 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
391 = Exp[0]->GetFieldDefinitions();
392 std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
394 vector<string> outname;
395 outname.push_back(
"Q");
397 for (j = 0; j < nfields + addfields; ++j)
399 for (i = 0; i < FieldDef.size(); ++i)
403 FieldDef[i]->m_fields.push_back(outname[j - nfields]);
407 FieldDef[i]->m_fields.push_back(fielddef[i]->m_fields[j]);
409 Exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);