Skip to content
Merged
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
53 changes: 53 additions & 0 deletions .github/workflows/automated-dev-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,56 @@ jobs:
- name: Test
working-directory: ${{runner.workspace}}/build
run: ./glue-codes/openfast/openfast -v

cpp-interface-tests:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@main
with:
submodules: recursive

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.7'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh==1.4
sudo apt-get install libhdf5-dev libopenmpi-dev libyaml-cpp-dev

- name: Setup Workspace
run: cmake -E make_directory ${{runner.workspace}}/build
- name: Configure Build
working-directory: ${{runner.workspace}}/build
run: |
cmake \
-DCMAKE_INSTALL_PREFIX:PATH=${{runner.workspace}}/install \
-DCMAKE_Fortran_COMPILER:STRING=${{env.FORTRAN_COMPILER}} \
-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo \
-DBUILD_OPENFAST_CPP_API:BOOL=ON \
-DBUILD_SHARED_LIBS:BOOL=ON \
-DBUILD_TESTING:BOOL=ON \
-DCTEST_PLOT_ERRORS:BOOL=ON \
${GITHUB_WORKSPACE}
- name: Build OpenFAST C++ API
# if: contains(github.event.head_commit.message, 'Action - Test All') || contains(github.event.pull_request.labels.*.name, 'Action - Test All')
working-directory: ${{runner.workspace}}/build
run: |
cmake --build . --target openfastcpp -- -j ${{env.NUM_PROCS}}
cmake --build . --target regression_tests -- -j ${{env.NUM_PROCS}}

- name: Run OpenFAST C++ API tests
working-directory: ${{runner.workspace}}/build
run: |
ctest -VV -L cpp

- name: Failing test artifacts
uses: actions/upload-artifact@v2
if: failure()
with:
name: test-results
path: |
${{runner.workspace}}/build/reg_tests/glue-codes/openfast-cpp
!${{runner.workspace}}/build/reg_tests/glue-codes/openfast-cpp/5MW_Baseline
27 changes: 0 additions & 27 deletions cmake/FindYAMLCPP.cmake

This file was deleted.

11 changes: 5 additions & 6 deletions glue-codes/openfast-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ find_package(MPI REQUIRED)
find_package(LibXml2 REQUIRED)
find_package(ZLIB REQUIRED)
find_package(HDF5 REQUIRED COMPONENTS C HL)
find_package(YAMLCPP REQUIRED)
find_package(yaml-cpp REQUIRED)

include_directories(${YAML_INCLUDES})
include_directories(${YAML_CPP_INCLUDE_DIRS})
include_directories(${HDF5_INCLUDES})
include_directories(${HDF5_INCLUDE_DIR})
include_directories(${ZLIB_INCLUDES})
Expand All @@ -49,11 +49,10 @@ target_link_libraries(openfastcpplib
${MPI_LIBRARIES}
${CMAKE_DL_LIBS})

add_executable(openfastcpp
src/FAST_Prog.cpp)

