66#include <boost/program_options.hpp>
71namespace po = boost::program_options;
73int main(
int argc,
char *argv[])
76 po::options_description desc(
"Available options");
77 desc.add_options()(
"help,h",
"Produce this help message.");
79 po::options_description hidden(
"Hidden options");
80 hidden.add_options()(
"input-file", po::value<vector<string>>(),
83 po::options_description cmdline_options;
84 cmdline_options.add(desc).add(hidden);
86 po::options_description visible(
"Allowed options");
89 po::positional_options_description
p;
90 p.add(
"input-file", -1);
96 po::store(po::command_line_parser(argc, argv)
97 .options(cmdline_options)
103 catch (
const std::exception &e)
105 cerr << e.what() << endl;
110 std::vector<std::string> filenames;
111 if (vm.count(
"input-file"))
113 filenames = vm[
"input-file"].as<std::vector<std::string>>();
116 if (vm.count(
"help") || vm.count(
"input-file") != 1)
118 cerr <<
"Description: Extracts a surface from a 2D .fld file created "
119 "by the CompressibleFlowSolver and places it into a .cfs file"
121 cerr <<
"Usage: ExtractSurface2DCFS [options] meshFile fieldFile"
128 LibUtilities::SessionReader::CreateInstance(argc, argv);
130 SpatialDomains::MeshGraph::Read(vSession);
132 fname = vSession->GetSessionName() +
".cfs";
135 std::string fieldFile;
136 for (
auto &file : filenames)
138 if (file.size() > 4 && (file.substr(file.size() - 4, 4) ==
".fld" ||
139 file.substr(file.size() - 4, 4) ==
".chk"))
152 int nBndEdgePts, nBndEdges, nBndRegions;
154 std::string m_ViscosityType;
166 int nDimensions = m_spacedim;
170 ASSERTL0(vSession->DefinesParameter(
"Gamma"),
171 "Compressible flow sessions must define a Gamma parameter.");
172 vSession->LoadParameter(
"Gamma", m_gamma, 1.4);
175 ASSERTL0(vSession->DefinesParameter(
"pInf"),
176 "Compressible flow sessions must define a pInf parameter.");
177 vSession->LoadParameter(
"pInf", m_pInf, 101325);
180 ASSERTL0(vSession->DefinesParameter(
"rhoInf"),
181 "Compressible flow sessions must define a rhoInf parameter.");
182 vSession->LoadParameter(
"rhoInf",
m_rhoInf, 1.225);
185 ASSERTL0(vSession->DefinesParameter(
"uInf"),
186 "Compressible flow sessions must define a uInf parameter.");
187 vSession->LoadParameter(
"uInf",
m_uInf, 0.1);
190 if (m_spacedim == 2 || m_spacedim == 3)
192 ASSERTL0(vSession->DefinesParameter(
"vInf"),
193 "Compressible flow sessions must define a vInf parameter"
194 "for 2D/3D problems.");
195 vSession->LoadParameter(
"vInf",
m_vInf, 0.0);
201 ASSERTL0(vSession->DefinesParameter(
"wInf"),
202 "Compressible flow sessions must define a wInf parameter"
204 vSession->LoadParameter(
"wInf", m_wInf, 0.0);
207 vSession->LoadParameter(
"GasConstant", m_gasConstant, 287.058);
208 vSession->LoadParameter(
"Twall",
m_Twall, 300.15);
209 vSession->LoadSolverInfo(
"ViscosityType", m_ViscosityType,
"Constant");
210 vSession->LoadParameter(
"mu",
m_mu, 1.78e-05);
214 vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
215 vector<vector<NekDouble>> fieldData;
223 vector<vector<LibUtilities::PointsType>> pointsType;
224 for (i = 0; i < fieldDef.size(); ++i)
226 vector<LibUtilities::PointsType> ptype;
227 for (j = 0; j < 2; ++j)
231 pointsType.push_back(ptype);
233 graphShPt->SetExpansionInfo(fieldDef, pointsType);
239 int nfields = vSession->GetVariables().size();
243 for (i = 0; i < pFields.size(); i++)
247 vSession, graphShPt, vSession->GetVariable(i));
256 for (i = 1; i < nfields; ++i)
262 int nSolutionPts = pFields[0]->GetNpoints();
263 int nTracePts = pFields[0]->GetTrace()->GetTotPoints();
264 int nElements = pFields[0]->GetExpSize();
280 pFields[0]->GetCoords(x, y,
z);
282 pFields[0]->ExtractTracePhys(x, traceX);
283 pFields[0]->ExtractTracePhys(y, traceY);
284 pFields[0]->ExtractTracePhys(
z, traceZ);
294 for (j = 0; j < nfields; ++j)
300 for (i = 0; i < fieldData.size(); ++i)
302 Exp[j]->ExtractDataToCoeffs(fieldDef[i], fieldData[i],
303 fieldDef[i]->m_fields[j],
304 Exp[j]->UpdateCoeffs());
306 Exp[j]->BwdTrans(Exp[j]->GetCoeffs(), Exp[j]->UpdatePhys());
307 Vmath::Vcopy(nSolutionPts, Exp[j]->GetPhys(), 1, uFields[j], 1);
308 pFields[0]->ExtractTracePhys(uFields[j], traceFields[j]);
313 int nfieldsAdded = 20;
317 for (j = 0; j < nfieldsAdded; ++j)
331 for (i = 0; i < nDimensions; ++i)
335 pFields[0]->GetTrace()->GetNormals(m_traceNormals);
338 for (i = 0; i < nDimensions; ++i)
344 Vmath::Vcopy(nTracePts, &m_traceNormals[0][0], 1, &traceFieldsAdded[0][0],
348 Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &traceFieldsAdded[1][0],
352 Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &m_traceTangents[0][0],
354 Vmath::Neg(nTracePts, &m_traceTangents[0][0], 1);
356 Vmath::Vcopy(nTracePts, &m_traceTangents[0][0], 1, &traceFieldsAdded[2][0],
360 Vmath::Vcopy(nTracePts, &m_traceNormals[0][0], 1, &m_traceTangents[1][0],
363 Vmath::Vcopy(nTracePts, &m_traceTangents[1][0], 1, &traceFieldsAdded[3][0],
374 for (i = 0; i < m_spacedim; i++)
376 Vmath::Vmul(nSolutionPts, &uFields[i + 1][0], 1, &uFields[i + 1][0], 1,
379 Vmath::Smul(nSolutionPts, 0.5, &tmp[0], 1, &tmp[0], 1);
393 pFields[0]->ExtractTracePhys(
pressure, traceFieldsAdded[4]);
405 NekDouble GasConstantInv = 1.0 / m_gasConstant;
406 Vmath::Smul(nSolutionPts, GasConstantInv, &temperature[0], 1,
410 pFields[0]->ExtractTracePhys(temperature, traceFieldsAdded[5]);
419 for (i = 0; i < nDimensions; ++i)
425 for (i = 0; i < nDimensions; ++i)
427 for (n = 0; n < nElements; n++)
429 phys_offset = pFields[0]->GetPhys_Offset(n);
431 pFields[i]->GetExp(n)->PhysDeriv(i, temperature + phys_offset,
433 Dtemperature[i] + phys_offset);
436 pFields[0]->ExtractTracePhys(Dtemperature[i], traceDtemperature[i]);
439 for (i = 0; i < nDimensions; ++i)
442 &traceDtemperature[i][0], 1, &tmp[0], 1);
444 Vmath::Vadd(nTracePts, &traceFieldsAdded[6][0], 1, &tmp[0], 1,
445 &traceFieldsAdded[6][0], 1);
457 for (i = 0; i < nDimensions; ++i)
463 for (i = 0; i < nDimensions; ++i)
465 for (n = 0; n < nElements; n++)
467 phys_offset = pFields[0]->GetPhys_Offset(n);
469 pFields[i]->GetExp(n)->PhysDeriv(i,
pressure + phys_offset,
471 Dpressure[i] + phys_offset);
474 pFields[0]->ExtractTracePhys(Dpressure[i], traceDpressure[i]);
478 for (i = 0; i < nDimensions; ++i)
480 Vmath::Vmul(nTracePts, &m_traceTangents[i][0], 1, &traceDpressure[i][0],
483 Vmath::Vadd(nTracePts, &traceFieldsAdded[7][0], 1, &tmp[0], 1,
484 &traceFieldsAdded[7][0], 1);
488 Vmath::Vcopy(nTracePts, &traceDpressure[0][0], 1, &traceFieldsAdded[8][0],
492 Vmath::Vcopy(nTracePts, &traceDpressure[1][0], 1, &traceFieldsAdded[9][0],
506 for (i = 0; i < nDimensions; ++i)
512 Vmath::Vdiv(nSolutionPts, uFields[i + 1], 1, uFields[0], 1, velocity[i],
515 for (j = 0; j < nDimensions; ++j)
522 for (i = 0; i < nDimensions; ++i)
524 for (j = 0; j < nDimensions; ++j)
526 for (n = 0; n < nElements; n++)
528 phys_offset = pFields[0]->GetPhys_Offset(n);
530 pFields[i]->GetExp(n)->PhysDeriv(j, velocity[i] + phys_offset,
531 auxArray = Dvelocity[i][j] +
536 pFields[0]->ExtractTracePhys(Dvelocity[i][j], traceDvelocity[i][j]);
541 &traceFieldsAdded[10][0], 1);
543 &traceFieldsAdded[11][0], 1);
545 &traceFieldsAdded[12][0], 1);
547 &traceFieldsAdded[13][0], 1);
564 if (m_ViscosityType ==
"Variable")
570 for (
int i = 0; i < nSolutionPts; ++i)
572 ratio = temperature[i] / T_star;
573 mu[i] = mu_star * ratio *
sqrt(ratio) * (T_star + 110.0) /
574 (temperature[i] + 110.0);
587 Vmath::Smul(nSolutionPts, 2.0, &mu[0], 1, &mu2[0], 1);
590 Vmath::Vadd(nSolutionPts, &divVel[0], 1, &Dvelocity[0][0][0], 1, &divVel[0],
592 Vmath::Vadd(nSolutionPts, &divVel[0], 1, &Dvelocity[1][1][0], 1, &divVel[0],
596 Vmath::Smul(nSolutionPts, lambda, &divVel[0], 1, &divVel[0], 1);
597 Vmath::Vmul(nSolutionPts, &mu[0], 1, &divVel[0], 1, &divVel[0], 1);
601 for (j = 0; j < m_spacedim; ++j)
606 Vmath::Vmul(nSolutionPts, &mu2[0], 1, &Dvelocity[j][j][0], 1,
609 Vmath::Vadd(nSolutionPts, &temp[j][0], 1, &divVel[0], 1, &Sgg[j][0], 1);
616 Vmath::Vadd(nSolutionPts, &Dvelocity[0][1][0], 1, &Dvelocity[1][0][0], 1,
620 Vmath::Vmul(nSolutionPts, &mu[0], 1, &Sxy[0], 1, &Sxy[0], 1);
622 pFields[0]->ExtractTracePhys(Sgg[0], traceFieldsAdded[14]);
623 pFields[0]->ExtractTracePhys(Sgg[1], traceFieldsAdded[15]);
624 pFields[0]->ExtractTracePhys(Sxy, traceFieldsAdded[16]);
639 Vmath::Vcopy(nTracePts, &m_traceNormals[0][0], 1, &cosTeta[0], 1);
642 Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &sinTeta[0], 1);
645 Vmath::Vsub(nTracePts, &traceFieldsAdded[14][0], 1,
646 &traceFieldsAdded[15][0], 1, &sigma_diff[0], 1);
649 Vmath::Vmul(nTracePts, &cosTeta[0], 1, &sinTeta[0], 1, &tmpTeta[0], 1);
650 Vmath::Smul(nTracePts, 2.0, &tmpTeta[0], 1, &sin2Teta[0], 1);
653 Vmath::Vmul(nTracePts, &cosTeta[0], 1, &cosTeta[0], 1, &cos2Teta[0], 1);
654 Vmath::Vmul(nTracePts, &sinTeta[0], 1, &sinTeta[0], 1, &tmpTeta[0], 1);
655 Vmath::Vsub(nTracePts, &cos2Teta[0], 1, &tmpTeta[0], 1, &cos2Teta[0], 1);
658 Vmath::Smul(nTracePts, -0.5, &sigma_diff[0], 1, &sigma_diff[0], 1);
659 Vmath::Vmul(nTracePts, &sigma_diff[0], 1, &sin2Teta[0], 1, &tau_t[0], 1);
660 Vmath::Vmul(nTracePts, &traceFieldsAdded[16][0], 1, &cos2Teta[0], 1,
662 Vmath::Vadd(nTracePts, &tau_t[0], 1, &tmpTeta[0], 1, &tau_t[0], 1);
664 Vmath::Vcopy(nTracePts, &tau_t[0], 1, &traceFieldsAdded[17][0], 1);
670 pFields[0]->ExtractTracePhys(mu, traceFieldsAdded[18]);
681 Vmath::Smul(nSolutionPts, gamma, soundspeed, 1, soundspeed, 1);
682 Vmath::Vsqrt(nSolutionPts, soundspeed, 1, soundspeed, 1);
687 for (
int i = 0; i < m_spacedim; ++i)
689 Vmath::Vvtvp(nSolutionPts, uFields[i + 1], 1, uFields[i + 1], 1, mach,
693 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
694 Vmath::Vdiv(nSolutionPts, mach, 1, uFields[0], 1, mach, 1);
696 Vmath::Vdiv(nSolutionPts, mach, 1, soundspeed, 1, mach, 1);
698 pFields[0]->ExtractTracePhys(mach, traceFieldsAdded[19]);
703 if (pFields[0]->GetBndCondExpansions().size())
707 nBndRegions = pFields[0]->GetBndCondExpansions().size();
708 for (b = 0; b < nBndRegions; ++b)
710 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
711 for (e = 0; e < nBndEdges; ++e)
713 nBndEdgePts = pFields[0]
714 ->GetBndCondExpansions()[b]
718 id2 = pFields[0]->GetTrace()->GetPhys_Offset(
719 pFields[0]->GetTraceMap()->GetBndCondIDToGlobalTraceID(
722 if (pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
724 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
726 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
729 Vmath::Vcopy(nBndEdgePts, &traceX[id2], 1, &surfaceX[id1],
732 Vmath::Vcopy(nBndEdgePts, &traceY[id2], 1, &surfaceY[id1],
735 Vmath::Vcopy(nBndEdgePts, &traceZ[id2], 1, &surfaceZ[id1],
745 if (pFields[0]->GetBndCondExpansions().size())
747 for (j = 0; j < nfields; ++j)
751 nBndRegions = pFields[j]->GetBndCondExpansions().size();
752 for (b = 0; b < nBndRegions; ++b)
754 nBndEdges = pFields[j]->GetBndCondExpansions()[b]->GetExpSize();
755 for (e = 0; e < nBndEdges; ++e)
757 nBndEdgePts = pFields[j]
758 ->GetBndCondExpansions()[b]
762 id2 = pFields[j]->GetTrace()->GetPhys_Offset(
763 pFields[j]->GetTraceMap()->GetBndCondIDToGlobalTraceID(
766 if (pFields[j]->GetBndConditions()[b]->GetUserDefined() ==
768 pFields[j]->GetBndConditions()[b]->GetUserDefined() ==
770 pFields[j]->GetBndConditions()[b]->GetUserDefined() ==
774 &surfaceFields[j][id1], 1);
784 if (pFields[0]->GetBndCondExpansions().size())
786 for (j = 0; j < nfieldsAdded; ++j)
790 nBndRegions = pFields[0]->GetBndCondExpansions().size();
791 for (b = 0; b < nBndRegions; ++b)
793 nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
794 for (e = 0; e < nBndEdges; ++e)
796 nBndEdgePts = pFields[0]
797 ->GetBndCondExpansions()[b]
801 id2 = pFields[0]->GetTrace()->GetPhys_Offset(
802 pFields[0]->GetTraceMap()->GetBndCondIDToGlobalTraceID(
805 if (pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
807 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
809 pFields[0]->GetBndConditions()[b]->GetUserDefined() ==
813 &surfaceFieldsAdded[j][id1], 1);
824 std::string vEquation = vSession->GetSolverInfo(
"EQType");
827 BndExp = pFields[0]->GetBndCondExpansions();
838 for (
int i = 0; i < BndExp[0]->GetExpSize(); ++i)
861 for (
int j = 0; j < nbc; ++j)
864 nxOnBnd[j] = surfaceFieldsAdded[0][GlobalIndex];
865 nyOnBnd[j] = surfaceFieldsAdded[1][GlobalIndex];
866 txOnBnd[j] = surfaceFieldsAdded[2][GlobalIndex];
867 tyOnBnd[j] = surfaceFieldsAdded[3][GlobalIndex];
869 PressurOnBnd[j] = surfaceFieldsAdded[4][GlobalIndex];
871 if (vEquation ==
"NavierStokesCFE")
873 ShearStressOnBnd[j] = surfaceFieldsAdded[17][GlobalIndex];
893 Vmath::Vmul(nbc, PressurOnBnd, 1, nxOnBnd, 1, drag_p, 1);
894 Vmath::Vmul(nbc, PressurOnBnd, 1, nyOnBnd, 1, lift_p, 1);
899 Fxp += bc->Integral(drag_p);
900 Fyp += bc->Integral(lift_p);
902 if (vEquation ==
"NavierStokesCFE")
904 Vmath::Vmul(nbc, ShearStressOnBnd, 1, txOnBnd, 1, drag_v, 1);
905 Vmath::Vmul(nbc, ShearStressOnBnd, 1, tyOnBnd, 1, lift_v, 1);
910 Fxv += bc->Integral(drag_v);
911 Fyv += bc->Integral(lift_v);
914 Sref += bc->Integral(Unity);
917 cout <<
"\n Sref = " << Sref << endl;
922 cout <<
" Pressure drag (Fxp) = " << Fxp << endl;
923 cout <<
" Pressure lift (Fyp) = " << Fyp << endl;
924 cout <<
" Viscous drag (Fxv) = " << Fxv << endl;
925 cout <<
" Viscous lift (Fyv) = " << Fyv << endl;
926 cout <<
"\n ==> Total drag = " << Fxp + Fxv << endl;
927 cout <<
" ==> Total lift = " << Fyp + Fyv <<
"\n" << endl;
935 outfile.open(fname.c_str());
952 <<
"rhou[kg/(m^2 s)] "
954 <<
"rhov[kg/(m^2 s)] "
992 for (i = 0; i < id1; ++i)
994 outfile << scientific << setw(17) << setprecision(16) << surfaceX[i]
995 <<
" \t " << surfaceY[i] <<
" \t " << surfaceZ[i] <<
" \t "
996 << surfaceFieldsAdded[0][i] <<
" \t "
997 << surfaceFieldsAdded[1][i] <<
" \t "
998 << surfaceFieldsAdded[2][i] <<
" \t "
999 << surfaceFieldsAdded[3][i] <<
" \t " << surfaceFields[0][i]
1000 <<
" \t " << surfaceFields[1][i] <<
" \t "
1001 << surfaceFields[2][i] <<
" \t " << surfaceFields[3][i]
1002 <<
" \t " << surfaceFieldsAdded[4][i] <<
" \t "
1003 << surfaceFieldsAdded[5][i] <<
" \t "
1004 << surfaceFieldsAdded[6][i] <<
" \t "
1005 << surfaceFieldsAdded[7][i] <<
" \t "
1006 << surfaceFieldsAdded[8][i] <<
" \t "
1007 << surfaceFieldsAdded[9][i] <<
" \t "
1008 << surfaceFieldsAdded[10][i] <<
" \t "
1009 << surfaceFieldsAdded[11][i] <<
" \t "
1010 << surfaceFieldsAdded[12][i] <<
" \t "
1011 << surfaceFieldsAdded[13][i] <<
" \t "
1012 << surfaceFieldsAdded[14][i] <<
" \t "
1013 << surfaceFieldsAdded[15][i] <<
" \t "
1014 << surfaceFieldsAdded[16][i] <<
" \t "
1015 << surfaceFieldsAdded[17][i] <<
" \t "
1016 << surfaceFieldsAdded[18][i] <<
" \t "
1017 << surfaceFieldsAdded[19][i]
1022 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)
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 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)