-
Notifications
You must be signed in to change notification settings - Fork 469
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from gantech/cppLibraryGluecode
Cpp library gluecode
- Loading branch information
Showing
43 changed files
with
2,955 additions
and
459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
find_path(YAML_INCLUDES | ||
yaml-cpp/yaml.h | ||
HINTS ${YAML_ROOT} ${CMAKE_INSTALL_PREFIX} | ||
PATH_SUFFIXES include) | ||
|
||
find_library(YAML_LIBRARIES | ||
NAMES libyaml-cpp.a yaml-cpp | ||
HINTS ${YAML_ROOT} ${CMAKE_INSTALL_PREFIX} | ||
PATH_SUFFIXES lib) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(YAMLCPP DEFAULT_MSG YAML_INCLUDES YAML_LIBRARIES) | ||
mark_as_advanced(YAML_INCLUDES YAML_LIBRARIES) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# | ||
# Copyright 2016 National Renewable Energy Laboratory | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
@PACKAGE_INIT@ | ||
|
||
# Compilers use by OpenFAST build | ||
set(OpenFAST_CXX_COMPILER "@CMAKE_CXX_COMPILER@") | ||
set(OpenFAST_C_COMPILER "@CMAKE_C_COMPILER@") | ||
set(OpenFAST_Fortran_COMPILER "@CMAKE_Fortran_COMPILER@") | ||
|
||
# Compiler flags used by OpenFAST build | ||
set(OpenFAST_CXX_COMPILER_FLAGS "@CMAKE_CXX_FLAGS@") | ||
set(OpenFAST_C_COMPILER_FLAGS "@CMAKE_C_FLAGS@") | ||
set(OpenFAST_Fortran_COMPILER_FLAGS "@CMAKE_Fortran_FLAGS@") | ||
|
||
set_and_check(OpenFAST_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@") | ||
set_and_check(OpenFAST_LIBRARY_DIRS "@PACKAGE_LIB_INSTALL_DIR@") | ||
set_and_check(OpenFAST_FTNMOD_DIR "@PACKAGE_FTNMOD_INSTALL_DIR@") | ||
|
||
set(OpenFAST_LIBRARIES "openfastlib") | ||
set(OpenFAST_CPP_LIBRARIES "openfastcpplib") | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/OpenFASTLibraries.cmake") | ||
|
||
set(OpenFAST_HAS_CXX_API @OpenFAST_HAS_CXX_API@) | ||
set(OpenFAST_FOUND TRUE) | ||
|
||
if (NOT OpenFAST_FIND_COMPONENTS) | ||
if (OpenFAST_HAS_CXX_API) | ||
set(OpenFAST_FIND_COMPONENTS "openfastcpplib;openfastlib") | ||
else() | ||
set(OpenFAST_FIND_COMPONENTS "openfastlib") | ||
endif() | ||
endif () | ||
|
||
foreach (comp IN LISTS OpenFAST_FIND_COMPONENTS) | ||
if (${comp} STREQUAL "openfastcpplib") | ||
if (NOT OpenFAST_HAS_CXX_API) | ||
set(OpenFAST_${comp}_FOUND FALSE) | ||
message(WARNING "OpenFAST ${comp} NOT found") | ||
if(OpenFAST_FIND_REQUIRED_${comp}) | ||
set(OpenFAST_FOUND FALSE) | ||
endif() | ||
else() | ||
set(OpenFAST_${comp}_FOUND TRUE) | ||
endif() | ||
else() | ||
set(OpenFAST_${comp}_FOUND TRUE) | ||
endif() | ||
endforeach () | ||
|
||
check_required_components(OpenFAST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
|
||
add_subdirectory(fast) | ||
|
||
if(BUILD_FAST_CPP_API) | ||
add_subdirectory(fast-cpp) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# | ||
# Copyright 2016 National Renewable Energy Laboratory | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
find_package(MPI REQUIRED) | ||
find_package(HDF5 REQUIRED) | ||
find_package(YAMLCPP REQUIRED) | ||
|
||
include_directories(${YAML_INCLUDES}) | ||
include_directories(${HDF5_INCLUDES}) | ||
include_directories(${CMAKE_SOURCE_DIR}/modules-local/fast-library/src/) | ||
include_directories(${CMAKE_BINARY_DIR}/modules-local/openfoam/) | ||
include_directories(${CMAKE_BINARY_DIR}/modules-local/supercontroller/) | ||
include_directories(${MPI_INCLUDE_PATH}) | ||
|
||
add_library(openfastcpplib | ||
src/OpenFAST.cpp) | ||
target_link_libraries(openfastcpplib | ||
openfastlib | ||
${HDF5_LIBRARIES} | ||
${CMAKE_DL_LIBS}) | ||
|
||
add_executable(openfastcpp | ||
src/FAST_Prog.cpp) | ||
|
||
target_link_libraries(openfastcpp openfastcpplib openfastlib | ||
${MPI_LIBRARIES} ${YAML_LIBRARIES} ${CMAKE_DL_LIBS}) | ||
|
||
if(MPI_COMPILE_FLAGS) | ||
set_target_properties(openfastcpp PROPERTIES | ||
COMPILE_FLAGS "${MPI_COMPILE_FLAGS}") | ||
endif(MPI_COMPILE_FLAGS) | ||
|
||
if(MPI_LINK_FLAGS) | ||
set_target_properties(openfastcpp PROPERTIES | ||
LINK_FLAGS "${MPI_LINK_FLAGS}") | ||
endif(MPI_LINK_FLAGS) | ||
|
||
set_property(TARGET openfastcpp PROPERTY LINKER_LANGUAGE CXX) | ||
|
||
install(TARGETS openfastcpplib | ||
EXPORT "${CMAKE_PROJECT_NAME}Libraries" | ||
RUNTIME DESTINATION lib | ||
ARCHIVE DESTINATION lib | ||
LIBRARY DESTINATION lib) | ||
|
||
install(FILES | ||
src/OpenFAST.H src/SC.h | ||
DESTINATION include) | ||
|
||
install(TARGETS openfastcpp | ||
RUNTIME DESTINATION bin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
#include "OpenFAST.H" | ||
#include "yaml-cpp/yaml.h" | ||
#include <iostream> | ||
#include <mpi.h> | ||
|
||
inline bool checkFileExists(const std::string& name) { | ||
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>(); | ||
|
||
} | ||
|
||
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>(); | ||
} | ||
|
||
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("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.isRestart()) { | ||
FAST.solution0(); | ||
} | ||
|
||
if( !FAST.isDryRun() ) { | ||
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.end() ; | ||
MPI_Finalize() ; | ||
|
||
return 0; | ||
|
||
} | ||
|
Oops, something went wrong.