Skip to content

Commit

Permalink
Merge pull request OpenFAST#18 from psakievich/memory_fix
Browse files Browse the repository at this point in the history
Move super controller to unique_ptr
  • Loading branch information
gantech authored Feb 8, 2023
2 parents 0f5b00f + b3092a4 commit 15863a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
7 changes: 4 additions & 3 deletions glue-codes/openfast-cpp/src/OpenFAST.H
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <unordered_map>
#include <set>
#include <map>
#include <memory>
#include "netcdf.h"
#include "dlfcn.h"
//TODO: The skip MPICXX is put in place primarily to get around errors in OpenFOAM. This will cause problems if the driver program uses C++ API for MPI.
Expand Down Expand Up @@ -357,7 +358,7 @@ class OpenFAST {
create_sc_t * create_SuperController;
typedef void destroy_sc_t(SuperController *);
destroy_sc_t * destroy_SuperController;
SuperController * sc;
std::unique_ptr<SuperController> sc;

// MPI related book keeping for all processors containing turbines
//! Number of processors in a fastMPIGroup
Expand Down Expand Up @@ -486,8 +487,8 @@ class OpenFAST {
void getBladeRloc(double * bldRloc, int iTurbGlob);
//! Get the blade reference positions array 'bldRefPos' of turbine number 'iTurbGlob'
void getBladeRefPositions(double* bldRefPos, int iTurbGlob, int nSize=6);
//! Get the blade root reference positions array 'bldRootRefPos' of turbine number 'iTurbGlob'
void getBladeRootRefPositions(double* bldRootRefPos, int iTurbGlob, int nSize=6);
//! Get the blade root reference positions array 'bldRootRefPos' of turbine number 'iTurbGlob'
void getBladeRootRefPositions(double* bldRootRefPos, int iTurbGlob, int nSize=6);
//! Get the blade deflections array 'bldDefl' of turbine number 'iTurbGlob' at time step 't'
void getBladeDisplacements(double* bldDefl, double* bldVel, int iTurbGlob, fast::timeStep t = fast::STATE_NP1, int nSize=6);
//! Get the blade root deflections array 'bldRootDefl' of turbine number 'iTurbGlob' at time step 't'
Expand Down
20 changes: 10 additions & 10 deletions glue-codes/openfast-cpp/src/OpenFAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fast::fastInputs::fastInputs():
fast::OpenFAST::OpenFAST()
{

sc = new SuperController();
sc = std::unique_ptr<SuperController>(new SuperController);

ncRstVarNames_ = {"time", "rst_filename", "twr_ref_pos", "bld_ref_pos", "nac_ref_pos", "hub_ref_pos", "twr_def", "twr_vel", "twr_ld", "bld_def", "bld_vel", "bld_ld", "hub_def", "hub_vel", "nac_def", "nac_vel", "bld_root_def", "bld_pitch", "x_vel", "xdot_vel", "vel_vel", "x_force", "xdot_force", "orient_force", "vel_force", "force"};
ncRstDimNames_ = {"n_tsteps", "n_states", "n_twr_data", "n_bld_data", "n_pt_data", "n_bld_root_data", "n_bld_pitch_data", "n_vel_pts_data", "n_force_pts_data", "n_force_pts_orient_data"};
Expand Down Expand Up @@ -160,7 +160,7 @@ void fast::OpenFAST::prepareRestartFile(int iTurbLoc) {
const std::vector<int> twrDefLoadsDims{ncRstDimIDs_["n_tsteps"], ncRstDimIDs_["n_states"], ncRstDimIDs_["n_twr_data"]};
const std::vector<int> bldDefLoadsDims{ncRstDimIDs_["n_tsteps"], ncRstDimIDs_["n_states"], ncRstDimIDs_["n_bld_data"]};
const std::vector<int> bldRootDefsDims{ncRstDimIDs_["n_tsteps"], ncRstDimIDs_["n_states"], ncRstDimIDs_["n_bld_root_data"]};
const std::vector<int> bldPitchDims{ncRstDimIDs_["n_tsteps"], ncRstDimIDs_["n_states"], ncRstDimIDs_["n_bld_pitch_data"]};
const std::vector<int> bldPitchDims{ncRstDimIDs_["n_tsteps"], ncRstDimIDs_["n_states"], ncRstDimIDs_["n_bld_pitch_data"]};
const std::vector<int> ptDefLoadsDims{ncRstDimIDs_["n_tsteps"], ncRstDimIDs_["n_states"], ncRstDimIDs_["n_pt_data"],};

ierr = nc_def_var(ncid, "twr_def", NC_DOUBLE, 3, twrDefLoadsDims.data(), &tmpVarID);
Expand All @@ -186,7 +186,7 @@ void fast::OpenFAST::prepareRestartFile(int iTurbLoc) {
ierr = nc_def_var(ncid, "bld_root_def", NC_DOUBLE, 3, bldRootDefsDims.data(), &tmpVarID);
ncRstVarIDs_["bld_root_def"] = tmpVarID;
ierr = nc_def_var(ncid, "bld_pitch", NC_DOUBLE, 3, bldPitchDims.data(), &tmpVarID);
ncRstVarIDs_["bld_pitch"] = tmpVarID;
ncRstVarIDs_["bld_pitch"] = tmpVarID;

} else if (turbineData[iTurbLoc].sType == EXTINFLOW) {

Expand Down Expand Up @@ -1053,7 +1053,7 @@ void fast::OpenFAST::predict_states() {
for (int k=0; k < 3; k++) {
brFSIData[iTurb][fast::STATE_NP1].bld_root_def[j*6+k] = brFSIData[iTurb][fast::STATE_NM2].bld_root_def[j*6+k] + 3.0*(brFSIData[iTurb][fast::STATE_N].bld_root_def[j*6+k] - brFSIData[iTurb][fast::STATE_NM1].bld_root_def[j*6+k]);
}
}
}

int nPtsTwr = turbineData[iTurb].nBRfsiPtsTwr;
for (int j=0; j < nPtsTwr; j++) {
Expand Down Expand Up @@ -1816,7 +1816,7 @@ void fast::OpenFAST::computeTorqueThrust(int iTurbGlob, double* torque, double*

std::vector<double> hubShftVec(3);
getHubShftDir(hubShftVec, iTurbGlob, fast::STATE_NP1);

int nfpts = get_numForcePtsBlade(iTurbLoc);
for (int k=0; k < get_numBladesLoc(iTurbLoc); k++) {
for (int j=0; j < nfpts; j++) {
Expand Down Expand Up @@ -2404,7 +2404,7 @@ void fast::OpenFAST::readRestartFile(int iTurbLoc, int n_t_global) {
const std::vector<size_t> twrDataDims{1, 1, static_cast<size_t>(6*nBRfsiPtsTwr)};
const std::vector<size_t> bldDataDims{1, 1, static_cast<size_t>(6*nTotBRfsiPtsBlade)};
const std::vector<size_t> bldRootDataDims{1, 1, static_cast<size_t>(6*nBlades)};
const std::vector<size_t> bldPitchDataDims{1, 1, static_cast<size_t>(nBlades)};
const std::vector<size_t> bldPitchDataDims{1, 1, static_cast<size_t>(nBlades)};
const std::vector<size_t> ptDataDims{1, 1, 6};

for (size_t j=0; j < 4; j++) { // Loop over states - NM2, STATE_NM1, N, NP1
Expand All @@ -2430,7 +2430,7 @@ void fast::OpenFAST::readRestartFile(int iTurbLoc, int n_t_global) {

}



}

Expand Down Expand Up @@ -2826,7 +2826,7 @@ void fast::OpenFAST::writeRestartFile(int iTurbLoc, int n_t_global) {
const std::vector<size_t> twrDataDims{1, 1, static_cast<size_t>(6*nPtsTwr)};
const std::vector<size_t> bldDataDims{1, 1, static_cast<size_t>(6*nTotBldPts)};
const std::vector<size_t> bldRootDataDims{1, 1, static_cast<size_t>(6*nBlades)};
const std::vector<size_t> bldPitchDataDims{1, 1, static_cast<size_t>(nBlades)};
const std::vector<size_t> bldPitchDataDims{1, 1, static_cast<size_t>(nBlades)};
const std::vector<size_t> ptDataDims{1, 1, 6};

for (size_t j=0; j < 4; j++) { // Loop over states - STATE_NM2, STATE_NM1, STATE_N, STATE_NP1
Expand Down Expand Up @@ -2996,7 +2996,7 @@ void fast::OpenFAST::getBladeDisplacements(double* bldDefl, double* bldVel, int
<< brFSIData[iTurbLoc][t].bld_vel[iRunTot*6+3] << ","
<< brFSIData[iTurbLoc][t].bld_vel[iRunTot*6+4] << ","
<< brFSIData[iTurbLoc][t].bld_vel[iRunTot*6+5] << std::endl;

for (int k=0; k < nSize; k++) {
bldDefl[iRunTot*6+k] = brFSIData[iTurbLoc][t].bld_def[iRunTot*6+k];
bldVel[iRunTot*6+k] = brFSIData[iTurbLoc][t].bld_vel[iRunTot*6+k];
Expand Down Expand Up @@ -3140,7 +3140,7 @@ void fast::OpenFAST::setUniformXBladeForces(double loadX) {
int nBldPts = turbineData[iTurb].nBRfsiPtsBlade[iBlade];
dr[iNode] = 0.5*(brFSIData[iTurb][3].bld_rloc[iNode+1] - brFSIData[iTurb][3].bld_rloc[iNode]);
iNode++;

for(int i=1; i < nBldPts-1; i++) {
dr[iNode] = 0.5*(brFSIData[iTurb][3].bld_rloc[iNode+1] - brFSIData[iTurb][3].bld_rloc[iNode-1]);
iNode++;
Expand Down

0 comments on commit 15863a1

Please sign in to comment.