Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Sobolev smoothing method to the discrete adjoint gradient calculation. #1446

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b11dbc1
Created a new branch containing a Sobolev smoothing solver for gradie…
thomasdick Nov 18, 2021
f29dcfc
Added Eigen as a submodule.
thomasdick Nov 18, 2021
c9a1cf3
Merge remote-tracking branch 'upstream/develop' into feature_Sobolev_…
thomasdick Nov 18, 2021
b41e5bb
Made second order Gauss quadrature the norm for finite elments in the…
thomasdick Nov 19, 2021
d03a8c5
Reworked comments for the Sobolev smoothing solver and fixed compiler…
thomasdick Nov 22, 2021
0a8685a
Added options for the smoothing solver to config_template.cfg.
thomasdick Nov 22, 2021
7b2d6ee
Removed dependency on Eigen from CGradientSmoothingSolver and removed…
thomasdick Nov 25, 2021
5492bfc
Reworked the way finite elements are used for embedded surfaces.
thomasdick Nov 25, 2021
e9c4cfc
Made the CSysSolver constructor option mesh_deform an enum class.
thomasdick Nov 26, 2021
231670e
Fixed a compiler warning created by missing initialization in CSysSol…
thomasdick Nov 29, 2021
4ee9c76
Merge remote-tracking branch 'upstream/develop' into HEAD
thomasdick Nov 29, 2021
e4b544b
Moved the application of Sobolev gradient smoothing to SU2_DOT_AD.
thomasdick Dec 2, 2021
8139884
Merge remote-tracking branch 'upstream/develop' into feature_Sobolev_…
thomasdick Dec 2, 2021
84122b1
Split the derivative treatment in SU2_DOT into 2 parts for mesh and d…
thomasdick Dec 3, 2021
81465a0
- Adapted calls to the volume deformation class after moving the gra…
thomasdick Dec 8, 2021
e4dfa58
Moved solver, numerics and variables file to according SU2_CFD subdir…
thomasdick Dec 8, 2021
eeb6081
Reintroduced the Kind_SensSmooth Config option and the ENUM_SENS_SMOO…
thomasdick Dec 9, 2021
1dfa00c
Reworked the meson.build for SU2_DOT and SU2_DOT_AD. Executables are …
thomasdick Dec 9, 2021
02de958
Apply suggestions from code review
thomasdick Dec 13, 2021
6df5603
Merge remote-tracking branch 'upstream/develop' into feature_Sobolev_…
thomasdick Dec 13, 2021
36bc84c
Apply more changes from code review.
thomasdick Dec 16, 2021
f738172
Various suggestions from code review.
thomasdick Dec 22, 2021
16a7e47
Merge remote-tracking branch 'upstream/develop' into feature_Sobolev_…
thomasdick Jan 10, 2022
576d52a
Reworked consecutive handling for multiple dv markers.
thomasdick Jan 11, 2022
ca8b8ef
Merge branch 'develop' into feature_Sobolev_smoothing_solver
thomasdick Jan 12, 2022
0630b4a
Reworked surface smoothing handling for multiple design markers.
thomasdick Jan 13, 2022
57e8c12
Merge branch 'develop' into feature_Sobolev_smoothing_solver
thomasdick Jan 13, 2022
db9d268
Fix for the regression test workflow.
thomasdick Jan 13, 2022
608cfb2
Apply suggestions from code review.
thomasdick Jan 13, 2022
f00eabb
Merge remote-tracking branch 'upstream/develop' into feature_Sobolev_…
thomasdick Jan 14, 2022
654b531
Apply more changes from code review.
thomasdick Jan 14, 2022
d138d8c
Apply changes from code review.
thomasdick Jan 17, 2022
67996c1
Use unique_ptr for gradient smoothing numerics in SU"_DOT.cpp.
thomasdick Jan 17, 2022
347ef7d
Added filediff reference files for the regression tests.
thomasdick Jan 20, 2022
5598ad2
Merge remote-tracking branch 'upstream/develop' into feature_Sobolev_…
thomasdick Jan 20, 2022
fa88da8
Merge branch 'develop' into feature_Sobolev_smoothing_solver
thomasdick Jan 20, 2022
78a856a
Merge branch 'develop' into feature_Sobolev_smoothing_solver
thomasdick Jan 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 140 additions & 16 deletions Common/include/CConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,20 @@ class CConfig {
Max_DeltaTime, /*!< \brief Max delta time. */
Unst_CFL; /*!< \brief Unsteady CFL number. */

/* Gradient smoothing options */
su2double SmoothingEps1; /*!< \brief Parameter for the identity part in gradient smoothing. */
su2double SmoothingEps2; /*!< \brief Parameter for the Laplace part in gradient smoothing. */
bool SmoothGradient; /*!< \brief Flag for enabling gradient smoothing. */
bool SmoothSepDim; /*!< \brief Flag for enabling separated calculation for every dimension. */
bool SmoothOnSurface; /*!< \brief Flag for assembling the system only on the surface. */
bool SmoothDirichletSurfaceBound; /*!< \brief Flag for using zero Dirichlet boundary in the surface case. */
ENUM_SOBOLEV_MODUS SmoothNumMode; /*!< \brief The mode in which the Sobolev smoothing solver is applied. */

unsigned short Kind_Grad_Linear_Solver, /*!< Numerical method to smooth the gradient */
Kind_Grad_Linear_Solver_Prec; /*!< \brief Preconditioner of the linear solver. */
su2double Grad_Linear_Solver_Error; /*!< \brief Min error of the linear solver for the gradient smoothing. */
unsigned long Grad_Linear_Solver_Iter; /*!< \brief Max iterations of the linear solver for the gradient smoothing. */

bool ReorientElements; /*!< \brief Flag for enabling element reorientation. */
string CustomObjFunc; /*!< \brief User-defined objective function. */
unsigned short nDV, /*!< \brief Number of design variables. */
Expand Down Expand Up @@ -676,7 +690,8 @@ class CConfig {
nMarker_Moving, /*!< \brief Number of markers in motion (DEFORMING, MOVING_WALL). */
nMarker_PyCustom, /*!< \brief Number of markers that are customizable in Python. */
nMarker_DV, /*!< \brief Number of markers affected by the design variables. */
nMarker_WallFunctions; /*!< \brief Number of markers for which wall functions must be applied. */
nMarker_WallFunctions, /*!< \brief Number of markers for which wall functions must be applied. */
nMarker_SobolevBC; /*!< \brief Number of markers treaded in the gradient problem. */
string *Marker_Monitoring, /*!< \brief Markers to monitor. */
*Marker_Designing, /*!< \brief Markers to design. */
*Marker_GeoEval, /*!< \brief Markers to evaluate geometry. */
Expand All @@ -686,7 +701,8 @@ class CConfig {
*Marker_Moving, /*!< \brief Markers in motion (DEFORMING, MOVING_WALL). */
*Marker_PyCustom, /*!< \brief Markers that are customizable in Python. */
*Marker_DV, /*!< \brief Markers affected by the design variables. */
*Marker_WallFunctions; /*!< \brief Markers for which wall functions must be applied. */
*Marker_WallFunctions, /*!< \brief Markers for which wall functions must be applied. */
*Marker_SobolevBC; /*!< \brief Markers in the gradient solver */

unsigned short nConfig_Files; /*!< \brief Number of config files for multiphysics problems. */
string *Config_Filenames; /*!< \brief List of names for configuration files. */
Expand All @@ -708,6 +724,7 @@ class CConfig {
*Marker_All_Fluid_Load, /*!< \brief Global index for markers in which the flow load is computed/employed. */
*Marker_All_PyCustom, /*!< \brief Global index for Python customizable surfaces using the grid information. */
*Marker_All_Designing, /*!< \brief Global index for moving using the grid information. */
*Marker_All_SobolevBC, /*!< \brief Global index for boundary condition applied to gradient smoothing. */
*Marker_CfgFile_Monitoring, /*!< \brief Global index for monitoring using the config information. */
*Marker_CfgFile_Designing, /*!< \brief Global index for monitoring using the config information. */
*Marker_CfgFile_GeoEval, /*!< \brief Global index for monitoring using the config information. */
Expand All @@ -723,7 +740,8 @@ class CConfig {
*Marker_CfgFile_Fluid_Load, /*!< \brief Global index for markers in which the flow load is computed/employed. */
*Marker_CfgFile_PyCustom, /*!< \brief Global index for Python customizable surfaces using the config information. */
*Marker_CfgFile_DV, /*!< \brief Global index for design variable markers using the config information. */
*Marker_CfgFile_PerBound; /*!< \brief Global index for periodic boundaries using the config information. */
*Marker_CfgFile_PerBound, /*!< \brief Global index for periodic boundaries using the config information. */
*Marker_CfgFile_SobolevBC; /*!< \brief Global index for boundary condition applied to gradient smoothing using the config information. */
string *PlaneTag; /*!< \brief Global index for the plane adaptation (upper, lower). */
su2double *nBlades; /*!< \brief number of blades for turbomachinery computation. */
unsigned short Geo_Description; /*!< \brief Description of the geometry. */
Expand Down Expand Up @@ -767,7 +785,8 @@ class CConfig {
SurfCoeff_FileName, /*!< \brief Output file with the flow variables on the surface. */
SurfAdjCoeff_FileName, /*!< \brief Output file with the adjoint variables on the surface. */
SurfSens_FileName, /*!< \brief Output file for the sensitivity on the surface (discrete adjoint). */
VolSens_FileName; /*!< \brief Output file for the sensitivity in the volume (discrete adjoint). */
VolSens_FileName, /*!< \brief Output file for the sensitivity in the volume (discrete adjoint). */
ObjFunc_Hess_FileName; /*!< \brief Hessian approximation obtained by the Sobolev smoothing solver. */

bool
Wrt_Performance, /*!< \brief Write the performance summary at the end of a calculation. */
Expand Down Expand Up @@ -2787,6 +2806,18 @@ class CConfig {
*/
unsigned short GetnDV_Value(unsigned short iDV) const { return nDV_Value[iDV]; }

/*!
* \brief Get the total number of design variables.
*/
unsigned short GetnDV_Total(void) const {
if (!nDV_Value) return 0;
unsigned short sum = 0;
for (unsigned short iDV = 0; iDV < nDV; iDV++) {
sum += nDV_Value[iDV];
}
return sum;
}

/*!
* \brief Get the number of FFD boxes.
* \return Number of FFD boxes.
Expand Down Expand Up @@ -2967,6 +2998,12 @@ class CConfig {
*/
unsigned short GetnMarker_Moving(void) const { return nMarker_Moving; }

/*!
* \brief Get the total number of markers for gradient treatment.
* \return Total number of markers for gradient treatment.
*/
unsigned short GetnMarker_SobolevBC(void) const { return nMarker_SobolevBC; }

/*!
* \brief Get the total number of Python customizable markers.
* \return Total number of Python customizable markers.
Expand Down Expand Up @@ -3329,6 +3366,13 @@ class CConfig {
*/
void SetMarker_All_Moving(unsigned short val_marker, unsigned short val_moving) { Marker_All_Moving[val_marker] = val_moving; }

/*!
* \brief Set if a marker how <i>val_marker</i> is going to be applied in gradient treatment.
* \param[in] val_marker - Index of the marker in which we are interested.
* \param[in] val_sobolev - 0 or 1 depending if the marker is selected.
*/
void SetMarker_All_SobolevBC(unsigned short val_marker, unsigned short val_sobolev) { Marker_All_SobolevBC[val_marker] = val_sobolev; }

/*!
* \brief Set if a marker <i>val_marker</i> allows deformation at the boundary.
* \param[in] val_marker - Index of the marker in which we are interested.
Expand Down Expand Up @@ -3473,6 +3517,13 @@ class CConfig {
*/
unsigned short GetMarker_All_Moving(unsigned short val_marker) const { return Marker_All_Moving[val_marker]; }

/*!
* \brief Get the information if gradient treatment uses a marker <i>val_marker</i>.
* \param[in] val_marker
* \return 0 or 1 depending if the marker is going to be selected.
*/
unsigned short GetMarker_All_SobolevBC(unsigned short val_marker) const { return Marker_All_SobolevBC[val_marker]; }

/*!
* \brief Get whether marker <i>val_marker</i> is a DEFORM_MESH marker
* \param[in] val_marker - 0 or 1 depending if the the marker belongs to the DEFORM_MESH subset.
Expand Down Expand Up @@ -4007,18 +4058,6 @@ class CConfig {
*/
unsigned short GetKind_Deform_Linear_Solver(void) const { return Kind_Deform_Linear_Solver; }

/*!
* \brief Set the kind of preconditioner for the implicit solver.
* \return Numerical preconditioner for implicit formulation (solving the linear system).
*/
void SetKind_Deform_Linear_Solver_Prec(unsigned short val_kind_prec) { Kind_Deform_Linear_Solver_Prec = val_kind_prec; }

/*!
* \brief Set the kind of preconditioner for the implicit solver.
* \return Numerical preconditioner for implicit formulation (solving the linear system).
*/
void SetKind_Linear_Solver_Prec(unsigned short val_kind_prec) { Kind_Linear_Solver_Prec = val_kind_prec; }

/*!
* \brief Get min error of the linear solver for the implicit formulation.
* \return Min error of the linear solver for the implicit formulation.
Expand Down Expand Up @@ -6131,6 +6170,12 @@ class CConfig {
*/
unsigned short GetMarker_CfgFile_Moving(string val_marker) const;

/*!
* \brief Get the gradient boundary information from the config definition for the marker <i>val_marker</i>.
* \return Gradient boundary information of the boundary in the config information for the marker <i>val_marker</i>.
*/
unsigned short GetMarker_CfgFile_SobolevBC(string val_marker) const;

/*!
* \brief Get the DEFORM_MESH information from the config definition for the marker <i>val_marker</i>.
* \return DEFORM_MESH information of the boundary in the config information for the marker <i>val_marker</i>.
Expand Down Expand Up @@ -6470,6 +6515,12 @@ class CConfig {
*/
unsigned short GetMarker_Fluid_Load(string val_marker) const;

/*!
* \brief Get the internal index for a gradient boundary condition <i>val_marker</i>.
* \return Internal index for a gradient boundary condition <i>val_marker</i>.
*/
unsigned short GetMarker_SobolevBC(string val_marker) const;

/*!
* \brief Get the name of the surface defined in the geometry file.
* \param[in] val_marker - Value of the marker in which we are interested.
Expand Down Expand Up @@ -9513,4 +9564,77 @@ class CConfig {
* \return Save frequency for unsteady time steps.
*/
unsigned short GetRom_SaveFreq(void) const { return rom_save_freq; }

/*!
* \brief Check if the gradient smoothing is active
* \return true means that smoothing is applied to the sensitivities
*/
bool GetSmoothGradient(void) const {return SmoothGradient; }

/*!
* \brief Gets the factor epsilon in front of the Laplace term
* \return epsilon
*/
su2double GetSmoothingEps1(void) const { return SmoothingEps1; }

/*!
* \brief Gets the factor zeta in front of the identity term
* \return zeta
*/
su2double GetSmoothingEps2(void) const { return SmoothingEps2; }

/*!
* \brief Check if we split in the dimensions
* \return true means that smoothing is for each dimension separate
*/
bool GetSmoothSepDim(void) const { return SmoothSepDim; }

/*!
* \brief Check if we assemble the operator on the surface
* \return true means that smoothing is done on the surface level
*/
bool GetSmoothOnSurface(void) const { return SmoothOnSurface; }

/*!
* \brief Check if we use zero Dirichlet boundarys on the bound of the surface
* \return true means that we use zero Dirichlet boundary
*/
bool GetDirichletSurfaceBound(void) const { return SmoothDirichletSurfaceBound; }

/*!
* \brief The modus of operation for the Sobolev solver
* \return returns on what level we operate
*/
ENUM_SOBOLEV_MODUS GetSobMode(void) const { return SmoothNumMode; }

/*!
* \brief Get the name of the file with the hessian of the objective function.
* \return Name of the file with the hessian of the objective function.
*/
string GetObjFunc_Hess_FileName(void) const { return ObjFunc_Hess_FileName; }

/*!
* \brief Get min error of the linear solver for the gradient smoothing.
* \return Min error of the linear solver for the gradient smoothing.
*/
su2double GetGrad_Linear_Solver_Error(void) const { return Grad_Linear_Solver_Error; }

/*!
* \brief Get the kind of solver for the gradient smoothing.
* \return Numerical solver for the gradient smoothing.
*/
unsigned short GetKind_Grad_Linear_Solver(void) const { return Kind_Grad_Linear_Solver; }

/*!
* \brief Get the kind of preconditioner for the gradient smoothing.
* \return Numerical preconditioner for the gradient smoothing.
*/
unsigned short GetKind_Grad_Linear_Solver_Prec(void) const { return Kind_Grad_Linear_Solver_Prec; }

/*!
* \brief Get max number of iterations of the for the gradient smoothing.
* \return Max number of iterations of the linear solver for the gradient smoothing.
*/
unsigned long GetGrad_Linear_Solver_Iter(void) const { return Grad_Linear_Solver_Iter; }

};
7 changes: 7 additions & 0 deletions Common/include/basic_types/ad_structure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ namespace AD{
*/
inline void ComputeAdjoint(unsigned short enter, unsigned short leave) {}

/*!
* \brief Computes the adjoints, i.e., the derivatives of the output with respect to the input variables, using forward tape evaluation.
*/
inline void ComputeAdjointForward() {}

/*!
* \brief Reset the tape structure to be ready for a new recording.
*/
Expand Down Expand Up @@ -354,6 +359,8 @@ namespace AD{
#endif
}

FORCEINLINE void ComputeAdjointForward() {AD::getGlobalTape().evaluateForward();}

FORCEINLINE void Reset() {
AD::getGlobalTape().reset();
#if defined(HAVE_OPDI)
Expand Down
Loading