Skip to content

Commit b01a639

Browse files
Add look-up table class (#1637)
* initial commit, adding files * added files to makefile and meson * run through clang-format * end files with newline * namespace to header file * removed local implementation of gaussian inverse, added initial unit-test * change .at in vectors, moved hpp to containers * corrected path to hpp files * move files to containers folder * move files to containers, including lookup table * introduce su2matrix for table_data * remove unused variable Weights, introduce std::array for fixed size arrays * changed triangle into su2matrix * cleaned up some unused code * get rid of vector<vector> for table_data * change edge_to_triangle to std::array * remove std namespace from header files and using std::array and std::vector * remove unnecessary includes * update lookuptable unit tests * removed large unit test, kept small unit test for lookup table * fix lookup table * fix unit regression values * modified some comments * fixed unsigned int * fix unit regression values * added descriptions of class functions, used mpi::wtime, make some class functions const * remove using namespace std * added additional info, removed lookup table identifier * fix const * fix lookuptable_test roundoff value * remove namespace std Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com>
1 parent eed1e67 commit b01a639

16 files changed

Lines changed: 1627 additions & 6 deletions

File tree

.github/workflows/regression.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jobs:
129129
with:
130130
# -t <Tutorials-branch> -c <Testcases-branch>
131131
args: -b ${{github.ref}} -t develop -c develop -s ${{matrix.testscript}}
132-
- name: Cleanup
132+
- name: Cleanup
133133
uses: docker://ghcr.io/su2code/su2/test-su2:220614-1237
134134
with:
135135
entrypoint: /bin/rm
@@ -192,12 +192,31 @@ jobs:
192192
done
193193
find $BIN_FOLDER -type f -exec chmod a+x '{}' \;
194194
ls -lahR $BIN_FOLDER
195+
echo "cloning branch"
196+
branch="${{github.ref}}"
197+
name="SU2"
198+
SRC_FOLDER="$PWD/src"
199+
mkdir -p $SRC_FOLDER
200+
cd $SRC_FOLDER
201+
git clone --recursive --depth=1 --shallow-submodules https://github.com/su2code/SU2 $name
202+
cd $name
203+
git config --add remote.origin.fetch '+refs/pull/*/merge:refs/remotes/origin/refs/pull/*/merge'
204+
git config --add remote.origin.fetch '+refs/heads/*:refs/remotes/origin/refs/heads/*'
205+
git fetch origin --depth=1 $branch:$branch
206+
git checkout $branch
207+
git submodule update
208+
echo $PWD
209+
ls -lahR
210+
cd ..
211+
echo "done cloning"
212+
echo $PWD
213+
ls -lahR
195214
- name: Run Unit Tests
196215
uses: docker://ghcr.io/su2code/su2/test-su2:220614-1237
197216
with:
198217
entrypoint: install/bin/${{matrix.testdriver}}
199-
- name: Post Cleanup
218+
- name: Post Cleanup
200219
uses: docker://ghcr.io/su2code/su2/test-su2:220614-1237
201220
with:
202221
entrypoint: /bin/rm
203-
args: -rf install install_bin.tgz src ccache ${{ matrix.config_set }}
222+
args: -rf install install_bin.tgz src ccache ${{ matrix.config_set }}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*!
2+
* \file CFileReaderLUT.hpp
3+
* \brief reading lookup table for tabulated fluid properties
4+
* \author D. Mayer, T. Economon
5+
* \version 7.3.1 "Blackbird"
6+
*
7+
* SU2 Project Website: https://su2code.github.io
8+
*
9+
* The SU2 Project is maintained by the SU2 Foundation
10+
* (http://su2foundation.org)
11+
*
12+
* Copyright 2012-2022, SU2 Contributors (cf. AUTHORS.md)
13+
*
14+
* SU2 is free software; you can redistribute it and/or
15+
* modify it under the terms of the GNU Lesser General Public
16+
* License as published by the Free Software Foundation; either
17+
* version 2.1 of the License, or (at your option) any later version.
18+
*
19+
* SU2 is distributed in the hope that it will be useful,
20+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22+
* Lesser General Public License for more details.
23+
*
24+
* You should have received a copy of the GNU Lesser General Public
25+
* License along with SU2. If not, see <http://www.gnu.org/licenses/>.
26+
*/
27+
#pragma once
28+
29+
#include <fstream>
30+
#include <string>
31+
#include <vector>
32+
33+
#include "../../Common/include/parallelization/mpi_structure.hpp"
34+
#include "../../../Common/include/linear_algebra/blas_structure.hpp"
35+
#include "../../../Common/include/toolboxes/CSquareMatrixCM.hpp"
36+
37+
class CFileReaderLUT {
38+
protected:
39+
int rank;
40+
41+
std::string version_lut;
42+
std::string version_reader;
43+
unsigned long n_points;
44+
unsigned long n_triangles;
45+
unsigned long n_hull_points;
46+
unsigned long n_variables;
47+
48+
/*! \brief Holds the variable names stored in the table file.
49+
* Order is in sync with tableFlamelet.
50+
*/
51+
std::vector<std::string> names_var;
52+
53+
/*! \brief Holds all data stored in the table.
54+
* First index addresses the variable while second index addresses the point.
55+
*/
56+
su2activematrix table_data;
57+
58+
su2matrix<unsigned long> triangles;
59+
60+
std::vector<unsigned long> hull;
61+
62+
std::string SkipToFlag(std::ifstream* file_stream, const std::string& flag);
63+
64+
public:
65+
CFileReaderLUT(){};
66+
67+
inline const std::string& GetVersionLUT() const { return version_lut; }
68+
inline const std::string& GetVersionReader() const { return version_reader; }
69+
inline unsigned long GetNPoints() const { return n_points; }
70+
inline unsigned long GetNTriangles() const { return n_triangles; }
71+
inline unsigned long GetNHullPoints() const { return n_hull_points; }
72+
inline unsigned long GetNVariables() const { return n_variables; }
73+
74+
inline const std::vector<std::string>& GetNamesVar() const { return names_var; }
75+
76+
inline const su2activematrix& GetTableData() const { return table_data; }
77+
78+
inline const su2matrix<unsigned long>& GetTriangles() const { return triangles; };
79+
80+
inline const std::vector<unsigned long>& GetHull() const { return hull; };
81+
82+
void ReadRawDRG(const std::string& file_name);
83+
};
Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
/*!
2+
* \file CLookupTable.hpp
3+
* \brief tabulation of fluid properties
4+
* \author D. Mayer, T. Economon
5+
* \version 7.3.1 "Blackbird"
6+
*
7+
* SU2 Project Website: https://su2code.github.io
8+
*
9+
* The SU2 Project is maintained by the SU2 Foundation
10+
* (http://su2foundation.org)
11+
*
12+
* Copyright 2012-2022, SU2 Contributors (cf. AUTHORS.md)
13+
*
14+
* SU2 is free software; you can redistribute it and/or
15+
* modify it under the terms of the GNU Lesser General Public
16+
* License as published by the Free Software Foundation; either
17+
* version 2.1 of the License, or (at your option) any later version.
18+
*
19+
* SU2 is distributed in the hope that it will be useful,
20+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22+
* Lesser General Public License for more details.
23+
*
24+
* You should have received a copy of the GNU Lesser General Public
25+
* License along with SU2. If not, see <http://www.gnu.org/licenses/>.
26+
*/
27+
28+
#pragma once
29+
30+
#include <iomanip>
31+
#include <string>
32+
#include <vector>
33+
34+
#include "../../Common/include/option_structure.hpp"
35+
#include "CFileReaderLUT.hpp"
36+
#include "CTrapezoidalMap.hpp"
37+
38+
class CLookUpTable {
39+
protected:
40+
int rank; /*!< \brief MPI Rank. */
41+
42+
std::string file_name_lut;
43+
std::string version_lut;
44+
std::string version_reader;
45+
unsigned long n_points;
46+
unsigned long n_triangles;
47+
unsigned long n_variables;
48+
unsigned long n_hull_points;
49+
50+
/*!
51+
* \brief the lower and upper limits of the enthalpy and progress variable.
52+
*/
53+
su2double limits_table_enth[2];
54+
su2double limits_table_prog[2];
55+
56+
/*! \brief Holds the variable names stored in the table file.
57+
* Order is in sync with data
58+
*/
59+
std::vector<std::string> names_var;
60+
61+
/*! \brief
62+
* Holds all data stored in the table. First index addresses the variable
63+
* while second index addresses the point.
64+
*/
65+
su2activematrix table_data;
66+
67+
su2matrix<unsigned long> triangles;
68+
69+
/* we do not know this size in advance until we go through the entire lookup table */
70+
std::vector<std::vector<unsigned long> > edges;
71+
std::vector<std::vector<unsigned long> > edge_to_triangle;
72+
73+
/*! \brief
74+
* The hull contains the boundary of the lookup table.
75+
*/
76+
std::vector<unsigned long> hull;
77+
78+
CTrapezoidalMap trap_map_prog_enth;
79+
80+
/*! \brief
81+
* vector of all the weight factors for the interpolation.
82+
*/
83+
std::vector<su2activematrix> interp_mat_inv_prog_enth;
84+
85+
/*! \brief
86+
* returns the index to the variable in the lookup table.
87+
*/
88+
inline unsigned int GetIndexOfVar(const std::string& nameVar) const {
89+
int index = find(names_var.begin(), names_var.end(), nameVar) - names_var.begin();
90+
if (index == int(names_var.size())) {
91+
index = -1;
92+
std::string error_msg = "Variable '";
93+
error_msg.append(nameVar);
94+
error_msg.append("' is not in the lookup table.");
95+
SU2_MPI::Error(error_msg, CURRENT_FUNCTION);
96+
}
97+
return index;
98+
}
99+
100+
/*!
101+
* \brief Get the pointer to the column data of the table (density, temperature, source terms, ...).
102+
* \returns pointer to the column data.
103+
*/
104+
inline const su2double* GetDataP(const std::string& name_var) const {
105+
return table_data[GetIndexOfVar(name_var)];
106+
}
107+
108+
/*!
109+
* \brief find the table limits, i.e. the minimum and maximum values of the 2 independent.
110+
* controlling variables (progress variable and enthalpy). We put the values in the variables.
111+
* limits_table_prog[2] and limit_table_enth[2].
112+
* \param[in] name_prog - the string name for the first controlling variable.
113+
* \param[in] name_enth - the string name of the second controlling variable.
114+
*/
115+
void FindTableLimits(const std::string& name_prog, const std::string& name_enth);
116+
117+
/*!
118+
* \brief construct a list of all the edges and a list of the pair of elements left and right of the edge.
119+
*/
120+
void IdentifyUniqueEdges();
121+
122+
/*!
123+
* \brief read the lookup table from file and store the data.
124+
* \param[in] file_name_lut - the filename of the lookup table.
125+
*/
126+
void LoadTableRaw(const std::string& file_name_lut);
127+
128+
/*!
129+
* \brief compute vector of all (inverse) interpolation coefficients "interp_mat_inv_prog_enth" of all triangles.
130+
* \param[in] name_prog - the string name of the first controlling variable (progress variable).
131+
* \param[in] name_enth - the string name of the second controlling variable (enthalpy).
132+
*/
133+
void ComputeInterpCoeffs(const std::string& name_prog, const std::string& name_enth);
134+
135+
/*!
136+
* \brief compute the inverse matrix for interpolation.
137+
* \param[in] vec_x - pointer to first coordinate (progress variable).
138+
* \param[in] vec_y - pointer to second coordinate (enthalpy).
139+
* \param[in] point_ids - single triangle data.
140+
* \param[out] interp_mat_inv - inverse matrix for interpolation.
141+
*/
142+
void GetInterpMatInv(const su2double* vec_x, const su2double* vec_y, std::array<unsigned long,3>& point_ids,
143+
su2activematrix& interp_mat_inv);
144+
145+
/*!
146+
* \brief compute the interpolation coefficients for the triangular interpolation.
147+
* \param[in] val_x - value of first coordinate (progress variable).
148+
* \param[in] val_y - value of second coordinate (enthalpy).
149+
* \param[in] interp_mat_inv - inverse matrix for interpolation.
150+
* \param[out] interp_coeffs - interpolation coefficients.
151+
*/
152+
void GetInterpCoeffs(su2double val_x, su2double val_y, su2activematrix& interp_mat_inv,
153+
std::array<su2double,3>& interp_coeffs);
154+
155+
/*!
156+
* \brief compute interpolated value of a point P in the triangle.
157+
* \param[in] val_samples - pointer to the variable data.
158+
* \param[in] val_triangle - ID to the triangle.
159+
* \param[in] val_interp_coeffs - interpolation coefficients using the point data in P.
160+
* \returns resulting value of the interpolation.
161+
*/
162+
su2double Interpolate(const su2double* val_samples, std::array<unsigned long,3>& val_triangle,
163+
std::array<su2double,3>& val_interp_coeffs);
164+
165+
/*!
166+
* \brief find the point on the hull (boundary of the table) that is closest to the point P(val_prog,val_enth).
167+
* \param[in] val_x - first coordinate of point P(val_x,val_y) to check.
168+
* \param[in] val_y - second coordinate of point P(val_x,val_y) to check.
169+
* \param[in] name_prog - string name of the first controlling variable.
170+
* \param[in] name_enth - string name of the second controlling variable.
171+
* \returns point id of the nearest neighbor on the hull.
172+
*/
173+
unsigned long FindNearestNeighborOnHull(su2double val_prog, su2double val_enth, const std::string& name_prog, const std::string& name_enth);
174+
175+
/*!
176+
* \brief determine if a point P(val_x,val_y) is inside the triangle val_id_triangle.
177+
* \param[in] val_x - first coordinate of point P(val_x,val_y) to check.
178+
* \param[in] val_y - second coordinate of point P(val_x,val_y) to check.
179+
* \param[in] val_id_triangle - ID of the triangle to check.
180+
* \param[in] name_prog - string name of the first controlling variable.
181+
* \param[in] name_enth - string name of the second controlling variable.
182+
* \returns true if the point is in the triangle, false if it is outside.
183+
*/
184+
bool IsInTriangle(su2double val_x, su2double val_y, unsigned long val_id_triangle, const std::string& name_prog,
185+
const std::string& name_enth);
186+
187+
/*!
188+
* \brief compute the area of a triangle given the 3 points of the triangle.
189+
* \param[in] x1 - the coordinates of the points P1(x1,y1), P2(x2,y2) and P3(x3,y3).
190+
* \param[in] y1 - the coordinates of the points P1(x1,y1), P2(x2,y2) and P3(x3,y3).
191+
* \param[in] x2 - the coordinates of the points P1(x1,y1), P2(x2,y2) and P3(x3,y3).
192+
* \param[in] y2 - the coordinates of the points P1(x1,y1), P2(x2,y2) and P3(x3,y3).
193+
* \param[in] x3 - the coordinates of the points P1(x1,y1), P2(x2,y2) and P3(x3,y3).
194+
* \param[in] y3 - the coordinates of the points P1(x1,y1), P2(x2,y2) and P3(x3,y3).
195+
* \returns the absolute value of the area of the triangle.
196+
*/
197+
inline su2double TriArea(su2double x1, su2double y1, su2double x2, su2double y2, su2double x3, su2double y3) {
198+
return abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) * 0.5);
199+
}
200+
201+
public:
202+
CLookUpTable(const std::string& file_name_lut, const std::string& name_prog, const std::string& name_enth);
203+
204+
205+
/*!
206+
* \brief print information to screen.
207+
*/
208+
void PrintTableInfo();
209+
210+
/*!
211+
* \brief lookup 1 value of the single variable "val_name_var" using controlling variable values(val_prog,val_enth)
212+
* whose controlling variable names are "name_prog" and "name_enth".
213+
* \param[in] val_name_var - string name of the variable to look up.
214+
* \param[out] val_var - the stored value of the variable to look up.
215+
* \param[in] val_prog - value of controlling variable 1 (progress variable).
216+
* \param[in] val_enth - value of controlling variable 2 (enthalpy).
217+
* \param[in] name_prog - string name of controlling variable 1 (progress variable).
218+
* \param[in] name_enth - string name of controlling variable 2 (enthalpy).
219+
* \returns 1 if the lookup and subsequent interpolation was a success, 0 if not.
220+
*/
221+
unsigned long LookUp_ProgEnth(const std::string& val_name_var, su2double* val_var, su2double val_prog, su2double val_enth,
222+
const std::string& name_prog, const std::string& name_enth);
223+
224+
/*!
225+
* \brief lookup 1 value for each of the variables in "val_name_var" using controlling variable values(val_prog,val_enth)
226+
* whose controlling variable names are "name_prog" and "name_enth".
227+
* \param[in] val_names_var - vector of string names of the variables to look up.
228+
* \param[out] val_vars - pointer to the vector of stored values of the variables to look up.
229+
* \param[in] val_prog - value of controlling variable 1 (progress variable).
230+
* \param[in] val_enth - value of controlling variable 2 (enthalpy).
231+
* \param[in] name_prog - string name of controlling variable 1 (progress variable).
232+
* \param[in] name_enth - string name of controlling variable 2 (enthalpy).
233+
* \returns 1 if the lookup and subsequent interpolation was a success, 0 if not.
234+
*/
235+
unsigned long LookUp_ProgEnth(const std::vector<std::string>& val_names_var, std::vector<su2double*>& val_vars, su2double val_prog,
236+
su2double val_enth, const std::string& name_prog, const std::string& name_enth);
237+
238+
/*!
239+
* \brief lookup the value of the variable "val_name_var" using controlling variable values(val_prog,val_enth)
240+
* whose controlling variable names are "name_prog" and "name_enth".
241+
* \param[in] val_name_var - string name of the variable to look up.
242+
* \param[out] val_var - the stored value of the variable to look up.
243+
* \param[in] val_prog - value of controlling variable 1 (progress variable).
244+
* \param[in] val_enth - value of controlling variable 2 (enthalpy).
245+
* \param[in] name_prog - string name of controlling variable 1 (progress variable).
246+
* \param[in] name_enth - string name of controlling variable 2 (enthalpy).
247+
* \returns 1 if the lookup and subsequent interpolation was a success, 0 if not.
248+
*/
249+
unsigned long LookUp_ProgEnth(const std::vector<std::string>& val_names_var, std::vector<su2double>& val_vars, su2double val_prog,
250+
su2double val_enth, const std::string& name_prog, const std::string& name_enth);
251+
252+
/*!
253+
* \brief determine the minimum and maximum value of the enthalpy (controlling variable 2).
254+
* \returns pair of minimum and maximum value of controlling variable 2.
255+
*/
256+
inline std::pair<su2double, su2double> GetTableLimitsEnth() const {
257+
return std::make_pair(limits_table_enth[0], limits_table_enth[1]);
258+
}
259+
260+
/*!
261+
* \brief determine the minimum and maximum value of the progress variable (controlling variable 1).
262+
* \returns pair of minimum and maximum value of controlling variable 1.
263+
*/
264+
inline std::pair<su2double, su2double> GetTableLimitsProg() const {
265+
return std::make_pair(limits_table_prog[0], limits_table_prog[1]);
266+
}
267+
};

0 commit comments

Comments
 (0)