Skip to content

Commit 7edc68b

Browse files
committed
Refactored CSolver
1 parent ef9285b commit 7edc68b

File tree

3 files changed

+106
-78
lines changed

3 files changed

+106
-78
lines changed

Common/include/toolboxes/geometry_toolbox.hpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,18 @@ inline bool IntersectEdge(Int nDim, const T* p0, const T* n, const T* p1, const
236236
else
237237
return false;
238238
}
239+
240+
/*!
241+
* \brief Check if a point is inside a polygon
242+
* \param[in] nDim - Number of dimensions of the particular problem.
243+
* \param[in] vector - Vector to normalize.
244+
*/
245+
template <class T, class Int>
246+
inline void NormalizeVector(Int nDim, T* vector) {
247+
T norm = Norm(nDim, vector);
248+
for (Int i = 0; i < nDim; i++) vector[i] /= norm;
249+
}
250+
239251
/*!
240252
* \brief Check if a point is inside a polygon
241253
* \param[in] nDim - Number of dimensions of the particular problem.
@@ -257,11 +269,12 @@ inline bool PointInConvexPolygon(Int nDim, const Mat& pVert, const T* p0, int nV
257269
if (nDim == 3) {
258270
T plane_norm[3];
259271
TriangleNormal(pVert, plane_norm);
260-
auto normPlane_norm = Norm(3, plane_norm);
272+
NormalizeVector(3, plane_norm);
273+
261274
for (unsigned short iDim = 0; iDim < nDim; iDim++) {
262-
if (abs(plane_norm[iDim] / normPlane_norm) > max_proj) {
275+
if (abs(plane_norm[iDim]) > max_proj) {
263276
proj_index = iDim;
264-
max_proj = abs(plane_norm[iDim] / normPlane_norm);
277+
max_proj = abs(plane_norm[iDim]);
265278
}
266279
}
267280

@@ -296,6 +309,7 @@ inline bool PointInConvexPolygon(Int nDim, const Mat& pVert, const T* p0, int nV
296309

297310
return nIntersections % 2 == 1;
298311
}
312+
299313
// end added by max
300314
/// @}
301315
} // namespace GeometryToolbox

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,9 @@ class CSolver {
15831583
//Added by max
15841584
void ReadVGConfigFile(CConfig* config);
15851585

1586-
//End added by max
1586+
void InitializeVGVariables(unsigned short nVgs_file, std::vector<std::string>& lines_configVg, CConfig* config);
1587+
1588+
// End added by max
15871589

15881590
/*!
15891591
* \brief A virtual member.

SU2_CFD/src/solvers/CSolver.cpp

Lines changed: 86 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -4316,29 +4316,15 @@ void CSolver::SavelibROM(CGeometry *geometry, CConfig *config, bool converged) {
43164316
//Added by max
43174317
void CSolver::ReadVGConfigFile(CConfig* config) {
43184318
string filename, line;
4319-
unsigned short nVgs_file = 0;
4320-
su2double **vg_b, **vg_t, **vg_n, **vg_uhat, ***vg_coord, *Svg, *betaVg;
4321-
su2double bNorm, nNorm, tNorm;
4322-
const unsigned short p1_idx = 4, l_idx = 0, h_idx = 1, nOpt = 13, un_idx = 7, u_idx = 10;
4323-
vector<string> lines_configVg;
4324-
int restart_iter;
4319+
unsigned short nVgs = 0;
4320+
vector<string> lines_vgConfig;
4321+
bool unsteady_restart = config->GetTime_Domain() && config->GetRestart();
4322+
bool ts_2nd = config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_2ND;
43254323

43264324
/*--- Get the vortex generator filename. ---*/
43274325

