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;
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);
167 vSession->LoadParameter (
"thermalConductivity",
168 m_thermalConductivity, 0.0257);
172 string meshfile(argv[1]);
174 SpatialDomains::MeshGraph::Read(vSession);
179 string fieldFile(argv[2]);
180 vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
181 vector<vector<NekDouble> > fieldData;
188 vector< vector<LibUtilities::PointsType> > pointsType;
189 for (i = 0; i < fieldDef.size(); ++i)
191 vector<LibUtilities::PointsType> ptype;
192 for (j = 0; j < 3; ++j)
196 pointsType.push_back(ptype);
198 graphShPt->SetExpansions(fieldDef, pointsType);
205 int nfields = fieldDef[0]->m_fields.size();
209 for(i = 0; i < pFields.num_elements(); i++)
213 vSession->GetVariable(i));
222 for (i = 1; i < nfields; ++i)
230 if (pFields[0]->GetBndCondExpansions().num_elements())
234 nBndRegions = pFields[0]->GetBndCondExpansions().num_elements();
235 for (b = 0; b < nBndRegions; ++b)
237 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
238 for (e = 0; e < nBndEdges; ++e)
240 nBndEdgePts = pFields[0]->
241 GetBndCondExpansions()[b]->GetExp(e)->GetTotPoints();
243 if (pFields[0]->GetBndConditions()[b]->
244 GetUserDefined() ==
"WallViscous" ||
245 pFields[0]->GetBndConditions()[b]->
246 GetUserDefined() ==
"WallAdiabatic" ||
247 pFields[0]->GetBndConditions()[b]->
248 GetUserDefined() ==
"Wall")
250 nSurfacePts += nBndEdgePts;
257 int nSolutionPts = pFields[0]->GetNpoints();
258 int nTracePts = pFields[0]->GetTrace()->GetTotPoints();
259 int nElements = pFields[0]->GetExpSize();
275 pFields[0]->GetCoords(x, y, z);
277 pFields[0]->ExtractTracePhys(x, traceX);
278 pFields[0]->ExtractTracePhys(y, traceY);
279 pFields[0]->ExtractTracePhys(z, traceZ);
289 for (j = 0; j < nfields; ++j)
296 for (i = 0; i < fieldData.size(); ++i)
298 Exp[j]->ExtractDataToCoeffs(fieldDef[i], fieldData[i],
299 fieldDef[i]->m_fields[j],
300 Exp[j]->UpdateCoeffs());
302 Exp[j]->BwdTrans(Exp[j]->GetCoeffs(), Exp[j]->UpdatePhys());
303 Vmath::Vcopy(nSolutionPts, Exp[j]->GetPhys(), 1, uFields[j], 1);
304 pFields[0]->ExtractTracePhys(uFields[j], traceFields[j]);
309 int nfieldsAdded = 34;
313 for (j = 0; j < nfieldsAdded; ++j)
333 for(i = 0; i < nDimensions; ++i)
337 pFields[0]->GetTrace()->GetNormals(m_traceNormals);
347 for(i = 0; i < nDimensions; ++i)
358 &m_traceNormals[0][0], 1,
359 &traceFieldsAdded[0][0], 1);
363 &m_traceNormals[1][0], 1,
364 &traceFieldsAdded[1][0], 1);
368 &m_traceNormals[2][0], 1,
369 &traceFieldsAdded[2][0], 1);
375 &m_traceNormals[0][0], 1,
380 &m_traceNormals[1][0], 1,
384 &m_traceNormals[2][0], 1,
388 for (i = 0; i < m_spacedim; i++)
391 &NormH[0],1, &NormH[0],1);
407 &m_traceBinormals[0][0], 1);
410 &m_traceBinormals[0][0], 1,
411 &traceFieldsAdded[3][0], 1);
432 &m_traceBinormals[1][0], 1);
435 &m_traceBinormals[1][0], 1,
436 &traceFieldsAdded[4][0], 1);
452 &m_traceBinormals[2][0], 1);
455 &m_traceBinormals[2][0], 1,
456 &traceFieldsAdded[5][0], 1);
472 &m_traceTangents[0][0], 1);
475 &m_traceTangents[0][0], 1,
476 &traceFieldsAdded[6][0], 1);
480 &m_traceBinormals[2][0], 1,
481 &m_traceTangents[1][0], 1);
484 &m_traceTangents[1][0], 1,
485 &traceFieldsAdded[7][0], 1);
506 &m_traceTangents[2][0], 1);
509 &m_traceTangents[2][0], 1,
510 &traceFieldsAdded[8][0], 1);
522 for (i = 0; i < m_spacedim; i++)
525 &uFields[i + 1][0], 1,
526 &uFields[i + 1][0], 1,
546 &uFields[nfields - 1][0], 1,
555 pFields[0]->ExtractTracePhys(pressure, traceFieldsAdded[9]);
569 NekDouble GasConstantInv = 1.0/m_gasConstant;
575 pFields[0]->ExtractTracePhys(temperature, traceFieldsAdded[10]);
584 for (i = 0; i < nDimensions; ++ i)
590 for (i = 0; i < nDimensions; ++ i)
592 for (n = 0; n < nElements; n++)
594 phys_offset = pFields[0]->GetPhys_Offset(n);
596 pFields[i]->GetExp(n)->PhysDeriv(
597 i, temperature + phys_offset,
598 auxArray = Dtemperature[i] + phys_offset);
601 pFields[0]->ExtractTracePhys(Dtemperature[i], traceDtemperature[i]);
604 for(i = 0; i < nDimensions; ++i)
607 &m_traceNormals[i][0], 1,
608 &traceDtemperature[i][0], 1,
612 &traceFieldsAdded[11][0], 1,
614 &traceFieldsAdded[11][0], 1);
628 for (i = 0; i < nDimensions; ++ i)
634 for (i = 0; i < nDimensions; ++ i)
636 for (n = 0; n < nElements; n++)
638 phys_offset = pFields[0]->GetPhys_Offset(n);
640 pFields[i]->GetExp(n)->PhysDeriv(
641 i, pressure + phys_offset,
642 auxArray = Dpressure[i] + phys_offset);
645 pFields[0]->ExtractTracePhys(Dpressure[i], traceDpressure[i]);
649 for(i = 0; i < nDimensions; ++i)
652 &m_traceTangents[i][0], 1,
653 &traceDpressure[i][0], 1,
657 &traceFieldsAdded[12][0], 1,
659 &traceFieldsAdded[12][0], 1);
663 for(i = 0; i < nDimensions; ++i)
666 &m_traceBinormals[i][0], 1,
667 &traceDpressure[i][0], 1,
671 &traceFieldsAdded[13][0], 1,
673 &traceFieldsAdded[13][0], 1);
679 &traceDpressure[0][0], 1,
680 &traceFieldsAdded[14][0], 1);
684 &traceDpressure[1][0], 1,
685 &traceFieldsAdded[15][0], 1);
689 &traceDpressure[2][0], 1,
690 &traceFieldsAdded[16][0], 1);
709 for (i = 0; i < nDimensions; ++ i)
715 Vmath::Vdiv(nSolutionPts, uFields[i+1], 1, uFields[0], 1,
718 for (j = 0; j < nDimensions; ++j)
725 for (i = 0; i < nDimensions; ++i)
727 for (j = 0; j < nDimensions; ++j)
729 for (n = 0; n < nElements; n++)
731 phys_offset = pFields[0]->GetPhys_Offset(n);
733 pFields[i]->GetExp(n)->PhysDeriv(
734 j, velocity[i] + phys_offset,
735 auxArray = Dvelocity[i][j] + phys_offset);
739 pFields[0]->ExtractTracePhys(Dvelocity[i][j], traceDvelocity[i][j]);
744 &traceDvelocity[0][0][0], 1,
745 &traceFieldsAdded[17][0], 1);
747 &traceDvelocity[0][1][0], 1,
748 &traceFieldsAdded[18][0], 1);
750 &traceDvelocity[0][2][0], 1,
751 &traceFieldsAdded[19][0], 1);
753 &traceDvelocity[1][0][0], 1,
754 &traceFieldsAdded[20][0], 1);
756 &traceDvelocity[1][1][0], 1,
757 &traceFieldsAdded[21][0], 1);
759 &traceDvelocity[1][2][0], 1,
760 &traceFieldsAdded[22][0], 1);
762 &traceDvelocity[2][0][0], 1,
763 &traceFieldsAdded[23][0], 1);
765 &traceDvelocity[2][1][0], 1,
766 &traceFieldsAdded[24][0], 1);
768 &traceDvelocity[2][2][0], 1,
769 &traceFieldsAdded[25][0], 1);
790 if (m_ViscosityType ==
"Variable")
793 NekDouble T_star = m_pInf / (m_rhoInf * m_gasConstant);
796 for (
int i = 0; i < nSolutionPts; ++i)
798 ratio = temperature[i] / T_star;
799 mu[i] = mu_star * ratio * sqrt(ratio) *
800 (T_star + 110.0) / (temperature[i] + 110.0);
813 Vmath::Smul(nSolutionPts, 2.0, &mu[0], 1, &mu2[0], 1);
817 &Dvelocity[0][0][0], 1, &divVel[0], 1);
819 &Dvelocity[1][1][0], 1, &divVel[0], 1);
822 Vmath::Smul(nSolutionPts, lambda, &divVel[0], 1, &divVel[0], 1);
823 Vmath::Vmul(nSolutionPts, &mu[0], 1, &divVel[0], 1, &divVel[0], 1);
827 for (j = 0; j < m_spacedim; ++j)
832 Vmath::Vmul(nSolutionPts, &mu2[0], 1, &Dvelocity[j][j][0], 1,
835 Vmath::Vadd(nSolutionPts, &temp[j][0], 1, &divVel[0], 1, &Sgg[j][0], 1);
845 &Dvelocity[1][0][0], 1, &Sxy[0], 1);
849 &Dvelocity[2][0][0], 1, &Sxz[0], 1);
853 &Dvelocity[2][1][0], 1, &Syz[0], 1);
856 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Sxy[0], 1, &Sxy[0], 1);
859 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Sxz[0], 1, &Sxz[0], 1);
862 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Syz[0], 1, &Syz[0], 1);
866 pFields[0]->ExtractTracePhys(Sgg[0], traceFieldsAdded[26]);
867 pFields[0]->ExtractTracePhys(Sgg[1], traceFieldsAdded[27]);
868 pFields[0]->ExtractTracePhys(Sgg[2], traceFieldsAdded[28]);
869 pFields[0]->ExtractTracePhys(Sxy, traceFieldsAdded[29]);
870 pFields[0]->ExtractTracePhys(Sxz, traceFieldsAdded[30]);
871 pFields[0]->ExtractTracePhys(Syz, traceFieldsAdded[31]);
877 pFields[0]->ExtractTracePhys(mu, traceFieldsAdded[32]);
887 Vmath::Vdiv (nSolutionPts, pressure, 1, uFields[0], 1, soundspeed, 1);
888 Vmath::Smul (nSolutionPts, gamma, soundspeed, 1, soundspeed, 1);
889 Vmath::Vsqrt(nSolutionPts, soundspeed, 1, soundspeed, 1);
894 for (
int i = 0; i < m_spacedim; ++i)
902 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
903 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
905 Vmath::Vdiv(nSolutionPts, mach, 1, soundspeed, 1, mach, 1);
907 pFields[0]->ExtractTracePhys(mach, traceFieldsAdded[33]);
914 if (pFields[0]->GetBndCondExpansions().num_elements())
918 nBndRegions = pFields[0]->GetBndCondExpansions().num_elements();
919 for (b = 0; b < nBndRegions; ++b)
921 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
922 for (e = 0; e < nBndEdges; ++e)
924 nBndEdgePts = pFields[0]->
925 GetBndCondExpansions()[b]->GetExp(e)->GetTotPoints();
927 id2 = pFields[0]->GetTrace()->
928 GetPhys_Offset(pFields[0]->GetTraceMap()->
929 GetBndCondTraceToGlobalTraceMap(cnt++));
931 if (pFields[0]->GetBndConditions()[b]->
932 GetUserDefined() ==
"WallViscous" ||
933 pFields[0]->GetBndConditions()[b]->
934 GetUserDefined() ==
"WallAdiabatic" ||
935 pFields[0]->GetBndConditions()[b]->
936 GetUserDefined() ==
"Wall")
955 if (pFields[0]->GetBndCondExpansions().num_elements())
958 for (j = 0; j < nfields; ++j)
960 cout <<
"field " << j << endl;
964 nBndRegions = pFields[j]->GetBndCondExpansions().num_elements();
965 for (b = 0; b < nBndRegions; ++b)
967 nBndEdges = pFields[j]->GetBndCondExpansions()[b]->GetExpSize();
968 for (e = 0; e < nBndEdges; ++e)
970 nBndEdgePts = pFields[j]->
971 GetBndCondExpansions()[b]->GetExp(e)->GetTotPoints();
973 id2 = pFields[j]->GetTrace()->
974 GetPhys_Offset(pFields[j]->GetTraceMap()->
975 GetBndCondTraceToGlobalTraceMap(cnt++));
977 if (pFields[j]->GetBndConditions()[b]->
978 GetUserDefined() ==
"WallViscous" ||
979 pFields[j]->GetBndConditions()[b]->
980 GetUserDefined() ==
"WallAdiabatic" ||
981 pFields[j]->GetBndConditions()[b]->
982 GetUserDefined() ==
"Wall")
985 &surfaceFields[j][id1], 1);
995 if (pFields[0]->GetBndCondExpansions().num_elements())
997 for (j = 0; j < nfieldsAdded; ++j)
999 cout <<
"field added " << j << endl;
1003 nBndRegions = pFields[0]->GetBndCondExpansions().num_elements();
1004 for (b = 0; b < nBndRegions; ++b)
1006 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
1007 for (e = 0; e < nBndEdges; ++e)
1009 nBndEdgePts = pFields[0]->
1010 GetBndCondExpansions()[b]->GetExp(e)->GetTotPoints();
1012 id2 = pFields[0]->GetTrace()->
1013 GetPhys_Offset(pFields[0]->GetTraceMap()->
1014 GetBndCondTraceToGlobalTraceMap(cnt++));
1016 if (pFields[0]->GetBndConditions()[b]->
1017 GetUserDefined() ==
"WallViscous" ||
1018 pFields[0]->GetBndConditions()[b]->
1019 GetUserDefined() ==
"WallAdiabatic" ||
1020 pFields[0]->GetBndConditions()[b]->
1021 GetUserDefined() ==
"Wall")
1023 Vmath::Vcopy(nBndEdgePts, &traceFieldsAdded[j][id2], 1,
1024 &surfaceFieldsAdded[j][id1], 1);
1039 outfile.open(fname.c_str());
1040 outfile <<
"% x[m] " <<
" \t"
1052 <<
"rho[kg/m^3] " <<
" \t"
1053 <<
"rhou[kg/(m^2 s)] " <<
" \t"
1054 <<
"rhov[kg/(m^2 s)] " <<
" \t"
1055 <<
"rhow[kg/(m^2 s)] " <<
" \t"
1056 <<
"E[Pa] " <<
" \t"
1057 <<
"p[Pa] " <<
" \t"
1059 <<
"dT/dn[k/m] " <<
" \t"
1060 <<
"dp/dT[Pa/m] " <<
" \t"
1061 <<
"dp/dB[Pa/m] " <<
" \t"
1062 <<
"dp/dx[Pa/m] " <<
" \t"
1063 <<
"dp/dy[Pa/m] " <<
" \t"
1064 <<
"dp/dz[Pa/m] " <<
" \t"
1065 <<
"du/dx[s^-1] " <<
" \t"
1066 <<
"du/dy[s^-1] " <<
" \t"
1067 <<
"du/dz[s^-1] " <<
" \t"
1068 <<
"dv/dx[s^-1] " <<
" \t"
1069 <<
"dv/dy[s^-1] " <<
" \t"
1070 <<
"dv/dz[s^-1] " <<
" \t"
1071 <<
"dw/dx[s^-1] " <<
" \t"
1072 <<
"dw/dy[s^-1] " <<
" \t"
1073 <<
"dw/dz[s^-1] " <<
" \t"
1074 <<
"tau_xx[Pa] " <<
" \t"
1075 <<
"tau_yy[Pa] " <<
" \t"
1076 <<
"tau_zz[Pa] " <<
" \t"
1077 <<
"tau_xy[Pa] " <<
" \t"
1078 <<
"tau_xz[Pa] " <<
" \t"
1079 <<
"tau_yz[Pa] " <<
" \t"
1080 <<
"mu[Pa s] " <<
" \t"
1083 for (i = 0; i < nSurfacePts; ++i)
1085 outfile << scientific
1088 << surfaceX[i] <<
" \t "
1089 << surfaceY[i] <<
" \t "
1090 << surfaceZ[i] <<
" \t "
1091 << surfaceFieldsAdded[0][i] <<
" \t "
1092 << surfaceFieldsAdded[1][i] <<
" \t "
1093 << surfaceFieldsAdded[2][i] <<
" \t "
1094 << surfaceFieldsAdded[3][i] <<
" \t "
1095 << surfaceFieldsAdded[4][i] <<
" \t "
1096 << surfaceFieldsAdded[5][i] <<
" \t "
1097 << surfaceFieldsAdded[6][i] <<
" \t "
1098 << surfaceFieldsAdded[7][i] <<
" \t "
1099 << surfaceFieldsAdded[8][i] <<
" \t "
1100 << surfaceFields[0][i] <<
" \t "
1101 << surfaceFields[1][i] <<
" \t "
1102 << surfaceFields[2][i] <<
" \t "
1103 << surfaceFields[3][i] <<
" \t "
1104 << surfaceFields[4][i] <<
" \t "
1105 << surfaceFieldsAdded[9][i] <<
" \t "
1106 << surfaceFieldsAdded[10][i] <<
" \t "
1107 << surfaceFieldsAdded[11][i] <<
" \t "
1108 << surfaceFieldsAdded[12][i] <<
" \t "
1109 << surfaceFieldsAdded[13][i] <<
" \t "
1110 << surfaceFieldsAdded[14][i] <<
" \t "
1111 << surfaceFieldsAdded[15][i] <<
" \t "
1112 << surfaceFieldsAdded[16][i] <<
" \t "
1113 << surfaceFieldsAdded[17][i] <<
" \t "
1114 << surfaceFieldsAdded[18][i] <<
" \t "
1115 << surfaceFieldsAdded[19][i] <<
" \t "
1116 << surfaceFieldsAdded[20][i] <<
" \t "
1117 << surfaceFieldsAdded[21][i] <<
" \t "
1118 << surfaceFieldsAdded[22][i] <<
" \t "
1119 << surfaceFieldsAdded[23][i] <<
" \t "
1120 << surfaceFieldsAdded[24][i] <<
" \t "
1121 << surfaceFieldsAdded[25][i] <<
" \t "
1122 << surfaceFieldsAdded[26][i] <<
" \t "
1123 << surfaceFieldsAdded[27][i] <<
" \t "
1124 << surfaceFieldsAdded[28][i] <<
" \t "
1125 << surfaceFieldsAdded[29][i] <<
" \t "
1126 << surfaceFieldsAdded[30][i] <<
" \t "
1127 << surfaceFieldsAdded[31][i] <<
" \t "
1128 << surfaceFieldsAdded[32][i] <<
" \t "
1129 << surfaceFieldsAdded[33][i] <<
" \t "
1132 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
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.