Skip to content

Commit

Permalink
Merge pull request #18 from rafmudaf/f/fast-farm
Browse files Browse the repository at this point in the history
FAST.Farm-C++ API Bug Fixes
  • Loading branch information
jjonkman authored Apr 13, 2021
2 parents f9df102 + e650a23 commit e543649
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 59 deletions.
69 changes: 42 additions & 27 deletions glue-codes/openfast-cpp/src/OpenFAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,19 @@ void fast::OpenFAST::init() {
if (nTurbinesProc > 0) velNodeDataFile = openVelocityDataFile(false);

if(scStatus) {
sc.readRestartFile(nt_global);
std::cout << "Use of Supercontroller is not supported through the C++ API right now" << std::endl;
//sc.readRestartFile(nt_global);
}

break ;

case fast::init:

if (scStatus) {
sc.init(scio, nTurbinesProc, turbineMapProcToGlob, fastMPIComm);
sc.calcOutputs_n(0.0);
sc.init(scio, nTurbinesProc);
if(scStatus) {
std::cout << "Use of Supercontroller is not supported through the C++ API right now" << std::endl;
// sc.init_sc(scio, nTurbinesProc, turbineMapProcToGlob, fastMPIComm);
// sc.calcOutputs_n(0.0);
}

// this calls the Init() routines of each module
Expand Down Expand Up @@ -154,9 +157,11 @@ void fast::OpenFAST::init() {

case fast::restartDriverInitFAST:

sc.init(scio, nTurbinesProc);
if(scStatus) {
sc.init(scio, nTurbinesProc, turbineMapProcToGlob, fastMPIComm);
sc.calcOutputs_n(0.0);
std::cout << "Use of Supercontroller is not supported through the C++ API right now" << std::endl;
// sc.init_sc(scio, nTurbinesProc, turbineMapProcToGlob, fastMPIComm);
// sc.calcOutputs_n(0.0);
}

for (int iTurb=0; iTurb < nTurbinesProc; iTurb++) {
Expand Down Expand Up @@ -244,7 +249,8 @@ void fast::OpenFAST::solution0() {
// }

if(scStatus) {
sc.fastSCInputOutput();
std::cout << "Use of Supercontroller is not supported through the C++ API right now" << std::endl;
// sc.fastSCInputOutput();
}

for (int iTurb=0; iTurb < nTurbinesProc; iTurb++) {
Expand All @@ -255,8 +261,9 @@ void fast::OpenFAST::solution0() {
timeZero = false;

if (scStatus) {
sc.calcOutputs_n(0.0);
sc.fastSCInputOutput();
std::cout << "Use of Supercontroller is not supported through the C++ API right now" << std::endl;
// sc.calcOutputs_n(0.0);
// sc.fastSCInputOutput();
}
}
}
Expand Down Expand Up @@ -319,16 +326,18 @@ void fast::OpenFAST::step() {
}

if(scStatus) {
sc.updateStates(nt_global * dtFAST); // Predict state at 'n+1' based on inputs
sc.calcOutputs_np1( (nt_global + 1) * dtFAST);
sc.fastSCInputOutput();
std::cout << "Use of Supercontroller is not supported through the C++ API right now" << std::endl;
// sc.updateStates(nt_global * dtFAST); // Predict state at 'n+1' based on inputs
// sc.calcOutputs_np1( (nt_global + 1) * dtFAST);
// sc.fastSCInputOutput();
}


nt_global = nt_global + 1;

if(scStatus) {
sc.advanceTime(); // Advance states, inputs and outputs from 'n' to 'n+1'
std::cout << "Use of Supercontroller is not supported through the C++ API right now" << std::endl;
// sc.advanceTime(); // Advance states, inputs and outputs from 'n' to 'n+1'
}

if ( (((nt_global - ntStart) % nEveryCheckPoint) == 0 ) && (nt_global != ntStart) ) {
Expand All @@ -345,9 +354,10 @@ void fast::OpenFAST::step() {
checkError(ErrStat, ErrMsg);
}
if(scStatus) {
if (fastMPIRank == 0) {
sc.writeRestartFile(nt_global);
}
std::cout << "Use of Supercontroller is not supported through the C++ API right now" << std::endl;
// if (fastMPIRank == 0) {
// sc.writeRestartFile(nt_global);
// }
}
}

Expand All @@ -372,15 +382,17 @@ void fast::OpenFAST::stepNoWrite() {
}

if(scStatus) {
sc.updateStates( nt_global * dtFAST); // Predict state at 'n+1' based on inputs
sc.calcOutputs_np1( (nt_global+1) * dtFAST);
sc.fastSCInputOutput();
std::cout << "Use of Supercontroller is not supported through the C++ API right now" << std::endl;
// sc.updateStates( nt_global * dtFAST); // Predict state at 'n+1' based on inputs
// sc.calcOutputs_np1( (nt_global+1) * dtFAST);
// sc.fastSCInputOutput();
}

nt_global = nt_global + 1;

if(scStatus) {
sc.advanceTime(); // Advance states, inputs and outputs from 'n' to 'n+1'
std::cout << "Use of Supercontroller is not supported through the C++ API right now" << std::endl;
// sc.advanceTime(); // Advance states, inputs and outputs from 'n' to 'n+1'
}

}
Expand Down Expand Up @@ -820,8 +832,10 @@ void fast::OpenFAST::allocateMemory() {
cDriver_Input_from_FAST.resize(nTurbinesProc) ;
cDriver_Output_to_FAST.resize(nTurbinesProc) ;

if(!scStatus)
scio.from_SC.resize(nTurbinesProc);
if(scStatus) {
std::cout << "Use of Supercontroller is not supported through the C++ API right now" << std::endl;
// scio.from_SC.resize(nTurbinesProc);
}
}

void fast::OpenFAST::allocateTurbinesToProcsSimple() {
Expand Down Expand Up @@ -852,9 +866,9 @@ void fast::OpenFAST::end() {
MPI_Group_free(&worldMPIGroup);

if(scStatus) {
sc.end();

}
std::cout << "Use of Supercontroller is not supported through the C++ API right now" << std::endl;
// sc.end();
}
}

void fast::OpenFAST::readVelocityData(int nTimesteps) {
Expand Down Expand Up @@ -1007,8 +1021,9 @@ void fast::OpenFAST::applyVelocityData(int iPrestart, int iTurb, OpFM_OutputType
void fast::OpenFAST::loadSuperController(const fast::fastInputs & fi) {

if(fi.scStatus) {
scStatus = fi.scStatus;
sc.load(fi.nTurbinesGlob, fi.scLibFile, scio);
std::cout << "Use of Supercontroller is not supported through the C++ API right now" << std::endl;
// scStatus = fi.scStatus;
// sc.load(fi.nTurbinesGlob, fi.scLibFile, scio);

} else {

Expand Down
39 changes: 21 additions & 18 deletions glue-codes/openfast-cpp/src/SC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ nStatesTurbine(0)
}

SuperController::~SuperController() {

if (nTurbinesProc > 0) {

if(scLibHandle != NULL) {
// close the library
std::cout << "Closing SC library..." << std::endl;
dlclose(scLibHandle);
}
// close the library
if (sc_library_loaded) {
std::cout << "Closing SC library..." << std::endl;
dlclose(scLibHandle);
}
}

Expand All @@ -33,6 +29,7 @@ void SuperController::load(int inNTurbinesGlob, std::string inScLibFile, scInitO
if (!scLibHandle) {
std::cerr << "Cannot open library: " << dlerror() << '\n';
}
sc_library_loaded = true;

sc_init = (sc_init_t*) dlsym(scLibHandle, "sc_init");
// reset errors
Expand Down Expand Up @@ -99,7 +96,22 @@ void SuperController::load(int inNTurbinesGlob, std::string inScLibFile, scInitO

}

void SuperController::init(scInitOutData & scio, int inNTurbinesProc, std::map<int, int> iTurbineMapProcToGlob, MPI_Comm inFastMPIComm) {
void SuperController::init(scInitOutData & scio, int nTurbinesProc) {
ip_from_FAST.resize(nTurbinesProc) ;
op_to_FAST.resize(nTurbinesProc) ;

scio.nSC2CtrlGlob = 0;
scio.nSC2Ctrl = 0;
scio.nCtrl2SC = 0;

scio.from_SCglob.resize(nSC2CtrlGlob);
scio.from_SC.resize(nTurbinesProc);
for(int iTurb=0; iTurb < nTurbinesProc; iTurb++) {
scio.from_SC[iTurb].resize(nSC2Ctrl);
}
}

void SuperController::init_sc(scInitOutData & scio, int inNTurbinesProc, std::map<int, int> iTurbineMapProcToGlob, MPI_Comm inFastMPIComm) {

fastMPIComm = inFastMPIComm;
nTurbinesProc = inNTurbinesProc;
Expand Down Expand Up @@ -132,17 +144,8 @@ void SuperController::init(scInitOutData & scio, int inNTurbinesProc, std::map<i
to_SCglob_n.resize(nTurbinesGlob*nInpGlobal);
to_SCglob_np1.resize(nTurbinesGlob*nInpGlobal);

ip_from_FAST.resize(nTurbinesProc) ;
op_to_FAST.resize(nTurbinesProc) ;

sc_getInitData(&nTurbinesGlob, &nParamGlobal, &nParamTurbine, paramGlobal.data(), paramTurbine.data(), &nSC2CtrlGlob, from_SCglob_nm1.data(), &nSC2Ctrl, from_SC_nm1.data(), &nStatesGlobal, globStates.data(), &nStatesTurbine, turbineStates.data(), &ErrStat, ErrMsg);

scio.from_SC.resize(nTurbinesProc);
for(int iTurb=0; iTurb < nTurbinesProc; iTurb++)
scio.from_SC[iTurb].resize(nSC2Ctrl);

scio.from_SCglob.resize(nSC2CtrlGlob);

for(int i=0; i < nSC2CtrlGlob; i++) {
scio.from_SCglob[i] = from_SCglob_nm1[i];
}
Expand Down
5 changes: 4 additions & 1 deletion glue-codes/openfast-cpp/src/SC.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <string>
#include <vector>
#include <map>
#include "mpi.h"
#include "hdf5.h"
#include "dlfcn.h"

Expand Down Expand Up @@ -86,6 +87,7 @@ class SuperController {
void *scLibHandle ;
typedef void sc_init_t(int * nTurbinesGlob, int * nInpGlobal, int * nCtrl2SC, int * nParamGlobal, int * nParamTurbine, int * nStatesGlobal, int * nStatesTurbine, int * nSC2CtrlGlob, int * nSC2Ctrl, int *ErrStat, char * ErrMsg);
sc_init_t * sc_init;
bool sc_library_loaded = false;

typedef void sc_getInitData_t(int * nTurbinesGlob, int * nParamGlobal, int * nParamTurbine, float * paramGlobal, float * paramTurbine, int * nSC2CtrlGlob, float * from_SCglob, int * nSC2Ctrl, float * from_SC, int * nStatesGlobal, float * globStates, int * nStatesTurbine, float * turbineStates, int *ErrStat, char * ErrMsg);
sc_getInitData_t * sc_getInitData;
Expand All @@ -103,7 +105,8 @@ class SuperController {

~SuperController() ;

void init(scInitOutData & scio, int inNTurbinesProc, std::map<int, int> iTurbineMapProcToGlob, MPI_Comm inFastMPIComm);
void init(scInitOutData & scio, int nTurbinesProc);
void init_sc(scInitOutData & scio, int inNTurbinesProc, std::map<int, int> iTurbineMapProcToGlob, MPI_Comm inFastMPIComm);

void load(int inNTurbinesGlob, std::string inScLibFile, scInitOutData & scio);

Expand Down
22 changes: 13 additions & 9 deletions modules/openfast-library/src/FAST_Library.f90
Original file line number Diff line number Diff line change
Expand Up @@ -665,16 +665,20 @@ subroutine SetOpenFOAM_pointers(iTurb, OpFM_Input_from_FAST, OpFM_Output_to_FAST
OpFM_Input_from_FAST%momentz_Len = Turbine(iTurb)%OpFM%u%c_obj%momentz_Len; OpFM_Input_from_FAST%momentz = Turbine(iTurb)%OpFM%u%c_obj%momentz
OpFM_Input_from_FAST%forceNodesChord_Len = Turbine(iTurb)%OpFM%u%c_obj%forceNodesChord_Len; OpFM_Input_from_FAST%forceNodesChord = Turbine(iTurb)%OpFM%u%c_obj%forceNodesChord

SC_DX_Input_from_FAST%toSC_Len = Turbine(iTurb)%SC_DX%u%c_obj%toSC_Len
SC_DX_Input_from_FAST%toSC = Turbine(iTurb)%SC_DX%u%c_obj%toSC

OpFM_Output_to_FAST%u_Len = Turbine(iTurb)%OpFM%y%c_obj%u_Len; OpFM_Output_to_FAST%u = Turbine(iTurb)%OpFM%y%c_obj%u
OpFM_Output_to_FAST%v_Len = Turbine(iTurb)%OpFM%y%c_obj%v_Len; OpFM_Output_to_FAST%v = Turbine(iTurb)%OpFM%y%c_obj%v
OpFM_Output_to_FAST%w_Len = Turbine(iTurb)%OpFM%y%c_obj%w_Len; OpFM_Output_to_FAST%w = Turbine(iTurb)%OpFM%y%c_obj%w
if (Turbine(iTurb)%p_FAST%UseSC) then
SC_DX_Input_from_FAST%toSC_Len = Turbine(iTurb)%SC_DX%u%c_obj%toSC_Len
SC_DX_Input_from_FAST%toSC = Turbine(iTurb)%SC_DX%u%c_obj%toSC
end if

OpFM_Output_to_FAST%u_Len = Turbine(iTurb)%OpFM%y%c_obj%u_Len; OpFM_Output_to_FAST%u = Turbine(iTurb)%OpFM%y%c_obj%u
OpFM_Output_to_FAST%v_Len = Turbine(iTurb)%OpFM%y%c_obj%v_Len; OpFM_Output_to_FAST%v = Turbine(iTurb)%OpFM%y%c_obj%v
OpFM_Output_to_FAST%w_Len = Turbine(iTurb)%OpFM%y%c_obj%w_Len; OpFM_Output_to_FAST%w = Turbine(iTurb)%OpFM%y%c_obj%w

if (Turbine(iTurb)%p_FAST%UseSC) then
SC_DX_Output_to_FAST%fromSC_Len = Turbine(iTurb)%SC_DX%y%c_obj%fromSC_Len
SC_DX_Output_to_FAST%fromSC = Turbine(iTurb)%SC_DX%y%c_obj%fromSC
end if

SC_DX_Output_to_FAST%fromSC_Len = Turbine(iTurb)%SC_DX%y%c_obj%fromSC_Len
SC_DX_Output_to_FAST%fromSC = Turbine(iTurb)%SC_DX%y%c_obj%fromSC

end subroutine SetOpenFOAM_pointers
!==================================================================================================================================
subroutine FAST_OpFM_Step(iTurb, ErrStat_c, ErrMsg_c) BIND (C, NAME='FAST_OpFM_Step')
Expand Down
12 changes: 8 additions & 4 deletions modules/servodyn/src/ServoDyn.f90
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,20 @@ SUBROUTINE SrvD_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, InitO
p%UseSC = .FALSE.
END IF

IF (InitInp%NumSC2Ctrl > 0 .and. p%UseBladedInterface) THEN
IF (p%UseBladedInterface) THEN
CALL AllocAry( u%fromSC, InitInp%NumSC2Ctrl, 'u%fromSC', ErrStat2, ErrMsg2 )
if (Failed()) return;
u%fromSC = InitInp%fromSC
if (InitInp%NumSC2Ctrl > 0 ) then
u%fromSC = InitInp%fromSC
end if
END IF

IF (InitInp%NumSC2CtrlGlob > 0 .and. p%UseBladedInterface) THEN
IF (p%UseBladedInterface) THEN
CALL AllocAry( u%fromSCglob, InitInp%NumSC2CtrlGlob, 'u%fromSCglob', ErrStat2, ErrMsg2 )
if (Failed()) return;
u%fromSCglob = InitInp%fromSCGlob
if (InitInp%NumSC2CtrlGlob > 0) then
u%fromSCglob = InitInp%fromSCGlob
end if
END IF

u%BlPitch = p%BlPitchInit(1:p%NumBl)
Expand Down

0 comments on commit e543649

Please sign in to comment.