Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable coupling to openfast 4.0 #1441

Merged
merged 4 commits into from
Jan 16, 2025
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
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ if(AMR_WIND_ENABLE_OPENFAST)
target_compile_definitions(${amr_wind_lib_name} PUBLIC AMR_WIND_USE_OPENFAST)
target_include_directories(${amr_wind_lib_name} PUBLIC ${OpenFAST_INCLUDE_DIRS})
target_link_libraries(${amr_wind_lib_name} PUBLIC ${OpenFAST_LIBRARIES})

set(AMR_WIND_OPENFAST_VERSION "3" CACHE STRING "OpenFAST major version")
if((AMR_WIND_OPENFAST_VERSION STREQUAL "master") OR (AMR_WIND_OPENFAST_VERSION STREQUAL "main") OR (AMR_WIND_OPENFAST_VERSION STREQUAL "develop"))
set(AMR_WIND_OPENFAST_VERSION "4.0")
endif()
if(NOT AMR_WIND_OPENFAST_VERSION VERSION_LESS "5")
message(FATAL_ERROR "AMR_WIND_OPENFAST_VERSION must be less than 5.")
endif()
string(REPLACE "." ";" OPENFAST_VERSION_LIST ${AMR_WIND_OPENFAST_VERSION})
list(LENGTH OPENFAST_VERSION_LIST OPENFAST_VERSION_LIST_LENGTH)
if(OPENFAST_VERSION_LIST_LENGTH GREATER_EQUAL 1)
list(GET OPENFAST_VERSION_LIST 0 OPENFAST_VERSION_MAJOR)
endif()
target_compile_definitions(${amr_wind_lib_name} PUBLIC OPENFAST_VERSION_MAJOR=${OPENFAST_VERSION_MAJOR})
endif()

if(AMR_WIND_ENABLE_ASCENT)
Expand Down
4 changes: 4 additions & 0 deletions amr-wind/wind_energy/actuator/turbine/fast/FastIface.H
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ protected:
int m_num_sc_inputs{0};
int m_num_sc_outputs{0};

#if OPENFAST_VERSION_MAJOR == 4
int m_inflow_type{2};
#endif

int m_num_sc_inputs_glob{0};
float m_init_sc_inputs_glob{0.0};
float m_init_sc_inputs_turbine{0.0};
Expand Down
28 changes: 24 additions & 4 deletions amr-wind/wind_energy/actuator/turbine/fast/FastIface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void FastIface::init_solution(const int local_id)
AMREX_ALWAYS_ASSERT(m_is_initialized);

auto& fi = *m_turbine_data[local_id];
fast_func(FAST_OpFM_Solution0, &fi.tid_local);
fast_func(FAST_Solution0, &fi.tid_local);
fi.is_solution0 = false;
}

Expand Down Expand Up @@ -168,7 +168,7 @@ void FastIface::advance_turbine(const int local_id)

write_velocity_data(fi);
for (int i = 0; i < fi.num_substeps; ++i, ++fi.time_index) {
fast_func(FAST_OpFM_Step, &fi.tid_local);
fast_func(FAST_Step, &fi.tid_local);
}

