Skip to content

Commit

Permalink
Merge pull request #28 from gantech/cppLibraryGluecode
Browse files Browse the repository at this point in the history
Bug fixes to C++ API
  • Loading branch information
michaelasprague authored May 31, 2017
2 parents aeebe81 + 15d9d20 commit 3a39dba
Show file tree
Hide file tree
Showing 5 changed files with 460 additions and 163 deletions.
5 changes: 3 additions & 2 deletions glue-codes/fast-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(MPI REQUIRED)
find_package(HDF5 REQUIRED)
find_package(HDF5 REQUIRED PATHS HDF5_ROOT)
find_package(YAMLCPP REQUIRED)

include_directories(${YAML_INCLUDES})
Expand All @@ -32,7 +32,8 @@ add_library(openfastcpplib
src/OpenFAST.cpp)
target_link_libraries(openfastcpplib
openfastlib
${HDF5_LIBRARIES}
${HDF5_C_STATIC_LIBRARY}
${HDF5_HL_STATIC_LIBRARY}
${CMAKE_DL_LIBS})

add_executable(openfastcpp
Expand Down
14 changes: 13 additions & 1 deletion glue-codes/fast-cpp/src/FAST_Prog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ void readInputFile(fast::fastInputs & fi, std::string cInterfaceInputFile, doubl
if(cDriverInp["debug"]) {
fi.debug = cDriverInp["debug"].as<bool>();
}

if(cDriverInp["simStart"]) {
if (cDriverInp["simStart"].as<std::string>() == "init") {
fi.simStart = fast::init;
} else if(cDriverInp["simStart"].as<std::string>() == "trueRestart") {
fi.simStart = fast::trueRestart;
} else if(cDriverInp["simStart"].as<std::string>() == "restartDriverInitFAST") {
fi.simStart = fast::restartDriverInitFAST;
} else {
throw std::runtime_error("simStart is not well defined in the input file");
}
}

fi.tStart = cDriverInp["tStart"].as<double>();
*tEnd = cDriverInp["tEnd"].as<double>();
Expand Down Expand Up @@ -110,7 +122,7 @@ int main() {
// Or allocate turbines to procs by calling "setTurbineProcNo(iTurbGlob, procId)" for turbine.

FAST.init();
if (!FAST.isRestart()) {
if (FAST.isTimeZero()) {
FAST.solution0();
}

Expand Down
40 changes: 32 additions & 8 deletions glue-codes/fast-cpp/src/OpenFAST.H
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#ifndef OpenFAST_h
#define OpenFAST_h

#include "FAST_Library.h"
#include "sys/stat.h"
#include "math.h"
Expand All @@ -13,8 +12,12 @@
#include <set>
#include <map>
#include "dlfcn.h"
#define OMPI_SKIP_MPICXX
#define MPICH_SKIP_MPICXX
#ifndef OMPI_SKIP_MPICXX
#define OMPI_SKIP_MPICXX
#endif
#ifndef MPICH_SKIP_MPICXX
#define MPICH_SKIP_MPICXX
#endif
#include "mpi.h"
#include "SC.h"

Expand All @@ -38,6 +41,14 @@ enum ActuatorNodeType {
ActuatorNodeType_END
};

enum simStartType {
init = 0,
trueRestart = 1,
restartDriverInitFAST = 2,
simStartType_END
};


class fastInputs {

public:
Expand All @@ -47,6 +58,7 @@ class fastInputs {
bool dryRun;
bool debug;
double tStart;
simStartType simStart;
int nEveryCheckPoint;
double tMax;
double dtFAST;
Expand Down Expand Up @@ -76,12 +88,12 @@ class OpenFAST {
std::vector<globTurbineDataType> globTurbineData;
int nTurbinesProc;
int nTurbinesGlob;
bool restart;
simStartType simStart;
bool timeZero;
double dtFAST;
double tMax;
std::vector<std::vector<float>> TurbineBasePos;
std::vector<std::vector<float>> TurbineHubPos;
std::vector<std::vector<float> > TurbineBasePos;
std::vector<std::vector<float> > TurbineHubPos;
std::vector<int> TurbID;
std::vector<std::string > FASTInputFileName;
std::vector<std::string > CheckpointFileRoot;
Expand All @@ -99,7 +111,10 @@ class OpenFAST {
std::vector<double> scOutputsGlob; // # outputs from the supercontroller for all turbines
std::vector<double> scInputsGlob; // # inputs to the supercontroller for all turbines

std::vector<std::vector<std::vector<double>>> forceNodeVel; // Velocity at force nodes - Store temporarily to interpolate to the velocity nodes
std::vector<std::vector<std::vector<double> > > forceNodeVel; // Velocity at force nodes - Store temporarily to interpolate to the velocity nodes
std::vector<std::vector<double> > velNodeData; // Position and velocity data at the velocity (aerodyn) nodes - (nTurbines, nTimesteps * nPoints * 6)
hid_t velNodeDataFile; // HDF-5 tag of file containing velocity (aerodyn) node data file

std::vector<OpFM_InputType_t> cDriver_Input_from_FAST;
std::vector<OpFM_OutputType_t> cDriver_Output_to_FAST;

Expand Down Expand Up @@ -148,16 +163,24 @@ class OpenFAST {
void init();
void solution0();
void step();
void stepNoWrite();
void end();

hid_t openVelocityDataFile(bool createFile);
int readVelocityData();
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 setTurbineProcNo(int iTurbGlob, int procNo) { turbineMapGlobToProc[iTurbGlob] = procNo; }
void allocateTurbinesToProcsSimple();
void getApproxHubPos(std::vector<double> & currentCoords, int iTurbGlob);
void getHubPos(std::vector<double> & currentCoords, int iTurbGlob);
void getHubShftDir(std::vector<double> & hubShftVec, int iTurbGlob);

ActuatorNodeType getVelNodeType(int iTurbGlob, int iNode);
void getVelNodeCoordinates(std::vector<double> & currentCoords, int iNode, int iTurbGlob);
void setVelocity(std::vector<double> & velocity, int iNode, int iTurbGlob);
void setVelocityForceNode(std::vector<double> & velocity, int iNode, int iTurbGlob);
void interpolateVel_ForceToVelNodes();
ActuatorNodeType getForceNodeType(int iTurbGlob, int iNode);
void getForceNodeCoordinates(std::vector<double> & currentCoords, int iNode, int iTurbGlob);
Expand All @@ -168,7 +191,7 @@ class OpenFAST {
int get_ntStart() { return ntStart; }
bool isDryRun() { return dryRun; }
bool isDebug() { return debug; }
bool isRestart() { return restart; }
simStartType get_simStartType() { return simStart; }
bool isTimeZero() { return timeZero; }
int get_procNo(int iTurbGlob) { return turbineMapGlobToProc[iTurbGlob] ; } // Get processor number of a turbine with global id 'iTurbGlob'
int get_localTurbNo(int iTurbGlob) { return reverseTurbineMapProcToGlob[iTurbGlob]; }
Expand Down Expand Up @@ -204,6 +227,7 @@ class OpenFAST {
void fillScOutputsLoc() ;

void setOutputsToFAST(OpFM_InputType_t cDriver_Input_from_FAST, OpFM_OutputType_t cDriver_Output_to_FAST) ; // An example to set velocities at the Aerodyn nodes
void applyVelocityData(int iPrestart, int iTurb, OpFM_OutputType_t cDriver_Output_to_FAST, std::vector<double> & velData) ;

};

Expand Down
Loading

0 comments on commit 3a39dba

Please sign in to comment.