Skip to content

Commit f30b478

Browse files
committed
AD fixes for RegisterVariables (however, it needs more maintenance).
1 parent 8611b55 commit f30b478

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

Common/include/CConfig.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,12 @@ class CConfig {
18991899
*/
19001900
su2double GetPressure_FreeStreamND(void) const { return Pressure_FreeStreamND; }
19011901

1902+
/*!
1903+
* \brief Get a reference to the non-dimensionalized freestream pressure (used for AD tracking).
1904+
* \return Reference to non-dimensionalized freestream pressure.
1905+
*/
1906+
su2double& GetPressure_FreeStreamND(void) { return Pressure_FreeStreamND; }
1907+
19021908
/*!
19031909
* \brief Get the value of the thermodynamic pressure.
19041910
* \return Thermodynamic pressure.
@@ -1924,6 +1930,12 @@ class CConfig {
19241930
*/
19251931
su2double GetTemperature_FreeStreamND(void) const { return Temperature_FreeStreamND; }
19261932

1933+
/*!
1934+
* \brief Get a reference to the non-dimensionalized freestream temperature (used for AD tracking).
1935+
* \return Reference to non-dimensionalized freestream temperature.
1936+
*/
1937+
su2double& GetTemperature_FreeStreamND(void) { return Temperature_FreeStreamND; }
1938+
19271939
/*!
19281940
* \brief Get the value of the non-dimensionalized vibrational-electronic freestream temperature.
19291941
* \return Non-dimensionalized vibrational-electronic freestream temperature.

Common/include/basic_types/ad_structure.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@ inline void SetIndex(Identifier& index, const su2double& data) {}
276276
*/
277277
inline void SetTag(int tag) {}
278278

279+
/*!
280+
* \brief Sets the tag of a variable to 0.
281+
* \param[in] v - the variable whose tag is cleared.
282+
*/
283+
inline void ClearTagOnVariable(su2double& v) {}
284+
279285
/*!
280286
* \brief Pushes back the current tape position to the tape position's vector.
281287
*/
@@ -684,8 +690,10 @@ FORCEINLINE void ResumePreaccumulation(bool wasActive) {
684690

685691
#ifdef CODI_TAG_TAPE
686692
FORCEINLINE void SetTag(int tag) { AD::getTape().setCurTag(tag); }
693+
FORCEINLINE void ClearTagOnVariable(su2double& v) { AD::getTape().clearTagOnVariable(v); }
687694
#else
688695
FORCEINLINE void SetTag(int tag) {}
696+
FORCEINLINE void ClearTagOnVariable(su2double& v) {}
689697
#endif
690698

691699
#endif // CODI_REVERSE_TYPE

SU2_CFD/src/solvers/CDiscAdjSolver.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,16 @@ void CDiscAdjSolver::RegisterVariables(CGeometry *geometry, CConfig *config, boo
184184
Alpha = config->GetAoA()*PI_NUMBER/180.0;
185185
Beta = config->GetAoS()*PI_NUMBER/180.0;
186186
Mach = config->GetMach();
187-
Pressure = config->GetPressure_FreeStreamND();
188-
Temperature = config->GetTemperature_FreeStreamND();
187+
su2double& Pressure = config->GetPressure_FreeStreamND();
188+
su2double& Temperature = config->GetTemperature_FreeStreamND();
189189

190190
su2double SoundSpeed = 0.0;
191191

192+
AD::StopRecording();
193+
AD::ClearTagOnVariable(config->GetVelocity_FreeStreamND()[0]);
192194
if (nDim == 2) { SoundSpeed = config->GetVelocity_FreeStreamND()[0]*Velocity_Ref/(cos(Alpha)*Mach); }
193195
if (nDim == 3) { SoundSpeed = config->GetVelocity_FreeStreamND()[0]*Velocity_Ref/(cos(Alpha)*cos(Beta)*Mach); }
196+
AD::StartRecording();
194197

195198
if (!reset) {
196199
AD::RegisterInput(Mach);

0 commit comments

Comments
 (0)