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]
72 string fname = std::string(argv[2]);
73 int fdot = fname.find_last_of(
'.');
74 if (fdot != std::string::npos)
76 string ending = fname.substr(fdot);
81 if (ending ==
".chk" || ending ==
".fld")
83 fname = fname.substr(0,fdot);
87 fname = fname +
".txt";
95 int nBndEdgePts, nBndEdges, nBndRegions;
100 "Usage: ExtractSurface2DCFS meshfile fieldFile\n");
102 "Extracts a surface from a 2D fld file"
103 "(only for CompressibleFlowSolver and purely 2D .fld files)\n");
108 = LibUtilities::SessionReader::CreateInstance(3, argv);
110 SpatialDomains::MeshGraph::Read(vSession);
112 std::string m_ViscosityType;
125 int nDimensions = m_spacedim;
129 ASSERTL0(vSession->DefinesParameter(
"Gamma"),
130 "Compressible flow sessions must define a Gamma parameter.");
131 vSession->LoadParameter(
"Gamma", m_gamma, 1.4);
134 ASSERTL0(vSession->DefinesParameter(
"pInf"),
135 "Compressible flow sessions must define a pInf parameter.");
136 vSession->LoadParameter(
"pInf", m_pInf, 101325);
139 ASSERTL0(vSession->DefinesParameter(
"rhoInf"),
140 "Compressible flow sessions must define a rhoInf parameter.");
141 vSession->LoadParameter(
"rhoInf",
m_rhoInf, 1.225);
144 ASSERTL0(vSession->DefinesParameter(
"uInf"),
145 "Compressible flow sessions must define a uInf parameter.");
146 vSession->LoadParameter(
"uInf",
m_uInf, 0.1);
149 if (m_spacedim == 2 || m_spacedim == 3)
151 ASSERTL0(vSession->DefinesParameter(
"vInf"),
152 "Compressible flow sessions must define a vInf parameter"
153 "for 2D/3D problems.");
154 vSession->LoadParameter(
"vInf",
m_vInf, 0.0);
160 ASSERTL0(vSession->DefinesParameter(
"wInf"),
161 "Compressible flow sessions must define a wInf parameter"
163 vSession->LoadParameter(
"wInf", m_wInf, 0.0);
166 vSession->LoadParameter (
"GasConstant", m_gasConstant, 287.058);
167 vSession->LoadParameter (
"Twall",
m_Twall, 300.15);
168 vSession->LoadSolverInfo(
"ViscosityType", m_ViscosityType,
"Constant");
169 vSession->LoadParameter (
"mu",
m_mu, 1.78e-05);
173 string fieldFile(argv[2]);
174 vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
175 vector<vector<NekDouble> > fieldData;
182 vector< vector<LibUtilities::PointsType> > pointsType;
183 for (i = 0; i < fieldDef.size(); ++i)
185 vector<LibUtilities::PointsType> ptype;
186 for (j = 0; j < 2; ++j)
190 pointsType.push_back(ptype);
192 graphShPt->SetExpansions(fieldDef, pointsType);
199 int nfields = fieldDef[0]->m_fields.size();
203 for(i = 0; i < pFields.num_elements(); i++)
207 vSession, graphShPt, vSession->GetVariable(i));
216 for (i = 1; i < nfields; ++i)
222 int nSolutionPts = pFields[0]->GetNpoints();
223 int nTracePts = pFields[0]->GetTrace()->GetTotPoints();
224 int nElements = pFields[0]->GetExpSize();
240 pFields[0]->GetCoords(x, y, z);
242 pFields[0]->ExtractTracePhys(x, traceX);
243 pFields[0]->ExtractTracePhys(y, traceY);
244 pFields[0]->ExtractTracePhys(z, traceZ);
254 for (j = 0; j < nfields; ++j)
261 for (i = 0; i < fieldData.size(); ++i)
263 Exp[j]->ExtractDataToCoeffs(fieldDef[i], fieldData[i],
264 fieldDef[i]->m_fields[j],
265 Exp[j]->UpdateCoeffs());
267 Exp[j]->BwdTrans(Exp[j]->GetCoeffs(), Exp[j]->UpdatePhys());
268 Vmath::Vcopy(nSolutionPts, Exp[j]->GetPhys(), 1, uFields[j], 1);
269 pFields[0]->ExtractTracePhys(uFields[j], traceFields[j]);
274 int nfieldsAdded = 20;
278 for (j = 0; j < nfieldsAdded; ++j)
292 for(i = 0; i < nDimensions; ++i)
296 pFields[0]->GetTrace()->GetNormals(m_traceNormals);
299 for(i = 0; i < nDimensions; ++i)
307 &m_traceNormals[0][0], 1,
308 &traceFieldsAdded[0][0], 1);
312 &m_traceNormals[1][0], 1,
313 &traceFieldsAdded[1][0], 1);
317 &m_traceNormals[1][0], 1,
318 &m_traceTangents[0][0], 1);
319 Vmath::Neg(nTracePts, &m_traceTangents[0][0], 1);
322 &m_traceTangents[0][0], 1,
323 &traceFieldsAdded[2][0], 1);
327 &m_traceNormals[0][0], 1,
328 &m_traceTangents[1][0], 1);
331 &m_traceTangents[1][0], 1,
332 &traceFieldsAdded[3][0], 1);
342 for (i = 0; i < m_spacedim; i++)
345 &uFields[i + 1][0], 1,
346 &uFields[i + 1][0], 1,
366 &uFields[nfields - 1][0], 1,
375 pFields[0]->ExtractTracePhys(
pressure, traceFieldsAdded[4]);
389 NekDouble GasConstantInv = 1.0/m_gasConstant;
395 pFields[0]->ExtractTracePhys(temperature, traceFieldsAdded[5]);
404 for (i = 0; i < nDimensions; ++ i)
410 for (i = 0; i < nDimensions; ++ i)
412 for (n = 0; n < nElements; n++)
414 phys_offset = pFields[0]->GetPhys_Offset(n);
416 pFields[i]->GetExp(n)->PhysDeriv(
417 i, temperature + phys_offset,
418 auxArray = Dtemperature[i] + phys_offset);
421 pFields[0]->ExtractTracePhys(Dtemperature[i], traceDtemperature[i]);
424 for(i = 0; i < nDimensions; ++i)
427 &m_traceNormals[i][0], 1,
428 &traceDtemperature[i][0], 1,
432 &traceFieldsAdded[6][0], 1,
434 &traceFieldsAdded[6][0], 1);
446 for (i = 0; i < nDimensions; ++ i)
452 for (i = 0; i < nDimensions; ++ i)
454 for (n = 0; n < nElements; n++)
456 phys_offset = pFields[0]->GetPhys_Offset(n);
458 pFields[i]->GetExp(n)->PhysDeriv(
460 auxArray = Dpressure[i] + phys_offset);
463 pFields[0]->ExtractTracePhys(Dpressure[i], traceDpressure[i]);
467 for(i = 0; i < nDimensions; ++i)
470 &m_traceTangents[i][0], 1,
471 &traceDpressure[i][0], 1,
475 &traceFieldsAdded[7][0], 1,
477 &traceFieldsAdded[7][0], 1);
482 &traceDpressure[0][0], 1,
483 &traceFieldsAdded[8][0], 1);
487 &traceDpressure[1][0], 1,
488 &traceFieldsAdded[9][0], 1);
500 for (i = 0; i < nDimensions; ++ i)
506 Vmath::Vdiv(nSolutionPts, uFields[i+1], 1, uFields[0], 1,
509 for (j = 0; j < nDimensions; ++j)
516 for (i = 0; i < nDimensions; ++i)
518 for (j = 0; j < nDimensions; ++j)
520 for (n = 0; n < nElements; n++)
522 phys_offset = pFields[0]->GetPhys_Offset(n);
524 pFields[i]->GetExp(n)->PhysDeriv(
525 j, velocity[i] + phys_offset,
526 auxArray = Dvelocity[i][j] + phys_offset);
530 pFields[0]->ExtractTracePhys(Dvelocity[i][j], traceDvelocity[i][j]);
535 &traceDvelocity[0][0][0], 1,
536 &traceFieldsAdded[10][0], 1);
538 &traceDvelocity[0][1][0], 1,
539 &traceFieldsAdded[11][0], 1);
541 &traceDvelocity[1][0][0], 1,
542 &traceFieldsAdded[12][0], 1);
544 &traceDvelocity[1][1][0], 1,
545 &traceFieldsAdded[13][0], 1);
563 if (m_ViscosityType ==
"Variable")
569 for (
int i = 0; i < nSolutionPts; ++i)
571 ratio = temperature[i] / T_star;
572 mu[i] = mu_star * ratio * sqrt(ratio) *
573 (T_star + 110.0) / (temperature[i] + 110.0);
586 Vmath::Smul(nSolutionPts, 2.0, &mu[0], 1, &mu2[0], 1);
590 &Dvelocity[0][0][0], 1, &divVel[0], 1);
592 &Dvelocity[1][1][0], 1, &divVel[0], 1);
595 Vmath::Smul(nSolutionPts, lambda, &divVel[0], 1, &divVel[0], 1);
596 Vmath::Vmul(nSolutionPts, &mu[0], 1, &divVel[0], 1, &divVel[0], 1);
600 for (j = 0; j < m_spacedim; ++j)
605 Vmath::Vmul(nSolutionPts, &mu2[0], 1, &Dvelocity[j][j][0], 1,
608 Vmath::Vadd(nSolutionPts, &temp[j][0], 1, &divVel[0], 1, &Sgg[j][0], 1);
616 &Dvelocity[1][0][0], 1, &Sxy[0], 1);
619 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Sxy[0], 1, &Sxy[0], 1);
621 pFields[0]->ExtractTracePhys(Sgg[0], traceFieldsAdded[14]);
622 pFields[0]->ExtractTracePhys(Sgg[1], traceFieldsAdded[15]);
623 pFields[0]->ExtractTracePhys(Sxy, traceFieldsAdded[16]);
638 Vmath::Vcopy(nTracePts, &m_traceNormals[0][0], 1, &cosTeta[0], 1);
641 Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &sinTeta[0], 1);
644 Vmath::Vsub(nTracePts, &traceFieldsAdded[14][0], 1,
645 &traceFieldsAdded[15][0], 1, &sigma_diff[0], 1);
648 Vmath::Vmul(nTracePts, &cosTeta[0], 1, &sinTeta[0], 1, &tmpTeta[0], 1);
649 Vmath::Smul(nTracePts, 2.0, &tmpTeta[0], 1, &sin2Teta[0], 1);
652 Vmath::Vmul(nTracePts, &cosTeta[0], 1, &cosTeta[0], 1, &cos2Teta[0], 1);
653 Vmath::Vmul(nTracePts, &sinTeta[0], 1, &sinTeta[0], 1, &tmpTeta[0], 1);
654 Vmath::Vsub(nTracePts, &cos2Teta[0], 1, &tmpTeta[0], 1, &cos2Teta[0], 1);
657 Vmath::Smul(nTracePts, -0.5, &sigma_diff[0], 1, &sigma_diff[0], 1);
658 Vmath::Vmul(nTracePts, &sigma_diff[0], 1, &sin2Teta[0], 1, &tau_t[0], 1);
659 Vmath::Vmul(nTracePts, &traceFieldsAdded[16][0], 1, &cos2Teta[0], 1,
661 Vmath::Vadd(nTracePts, &tau_t[0], 1, &tmpTeta[0], 1, &tau_t[0], 1);
663 Vmath::Vcopy(nTracePts, &tau_t[0], 1, &traceFieldsAdded[17][0], 1);
669 pFields[0]->ExtractTracePhys(mu, traceFieldsAdded[18]);
680 Vmath::Smul (nSolutionPts, gamma, soundspeed, 1, soundspeed, 1);
681 Vmath::Vsqrt(nSolutionPts, soundspeed, 1, soundspeed, 1);
686 for (
int i = 0; i < m_spacedim; ++i)
688 Vmath::Vvtvp(nSolutionPts, uFields[i + 1], 1, uFields[i + 1], 1,
692 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
693 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
695 Vmath::Vdiv(nSolutionPts, mach, 1, soundspeed, 1, mach, 1);
697 pFields[0]->ExtractTracePhys(mach, traceFieldsAdded[19]);
702 if (pFields[0]->GetBndCondExpansions().num_elements())
706 nBndRegions = pFields[0]->GetBndCondExpansions().num_elements();
707 for (b = 0; b < nBndRegions; ++b)
709 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
710 for (e = 0; e < nBndEdges; ++e)
712 nBndEdgePts = pFields[0]->
713 GetBndCondExpansions()[b]->GetExp(e)->GetNumPoints(0);
715 id2 = pFields[0]->GetTrace()->
716 GetPhys_Offset(pFields[0]->GetTraceMap()->
717 GetBndCondTraceToGlobalTraceMap(cnt++));
719 if (pFields[0]->GetBndConditions()[b]->
720 GetUserDefined() ==
"WallViscous" ||
721 pFields[0]->GetBndConditions()[b]->
722 GetUserDefined() ==
"WallAdiabatic" ||
723 pFields[0]->GetBndConditions()[b]->
724 GetUserDefined() ==
"Wall")
742 if (pFields[0]->GetBndCondExpansions().num_elements())
744 for (j = 0; j < nfields; ++j)
748 nBndRegions = pFields[j]->GetBndCondExpansions().num_elements();
749 for (b = 0; b < nBndRegions; ++b)
751 nBndEdges = pFields[j]->GetBndCondExpansions()[b]->GetExpSize();
752 for (e = 0; e < nBndEdges; ++e)
754 nBndEdgePts = pFields[j]->
755 GetBndCondExpansions()[b]->GetExp(e)->GetNumPoints(0);
757 id2 = pFields[j]->GetTrace()->
758 GetPhys_Offset(pFields[j]->GetTraceMap()->
759 GetBndCondTraceToGlobalTraceMap(cnt++));
761 if (pFields[j]->GetBndConditions()[b]->
762 GetUserDefined() ==
"WallViscous" ||
763 pFields[j]->GetBndConditions()[b]->
764 GetUserDefined() ==
"WallAdiabatic" ||
765 pFields[j]->GetBndConditions()[b]->
766 GetUserDefined() ==
"Wall")
769 &surfaceFields[j][id1], 1);
779 if (pFields[0]->GetBndCondExpansions().num_elements())
781 for (j = 0; j < nfieldsAdded; ++j)
785 nBndRegions = pFields[0]->GetBndCondExpansions().num_elements();
786 for (b = 0; b < nBndRegions; ++b)
788 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
789 for (e = 0; e < nBndEdges; ++e)
791 nBndEdgePts = pFields[0]->
792 GetBndCondExpansions()[b]->GetExp(e)->GetNumPoints(0);
794 id2 = pFields[0]->GetTrace()->
795 GetPhys_Offset(pFields[0]->GetTraceMap()->
796 GetBndCondTraceToGlobalTraceMap(cnt++));
798 if (pFields[0]->GetBndConditions()[b]->
799 GetUserDefined() ==
"WallViscous" ||
800 pFields[0]->GetBndConditions()[b]->
801 GetUserDefined() ==
"WallAdiabatic" ||
802 pFields[0]->GetBndConditions()[b]->
803 GetUserDefined() ==
"Wall")
806 &surfaceFieldsAdded[j][id1], 1);
817 std::string vEquation = vSession->GetSolverInfo(
"EQType");
820 BndExp = pFields[0]->GetBndCondExpansions();
831 for(
int i = 0; i < BndExp[0]->GetExpSize(); ++i)
854 for(
int j = 0; j < nbc; ++j)
857 nxOnBnd[j] = surfaceFieldsAdded[0][GlobalIndex];
858 nyOnBnd[j] = surfaceFieldsAdded[1][GlobalIndex];
859 txOnBnd[j] = surfaceFieldsAdded[2][GlobalIndex];
860 tyOnBnd[j] = surfaceFieldsAdded[3][GlobalIndex];
862 PressurOnBnd[j] = surfaceFieldsAdded[4][GlobalIndex];
864 if (vEquation ==
"NavierStokesCFE")
866 ShearStressOnBnd[j] = surfaceFieldsAdded[17][GlobalIndex];
883 Vmath::Vmul(nbc,PressurOnBnd,1,nxOnBnd,1, drag_p,1);
884 Vmath::Vmul(nbc,PressurOnBnd,1,nyOnBnd,1, lift_p,1);
889 Fxp += bc->Integral(drag_p);
890 Fyp += bc->Integral(lift_p);
892 if (vEquation ==
"NavierStokesCFE")
894 Vmath::Vmul(nbc,ShearStressOnBnd,1,txOnBnd,1, drag_v,1);
895 Vmath::Vmul(nbc,ShearStressOnBnd,1,tyOnBnd,1, lift_v,1);
900 Fxv += bc->Integral(drag_v);
901 Fyv += bc->Integral(lift_v);
904 Sref += bc->Integral(Unity);
908 cout <<
"\n Sref = " << Sref << endl;
913 cout <<
" Pressure drag (Fxp) = " << Fxp << endl;
914 cout <<
" Pressure lift (Fyp) = " << Fyp << endl;
915 cout <<
" Viscous drag (Fxv) = " << Fxv << endl;
916 cout <<
" Viscous lift (Fyv) = " << Fyv << endl;
917 cout <<
"\n ==> Total drag = " << Fxp+Fxv << endl;
918 cout <<
" ==> Total lift = " << Fyp+Fyv <<
"\n" << endl;
927 outfile.open(fname.c_str());
928 outfile <<
"% x[m] " <<
" \t"
935 <<
"rho[kg/m^3] " <<
" \t"
936 <<
"rhou[kg/(m^2 s)] " <<
" \t"
937 <<
"rhov[kg/(m^2 s)] " <<
" \t"
941 <<
"dT/dn[k/m] " <<
" \t"
942 <<
"dp/dT[Pa/m] " <<
" \t"
943 <<
"dp/dx[Pa/m] " <<
" \t"
944 <<
"dp/dy[Pa/m] " <<
" \t"
945 <<
"du/dx[s^-1] " <<
" \t"
946 <<
"du/dy[s^-1] " <<
" \t"
947 <<
"dv/dx[s^-1] " <<
" \t"
948 <<
"dv/dy[s^-1] " <<
" \t"
949 <<
"tau_xx[Pa] " <<
" \t"
950 <<
"tau_yy[Pa] " <<
" \t"
951 <<
"tau_xy[Pa] " <<
" \t"
952 <<
"tau_t[Pa] " <<
" \t"
953 <<
"mu[Pa s] " <<
" \t"
957 for (i = 0; i < id1; ++i)
959 outfile << scientific
962 << surfaceX[i] <<
" \t "
963 << surfaceY[i] <<
" \t "
964 << surfaceZ[i] <<
" \t "
965 << surfaceFieldsAdded[0][i] <<
" \t "
966 << surfaceFieldsAdded[1][i] <<
" \t "
967 << surfaceFieldsAdded[2][i] <<
" \t "
968 << surfaceFieldsAdded[3][i] <<
" \t "
969 << surfaceFields[0][i] <<
" \t "
970 << surfaceFields[1][i] <<
" \t "
971 << surfaceFields[2][i] <<
" \t "
972 << surfaceFields[3][i] <<
" \t "
973 << surfaceFieldsAdded[4][i] <<
" \t "
974 << surfaceFieldsAdded[5][i] <<
" \t "
975 << surfaceFieldsAdded[6][i] <<
" \t "
976 << surfaceFieldsAdded[7][i] <<
" \t "
977 << surfaceFieldsAdded[8][i] <<
" \t "
978 << surfaceFieldsAdded[9][i] <<
" \t "
979 << surfaceFieldsAdded[10][i] <<
" \t "
980 << surfaceFieldsAdded[11][i] <<
" \t "
981 << surfaceFieldsAdded[12][i] <<
" \t "
982 << surfaceFieldsAdded[13][i] <<
" \t "
983 << surfaceFieldsAdded[14][i] <<
" \t "
984 << surfaceFieldsAdded[15][i] <<
" \t "
985 << surfaceFieldsAdded[16][i] <<
" \t "
986 << surfaceFieldsAdded[17][i] <<
" \t "
987 << surfaceFieldsAdded[18][i] <<
" \t "
988 << surfaceFieldsAdded[19][i] <<
" \t "
992 outfile << endl << endl;
#define ASSERTL0(condition, msg)
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
int GetTotPoints() const
This function returns the total number of quadrature points used in the element.
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...
std::shared_ptr< SessionReader > SessionReaderSharedPtr
@ ePolyEvenlySpaced
1D Evenly-spaced points using Lagrange polynomial
std::shared_ptr< ExpList2D > ExpList2DSharedPtr
Shared pointer to an ExpList2D object.
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
std::shared_ptr< StdExpansion1D > StdExpansion1DSharedPtr
void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
sqrt y = sqrt(x)
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.
void Neg(int n, T *x, const int incx)
Negate x = -x.
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 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 Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*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.
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
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.