Evaluation of the velocity gradient in the cartesian directions Du_x: traceFieldsAdded[10] Du_y: traceFieldsAdded[11] Dv_x: traceFieldsAdded[12] Dv_y: traceFieldsAdded[13]
73 string fname = std::string(argv[2]);
74 int fdot = fname.find_last_of(
'.');
75 if (fdot != std::string::npos)
77 string ending = fname.substr(fdot);
82 if (ending ==
".chk" || ending ==
".fld")
84 fname = fname.substr(0,fdot);
88 fname = fname +
".txt";
96 int nBndEdgePts, nBndEdges, nBndRegions;
101 "Usage: ExtractSurface2DCFS meshfile fieldFile\n");
103 "Extracts a surface from a 2D fld file"
104 "(only for CompressibleFlowSolver and purely 2D .fld files)\n");
109 = LibUtilities::SessionReader::CreateInstance(3, argv);
111 std::string m_ViscosityType;
124 int nDimensions = m_spacedim;
128 ASSERTL0(vSession->DefinesParameter(
"Gamma"),
129 "Compressible flow sessions must define a Gamma parameter.");
130 vSession->LoadParameter(
"Gamma", m_gamma, 1.4);
133 ASSERTL0(vSession->DefinesParameter(
"pInf"),
134 "Compressible flow sessions must define a pInf parameter.");
135 vSession->LoadParameter(
"pInf", m_pInf, 101325);
138 ASSERTL0(vSession->DefinesParameter(
"rhoInf"),
139 "Compressible flow sessions must define a rhoInf parameter.");
140 vSession->LoadParameter(
"rhoInf", m_rhoInf, 1.225);
143 ASSERTL0(vSession->DefinesParameter(
"uInf"),
144 "Compressible flow sessions must define a uInf parameter.");
145 vSession->LoadParameter(
"uInf", m_uInf, 0.1);
148 if (m_spacedim == 2 || m_spacedim == 3)
150 ASSERTL0(vSession->DefinesParameter(
"vInf"),
151 "Compressible flow sessions must define a vInf parameter"
152 "for 2D/3D problems.");
153 vSession->LoadParameter(
"vInf", m_vInf, 0.0);
159 ASSERTL0(vSession->DefinesParameter(
"wInf"),
160 "Compressible flow sessions must define a wInf parameter"
162 vSession->LoadParameter(
"wInf", m_wInf, 0.0);
165 vSession->LoadParameter (
"GasConstant", m_gasConstant, 287.058);
166 vSession->LoadParameter (
"Twall", m_Twall, 300.15);
167 vSession->LoadSolverInfo(
"ViscosityType", m_ViscosityType,
"Constant");
168 vSession->LoadParameter (
"mu", m_mu, 1.78e-05);
172 string meshfile(argv[1]);
174 SpatialDomains::MeshGraph::Read(vSession);
179 string fieldFile(argv[2]);
180 vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
181 vector<vector<NekDouble> > fieldData;
188 vector< vector<LibUtilities::PointsType> > pointsType;
189 for (i = 0; i < fieldDef.size(); ++i)
191 vector<LibUtilities::PointsType> ptype;
192 for (j = 0; j < 2; ++j)
196 pointsType.push_back(ptype);
198 graphShPt->SetExpansions(fieldDef, pointsType);
205 int nfields = fieldDef[0]->m_fields.size();
209 for(i = 0; i < pFields.num_elements(); i++)
213 vSession, graphShPt, vSession->GetVariable(i));
222 for (i = 1; i < nfields; ++i)
228 int nSolutionPts = pFields[0]->GetNpoints();
229 int nTracePts = pFields[0]->GetTrace()->GetTotPoints();
230 int nElements = pFields[0]->GetExpSize();
246 pFields[0]->GetCoords(x, y, z);
248 pFields[0]->ExtractTracePhys(x, traceX);
249 pFields[0]->ExtractTracePhys(y, traceY);
250 pFields[0]->ExtractTracePhys(z, traceZ);
260 for (j = 0; j < nfields; ++j)
267 for (i = 0; i < fieldData.size(); ++i)
269 Exp[j]->ExtractDataToCoeffs(fieldDef[i], fieldData[i],
270 fieldDef[i]->m_fields[j],
271 Exp[j]->UpdateCoeffs());
273 Exp[j]->BwdTrans(Exp[j]->GetCoeffs(), Exp[j]->UpdatePhys());
274 Vmath::Vcopy(nSolutionPts, Exp[j]->GetPhys(), 1, uFields[j], 1);
275 pFields[0]->ExtractTracePhys(uFields[j], traceFields[j]);
280 int nfieldsAdded = 20;
284 for (j = 0; j < nfieldsAdded; ++j)
298 for(i = 0; i < nDimensions; ++i)
302 pFields[0]->GetTrace()->GetNormals(m_traceNormals);
305 for(i = 0; i < nDimensions; ++i)
313 &m_traceNormals[0][0], 1,
314 &traceFieldsAdded[0][0], 1);
318 &m_traceNormals[1][0], 1,
319 &traceFieldsAdded[1][0], 1);
323 &m_traceNormals[1][0], 1,
324 &m_traceTangents[0][0], 1);
325 Vmath::Neg(nTracePts, &m_traceTangents[0][0], 1);
328 &m_traceTangents[0][0], 1,
329 &traceFieldsAdded[2][0], 1);
333 &m_traceNormals[0][0], 1,
334 &m_traceTangents[1][0], 1);
337 &m_traceTangents[1][0], 1,
338 &traceFieldsAdded[3][0], 1);
348 for (i = 0; i < m_spacedim; i++)
351 &uFields[i + 1][0], 1,
352 &uFields[i + 1][0], 1,
372 &uFields[nfields - 1][0], 1,
381 pFields[0]->ExtractTracePhys(pressure, traceFieldsAdded[4]);
395 NekDouble GasConstantInv = 1.0/m_gasConstant;
401 pFields[0]->ExtractTracePhys(temperature, traceFieldsAdded[5]);
410 for (i = 0; i < nDimensions; ++ i)
416 for (i = 0; i < nDimensions; ++ i)
418 for (n = 0; n < nElements; n++)
420 phys_offset = pFields[0]->GetPhys_Offset(n);
422 pFields[i]->GetExp(n)->PhysDeriv(
423 i, temperature + phys_offset,
424 auxArray = Dtemperature[i] + phys_offset);
427 pFields[0]->ExtractTracePhys(Dtemperature[i], traceDtemperature[i]);
430 for(i = 0; i < nDimensions; ++i)
433 &m_traceNormals[i][0], 1,
434 &traceDtemperature[i][0], 1,
438 &traceFieldsAdded[6][0], 1,
440 &traceFieldsAdded[6][0], 1);
452 for (i = 0; i < nDimensions; ++ i)
458 for (i = 0; i < nDimensions; ++ i)
460 for (n = 0; n < nElements; n++)
462 phys_offset = pFields[0]->GetPhys_Offset(n);
464 pFields[i]->GetExp(n)->PhysDeriv(
465 i, pressure + phys_offset,
466 auxArray = Dpressure[i] + phys_offset);
469 pFields[0]->ExtractTracePhys(Dpressure[i], traceDpressure[i]);
473 for(i = 0; i < nDimensions; ++i)
476 &m_traceTangents[i][0], 1,
477 &traceDpressure[i][0], 1,
481 &traceFieldsAdded[7][0], 1,
483 &traceFieldsAdded[7][0], 1);
488 &traceDpressure[0][0], 1,
489 &traceFieldsAdded[8][0], 1);
493 &traceDpressure[1][0], 1,
494 &traceFieldsAdded[9][0], 1);
506 for (i = 0; i < nDimensions; ++ i)
512 Vmath::Vdiv(nSolutionPts, uFields[i+1], 1, uFields[0], 1,
515 for (j = 0; j < nDimensions; ++j)
522 for (i = 0; i < nDimensions; ++i)
524 for (j = 0; j < nDimensions; ++j)
526 for (n = 0; n < nElements; n++)
528 phys_offset = pFields[0]->GetPhys_Offset(n);
530 pFields[i]->GetExp(n)->PhysDeriv(
531 j, velocity[i] + phys_offset,
532 auxArray = Dvelocity[i][j] + phys_offset);
536 pFields[0]->ExtractTracePhys(Dvelocity[i][j], traceDvelocity[i][j]);
541 &traceDvelocity[0][0][0], 1,
542 &traceFieldsAdded[10][0], 1);
544 &traceDvelocity[0][1][0], 1,
545 &traceFieldsAdded[11][0], 1);
547 &traceDvelocity[1][0][0], 1,
548 &traceFieldsAdded[12][0], 1);
550 &traceDvelocity[1][1][0], 1,
551 &traceFieldsAdded[13][0], 1);
569 if (m_ViscosityType ==
"Variable")
572 NekDouble T_star = m_pInf / (m_rhoInf * m_gasConstant);
575 for (
int i = 0; i < nSolutionPts; ++i)
577 ratio = temperature[i] / T_star;
578 mu[i] = mu_star * ratio * sqrt(ratio) *
579 (T_star + 110.0) / (temperature[i] + 110.0);
592 Vmath::Smul(nSolutionPts, 2.0, &mu[0], 1, &mu2[0], 1);
596 &Dvelocity[0][0][0], 1, &divVel[0], 1);
598 &Dvelocity[1][1][0], 1, &divVel[0], 1);
601 Vmath::Smul(nSolutionPts, lambda, &divVel[0], 1, &divVel[0], 1);
602 Vmath::Vmul(nSolutionPts, &mu[0], 1, &divVel[0], 1, &divVel[0], 1);
606 for (j = 0; j < m_spacedim; ++j)
611 Vmath::Vmul(nSolutionPts, &mu2[0], 1, &Dvelocity[j][j][0], 1,
614 Vmath::Vadd(nSolutionPts, &temp[j][0], 1, &divVel[0], 1, &Sgg[j][0], 1);
622 &Dvelocity[1][0][0], 1, &Sxy[0], 1);
625 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Sxy[0], 1, &Sxy[0], 1);
627 pFields[0]->ExtractTracePhys(Sgg[0], traceFieldsAdded[14]);
628 pFields[0]->ExtractTracePhys(Sgg[1], traceFieldsAdded[15]);
629 pFields[0]->ExtractTracePhys(Sxy, traceFieldsAdded[16]);
644 Vmath::Vcopy(nTracePts, &m_traceNormals[0][0], 1, &cosTeta[0], 1);
647 Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &sinTeta[0], 1);
650 Vmath::Vsub(nTracePts, &traceFieldsAdded[14][0], 1,
651 &traceFieldsAdded[15][0], 1, &sigma_diff[0], 1);
654 Vmath::Vmul(nTracePts, &cosTeta[0], 1, &sinTeta[0], 1, &tmpTeta[0], 1);
655 Vmath::Smul(nTracePts, 2.0, &tmpTeta[0], 1, &sin2Teta[0], 1);
658 Vmath::Vmul(nTracePts, &cosTeta[0], 1, &cosTeta[0], 1, &cos2Teta[0], 1);
659 Vmath::Vmul(nTracePts, &sinTeta[0], 1, &sinTeta[0], 1, &tmpTeta[0], 1);
660 Vmath::Vsub(nTracePts, &cos2Teta[0], 1, &tmpTeta[0], 1, &cos2Teta[0], 1);
663 Vmath::Smul(nTracePts, -0.5, &sigma_diff[0], 1, &sigma_diff[0], 1);
664 Vmath::Vmul(nTracePts, &sigma_diff[0], 1, &sin2Teta[0], 1, &tau_t[0], 1);
665 Vmath::Vmul(nTracePts, &traceFieldsAdded[16][0], 1, &cos2Teta[0], 1,
667 Vmath::Vadd(nTracePts, &tau_t[0], 1, &tmpTeta[0], 1, &tau_t[0], 1);
669 Vmath::Vcopy(nTracePts, &tau_t[0], 1, &traceFieldsAdded[17][0], 1);
675 pFields[0]->ExtractTracePhys(mu, traceFieldsAdded[18]);
685 Vmath::Vdiv (nSolutionPts, pressure, 1, uFields[0], 1, soundspeed, 1);
686 Vmath::Smul (nSolutionPts, gamma, soundspeed, 1, soundspeed, 1);
687 Vmath::Vsqrt(nSolutionPts, soundspeed, 1, soundspeed, 1);
692 for (
int i = 0; i < m_spacedim; ++i)
694 Vmath::Vvtvp(nSolutionPts, uFields[i + 1], 1, uFields[i + 1], 1,
698 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
699 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
701 Vmath::Vdiv(nSolutionPts, mach, 1, soundspeed, 1, mach, 1);
703 pFields[0]->ExtractTracePhys(mach, traceFieldsAdded[19]);
708 if (pFields[0]->GetBndCondExpansions().num_elements())
712 nBndRegions = pFields[0]->GetBndCondExpansions().num_elements();
713 for (b = 0; b < nBndRegions; ++b)
715 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
716 for (e = 0; e < nBndEdges; ++e)
718 nBndEdgePts = pFields[0]->
719 GetBndCondExpansions()[b]->GetExp(e)->GetNumPoints(0);
721 id2 = pFields[0]->GetTrace()->
722 GetPhys_Offset(pFields[0]->GetTraceMap()->
723 GetBndCondTraceToGlobalTraceMap(cnt++));
725 if (pFields[0]->GetBndConditions()[b]->
726 GetUserDefined() ==
"WallViscous" ||
727 pFields[0]->GetBndConditions()[b]->
728 GetUserDefined() ==
"WallAdiabatic" ||
729 pFields[0]->GetBndConditions()[b]->
730 GetUserDefined() ==
"Wall")
748 if (pFields[0]->GetBndCondExpansions().num_elements())
750 for (j = 0; j < nfields; ++j)
754 nBndRegions = pFields[j]->GetBndCondExpansions().num_elements();
755 for (b = 0; b < nBndRegions; ++b)
757 nBndEdges = pFields[j]->GetBndCondExpansions()[b]->GetExpSize();
758 for (e = 0; e < nBndEdges; ++e)
760 nBndEdgePts = pFields[j]->
761 GetBndCondExpansions()[b]->GetExp(e)->GetNumPoints(0);
763 id2 = pFields[j]->GetTrace()->
764 GetPhys_Offset(pFields[j]->GetTraceMap()->
765 GetBndCondTraceToGlobalTraceMap(cnt++));
767 if (pFields[j]->GetBndConditions()[b]->
768 GetUserDefined() ==
"WallViscous" ||
769 pFields[j]->GetBndConditions()[b]->
770 GetUserDefined() ==
"WallAdiabatic" ||
771 pFields[j]->GetBndConditions()[b]->
772 GetUserDefined() ==
"Wall")
775 &surfaceFields[j][id1], 1);
785 if (pFields[0]->GetBndCondExpansions().num_elements())
787 for (j = 0; j < nfieldsAdded; ++j)
791 nBndRegions = pFields[0]->GetBndCondExpansions().num_elements();
792 for (b = 0; b < nBndRegions; ++b)
794 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
795 for (e = 0; e < nBndEdges; ++e)
797 nBndEdgePts = pFields[0]->
798 GetBndCondExpansions()[b]->GetExp(e)->GetNumPoints(0);
800 id2 = pFields[0]->GetTrace()->
801 GetPhys_Offset(pFields[0]->GetTraceMap()->
802 GetBndCondTraceToGlobalTraceMap(cnt++));
804 if (pFields[0]->GetBndConditions()[b]->
805 GetUserDefined() ==
"WallViscous" ||
806 pFields[0]->GetBndConditions()[b]->
807 GetUserDefined() ==
"WallAdiabatic" ||
808 pFields[0]->GetBndConditions()[b]->
809 GetUserDefined() ==
"Wall")
812 &surfaceFieldsAdded[j][id1], 1);
823 std::string vEquation = vSession->GetSolverInfo(
"EQType");
826 BndExp = pFields[0]->GetBndCondExpansions();
837 for(
int i = 0; i < BndExp[0]->GetExpSize(); ++i)
860 for(
int j = 0; j < nbc; ++j)
863 nxOnBnd[j] = surfaceFieldsAdded[0][GlobalIndex];
864 nyOnBnd[j] = surfaceFieldsAdded[1][GlobalIndex];
865 txOnBnd[j] = surfaceFieldsAdded[2][GlobalIndex];
866 tyOnBnd[j] = surfaceFieldsAdded[3][GlobalIndex];
868 PressurOnBnd[j] = surfaceFieldsAdded[4][GlobalIndex];
870 if (vEquation ==
"NavierStokesCFE")
872 ShearStressOnBnd[j] = surfaceFieldsAdded[17][GlobalIndex];
889 Vmath::Vmul(nbc,PressurOnBnd,1,nxOnBnd,1, drag_p,1);
890 Vmath::Vmul(nbc,PressurOnBnd,1,nyOnBnd,1, lift_p,1);
895 Fxp += bc->Integral(drag_p);
896 Fyp += bc->Integral(lift_p);
898 if (vEquation ==
"NavierStokesCFE")
900 Vmath::Vmul(nbc,ShearStressOnBnd,1,txOnBnd,1, drag_v,1);
901 Vmath::Vmul(nbc,ShearStressOnBnd,1,tyOnBnd,1, lift_v,1);
906 Fxv += bc->Integral(drag_v);
907 Fyv += bc->Integral(lift_v);
910 Sref += bc->Integral(Unity);
914 cout <<
"\n Sref = " << Sref << endl;
919 cout <<
" Pressure drag (Fxp) = " << Fxp << endl;
920 cout <<
" Pressure lift (Fyp) = " << Fyp << endl;
921 cout <<
" Viscous drag (Fxv) = " << Fxv << endl;
922 cout <<
" Viscous lift (Fyv) = " << Fyv << endl;
923 cout <<
"\n ==> Total drag = " << Fxp+Fxv << endl;
924 cout <<
" ==> Total lift = " << Fyp+Fyv <<
"\n" << endl;
933 outfile.open(fname.c_str());
934 outfile <<
"% x[m] " <<
" \t"
941 <<
"rho[kg/m^3] " <<
" \t"
942 <<
"rhou[kg/(m^2 s)] " <<
" \t"
943 <<
"rhov[kg/(m^2 s)] " <<
" \t"
947 <<
"dT/dn[k/m] " <<
" \t"
948 <<
"dp/dT[Pa/m] " <<
" \t"
949 <<
"dp/dx[Pa/m] " <<
" \t"
950 <<
"dp/dy[Pa/m] " <<
" \t"
951 <<
"du/dx[s^-1] " <<
" \t"
952 <<
"du/dy[s^-1] " <<
" \t"
953 <<
"dv/dx[s^-1] " <<
" \t"
954 <<
"dv/dy[s^-1] " <<
" \t"
955 <<
"tau_xx[Pa] " <<
" \t"
956 <<
"tau_yy[Pa] " <<
" \t"
957 <<
"tau_xy[Pa] " <<
" \t"
958 <<
"tau_t[Pa] " <<
" \t"
959 <<
"mu[Pa s] " <<
" \t"
963 for (i = 0; i < id1; ++i)
965 outfile << scientific
968 << surfaceX[i] <<
" \t "
969 << surfaceY[i] <<
" \t "
970 << surfaceZ[i] <<
" \t "
971 << surfaceFieldsAdded[0][i] <<
" \t "
972 << surfaceFieldsAdded[1][i] <<
" \t "
973 << surfaceFieldsAdded[2][i] <<
" \t "
974 << surfaceFieldsAdded[3][i] <<
" \t "
975 << surfaceFields[0][i] <<
" \t "
976 << surfaceFields[1][i] <<
" \t "
977 << surfaceFields[2][i] <<
" \t "
978 << surfaceFields[3][i] <<
" \t "
979 << surfaceFieldsAdded[4][i] <<
" \t "
980 << surfaceFieldsAdded[5][i] <<
" \t "
981 << surfaceFieldsAdded[6][i] <<
" \t "
982 << surfaceFieldsAdded[7][i] <<
" \t "
983 << surfaceFieldsAdded[8][i] <<
" \t "
984 << surfaceFieldsAdded[9][i] <<
" \t "
985 << surfaceFieldsAdded[10][i] <<
" \t "
986 << surfaceFieldsAdded[11][i] <<
" \t "
987 << surfaceFieldsAdded[12][i] <<
" \t "
988 << surfaceFieldsAdded[13][i] <<
" \t "
989 << surfaceFieldsAdded[14][i] <<
" \t "
990 << surfaceFieldsAdded[15][i] <<
" \t "
991 << surfaceFieldsAdded[16][i] <<
" \t "
992 << surfaceFieldsAdded[17][i] <<
" \t "
993 << surfaceFieldsAdded[18][i] <<
" \t "
994 << surfaceFieldsAdded[19][i] <<
" \t "
998 outfile << endl << endl;
#define ASSERTL0(condition, msg)
void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
sqrt y = sqrt(x)
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...
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
void Vdiv(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x/y.
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
1D Evenly-spaced points using Lagrange polynomial
int GetTotPoints() const
This function returns the total number of quadrature points used in the element.
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*y.
boost::shared_ptr< StdExpansion1D > StdExpansion1DSharedPtr
void Neg(int n, T *x, const int incx)
Negate x = -x.
boost::shared_ptr< ExpList2D > ExpList2DSharedPtr
Shared pointer to an ExpList2D object.
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
boost::shared_ptr< MeshGraph > MeshGraphSharedPtr
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.