Skip to content

Commit d94de4e

Browse files
committed
Refactored CSolver
1 parent ef9285b commit d94de4e

File tree

3 files changed

+97
-74
lines changed

3 files changed

+97
-74
lines changed

Common/include/toolboxes/geometry_toolbox.hpp

+17-3
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

+3-1
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

+77-70
Original file line numberDiff line numberDiff line change
@@ -4316,29 +4316,16 @@ 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-
}
4326+
if (unsteady_restart) {
43414327

4328+
int restart_iter = config->GetRestart_Iter()-1-ts_2nd;
43424329
filename = config->GetUnsteady_FileName(config->GetVGFileName(), restart_iter, ".cfg");
43434330

43444331
} else {
@@ -4351,87 +4338,107 @@ void CSolver::ReadVGConfigFile(CConfig* config) {
43514338

43524339
while (std::getline(file, line)) {
43534340
if (line.empty() || line.front() == '#') continue;
4354-
nVgs_file++;
4355-
lines_configVg.push_back(line);
4341+
nVgs++;
4342+
lines_vgConfig.push_back(line);
43564343
};
43574344
file.close();
43584345

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

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;
4378-
}
4356+
su2double **vg_b = new su2double*[nVgs];
4357+
su2double **vg_n = new su2double*[nVgs];
4358+
su2double **vg_t = new su2double*[nVgs];
4359+
su2double **vg_uhat = new su2double*[nVgs];
4360+
su2double ***vg_coord = new su2double**[nVgs];
4361+
su2double *Svg = new su2double[nVgs];
4362+
su2double *betaVg = new su2double[nVgs];
4363+
4364+
for (unsigned short iVG = 0; iVG < nVgs; iVG++) {
4365+
4366+
/* --- Parse variables ---*/
4367+
istringstream vg_line{lines_vgConfig[iVG]};
43794368

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};
4369+
vg_line >> l;
4370+
vg_line >> h1;
4371+
vg_line >> h2;
4372+
vg_line >> beta;
43854373

4386-
const auto beta = betaVg[iVG] * PI_NUMBER / 180.0;
4374+
for (unsigned short iDim = 0; iDim < 3; iDim++) {
4375+
vg_line >> p1[iDim];
4376+
}
43874377

4388-
su2double uc[3];
4389-
GeometryToolbox::CrossProduct(vg_b[iVG], vg_uhat[iVG], uc);
4378+
for (unsigned short iDim = 0; iDim < 3; iDim++) {
4379+
vg_line >> un[iDim];
4380+
}
43904381

43914382
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);
4383+
vg_line >> u[iDim];
43944384
}
4385+
4386+
/*--- Allocate Variable ---*/
4387+
4388+
vg_b[iVG] = new su2double[3];
4389+
vg_uhat[iVG] = new su2double[3];
4390+
vg_n[iVG] = new su2double[3];
4391+
vg_t[iVG] = new su2double[3];
4392+
4393+
/*--- Compute the VG variables ---*/
43954394

4396-
bNorm = GeometryToolbox::Norm(nDim, vg_b[iVG]);
4397-
nNorm = GeometryToolbox::Norm(nDim, vg_n[iVG]);
4398-
tNorm = GeometryToolbox::Norm(nDim, vg_t[iVG]);
4395+
beta *= PI_NUMBER / 180.0;
4396+
4397+
GeometryToolbox::CrossProduct(un, u, uc);
43994398

44004399
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;
4400+
vg_t[iVG][iDim] = u[iDim] * cos(beta) + uc[iDim] * sin(beta);
4401+
vg_n[iVG][iDim] = u[iDim] * sin(beta) + uc[iDim] * cos(beta);
4402+
vg_b[iVG][iDim] = un[iDim];
4403+
vg_uhat[iVG][iDim] = u[iDim];
44044404
}
4405+
betaVg[iVG] = beta;
4406+
4407+
GeometryToolbox::NormalizeVector(nDim, vg_t[iVG]);
4408+
GeometryToolbox::NormalizeVector(nDim, vg_b[iVG]);
4409+
GeometryToolbox::NormalizeVector(nDim, vg_n[iVG]);
44054410

44064411
/*--- Set variables in CConfig ---*/
44074412

44084413
vg_coord[iVG] = new su2double*[4];
44094414

4410-
vg_coord[iVG][0] = new su2double[3]{opt[p1_idx], opt[p1_idx + 1], opt[p1_idx + 2]};
4415+
vg_coord[iVG][0] = new su2double[3]{p1[0], p1[1], p1[2]};
4416+
4417+
vg_coord[iVG][1] = new su2double[3]{p1[0] + vg_t[iVG][0] * l,
4418+
p1[1] + vg_t[iVG][1] * l,
4419+
p1[2] + vg_t[iVG][2] * l};
44114420

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]};
4421+
su2double* p2=vg_coord[iVG][1];
44154422

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]};
4423+
vg_coord[iVG][2] = new su2double[3]{p2[0] + vg_b[iVG][0] * h2,
4424+
p2[1] + vg_b[iVG][1] * h2,
4425+
p2[2] + vg_b[iVG][2] * h2};
44194426

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]};
4427+
vg_coord[iVG][3] = new su2double[3]{p1[0] + vg_b[iVG][0] * h1,
4428+
p1[1] + vg_b[iVG][1] * h1,
4429+
p1[2] + vg_b[iVG][2] * h1};
44234430

4424-
Svg[iVG] = 0.5 * (opt[h_idx] + opt[h_idx + 1]) * opt[l_idx];
4431+
Svg[iVG] = 0.5 * (h1 + h2) * l;
44254432
};
44264433

4434+
/*--- Set the variables in CConfig ---*/
4435+
44274436
config->Set_nVG(vg_n);
44284437
config->Set_bVG(vg_b);
44294438
config->Set_tVG(vg_t);
44304439
config->SetVGCoord(vg_coord);
44314440
config->Set_Svg(Svg);
4432-
config->Set_nVGs(nVgs_file);
4441+
config->Set_nVGs(nVgs);
44334442
config->Set_uhatVg(vg_uhat);
44344443
config->Set_betaVg(betaVg);
4435-
}
4436-
4437-
//End added by max
4444+
}//End added by max

0 commit comments

Comments
 (0)