63#include <boost/program_options.hpp>
68namespace po = boost::program_options;
70int main(
int argc,
char *argv[])
73 po::options_description desc(
"Available options");
74 desc.add_options()(
"help,h",
"Produce this help message.");
76 po::options_description hidden(
"Hidden options");
77 hidden.add_options()(
"input-file", po::value<vector<string>>(),
80 po::options_description cmdline_options;
81 cmdline_options.add(desc).add(hidden);
83 po::options_description visible(
"Allowed options");
86 po::positional_options_description
p;
87 p.add(
"input-file", -1);
93 po::store(po::command_line_parser(argc, argv)
94 .options(cmdline_options)
100 catch (
const std::exception &e)
102 cerr << e.what() << endl;
107 std::vector<std::string> filenames;
108 if (vm.count(
"input-file"))
110 filenames = vm[
"input-file"].as<std::vector<std::string>>();
113 if (vm.count(
"help") || vm.count(
"input-file") != 1)
115 cerr <<
"Description: Extracts a surface from a 2D .fld file created "
116 "by the CompressibleFlowSolver and places it into a .cfs file"
118 cerr <<
"Usage: ExtractSurface2DCFS [options] meshFile fieldFile"
125 LibUtilities::SessionReader::CreateInstance(argc, argv);
127 SpatialDomains::MeshGraphIO::Read(vSession);
129 fname = vSession->GetSessionName() +
".cfs";
132 std::string fieldFile;
133 for (
auto &file : filenames)
135 if (file.size() > 4 && (file.substr(file.size() - 4, 4) ==
".fld" ||
136 file.substr(file.size() - 4, 4) ==
".chk"))
149 int nBndEdgePts, nBndEdges, nBndRegions;
151 std::string m_ViscosityType;
163 int nDimensions = m_spacedim;
167 ASSERTL0(vSession->DefinesParameter(
"Gamma"),
168 "Compressible flow sessions must define a Gamma parameter.");
169 vSession->LoadParameter(
"Gamma", m_gamma, 1.4);
172 ASSERTL0(vSession->DefinesParameter(
"pInf"),
173 "Compressible flow sessions must define a pInf parameter.");
174 vSession->LoadParameter(
"pInf", m_pInf, 101325);
177 ASSERTL0(vSession->DefinesParameter(
"rhoInf"),
178 "Compressible flow sessions must define a rhoInf parameter.");
179 vSession->LoadParameter(
"rhoInf",
m_rhoInf, 1.225);
182 ASSERTL0(vSession->DefinesParameter(
"uInf"),
183 "Compressible flow sessions must define a uInf parameter.");
184 vSession->LoadParameter(
"uInf",
m_uInf, 0.1);
187 if (m_spacedim == 2 || m_spacedim == 3)
189 ASSERTL0(vSession->DefinesParameter(
"vInf"),
190 "Compressible flow sessions must define a vInf parameter"
191 "for 2D/3D problems.");
192 vSession->LoadParameter(
"vInf",
m_vInf, 0.0);
198 ASSERTL0(vSession->DefinesParameter(
"wInf"),
199 "Compressible flow sessions must define a wInf parameter"
201 vSession->LoadParameter(
"wInf", m_wInf, 0.0);
204 vSession->LoadParameter(
"GasConstant", m_gasConstant, 287.058);
205 vSession->LoadParameter(
"Twall",
m_Twall, 300.15);
206 vSession->LoadSolverInfo(
"ViscosityType", m_ViscosityType,
"Constant");
207 vSession->LoadParameter(
"mu",
m_mu, 1.78e-05);
211 vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
212 vector<vector<NekDouble>> fieldData;
220 vector<vector<LibUtilities::PointsType>> pointsType;
221 for (i = 0; i < fieldDef.size(); ++i)
223 vector<LibUtilities::PointsType> ptype;
224 for (j = 0; j < 2; ++j)
228 pointsType.push_back(ptype);
230 graphShPt->SetExpansionInfo(fieldDef, pointsType);
236 int nfields = vSession->GetVariables().size();
240 for (i = 0; i < pFields.size(); i++)
244 vSession, graphShPt, vSession->GetVariable(i));
248 for (
auto &fld : pFields)
250 if (fld->GetGraph()->GetMovement() !=
nullptr)
252 fld->GetGraph()->GetMovement()->PerformMovement(
253 std::stod(fieldMetaDataMap[
"Time"]));
255 fld->SetUpPhysNormals();
265 for (i = 1; i < nfields; ++i)
271 int nSolutionPts = pFields[0]->GetNpoints();
272 int nTracePts = pFields[0]->GetTrace()->GetTotPoints();
273 int nElements = pFields[0]->GetExpSize();
289 pFields[0]->GetCoords(x, y,
z);
291 pFields[0]->ExtractTracePhys(x, traceX);
292 pFields[0]->ExtractTracePhys(y, traceY);
293 pFields[0]->ExtractTracePhys(
z, traceZ);
303 for (j = 0; j < nfields; ++j)
309 for (i = 0; i < fieldData.size(); ++i)
311 Exp[j]->ExtractDataToCoeffs(fieldDef[i], fieldData[i],
312 fieldDef[i]->m_fields[j],
313 Exp[j]->UpdateCoeffs());
315 Exp[j]->BwdTrans(Exp[j]->GetCoeffs(), Exp[j]->UpdatePhys());
316 Vmath::Vcopy(nSolutionPts, Exp[j]->GetPhys(), 1, uFields[j], 1);
317 pFields[0]->ExtractTracePhys(uFields[j], traceFields[j]);
322 int nfieldsAdded = 20;
326 for (j = 0; j < nfieldsAdded; ++j)
340 for (i = 0; i < nDimensions; ++i)
344 pFields[0]->GetTrace()->GetNormals(m_traceNormals);
347 for (i = 0; i < nDimensions; ++i)
353 Vmath::Vcopy(nTracePts, &m_traceNormals[0][0], 1, &traceFieldsAdded[0][0],
357 Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &traceFieldsAdded[1][0],
361 Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &m_traceTangents[0][0],
363 Vmath::Neg(nTracePts, &m_traceTangents[0][0], 1);
365 Vmath::Vcopy(nTracePts, &m_traceTangents[0][0], 1, &traceFieldsAdded[2][0],
369 Vmath::Vcopy(nTracePts, &m_traceNormals[0][0], 1, &m_traceTangents[1][0],
372 Vmath::Vcopy(nTracePts, &m_traceTangents[1][0], 1, &traceFieldsAdded[3][0],
383 for (i = 0; i < m_spacedim; i++)
385 Vmath::Vmul(nSolutionPts, &uFields[i + 1][0], 1, &uFields[i + 1][0], 1,
388 Vmath::Smul(nSolutionPts, 0.5, &tmp[0], 1, &tmp[0], 1);
402 pFields[0]->ExtractTracePhys(
pressure, traceFieldsAdded[4]);
414 NekDouble GasConstantInv = 1.0 / m_gasConstant;
415 Vmath::Smul(nSolutionPts, GasConstantInv, &temperature[0], 1,
419 pFields[0]->ExtractTracePhys(temperature, traceFieldsAdded[5]);
428 for (i = 0; i < nDimensions; ++i)
434 for (i = 0; i < nDimensions; ++i)
436 for (n = 0; n < nElements; n++)
438 phys_offset = pFields[0]->GetPhys_Offset(n);
440 pFields[i]->GetExp(n)->PhysDeriv(i, temperature + phys_offset,
442 Dtemperature[i] + phys_offset);
445 pFields[0]->ExtractTracePhys(Dtemperature[i], traceDtemperature[i]);
448 for (i = 0; i < nDimensions; ++i)
451 &traceDtemperature[i][0], 1, &tmp[0], 1);
453 Vmath::Vadd(nTracePts, &traceFieldsAdded[6][0], 1, &tmp[0], 1,
454 &traceFieldsAdded[6][0], 1);
466 for (i = 0; i < nDimensions; ++i)
472 for (i = 0; i < nDimensions; ++i)
474 for (n = 0; n < nElements; n++)
476 phys_offset = pFields[0]->GetPhys_Offset(n);
478 pFields[i]->GetExp(n)->PhysDeriv(i,
pressure + phys_offset,
480 Dpressure[i] + phys_offset);
483 pFields[0]->ExtractTracePhys(Dpressure[i], traceDpressure[i]);
487 for (i = 0; i < nDimensions; ++i)
489 Vmath::Vmul(nTracePts, &m_traceTangents[i][0], 1, &traceDpressure[i][0],
492 Vmath::Vadd(nTracePts, &traceFieldsAdded[7][0], 1, &tmp[0], 1,
493 &traceFieldsAdded[7][0], 1);
497 Vmath::Vcopy(nTracePts, &traceDpressure[0][0], 1, &traceFieldsAdded[8][0],
501 Vmath::Vcopy(nTracePts, &traceDpressure[1][0], 1, &traceFieldsAdded[9][0],
515 for (i = 0; i < nDimensions; ++i)
521 Vmath::Vdiv(nSolutionPts, uFields[i + 1], 1, uFields[0], 1, velocity[i],
524 for (j = 0; j < nDimensions; ++j)
531 for (i = 0; i < nDimensions; ++i)
533 for (j = 0; j < nDimensions; ++j)
535 for (n = 0; n < nElements; n++)
537 phys_offset = pFields[0]->GetPhys_Offset(n);
539 pFields[i]->GetExp(n)->PhysDeriv(j, velocity[i] + phys_offset,
540 auxArray = Dvelocity[i][j] +
545 pFields[0]->ExtractTracePhys(Dvelocity[i][j], traceDvelocity[i][j]);
550 &traceFieldsAdded[10][0], 1);
552 &traceFieldsAdded[11][0], 1);
554 &traceFieldsAdded[12][0], 1);
556 &traceFieldsAdded[13][0], 1);
573 if (m_ViscosityType ==
"Variable")
579 for (
int i = 0; i < nSolutionPts; ++i)
581 ratio = temperature[i] / T_star;
582 mu[i] = mu_star * ratio *
sqrt(ratio) * (T_star + 110.0) /
583 (temperature[i] + 110.0);
596 Vmath::Smul(nSolutionPts, 2.0, &mu[0], 1, &mu2[0], 1);
599 Vmath::Vadd(nSolutionPts, &divVel[0], 1, &Dvelocity[0][0][0], 1, &divVel[0],
601 Vmath::Vadd(nSolutionPts, &divVel[0], 1, &Dvelocity[1][1][0], 1, &divVel[0],
605 Vmath::Smul(nSolutionPts, lambda, &divVel[0], 1, &divVel[0], 1);
606 Vmath::Vmul(nSolutionPts, &mu[0], 1, &divVel[0], 1, &divVel[0], 1);
610 for (j = 0; j < m_spacedim; ++j)
615 Vmath::Vmul(nSolutionPts, &mu2[0], 1, &Dvelocity[j][j][0], 1,
618 Vmath::Vadd(nSolutionPts, &temp[j][0], 1, &divVel[0], 1, &Sgg[j][0], 1);
625 Vmath::Vadd(nSolutionPts, &Dvelocity[0][1][0], 1, &Dvelocity[1][0][0], 1,
629 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Sxy[0], 1, &Sxy[0], 1);
631 pFields[0]->ExtractTracePhys(Sgg[0], traceFieldsAdded[14]);
632 pFields[0]->ExtractTracePhys(Sgg[1], traceFieldsAdded[15]);
633 pFields[0]->ExtractTracePhys(Sxy, traceFieldsAdded[16]);
648 Vmath::Vcopy(nTracePts, &m_traceNormals[0][0], 1, &cosTeta[0], 1);
651 Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &sinTeta[0], 1);
654 Vmath::Vsub(nTracePts, &traceFieldsAdded[14][0], 1,
655 &traceFieldsAdded[15][0], 1, &sigma_diff[0], 1);
658 Vmath::Vmul(nTracePts, &cosTeta[0], 1, &sinTeta[0], 1, &tmpTeta[0], 1);
659 Vmath::Smul(nTracePts, 2.0, &tmpTeta[0], 1, &sin2Teta[0], 1);
662 Vmath::Vmul(nTracePts, &cosTeta[0], 1, &cosTeta[0], 1, &cos2Teta[0], 1);
663 Vmath::Vmul(nTracePts, &sinTeta[0], 1, &sinTeta[0], 1, &tmpTeta[0], 1);
664 Vmath::Vsub(nTracePts, &cos2Teta[0], 1, &tmpTeta[0], 1, &cos2Teta[0], 1);
667 Vmath::Smul(nTracePts, -0.5, &sigma_diff[0], 1, &sigma_diff[0], 1);
668 Vmath::Vmul(nTracePts, &sigma_diff[0], 1, &sin2Teta[0], 1, &tau_t[0], 1);
669 Vmath::Vmul(nTracePts, &traceFieldsAdded[16][0], 1, &cos2Teta[0], 1,
671 Vmath::Vadd(nTracePts, &tau_t[0], 1, &tmpTeta[0], 1, &tau_t[0], 1);
673 Vmath::Vcopy(nTracePts, &tau_t[0], 1, &traceFieldsAdded[17][0], 1);
679 pFields[0]->ExtractTracePhys(mu, traceFieldsAdded[18]);
690 Vmath::Smul(nSolutionPts, gamma, soundspeed, 1, soundspeed, 1);
691 Vmath::Vsqrt(nSolutionPts, soundspeed, 1, soundspeed, 1);
696 for (
int i = 0; i < m_spacedim; ++i)
698 Vmath::Vvtvp(nSolutionPts, uFields[i + 1], 1, uFields[i + 1], 1, mach,
702 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
703 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
705 Vmath::Vdiv(nSolutionPts, mach, 1, soundspeed, 1, mach, 1);
707 pFields[0]->ExtractTracePhys(mach, traceFieldsAdded[19]);
712 if (pFields[0]->GetBndCondExpansions().size())
716 nBndRegions = pFields[0]->GetBndCondExpansions().size();
717 for (b = 0; b < nBndRegions; ++b)
719 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
720 for (e = 0; e < nBndEdges; ++e)
722 nBndEdgePts = pFields[0]
723 ->GetBndCondExpansions()[b]
727 id2 = pFields[0]->GetTrace()->GetPhys_Offset(
728 pFields[0]->GetTraceMap()->GetBndCondIDToGlobalTraceID(
731 if (pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
733 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
735 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
738 Vmath::Vcopy(nBndEdgePts, &traceX[id2], 1, &surfaceX[id1],
741 Vmath::Vcopy(nBndEdgePts, &traceY[id2], 1, &surfaceY[id1],
744 Vmath::Vcopy(nBndEdgePts, &traceZ[id2], 1, &surfaceZ[id1],
754 if (pFields[0]->GetBndCondExpansions().size())
756 for (j = 0; j < nfields; ++j)
760 nBndRegions = pFields[j]->GetBndCondExpansions().size();
761 for (b = 0; b < nBndRegions; ++b)
763 nBndEdges = pFields[j]->GetBndCondExpansions()[b]->GetExpSize();
764 for (e = 0; e < nBndEdges; ++e)
766 nBndEdgePts = pFields[j]
767 ->GetBndCondExpansions()[b]
771 id2 = pFields[j]->GetTrace()->GetPhys_Offset(
772 pFields[j]->GetTraceMap()->GetBndCondIDToGlobalTraceID(
775 if (pFields[j]->GetBndConditions()[b]->GetUserDefined() ==
777 pFields[j]->GetBndConditions()[b]->GetUserDefined() ==
779 pFields[j]->GetBndConditions()[b]->GetUserDefined() ==
783 &surfaceFields[j][id1], 1);
793 if (pFields[0]->GetBndCondExpansions().size())
795 for (j = 0; j < nfieldsAdded; ++j)
799 nBndRegions = pFields[0]->GetBndCondExpansions().size();
800 for (b = 0; b < nBndRegions; ++b)
802 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
803 for (e = 0; e < nBndEdges; ++e)
805 nBndEdgePts = pFields[0]
806 ->GetBndCondExpansions()[b]
810 id2 = pFields[0]->GetTrace()->GetPhys_Offset(
811 pFields[0]->GetTraceMap()->GetBndCondIDToGlobalTraceID(
814 if (pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
816 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
818 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
822 &surfaceFieldsAdded[j][id1], 1);
833 std::string vEquation = vSession->GetSolverInfo(
"EQType");
836 BndExp = pFields[0]->GetBndCondExpansions();
847 for (
int i = 0; i < BndExp[0]->GetExpSize(); ++i)
870 for (
int j = 0; j < nbc; ++j)
873 nxOnBnd[j] = surfaceFieldsAdded[0][GlobalIndex];
874 nyOnBnd[j] = surfaceFieldsAdded[1][GlobalIndex];
875 txOnBnd[j] = surfaceFieldsAdded[2][GlobalIndex];
876 tyOnBnd[j] = surfaceFieldsAdded[3][GlobalIndex];
878 PressurOnBnd[j] = surfaceFieldsAdded[4][GlobalIndex];
880 if (vEquation ==
"NavierStokesCFE")
882 ShearStressOnBnd[j] = surfaceFieldsAdded[17][GlobalIndex];
902 Vmath::Vmul(nbc, PressurOnBnd, 1, nxOnBnd, 1, drag_p, 1);
903 Vmath::Vmul(nbc, PressurOnBnd, 1, nyOnBnd, 1, lift_p, 1);
908 Fxp += bc->Integral(drag_p);
909 Fyp += bc->Integral(lift_p);
911 if (vEquation ==
"NavierStokesCFE")
913 Vmath::Vmul(nbc, ShearStressOnBnd, 1, txOnBnd, 1, drag_v, 1);
914 Vmath::Vmul(nbc, ShearStressOnBnd, 1, tyOnBnd, 1, lift_v, 1);
919 Fxv += bc->Integral(drag_v);
920 Fyv += bc->Integral(lift_v);
923 Sref += bc->Integral(Unity);
926 cout <<
"\n Sref = " << Sref << endl;
931 cout <<
" Pressure drag (Fxp) = " << Fxp << endl;
932 cout <<
" Pressure lift (Fyp) = " << Fyp << endl;
933 cout <<
" Viscous drag (Fxv) = " << Fxv << endl;
934 cout <<
" Viscous lift (Fyv) = " << Fyv << endl;
935 cout <<
"\n ==> Total drag = " << Fxp + Fxv << endl;
936 cout <<
" ==> Total lift = " << Fyp + Fyv <<
"\n" << endl;
944 outfile.open(fname.c_str());
961 <<
"rhou[kg/(m^2 s)] "
963 <<
"rhov[kg/(m^2 s)] "
1001 for (i = 0; i < id1; ++i)
1003 outfile << scientific << setw(17) << setprecision(16) << surfaceX[i]
1004 <<
" \t " << surfaceY[i] <<
" \t " << surfaceZ[i] <<
" \t "
1005 << surfaceFieldsAdded[0][i] <<
" \t "
1006 << surfaceFieldsAdded[1][i] <<
" \t "
1007 << surfaceFieldsAdded[2][i] <<
" \t "
1008 << surfaceFieldsAdded[3][i] <<
" \t " << surfaceFields[0][i]
1009 <<
" \t " << surfaceFields[1][i] <<
" \t "
1010 << surfaceFields[2][i] <<
" \t " << surfaceFields[3][i]
1011 <<
" \t " << surfaceFieldsAdded[4][i] <<
" \t "
1012 << surfaceFieldsAdded[5][i] <<
" \t "
1013 << surfaceFieldsAdded[6][i] <<
" \t "
1014 << surfaceFieldsAdded[7][i] <<
" \t "
1015 << surfaceFieldsAdded[8][i] <<
" \t "
1016 << surfaceFieldsAdded[9][i] <<
" \t "
1017 << surfaceFieldsAdded[10][i] <<
" \t "
1018 << surfaceFieldsAdded[11][i] <<
" \t "
1019 << surfaceFieldsAdded[12][i] <<
" \t "
1020 << surfaceFieldsAdded[13][i] <<
" \t "
1021 << surfaceFieldsAdded[14][i] <<
" \t "
1022 << surfaceFieldsAdded[15][i] <<
" \t "
1023 << surfaceFieldsAdded[16][i] <<
" \t "
1024 << surfaceFieldsAdded[17][i] <<
" \t "
1025 << surfaceFieldsAdded[18][i] <<
" \t "
1026 << surfaceFieldsAdded[19][i]
1031 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::map< std::string, std::string > FieldMetaDataMap
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
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 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)