Skip to content

Commit

Permalink
Fix issues to get C++ API to run
Browse files Browse the repository at this point in the history
  • Loading branch information
gantech committed Dec 11, 2023
1 parent a6a97a3 commit 69fb0b8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
7 changes: 5 additions & 2 deletions glue-codes/openfast-cpp/src/FAST_Prog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ void readTurbineData(int iTurb, fast::fastInputs & fi, YAML::Node turbNode) {

get_if_present(turbNode, "num_force_pts_blade", fi.globTurbineData[iTurb].numForcePtsBlade, 0);
get_if_present(turbNode, "num_force_pts_tower", fi.globTurbineData[iTurb].numForcePtsTwr, 0);
fi.globTurbineData[iTurb].numForcePts =
fi.globTurbineData[iTurb].numForcePtsBlade +
fi.globTurbineData[iTurb].numForcePtsTwr;

float fZero = 0.0;
get_if_present(turbNode, "nacelle_cd", fi.globTurbineData[iTurb].nacelle_cd, fZero);
Expand Down Expand Up @@ -145,7 +148,7 @@ void readInputFile(fast::fastInputs & fi, std::string cInterfaceInputFile, doubl
get_if_present(cDriverInp, "set_exp_law_wind", *setExpLawWind, false);
get_if_present(cDriverInp, "set_uniform_x_blade_forces", *setUniformXBladeForces, false);
if (setUniformXBladeForces)
get_required(cDriverInp, "x_blade_force", *xBladeForce);
get_if_present(cDriverInp, "x_blade_force", *xBladeForce, 0.0);

get_if_present(cDriverInp, "super_controller", fi.scStatus, false);
if(fi.scStatus) {
Expand Down Expand Up @@ -197,7 +200,7 @@ int main(int argc, char** argv) {
bool setUniformXBladeForces; // Set uniform X blade forces on all blade nodes
int nIter;
double xBladeForce = 0.0;

std::string cDriverInputFile=argv[1];
fast::OpenFAST FAST;
fast::fastInputs fi ;
Expand Down
16 changes: 13 additions & 3 deletions glue-codes/openfast-cpp/src/OpenFAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ void fast::OpenFAST::prepareRestartFile(int iTurbLoc) {
ierr = nc_enddef(ncid);
check_nc_error(ierr, "nc_enddef");

if (turbineData[iTurbLoc].sType == EXTINFLOW) {
if ( (turbineData[iTurbLoc].sType == EXTINFLOW) && (turbineData[iTurbLoc].inflowType == 2) ) {

int nfpts_data = 3*get_numForcePtsLoc(iTurbLoc);
int ierr = nc_put_var_double(ncid, ncRstVarIDs_["xref_force"], velForceNodeData[iTurbLoc][fast::STATE_NP1].xref_force.data());
}
Expand Down Expand Up @@ -729,6 +730,8 @@ void fast::OpenFAST::init() {
ErrMsg);
checkError(ErrStat, ErrMsg);

std::cerr << "turbineData[iTurb].inflowType = " << turbineData[iTurb].inflowType << std::endl;

turbineData[iTurb].numVelPtsTwr = extinfw_o_t_FAST[iTurb].u_Len - turbineData[iTurb].numBlades*turbineData[iTurb].numVelPtsBlade - 1;
if(turbineData[iTurb].numVelPtsTwr == 0) {
turbineData[iTurb].numForcePtsTwr = 0;
Expand Down Expand Up @@ -2118,6 +2121,11 @@ void fast::OpenFAST::allocateMemory_postInit(int iTurbLoc) {
}
}
}
std::cerr << "turbineData[iTurbLoc].inflowType " << turbineData[iTurbLoc].inflowType << std::endl;
std::cerr << "turbineData[iTurbLoc].numForcePtsTwr = " << turbineData[iTurbLoc].numForcePtsTwr << std::endl;
std::cerr << "turbineData[iTurbLoc].numForcePtsBlade = " << turbineData[iTurbLoc].numForcePtsBlade << std::endl;
std::cerr << "turbineData[iTurbLoc].numForcePts = " << turbineData[iTurbLoc].numForcePts << std::endl;


} else if (turbineData[iTurbLoc].sType == EXTLOADS) {
turbineData[iTurbLoc].nBRfsiPtsBlade.resize(turbineData[iTurbLoc].numBlades);
Expand Down Expand Up @@ -2360,6 +2368,8 @@ void fast::OpenFAST::get_data_from_openfast(timeStep t) {
if (turbineData[iTurb].inflowType == 2) {
int nvelpts = get_numVelPtsLoc(iTurb);
int nfpts = get_numForcePtsLoc(iTurb);
std::cerr << "nvelpts = " << nvelpts << std::endl;
std::cerr << "nfpts = " << nfpts << " " << get_numForcePtsBladeLoc(iTurb) << " " << get_numForcePtsTwrLoc(iTurb) << std::endl;
for (int i=0; i<nvelpts; i++) {
velForceNodeData[iTurb][t].x_vel_resid += (velForceNodeData[iTurb][t].x_vel[i*3+0] - extinfw_i_f_FAST[iTurb].pxVel[i])*(velForceNodeData[iTurb][t].x_vel[i*3+0] - extinfw_i_f_FAST[iTurb].pxVel[i]);
velForceNodeData[iTurb][t].x_vel[i*3+0] = extinfw_i_f_FAST[iTurb].pxVel[i];
Expand Down Expand Up @@ -2588,7 +2598,7 @@ void fast::OpenFAST::writeOutputFile(int iTurbLoc, int n_t_global) {
double curTime = n_t_global * dtFAST;
ierr = nc_put_vara_double(ncid, ncOutVarIDs_["time"], &n_tsteps, &count1, &curTime);

if (turbineData[iTurbLoc].sType == EXTINFLOW) {
if ( (turbineData[iTurbLoc].sType == EXTINFLOW) && (turbineData[iTurbLoc].inflowType == 2) ) {

// Nothing to do here yet
int nBlades = get_numBladesLoc(iTurbLoc);
Expand Down Expand Up @@ -2883,7 +2893,7 @@ void fast::OpenFAST::writeRestartFile(int iTurbLoc, int n_t_global) {
double curTime = n_t_global * dtFAST;
ierr = nc_put_vara_double(ncid, ncRstVarIDs_["time"], &n_tsteps, &count1, &curTime);

if (turbineData[iTurbLoc].sType == EXTINFLOW) {
if ( (turbineData[iTurbLoc].sType == EXTINFLOW) && (turbineData[iTurbLoc].inflowType == 2) ){

int nvelpts = get_numVelPtsLoc(iTurbLoc);
int nfpts = get_numForcePtsLoc(iTurbLoc);
Expand Down
12 changes: 9 additions & 3 deletions modules/openfast-library/src/FAST_Library.f90
Original file line number Diff line number Diff line change
Expand Up @@ -704,13 +704,19 @@ subroutine FAST_ExtInfw_Init(iTurb, TMax, InputFileName_c, TurbID, OutFileRoot_c

dt_c = Turbine(iTurb)%p_FAST%dt

InflowType = Turbine(iTurb)%p_FAST%CompInflow
if (Turbine(iTurb)%p_FAST%CompInflow == Module_ExtInfw) then
InflowType = 2
else if (Turbine(iTurb)%p_FAST%CompInflow == Module_IfW) then
InflowType = 1
else
InflowType = 0
end if

if ( (InflowType == 3) .and. (NumActForcePtsBlade .eq. 0) .and. (NumActForcePtsTower .eq. 0) ) then
if ( (Turbine(iTurb)%p_FAST%CompInflow == Module_ExtInfw) .and. (NumActForcePtsBlade .eq. 0) .and. (NumActForcePtsTower .eq. 0) ) then
CALL SetErrStat(ErrID_Warn, "Number of actuator points is zero when inflow type is 2. Mapping of loads may not work. ", ErrStat, ErrMsg, RoutineName )
end if

if ( (InflowType .ne. 3) .and. ((NumActForcePtsBlade .ne. 0) .or. (NumActForcePtsTower .ne. 0)) ) then
if ( (Turbine(iTurb)%p_FAST%CompInflow .ne. Module_ExtInfw) .and. ((NumActForcePtsBlade .ne. 0) .or. (NumActForcePtsTower .ne. 0)) ) then
!!FAST reassigns CompInflow after reading it to a module number based on an internal list in the FAST_Registry. So 2 in input file becomes 3 inside the code.
CALL SetErrStat(ErrID_Fatal, "Number of requested actuator points is non-zero when inflow type is not 2. Please set number of actuator points to zero when induction is turned on.", ErrStat, ErrMsg, RoutineName )
ErrStat_c = ErrStat
Expand Down

0 comments on commit 69fb0b8

Please sign in to comment.