@@ -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
199200void 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
223231void 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
725737void 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-
10341028void CGradientSmoothingSolver::Complete_Surface_StiffMatrix (const CGeometry* geometry) {
10351029
10361030 su2activematrix mId_Aux ;
0 commit comments