add_executable(openfastcpp src/FAST_Prog.cpp)
target_link_libraries(openfastcpp openfastcpplib openfastlib
${MPI_LIBRARIES} ${YAML_LIBRARIES}
${MPI_LIBRARIES}
${YAML_CPP_LIBRARIES}
${HDF5_C_LIBRARIES}
${HDF5_HL_LIBRARIES}
${ZLIB_LIBRARIES}
Expand Down
262 changes: 135 additions & 127 deletions glue-codes/openfast-cpp/src/FAST_Prog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,147 +3,155 @@
#include <iostream>
#include <mpi.h>

#include <filesystem>

inline bool checkFileExists(const std::string& name) {
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
}

void readTurbineData(int iTurb, fast::fastInputs & fi, YAML::Node turbNode) {

//Read turbine data for a given turbine using the YAML node
fi.globTurbineData[iTurb].TurbID = turbNode["turb_id"].as<int>();
fi.globTurbineData[iTurb].FASTInputFileName = turbNode["FAST_input_filename"].as<std::string>() ;
fi.globTurbineData[iTurb].FASTRestartFileName = turbNode["restart_filename"].as<std::string>() ;
if (turbNode["turbine_base_pos"].IsSequence() ) {
fi.globTurbineData[iTurb].TurbineBasePos = turbNode["turbine_base_pos"].as<std::vector<double> >() ;
}
if (turbNode["turbine_hub_pos"].IsSequence() ) {
fi.globTurbineData[iTurb].TurbineHubPos = turbNode["turbine_hub_pos"].as<std::vector<double> >() ;
}
fi.globTurbineData[iTurb].numForcePtsBlade = turbNode["num_force_pts_blade"].as<int>();
fi.globTurbineData[iTurb].numForcePtsTwr = turbNode["num_force_pts_tower"].as<int>();
if (turbNode["nacelle_cd"]) {fi.globTurbineData[iTurb].nacelle_cd = turbNode["nacelle_cd"].as<float>();}
if (turbNode["nacelle_area"]) {fi.globTurbineData[iTurb].nacelle_area = turbNode["nacelle_area"].as<float>();}
if (turbNode["air_density"]) {fi.globTurbineData[iTurb].air_density = turbNode["air_density"].as<float>();}
//Read turbine data for a given turbine using the YAML node
fi.globTurbineData[iTurb].TurbID = turbNode["turb_id"].as<int>();
fi.globTurbineData[iTurb].FASTInputFileName = turbNode["FAST_input_filename"].as<std::string>();
fi.globTurbineData[iTurb].FASTRestartFileName = turbNode["restart_filename"].as<std::string>();
if (turbNode["turbine_base_pos"].IsSequence() ) {
fi.globTurbineData[iTurb].TurbineBasePos = turbNode["turbine_base_pos"].as<std::vector<double> >();
}
if (turbNode["turbine_hub_pos"].IsSequence() ) {
fi.globTurbineData[iTurb].TurbineHubPos = turbNode["turbine_hub_pos"].as<std::vector<double> >();
}
fi.globTurbineData[iTurb].numForcePtsBlade = turbNode["num_force_pts_blade"].as<int>();
fi.globTurbineData[iTurb].numForcePtsTwr = turbNode["num_force_pts_tower"].as<int>();
if (turbNode["nacelle_cd"]) fi.globTurbineData[iTurb].nacelle_cd = turbNode["nacelle_cd"].as<float>();
if (turbNode["nacelle_area"]) fi.globTurbineData[iTurb].nacelle_area = turbNode["nacelle_area"].as<float>();
if (turbNode["air_density"]) fi.globTurbineData[iTurb].air_density = turbNode["air_density"].as<float>();
}

void readInputFile(fast::fastInputs & fi, std::string cInterfaceInputFile, double * tEnd) {

fi.comm = MPI_COMM_WORLD;

// Check if the input file exists and read it
if ( checkFileExists(cInterfaceInputFile) ) {

YAML::Node cDriverInp = YAML::LoadFile(cInterfaceInputFile);

fi.nTurbinesGlob = cDriverInp["nTurbinesGlob"].as<int>();

if (fi.nTurbinesGlob > 0) {

if(cDriverInp["dryRun"]) {
fi.dryRun = cDriverInp["dryRun"].as<bool>();
}

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>();
fi.nEveryCheckPoint = cDriverInp["nEveryCheckPoint"].as<int>();
fi.dtFAST = cDriverInp["dtFAST"].as<double>();
fi.tMax = cDriverInp["tMax"].as<double>(); // tMax is the total duration to which you want to run FAST. This should be the same or greater than the max time given in the FAST fst file. Choose this carefully as FAST writes the output file only at this point if you choose the binary file output.

if(cDriverInp["superController"]) {
fi.scStatus = cDriverInp["superController"].as<bool>();
fi.scLibFile = cDriverInp["scLibFile"].as<std::string>();
fi.numScInputs = cDriverInp["numScInputs"].as<int>();
fi.numScOutputs = cDriverInp["numScOutputs"].as<int>();
}

fi.globTurbineData.resize(fi.nTurbinesGlob);
for (int iTurb=0; iTurb < fi.nTurbinesGlob; iTurb++) {
if (cDriverInp["Turbine" + std::to_string(iTurb)]) {
readTurbineData(iTurb, fi, cDriverInp["Turbine" + std::to_string(iTurb)] );
} else {
throw std::runtime_error("Node for Turbine" + std::to_string(iTurb) + " not present in input file or I cannot read it");
}
}

fi.comm = MPI_COMM_WORLD;

// Check if the input file exists and read it
if ( checkFileExists(cInterfaceInputFile) ) {

YAML::Node cDriverInp = YAML::LoadFile(cInterfaceInputFile);

fi.nTurbinesGlob = cDriverInp["nTurbinesGlob"].as<int>();

if (fi.nTurbinesGlob > 0) {

if(cDriverInp["dryRun"]) {
fi.dryRun = cDriverInp["dryRun"].as<bool>();
}

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>();
fi.nEveryCheckPoint = cDriverInp["nEveryCheckPoint"].as<int>();
fi.dtFAST = cDriverInp["dtFAST"].as<double>();
fi.tMax = cDriverInp["tMax"].as<double>(); // tMax is the total duration to which you want to run FAST. This should be the same or greater than the max time given in the FAST fst file. Choose this carefully as FAST writes the output file only at this point if you choose the binary file output.

if(cDriverInp["superController"]) {
fi.scStatus = cDriverInp["superController"].as<bool>();
fi.scLibFile = cDriverInp["scLibFile"].as<std::string>();
fi.numScInputs = cDriverInp["numScInputs"].as<int>();
fi.numScOutputs = cDriverInp["numScOutputs"].as<int>();
}

fi.globTurbineData.resize(fi.nTurbinesGlob);
for (int iTurb=0; iTurb < fi.nTurbinesGlob; iTurb++) {
if (cDriverInp["Turbine" + std::to_string(iTurb)]) {
readTurbineData(iTurb, fi, cDriverInp["Turbine" + std::to_string(iTurb)] );
} else {
throw std::runtime_error("Node for Turbine" + std::to_string(iTurb) + " not present in input file or I cannot read it");
}
}

} else {
throw std::runtime_error("Number of turbines <= 0 ");
}

} else {
throw std::runtime_error("Number of turbines <= 0 ");
throw std::runtime_error("Input file " + cInterfaceInputFile + " does not exist or I cannot access it");
}

} else {
throw std::runtime_error("Input file " + cInterfaceInputFile + " does not exist or I cannot access it");
}

}

int main() {
int iErr;
int nProcs;
int rank;
std::vector<double> torque (3, 0.0);
std::vector<double> thrust (3, 0.0);

iErr = MPI_Init(NULL, NULL);
iErr = MPI_Comm_size( MPI_COMM_WORLD, &nProcs);
iErr = MPI_Comm_rank( MPI_COMM_WORLD, &rank);

double tEnd ; // This doesn't belong in the FAST - C++ interface
int ntEnd ; // This doesn't belong in the FAST - C++ interface

std::string cDriverInputFile="cDriver.i";
fast::OpenFAST FAST;
fast::fastInputs fi ;
try {
readInputFile(fi, cDriverInputFile, &tEnd);
}
catch( const std::runtime_error & ex) {
std::cerr << ex.what() << std::endl ;
std::cerr << "Program quitting now" << std::endl ;
return 1;
}
ntEnd = tEnd/fi.dtFAST; //Calculate the last time step

FAST.setInputs(fi);
FAST.allocateTurbinesToProcsSimple();
// Or allocate turbines to procs by calling "setTurbineProcNo(iTurbGlob, procId)" for turbine.

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

if( !FAST.isDryRun() ) {
int main(int argc, char** argv) {
if (argc != 2) {
std::cerr << "Incorrect syntax. Try: openfastcpp inputfile.yaml" << std::endl ;
return 1;
}

int iErr;
int nProcs;
int rank;
std::vector<double> torque (3, 0.0);
std::vector<double> thrust (3, 0.0);

iErr = MPI_Init(NULL, NULL);
iErr = MPI_Comm_size( MPI_COMM_WORLD, &nProcs);
iErr = MPI_Comm_rank( MPI_COMM_WORLD, &rank);

double tEnd ; // This doesn't belong in the FAST - C++ interface
int ntEnd ; // This doesn't belong in the FAST - C++ interface

std::string cDriverInputFile=argv[1];
fast::OpenFAST FAST;
fast::fastInputs fi ;
try {
readInputFile(fi, cDriverInputFile, &tEnd);
} catch( const std::runtime_error & ex) {
std::cerr << ex.what() << std::endl ;
std::cerr << "Program quitting now" << std::endl ;
return 1;
}

// Calculate the last time step
ntEnd = tEnd/fi.dtFAST;

FAST.setInputs(fi);
FAST.allocateTurbinesToProcsSimple();
// Or allocate turbines to procs by calling "setTurbineProcNo(iTurbGlob, procId)" for turbine.

FAST.init();

if (FAST.isTimeZero()) FAST.solution0();

if ( FAST.isDryRun() ) {
FAST.end() ;
MPI_Finalize() ;
return 0;
}

for (int nt = FAST.get_ntStart(); nt < ntEnd; nt++) {
FAST.step();
if (FAST.isDebug()) {
FAST.computeTorqueThrust(0,torque,thrust);
std::cout.precision(16);
std::cout << "Torque = " << torque[0] << " " << torque[1] << " " << torque[2] << std::endl ;
std::cout << "Thrust = " << thrust[0] << " " << thrust[1] << " " << thrust[2] << std::endl ;
}
FAST.step();
if (FAST.isDebug()) {
FAST.computeTorqueThrust(0,torque,thrust);
std::cout.precision(16);
std::cout << "Torque = " << torque[0] << " " << torque[1] << " " << torque[2] << std::endl ;
std::cout << "Thrust = " << thrust[0] << " " << thrust[1] << " " << thrust[2] << std::endl ;
}
}
}

FAST.end() ;
MPI_Finalize() ;
FAST.end() ;
MPI_Finalize() ;

return 0;

}
return 0;

}
Loading