Skip to content

Commit

Permalink
Merge pull request #75 from gantech/backup_hdf5File
Browse files Browse the repository at this point in the history
Backup HDF5 velocity data file whenever OpenFAST dumps a restart file
  • Loading branch information
rafmudaf authored Jan 11, 2018
2 parents 1c5fc77 + bbdbc5b commit 5f5e531
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions glue-codes/fast-cpp/src/OpenFAST.H
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class OpenFAST {
void readVelocityData(int nTimesteps);
void writeVelocityData(hid_t h5file, int iTurb, int iTimestep, OpFM_InputType_t iData, OpFM_OutputType_t oData);
herr_t closeVelocityDataFile(int nt_global, hid_t velDataFile);
void backupVelocityDataFile(int curTimeStep, hid_t & velDataFile);

void setTurbineProcNo(int iTurbGlob, int procNo) { turbineMapGlobToProc[iTurbGlob] = procNo; }
void allocateTurbinesToProcsSimple();
Expand Down
16 changes: 16 additions & 0 deletions glue-codes/fast-cpp/src/OpenFAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ void fast::OpenFAST::step() {
nt_global = nt_global + 1;

if ( (((nt_global - ntStart) % nEveryCheckPoint) == 0 ) && (nt_global != ntStart) ) {
if (nTurbinesProc > 0) backupVelocityDataFile(nt_global, velNodeDataFile);

//sprintf(CheckpointFileRoot, "../../CertTest/Test18.%d", nt_global);
for (int iTurb=0; iTurb < nTurbinesProc; iTurb++) {
CheckpointFileRoot[iTurb] = " "; // if blank, it will use FAST convention <RootName>.nt_global
Expand Down Expand Up @@ -851,6 +853,20 @@ herr_t fast::OpenFAST::closeVelocityDataFile(int nt_global, hid_t velDataFile) {
}


void fast::OpenFAST::backupVelocityDataFile(int curTimeStep, hid_t & velDataFile) {

closeVelocityDataFile(curTimeStep, velDataFile);

std::ifstream source("velDatafile." + std::to_string(worldMPIRank) + ".h5", std::ios::binary);
std::ofstream dest("velDatafile." + std::to_string(worldMPIRank) + ".h5." + std::to_string(curTimeStep) + ".bak", std::ios::binary);

dest << source.rdbuf();
source.close();
dest.close();

velDataFile = openVelocityDataFile(false);
}

void fast::OpenFAST::writeVelocityData(hid_t h5File, int iTurb, int iTimestep, OpFM_InputType_t iData, OpFM_OutputType_t oData) {

hsize_t start[3]; start[0] = iTimestep; start[1] = 0; start[2] = 0;
Expand Down

0 comments on commit 5f5e531

Please sign in to comment.