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]
70 string fname = std::string(argv[2]);
71 int fdot = fname.find_last_of(
'.');
72 if (fdot != std::string::npos)
74 string ending = fname.substr(fdot);
79 if (ending ==
".chk" || ending ==
".fld")
81 fname = fname.substr(0, fdot);
85 fname = fname +
".txt";
93 int nBndEdgePts, nBndEdges, nBndRegions;
97 fprintf(stderr,
"Usage: ExtractSurface2DCFS meshfile fieldFile\n");
99 "Extracts a surface from a 2D fld file"
100 "(only for CompressibleFlowSolver and purely 2D .fld files)\n");
105 LibUtilities::SessionReader::CreateInstance(3, argv);
107 SpatialDomains::MeshGraph::Read(vSession);
109 std::string m_ViscosityType;
122 int nDimensions = m_spacedim;
126 ASSERTL0(vSession->DefinesParameter(
"Gamma"),
127 "Compressible flow sessions must define a Gamma parameter.");
128 vSession->LoadParameter(
"Gamma", m_gamma, 1.4);
131 ASSERTL0(vSession->DefinesParameter(
"pInf"),
132 "Compressible flow sessions must define a pInf parameter.");
133 vSession->LoadParameter(
"pInf", m_pInf, 101325);
136 ASSERTL0(vSession->DefinesParameter(
"rhoInf"),
137 "Compressible flow sessions must define a rhoInf parameter.");
138 vSession->LoadParameter(
"rhoInf",
m_rhoInf, 1.225);
141 ASSERTL0(vSession->DefinesParameter(
"uInf"),
142 "Compressible flow sessions must define a uInf parameter.");
143 vSession->LoadParameter(
"uInf",
m_uInf, 0.1);
146 if (m_spacedim == 2 || m_spacedim == 3)
148 ASSERTL0(vSession->DefinesParameter(
"vInf"),
149 "Compressible flow sessions must define a vInf parameter"
150 "for 2D/3D problems.");
151 vSession->LoadParameter(
"vInf",
m_vInf, 0.0);
157 ASSERTL0(vSession->DefinesParameter(
"wInf"),
158 "Compressible flow sessions must define a wInf parameter"
160 vSession->LoadParameter(
"wInf", m_wInf, 0.0);
163 vSession->LoadParameter(
"GasConstant", m_gasConstant, 287.058);
164 vSession->LoadParameter(
"Twall",
m_Twall, 300.15);
165 vSession->LoadSolverInfo(
"ViscosityType", m_ViscosityType,
"Constant");
166 vSession->LoadParameter(
"mu",
m_mu, 1.78e-05);
170 string fieldFile(argv[2]);
171 vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
172 vector<vector<NekDouble>> fieldData;
179 vector<vector<LibUtilities::PointsType>> pointsType;
180 for (i = 0; i < fieldDef.size(); ++i)
182 vector<LibUtilities::PointsType> ptype;
183 for (j = 0; j < 2; ++j)
187 pointsType.push_back(ptype);
189 graphShPt->SetExpansionInfo(fieldDef, pointsType);
195 int nfields = fieldDef[0]->m_fields.size();
199 for (i = 0; i < pFields.size(); i++)
203 vSession, graphShPt, vSession->GetVariable(i));
212 for (i = 1; i < nfields; ++i)
218 int nSolutionPts = pFields[0]->GetNpoints();
219 int nTracePts = pFields[0]->GetTrace()->GetTotPoints();
220 int nElements = pFields[0]->GetExpSize();
236 pFields[0]->GetCoords(x, y, z);
238 pFields[0]->ExtractTracePhys(x, traceX);
239 pFields[0]->ExtractTracePhys(y, traceY);
240 pFields[0]->ExtractTracePhys(z, traceZ);
250 for (j = 0; j < nfields; ++j)
256 for (i = 0; i < fieldData.size(); ++i)
258 Exp[j]->ExtractDataToCoeffs(fieldDef[i], fieldData[i],
259 fieldDef[i]->m_fields[j],
260 Exp[j]->UpdateCoeffs());
262 Exp[j]->BwdTrans(Exp[j]->GetCoeffs(), Exp[j]->UpdatePhys());
263 Vmath::Vcopy(nSolutionPts, Exp[j]->GetPhys(), 1, uFields[j], 1);
264 pFields[0]->ExtractTracePhys(uFields[j], traceFields[j]);
269 int nfieldsAdded = 20;
273 for (j = 0; j < nfieldsAdded; ++j)
287 for (i = 0; i < nDimensions; ++i)
291 pFields[0]->GetTrace()->GetNormals(m_traceNormals);
294 for (i = 0; i < nDimensions; ++i)
300 Vmath::Vcopy(nTracePts, &m_traceNormals[0][0], 1, &traceFieldsAdded[0][0],
304 Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &traceFieldsAdded[1][0],
308 Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &m_traceTangents[0][0],
310 Vmath::Neg(nTracePts, &m_traceTangents[0][0], 1);
312 Vmath::Vcopy(nTracePts, &m_traceTangents[0][0], 1, &traceFieldsAdded[2][0],
316 Vmath::Vcopy(nTracePts, &m_traceNormals[0][0], 1, &m_traceTangents[1][0],
319 Vmath::Vcopy(nTracePts, &m_traceTangents[1][0], 1, &traceFieldsAdded[3][0],
330 for (i = 0; i < m_spacedim; i++)
332 Vmath::Vmul(nSolutionPts, &uFields[i + 1][0], 1, &uFields[i + 1][0], 1,
335 Vmath::Smul(nSolutionPts, 0.5, &tmp[0], 1, &tmp[0], 1);
349 pFields[0]->ExtractTracePhys(
pressure, traceFieldsAdded[4]);
361 NekDouble GasConstantInv = 1.0 / m_gasConstant;
362 Vmath::Smul(nSolutionPts, GasConstantInv, &temperature[0], 1,
366 pFields[0]->ExtractTracePhys(temperature, traceFieldsAdded[5]);
375 for (i = 0; i < nDimensions; ++i)
381 for (i = 0; i < nDimensions; ++i)
383 for (n = 0; n < nElements; n++)
385 phys_offset = pFields[0]->GetPhys_Offset(n);
387 pFields[i]->GetExp(n)->PhysDeriv(i, temperature + phys_offset,
389 Dtemperature[i] + phys_offset);
392 pFields[0]->ExtractTracePhys(Dtemperature[i], traceDtemperature[i]);
395 for (i = 0; i < nDimensions; ++i)
398 &traceDtemperature[i][0], 1, &tmp[0], 1);
400 Vmath::Vadd(nTracePts, &traceFieldsAdded[6][0], 1, &tmp[0], 1,
401 &traceFieldsAdded[6][0], 1);
413 for (i = 0; i < nDimensions; ++i)
419 for (i = 0; i < nDimensions; ++i)
421 for (n = 0; n < nElements; n++)
423 phys_offset = pFields[0]->GetPhys_Offset(n);
425 pFields[i]->GetExp(n)->PhysDeriv(i,
pressure + phys_offset,
427 Dpressure[i] + phys_offset);
430 pFields[0]->ExtractTracePhys(Dpressure[i], traceDpressure[i]);
434 for (i = 0; i < nDimensions; ++i)
436 Vmath::Vmul(nTracePts, &m_traceTangents[i][0], 1, &traceDpressure[i][0],
439 Vmath::Vadd(nTracePts, &traceFieldsAdded[7][0], 1, &tmp[0], 1,
440 &traceFieldsAdded[7][0], 1);
444 Vmath::Vcopy(nTracePts, &traceDpressure[0][0], 1, &traceFieldsAdded[8][0],
448 Vmath::Vcopy(nTracePts, &traceDpressure[1][0], 1, &traceFieldsAdded[9][0],
462 for (i = 0; i < nDimensions; ++i)
468 Vmath::Vdiv(nSolutionPts, uFields[i + 1], 1, uFields[0], 1, velocity[i],
471 for (j = 0; j < nDimensions; ++j)
478 for (i = 0; i < nDimensions; ++i)
480 for (j = 0; j < nDimensions; ++j)
482 for (n = 0; n < nElements; n++)
484 phys_offset = pFields[0]->GetPhys_Offset(n);
486 pFields[i]->GetExp(n)->PhysDeriv(j, velocity[i] + phys_offset,
487 auxArray = Dvelocity[i][j] +
492 pFields[0]->ExtractTracePhys(Dvelocity[i][j], traceDvelocity[i][j]);
497 &traceFieldsAdded[10][0], 1);
499 &traceFieldsAdded[11][0], 1);
501 &traceFieldsAdded[12][0], 1);
503 &traceFieldsAdded[13][0], 1);
520 if (m_ViscosityType ==
"Variable")
526 for (
int i = 0; i < nSolutionPts; ++i)
528 ratio = temperature[i] / T_star;
529 mu[i] = mu_star * ratio *
sqrt(ratio) * (T_star + 110.0) /
530 (temperature[i] + 110.0);
543 Vmath::Smul(nSolutionPts, 2.0, &mu[0], 1, &mu2[0], 1);
546 Vmath::Vadd(nSolutionPts, &divVel[0], 1, &Dvelocity[0][0][0], 1, &divVel[0],
548 Vmath::Vadd(nSolutionPts, &divVel[0], 1, &Dvelocity[1][1][0], 1, &divVel[0],
552 Vmath::Smul(nSolutionPts, lambda, &divVel[0], 1, &divVel[0], 1);
553 Vmath::Vmul(nSolutionPts, &mu[0], 1, &divVel[0], 1, &divVel[0], 1);
557 for (j = 0; j < m_spacedim; ++j)
562 Vmath::Vmul(nSolutionPts, &mu2[0], 1, &Dvelocity[j][j][0], 1,
565 Vmath::Vadd(nSolutionPts, &temp[j][0], 1, &divVel[0], 1, &Sgg[j][0], 1);
572 Vmath::Vadd(nSolutionPts, &Dvelocity[0][1][0], 1, &Dvelocity[1][0][0], 1,
576 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Sxy[0], 1, &Sxy[0], 1);
578 pFields[0]->ExtractTracePhys(Sgg[0], traceFieldsAdded[14]);
579 pFields[0]->ExtractTracePhys(Sgg[1], traceFieldsAdded[15]);
580 pFields[0]->ExtractTracePhys(Sxy, traceFieldsAdded[16]);
595 Vmath::Vcopy(nTracePts, &m_traceNormals[0][0], 1, &cosTeta[0], 1);
598 Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &sinTeta[0], 1);
601 Vmath::Vsub(nTracePts, &traceFieldsAdded[14][0], 1,
602 &traceFieldsAdded[15][0], 1, &sigma_diff[0], 1);
605 Vmath::Vmul(nTracePts, &cosTeta[0], 1, &sinTeta[0], 1, &tmpTeta[0], 1);
606 Vmath::Smul(nTracePts, 2.0, &tmpTeta[0], 1, &sin2Teta[0], 1);
609 Vmath::Vmul(nTracePts, &cosTeta[0], 1, &cosTeta[0], 1, &cos2Teta[0], 1);
610 Vmath::Vmul(nTracePts, &sinTeta[0], 1, &sinTeta[0], 1, &tmpTeta[0], 1);
611 Vmath::Vsub(nTracePts, &cos2Teta[0], 1, &tmpTeta[0], 1, &cos2Teta[0], 1);
614 Vmath::Smul(nTracePts, -0.5, &sigma_diff[0], 1, &sigma_diff[0], 1);
615 Vmath::Vmul(nTracePts, &sigma_diff[0], 1, &sin2Teta[0], 1, &tau_t[0], 1);
616 Vmath::Vmul(nTracePts, &traceFieldsAdded[16][0], 1, &cos2Teta[0], 1,
618 Vmath::Vadd(nTracePts, &tau_t[0], 1, &tmpTeta[0], 1, &tau_t[0], 1);
620 Vmath::Vcopy(nTracePts, &tau_t[0], 1, &traceFieldsAdded[17][0], 1);
626 pFields[0]->ExtractTracePhys(mu, traceFieldsAdded[18]);
637 Vmath::Smul(nSolutionPts, gamma, soundspeed, 1, soundspeed, 1);
638 Vmath::Vsqrt(nSolutionPts, soundspeed, 1, soundspeed, 1);
643 for (
int i = 0; i < m_spacedim; ++i)
645 Vmath::Vvtvp(nSolutionPts, uFields[i + 1], 1, uFields[i + 1], 1, mach,
649 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
650 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
652 Vmath::Vdiv(nSolutionPts, mach, 1, soundspeed, 1, mach, 1);
654 pFields[0]->ExtractTracePhys(mach, traceFieldsAdded[19]);
659 if (pFields[0]->GetBndCondExpansions().size())
663 nBndRegions = pFields[0]->GetBndCondExpansions().size();
664 for (b = 0; b < nBndRegions; ++b)
666 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
667 for (e = 0; e < nBndEdges; ++e)
669 nBndEdgePts = pFields[0]
670 ->GetBndCondExpansions()[b]
674 id2 = pFields[0]->GetTrace()->GetPhys_Offset(
675 pFields[0]->GetTraceMap()->GetBndCondIDToGlobalTraceID(
678 if (pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
680 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
682 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
685 Vmath::Vcopy(nBndEdgePts, &traceX[id2], 1, &surfaceX[id1],
688 Vmath::Vcopy(nBndEdgePts, &traceY[id2], 1, &surfaceY[id1],
691 Vmath::Vcopy(nBndEdgePts, &traceZ[id2], 1, &surfaceZ[id1],
701 if (pFields[0]->GetBndCondExpansions().size())
703 for (j = 0; j < nfields; ++j)
707 nBndRegions = pFields[j]->GetBndCondExpansions().size();
708 for (b = 0; b < nBndRegions; ++b)
710 nBndEdges = pFields[j]->GetBndCondExpansions()[b]->GetExpSize();
711 for (e = 0; e < nBndEdges; ++e)
713 nBndEdgePts = pFields[j]
714 ->GetBndCondExpansions()[b]
718 id2 = pFields[j]->GetTrace()->GetPhys_Offset(
719 pFields[j]->GetTraceMap()->GetBndCondIDToGlobalTraceID(
722 if (pFields[j]->GetBndConditions()[b]->GetUserDefined() ==
724 pFields[j]->GetBndConditions()[b]->GetUserDefined() ==
726 pFields[j]->GetBndConditions()[b]->GetUserDefined() ==
730 &surfaceFields[j][id1], 1);
740 if (pFields[0]->GetBndCondExpansions().size())
742 for (j = 0; j < nfieldsAdded; ++j)
746 nBndRegions = pFields[0]->GetBndCondExpansions().size();
747 for (b = 0; b < nBndRegions; ++b)
749 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
750 for (e = 0; e < nBndEdges; ++e)
752 nBndEdgePts = pFields[0]
753 ->GetBndCondExpansions()[b]
757 id2 = pFields[0]->GetTrace()->GetPhys_Offset(
758 pFields[0]->GetTraceMap()->GetBndCondIDToGlobalTraceID(
761 if (pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
763 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
765 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
769 &surfaceFieldsAdded[j][id1], 1);
780 std::string vEquation = vSession->GetSolverInfo(
"EQType");
783 BndExp = pFields[0]->GetBndCondExpansions();
794 for (
int i = 0; i < BndExp[0]->GetExpSize(); ++i)
817 for (
int j = 0; j < nbc; ++j)
820 nxOnBnd[j] = surfaceFieldsAdded[0][GlobalIndex];
821 nyOnBnd[j] = surfaceFieldsAdded[1][GlobalIndex];
822 txOnBnd[j] = surfaceFieldsAdded[2][GlobalIndex];
823 tyOnBnd[j] = surfaceFieldsAdded[3][GlobalIndex];
825 PressurOnBnd[j] = surfaceFieldsAdded[4][GlobalIndex];
827 if (vEquation ==
"NavierStokesCFE")
829 ShearStressOnBnd[j] = surfaceFieldsAdded[17][GlobalIndex];
849 Vmath::Vmul(nbc, PressurOnBnd, 1, nxOnBnd, 1, drag_p, 1);
850 Vmath::Vmul(nbc, PressurOnBnd, 1, nyOnBnd, 1, lift_p, 1);
855 Fxp += bc->Integral(drag_p);
856 Fyp += bc->Integral(lift_p);
858 if (vEquation ==
"NavierStokesCFE")
860 Vmath::Vmul(nbc, ShearStressOnBnd, 1, txOnBnd, 1, drag_v, 1);
861 Vmath::Vmul(nbc, ShearStressOnBnd, 1, tyOnBnd, 1, lift_v, 1);
866 Fxv += bc->Integral(drag_v);
867 Fyv += bc->Integral(lift_v);
870 Sref += bc->Integral(Unity);
873 cout <<
"\n Sref = " << Sref << endl;
878 cout <<
" Pressure drag (Fxp) = " << Fxp << endl;
879 cout <<
" Pressure lift (Fyp) = " << Fyp << endl;
880 cout <<
" Viscous drag (Fxv) = " << Fxv << endl;
881 cout <<
" Viscous lift (Fyv) = " << Fyv << endl;
882 cout <<
"\n ==> Total drag = " << Fxp + Fxv << endl;
883 cout <<
" ==> Total lift = " << Fyp + Fyv <<
"\n" << endl;
891 outfile.open(fname.c_str());
908 <<
"rhou[kg/(m^2 s)] "
910 <<
"rhov[kg/(m^2 s)] "
948 for (i = 0; i < id1; ++i)
950 outfile << scientific << setw(17) << setprecision(16) << surfaceX[i]
951 <<
" \t " << surfaceY[i] <<
" \t " << surfaceZ[i] <<
" \t "
952 << surfaceFieldsAdded[0][i] <<
" \t "
953 << surfaceFieldsAdded[1][i] <<
" \t "
954 << surfaceFieldsAdded[2][i] <<
" \t "
955 << surfaceFieldsAdded[3][i] <<
" \t " << surfaceFields[0][i]
956 <<
" \t " << surfaceFields[1][i] <<
" \t "
957 << surfaceFields[2][i] <<
" \t " << surfaceFields[3][i]
958 <<
" \t " << surfaceFieldsAdded[4][i] <<
" \t "
959 << surfaceFieldsAdded[5][i] <<
" \t "
960 << surfaceFieldsAdded[6][i] <<
" \t "
961 << surfaceFieldsAdded[7][i] <<
" \t "
962 << surfaceFieldsAdded[8][i] <<
" \t "
963 << surfaceFieldsAdded[9][i] <<
" \t "
964 << surfaceFieldsAdded[10][i] <<
" \t "
965 << surfaceFieldsAdded[11][i] <<
" \t "
966 << surfaceFieldsAdded[12][i] <<
" \t "
967 << surfaceFieldsAdded[13][i] <<
" \t "
968 << surfaceFieldsAdded[14][i] <<
" \t "
969 << surfaceFieldsAdded[15][i] <<
" \t "
970 << surfaceFieldsAdded[16][i] <<
" \t "
971 << surfaceFieldsAdded[17][i] <<
" \t "
972 << surfaceFieldsAdded[18][i] <<
" \t "
973 << surfaceFieldsAdded[19][i]
978 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< ExpList > ExpListSharedPtr
Shared pointer to an ExpList 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*x.
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.
scalarT< T > sqrt(scalarT< T > in)