if (fi.chkpt_interval > 0 &&
Expand Down Expand Up @@ -220,13 +220,25 @@ void FastIface::fast_init_turbine(FastTurbine& fi)
amrex::Array<char, fast_strlen()> inp_file;
copy_filename(fi.input_file, inp_file.begin());

#if OPENFAST_VERSION_MAJOR == 4
char out_file[fast_strlen()];
fast_func(
FAST_ExtInfw_Init, &fi.tid_local, &fi.stop_time, inp_file.begin(),
&fi.tid_global, out_file, &m_num_sc_inputs_glob, &m_num_sc_inputs,
&m_num_sc_outputs, &m_init_sc_inputs_glob, &m_init_sc_inputs_turbine,
&fi.num_pts_blade, &fi.num_pts_tower, fi.base_pos.begin(), &abort_lev,
&fi.dt_cfd, &fi.dt_fast, &m_inflow_type, &fi.num_blades,
&fi.num_blade_elem, &fi.num_tower_elem, &fi.chord_cluster_type,
&fi.to_cfd, &fi.from_cfd, &fi.to_sc, &fi.from_sc);
#else
fast_func(
FAST_OpFM_Init, &fi.tid_local, &fi.stop_time, inp_file.begin(),
&fi.tid_global, &m_num_sc_inputs_glob, &m_num_sc_inputs,
&m_num_sc_outputs, &m_init_sc_inputs_glob, &m_init_sc_inputs_turbine,
&fi.num_pts_blade, &fi.num_pts_tower, fi.base_pos.begin(), &abort_lev,
&fi.dt_fast, &fi.num_blades, &fi.num_blade_elem, &fi.chord_cluster_type,
&fi.to_cfd, &fi.from_cfd, &fi.to_sc, &fi.from_sc);
#endif

{
#ifdef AMR_WIND_USE_OPENFAST
Expand Down Expand Up @@ -289,13 +301,13 @@ void FastIface::fast_replay_turbine(FastTurbine& fi)
// restart
fi.time_index = 0;
read_velocity_data(fi, ncf, 0);
fast_func(FAST_OpFM_Solution0, &fi.tid_local);
fast_func(FAST_Solution0, &fi.tid_local);
fi.is_solution0 = false;

for (int ic = 0; ic < num_cfd_steps; ++ic) {
read_velocity_data(fi, ncf, ic);
for (int i = 0; i < fi.num_substeps; ++i, ++fi.time_index) {
fast_func(FAST_OpFM_Step, &fi.tid_local);
fast_func(FAST_Step, &fi.tid_local);
}
}
AMREX_ALWAYS_ASSERT(fi.time_index == num_steps);
Expand All @@ -321,10 +333,18 @@ void FastIface::fast_restart_turbine(FastTurbine& fi)
amrex::Array<char, fast_strlen()> chkpt_file;
copy_filename(fi.checkpoint_file, chkpt_file.begin());

#if OPENFAST_VERSION_MAJOR == 4
fast_func(
FAST_ExtInfw_Restart, &fi.tid_local, chkpt_file.begin(), &abort_lev,
&fi.dt_fast, &m_inflow_type, &fi.num_blades, &fi.num_blade_elem,
&fi.num_tower_elem, &fi.time_index, &fi.to_cfd, &fi.from_cfd, &fi.to_sc,
&fi.from_sc);
#else
fast_func(
FAST_OpFM_Restart, &fi.tid_local, chkpt_file.begin(), &abort_lev,
&fi.dt_fast, &fi.num_blades, &fi.num_blade_elem, &fi.time_index,
&fi.to_cfd, &fi.from_cfd, &fi.to_sc, &fi.from_sc);
#endif

{
#ifdef AMR_WIND_USE_OPENFAST
Expand Down
8 changes: 6 additions & 2 deletions amr-wind/wind_energy/actuator/turbine/fast/fast_types.H
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ struct FastTurbine

//! Total number of elements along the blade
int num_blade_elem;
#if OPENFAST_VERSION_MAJOR == 4
//! Total number of elements along the tower
int num_tower_elem;
#endif

//! Node cluster type for the chord
int chord_cluster_type{0};
Expand Down Expand Up @@ -87,8 +91,8 @@ struct FastTurbine

// Data structures that are used to exchange between fast/cfd

exw_fast::OpFM_InputType to_cfd;
exw_fast::OpFM_OutputType from_cfd;
exw_fast::OfInputType to_cfd;
exw_fast::OfOutputType from_cfd;

exw_fast::SC_DX_InputType to_sc;
exw_fast::SC_DX_OutputType from_sc;
Expand Down
100 changes: 90 additions & 10 deletions amr-wind/wind_energy/actuator/turbine/fast/fast_wrapper.H
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define FAST_WRAPPER_H

namespace exw_fast {

#ifdef AMR_WIND_USE_OPENFAST
extern "C" {
#include "FAST_Library.h"
Expand All @@ -19,11 +20,6 @@ inline constexpr int fast_strlen() { return INTERFACE_STRING_LENGTH; }
#define ErrID_Severe 3
#define ErrID_Fatal 4

struct OpFM_InputType
{};
struct OpFM_OutputType
{};

struct SC_DX_InputType
{};
struct SC_DX_OutputType
Expand All @@ -37,11 +33,7 @@ inline void
FAST_AllocateTurbines(int* /*unused*/, int* /*unused*/, char* /*unused*/)
{}
inline void FAST_DeallocateTurbines(int* /*unused*/, char* /*unused*/) {}
inline void
FAST_OpFM_Solution0(int* /*unused*/, int* /*unused*/, char* /*unused*/)
{}
inline void FAST_OpFM_Step(int* /*unused*/, int* /*unused*/, char* /*unused*/)
{}

inline void FAST_CreateCheckpoint(
int* /*unused*/, char* /*unused*/, int* /*unused*/, char* /*unused*/)
{}
Expand All @@ -55,6 +47,79 @@ inline void FAST_HubPosition(
char* /*unused*/)
{}

#if OPENFAST_VERSION_MAJOR == 4
struct ExtInfw_InputType_t
{};

struct ExtInfw_OutputType_t
{};

inline void
FAST_CFD_Solution0(int* /*unused*/, int* /*unused*/, char* /*unused*/)
{}

inline void FAST_CFD_Step(int* /*unused*/, int* /*unused*/, char* /*unused*/) {}

inline void FAST_ExtInfw_Init(
int* /*unused*/,
double* /*unused*/,
const char* /*unused*/,
int* /*unused*/,
const char* /*unused*/,
int* /*unused*/,
int* /*unused*/,
int* /*unused*/,
float* /*unused*/,
float* /*unused*/,
int* /*unused*/,
int* /*unused*/,
float* /*unused*/,
int* /*unused*/,
double* /*unused*/,
int* /*unused*/,
int* /*unused*/,
int* /*unused*/,
int* /*unused*/,
int* /*unused*/,
OpFM_InputType* /*unused*/,
OpFM_OutputType* /*unused*/,
SC_DX_InputType* /*unused*/,
SC_DX_OutputType* /*unused*/,
int* /*unused*/,
char* /*unused*/)
{}

inline void FAST_ExtInfw_Restart(
int* /*unused*/,
char* /*unused*/,
int* /*unused*/,
double* /*unused*/,
int* /*unused*/,
int* /*unused*/,
int* /*unused*/,
int* /*unused*/,
OpFM_InputType* /*unused*/,
OpFM_OutputType* /*unused*/,
SC_DX_InputType* /*unused*/,
SC_DX_OutputType* /*unused*/,
int* /*unused*/,
char* /*unused*/)
{}

#else
struct OpFM_InputType
{};

struct OpFM_OutputType
{};

inline void
FAST_OpFM_Solution0(int* /*unused*/, int* /*unused*/, char* /*unused*/)
{}

inline void FAST_OpFM_Step(int* /*unused*/, int* /*unused*/, char* /*unused*/)
{}

inline void FAST_OpFM_Init(
int* /*unused*/,
double* /*unused*/,
Expand Down Expand Up @@ -97,6 +162,21 @@ inline void FAST_OpFM_Restart(
char* /*unused*/)
{}
#endif

#endif

#if OPENFAST_VERSION_MAJOR == 4
static constexpr auto& FAST_Solution0 = FAST_CFD_Solution0;
static constexpr auto& FAST_Step = FAST_CFD_Step;
using OfInputType = ExtInfw_InputType_t;
using OfOutputType = ExtInfw_OutputType_t;
#else
static constexpr auto& FAST_Solution0 = FAST_OpFM_Solution0;
static constexpr auto& FAST_Step = FAST_OpFM_Step;
using OfInputType = OpFM_InputType;
using OfOutputType = OpFM_OutputType;
#endif

} // namespace exw_fast

#endif /* FAST_WRAPPER_H */
8 changes: 8 additions & 0 deletions docs/sphinx/user/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ Dependencies

Enable NetCDF outputs. Default: OFF

.. cmakeval:: AMR_WIND_ENABLE_OPENFAST

Enable OpenFAST coupling. Default: OFF

.. cmakeval:: AMR_WIND_OPENFAST_VERSION

OpenFAST version. Default: 3

Other AMR-Wind specific options
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ if(AMR_WIND_ENABLE_W2A)
add_test_re(abl_multiphase_w2a)
endif()

if(AMR_WIND_ENABLE_OPENFAST)
if(AMR_WIND_ENABLE_OPENFAST AND AMR_WIND_OPENFAST_VERSION VERSION_LESS "4")
set(ACT_UNIFORM_ALM_TEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test_files/act_uniform_alm)
set(ACT_UNIFORM_ALM_TEST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/test_files/act_uniform_alm)
set(RTEST_ACT_UNIFORM_ALM_TEST_BINARY_DIR ${ACT_UNIFORM_ALM_TEST_BINARY_DIR}/r-test)
Expand Down