69 int main(
int argc,
char *argv[])
71 string fname = std::string(argv[2]);
72 int fdot = fname.find_last_of(
'.');
73 if (fdot != std::string::npos)
75 string ending = fname.substr(fdot);
80 if (ending ==
".chk" || ending ==
".fld")
82 fname = fname.substr(0,fdot);
86 fname = fname +
".txt";
93 int nBndEdgePts, nBndEdges, nBndRegions;
98 "Usage: ExtractSurface3DCFS meshfile fieldFile\n");
100 "Extracts a surface from a 3D fld file"
101 "(only for CompressibleFlowSolver and purely 3D .fld files)\n");
106 = LibUtilities::SessionReader::CreateInstance(3, argv);
108 std::string m_ViscosityType;
121 int nDimensions = m_spacedim;
125 ASSERTL0(vSession->DefinesParameter(
"Gamma"),
126 "Compressible flow sessions must define a Gamma parameter.");
127 vSession->LoadParameter(
"Gamma", m_gamma, 1.4);
130 ASSERTL0(vSession->DefinesParameter(
"pInf"),
131 "Compressible flow sessions must define a pInf parameter.");
132 vSession->LoadParameter(
"pInf", m_pInf, 101325);
135 ASSERTL0(vSession->DefinesParameter(
"rhoInf"),
136 "Compressible flow sessions must define a rhoInf parameter.");
137 vSession->LoadParameter(
"rhoInf", m_rhoInf, 1.225);
140 ASSERTL0(vSession->DefinesParameter(
"uInf"),
141 "Compressible flow sessions must define a uInf parameter.");
142 vSession->LoadParameter(
"uInf", m_uInf, 0.1);
145 if (m_spacedim == 2 || m_spacedim == 3)
147 ASSERTL0(vSession->DefinesParameter(
"vInf"),
148 "Compressible flow sessions must define a vInf parameter"
149 "for 2D/3D problems.");
150 vSession->LoadParameter(
"vInf", m_vInf, 0.0);
156 ASSERTL0(vSession->DefinesParameter(
"wInf"),
157 "Compressible flow sessions must define a wInf parameter"
159 vSession->LoadParameter(
"wInf", m_wInf, 0.0);
162 vSession->LoadParameter (
"GasConstant", m_gasConstant, 287.058);
163 vSession->LoadParameter (
"Twall", m_Twall, 300.15);
164 vSession->LoadSolverInfo(
"ViscosityType", m_ViscosityType,
"Constant");
165 vSession->LoadParameter (
"mu", m_mu, 1.78e-05);
169 string meshfile(argv[1]);
171 SpatialDomains::MeshGraph::Read(vSession);
176 string fieldFile(argv[2]);
177 vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
178 vector<vector<NekDouble> > fieldData;
185 vector< vector<LibUtilities::PointsType> > pointsType;
186 for (i = 0; i < fieldDef.size(); ++i)
188 vector<LibUtilities::PointsType> ptype;
189 for (j = 0; j < 3; ++j)
193 pointsType.push_back(ptype);
195 graphShPt->SetExpansions(fieldDef, pointsType);
202 int nfields = fieldDef[0]->m_fields.size();
206 for(i = 0; i < pFields.num_elements(); i++)
210 vSession->GetVariable(i));
219 for (i = 1; i < nfields; ++i)
227 if (pFields[0]->GetBndCondExpansions().num_elements())
231 nBndRegions = pFields[0]->GetBndCondExpansions().num_elements();
232 for (b = 0; b < nBndRegions; ++b)
234 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
235 for (e = 0; e < nBndEdges; ++e)
237 nBndEdgePts = pFields[0]->
238 GetBndCondExpansions()[b]->GetExp(e)->GetTotPoints();
240 if (pFields[0]->GetBndConditions()[b]->
241 GetUserDefined() ==
"WallViscous" ||
242 pFields[0]->GetBndConditions()[b]->
243 GetUserDefined() ==
"WallAdiabatic" ||
244 pFields[0]->GetBndConditions()[b]->
245 GetUserDefined() ==
"Wall")
247 nSurfacePts += nBndEdgePts;
254 int nSolutionPts = pFields[0]->GetNpoints();
255 int nTracePts = pFields[0]->GetTrace()->GetTotPoints();
256 int nElements = pFields[0]->GetExpSize();
272 pFields[0]->GetCoords(x, y, z);
274 pFields[0]->ExtractTracePhys(x, traceX);
275 pFields[0]->ExtractTracePhys(y, traceY);
276 pFields[0]->ExtractTracePhys(z, traceZ);
286 for (j = 0; j < nfields; ++j)
293 for (i = 0; i < fieldData.size(); ++i)
295 Exp[j]->ExtractDataToCoeffs(fieldDef[i], fieldData[i],
296 fieldDef[i]->m_fields[j],
297 Exp[j]->UpdateCoeffs());
299 Exp[j]->BwdTrans(Exp[j]->GetCoeffs(), Exp[j]->UpdatePhys());
300 Vmath::Vcopy(nSolutionPts, Exp[j]->GetPhys(), 1, uFields[j], 1);
301 pFields[0]->ExtractTracePhys(uFields[j], traceFields[j]);
306 int nfieldsAdded = 34;
310 for (j = 0; j < nfieldsAdded; ++j)
330 for(i = 0; i < nDimensions; ++i)
334 pFields[0]->GetTrace()->GetNormals(m_traceNormals);
344 for(i = 0; i < nDimensions; ++i)
355 &m_traceNormals[0][0], 1,
356 &traceFieldsAdded[0][0], 1);
360 &m_traceNormals[1][0], 1,
361 &traceFieldsAdded[1][0], 1);
365 &m_traceNormals[2][0], 1,
366 &traceFieldsAdded[2][0], 1);
372 &m_traceNormals[0][0], 1,
377 &m_traceNormals[1][0], 1,
381 &m_traceNormals[2][0], 1,
385 for (i = 0; i < m_spacedim; i++)
388 &NormH[0],1, &NormH[0],1);
404 &m_traceBinormals[0][0], 1);
407 &m_traceBinormals[0][0], 1,
408 &traceFieldsAdded[3][0], 1);
429 &m_traceBinormals[1][0], 1);
432 &m_traceBinormals[1][0], 1,
433 &traceFieldsAdded[4][0], 1);
449 &m_traceBinormals[2][0], 1);
452 &m_traceBinormals[2][0], 1,
453 &traceFieldsAdded[5][0], 1);
469 &m_traceTangents[0][0], 1);
472 &m_traceTangents[0][0], 1,
473 &traceFieldsAdded[6][0], 1);
477 &m_traceBinormals[2][0], 1,
478 &m_traceTangents[1][0], 1);
481 &m_traceTangents[1][0], 1,
482 &traceFieldsAdded[7][0], 1);
503 &m_traceTangents[2][0], 1);
506 &m_traceTangents[2][0], 1,
507 &traceFieldsAdded[8][0], 1);
519 for (i = 0; i < m_spacedim; i++)
522 &uFields[i + 1][0], 1,
523 &uFields[i + 1][0], 1,
543 &uFields[nfields - 1][0], 1,
552 pFields[0]->ExtractTracePhys(pressure, traceFieldsAdded[9]);
566 NekDouble GasConstantInv = 1.0/m_gasConstant;
572 pFields[0]->ExtractTracePhys(temperature, traceFieldsAdded[10]);
581 for (i = 0; i < nDimensions; ++ i)
587 for (i = 0; i < nDimensions; ++ i)
589 for (n = 0; n < nElements; n++)
591 phys_offset = pFields[0]->GetPhys_Offset(n);
593 pFields[i]->GetExp(n)->PhysDeriv(
594 i, temperature + phys_offset,
595 auxArray = Dtemperature[i] + phys_offset);
598 pFields[0]->ExtractTracePhys(Dtemperature[i], traceDtemperature[i]);
601 for(i = 0; i < nDimensions; ++i)
604 &m_traceNormals[i][0], 1,
605 &traceDtemperature[i][0], 1,
609 &traceFieldsAdded[11][0], 1,
611 &traceFieldsAdded[11][0], 1);
625 for (i = 0; i < nDimensions; ++ i)
631 for (i = 0; i < nDimensions; ++ i)
633 for (n = 0; n < nElements; n++)
635 phys_offset = pFields[0]->GetPhys_Offset(n);
637 pFields[i]->GetExp(n)->PhysDeriv(
638 i, pressure + phys_offset,
639 auxArray = Dpressure[i] + phys_offset);
642 pFields[0]->ExtractTracePhys(Dpressure[i], traceDpressure[i]);
646 for(i = 0; i < nDimensions; ++i)
649 &m_traceTangents[i][0], 1,
650 &traceDpressure[i][0], 1,
654 &traceFieldsAdded[12][0], 1,
656 &traceFieldsAdded[12][0], 1);
660 for(i = 0; i < nDimensions; ++i)
663 &m_traceBinormals[i][0], 1,
664 &traceDpressure[i][0], 1,
668 &traceFieldsAdded[13][0], 1,
670 &traceFieldsAdded[13][0], 1);
676 &traceDpressure[0][0], 1,
677 &traceFieldsAdded[14][0], 1);
681 &traceDpressure[1][0], 1,
682 &traceFieldsAdded[15][0], 1);
686 &traceDpressure[2][0], 1,
687 &traceFieldsAdded[16][0], 1);
706 for (i = 0; i < nDimensions; ++ i)
712 Vmath::Vdiv(nSolutionPts, uFields[i+1], 1, uFields[0], 1,
715 for (j = 0; j < nDimensions; ++j)
722 for (i = 0; i < nDimensions; ++i)
724 for (j = 0; j < nDimensions; ++j)
726 for (n = 0; n < nElements; n++)
728 phys_offset = pFields[0]->GetPhys_Offset(n);
730 pFields[i]->GetExp(n)->PhysDeriv(
731 j, velocity[i] + phys_offset,
732 auxArray = Dvelocity[i][j] + phys_offset);
736 pFields[0]->ExtractTracePhys(Dvelocity[i][j], traceDvelocity[i][j]);
741 &traceDvelocity[0][0][0], 1,
742 &traceFieldsAdded[17][0], 1);
744 &traceDvelocity[0][1][0], 1,
745 &traceFieldsAdded[18][0], 1);
747 &traceDvelocity[0][2][0], 1,
748 &traceFieldsAdded[19][0], 1);
750 &traceDvelocity[1][0][0], 1,
751 &traceFieldsAdded[20][0], 1);
753 &traceDvelocity[1][1][0], 1,
754 &traceFieldsAdded[21][0], 1);
756 &traceDvelocity[1][2][0], 1,
757 &traceFieldsAdded[22][0], 1);
759 &traceDvelocity[2][0][0], 1,
760 &traceFieldsAdded[23][0], 1);
762 &traceDvelocity[2][1][0], 1,
763 &traceFieldsAdded[24][0], 1);
765 &traceDvelocity[2][2][0], 1,
766 &traceFieldsAdded[25][0], 1);
787 if (m_ViscosityType ==
"Variable")
790 NekDouble T_star = m_pInf / (m_rhoInf * m_gasConstant);
793 for (
int i = 0; i < nSolutionPts; ++i)
795 ratio = temperature[i] / T_star;
796 mu[i] = mu_star * ratio * sqrt(ratio) *
797 (T_star + 110.0) / (temperature[i] + 110.0);
810 Vmath::Smul(nSolutionPts, 2.0, &mu[0], 1, &mu2[0], 1);
814 &Dvelocity[0][0][0], 1, &divVel[0], 1);
816 &Dvelocity[1][1][0], 1, &divVel[0], 1);
819 Vmath::Smul(nSolutionPts, lambda, &divVel[0], 1, &divVel[0], 1);
820 Vmath::Vmul(nSolutionPts, &mu[0], 1, &divVel[0], 1, &divVel[0], 1);
824 for (j = 0; j < m_spacedim; ++j)
829 Vmath::Vmul(nSolutionPts, &mu2[0], 1, &Dvelocity[j][j][0], 1,
832 Vmath::Vadd(nSolutionPts, &temp[j][0], 1, &divVel[0], 1, &Sgg[j][0], 1);
842 &Dvelocity[1][0][0], 1, &Sxy[0], 1);
846 &Dvelocity[2][0][0], 1, &Sxz[0], 1);
850 &Dvelocity[2][1][0], 1, &Syz[0], 1);
853 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Sxy[0], 1, &Sxy[0], 1);
856 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Sxz[0], 1, &Sxz[0], 1);
859 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Syz[0], 1, &Syz[0], 1);
863 pFields[0]->ExtractTracePhys(Sgg[0], traceFieldsAdded[26]);
864 pFields[0]->ExtractTracePhys(Sgg[1], traceFieldsAdded[27]);
865 pFields[0]->ExtractTracePhys(Sgg[2], traceFieldsAdded[28]);
866 pFields[0]->ExtractTracePhys(Sxy, traceFieldsAdded[29]);
867 pFields[0]->ExtractTracePhys(Sxz, traceFieldsAdded[30]);
868 pFields[0]->ExtractTracePhys(Syz, traceFieldsAdded[31]);
874 pFields[0]->ExtractTracePhys(mu, traceFieldsAdded[32]);
884 Vmath::Vdiv (nSolutionPts, pressure, 1, uFields[0], 1, soundspeed, 1);
885 Vmath::Smul (nSolutionPts, gamma, soundspeed, 1, soundspeed, 1);
886 Vmath::Vsqrt(nSolutionPts, soundspeed, 1, soundspeed, 1);
891 for (
int i = 0; i < m_spacedim; ++i)
899 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
900 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
902 Vmath::Vdiv(nSolutionPts, mach, 1, soundspeed, 1, mach, 1);
904 pFields[0]->ExtractTracePhys(mach, traceFieldsAdded[33]);
911 if (pFields[0]->GetBndCondExpansions().num_elements())
915 nBndRegions = pFields[0]->GetBndCondExpansions().num_elements();
916 for (b = 0; b < nBndRegions; ++b)
918 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
919 for (e = 0; e < nBndEdges; ++e)
921 nBndEdgePts = pFields[0]->
922 GetBndCondExpansions()[b]->GetExp(e)->GetTotPoints();
924 id2 = pFields[0]->GetTrace()->
925 GetPhys_Offset(pFields[0]->GetTraceMap()->
926 GetBndCondTraceToGlobalTraceMap(cnt++));
928 if (pFields[0]->GetBndConditions()[b]->
929 GetUserDefined() ==
"WallViscous" ||
930 pFields[0]->GetBndConditions()[b]->
931 GetUserDefined() ==
"WallAdiabatic" ||
932 pFields[0]->GetBndConditions()[b]->
933 GetUserDefined() ==
"Wall")
952 if (pFields[0]->GetBndCondExpansions().num_elements())
955 for (j = 0; j < nfields; ++j)
957 cout <<
"field " << j << endl;
961 nBndRegions = pFields[j]->GetBndCondExpansions().num_elements();
962 for (b = 0; b < nBndRegions; ++b)
964 nBndEdges = pFields[j]->GetBndCondExpansions()[b]->GetExpSize();
965 for (e = 0; e < nBndEdges; ++e)
967 nBndEdgePts = pFields[j]->
968 GetBndCondExpansions()[b]->GetExp(e)->GetTotPoints();
970 id2 = pFields[j]->GetTrace()->
971 GetPhys_Offset(pFields[j]->GetTraceMap()->
972 GetBndCondTraceToGlobalTraceMap(cnt++));
974 if (pFields[j]->GetBndConditions()[b]->
975 GetUserDefined() ==
"WallViscous" ||
976 pFields[j]->GetBndConditions()[b]->
977 GetUserDefined() ==
"WallAdiabatic" ||
978 pFields[j]->GetBndConditions()[b]->
979 GetUserDefined() ==
"Wall")
982 &surfaceFields[j][id1], 1);
992 if (pFields[0]->GetBndCondExpansions().num_elements())
994 for (j = 0; j < nfieldsAdded; ++j)
996 cout <<
"field added " << j << endl;
1000 nBndRegions = pFields[0]->GetBndCondExpansions().num_elements();
1001 for (b = 0; b < nBndRegions; ++b)
1003 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
1004 for (e = 0; e < nBndEdges; ++e)
1006 nBndEdgePts = pFields[0]->
1007 GetBndCondExpansions()[b]->GetExp(e)->GetTotPoints();
1009 id2 = pFields[0]->GetTrace()->
1010 GetPhys_Offset(pFields[0]->GetTraceMap()->
1011 GetBndCondTraceToGlobalTraceMap(cnt++));
1013 if (pFields[0]->GetBndConditions()[b]->
1014 GetUserDefined() ==
"WallViscous" ||
1015 pFields[0]->GetBndConditions()[b]->
1016 GetUserDefined() ==
"WallAdiabatic" ||
1017 pFields[0]->GetBndConditions()[b]->
1018 GetUserDefined() ==
"Wall")
1020 Vmath::Vcopy(nBndEdgePts, &traceFieldsAdded[j][id2], 1,
1021 &surfaceFieldsAdded[j][id1], 1);
1036 outfile.open(fname.c_str());
1037 outfile <<
"% x[m] " <<
" \t"
1049 <<
"rho[kg/m^3] " <<
" \t"
1050 <<
"rhou[kg/(m^2 s)] " <<
" \t"
1051 <<
"rhov[kg/(m^2 s)] " <<
" \t"
1052 <<
"rhow[kg/(m^2 s)] " <<
" \t"
1053 <<
"E[Pa] " <<
" \t"
1054 <<
"p[Pa] " <<
" \t"
1056 <<
"dT/dn[k/m] " <<
" \t"
1057 <<
"dp/dT[Pa/m] " <<
" \t"
1058 <<
"dp/dB[Pa/m] " <<
" \t"
1059 <<
"dp/dx[Pa/m] " <<
" \t"
1060 <<
"dp/dy[Pa/m] " <<
" \t"
1061 <<
"dp/dz[Pa/m] " <<
" \t"
1062 <<
"du/dx[s^-1] " <<
" \t"
1063 <<
"du/dy[s^-1] " <<
" \t"
1064 <<
"du/dz[s^-1] " <<
" \t"
1065 <<
"dv/dx[s^-1] " <<
" \t"
1066 <<
"dv/dy[s^-1] " <<
" \t"
1067 <<
"dv/dz[s^-1] " <<
" \t"
1068 <<
"dw/dx[s^-1] " <<
" \t"
1069 <<
"dw/dy[s^-1] " <<
" \t"
1070 <<
"dw/dz[s^-1] " <<
" \t"
1071 <<
"tau_xx[Pa] " <<
" \t"
1072 <<
"tau_yy[Pa] " <<
" \t"
1073 <<
"tau_zz[Pa] " <<
" \t"
1074 <<
"tau_xy[Pa] " <<
" \t"
1075 <<
"tau_xz[Pa] " <<
" \t"
1076 <<
"tau_yz[Pa] " <<
" \t"
1077 <<
"mu[Pa s] " <<
" \t"
1080 for (i = 0; i < nSurfacePts; ++i)
1082 outfile << scientific
1085 << surfaceX[i] <<
" \t "
1086 << surfaceY[i] <<
" \t "
1087 << surfaceZ[i] <<
" \t "
1088 << surfaceFieldsAdded[0][i] <<
" \t "
1089 << surfaceFieldsAdded[1][i] <<
" \t "
1090 << surfaceFieldsAdded[2][i] <<
" \t "
1091 << surfaceFieldsAdded[3][i] <<
" \t "
1092 << surfaceFieldsAdded[4][i] <<
" \t "
1093 << surfaceFieldsAdded[5][i] <<
" \t "
1094 << surfaceFieldsAdded[6][i] <<
" \t "
1095 << surfaceFieldsAdded[7][i] <<
" \t "
1096 << surfaceFieldsAdded[8][i] <<
" \t "
1097 << surfaceFields[0][i] <<
" \t "
1098 << surfaceFields[1][i] <<
" \t "
1099 << surfaceFields[2][i] <<
" \t "
1100 << surfaceFields[3][i] <<
" \t "
1101 << surfaceFields[4][i] <<
" \t "
1102 << surfaceFieldsAdded[9][i] <<
" \t "
1103 << surfaceFieldsAdded[10][i] <<
" \t "
1104 << surfaceFieldsAdded[11][i] <<
" \t "
1105 << surfaceFieldsAdded[12][i] <<
" \t "
1106 << surfaceFieldsAdded[13][i] <<
" \t "
1107 << surfaceFieldsAdded[14][i] <<
" \t "
1108 << surfaceFieldsAdded[15][i] <<
" \t "
1109 << surfaceFieldsAdded[16][i] <<
" \t "
1110 << surfaceFieldsAdded[17][i] <<
" \t "
1111 << surfaceFieldsAdded[18][i] <<
" \t "
1112 << surfaceFieldsAdded[19][i] <<
" \t "
1113 << surfaceFieldsAdded[20][i] <<
" \t "
1114 << surfaceFieldsAdded[21][i] <<
" \t "
1115 << surfaceFieldsAdded[22][i] <<
" \t "
1116 << surfaceFieldsAdded[23][i] <<
" \t "
1117 << surfaceFieldsAdded[24][i] <<
" \t "
1118 << surfaceFieldsAdded[25][i] <<
" \t "
1119 << surfaceFieldsAdded[26][i] <<
" \t "
1120 << surfaceFieldsAdded[27][i] <<
" \t "
1121 << surfaceFieldsAdded[28][i] <<
" \t "
1122 << surfaceFieldsAdded[29][i] <<
" \t "
1123 << surfaceFieldsAdded[30][i] <<
" \t "
1124 << surfaceFieldsAdded[31][i] <<
" \t "
1125 << surfaceFieldsAdded[32][i] <<
" \t "
1126 << surfaceFieldsAdded[33][i] <<
" \t "
1129 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)
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...
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
1D Evenly-spaced points using Lagrange polynomial
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*y.
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< ExpList3D > ExpList3DSharedPtr
Shared pointer to an ExpList3D object.
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.