13 using namespace Nektar;
15 int main(
int argc,
char *argv[])
18 int surfID, nfiles, nStart;
22 fprintf(stderr,
"Usage: FldAddWSS meshfile nfiles infld BoundaryID\n");
26 surfID = boost::lexical_cast<
int>(argv[argc - 1]);
27 nfiles = boost::lexical_cast<
int>(argv[2]);
29 vector<string> infiles(nfiles), outfiles(nfiles);
39 string basename = argv[3];
40 basename = basename.substr(0, basename.find_last_of(
"."));
41 stringstream filename2;
42 filename2 << basename <<
"_wss.fld";
43 filename2 >> outfiles[0];
47 string basename = argv[3];
48 basename = basename.substr(basename.find_last_of(
"t")+1, basename.find_last_of(
".")-basename.find_last_of(
"t"));
49 stringstream filename3;
50 filename3 << basename;
53 for (i = 0; i< nfiles; ++i)
56 string extension =
".fld";
57 basename = basename.substr(0, basename.find_first_of(
"_"));
58 stringstream filename, filename2;
59 filename << basename <<
"_t" << i + nStart << extension;
60 filename >> infiles[i];
61 filename2 << basename <<
"_t" << i +nStart <<
"_wss.fld";
62 filename2 >> outfiles[i];
66 argv[argc - 1] = argv[argc - 2];
67 argv[argc - 3] = argv[argc - 2];
74 string meshfile(argv[argc-4]);
81 m_kinvis = vSession->GetParameter(
"Kinvis");
86 string fieldfile(argv[3]);
87 vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef;
88 vector<vector<NekDouble> > fielddata;
94 int expdim = graphShPt->GetMeshDimension();
95 int nfields = fielddef[0]->m_fields.size()-1;
96 int addfields = (nfields == 3)? 4:3;
97 int nstress = (nfields == 3)? 6:3;
98 Array<OneD, MultiRegions::ExpListSharedPtr> vel(nfields), shear(addfields);
105 ASSERTL0(
false,
"Expansion dimension not recognised");
111 ASSERTL0(
false,
"Not implemented in 2D");
119 for(i = 1; i < nfields; ++i)
131 vSession->GetVariable(0));
133 m_locToGlobalMap = firstfield->GetLocalToGlobalMap();
136 for(i = 1; i < nfields; ++i)
140 vSession->GetVariable(i));
143 for(i = 0; i < addfields; ++i)
147 vSession->GetVariable(0));
152 ASSERTL0(
false,
"Expansion dimension not recognised");
159 int n, cnt, elmtid, nq, offset, nt, boundary, nfq;
160 Array<OneD, Array<OneD, NekDouble> > grad(nfields*nfields);
161 Array<OneD, Array<OneD, NekDouble> > stress(nstress), fstress(nstress);
162 Array<OneD, Array<OneD, NekDouble> > values(addfields);
167 Array<OneD, int> BoundarytoElmtID, BoundarytoTraceID;
168 Array<OneD, Array<OneD, MultiRegions::ExpListSharedPtr> > BndExp(addfields);
171 for (
int fileNo = 0; fileNo < nfiles ; ++fileNo)
182 for(j = 0; j < nfields; ++j)
184 for(i = 0; i < fielddata.size(); ++i)
186 vel[j]->ExtractDataToCoeffs(fielddef[i],
188 fielddef[i]->m_fields[j],
189 vel[j]->UpdateCoeffs());
192 vel[j]->BwdTrans(vel[j]->GetCoeffs(),vel[j]->UpdatePhys());
195 for(j = 0; j < addfields; ++j)
197 for(i = 0; i < fielddata.size(); ++i)
199 shear[j]->ExtractDataToCoeffs(fielddef[i],
201 fielddef[i]->m_fields[0],
202 shear[j]->UpdateCoeffs());
206 shear[j]->BwdTrans(shear[j]->GetCoeffs(),shear[j]->UpdatePhys());
214 nt = shear[0]->GetNpoints();
215 Array<OneD, const NekDouble> U(nt),V(nt),W(nt);
217 for(j = 0; j < addfields; ++j)
219 values[j] = Array<OneD, NekDouble>(nt);
223 shear[0]->GetBoundaryToElmtMap(BoundarytoElmtID,BoundarytoTraceID);
226 for(j = 0; j < addfields; ++j)
228 BndExp[j] = shear[j]->GetBndCondExpansions();
232 for(cnt = n = 0; n < BndExp[0].num_elements(); ++n)
237 for(i = 0; i < BndExp[0][n]->GetExpSize(); ++i, cnt++)
240 elmtid = BoundarytoElmtID[cnt];
241 elmt = shear[0]->GetExp(elmtid);
242 nq = elmt->GetTotPoints();
243 offset = shear[0]->GetPhys_Offset(elmtid);
247 for(j = 0; j < nfields*nfields; ++j)
249 grad[j] = Array<OneD, NekDouble>(nq);
252 for(j = 0; j < nstress; ++j)
254 stress[j] = Array<OneD, NekDouble>(nq);
269 boundary = BoundarytoTraceID[cnt];
274 const Array<OneD, const Array<OneD, NekDouble> > normals
275 = elmt->GetFaceNormal(boundary);
278 for(j = 0; j < nstress; ++j)
280 fstress[j] = Array<OneD, NekDouble>(nfq);
282 Array<OneD, NekDouble> values2(nfq), S(nfq), Sx(nfq), Sy(nfq), Sz(nfq);
285 U = vel[0]->GetPhys() + offset;
286 V = vel[1]->GetPhys() + offset;
287 W = vel[2]->GetPhys() + offset;
290 elmt->PhysDeriv(U,grad[0],grad[1],grad[2]);
291 elmt->PhysDeriv(V,grad[3],grad[4],grad[5]);
292 elmt->PhysDeriv(W,grad[6],grad[7],grad[8]);
296 Vmath::Smul (nq,(2*m_kinvis),grad[0],1,stress[0],1);
298 Vmath::Smul (nq,(2*m_kinvis),grad[4],1,stress[1],1);
300 Vmath::Smul (nq,(2*m_kinvis),grad[8],1,stress[2],1);
312 for(j = 0; j < nstress; ++j)
314 elmt->GetFacePhysVals(boundary,bc,stress[j],fstress[j]);
318 for (j = 0; j< addfields; j++)
320 values[j] = BndExp[j][n]->UpdateCoeffs() + BndExp[j][n]->GetCoeff_Offset(i);
327 normals[1],1,fstress[3],1,Sx,1);
332 normals[1],1,fstress[1],1,Sy,1);
337 normals[1],1,fstress[5],1,Sz,1);
344 normals[1][0],fstress[3],1,Sx,1);
349 normals[1][0],fstress[1],1,Sy,1);
354 normals[1][0],fstress[5],1,Sz,1);
362 normals[1],1, Sy,1,values2,1);
363 Vmath::Vvtvp (nfq,normals[2],1, Sz,1,values2,1,values2,1);
370 bc->FwdTrans(Sx, values[0]);
374 bc->FwdTrans(Sy, values[1]);
378 bc->FwdTrans(Sz, values[2]);
384 normals[1][0],Sy,1,values2,1);
385 Vmath::Svtvp(nfq,normals[2][0],Sz,1,values2,1,values2,1);
391 bc->FwdTrans(Sx, values[0]);
395 bc->FwdTrans(Sy, values[1]);
399 bc->FwdTrans(Sz, values[2]);
404 Vmath::Vvtvvtp(nfq, Sx, 1, Sx, 1, Sy, 1, Sy, 1, S, 1);
407 bc->FwdTrans(S, values[3]);
413 cnt += BndExp[0][n]->GetExpSize();
418 for(j = 0; j < addfields; ++j)
420 int ncoeffs = shear[j]->GetNcoeffs();
421 Array<OneD, NekDouble> output(ncoeffs);
423 output=shear[j]->UpdateCoeffs();
425 int nGlobal=m_locToGlobalMap->GetNumGlobalCoeffs();
426 Array<OneD, NekDouble> outarray(nGlobal,0.0);
430 const Array<OneD,const int>& map = m_locToGlobalMap->GetBndCondCoeffsToGlobalCoeffsMap();
433 for(i = 0; i < BndExp[j].num_elements(); ++i)
437 const Array<OneD,const NekDouble>& coeffs = BndExp[j][i]->GetCoeffs();
438 for(k = 0; k < (BndExp[j][i])->GetNcoeffs(); ++k)
440 sign = m_locToGlobalMap->GetBndCondCoeffsToGlobalCoeffsSign(bndcnt);
441 outarray[map[bndcnt++]] = sign * coeffs[k];
446 bndcnt += BndExp[j][i]->GetNcoeffs();
449 m_locToGlobalMap->GlobalToLocal(outarray,output);
455 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
456 = shear[0]->GetFieldDefinitions();
457 std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
459 vector<string > outname;
467 outname.push_back(
"Tx");
468 outname.push_back(
"Ty");
469 outname.push_back(
"Tz");
470 outname.push_back(
"Tw");
473 for(j = 0; j < nfields + addfields; ++j)
475 for(i = 0; i < FieldDef.size(); ++i)
479 FieldDef[i]->m_fields.push_back(fielddef[i]->m_fields[j]);
480 vel[j]->AppendFieldData(FieldDef[i], FieldData[i]);
484 FieldDef[i]->m_fields.push_back(outname[j-nfields]);
485 shear[j-nfields]->AppendFieldData(FieldDef[i], FieldData[i]);