4328-
if (config->GetTime_Domain() && config->GetRestart()) {
4329-
4330-
switch (config->GetTime_Marching())
4331-
{
4332-
case TIME_MARCHING::DT_STEPPING_1ST:
4333-
restart_iter = config->GetRestart_Iter() - 1;
4334-
break;
4335-
case TIME_MARCHING::DT_STEPPING_2ND:
4336-
restart_iter = config->GetRestart_Iter() - 2;
4337-
break;
4338-
default:
4339-
break;
4340-
}
4341-
4326+
if (unsteady_restart) {
4327+
int restart_iter = config->GetRestart_Iter() - 1 - ts_2nd;
43424328
filename = config->GetUnsteady_FileName(config->GetVGFileName(), restart_iter, ".cfg");
43434329

43444330
} else {
@@ -4351,87 +4337,113 @@ void CSolver::ReadVGConfigFile(CConfig* config) {
43514337

43524338
while (std::getline(file, line)) {
43534339
if (line.empty() || line.front() == '#') continue;
4354-
nVgs_file++;
4355-
lines_configVg.push_back(line);
4340+
nVgs++;
4341+
lines_vgConfig.push_back(line);
43564342
};
43574343
file.close();
43584344

4345+
InitializeVGVariables(nVgs, lines_vgConfig, config);
4346+
}
4347+
4348+
void CSolver::InitializeVGVariables(unsigned short nVgs, std::vector<std::string>& lines_vgConfig, CConfig* config) {
4349+
su2double l, h1, h2, beta, p1[3], un[3], u[3], uc[3];
4350+
unsigned short iDim;
4351+
43594352
/*--- Allocate and compute the required varibales for the vortex generator model ---*/
43604353

4361-
vg_b = new su2double*[nVgs_file];
4362-
vg_n = new su2double*[nVgs_file];
4363-
vg_t = new su2double*[nVgs_file];
4364-
vg_uhat = new su2double*[nVgs_file];
4365-
vg_coord = new su2double**[nVgs_file];
4366-
Svg = new su2double[nVgs_file];
4367-
betaVg = new su2double[nVgs_file];
4368-
4369-
for (unsigned short iVG = 0; iVG < nVgs_file; iVG++) {
4370-
istringstream vg_line{lines_configVg[iVG]};
4371-
su2double opt[13];
4372-
su2double tmp;
4373-
unsigned short iOpt;
4374-
4375-
for (iOpt = 0; iOpt < nOpt; iOpt++) {
4376-
vg_line >> tmp;
4377-
opt[iOpt] = tmp;
4354+
su2double** vg_b = new su2double*[nVgs];
4355+
su2double** vg_n = new su2double*[nVgs];
4356+
su2double** vg_t = new su2double*[nVgs];
4357+
su2double** vg_uhat = new su2double*[nVgs];
4358+
su2double*** vg_coord = new su2double**[nVgs];
4359+
su2double* Svg = new su2double[nVgs];
4360+
su2double* betaVg = new su2double[nVgs];
4361+
4362+
for (unsigned short iVG = 0; iVG < nVgs; iVG++) {
4363+
/* --- Parse variables ---*/
4364+
istringstream vg_line{lines_vgConfig[iVG]};
4365+
4366+
vg_line >> l;
4367+
vg_line >> h1;
4368+
vg_line >> h2;
4369+
vg_line >> beta;
4370+
4371+
for (iDim = 0; iDim < nDim; iDim++) {
4372+
vg_line >> p1[iDim];
43784373
}
43794374

4380-
betaVg[iVG] = opt[3];
4381-
vg_b[iVG] = new su2double[3]{opt[un_idx], opt[un_idx + 1], opt[un_idx + 2]};
4382-
vg_uhat[iVG] = new su2double[3]{opt[u_idx], opt[u_idx + 1], opt[u_idx + 2]};
4383-
vg_n[iVG] = new su2double[3]{0};
4384-
vg_t[iVG] = new su2double[3]{0};
4375+
for (iDim = 0; iDim < nDim; iDim++) {
4376+
vg_line >> un[iDim];
4377+
}
43854378

4386-
const auto beta = betaVg[iVG] * PI_NUMBER / 180.0;
4379+
for (iDim = 0; iDim < nDim; iDim++) {
4380+
vg_line >> u[iDim];
4381+
}
43874382

4388-
su2double uc[3];
4389-
GeometryToolbox::CrossProduct(vg_b[iVG], vg_uhat[iVG], uc);
4383+
/*--- Allocate Variable ---*/
43904384

4391-
for (unsigned short iDim = 0; iDim < 3; iDim++) {
4392-
vg_t[iVG][iDim] = vg_uhat[iVG][iDim] * cos(beta) + uc[iDim] * sin(beta);
4393-
vg_n[iVG][iDim] = vg_uhat[iVG][iDim] * sin(beta) + uc[iDim] * cos(beta);
4394-
}
4385+
vg_b[iVG] = new su2double[3];
4386+
vg_uhat[iVG] = new su2double[3];
4387+
vg_n[iVG] = new su2double[3];
4388+
vg_t[iVG] = new su2double[3];
4389+
4390+
/*--- Compute the VG variables ---*/
43954391

4396-
bNorm = GeometryToolbox::Norm(nDim, vg_b[iVG]);
4397-
nNorm = GeometryToolbox::Norm(nDim, vg_n[iVG]);
4398-
tNorm = GeometryToolbox::Norm(nDim, vg_t[iVG]);
4392+
beta *= PI_NUMBER / 180.0;
43994393

4400-
for (unsigned short iDim = 0; iDim < 3; iDim++) {
4401-
vg_t[iVG][iDim] /= tNorm;
4402-
vg_b[iVG][iDim] /= bNorm;
4403-
vg_n[iVG][iDim] /= nNorm;
4394+
GeometryToolbox::CrossProduct(un, u, uc);
4395+
4396+
for (iDim = 0; iDim < 3; iDim++) {
4397+
vg_t[iVG][iDim] = u[iDim] * cos(beta) + uc[iDim] * sin(beta);
4398+
vg_n[iVG][iDim] = u[iDim] * sin(beta) + uc[iDim] * cos(beta);
4399+
vg_b[iVG][iDim] = un[iDim];
4400+
vg_uhat[iVG][iDim] = u[iDim];
44044401
}
4402+
betaVg[iVG] = beta;
4403+
4404+
GeometryToolbox::NormalizeVector(nDim, vg_t[iVG]);
4405+
GeometryToolbox::NormalizeVector(nDim, vg_b[iVG]);
4406+
GeometryToolbox::NormalizeVector(nDim, vg_n[iVG]);
44054407

44064408
/*--- Set variables in CConfig ---*/
44074409

44084410
vg_coord[iVG] = new su2double*[4];
44094411

4410-
vg_coord[iVG][0] = new su2double[3]{opt[p1_idx], opt[p1_idx + 1], opt[p1_idx + 2]};
4412+
vg_coord[iVG][0] = new su2double[3]{
4413+
p1[0], p1[1], p1[2]
4414+
};
44114415

4412-
vg_coord[iVG][1] = new su2double[3]{opt[p1_idx] + vg_t[iVG][0] * opt[l_idx],
4413-
opt[p1_idx + 1] + vg_t[iVG][1] * opt[l_idx],
4414-
opt[p1_idx + 2] + vg_t[iVG][2] * opt[l_idx]};
4416+
vg_coord[iVG][1] = new su2double[3]{
4417+
p1[0] + vg_t[iVG][0] * l,
4418+
p1[1] + vg_t[iVG][1] * l,
4419+
p1[2] + vg_t[iVG][2] * l
4420+
};
44154421

4416-
vg_coord[iVG][2] = new su2double[3]{vg_coord[iVG][1][0] + vg_b[iVG][0] * opt[h_idx],
4417-
vg_coord[iVG][1][1] + vg_b[iVG][1] * opt[h_idx],
4418-
vg_coord[iVG][1][2] + vg_b[iVG][2] * opt[h_idx]};
4422+
su2double* p2 = vg_coord[iVG][1];
44194423

4420-
vg_coord[iVG][3] = new su2double[3]{opt[p1_idx] + vg_b[iVG][0] * opt[h_idx + 1],
4421-
opt[p1_idx + 1] + vg_b[iVG][1] * opt[h_idx + 1],
4422-
opt[p1_idx + 2] + vg_b[iVG][2] * opt[h_idx + 1]};
4423-
4424-
Svg[iVG] = 0.5 * (opt[h_idx] + opt[h_idx + 1]) * opt[l_idx];
4424+
vg_coord[iVG][2] = new su2double[3]{
4425+
p2[0] + vg_b[iVG][0] * h2,
4426+
p2[1] + vg_b[iVG][1] * h2,
4427+
p2[2] + vg_b[iVG][2] * h2
4428+
};
4429+
4430+
vg_coord[iVG][3] = new su2double[3]{
4431+
p1[0] + vg_b[iVG][0] * h1,
4432+
p1[1] + vg_b[iVG][1] * h1,
4433+
p1[2] + vg_b[iVG][2] * h1
4434+
};
4435+
4436+
Svg[iVG] = 0.5 * (h1 + h2) * l;
44254437
};
44264438

4439+
/*--- Set the variables in CConfig ---*/
4440+
44274441
config->Set_nVG(vg_n);
44284442
config->Set_bVG(vg_b);
44294443
config->Set_tVG(vg_t);
44304444
config->SetVGCoord(vg_coord);
44314445
config->Set_Svg(Svg);
4432-
config->Set_nVGs(nVgs_file);
4446+
config->Set_nVGs(nVgs);
44334447
config->Set_uhatVg(vg_uhat);
44344448
config->Set_betaVg(betaVg);
4435-
}
4436-
4437-
//End added by max
4449+
} // End added by max

0 commit comments

Comments
 (0)