Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update LUT routine #1792

Merged
merged 18 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Common/include/containers/CFileReaderLUT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ class CFileReaderLUT {

std::vector<unsigned long> hull;

std::string SkipToFlag(std::ifstream* file_stream, const std::string& flag);
void SkipToFlag(std::ifstream& file_stream, const std::string& current_line, const std::string& flag) const;

bool GetNextNonEmptyLine(std::ifstream& file_stream, std::string& line) const;

bool GetStrippedLine(std::ifstream& file_stream, std::string& line) const;

public:
CFileReaderLUT(){};
Expand Down
4 changes: 2 additions & 2 deletions Common/src/CConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ void CConfig::SetConfig_Options() {
/*!\brief KIND_TRANS_MODEL \n DESCRIPTION: Specify transition model OPTIONS: see \link Trans_Model_Map \endlink \n DEFAULT: NONE \ingroup Config*/
addEnumOption("KIND_TRANS_MODEL", Kind_Trans_Model, Trans_Model_Map, TURB_TRANS_MODEL::NONE);

/*!\brief KIND_SPECIES_MODEL \n DESCRIPTION: Specify scalar transport model \n Options: see \link Scalar_Model_Map \endlink \n DEFAULT: NONE \ingroup Config*/
/*!\brief KIND_SCALAR_MODEL \n DESCRIPTION: Specify scalar transport model \n Options: see \link Scalar_Model_Map \endlink \n DEFAULT: NONE \ingroup Config*/
addEnumOption("KIND_SCALAR_MODEL", Kind_Species_Model, Species_Model_Map, SPECIES_MODEL::NONE);

/*!\brief KIND_SGS_MODEL \n DESCRIPTION: Specify subgrid scale model OPTIONS: see \link SGS_Model_Map \endlink \n DEFAULT: NONE \ingroup Config*/
Expand Down Expand Up @@ -5339,7 +5339,7 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
}

/*--- Checks for additional species transport. ---*/
if (Kind_Species_Model != SPECIES_MODEL::NONE) {
if (Kind_Species_Model == SPECIES_MODEL::SPECIES_TRANSPORT) {
if (Kind_Solver != MAIN_SOLVER::INC_NAVIER_STOKES &&
Kind_Solver != MAIN_SOLVER::INC_RANS &&
Kind_Solver != MAIN_SOLVER::DISC_ADJ_INC_NAVIER_STOKES &&
Expand Down
202 changes: 122 additions & 80 deletions Common/src/containers/CFileReaderLUT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@

using namespace std;

void CFileReaderLUT::ReadRawDRG(const string& file_name) {
version_reader = "1.0.0";
void CFileReaderLUT::ReadRawLUT(const string& file_name) {
version_reader = "1.0.1";

/*--- Store MPI rank. ---*/
rank = SU2_MPI::GetRank();
Expand All @@ -46,8 +46,6 @@ void CFileReaderLUT::ReadRawDRG(const string& file_name) {

ifstream file_stream;

int ixColon;

bool eoHeader = false;
bool eoData = false;
bool eoConnectivity = false;
Expand All @@ -59,106 +57,104 @@ void CFileReaderLUT::ReadRawDRG(const string& file_name) {
SU2_MPI::Error(string("There is no look-up-table file called ") + file_name, CURRENT_FUNCTION);
}

/* Read header */
line = SkipToFlag(&file_stream, "<header>");
/*--- Read header ---*/
SkipToFlag(file_stream, line, "<Header>");

while (GetNextNonEmptyLine(file_stream, line) && !eoHeader) {

while (getline(file_stream, line) && !eoHeader) {
/* number of points in LUT */
if (line.compare("[version]") == 0) {
getline(file_stream, line);
/*--- number of points in LUT ---*/
if (line.compare("[Version]") == 0) {
GetNextNonEmptyLine(file_stream, line);
version_lut = line;
}

/* number of points in LUT */
if (line.compare("[number of points]") == 0) {
getline(file_stream, line);
/*--- number of points in LUT ---*/
if (line.compare("[Number of points]") == 0) {
GetNextNonEmptyLine(file_stream, line);
n_points = stoi(line);
}

/* number of triangles in LUT */
if (line.compare("[number of triangles]") == 0) {
getline(file_stream, line);
/*--- number of triangles in LUT ---*/
if (line.compare("[Number of triangles]") == 0) {
GetNextNonEmptyLine(file_stream, line);
n_triangles = stoi(line);
}

/* number of points on the hull */
if (line.compare("[number of hull points]") == 0) {
getline(file_stream, line);
/*--- number of points on the hull ---*/
if (line.compare("[Number of hull points]") == 0) {
GetNextNonEmptyLine(file_stream, line);
n_hull_points = stoi(line);
}

/* number of variables in LUT */
if (line.compare("[number of variables]") == 0) {
getline(file_stream, line);
/*--- number of variables in LUT ---*/
if (line.compare("[Number of variables]") == 0) {
GetNextNonEmptyLine(file_stream, line);
n_variables = stoi(line);
}

/* variable names */
if (line.compare("[variable names]") == 0) {
getline(file_stream, line);
stream_names_var.str(line);
while (stream_names_var) {
stream_names_var >> word;
ixColon = (int)word.find(":");
/*--- variable names ---*/
if (line.compare("[Variable names]") == 0) {

for (unsigned long i = 0; i < n_variables; i++){

names_var.push_back(word.substr(ixColon + 1, word.size() - 1));
/*--- grab a single line ---*/
GetNextNonEmptyLine(file_stream, line);
names_var.push_back(line.substr(line.find(":")+1));
}
names_var.pop_back(); // removes last redundant element
}

// check if end of header is reached
if (line.compare("</header>") == 0) eoHeader = true;
/*--- check if end of header is reached ---*/
if (line.compare("</Header>") == 0) eoHeader = true;
}

// check version_lut
/*--- check version_lut ---*/
pcarruscag marked this conversation as resolved.
Show resolved Hide resolved
if (version_lut.compare(version_reader) != 0)
SU2_MPI::Error("Version conflict between Dragon reader and Dragon library file.", CURRENT_FUNCTION);
SU2_MPI::Error("Version conflict between LUT reader and LUT library file.", CURRENT_FUNCTION);

// check header quantities
/*--- check header quantities ---*/
if (n_points == 0 || n_triangles == 0 || n_variables == 0 || n_hull_points == 0)
SU2_MPI::Error(
"Number of points, triangles, hull points, or variables in Dragon "
"Number of points, triangles, hull points, or variables in lookup table "
"library header is zero.",
CURRENT_FUNCTION);

// check if number of variables is consistent
/*--- check if number of variables is consistent ---*/
if (n_variables != names_var.size())
SU2_MPI::Error(
"Number of read variables does not match number of "
"variables specified in Dragon "
"variables specified in lookup table "
"library header.",
CURRENT_FUNCTION);

/* now that n_variables, n_points, n_hull_points and n_variables is available,
* allocate memory */
if (rank == MASTER_NODE) cout << "allocating memory for the data" << endl;
/*--- now that n_variables, n_points, n_hull_points and n_variables are available, allocate memory ---*/
if (rank == MASTER_NODE) cout << "allocating memory for the data, size = ( " << GetNVariables() << " , " << GetNPoints() << " )" << endl;
table_data.resize(GetNVariables(), GetNPoints());


if (rank == MASTER_NODE) cout << "allocating memory for the triangles" << endl;
if (rank == MASTER_NODE) cout << "allocating memory for the triangles, size = "<< GetNTriangles() << endl;
triangles.resize(GetNTriangles(), 3);

if (rank == MASTER_NODE) cout << "allocating memory for the hull points" << endl;
if (rank == MASTER_NODE) cout << "allocating memory for the hull points, size = " << GetNHullPoints() << endl;
hull.resize(GetNHullPoints());

/* flush any cout */
/*--- flush any cout ---*/
if (rank == MASTER_NODE) cout << endl;

// read data block
/*--- read data block ---*/
if (rank == MASTER_NODE) cout << "loading data block" << endl;

line = SkipToFlag(&file_stream, "<data>");
SkipToFlag(file_stream, line, "<Data>");

unsigned long pointCounter = 0;
while (getline(file_stream, line) && !eoData) {
// check if end of data is reached
if (line.compare("</data>") == 0) eoData = true;
while (GetNextNonEmptyLine(file_stream, line) && !eoData) {

/*--- check if end of data is reached ---*/
if (line.compare("</Data>") == 0) eoData = true;

if (!eoData) {
// one line contains values for one point for all variables
/*--- one line contains values for one point for all variables ---*/
istringstream streamDataLine(line);

// add next line to table array
/*--- add next line to table array ---*/
for (unsigned long iVar = 0; iVar < n_variables; iVar++) {
streamDataLine >> word;
passivedouble tmp = stod(word);
Expand All @@ -171,28 +167,32 @@ void CFileReaderLUT::ReadRawDRG(const string& file_name) {
if (n_points != pointCounter - 1)
SU2_MPI::Error(
"Number of read points does not match number of points "
"specified in Dragon library header.",
"specified in lookup table library header.",
CURRENT_FUNCTION);

// read connectivity
/*--- read connectivity ---*/
if (rank == MASTER_NODE) cout << "loading connectivity block" << endl;

line = SkipToFlag(&file_stream, "<connectivity>");
SkipToFlag(file_stream, line, "<Connectivity>");

unsigned long triCounter = 0;
while (getline(file_stream, line) && !eoConnectivity) {
// check if end of data is reached
if (line.compare("</connectivity>") == 0) eoConnectivity = true;
while (GetNextNonEmptyLine(file_stream, line) && !eoConnectivity) {
if (!line.empty() && (line[line.length()-1] == '\n' || line[line.length()-1] == '\r' )) {
line.erase(line.length()-1);
}
/*--- check if end of data is reached ---*/
if (line.compare("</Connectivity>") == 0) eoConnectivity = true;

if (!eoConnectivity) {
// one line contains values for one triangle (3 points)
/*--- one line contains values for one triangle (3 points) ---*/
istringstream streamTriLine(line);

// add next line to triangles
/*--- add next line to triangles ---*/
for (int iPoint = 0; iPoint < 3; iPoint++) {

streamTriLine >> word;
// Dragon table index starts with 1, convert to c++ indexing starting
// with 0:

/*--- lookup table index starts with 1, convert to c++ indexing starting with 0: ---*/
triangles[triCounter][iPoint] = stol(word) - 1;
}
}
Expand All @@ -202,27 +202,29 @@ void CFileReaderLUT::ReadRawDRG(const string& file_name) {
if (n_triangles != triCounter - 1)
SU2_MPI::Error(
"Number of read triangles does not match number of points "
"specified in Dragon library header.",
"specified in lookup table library header.",
CURRENT_FUNCTION);

// read hull points
/*--- read hull points ---*/
if (rank == MASTER_NODE) cout << "loading hull block" << endl;

line = SkipToFlag(&file_stream, "<hull>");
SkipToFlag(file_stream, line, "<Hull>");

unsigned long hullCounter = 0;
while (getline(file_stream, line) && !eoHull) {
// check if end of data is reached
if (line.compare("</hull>") == 0) eoHull = true;
while (GetNextNonEmptyLine(file_stream, line) && !eoHull) {
if (!line.empty() && (line[line.length()-1] == '\n' || line[line.length()-1] == '\r' )) {
line.erase(line.length()-1);
}
/*--- check if end of data is reached ---*/
if (line.compare("</Hull>") == 0) eoHull = true;

if (!eoHull) {
// one line contains one point ID for one point on the hull
/*--- one line contains one point ID for one point on the hull ---*/
istringstream streamHullLine(line);

streamHullLine >> word;

// Dragon table indices start with 1, convert to c++ indexing starting
// with 0:
/*--- Lookup table indices start with 1, convert to c++ indexing starting with 0: ---*/
hull[hullCounter] = stol(word) - 1;
}
hullCounter++;
Expand All @@ -231,22 +233,62 @@ void CFileReaderLUT::ReadRawDRG(const string& file_name) {
if (n_hull_points != hullCounter - 1)
SU2_MPI::Error(
"Number of read hull points does not match number of points "
"specified in Dragon library header.",
"specified in lookup table library header.",
CURRENT_FUNCTION);

file_stream.close();

}

string CFileReaderLUT::SkipToFlag(ifstream* file_stream, const string& flag) {
string line;
getline(*file_stream, line);

while (line.compare(flag) != 0 && !(*file_stream).eof()) {
getline(*file_stream, line);
/*! \brief Searches for the position of flag in file_stream and
* sets the stream position of file_stream to that position.
*/
void CFileReaderLUT::SkipToFlag(ifstream& file_stream, const string& current_line, const string& flag) const {
string next_line = "";

/*--- compare current line to flag and return if equal ---*/
if (current_line.compare(flag) == 0) return;

/*--- else, search for flag ---*/
while (next_line.find(flag) == string::npos && !(file_stream).eof()) {
GetStrippedLine(file_stream, next_line);
}

if ((*file_stream).eof()) SU2_MPI::Error("Flag not found in file", CURRENT_FUNCTION);
/*--- throw error if end of file reached ---*/
if ((file_stream).eof()) SU2_MPI::Error("Flag " + flag + " not found in file", CURRENT_FUNCTION);
}

return line;
/*! \brief Extracts the next non-empty characters from file_stream and stores them into line.
*/
bool CFileReaderLUT::GetNextNonEmptyLine(ifstream& file_stream, string& line) const {

/*--- get next line and save return value ---*/
bool return_value = GetStrippedLine(file_stream, line);

/*--- skip empty lines ---*/
while (line.empty() && !(file_stream).eof()){
return_value = GetStrippedLine(file_stream, line);
}

/*--- return true if line is not empty, else return false ---*/
return return_value;
}

/*! \brief Extracts characters from file_stream, removes trailing control characters,
* and stores them into line.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw it is usually better to put the doxygen comment on the declaration hpp, but it's fine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've moved it to the hpp files. When it goes through the regression tests, I'll merge.

bool CFileReaderLUT::GetStrippedLine(ifstream& file_stream, string& line) const {

/*--- get next line and save return value ---*/
getline(file_stream, line);

/*--- find last non-control-character character ---*/
size_t end = line.find_last_not_of(" \n\r\t\f\v");

/*--- clean up line ---*/
line = (end == string::npos) ? "" : line.substr(0, end + 1);

/*--- return true if line is not empty, else return false ---*/
return !line.empty();
}
7 changes: 5 additions & 2 deletions Common/src/containers/CTrapezoidalMap.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* \file CTrapezoidalMap.cpp
* \brief Implementation of the trapezoidal map for tabulation and lookup of fluid properties
* \author D. Mayer, T. Economon
* \author D. Mayer, T. Economon, N. Beishuizen
* \version 7.4.0 "Blackbird"
*
* SU2 Project Website: https://su2code.github.io
Expand Down Expand Up @@ -35,6 +35,7 @@ using namespace std;
/* Trapezoidal map implementation. Reference:
* M. de Berg, O. Cheong M. van Kreveld, M. Overmars,
* Computational Geometry, Algorithms and Applications pp. 121-146 (2008)
* NOTE: the current implementation is actually the simpler 'slab' approach.
*/
CTrapezoidalMap::CTrapezoidalMap(const su2double* samples_x, const su2double* samples_y, const unsigned long size,
vector<vector<unsigned long> > const& edges,
Expand Down Expand Up @@ -174,7 +175,9 @@ pair<unsigned long, unsigned long> CTrapezoidalMap::GetBand(su2double val_x) {

std::pair<std::vector<su2double>::iterator,std::vector<su2double>::iterator> bounds;
bounds = std::equal_range (unique_bands_x.begin(), unique_bands_x.end(), val_x);
i_up = bounds.first - unique_bands_x.begin();

/*--- if upper bound = 0, then use the range [0,1] ---*/
i_up = max<unsigned long>(1, bounds.first - unique_bands_x.begin());
i_low = i_up-1;

return make_pair(i_low, i_up);
Expand Down
2 changes: 1 addition & 1 deletion SU2_CFD/src/solvers/CSpeciesSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ CSpeciesSolver::CSpeciesSolver(CGeometry* geometry, CConfig* config, unsigned sh

/*--- Initialization of the structure of the whole Jacobian ---*/

if (rank == MASTER_NODE) cout << "Initialize Jacobian structure (passive scalar model)." << endl;
if (rank == MASTER_NODE) cout << "Initialize Jacobian structure (species transport model)." << endl;
Jacobian.Initialize(nPoint, nPointDomain, nVar, nVar, true, geometry, config, ReducerStrategy);

if (config->GetKind_Linear_Solver_Prec() == LINELET) {
Expand Down
Loading