Skip to content

Commit

Permalink
Merge pull request #27 from psakievich/bug/ratio-fix
Browse files Browse the repository at this point in the history
Fix precision errors based on integer conversion
  • Loading branch information
gantech authored Oct 26, 2023
2 parents c2aea80 + ecfb37a commit c18fb0c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion glue-codes/openfast-cpp/src/OpenFAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1419,8 +1419,11 @@ void fast::OpenFAST::step(bool writeFiles) {
}

if (writeFiles) {
// provide an epsilon that is small relative to dtFast to help with integer conversion
const double eps = dtFast*1e-6;
for (int iTurb=0; iTurb < nTurbinesProc; iTurb++) {
int tStepRatio = dtDriver/dtFAST;
// ensure that the ratio is robust to integer conversion by making sure it will always truncate down
int tStepRatio = static_cast<int>((dtDriver+eps)/dtFAST);
if ( (((nt_global - ntStart) % (restartFreq_ * tStepRatio)) == 0 ) && (nt_global != ntStart) ) {
turbineData[iTurb].FASTRestartFileName = " "; // if blank, it will use FAST convention <RootName>.nt_global
FAST_CreateCheckpoint(&iTurb, turbineData[iTurb].FASTRestartFileName.data(), &ErrStat, ErrMsg);
Expand Down

0 comments on commit c18fb0c

Please sign in to comment.