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

[WIP] Change unsteady timestep using Python wrapper #2190

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 16 additions & 1 deletion Common/include/CConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,8 @@ class CConfig {
Restart_Iter; /*!< \brief Determines the restart iteration in the multizone problem */
su2double Time_Step; /*!< \brief Determines the time step for the multizone problem */
su2double Max_Time; /*!< \brief Determines the maximum time for the time-domain problems */

su2double Start_Time; /*!< \brief Determines the starting time for the time-domain problems */

unsigned long HistoryWrtFreq[3], /*!< \brief Array containing history writing frequencies for timer iter, outer iter, inner iter */
ScreenWrtFreq[3]; /*!< \brief Array containing screen writing frequencies for timer iter, outer iter, inner iter */
OUTPUT_TYPE* VolumeOutputFiles; /*!< \brief File formats to output */
Expand Down Expand Up @@ -5737,6 +5738,13 @@ class CConfig {
*/
su2double GetDelta_UnstTime(void) const { return Delta_UnstTime; }

/*!
* \brief Set Delta_UnstTime (dimensional timestep)
* \param[in] val_delta_unsttime - Value of the unsteady dimensional timestep
*/
void SetDelta_UnstTime(su2double val_delta_unsttime) { Delta_UnstTime = val_delta_unsttime; }


/*!
* \brief Set the value of the unsteadty time step using the CFL number.
* \param[in] val_delta_unsttimend - Value of the unsteady time step using CFL number.
Expand Down Expand Up @@ -9372,6 +9380,13 @@ class CConfig {
*/
su2double GetMax_Time(void) const { return Max_Time; }

/*!
* \brief Get the start simulation time for time-domain problems
* \return Simulation start time for multizone problems, it is set on all the zones
*/
su2double GetStart_Time(void) const { return Start_Time; }


/*!
* \brief Get the level of MPI communications to be performed.
* \return Level of MPI communications.
Expand Down
6 changes: 6 additions & 0 deletions Common/src/CConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2548,6 +2548,8 @@ void CConfig::SetConfig_Options() {
addDoubleOption("TIME_STEP", Time_Step, 0.0);
/* DESCRIPTION: Total Physical Time for time-domain problems (s) */
addDoubleOption("MAX_TIME", Max_Time, 1.0);
/* DESCRIPTION: Start Physical Time for time-domain problems (s) */
addDoubleOption("START_TIME", Start_Time, -1.0);
/* DESCRIPTION: Determines if the special output is written out */
addBoolOption("SPECIAL_OUTPUT", SpecialOutput, false);

Expand Down Expand Up @@ -3722,6 +3724,10 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
if(nTimeIter <= Restart_Iter) SU2_MPI::Error("TIME_ITER must be larger than RESTART_ITER.", CURRENT_FUNCTION);
}

/*--- Set default start time for simulations if given time < 0 ---*/
if (Start_Time < 0)
Start_Time = Restart_Iter*Time_Step;

/*--- WINDOW_START_ITER must be larger than or equal to: RESTART_ITER. Otherwise, the running average is wrong. ---*/
if (OptionIsSet("WINDOW_START_ITER")) {
if (StartWindowIteration < Restart_Iter) {
Expand Down
7 changes: 7 additions & 0 deletions SU2_CFD/include/drivers/CDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,13 @@ class CDriver : public CDriverBase {
*/
passivedouble GetUnsteadyTimeStep() const;

/*!
* \brief Set the unsteady time step.
* \param[in] unst_dt - Dimensional unsteady time step.
*/
void SetUnsteadyTimeStep(passivedouble unst_dt);


/*!
* \brief Get the name of the output file for the surface.
* \return File name for the surface output.
Expand Down
9 changes: 7 additions & 2 deletions SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,13 @@ void CDiscAdjMultizoneDriver::Preprocess(unsigned long TimeIter) {
config_container[iZone]->SetTimeIter(TimeIter);

if (time_domain)
config_container[iZone]->SetPhysicalTime(static_cast<su2double>(TimeIter)*config_container[iZone]->GetDelta_UnstTimeND());
else
{
/*--- If first iteration, use start time. Otherwise, add dt ---*/
if (TimeIter == config_container[iZone]->GetRestart_Iter())
config_container[iZone]->SetPhysicalTime(config_container[iZone]->GetStart_Time()/config_container[iZone]->GetTime_Ref());
else
config_container[iZone]->SetPhysicalTime(config_container[iZone]->GetPhysicalTime() + config_container[iZone]->GetDelta_UnstTimeND());
} else
config_container[iZone]->SetPhysicalTime(0.0);

/*--- Preprocess the iteration of each zone. ---*/
Expand Down
10 changes: 7 additions & 3 deletions SU2_CFD/src/drivers/CDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3022,9 +3022,13 @@ void CFluidDriver::Preprocess(unsigned long Iter) {

for (iZone = 0; iZone < nZone; iZone++) {
config_container[iZone]->SetInnerIter(Iter);
if (config_container[iZone]->GetTime_Marching() != TIME_MARCHING::STEADY)
config_container[iZone]->SetPhysicalTime(static_cast<su2double>(Iter)*config_container[iZone]->GetDelta_UnstTimeND());
else
if (config_container[iZone]->GetTime_Marching() != TIME_MARCHING::STEADY) {
/*--- If first iteration, use start time. Otherwise, add dt ---*/
if (Iter == config_container[iZone]->GetRestart_Iter())
config_container[iZone]->SetPhysicalTime(config_container[iZone]->GetStart_Time()/config_container[iZone]->GetTime_Ref());
else
config_container[iZone]->SetPhysicalTime(config_container[iZone]->GetPhysicalTime() + config_container[iZone]->GetDelta_UnstTimeND());
} else
config_container[iZone]->SetPhysicalTime(0.0);
}

Expand Down
6 changes: 5 additions & 1 deletion SU2_CFD/src/drivers/CMultizoneDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ void CMultizoneDriver::Preprocess(unsigned long TimeIter) {
general once the drivers are more stable. ---*/

if (driver_config->GetTime_Domain()) {
config_container[iZone]->SetPhysicalTime(static_cast<su2double>(TimeIter)*config_container[iZone]->GetDelta_UnstTimeND());
/*--- If first iteration, use start time. Otherwise, add dt ---*/
if (TimeIter == config_container[iZone]->GetRestart_Iter())
config_container[iZone]->SetPhysicalTime(config_container[iZone]->GetStart_Time()/config_container[iZone]->GetTime_Ref());
else
config_container[iZone]->SetPhysicalTime(config_container[iZone]->GetPhysicalTime() + config_container[iZone]->GetDelta_UnstTimeND());
}
else {
config_container[iZone]->SetPhysicalTime(0.0);
Expand Down
10 changes: 7 additions & 3 deletions SU2_CFD/src/drivers/CSinglezoneDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,13 @@ void CSinglezoneDriver::Preprocess(unsigned long TimeIter) {
this can be used for verification / MMS. This should also be more
general once the drivers are more stable. ---*/

if (config_container[ZONE_0]->GetTime_Marching() != TIME_MARCHING::STEADY)
config_container[ZONE_0]->SetPhysicalTime(static_cast<su2double>(TimeIter)*config_container[ZONE_0]->GetDelta_UnstTimeND());
else
if (config_container[ZONE_0]->GetTime_Marching() != TIME_MARCHING::STEADY) {
/*--- If first iteration, use start time. Otherwise, add dt ---*/
if (TimeIter == config_container[ZONE_0]->GetRestart_Iter())
config_container[ZONE_0]->SetPhysicalTime(config_container[ZONE_0]->GetStart_Time()/config_container[ZONE_0]->GetTime_Ref());
else
config_container[ZONE_0]->SetPhysicalTime(config_container[ZONE_0]->GetPhysicalTime() + config_container[ZONE_0]->GetDelta_UnstTimeND());
} else
config_container[ZONE_0]->SetPhysicalTime(0.0);

/*--- Ramp turbo BCs for this time step. ---*/
Expand Down
5 changes: 2 additions & 3 deletions SU2_CFD/src/output/COutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2191,13 +2191,12 @@ void COutput::ComputeSimpleCustomOutputs(const CConfig *config) {

void COutput::LoadCommonHistoryData(const CConfig *config) {

SetHistoryOutputValue("TIME_STEP", config->GetDelta_UnstTimeND()*config->GetTime_Ref());

/*--- Update the current time only if the time iteration has changed ---*/

if (SU2_TYPE::Int(GetHistoryFieldValue("TIME_ITER")) != static_cast<int>(curTimeIter)) {
SetHistoryOutputValue("CUR_TIME", GetHistoryFieldValue("CUR_TIME") + GetHistoryFieldValue("TIME_STEP"));
}

SetHistoryOutputValue("TIME_STEP", config->GetDelta_UnstTimeND()*config->GetTime_Ref());

SetHistoryOutputValue("TIME_ITER", curTimeIter);
SetHistoryOutputValue("INNER_ITER", curInnerIter);
Expand Down
10 changes: 9 additions & 1 deletion SU2_CFD/src/python_wrapper_structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ unsigned long CDriver::GetNumberTimeIter() const { return config_container[selec
unsigned long CDriver::GetTimeIter() const { return TimeIter; }

passivedouble CDriver::GetUnsteadyTimeStep() const {
return SU2_TYPE::GetValue(config_container[selected_zone]->GetTime_Step());
return SU2_TYPE::GetValue(config_container[selected_zone]->GetDelta_UnstTime());
}

void CDriver::SetUnsteadyTimeStep(passivedouble unst_dt) {
// Set across all zones
for (iZone = 0; iZone < nZone; iZone++) {
config_container[iZone]->SetDelta_UnstTime(unst_dt);
config_container[iZone]->SetDelta_UnstTimeND(unst_dt/config_container[iZone]->GetTime_Ref());
}
}

string CDriver::GetSurfaceFileName() const { return config_container[selected_zone]->GetSurfCoeff_FileName(); }
Expand Down
4 changes: 4 additions & 0 deletions config_template.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ TIME_STEP= 0.0
% Total Physical Time for dual time stepping simulations (s)
MAX_TIME= 50.0
%
% Start time for dual time stepping simulations
% = -1 for default calculation (START_TIME=RESTART_ITER*TIME_STEP)
START_TIME=-1
%
% Unsteady Courant-Friedrichs-Lewy number of the finest grid
UNST_CFL_NUMBER= 0.0
%
Expand Down
Loading