Skip to content

Commit 58eaee1

Browse files
committed
fix some bugs
1 parent 76ab602 commit 58eaee1

2 files changed

Lines changed: 25 additions & 28 deletions

File tree

Common/include/grid_movement/CRadialBasisFunctionInterpolation.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class CRadialBasisFunctionInterpolation : public CVolumetricMovement {
4141
vector<CRadialBasisFunctionNode*>
4242
ReducedControlNodes; /*!< \brief Vector with selected control nodes in data reduction algorithm. */
4343

44-
vector<su2double> CtrlNodeDeformation; /*!< \brief Control Node Deformation.*/
45-
vector<su2double> InterpCoeff; /*!< \brief Control node interpolation coefficients.*/
44+
su2activematrix CtrlNodeDeformation; /*!< \brief Control Node Deformation.*/
45+
su2activematrix InterpCoeff; /*!< \brief Control node interpolation coefficients.*/
4646

4747
unsigned long nCtrlNodesGlobal{0}; /*!< \brief Total number of control nodes.*/
4848
su2activematrix CtrlCoords; /*!< \brief Coordinates of the control nodes.*/

Common/src/grid_movement/CRadialBasisFunctionInterpolation.cpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void CRadialBasisFunctionInterpolation::ComputeInterpolationMatrix(CGeometry* ge
241241
/*--- Looping over the control nodes ---*/
242242
for (auto jNode = iNode; jNode < nCtrlNodesGlobal; jNode++) {
243243
/*--- Distance between nodes ---*/
244-
auto dist = GeometryToolbox::Distance(nDim, CtrlCoords[iNode * nDim], CtrlCoords[jNode * nDim]);
244+
auto dist = GeometryToolbox::Distance(nDim, CtrlCoords[iNode], CtrlCoords[jNode]);
245245

246246
/*--- Evaluation of RBF ---*/
247247
interpMat(iNode, jNode) = SU2_TYPE::GetValue(CRadialBasisFunction::Get_RadialBasisValue(type, radius, dist));
@@ -259,8 +259,8 @@ void CRadialBasisFunctionInterpolation::ComputeInterpolationMatrix(CGeometry* ge
259259
}
260260

261261
void CRadialBasisFunctionInterpolation::SetDeformation(CGeometry* geometry, CConfig* config) {
262-
/* --- Initialization of the deformation vector ---*/
263-
CtrlNodeDeformation.resize(ControlNodes->size() * nDim, 0.0);
262+
/*--- Initialization of the deformation vector ---*/
263+
CtrlNodeDeformation.resize(ControlNodes->size(), nDim) = su2double(0.0);
264264

265265
/*--- If requested (no by default) impose the surface deflections in
266266
increments and solve the grid deformation with
@@ -275,12 +275,12 @@ void CRadialBasisFunctionInterpolation::SetDeformation(CGeometry* geometry, CCon
275275
* ---*/
276276
if (IsDeformationMarker(config, iMarker)) {
277277
for (auto iDim = 0u; iDim < nDim; iDim++) {
278-
CtrlNodeDeformation[iNode * nDim + iDim] = SU2_TYPE::GetValue(
278+
CtrlNodeDeformation(iNode, iDim) = SU2_TYPE::GetValue(
279279
geometry->vertex[iMarker][(*ControlNodes)[iNode]->GetVertex()]->GetVarCoord()[iDim] * VarIncrement);
280280
}
281281
} else {
282282
for (auto iDim = 0u; iDim < nDim; iDim++) {
283-
CtrlNodeDeformation[iNode * nDim + iDim] = 0.0;
283+
CtrlNodeDeformation(iNode, iDim) = 0.0;
284284
}
285285
}
286286
}
@@ -301,7 +301,7 @@ void CRadialBasisFunctionInterpolation::SetDeformation(CGeometry* geometry, CCon
301301
/*--- Gathering all deformation vectors on the master node ---*/
302302
if (rank == MASTER_NODE) {
303303
/*--- resizing the global deformation vector ---*/
304-
CtrlNodeDeformation.resize(nCtrlNodesGlobal * nDim);
304+
CtrlNodeDeformation.resize(nCtrlNodesGlobal, nDim);
305305

306306
/*--- Receiving the local deformation vector from other processes ---*/
307307
unsigned long start_idx = 0;
@@ -380,17 +380,16 @@ void CRadialBasisFunctionInterpolation::SetInternalNodes(CGeometry* geometry, CC
380380

381381
void CRadialBasisFunctionInterpolation::ComputeInterpCoeffs(su2passivematrix& invInterpMat) {
382382
/*--- resizing the interpolation coefficient vector ---*/
383-
InterpCoeff.resize(nDim * nCtrlNodesGlobal);
383+
InterpCoeff.resize(nCtrlNodesGlobal, nDim) = su2double(0.0);
384384

385385
/*--- Coefficients are found on the master process.
386386
Resulting coefficient is found by summing the multiplications of inverse interpolation matrix entries with
387387
deformation ---*/
388388
if (rank == MASTER_NODE) {
389389
for (auto iNode = 0ul; iNode < nCtrlNodesGlobal; iNode++) {
390-
for (auto iDim = 0u; iDim < nDim; iDim++) {
391-
InterpCoeff[iNode * nDim + iDim] = 0;
392-
for (auto jNode = 0ul; jNode < nCtrlNodesGlobal; jNode++) {
393-
InterpCoeff[iNode * nDim + iDim] += invInterpMat(iNode, jNode) * CtrlNodeDeformation[jNode * nDim + iDim];
390+
for (auto jNode = 0ul; jNode < nCtrlNodesGlobal; jNode++) {
391+
for (auto iDim = 0u; iDim < nDim; iDim++) {
392+
InterpCoeff(iNode, iDim) += invInterpMat(iNode, jNode) * CtrlNodeDeformation(jNode, iDim);
394393
}
395394
}
396395
}
@@ -432,15 +431,14 @@ void CRadialBasisFunctionInterpolation::UpdateInternalCoords(CGeometry* geometry
432431
/*--- Loop for contribution of each control node ---*/
433432
for (auto jNode = 0ul; jNode < nCtrlNodesGlobal; jNode++) {
434433
/*--- Determine distance between considered internal and control node ---*/
435-
auto dist =
436-
GeometryToolbox::Distance(nDim, CtrlCoords[jNode * nDim], geometry->nodes->GetCoord(internalNodes[iNode]));
434+
auto dist = GeometryToolbox::Distance(nDim, CtrlCoords[jNode], geometry->nodes->GetCoord(internalNodes[iNode]));
437435

438436
/*--- Evaluate RBF based on distance ---*/
439437
auto rbf = SU2_TYPE::GetValue(CRadialBasisFunction::Get_RadialBasisValue(type, radius, dist));
440438

441439
/*--- Add contribution to total coordinate variation ---*/
442440
for (auto iDim = 0u; iDim < nDim; iDim++) {
443-
var_coord[iDim] += rbf * InterpCoeff[jNode * nDim + iDim];
441+
var_coord[iDim] += rbf * InterpCoeff(jNode, iDim);
444442
}
445443
}
446444

@@ -464,15 +462,15 @@ void CRadialBasisFunctionInterpolation::UpdateBoundCoords(CGeometry* geometry, C
464462
/*--- Finding contribution of each control node ---*/
465463
for (auto jNode = 0ul; jNode < nCtrlNodesGlobal; jNode++) {
466464
/*--- Distance of non-selected boundary node to control node ---*/
467-
auto dist = GeometryToolbox::Distance(nDim, CtrlCoords[jNode * nDim],
465+
auto dist = GeometryToolbox::Distance(nDim, CtrlCoords[jNode],
468466
geometry->nodes->GetCoord(BoundNodes[iNode]->GetIndex()));
469467

470468
/*--- Evaluation of the radial basis function based on the distance ---*/
471469
auto rbf = SU2_TYPE::GetValue(CRadialBasisFunction::Get_RadialBasisValue(type, radius, dist));
472470

473471
/*--- Computing and add the resulting coordinate variation ---*/
474472
for (auto iDim = 0u; iDim < nDim; iDim++) {
475-
var_coord[iDim] += rbf * InterpCoeff[jNode * nDim + iDim];
473+
var_coord[iDim] += rbf * InterpCoeff(jNode, iDim);
476474
}
477475
}
478476

@@ -488,7 +486,7 @@ void CRadialBasisFunctionInterpolation::UpdateBoundCoords(CGeometry* geometry, C
488486
for (auto jNode = 0ul; jNode < ControlNodes->size(); jNode++) {
489487
if (config->GetMarker_All_Moving((*ControlNodes)[jNode]->GetMarker())) {
490488
for (auto iDim = 0u; iDim < nDim; iDim++) {
491-
geometry->nodes->AddCoord((*ControlNodes)[jNode]->GetIndex(), iDim, CtrlNodeDeformation[jNode * nDim + iDim]);
489+
geometry->nodes->AddCoord((*ControlNodes)[jNode]->GetIndex(), iDim, CtrlNodeDeformation(jNode, iDim));
492490
}
493491
}
494492
}
@@ -514,18 +512,17 @@ void CRadialBasisFunctionInterpolation::GetInitMaxErrorNode(CGeometry* geometry,
514512
}
515513

516514
/*--- Account for the possibility of applying the deformation in multiple steps ---*/
517-
maxErrorLocal = sqrt(maxErrorLocal) / ((su2double)config->GetGridDef_Nonlinear_Iter());
515+
maxErrorLocal = sqrt(maxErrorLocal) / config->GetGridDef_Nonlinear_Iter();
518516
}
519517

520518
void CRadialBasisFunctionInterpolation::SetCtrlNodeCoords(CGeometry* geometry) {
521519
/*--- The coordinates of all control nodes are made available on all processes ---*/
522520

523521
/*--- resizing the matrix containing the global control node coordinates ---*/
524-
std::cout << nCtrlNodesGlobal << std::endl;
525-
CtrlCoords.resize(nCtrlNodesGlobal * nDim);
522+
CtrlCoords.resize(nCtrlNodesGlobal, nDim);
526523

527524
/*--- Array containing the local control node coordinates ---*/
528-
std::vector<su2double> localCoords(nDim * ControlNodes->size());
525+
std::vector<su2double> localCoords(ControlNodes->size() * nDim);
529526

530527
/*--- Storing local control node coordinates ---*/
531528
for (auto iNode = 0ul; iNode < ControlNodes->size(); iNode++) {
@@ -537,7 +534,7 @@ void CRadialBasisFunctionInterpolation::SetCtrlNodeCoords(CGeometry* geometry) {
537534

538535
/*--- Gathering local control node coordinate sizes on all processes. ---*/
539536
std::vector<int> LocalCoordsSizes(size);
540-
int localCoordsSize = nDim * ControlNodes->size();
537+
int localCoordsSize = localCoords.size();
541538
SU2_MPI::Allgather(&localCoordsSize, 1, MPI_INT, LocalCoordsSizes.data(), 1, MPI_INT, SU2_MPI::GetComm());
542539

543540
/*--- Array containing the starting indices for the allgatherv operation */
@@ -548,7 +545,7 @@ void CRadialBasisFunctionInterpolation::SetCtrlNodeCoords(CGeometry* geometry) {
548545
}
549546

550547
/*--- Distributing global control node coordinates among all processes ---*/
551-
SU2_MPI::Allgatherv(&localCoords, localCoordsSize, MPI_DOUBLE, CtrlCoords.data(), LocalCoordsSizes.data(),
548+
SU2_MPI::Allgatherv(localCoords.data(), localCoordsSize, MPI_DOUBLE, CtrlCoords.data(), LocalCoordsSizes.data(),
552549
disps.data(), MPI_DOUBLE, SU2_MPI::GetComm());
553550
}
554551

@@ -604,15 +601,15 @@ void CRadialBasisFunctionInterpolation::GetNodalError(CGeometry* geometry, CConf
604601
/*--- Finding contribution of each control node ---*/
605602
for (auto jNode = 0ul; jNode < nCtrlNodesGlobal; jNode++) {
606603
/*--- Distance between non-selected boundary node and control node ---*/
607-
auto dist = GeometryToolbox::Distance(nDim, CtrlCoords[jNode * nDim],
608-
geometry->nodes->GetCoord(BoundNodes[iNode]->GetIndex()));
604+
auto dist =
605+
GeometryToolbox::Distance(nDim, CtrlCoords[jNode], geometry->nodes->GetCoord(BoundNodes[iNode]->GetIndex()));
609606

610607
/*--- Evaluation of Radial Basis Function ---*/
611608
auto rbf = SU2_TYPE::GetValue(CRadialBasisFunction::Get_RadialBasisValue(type, radius, dist));
612609

613610
/*--- Add contribution to error ---*/
614611
for (auto iDim = 0u; iDim < nDim; iDim++) {
615-
localError[iDim] += rbf * InterpCoeff[jNode * nDim + iDim];
612+
localError[iDim] += rbf * InterpCoeff(jNode, iDim);
616613
}
617614
}
618615
}

0 commit comments

Comments
 (0)