Skip to content

Commit 576d52a

Browse files
committed
Reworked consecutive handling for multiple dv markers.
1 parent 16a7e47 commit 576d52a

4 files changed

Lines changed: 97 additions & 59 deletions

File tree

SU2_CFD/include/solvers/CGradientSmoothingSolver.hpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class CGradientSmoothingSolver final : public CFEASolverBase {
6666

6767
CSquareMatrixCM hessian; /*!< \brief The approximated Hessian with respect to the design variables. */
6868

69+
std::vector<bool> visited; /*! <\brief Stores already visited points for surface applications with multiple markers. */
70+
6971
/*!
7072
* \brief The highest level in the variable hierarchy all derived solvers can safely use,
7173
* CVariable is the common denominator between the FEA and Mesh deformationd variables.
@@ -190,9 +192,10 @@ class CGradientSmoothingSolver final : public CFEASolverBase {
190192

191193
/*!
192194
* \brief Record a tape containing the parameter Jacobian.
193-
* \param geometry
194-
* \param config
195-
* \param surface_movement
195+
* \param geometry - Geometrical definition of the problem.
196+
* \param surface_movement - Surface movement of the problem.
197+
* \param registeredCoord - Indexes of the affected coordinates.
198+
* \param config - Definition of the particular problem.
196199
*/
197200
void RecordParameterizationJacobian(CGeometry *geometry,
198201
CSurfaceMovement *surface_movement,
@@ -201,9 +204,6 @@ class CGradientSmoothingSolver final : public CFEASolverBase {
201204

202205
/*!
203206
* \brief Forward evaluate parameterization Jacobian.
204-
* \param geometry
205-
* \param config
206-
* \param surface_movement
207207
*/
208208
void ProjectDVtoMesh(CGeometry *geometry,
209209
std::vector<su2double>& seeding,
@@ -213,9 +213,6 @@ class CGradientSmoothingSolver final : public CFEASolverBase {
213213

214214
/*!
215215
* \brief Reverse evaluate parameterization Jacobian.
216-
* \param geometry
217-
* \param config
218-
* \param surface_movement
219216
*/
220217
void ProjectMeshToDV(CGeometry *geometry,
221218
CSysVector<su2matvecscalar>& sensitivity,
@@ -235,6 +232,14 @@ class CGradientSmoothingSolver final : public CFEASolverBase {
235232
*/
236233
void ReadSensFromGeometry(const CGeometry *geometry) override;
237234

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+
238243
private:
239244
/*!
240245
* \brief Write the solution of the linear solver into the sensitivities of the nodes
@@ -268,6 +273,12 @@ class CGradientSmoothingSolver final : public CFEASolverBase {
268273
*/
269274
void Set_VertexEliminationSchedule(CGeometry* geometry, const CConfig* config);
270275

276+
/*!
277+
* \brief Complete the calculation of the surface stiffness matrix
278+
* \param[in] geometry - Geometrical definition of the problem.
279+
*/
280+
void Complete_Surface_StiffMatrix(const CGeometry* geometry);
281+
271282
/*!
272283
* \brief Get the element container index and number of nodes of a given VTK type.
273284
* \param[in] VTK_Type - Type of element.

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4188,6 +4188,14 @@ class CSolver {
41884188
*/
41894189
virtual void WriteSensToGeometry(CGeometry* geometry) const {}
41904190

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+
41914199
/*!
41924200
* \brief Routine that sets the flag controlling implicit treatment for periodic BCs.
41934201
* \param[in] val_implicit_periodic - Flag controlling implicit treatment for periodic BCs.

SU2_CFD/src/solvers/CGradientSmoothingSolver.cpp

Lines changed: 62 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ CGradientSmoothingSolver::CGradientSmoothingSolver(CGeometry *geometry, CConfig
9595
LinSysRes.Initialize(nPoint, nPointDomain, 1, 0.0);
9696
Jacobian.Initialize(nPoint, nPointDomain, 1, 1, false, geometry, config, false, true);
9797
}
98+
visited.resize(geometry->GetnPoint(), false);
9899
}
99100

100101
/*--- vectors needed for projection when working on the complete system ---*/
@@ -201,9 +202,11 @@ void CGradientSmoothingSolver::ApplyGradientSmoothingSurface(CGeometry* geometry
201202
LinSysSol.SetValZero();
202203
LinSysRes.SetValZero();
203204
Jacobian.SetValZero();
205+
std::fill(visited.begin(), visited.end(), false);
204206

205207
/*--- Compute the stiffness matrix for the smoothing operator. ---*/
206208
Compute_Surface_StiffMatrix(geometry, numerics, config, val_marker);
209+
Complete_Surface_StiffMatrix(geometry);
207210

208211
Compute_Surface_Residual(geometry, config, val_marker);
209212

@@ -397,18 +400,12 @@ void CGradientSmoothingSolver::Compute_Surface_StiffMatrix(CGeometry* geometry,
397400
std::array<unsigned long, MAXNNODE_2D> indexVertex;
398401
int EL_KIND = 0;
399402
su2double val_Coord, HiHj = 0.0;
400-
su2activematrix DHiDHj, Jacobian_block, mId_Aux;
403+
su2activematrix DHiDHj, Jacobian_block;
401404

402405
Jacobian_block.resize(nDim, nDim) = su2double(0.0);
403-
mId_Aux.resize(nDim, nDim) = su2double(0.0);
404-
for (iDim = 0; iDim < nDim; iDim++) {
405-
mId_Aux[iDim][iDim] = su2double(1.0);
406-
}
407-
408-
vector<bool> visited(geometry->GetnPoint(), false);
409406

410407
/*--- Check if the current MPI rank has a part of the marker ---*/
411-
if (val_marker!=NOT_AVAILABLE) {
408+
if (val_marker!=BC_TYPE::NOT_AVAILABLE) {
412409

413410
/*--- Loops over all the elements ---*/
414411
for (iElem = 0; iElem < geometry->GetnElem_Bound(val_marker); iElem++) {
@@ -463,13 +460,6 @@ void CGradientSmoothingSolver::Compute_Surface_StiffMatrix(CGeometry* geometry,
463460
}
464461
}
465462

466-
/*--- Assembling the stiffness matrix on the design surface means the Jacobian is the identity for nodes inside the domain. ---*/
467-
for (iPoint = 0; iPoint < geometry->GetnPointDomain(); iPoint++){
468-
if (visited[iPoint]==false) {
469-
Jacobian.AddBlock(iPoint, iPoint, mId_Aux);
470-
}
471-
}
472-
473463
}
474464

475465
void CGradientSmoothingSolver::Compute_Residual(CGeometry* geometry, const CConfig* config) {
@@ -539,7 +529,7 @@ void CGradientSmoothingSolver::Compute_Surface_Residual(CGeometry* geometry, con
539529
su2double* normal = NULL;
540530

541531
/*--- Check if the current MPI rank has a part of the marker ---*/
542-
if (val_marker!=NOT_AVAILABLE) {
532+
if (val_marker!=BC_TYPE::NOT_AVAILABLE) {
543533

544534
for (iElem = 0; iElem < geometry->GetnElem_Bound(val_marker); iElem++) {
545535

@@ -637,7 +627,7 @@ void CGradientSmoothingSolver::BC_Surface_Dirichlet(const CGeometry* geometry, c
637627
const su2double zeros[MAXNDIM] = {0.0};
638628

639629
/*--- Check if the current MPI rank has a part of the marker ---*/
640-
if (val_marker!=NOT_AVAILABLE) {
630+
if (val_marker!=BC_TYPE::NOT_AVAILABLE) {
641631
for (iVertex = 0; iVertex < geometry->nVertex[val_marker]; iVertex++) {
642632

643633
/*--- Get node index ---*/
@@ -680,17 +670,15 @@ template <typename scalar_type>
680670
CSysMatrixVectorProduct<scalar_type> CGradientSmoothingSolver::GetStiffnessMatrixVectorProduct(CGeometry* geometry,
681671
CNumerics* numerics,
682672
const CConfig* config) {
683-
bool surf = config->GetSmoothOnSurface();
684673

685674
/*--- Compute the sparse stiffness matrix ---*/
686-
if (surf) {
687-
unsigned long dvMarker=NOT_AVAILABLE;
688-
for (unsigned int iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++) {
689-
if ( config->GetMarker_All_DV(iMarker) == YES ) {
690-
dvMarker=iMarker;
675+
if (config->GetSmoothOnSurface()) {
676+
for (unsigned int iMarker = 0; iMarker < config->GetnMarker_CfgFile(); iMarker++) {
677+
if (config->GetMarker_All_DV(iMarker) == YES) {
678+
Compute_Surface_StiffMatrix(geometry, numerics, config, iMarker, nDim);
691679
}
692680
}
693-
Compute_Surface_StiffMatrix(geometry, numerics, config, dvMarker, nDim);
681+
Complete_Surface_StiffMatrix(geometry);
694682
} else {
695683
Compute_StiffMatrix(geometry, numerics, config);
696684
}
@@ -917,7 +905,7 @@ void CGradientSmoothingSolver::WriteSensitivity(CGeometry* geometry, const CConf
917905

918906
/*--- 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 ---*/
919907
if ( config->GetSmoothOnSurface() ) {
920-
if( val_marker!=NOT_AVAILABLE ) {
908+
if( val_marker!=BC_TYPE::NOT_AVAILABLE ) {
921909
for (unsigned long iVertex =0; iVertex<geometry->nVertex[val_marker]; iVertex++) {
922910
iPoint = geometry->vertex[val_marker][iVertex]->GetNode();
923911
normal = geometry->vertex[val_marker][iVertex]->GetNormal();
@@ -980,23 +968,25 @@ void CGradientSmoothingSolver::Set_VertexEliminationSchedule(CGeometry* geometry
980968
if (config->GetSmoothOnSurface()) {
981969

982970
/*--- Find Marker_DV if this node has any ---*/
983-
unsigned long dvMarker=NOT_AVAILABLE;
971+
unsigned long dvMarker=BC_TYPE::NOT_AVAILABLE;
984972
for (unsigned short iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++) {
985-
if (config->GetMarker_All_DV(iMarker) == YES) {
986-
dvMarker = iMarker;
987-
}
988-
}
989-
990-
/*--- Surface case:
991-
* Fix design boundary border if Dirichlet condition is set and the current rank holds part of it. ---*/
992-
if ( config->GetDirichletSurfaceBound() && dvMarker!=NOT_AVAILABLE) {
993-
for (iVertex = 0; iVertex < geometry->nVertex[dvMarker]; iVertex++) {
994-
/*--- Get node index ---*/
995-
iPoint = geometry->vertex[dvMarker][iVertex]->GetNode();
996-
if (nodes->GetIsBoundaryPoint(iPoint)) {
997-
myPoints.push_back(geometry->nodes->GetGlobalIndex(iPoint));
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++) {
982+
/*--- Get node index ---*/
983+
iPoint = geometry->vertex[dvMarker][iVertex]->GetNode();
984+
if (nodes->GetIsBoundaryPoint(iPoint)) {
985+
myPoints.push_back(geometry->nodes->GetGlobalIndex(iPoint));
986+
}
998987
}
999988
}
989+
1000990
}
1001991

1002992
} else {
@@ -1024,3 +1014,36 @@ void CGradientSmoothingSolver::Set_VertexEliminationSchedule(CGeometry* geometry
10241014
Jacobian.EnforceSolutionAtNode(iPoint, LinSysSol.GetBlock(iPoint), LinSysRes);
10251015
}
10261016
}
1017+
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+
1034+
void CGradientSmoothingSolver::Complete_Surface_StiffMatrix(const CGeometry* geometry) {
1035+
1036+
su2activematrix mId_Aux;
1037+
mId_Aux.resize(nDim, nDim) = su2double(0.0);
1038+
for (unsigned iDim = 0; iDim < nDim; iDim++) {
1039+
mId_Aux[iDim][iDim] = su2double(1.0);
1040+
}
1041+
1042+
/*--- Assembling the stiffness matrix on the design surface means the Jacobian is the identity for nodes inside the domain. ---*/
1043+
for (unsigned long iPoint = 0; iPoint < geometry->GetnPointDomain(); iPoint++){
1044+
if (visited[iPoint]==false) {
1045+
Jacobian.AddBlock(iPoint, iPoint, mId_Aux);
1046+
}
1047+
}
1048+
1049+
}

SU2_DOT/src/SU2_DOT.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,19 +1003,15 @@ 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-
/*--- Select DV marker, or NOT_AVAILABLE if none is specified. ---*/
1007-
unsigned long ndvMarker=0, dvMarker = BC_TYPE::NOT_AVAILABLE;
1008-
for (unsigned short iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++) {
1009-
if ( config->GetMarker_All_DV(iMarker) == YES ) {
1010-
dvMarker = iMarker;
1011-
++ndvMarker;
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);
10121013
}
10131014
}
1014-
if(ndvMarker>1) {
1015-
SU2_MPI::Error("Sobolev smoothing in surface mode only works with one marker at a time.",CURRENT_FUNCTION);
1016-
}
1017-
1018-
solver->ApplyGradientSmoothingSurface(geometry, numerics, config, dvMarker);
10191015

10201016
/*--- After appling the solver write the results back ---*/
10211017
solver->WriteSensToGeometry(geometry);

0 commit comments

Comments
 (0)