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]
74 string fname = std::string(argv[2]);
75 int fdot = fname.find_last_of(
'.');
76 if (fdot != std::string::npos)
78 string ending = fname.substr(fdot);
83 if (ending ==
".chk" || ending ==
".fld")
85 fname = fname.substr(0,fdot);
89 fname = fname +
".txt";
97 int nBndEdgePts, nBndEdges, nBndRegions;
102 "Usage: ExtractSurface2DCFS meshfile fieldFile\n");
104 "Extracts a surface from a 2D fld file"
105 "(only for CompressibleFlowSolver and purely 2D .fld files)\n");
110 = LibUtilities::SessionReader::CreateInstance(3, argv);
112 std::string m_ViscosityType;
126 int nDimensions = m_spacedim;
130 ASSERTL0(vSession->DefinesParameter(
"Gamma"),
131 "Compressible flow sessions must define a Gamma parameter.");
132 vSession->LoadParameter(
"Gamma", m_gamma, 1.4);
135 ASSERTL0(vSession->DefinesParameter(
"pInf"),
136 "Compressible flow sessions must define a pInf parameter.");
137 vSession->LoadParameter(
"pInf", m_pInf, 101325);
140 ASSERTL0(vSession->DefinesParameter(
"rhoInf"),
141 "Compressible flow sessions must define a rhoInf parameter.");
142 vSession->LoadParameter(
"rhoInf", m_rhoInf, 1.225);
145 ASSERTL0(vSession->DefinesParameter(
"uInf"),
146 "Compressible flow sessions must define a uInf parameter.");
147 vSession->LoadParameter(
"uInf", m_uInf, 0.1);
150 if (m_spacedim == 2 || m_spacedim == 3)
152 ASSERTL0(vSession->DefinesParameter(
"vInf"),
153 "Compressible flow sessions must define a vInf parameter"
154 "for 2D/3D problems.");
155 vSession->LoadParameter(
"vInf", m_vInf, 0.0);
161 ASSERTL0(vSession->DefinesParameter(
"wInf"),
162 "Compressible flow sessions must define a wInf parameter"
164 vSession->LoadParameter(
"wInf", m_wInf, 0.0);
167 vSession->LoadParameter (
"GasConstant", m_gasConstant, 287.058);
168 vSession->LoadParameter (
"Twall", m_Twall, 300.15);
169 vSession->LoadSolverInfo(
"ViscosityType", m_ViscosityType,
"Constant");
170 vSession->LoadParameter (
"mu", m_mu, 1.78e-05);
171 vSession->LoadParameter (
"thermalConductivity",
172 m_thermalConductivity, 0.0257);
176 string meshfile(argv[1]);
178 SpatialDomains::MeshGraph::Read(vSession);
183 string fieldFile(argv[2]);
184 vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
185 vector<vector<NekDouble> > fieldData;
192 vector< vector<LibUtilities::PointsType> > pointsType;
193 for (i = 0; i < fieldDef.size(); ++i)
195 vector<LibUtilities::PointsType> ptype;
196 for (j = 0; j < 2; ++j)
200 pointsType.push_back(ptype);
202 graphShPt->SetExpansions(fieldDef, pointsType);
209 int nfields = fieldDef[0]->m_fields.size();
213 for(i = 0; i < pFields.num_elements(); i++)
217 vSession, graphShPt, vSession->GetVariable(i));
226 for (i = 1; i < nfields; ++i)
232 int nSolutionPts = pFields[0]->GetNpoints();
233 int nTracePts = pFields[0]->GetTrace()->GetTotPoints();
234 int nElements = pFields[0]->GetExpSize();
250 pFields[0]->GetCoords(x, y, z);
252 pFields[0]->ExtractTracePhys(x, traceX);
253 pFields[0]->ExtractTracePhys(y, traceY);
254 pFields[0]->ExtractTracePhys(z, traceZ);
264 for (j = 0; j < nfields; ++j)
271 for (i = 0; i < fieldData.size(); ++i)
273 Exp[j]->ExtractDataToCoeffs(fieldDef[i], fieldData[i],
274 fieldDef[i]->m_fields[j],
275 Exp[j]->UpdateCoeffs());
277 Exp[j]->BwdTrans(Exp[j]->GetCoeffs(), Exp[j]->UpdatePhys());
278 Vmath::Vcopy(nSolutionPts, Exp[j]->GetPhys(), 1, uFields[j], 1);
279 pFields[0]->ExtractTracePhys(uFields[j], traceFields[j]);
284 int nfieldsAdded = 20;
288 for (j = 0; j < nfieldsAdded; ++j)
302 for(i = 0; i < nDimensions; ++i)
306 pFields[0]->GetTrace()->GetNormals(m_traceNormals);
309 for(i = 0; i < nDimensions; ++i)
317 &m_traceNormals[0][0], 1,
318 &traceFieldsAdded[0][0], 1);
322 &m_traceNormals[1][0], 1,
323 &traceFieldsAdded[1][0], 1);
327 &m_traceNormals[1][0], 1,
328 &m_traceTangents[0][0], 1);
329 Vmath::Neg(nTracePts, &m_traceTangents[0][0], 1);
332 &m_traceTangents[0][0], 1,
333 &traceFieldsAdded[2][0], 1);
337 &m_traceNormals[0][0], 1,
338 &m_traceTangents[1][0], 1);
341 &m_traceTangents[1][0], 1,
342 &traceFieldsAdded[3][0], 1);
352 for (i = 0; i < m_spacedim; i++)
355 &uFields[i + 1][0], 1,
356 &uFields[i + 1][0], 1,
376 &uFields[nfields - 1][0], 1,
385 pFields[0]->ExtractTracePhys(pressure, traceFieldsAdded[4]);
399 NekDouble GasConstantInv = 1.0/m_gasConstant;
405 pFields[0]->ExtractTracePhys(temperature, traceFieldsAdded[5]);
414 for (i = 0; i < nDimensions; ++ i)
420 for (i = 0; i < nDimensions; ++ i)
422 for (n = 0; n < nElements; n++)
424 phys_offset = pFields[0]->GetPhys_Offset(n);
426 pFields[i]->GetExp(n)->PhysDeriv(
427 i, temperature + phys_offset,
428 auxArray = Dtemperature[i] + phys_offset);
431 pFields[0]->ExtractTracePhys(Dtemperature[i], traceDtemperature[i]);
434 for(i = 0; i < nDimensions; ++i)
437 &m_traceNormals[i][0], 1,
438 &traceDtemperature[i][0], 1,
442 &traceFieldsAdded[6][0], 1,
444 &traceFieldsAdded[6][0], 1);
456 for (i = 0; i < nDimensions; ++ i)
462 for (i = 0; i < nDimensions; ++ i)
464 for (n = 0; n < nElements; n++)
466 phys_offset = pFields[0]->GetPhys_Offset(n);
468 pFields[i]->GetExp(n)->PhysDeriv(
469 i, pressure + phys_offset,
470 auxArray = Dpressure[i] + phys_offset);
473 pFields[0]->ExtractTracePhys(Dpressure[i], traceDpressure[i]);
477 for(i = 0; i < nDimensions; ++i)
480 &m_traceTangents[i][0], 1,
481 &traceDpressure[i][0], 1,
485 &traceFieldsAdded[7][0], 1,
487 &traceFieldsAdded[7][0], 1);
492 &traceDpressure[0][0], 1,
493 &traceFieldsAdded[8][0], 1);
497 &traceDpressure[1][0], 1,
498 &traceFieldsAdded[9][0], 1);
510 for (i = 0; i < nDimensions; ++ i)
516 Vmath::Vdiv(nSolutionPts, uFields[i+1], 1, uFields[0], 1,
519 for (j = 0; j < nDimensions; ++j)
526 for (i = 0; i < nDimensions; ++i)
528 for (j = 0; j < nDimensions; ++j)
530 for (n = 0; n < nElements; n++)
532 phys_offset = pFields[0]->GetPhys_Offset(n);
534 pFields[i]->GetExp(n)->PhysDeriv(
535 j, velocity[i] + phys_offset,
536 auxArray = Dvelocity[i][j] + phys_offset);
540 pFields[0]->ExtractTracePhys(Dvelocity[i][j], traceDvelocity[i][j]);
545 &traceDvelocity[0][0][0], 1,
546 &traceFieldsAdded[10][0], 1);
548 &traceDvelocity[0][1][0], 1,
549 &traceFieldsAdded[11][0], 1);
551 &traceDvelocity[1][0][0], 1,
552 &traceFieldsAdded[12][0], 1);
554 &traceDvelocity[1][1][0], 1,
555 &traceFieldsAdded[13][0], 1);
573 if (m_ViscosityType ==
"Variable")
576 NekDouble T_star = m_pInf / (m_rhoInf * m_gasConstant);
579 for (
int i = 0; i < nSolutionPts; ++i)
581 ratio = temperature[i] / T_star;
582 mu[i] = mu_star * ratio * sqrt(ratio) *
583 (T_star + 110.0) / (temperature[i] + 110.0);
596 Vmath::Smul(nSolutionPts, 2.0, &mu[0], 1, &mu2[0], 1);
600 &Dvelocity[0][0][0], 1, &divVel[0], 1);
602 &Dvelocity[1][1][0], 1, &divVel[0], 1);
605 Vmath::Smul(nSolutionPts, lambda, &divVel[0], 1, &divVel[0], 1);
606 Vmath::Vmul(nSolutionPts, &mu[0], 1, &divVel[0], 1, &divVel[0], 1);
610 for (j = 0; j < m_spacedim; ++j)
615 Vmath::Vmul(nSolutionPts, &mu2[0], 1, &Dvelocity[j][j][0], 1,
618 Vmath::Vadd(nSolutionPts, &temp[j][0], 1, &divVel[0], 1, &Sgg[j][0], 1);
626 &Dvelocity[1][0][0], 1, &Sxy[0], 1);
629 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Sxy[0], 1, &Sxy[0], 1);
631 pFields[0]->ExtractTracePhys(Sgg[0], traceFieldsAdded[14]);
632 pFields[0]->ExtractTracePhys(Sgg[1], traceFieldsAdded[15]);
633 pFields[0]->ExtractTracePhys(Sxy, traceFieldsAdded[16]);
648 Vmath::Vcopy(nTracePts, &m_traceNormals[0][0], 1, &cosTeta[0], 1);
651 Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &sinTeta[0], 1);
654 Vmath::Vsub(nTracePts, &traceFieldsAdded[14][0], 1,
655 &traceFieldsAdded[15][0], 1, &sigma_diff[0], 1);
658 Vmath::Vmul(nTracePts, &cosTeta[0], 1, &sinTeta[0], 1, &tmpTeta[0], 1);
659 Vmath::Smul(nTracePts, 2.0, &tmpTeta[0], 1, &sin2Teta[0], 1);
662 Vmath::Vmul(nTracePts, &cosTeta[0], 1, &cosTeta[0], 1, &cos2Teta[0], 1);
663 Vmath::Vmul(nTracePts, &sinTeta[0], 1, &sinTeta[0], 1, &tmpTeta[0], 1);
664 Vmath::Vsub(nTracePts, &cos2Teta[0], 1, &tmpTeta[0], 1, &cos2Teta[0], 1);
667 Vmath::Smul(nTracePts, -0.5, &sigma_diff[0], 1, &sigma_diff[0], 1);
668 Vmath::Vmul(nTracePts, &sigma_diff[0], 1, &sin2Teta[0], 1, &tau_t[0], 1);
669 Vmath::Vmul(nTracePts, &traceFieldsAdded[16][0], 1, &cos2Teta[0], 1,
671 Vmath::Vadd(nTracePts, &tau_t[0], 1, &tmpTeta[0], 1, &tau_t[0], 1);
673 Vmath::Vcopy(nTracePts, &tau_t[0], 1, &traceFieldsAdded[17][0], 1);
679 pFields[0]->ExtractTracePhys(mu, traceFieldsAdded[18]);
689 Vmath::Vdiv (nSolutionPts, pressure, 1, uFields[0], 1, soundspeed, 1);
690 Vmath::Smul (nSolutionPts, gamma, soundspeed, 1, soundspeed, 1);
691 Vmath::Vsqrt(nSolutionPts, soundspeed, 1, soundspeed, 1);
696 for (
int i = 0; i < m_spacedim; ++i)
698 Vmath::Vvtvp(nSolutionPts, uFields[i + 1], 1, uFields[i + 1], 1,
702 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
703 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
705 Vmath::Vdiv(nSolutionPts, mach, 1, soundspeed, 1, mach, 1);
707 pFields[0]->ExtractTracePhys(mach, traceFieldsAdded[19]);
712 if (pFields[0]->GetBndCondExpansions().num_elements())
716 nBndRegions = pFields[0]->GetBndCondExpansions().num_elements();
717 for (b = 0; b < nBndRegions; ++b)
719 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
720 for (e = 0; e < nBndEdges; ++e)
722 nBndEdgePts = pFields[0]->
723 GetBndCondExpansions()[b]->GetExp(e)->GetNumPoints(0);
725 id2 = pFields[0]->GetTrace()->
726 GetPhys_Offset(pFields[0]->GetTraceMap()->
727 GetBndCondTraceToGlobalTraceMap(cnt++));
729 if (pFields[0]->GetBndConditions()[b]->
730 GetUserDefined() ==
"WallViscous" ||
731 pFields[0]->GetBndConditions()[b]->
732 GetUserDefined() ==
"WallAdiabatic" ||
733 pFields[0]->GetBndConditions()[b]->
734 GetUserDefined() ==
"Wall")
752 if (pFields[0]->GetBndCondExpansions().num_elements())
754 for (j = 0; j < nfields; ++j)
758 nBndRegions = pFields[j]->GetBndCondExpansions().num_elements();
759 for (b = 0; b < nBndRegions; ++b)
761 nBndEdges = pFields[j]->GetBndCondExpansions()[b]->GetExpSize();
762 for (e = 0; e < nBndEdges; ++e)
764 nBndEdgePts = pFields[j]->
765 GetBndCondExpansions()[b]->GetExp(e)->GetNumPoints(0);
767 id2 = pFields[j]->GetTrace()->
768 GetPhys_Offset(pFields[j]->GetTraceMap()->
769 GetBndCondTraceToGlobalTraceMap(cnt++));
771 if (pFields[j]->GetBndConditions()[b]->
772 GetUserDefined() ==
"WallViscous" ||
773 pFields[j]->GetBndConditions()[b]->
774 GetUserDefined() ==
"WallAdiabatic" ||
775 pFields[j]->GetBndConditions()[b]->
776 GetUserDefined() ==
"Wall")
779 &surfaceFields[j][id1], 1);
789 if (pFields[0]->GetBndCondExpansions().num_elements())
791 for (j = 0; j < nfieldsAdded; ++j)
795 nBndRegions = pFields[0]->GetBndCondExpansions().num_elements();
796 for (b = 0; b < nBndRegions; ++b)
798 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
799 for (e = 0; e < nBndEdges; ++e)
801 nBndEdgePts = pFields[0]->
802 GetBndCondExpansions()[b]->GetExp(e)->GetNumPoints(0);
804 id2 = pFields[0]->GetTrace()->
805 GetPhys_Offset(pFields[0]->GetTraceMap()->
806 GetBndCondTraceToGlobalTraceMap(cnt++));
808 if (pFields[0]->GetBndConditions()[b]->
809 GetUserDefined() ==
"WallViscous" ||
810 pFields[0]->GetBndConditions()[b]->
811 GetUserDefined() ==
"WallAdiabatic" ||
812 pFields[0]->GetBndConditions()[b]->
813 GetUserDefined() ==
"Wall")
816 &surfaceFieldsAdded[j][id1], 1);
827 std::string vEquation = vSession->GetSolverInfo(
"EQType");
830 BndExp = pFields[0]->GetBndCondExpansions();
841 for(
int i = 0; i < BndExp[0]->GetExpSize(); ++i)
864 for(
int j = 0; j < nbc; ++j)
867 nxOnBnd[j] = surfaceFieldsAdded[0][GlobalIndex];
868 nyOnBnd[j] = surfaceFieldsAdded[1][GlobalIndex];
869 txOnBnd[j] = surfaceFieldsAdded[2][GlobalIndex];
870 tyOnBnd[j] = surfaceFieldsAdded[3][GlobalIndex];
872 PressurOnBnd[j] = surfaceFieldsAdded[4][GlobalIndex];
874 if (vEquation ==
"NavierStokesCFE")
876 ShearStressOnBnd[j] = surfaceFieldsAdded[17][GlobalIndex];
893 Vmath::Vmul(nbc,PressurOnBnd,1,nxOnBnd,1, drag_p,1);
894 Vmath::Vmul(nbc,PressurOnBnd,1,nyOnBnd,1, lift_p,1);
899 Fxp += bc->Integral(drag_p);
900 Fyp += bc->Integral(lift_p);
902 if (vEquation ==
"NavierStokesCFE")
904 Vmath::Vmul(nbc,ShearStressOnBnd,1,txOnBnd,1, drag_v,1);
905 Vmath::Vmul(nbc,ShearStressOnBnd,1,tyOnBnd,1, lift_v,1);
910 Fxv += bc->Integral(drag_v);
911 Fyv += bc->Integral(lift_v);
914 Sref += bc->Integral(Unity);
918 cout <<
"\n Sref = " << Sref << endl;
923 cout <<
" Pressure drag (Fxp) = " << Fxp << endl;
924 cout <<
" Pressure lift (Fyp) = " << Fyp << endl;
925 cout <<
" Viscous drag (Fxv) = " << Fxv << endl;
926 cout <<
" Viscous lift (Fyv) = " << Fyv << endl;
927 cout <<
"\n ==> Total drag = " << Fxp+Fxv << endl;
928 cout <<
" ==> Total lift = " << Fyp+Fyv <<
"\n" << endl;
937 outfile.open(fname.c_str());
938 outfile <<
"% x[m] " <<
" \t"
945 <<
"rho[kg/m^3] " <<
" \t"
946 <<
"rhou[kg/(m^2 s)] " <<
" \t"
947 <<
"rhov[kg/(m^2 s)] " <<
" \t"
951 <<
"dT/dn[k/m] " <<
" \t"
952 <<
"dp/dT[Pa/m] " <<
" \t"
953 <<
"dp/dx[Pa/m] " <<
" \t"
954 <<
"dp/dy[Pa/m] " <<
" \t"
955 <<
"du/dx[s^-1] " <<
" \t"
956 <<
"du/dy[s^-1] " <<
" \t"
957 <<
"dv/dx[s^-1] " <<
" \t"
958 <<
"dv/dy[s^-1] " <<
" \t"
959 <<
"tau_xx[Pa] " <<
" \t"
960 <<
"tau_yy[Pa] " <<
" \t"
961 <<
"tau_xy[Pa] " <<
" \t"
962 <<
"tau_t[Pa] " <<
" \t"
963 <<
"mu[Pa s] " <<
" \t"
967 for (i = 0; i < id1; ++i)
969 outfile << scientific
972 << surfaceX[i] <<
" \t "
973 << surfaceY[i] <<
" \t "
974 << surfaceZ[i] <<
" \t "
975 << surfaceFieldsAdded[0][i] <<
" \t "
976 << surfaceFieldsAdded[1][i] <<
" \t "
977 << surfaceFieldsAdded[2][i] <<
" \t "
978 << surfaceFieldsAdded[3][i] <<
" \t "
979 << surfaceFields[0][i] <<
" \t "
980 << surfaceFields[1][i] <<
" \t "
981 << surfaceFields[2][i] <<
" \t "
982 << surfaceFields[3][i] <<
" \t "
983 << surfaceFieldsAdded[4][i] <<
" \t "
984 << surfaceFieldsAdded[5][i] <<
" \t "
985 << surfaceFieldsAdded[6][i] <<
" \t "
986 << surfaceFieldsAdded[7][i] <<
" \t "
987 << surfaceFieldsAdded[8][i] <<
" \t "
988 << surfaceFieldsAdded[9][i] <<
" \t "
989 << surfaceFieldsAdded[10][i] <<
" \t "
990 << surfaceFieldsAdded[11][i] <<
" \t "
991 << surfaceFieldsAdded[12][i] <<
" \t "
992 << surfaceFieldsAdded[13][i] <<
" \t "
993 << surfaceFieldsAdded[14][i] <<
" \t "
994 << surfaceFieldsAdded[15][i] <<
" \t "
995 << surfaceFieldsAdded[16][i] <<
" \t "
996 << surfaceFieldsAdded[17][i] <<
" \t "
997 << surfaceFieldsAdded[18][i] <<
" \t "
998 << surfaceFieldsAdded[19][i] <<
" \t "
1002 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)
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
void Import(const std::string &infilename, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, FieldMetaDataMap &fieldinfomap, const Array< OneD, int > ElementiDs)
Imports an FLD file.
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.