65 int main(
int argc,
char *argv[])
67 string fname = std::string(argv[2]);
68 int fdot = fname.find_last_of(
'.');
69 if (fdot != std::string::npos)
71 string ending = fname.substr(fdot);
76 if (ending ==
".chk" || ending ==
".fld")
78 fname = fname.substr(0, fdot);
82 fname = fname +
".txt";
89 int nBndEdgePts, nBndEdges, nBndRegions;
93 fprintf(stderr,
"Usage: ExtractSurface3DCFS meshfile fieldFile\n");
95 "Extracts a surface from a 3D fld file"
96 "(only for CompressibleFlowSolver and purely 3D .fld files)\n");
101 LibUtilities::SessionReader::CreateInstance(3, argv);
103 SpatialDomains::MeshGraph::Read(vSession);
105 std::string m_ViscosityType;
118 int nDimensions = m_spacedim;
122 ASSERTL0(vSession->DefinesParameter(
"Gamma"),
123 "Compressible flow sessions must define a Gamma parameter.");
124 vSession->LoadParameter(
"Gamma", m_gamma, 1.4);
127 ASSERTL0(vSession->DefinesParameter(
"pInf"),
128 "Compressible flow sessions must define a pInf parameter.");
129 vSession->LoadParameter(
"pInf", m_pInf, 101325);
132 ASSERTL0(vSession->DefinesParameter(
"rhoInf"),
133 "Compressible flow sessions must define a rhoInf parameter.");
134 vSession->LoadParameter(
"rhoInf",
m_rhoInf, 1.225);
137 ASSERTL0(vSession->DefinesParameter(
"uInf"),
138 "Compressible flow sessions must define a uInf parameter.");
139 vSession->LoadParameter(
"uInf",
m_uInf, 0.1);
142 if (m_spacedim == 2 || m_spacedim == 3)
144 ASSERTL0(vSession->DefinesParameter(
"vInf"),
145 "Compressible flow sessions must define a vInf parameter"
146 "for 2D/3D problems.");
147 vSession->LoadParameter(
"vInf",
m_vInf, 0.0);
153 ASSERTL0(vSession->DefinesParameter(
"wInf"),
154 "Compressible flow sessions must define a wInf parameter"
156 vSession->LoadParameter(
"wInf", m_wInf, 0.0);
159 vSession->LoadParameter(
"GasConstant", m_gasConstant, 287.058);
160 vSession->LoadParameter(
"Twall",
m_Twall, 300.15);
161 vSession->LoadSolverInfo(
"ViscosityType", m_ViscosityType,
"Constant");
162 vSession->LoadParameter(
"mu",
m_mu, 1.78e-05);
166 string fieldFile(argv[2]);
167 vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
168 vector<vector<NekDouble>> fieldData;
175 vector<vector<LibUtilities::PointsType>> pointsType;
176 for (i = 0; i < fieldDef.size(); ++i)
178 vector<LibUtilities::PointsType> ptype;
179 for (j = 0; j < 3; ++j)
183 pointsType.push_back(ptype);
185 graphShPt->SetExpansionInfo(fieldDef, pointsType);
191 int nfields = fieldDef[0]->m_fields.size();
195 for (i = 0; i < pFields.size(); i++)
199 vSession, graphShPt, vSession->GetVariable(i));
208 for (i = 1; i < nfields; ++i)
216 if (pFields[0]->GetBndCondExpansions().size())
220 nBndRegions = pFields[0]->GetBndCondExpansions().size();
221 for (b = 0; b < nBndRegions; ++b)
223 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
224 for (e = 0; e < nBndEdges; ++e)
226 nBndEdgePts = pFields[0]
227 ->GetBndCondExpansions()[b]
231 if (pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
233 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
235 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
238 nSurfacePts += nBndEdgePts;
244 int nSolutionPts = pFields[0]->GetNpoints();
245 int nTracePts = pFields[0]->GetTrace()->GetTotPoints();
246 int nElements = pFields[0]->GetExpSize();
262 pFields[0]->GetCoords(x, y, z);
264 pFields[0]->ExtractTracePhys(x, traceX);
265 pFields[0]->ExtractTracePhys(y, traceY);
266 pFields[0]->ExtractTracePhys(z, traceZ);
276 for (j = 0; j < nfields; ++j)
282 for (i = 0; i < fieldData.size(); ++i)
284 Exp[j]->ExtractDataToCoeffs(fieldDef[i], fieldData[i],
285 fieldDef[i]->m_fields[j],
286 Exp[j]->UpdateCoeffs());
288 Exp[j]->BwdTrans(Exp[j]->GetCoeffs(), Exp[j]->UpdatePhys());
289 Vmath::Vcopy(nSolutionPts, Exp[j]->GetPhys(), 1, uFields[j], 1);
290 pFields[0]->ExtractTracePhys(uFields[j], traceFields[j]);
294 int nfieldsAdded = 34;
298 for (j = 0; j < nfieldsAdded; ++j)
318 for (i = 0; i < nDimensions; ++i)
322 pFields[0]->GetTrace()->GetNormals(m_traceNormals);
331 for (i = 0; i < nDimensions; ++i)
341 Vmath::Vcopy(nTracePts, &m_traceNormals[0][0], 1, &traceFieldsAdded[0][0],
345 Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &traceFieldsAdded[1][0],
349 Vmath::Vcopy(nTracePts, &m_traceNormals[2][0], 1, &traceFieldsAdded[2][0],
354 Vmath::Vadd(nTracePts, &m_traceNormals[0][0], 1, &tmpNorm[0], 1, &h[0][0],
357 Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &h[1][0], 1);
359 Vmath::Vcopy(nTracePts, &m_traceNormals[2][0], 1, &h[2][0], 1);
362 for (i = 0; i < m_spacedim; i++)
364 Vmath::Vvtvp(nTracePts, &h[i][0], 1, &h[i][0], 1, &NormH[0], 1,
369 Vmath::Vmul(nTracePts, &h[0][0], 1, &h[1][0], 1, &tmpTrace[0], 1);
371 Vmath::Vdiv(nTracePts, &tmpTrace[0], 1, &NormH[0], 1, &tmpTrace[0], 1);
373 Vmath::Smul(nTracePts, -2.0, &tmpTrace[0], 1, &m_traceBinormals[0][0], 1);
375 Vmath::Vcopy(nTracePts, &m_traceBinormals[0][0], 1, &traceFieldsAdded[3][0],
379 Vmath::Vmul(nTracePts, &h[1][0], 1, &h[1][0], 1, &tmpTrace[0], 1);
381 Vmath::Vdiv(nTracePts, &tmpTrace[0], 1, &NormH[0], 1, &tmpTrace[0], 1);
383 Vmath::Smul(nTracePts, -2.0, &tmpTrace[0], 1, &tmpTrace[0], 1);
385 Vmath::Vadd(nTracePts, &tmpTrace[0], 1, &tmpNorm[0], 1,
386 &m_traceBinormals[1][0], 1);
388 Vmath::Vcopy(nTracePts, &m_traceBinormals[1][0], 1, &traceFieldsAdded[4][0],
392 Vmath::Vmul(nTracePts, &h[1][0], 1, &h[2][0], 1, &tmpTrace[0], 1);
394 Vmath::Vdiv(nTracePts, &tmpTrace[0], 1, &NormH[0], 1, &tmpTrace[0], 1);
396 Vmath::Smul(nTracePts, -2.0, &tmpTrace[0], 1, &m_traceBinormals[2][0], 1);
398 Vmath::Vcopy(nTracePts, &m_traceBinormals[2][0], 1, &traceFieldsAdded[5][0],
402 Vmath::Vmul(nTracePts, &h[0][0], 1, &h[2][0], 1, &tmpTrace[0], 1);
404 Vmath::Vdiv(nTracePts, &tmpTrace[0], 1, &NormH[0], 1, &tmpTrace[0], 1);
406 Vmath::Smul(nTracePts, -2.0, &tmpTrace[0], 1, &m_traceTangents[0][0], 1);
408 Vmath::Vcopy(nTracePts, &m_traceTangents[0][0], 1, &traceFieldsAdded[6][0],
412 Vmath::Vcopy(nTracePts, &m_traceBinormals[2][0], 1, &m_traceTangents[1][0],
415 Vmath::Vcopy(nTracePts, &m_traceTangents[1][0], 1, &traceFieldsAdded[7][0],
419 Vmath::Vmul(nTracePts, &h[2][0], 1, &h[2][0], 1, &tmpTrace[0], 1);
421 Vmath::Vdiv(nTracePts, &tmpTrace[0], 1, &NormH[0], 1, &tmpTrace[0], 1);
423 Vmath::Smul(nTracePts, -2.0, &tmpTrace[0], 1, &tmpTrace[0], 1);
425 Vmath::Vadd(nTracePts, &tmpTrace[0], 1, &tmpNorm[0], 1,
426 &m_traceTangents[2][0], 1);
428 Vmath::Vcopy(nTracePts, &m_traceTangents[2][0], 1, &traceFieldsAdded[8][0],
439 for (i = 0; i < m_spacedim; i++)
441 Vmath::Vmul(nSolutionPts, &uFields[i + 1][0], 1, &uFields[i + 1][0], 1,
444 Vmath::Smul(nSolutionPts, 0.5, &tmp[0], 1, &tmp[0], 1);
458 pFields[0]->ExtractTracePhys(
pressure, traceFieldsAdded[9]);
470 NekDouble GasConstantInv = 1.0 / m_gasConstant;
471 Vmath::Smul(nSolutionPts, GasConstantInv, &temperature[0], 1,
475 pFields[0]->ExtractTracePhys(temperature, traceFieldsAdded[10]);
484 for (i = 0; i < nDimensions; ++i)
490 for (i = 0; i < nDimensions; ++i)
492 for (n = 0; n < nElements; n++)
494 phys_offset = pFields[0]->GetPhys_Offset(n);
496 pFields[i]->GetExp(n)->PhysDeriv(i, temperature + phys_offset,
498 Dtemperature[i] + phys_offset);
501 pFields[0]->ExtractTracePhys(Dtemperature[i], traceDtemperature[i]);
504 for (i = 0; i < nDimensions; ++i)
507 &traceDtemperature[i][0], 1, &tmp[0], 1);
509 Vmath::Vadd(nTracePts, &traceFieldsAdded[11][0], 1, &tmp[0], 1,
510 &traceFieldsAdded[11][0], 1);
524 for (i = 0; i < nDimensions; ++i)
530 for (i = 0; i < nDimensions; ++i)
532 for (n = 0; n < nElements; n++)
534 phys_offset = pFields[0]->GetPhys_Offset(n);
536 pFields[i]->GetExp(n)->PhysDeriv(i,
pressure + phys_offset,
538 Dpressure[i] + phys_offset);
541 pFields[0]->ExtractTracePhys(Dpressure[i], traceDpressure[i]);
545 for (i = 0; i < nDimensions; ++i)
547 Vmath::Vmul(nTracePts, &m_traceTangents[i][0], 1, &traceDpressure[i][0],
550 Vmath::Vadd(nTracePts, &traceFieldsAdded[12][0], 1, &tmp[0], 1,
551 &traceFieldsAdded[12][0], 1);
555 for (i = 0; i < nDimensions; ++i)
558 &traceDpressure[i][0], 1, &tmp[0], 1);
560 Vmath::Vadd(nTracePts, &traceFieldsAdded[13][0], 1, &tmp[0], 1,
561 &traceFieldsAdded[13][0], 1);
565 Vmath::Vcopy(nTracePts, &traceDpressure[0][0], 1, &traceFieldsAdded[14][0],
569 Vmath::Vcopy(nTracePts, &traceDpressure[1][0], 1, &traceFieldsAdded[15][0],
573 Vmath::Vcopy(nTracePts, &traceDpressure[2][0], 1, &traceFieldsAdded[16][0],
593 for (i = 0; i < nDimensions; ++i)
599 Vmath::Vdiv(nSolutionPts, uFields[i + 1], 1, uFields[0], 1, velocity[i],
602 for (j = 0; j < nDimensions; ++j)
609 for (i = 0; i < nDimensions; ++i)
611 for (j = 0; j < nDimensions; ++j)
613 for (n = 0; n < nElements; n++)
615 phys_offset = pFields[0]->GetPhys_Offset(n);
617 pFields[i]->GetExp(n)->PhysDeriv(j, velocity[i] + phys_offset,
618 auxArray = Dvelocity[i][j] +
623 pFields[0]->ExtractTracePhys(Dvelocity[i][j], traceDvelocity[i][j]);
628 &traceFieldsAdded[17][0], 1);
630 &traceFieldsAdded[18][0], 1);
632 &traceFieldsAdded[19][0], 1);
634 &traceFieldsAdded[20][0], 1);
636 &traceFieldsAdded[21][0], 1);
638 &traceFieldsAdded[22][0], 1);
640 &traceFieldsAdded[23][0], 1);
642 &traceFieldsAdded[24][0], 1);
644 &traceFieldsAdded[25][0], 1);
664 if (m_ViscosityType ==
"Variable")
670 for (
int i = 0; i < nSolutionPts; ++i)
672 ratio = temperature[i] / T_star;
673 mu[i] = mu_star * ratio *
sqrt(ratio) * (T_star + 110.0) /
674 (temperature[i] + 110.0);
687 Vmath::Smul(nSolutionPts, 2.0, &mu[0], 1, &mu2[0], 1);
690 Vmath::Vadd(nSolutionPts, &divVel[0], 1, &Dvelocity[0][0][0], 1, &divVel[0],
692 Vmath::Vadd(nSolutionPts, &divVel[0], 1, &Dvelocity[1][1][0], 1, &divVel[0],
696 Vmath::Smul(nSolutionPts, lambda, &divVel[0], 1, &divVel[0], 1);
697 Vmath::Vmul(nSolutionPts, &mu[0], 1, &divVel[0], 1, &divVel[0], 1);
701 for (j = 0; j < m_spacedim; ++j)
706 Vmath::Vmul(nSolutionPts, &mu2[0], 1, &Dvelocity[j][j][0], 1,
709 Vmath::Vadd(nSolutionPts, &temp[j][0], 1, &divVel[0], 1, &Sgg[j][0], 1);
718 Vmath::Vadd(nSolutionPts, &Dvelocity[0][1][0], 1, &Dvelocity[1][0][0], 1,
722 Vmath::Vadd(nSolutionPts, &Dvelocity[0][2][0], 1, &Dvelocity[2][0][0], 1,
726 Vmath::Vadd(nSolutionPts, &Dvelocity[1][2][0], 1, &Dvelocity[2][1][0], 1,
730 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Sxy[0], 1, &Sxy[0], 1);
733 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Sxz[0], 1, &Sxz[0], 1);
736 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Syz[0], 1, &Syz[0], 1);
738 pFields[0]->ExtractTracePhys(Sgg[0], traceFieldsAdded[26]);
739 pFields[0]->ExtractTracePhys(Sgg[1], traceFieldsAdded[27]);
740 pFields[0]->ExtractTracePhys(Sgg[2], traceFieldsAdded[28]);
741 pFields[0]->ExtractTracePhys(Sxy, traceFieldsAdded[29]);
742 pFields[0]->ExtractTracePhys(Sxz, traceFieldsAdded[30]);
743 pFields[0]->ExtractTracePhys(Syz, traceFieldsAdded[31]);
749 pFields[0]->ExtractTracePhys(mu, traceFieldsAdded[32]);
760 Vmath::Smul(nSolutionPts, gamma, soundspeed, 1, soundspeed, 1);
761 Vmath::Vsqrt(nSolutionPts, soundspeed, 1, soundspeed, 1);
766 for (
int i = 0; i < m_spacedim; ++i)
768 Vmath::Vvtvp(nSolutionPts, uFields[i + 1], 1, uFields[i + 1], 1, mach,
772 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
773 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
775 Vmath::Vdiv(nSolutionPts, mach, 1, soundspeed, 1, mach, 1);
777 pFields[0]->ExtractTracePhys(mach, traceFieldsAdded[33]);
782 if (pFields[0]->GetBndCondExpansions().size())
786 nBndRegions = pFields[0]->GetBndCondExpansions().size();
787 for (b = 0; b < nBndRegions; ++b)
789 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
790 for (e = 0; e < nBndEdges; ++e)
792 nBndEdgePts = pFields[0]
793 ->GetBndCondExpansions()[b]
797 id2 = pFields[0]->GetTrace()->GetPhys_Offset(
798 pFields[0]->GetTraceMap()->GetBndCondIDToGlobalTraceID(
801 if (pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
803 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
805 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
809 Vmath::Vcopy(nBndEdgePts, &traceX[id2], 1, &surfaceX[id1],
812 Vmath::Vcopy(nBndEdgePts, &traceY[id2], 1, &surfaceY[id1],
815 Vmath::Vcopy(nBndEdgePts, &traceZ[id2], 1, &surfaceZ[id1],
825 if (pFields[0]->GetBndCondExpansions().size())
828 for (j = 0; j < nfields; ++j)
830 cout <<
"field " << j << endl;
834 nBndRegions = pFields[j]->GetBndCondExpansions().size();
835 for (b = 0; b < nBndRegions; ++b)
837 nBndEdges = pFields[j]->GetBndCondExpansions()[b]->GetExpSize();
838 for (e = 0; e < nBndEdges; ++e)
840 nBndEdgePts = pFields[j]
841 ->GetBndCondExpansions()[b]
845 id2 = pFields[j]->GetTrace()->GetPhys_Offset(
846 pFields[j]->GetTraceMap()->GetBndCondIDToGlobalTraceID(
849 if (pFields[j]->GetBndConditions()[b]->GetUserDefined() ==
851 pFields[j]->GetBndConditions()[b]->GetUserDefined() ==
853 pFields[j]->GetBndConditions()[b]->GetUserDefined() ==
857 &surfaceFields[j][id1], 1);
867 if (pFields[0]->GetBndCondExpansions().size())
869 for (j = 0; j < nfieldsAdded; ++j)
871 cout <<
"field added " << j << endl;
875 nBndRegions = pFields[0]->GetBndCondExpansions().size();
876 for (b = 0; b < nBndRegions; ++b)
878 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
879 for (e = 0; e < nBndEdges; ++e)
881 nBndEdgePts = pFields[0]
882 ->GetBndCondExpansions()[b]
886 id2 = pFields[0]->GetTrace()->GetPhys_Offset(
887 pFields[0]->GetTraceMap()->GetBndCondIDToGlobalTraceID(
890 if (pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
892 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
894 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
898 &surfaceFieldsAdded[j][id1], 1);
913 outfile.open(fname.c_str());
940 <<
"rhou[kg/(m^2 s)] "
942 <<
"rhov[kg/(m^2 s)] "
944 <<
"rhow[kg/(m^2 s)] "
998 for (i = 0; i < nSurfacePts; ++i)
1001 << scientific << setw(17) << setprecision(16) << surfaceX[i]
1002 <<
" \t " << surfaceY[i] <<
" \t " << surfaceZ[i] <<
" \t "
1003 << surfaceFieldsAdded[0][i] <<
" \t " << surfaceFieldsAdded[1][i]
1004 <<
" \t " << surfaceFieldsAdded[2][i] <<
" \t "
1005 << surfaceFieldsAdded[3][i] <<
" \t " << surfaceFieldsAdded[4][i]
1006 <<
" \t " << surfaceFieldsAdded[5][i] <<
" \t "
1007 << surfaceFieldsAdded[6][i] <<
" \t " << surfaceFieldsAdded[7][i]
1008 <<
" \t " << surfaceFieldsAdded[8][i] <<
" \t "
1009 << surfaceFields[0][i] <<
" \t " << surfaceFields[1][i] <<
" \t "
1010 << surfaceFields[2][i] <<
" \t " << surfaceFields[3][i] <<
" \t "
1011 << surfaceFields[4][i] <<
" \t " << surfaceFieldsAdded[9][i]
1012 <<
" \t " << surfaceFieldsAdded[10][i] <<
" \t "
1013 << surfaceFieldsAdded[11][i] <<
" \t " << surfaceFieldsAdded[12][i]
1014 <<
" \t " << surfaceFieldsAdded[13][i] <<
" \t "
1015 << surfaceFieldsAdded[14][i] <<
" \t " << surfaceFieldsAdded[15][i]
1016 <<
" \t " << surfaceFieldsAdded[16][i] <<
" \t "
1017 << surfaceFieldsAdded[17][i] <<
" \t " << surfaceFieldsAdded[18][i]
1018 <<
" \t " << surfaceFieldsAdded[19][i] <<
" \t "
1019 << surfaceFieldsAdded[20][i] <<
" \t " << surfaceFieldsAdded[21][i]
1020 <<
" \t " << surfaceFieldsAdded[22][i] <<
" \t "
1021 << surfaceFieldsAdded[23][i] <<
" \t " << surfaceFieldsAdded[24][i]
1022 <<
" \t " << surfaceFieldsAdded[25][i] <<
" \t "
1023 << surfaceFieldsAdded[26][i] <<
" \t " << surfaceFieldsAdded[27][i]
1024 <<
" \t " << surfaceFieldsAdded[28][i] <<
" \t "
1025 << surfaceFieldsAdded[29][i] <<
" \t " << surfaceFieldsAdded[30][i]
1026 <<
" \t " << surfaceFieldsAdded[31][i] <<
" \t "
1027 << surfaceFieldsAdded[32][i] <<
" \t " << surfaceFieldsAdded[33][i]
1030 outfile << endl << endl;
#define ASSERTL0(condition, msg)
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
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
The above copyright notice and this permission notice shall be included.
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 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)