64int main(
int argc,
char *argv[])
66 string fname = std::string(argv[2]);
67 int fdot = fname.find_last_of(
'.');
68 if (fdot != std::string::npos)
70 string ending = fname.substr(fdot);
75 if (ending ==
".chk" || ending ==
".fld")
77 fname = fname.substr(0, fdot);
81 fname = fname +
".txt";
88 int nBndEdgePts, nBndEdges, nBndRegions;
92 fprintf(stderr,
"Usage: ExtractSurface3DCFS meshfile fieldFile\n");
94 "Extracts a surface from a 3D fld file"
95 "(only for CompressibleFlowSolver and purely 3D .fld files)\n");
100 LibUtilities::SessionReader::CreateInstance(3, argv);
102 SpatialDomains::MeshGraphIO::Read(vSession);
104 std::string m_ViscosityType;
117 int nDimensions = m_spacedim;
121 ASSERTL0(vSession->DefinesParameter(
"Gamma"),
122 "Compressible flow sessions must define a Gamma parameter.");
123 vSession->LoadParameter(
"Gamma", m_gamma, 1.4);
126 ASSERTL0(vSession->DefinesParameter(
"pInf"),
127 "Compressible flow sessions must define a pInf parameter.");
128 vSession->LoadParameter(
"pInf", m_pInf, 101325);
131 ASSERTL0(vSession->DefinesParameter(
"rhoInf"),
132 "Compressible flow sessions must define a rhoInf parameter.");
133 vSession->LoadParameter(
"rhoInf",
m_rhoInf, 1.225);
136 ASSERTL0(vSession->DefinesParameter(
"uInf"),
137 "Compressible flow sessions must define a uInf parameter.");
138 vSession->LoadParameter(
"uInf",
m_uInf, 0.1);
141 if (m_spacedim == 2 || m_spacedim == 3)
143 ASSERTL0(vSession->DefinesParameter(
"vInf"),
144 "Compressible flow sessions must define a vInf parameter"
145 "for 2D/3D problems.");
146 vSession->LoadParameter(
"vInf",
m_vInf, 0.0);
152 ASSERTL0(vSession->DefinesParameter(
"wInf"),
153 "Compressible flow sessions must define a wInf parameter"
155 vSession->LoadParameter(
"wInf", m_wInf, 0.0);
158 vSession->LoadParameter(
"GasConstant", m_gasConstant, 287.058);
159 vSession->LoadParameter(
"Twall",
m_Twall, 300.15);
160 vSession->LoadSolverInfo(
"ViscosityType", m_ViscosityType,
"Constant");
161 vSession->LoadParameter(
"mu",
m_mu, 1.78e-05);
165 string fieldFile(argv[2]);
166 vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
167 vector<vector<NekDouble>> fieldData;
174 vector<vector<LibUtilities::PointsType>> pointsType;
175 for (i = 0; i < fieldDef.size(); ++i)
177 vector<LibUtilities::PointsType> ptype;
178 for (j = 0; j < 3; ++j)
182 pointsType.push_back(ptype);
184 graphShPt->SetExpansionInfo(fieldDef, pointsType);
190 int nfields = fieldDef[0]->m_fields.size();
194 for (i = 0; i < pFields.size(); i++)
198 vSession, graphShPt, vSession->GetVariable(i));
207 for (i = 1; i < nfields; ++i)
215 if (pFields[0]->GetBndCondExpansions().size())
219 nBndRegions = pFields[0]->GetBndCondExpansions().size();
220 for (b = 0; b < nBndRegions; ++b)
222 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
223 for (e = 0; e < nBndEdges; ++e)
225 nBndEdgePts = pFields[0]
226 ->GetBndCondExpansions()[b]
230 if (pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
232 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
234 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
237 nSurfacePts += nBndEdgePts;
243 int nSolutionPts = pFields[0]->GetNpoints();
244 int nTracePts = pFields[0]->GetTrace()->GetTotPoints();
245 int nElements = pFields[0]->GetExpSize();
261 pFields[0]->GetCoords(x, y,
z);
263 pFields[0]->ExtractTracePhys(x, traceX);
264 pFields[0]->ExtractTracePhys(y, traceY);
265 pFields[0]->ExtractTracePhys(
z, traceZ);
275 for (j = 0; j < nfields; ++j)
281 for (i = 0; i < fieldData.size(); ++i)
283 Exp[j]->ExtractDataToCoeffs(fieldDef[i], fieldData[i],
284 fieldDef[i]->m_fields[j],
285 Exp[j]->UpdateCoeffs());
287 Exp[j]->BwdTrans(Exp[j]->GetCoeffs(), Exp[j]->UpdatePhys());
288 Vmath::Vcopy(nSolutionPts, Exp[j]->GetPhys(), 1, uFields[j], 1);
289 pFields[0]->ExtractTracePhys(uFields[j], traceFields[j]);
293 int nfieldsAdded = 34;
297 for (j = 0; j < nfieldsAdded; ++j)
317 for (i = 0; i < nDimensions; ++i)
321 pFields[0]->GetTrace()->GetNormals(m_traceNormals);
330 for (i = 0; i < nDimensions; ++i)
340 Vmath::Vcopy(nTracePts, &m_traceNormals[0][0], 1, &traceFieldsAdded[0][0],
344 Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &traceFieldsAdded[1][0],
348 Vmath::Vcopy(nTracePts, &m_traceNormals[2][0], 1, &traceFieldsAdded[2][0],
353 Vmath::Vadd(nTracePts, &m_traceNormals[0][0], 1, &tmpNorm[0], 1, &h[0][0],
356 Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &h[1][0], 1);
358 Vmath::Vcopy(nTracePts, &m_traceNormals[2][0], 1, &h[2][0], 1);
361 for (i = 0; i < m_spacedim; i++)
363 Vmath::Vvtvp(nTracePts, &h[i][0], 1, &h[i][0], 1, &NormH[0], 1,
368 Vmath::Vmul(nTracePts, &h[0][0], 1, &h[1][0], 1, &tmpTrace[0], 1);
370 Vmath::Vdiv(nTracePts, &tmpTrace[0], 1, &NormH[0], 1, &tmpTrace[0], 1);
372 Vmath::Smul(nTracePts, -2.0, &tmpTrace[0], 1, &m_traceBinormals[0][0], 1);
374 Vmath::Vcopy(nTracePts, &m_traceBinormals[0][0], 1, &traceFieldsAdded[3][0],
378 Vmath::Vmul(nTracePts, &h[1][0], 1, &h[1][0], 1, &tmpTrace[0], 1);
380 Vmath::Vdiv(nTracePts, &tmpTrace[0], 1, &NormH[0], 1, &tmpTrace[0], 1);
382 Vmath::Smul(nTracePts, -2.0, &tmpTrace[0], 1, &tmpTrace[0], 1);
384 Vmath::Vadd(nTracePts, &tmpTrace[0], 1, &tmpNorm[0], 1,
385 &m_traceBinormals[1][0], 1);
387 Vmath::Vcopy(nTracePts, &m_traceBinormals[1][0], 1, &traceFieldsAdded[4][0],
391 Vmath::Vmul(nTracePts, &h[1][0], 1, &h[2][0], 1, &tmpTrace[0], 1);
393 Vmath::Vdiv(nTracePts, &tmpTrace[0], 1, &NormH[0], 1, &tmpTrace[0], 1);
395 Vmath::Smul(nTracePts, -2.0, &tmpTrace[0], 1, &m_traceBinormals[2][0], 1);
397 Vmath::Vcopy(nTracePts, &m_traceBinormals[2][0], 1, &traceFieldsAdded[5][0],
401 Vmath::Vmul(nTracePts, &h[0][0], 1, &h[2][0], 1, &tmpTrace[0], 1);
403 Vmath::Vdiv(nTracePts, &tmpTrace[0], 1, &NormH[0], 1, &tmpTrace[0], 1);
405 Vmath::Smul(nTracePts, -2.0, &tmpTrace[0], 1, &m_traceTangents[0][0], 1);
407 Vmath::Vcopy(nTracePts, &m_traceTangents[0][0], 1, &traceFieldsAdded[6][0],
411 Vmath::Vcopy(nTracePts, &m_traceBinormals[2][0], 1, &m_traceTangents[1][0],
414 Vmath::Vcopy(nTracePts, &m_traceTangents[1][0], 1, &traceFieldsAdded[7][0],
418 Vmath::Vmul(nTracePts, &h[2][0], 1, &h[2][0], 1, &tmpTrace[0], 1);
420 Vmath::Vdiv(nTracePts, &tmpTrace[0], 1, &NormH[0], 1, &tmpTrace[0], 1);
422 Vmath::Smul(nTracePts, -2.0, &tmpTrace[0], 1, &tmpTrace[0], 1);
424 Vmath::Vadd(nTracePts, &tmpTrace[0], 1, &tmpNorm[0], 1,
425 &m_traceTangents[2][0], 1);
427 Vmath::Vcopy(nTracePts, &m_traceTangents[2][0], 1, &traceFieldsAdded[8][0],
438 for (i = 0; i < m_spacedim; i++)
440 Vmath::Vmul(nSolutionPts, &uFields[i + 1][0], 1, &uFields[i + 1][0], 1,
443 Vmath::Smul(nSolutionPts, 0.5, &tmp[0], 1, &tmp[0], 1);
457 pFields[0]->ExtractTracePhys(
pressure, traceFieldsAdded[9]);
469 NekDouble GasConstantInv = 1.0 / m_gasConstant;
470 Vmath::Smul(nSolutionPts, GasConstantInv, &temperature[0], 1,
474 pFields[0]->ExtractTracePhys(temperature, traceFieldsAdded[10]);
483 for (i = 0; i < nDimensions; ++i)
489 for (i = 0; i < nDimensions; ++i)
491 for (n = 0; n < nElements; n++)
493 phys_offset = pFields[0]->GetPhys_Offset(n);
495 pFields[i]->GetExp(n)->PhysDeriv(i, temperature + phys_offset,
497 Dtemperature[i] + phys_offset);
500 pFields[0]->ExtractTracePhys(Dtemperature[i], traceDtemperature[i]);
503 for (i = 0; i < nDimensions; ++i)
506 &traceDtemperature[i][0], 1, &tmp[0], 1);
508 Vmath::Vadd(nTracePts, &traceFieldsAdded[11][0], 1, &tmp[0], 1,
509 &traceFieldsAdded[11][0], 1);
523 for (i = 0; i < nDimensions; ++i)
529 for (i = 0; i < nDimensions; ++i)
531 for (n = 0; n < nElements; n++)
533 phys_offset = pFields[0]->GetPhys_Offset(n);
535 pFields[i]->GetExp(n)->PhysDeriv(i,
pressure + phys_offset,
537 Dpressure[i] + phys_offset);
540 pFields[0]->ExtractTracePhys(Dpressure[i], traceDpressure[i]);
544 for (i = 0; i < nDimensions; ++i)
546 Vmath::Vmul(nTracePts, &m_traceTangents[i][0], 1, &traceDpressure[i][0],
549 Vmath::Vadd(nTracePts, &traceFieldsAdded[12][0], 1, &tmp[0], 1,
550 &traceFieldsAdded[12][0], 1);
554 for (i = 0; i < nDimensions; ++i)
557 &traceDpressure[i][0], 1, &tmp[0], 1);
559 Vmath::Vadd(nTracePts, &traceFieldsAdded[13][0], 1, &tmp[0], 1,
560 &traceFieldsAdded[13][0], 1);
564 Vmath::Vcopy(nTracePts, &traceDpressure[0][0], 1, &traceFieldsAdded[14][0],
568 Vmath::Vcopy(nTracePts, &traceDpressure[1][0], 1, &traceFieldsAdded[15][0],
572 Vmath::Vcopy(nTracePts, &traceDpressure[2][0], 1, &traceFieldsAdded[16][0],
592 for (i = 0; i < nDimensions; ++i)
598 Vmath::Vdiv(nSolutionPts, uFields[i + 1], 1, uFields[0], 1, velocity[i],
601 for (j = 0; j < nDimensions; ++j)
608 for (i = 0; i < nDimensions; ++i)
610 for (j = 0; j < nDimensions; ++j)
612 for (n = 0; n < nElements; n++)
614 phys_offset = pFields[0]->GetPhys_Offset(n);
616 pFields[i]->GetExp(n)->PhysDeriv(j, velocity[i] + phys_offset,
617 auxArray = Dvelocity[i][j] +
622 pFields[0]->ExtractTracePhys(Dvelocity[i][j], traceDvelocity[i][j]);
627 &traceFieldsAdded[17][0], 1);
629 &traceFieldsAdded[18][0], 1);
631 &traceFieldsAdded[19][0], 1);
633 &traceFieldsAdded[20][0], 1);
635 &traceFieldsAdded[21][0], 1);
637 &traceFieldsAdded[22][0], 1);
639 &traceFieldsAdded[23][0], 1);
641 &traceFieldsAdded[24][0], 1);
643 &traceFieldsAdded[25][0], 1);
663 if (m_ViscosityType ==
"Variable")
669 for (
int i = 0; i < nSolutionPts; ++i)
671 ratio = temperature[i] / T_star;
672 mu[i] = mu_star * ratio *
sqrt(ratio) * (T_star + 110.0) /
673 (temperature[i] + 110.0);
686 Vmath::Smul(nSolutionPts, 2.0, &mu[0], 1, &mu2[0], 1);
689 Vmath::Vadd(nSolutionPts, &divVel[0], 1, &Dvelocity[0][0][0], 1, &divVel[0],
691 Vmath::Vadd(nSolutionPts, &divVel[0], 1, &Dvelocity[1][1][0], 1, &divVel[0],
695 Vmath::Smul(nSolutionPts, lambda, &divVel[0], 1, &divVel[0], 1);
696 Vmath::Vmul(nSolutionPts, &mu[0], 1, &divVel[0], 1, &divVel[0], 1);
700 for (j = 0; j < m_spacedim; ++j)
705 Vmath::Vmul(nSolutionPts, &mu2[0], 1, &Dvelocity[j][j][0], 1,
708 Vmath::Vadd(nSolutionPts, &temp[j][0], 1, &divVel[0], 1, &Sgg[j][0], 1);
717 Vmath::Vadd(nSolutionPts, &Dvelocity[0][1][0], 1, &Dvelocity[1][0][0], 1,
721 Vmath::Vadd(nSolutionPts, &Dvelocity[0][2][0], 1, &Dvelocity[2][0][0], 1,
725 Vmath::Vadd(nSolutionPts, &Dvelocity[1][2][0], 1, &Dvelocity[2][1][0], 1,
729 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Sxy[0], 1, &Sxy[0], 1);
732 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Sxz[0], 1, &Sxz[0], 1);
735 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Syz[0], 1, &Syz[0], 1);
737 pFields[0]->ExtractTracePhys(Sgg[0], traceFieldsAdded[26]);
738 pFields[0]->ExtractTracePhys(Sgg[1], traceFieldsAdded[27]);
739 pFields[0]->ExtractTracePhys(Sgg[2], traceFieldsAdded[28]);
740 pFields[0]->ExtractTracePhys(Sxy, traceFieldsAdded[29]);
741 pFields[0]->ExtractTracePhys(Sxz, traceFieldsAdded[30]);
742 pFields[0]->ExtractTracePhys(Syz, traceFieldsAdded[31]);
748 pFields[0]->ExtractTracePhys(mu, traceFieldsAdded[32]);
759 Vmath::Smul(nSolutionPts, gamma, soundspeed, 1, soundspeed, 1);
760 Vmath::Vsqrt(nSolutionPts, soundspeed, 1, soundspeed, 1);
765 for (
int i = 0; i < m_spacedim; ++i)
767 Vmath::Vvtvp(nSolutionPts, uFields[i + 1], 1, uFields[i + 1], 1, mach,
771 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
772 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
774 Vmath::Vdiv(nSolutionPts, mach, 1, soundspeed, 1, mach, 1);
776 pFields[0]->ExtractTracePhys(mach, traceFieldsAdded[33]);
781 if (pFields[0]->GetBndCondExpansions().size())
785 nBndRegions = pFields[0]->GetBndCondExpansions().size();
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]
796 id2 = pFields[0]->GetTrace()->GetPhys_Offset(
797 pFields[0]->GetTraceMap()->GetBndCondIDToGlobalTraceID(
800 if (pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
802 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
804 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
808 Vmath::Vcopy(nBndEdgePts, &traceX[id2], 1, &surfaceX[id1],
811 Vmath::Vcopy(nBndEdgePts, &traceY[id2], 1, &surfaceY[id1],
814 Vmath::Vcopy(nBndEdgePts, &traceZ[id2], 1, &surfaceZ[id1],
824 if (pFields[0]->GetBndCondExpansions().size())
827 for (j = 0; j < nfields; ++j)
829 cout <<
"field " << j << endl;
833 nBndRegions = pFields[j]->GetBndCondExpansions().size();
834 for (b = 0; b < nBndRegions; ++b)
836 nBndEdges = pFields[j]->GetBndCondExpansions()[b]->GetExpSize();
837 for (e = 0; e < nBndEdges; ++e)
839 nBndEdgePts = pFields[j]
840 ->GetBndCondExpansions()[b]
844 id2 = pFields[j]->GetTrace()->GetPhys_Offset(
845 pFields[j]->GetTraceMap()->GetBndCondIDToGlobalTraceID(
848 if (pFields[j]->GetBndConditions()[b]->GetUserDefined() ==
850 pFields[j]->GetBndConditions()[b]->GetUserDefined() ==
852 pFields[j]->GetBndConditions()[b]->GetUserDefined() ==
856 &surfaceFields[j][id1], 1);
866 if (pFields[0]->GetBndCondExpansions().size())
868 for (j = 0; j < nfieldsAdded; ++j)
870 cout <<
"field added " << j << endl;
874 nBndRegions = pFields[0]->GetBndCondExpansions().size();
875 for (b = 0; b < nBndRegions; ++b)
877 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
878 for (e = 0; e < nBndEdges; ++e)
880 nBndEdgePts = pFields[0]
881 ->GetBndCondExpansions()[b]
885 id2 = pFields[0]->GetTrace()->GetPhys_Offset(
886 pFields[0]->GetTraceMap()->GetBndCondIDToGlobalTraceID(
889 if (pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
891 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
893 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
897 &surfaceFieldsAdded[j][id1], 1);
912 outfile.open(fname.c_str());
939 <<
"rhou[kg/(m^2 s)] "
941 <<
"rhov[kg/(m^2 s)] "
943 <<
"rhow[kg/(m^2 s)] "
997 for (i = 0; i < nSurfacePts; ++i)
1000 << scientific << setw(17) << setprecision(16) << surfaceX[i]
1001 <<
" \t " << surfaceY[i] <<
" \t " << surfaceZ[i] <<
" \t "
1002 << surfaceFieldsAdded[0][i] <<
" \t " << surfaceFieldsAdded[1][i]
1003 <<
" \t " << surfaceFieldsAdded[2][i] <<
" \t "
1004 << surfaceFieldsAdded[3][i] <<
" \t " << surfaceFieldsAdded[4][i]
1005 <<
" \t " << surfaceFieldsAdded[5][i] <<
" \t "
1006 << surfaceFieldsAdded[6][i] <<
" \t " << surfaceFieldsAdded[7][i]
1007 <<
" \t " << surfaceFieldsAdded[8][i] <<
" \t "
1008 << surfaceFields[0][i] <<
" \t " << surfaceFields[1][i] <<
" \t "
1009 << surfaceFields[2][i] <<
" \t " << surfaceFields[3][i] <<
" \t "
1010 << surfaceFields[4][i] <<
" \t " << surfaceFieldsAdded[9][i]
1011 <<
" \t " << surfaceFieldsAdded[10][i] <<
" \t "
1012 << surfaceFieldsAdded[11][i] <<
" \t " << surfaceFieldsAdded[12][i]
1013 <<
" \t " << surfaceFieldsAdded[13][i] <<
" \t "
1014 << surfaceFieldsAdded[14][i] <<
" \t " << surfaceFieldsAdded[15][i]
1015 <<
" \t " << surfaceFieldsAdded[16][i] <<
" \t "
1016 << surfaceFieldsAdded[17][i] <<
" \t " << surfaceFieldsAdded[18][i]
1017 <<
" \t " << surfaceFieldsAdded[19][i] <<
" \t "
1018 << surfaceFieldsAdded[20][i] <<
" \t " << surfaceFieldsAdded[21][i]
1019 <<
" \t " << surfaceFieldsAdded[22][i] <<
" \t "
1020 << surfaceFieldsAdded[23][i] <<
" \t " << surfaceFieldsAdded[24][i]
1021 <<
" \t " << surfaceFieldsAdded[25][i] <<
" \t "
1022 << surfaceFieldsAdded[26][i] <<
" \t " << surfaceFieldsAdded[27][i]
1023 <<
" \t " << surfaceFieldsAdded[28][i] <<
" \t "
1024 << surfaceFieldsAdded[29][i] <<
" \t " << surfaceFieldsAdded[30][i]
1025 <<
" \t " << surfaceFieldsAdded[31][i] <<
" \t "
1026 << surfaceFieldsAdded[32][i] <<
" \t " << surfaceFieldsAdded[33][i]
1029 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
std::vector< double > z(NPUPPER)
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)