Skip to content

Commit 0630b4a

Browse files
committed
Reworked surface smoothing handling for multiple design markers.
Extended zone number to output files for multizone problems.
1 parent ca8b8ef commit 0630b4a

4 files changed

Lines changed: 58 additions & 90 deletions

File tree

SU2_CFD/include/solvers/CGradientSmoothingSolver.hpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ class CGradientSmoothingSolver final : public CFEASolverBase {
100100
* \brief Main routine to apply the method only on the surface for mesh sensitivities
101101
* Projects and smoothes only in the normal direction!
102102
*/
103-
void ApplyGradientSmoothingSurface(CGeometry* geometry, CNumerics* numerics, const CConfig* config,
104-
unsigned long val_marker) override;
103+
void ApplyGradientSmoothingSurface(CGeometry* geometry, CNumerics* numerics, const CConfig* config) override;
105104

106105
/*!
107106
* \brief All steps required for smoothing the whole system on DV level in an iterative way
@@ -232,19 +231,11 @@ class CGradientSmoothingSolver final : public CFEASolverBase {
232231
*/
233232
void ReadSensFromGeometry(const CGeometry *geometry) override;
234233

235-
/*!
236-
* \brief Helper function for derivative treatment.
237-
* to determine if a boundary marker is a DVmarker on any mpi rank.
238-
* \param[in] iMarker - the current boundary marker.
239-
* \param[in] config - Definition of the particular problem.
240-
*/
241-
bool MarkerIsDVMarker(unsigned short iMarker, const CConfig *config) const override;
242-
243234
private:
244235
/*!
245236
* \brief Write the solution of the linear solver into the sensitivities of the nodes
246237
*/
247-
void WriteSensitivity(CGeometry* geometry, const CConfig* config, unsigned long val_marker = 0);
238+
void WriteSensitivity(CGeometry* geometry, const CConfig* config);
248239

249240
/*!
250241
* \brief Copy sensitivities from a vector into the geometry

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4151,8 +4151,7 @@ class CSolver {
41514151
* \param[in] config - Definition of the particular problem.
41524152
*
41534153
*/
4154-
virtual void ApplyGradientSmoothingSurface(CGeometry* geometry, CNumerics* numerics, const CConfig* config,
4155-
unsigned long val_marker) {}
4154+
virtual void ApplyGradientSmoothingSurface(CGeometry* geometry, CNumerics* numerics, const CConfig* config) {}
41564155

41574156
/*!
41584157
* \brief All steps required for smoothing the whole system on DV level in an iterative way
@@ -4188,14 +4187,6 @@ class CSolver {
41884187
*/
41894188
virtual void WriteSensToGeometry(CGeometry* geometry) const {}
41904189

4191-
/*!
4192-
* \brief Helper function for derivative treatment.
4193-
* to determine if a boundary marker is a DVmarker on any mpi rank.
4194-
* \param[in] imMarker - the current boundary marker.
4195-
* \param[in] config - Definition of the particular problem.
4196-
*/
4197-
virtual bool MarkerIsDVMarker(unsigned short iMarker, const CConfig *config) const { return false; };
4198-
41994190
/*!
42004191
* \brief Routine that sets the flag controlling implicit treatment for periodic BCs.
42014192
* \param[in] val_implicit_periodic - Flag controlling implicit treatment for periodic BCs.

SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ CGradientSmoothingSolver::CGradientSmoothingSolver(CGeometry *geometry, CConfig
9999
}
100100

101101
/*--- vectors needed for projection when working on the complete system ---*/
102-
if (config->GetSobMode() == ENUM_SOBOLEV_MODUS::PARAM_LEVEL_COMPLETE || config->GetSobMode() == ENUM_SOBOLEV_MODUS::ONLY_GRAD) {
102+
if (config->GetSobMode() == ENUM_SOBOLEV_MODUS::PARAM_LEVEL_COMPLETE ||
103+
config->GetSobMode() == ENUM_SOBOLEV_MODUS::ONLY_GRAD || config->GetSobMode() == ENUM_SOBOLEV_MODUS::MESH_LEVEL) {
103104
activeCoord.Initialize(nPoint, nPointDomain, nDim, 0.0);
104105
helperVecIn.Initialize(nPoint, nPointDomain, nDim, 0.0);
105106
helperVecOut.Initialize(nPoint, nPointDomain, nDim, 0.0);
@@ -197,27 +198,34 @@ void CGradientSmoothingSolver::ApplyGradientSmoothingVolume(CGeometry* geometry,
197198
}
198199

199200
void CGradientSmoothingSolver::ApplyGradientSmoothingSurface(CGeometry* geometry, CNumerics* numerics,
200-
const CConfig* config, unsigned long val_marker) {
201+
const CConfig* config) {
201202
/*--- Set vector and sparse matrix to 0 ---*/
202203
LinSysSol.SetValZero();
203204
LinSysRes.SetValZero();
204205
Jacobian.SetValZero();
205206
std::fill(visited.begin(), visited.end(), false);
206207

207-
/*--- Compute the stiffness matrix for the smoothing operator. ---*/
208-
Compute_Surface_StiffMatrix(geometry, numerics, config, val_marker);
209-
Complete_Surface_StiffMatrix(geometry);
208+
/*--- Loop over all DV markers to compute the stiffness matrix for the smoothing operator. ---*/
209+
for (unsigned short iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++) {
210+
if (config->GetMarker_All_DV(iMarker) == YES) {
211+
/*--- Compute the stiffness matrix for the smoothing operator. ---*/
212+
Compute_Surface_StiffMatrix(geometry, numerics, config, iMarker);
210213

211-
Compute_Surface_Residual(geometry, config, val_marker);
214+
Compute_Surface_Residual(geometry, config, iMarker);
212215

213-
if ( config->GetDirichletSurfaceBound() ) {
214-
BC_Surface_Dirichlet(geometry, config, val_marker);
216+
if (config->GetDirichletSurfaceBound()) {
217+
BC_Surface_Dirichlet(geometry, config, iMarker);
218+
}
219+
}
215220
}
216221

222+
/*--- Set the matrix to identity if the current mpi rank holds no part of the DV marker. ---*/
223+
Complete_Surface_StiffMatrix(geometry);
224+
217225
/*--- Solve the system and write the result back. ---*/
218226
Solve_Linear_System(geometry, config);
219227

220-
WriteSensitivity(geometry, config, val_marker);
228+
WriteSensitivity(geometry, config);
221229
}
222230

223231
void CGradientSmoothingSolver::ApplyGradientSmoothingDV(CGeometry *geometry, CNumerics *numerics, CSurfaceMovement *surface_movement, CVolumetricMovement *grid_movement, CConfig *config, su2double** Gradient) {
@@ -312,8 +320,12 @@ void CGradientSmoothingSolver::ApplyGradientSmoothingDV(CGeometry *geometry, CNu
312320

313321
/*--- Output the complete system matrix. ---*/
314322
if (rank == MASTER_NODE) {
315-
ofstream SysMatrix(config->GetObjFunc_Hess_FileName());
323+
/*--- For multizone append zone number to filename. ---*/
324+
string hess_filename = config->GetObjFunc_Hess_FileName();
325+
if (config->GetnZone() > 1) config->GetMultizone_FileName(hess_filename, config->GetiZone(), ".dat");
326+
ofstream SysMatrix(hess_filename);
316327
SysMatrix.precision(config->GetOutput_Precision());
328+
317329
for (row=0; row<nDVtotal; row++) {
318330
for (column=0; column<nDVtotal; column++) {
319331
SysMatrix << hessian(row,column);
@@ -725,8 +737,11 @@ void CGradientSmoothingSolver::RecordTapeAndCalculateOriginalGradient(CGeometry
725737
void CGradientSmoothingSolver::OutputDVGradient(const CConfig* config, string out_file) {
726738
unsigned iDV;
727739
if (rank == MASTER_NODE) {
740+
/*--- For multizone append zone number to filename. ---*/
741+
if (config->GetnZone() > 1) config->GetMultizone_FileName(out_file, config->GetiZone(), ".dat");
728742
ofstream delta_p (out_file);
729743
delta_p.precision(config->GetOutput_Precision());
744+
730745
for (iDV = 0; iDV < deltaP.size(); iDV++) {
731746
delta_p << deltaP[iDV] << ",";
732747
}
@@ -897,28 +912,31 @@ void CGradientSmoothingSolver::ReadSensFromGeometry(const CGeometry* geometry) {
897912
}
898913
}
899914

900-
void CGradientSmoothingSolver::WriteSensitivity(CGeometry* geometry, const CConfig* config, unsigned long val_marker) {
915+
void CGradientSmoothingSolver::WriteSensitivity(CGeometry* geometry, const CConfig* config) {
901916
unsigned long iPoint, total_index;
902917
unsigned int iDim;
903918
su2double* normal;
904919
su2double norm;
905920

906-
/*--- split between surface and volume first, to avoid mpi ranks with no part of the marker to write back nonphysical solutions in the surface case ---*/
921+
/*--- Split between surface and volume first. ---*/
907922
if ( config->GetSmoothOnSurface() ) {
908-
if( val_marker!=BC_TYPE::NOT_AVAILABLE ) {
909-
for (unsigned long iVertex =0; iVertex<geometry->nVertex[val_marker]; iVertex++) {
910-
iPoint = geometry->vertex[val_marker][iVertex]->GetNode();
911-
normal = geometry->vertex[val_marker][iVertex]->GetNormal();
912-
norm = 0.0;
913-
for (iDim = 0; iDim < nDim; iDim++) {
914-
norm += normal[iDim]*normal[iDim];
915-
}
916-
norm = sqrt(norm);
917-
for (iDim = 0; iDim < nDim; iDim++) {
918-
normal[iDim] = normal[iDim] / norm;
919-
}
920-
for (iDim = 0; iDim < nDim; iDim++) {
921-
nodes->SetSensitivity(iPoint, iDim, normal[iDim]*LinSysSol[iPoint]);
923+
/*--- Write back values for all design boundaries in the surface case. ---*/
924+
for (unsigned short iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++) {
925+
if (config->GetMarker_All_DV(iMarker) == YES) {
926+
for (unsigned long iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++) {
927+
iPoint = geometry->vertex[iMarker][iVertex]->GetNode();
928+
normal = geometry->vertex[iMarker][iVertex]->GetNormal();
929+
norm = 0.0;
930+
for (iDim = 0; iDim < nDim; iDim++) {
931+
norm += normal[iDim] * normal[iDim];
932+
}
933+
norm = sqrt(norm);
934+
for (iDim = 0; iDim < nDim; iDim++) {
935+
normal[iDim] = normal[iDim] / norm;
936+
}
937+
for (iDim = 0; iDim < nDim; iDim++) {
938+
nodes->SetSensitivity(iPoint, iDim, normal[iDim] * LinSysSol[iPoint]);
939+
}
922940
}
923941
}
924942
}
@@ -966,27 +984,19 @@ void CGradientSmoothingSolver::Set_VertexEliminationSchedule(CGeometry* geometry
966984
/*--- get global indexes of Dirichlet boundaries ---*/
967985

968986
if (config->GetSmoothOnSurface()) {
969-
970-
/*--- Find Marker_DV if this node has any ---*/
971-
unsigned long dvMarker=BC_TYPE::NOT_AVAILABLE;
987+
/*--- Surface case:
988+
* Fix design boundary border if Dirichlet condition is set for the DV marker
989+
* and the current rank holds part of it. ---*/
972990
for (unsigned short iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++) {
973-
//if (MarkerIsDVMarker(iMarker, config)) {
974-
//dvMarker = BC_TYPE::NOT_AVAILABLE;
975-
if (config->GetMarker_All_DV(iMarker) == YES) dvMarker = iMarker;
976-
//}
977-
978-
/*--- Surface case:
979-
* Fix design boundary border if Dirichlet condition is set and the current rank holds part of it. ---*/
980-
if ( config->GetDirichletSurfaceBound() && dvMarker!=BC_TYPE::NOT_AVAILABLE) {
981-
for (iVertex = 0; iVertex < geometry->nVertex[dvMarker]; iVertex++) {
991+
if (config->GetMarker_All_DV(iMarker) == YES && config->GetDirichletSurfaceBound()) {
992+
for (iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++) {
982993
/*--- Get node index ---*/
983-
iPoint = geometry->vertex[dvMarker][iVertex]->GetNode();
994+
iPoint = geometry->vertex[iMarker][iVertex]->GetNode();
984995
if (nodes->GetIsBoundaryPoint(iPoint)) {
985996
myPoints.push_back(geometry->nodes->GetGlobalIndex(iPoint));
986997
}
987998
}
988999
}
989-
9901000
}
9911001

9921002
} else {
@@ -1015,22 +1025,6 @@ void CGradientSmoothingSolver::Set_VertexEliminationSchedule(CGeometry* geometry
10151025
}
10161026
}
10171027

1018-
bool CGradientSmoothingSolver::MarkerIsDVMarker(unsigned short iMarker, const CConfig *config) const {
1019-
1020-
int isLocalDVmarker, isGlobalDVmarker;
1021-
bool isDVmarker=false;
1022-
1023-
if ( config->GetMarker_All_DV(iMarker) == YES ) {
1024-
isLocalDVmarker = 1;
1025-
} else {
1026-
isLocalDVmarker = 0;
1027-
}
1028-
SU2_MPI::Allreduce(&isLocalDVmarker, &isGlobalDVmarker, 1, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm());
1029-
if (isGlobalDVmarker >= 1) isDVmarker=true;
1030-
1031-
return isDVmarker;
1032-
}
1033-
10341028
void CGradientSmoothingSolver::Complete_Surface_StiffMatrix(const CGeometry* geometry) {
10351029

10361030
su2activematrix mId_Aux;

SU2_DOT/src/SU2_DOT.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,15 +1003,8 @@ void DerivativeTreatment_MeshSensitivity(CGeometry *geometry, CConfig *config, C
10031003
/*--- Get the sensitivities from the geometry class to work with. ---*/
10041004
solver->ReadSensFromGeometry(geometry);
10051005

1006-
/*--- Perform the smoothing procedure sequentially for each DV marker. ---*/
1007-
unsigned long dvMarker;
1008-
for (unsigned short iMarker = 0; iMarker < config->GetnMarker_CfgFile(); iMarker++) {
1009-
if (solver->MarkerIsDVMarker(iMarker, config)) {
1010-
dvMarker = BC_TYPE::NOT_AVAILABLE;
1011-
if (config->GetMarker_All_DV(iMarker) == YES) dvMarker = iMarker;
1012-
solver->ApplyGradientSmoothingSurface(geometry, numerics, config, dvMarker);
1013-
}
1014-
}
1006+
/*--- Perform the smoothing procedure on all boundaries marked as DV marker. ---*/
1007+
solver->ApplyGradientSmoothingSurface(geometry, numerics, config);
10151008

10161009
/*--- After appling the solver write the results back ---*/
10171010
solver->WriteSensToGeometry(geometry);
@@ -1064,10 +1057,9 @@ void DerivativeTreatment_Gradient(CGeometry *geometry, CConfig *config, CVolumet
10641057
if (config->GetSobMode() == ENUM_SOBOLEV_MODUS::PARAM_LEVEL_COMPLETE) {
10651058
solver->ApplyGradientSmoothingDV(geometry, numerics, surface_movement, grid_movement, config, Gradient);
10661059

1067-
/*--- For some application, e.g. OneShot, we might only need the original gradient. ---*/
1068-
} else if (config->GetSobMode() == ENUM_SOBOLEV_MODUS::ONLY_GRAD) {
1060+
/*--- If smoothing already took place on the mesh level, or none is requested, just do standard projection. ---*/
1061+
} else if (config->GetSobMode() == ENUM_SOBOLEV_MODUS::ONLY_GRAD ||
1062+
config->GetSobMode() == ENUM_SOBOLEV_MODUS::MESH_LEVEL) {
10691063
solver->RecordTapeAndCalculateOriginalGradient(geometry, surface_movement, grid_movement, config, Gradient);
1070-
10711064
}
1072-
10731065
}

0 commit comments

Comments
 (0)