Skip to content

Commit 15863a1

Browse files
authored
Merge pull request OpenFAST#18 from psakievich/memory_fix
Move super controller to unique_ptr
2 parents 0f5b00f + b3092a4 commit 15863a1

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

glue-codes/openfast-cpp/src/OpenFAST.H

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <unordered_map>
1010
#include <set>
1111
#include <map>
12+
#include <memory>
1213
#include "netcdf.h"
1314
#include "dlfcn.h"
1415
//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.
@@ -357,7 +358,7 @@ class OpenFAST {
357358
create_sc_t * create_SuperController;
358359
typedef void destroy_sc_t(SuperController *);
359360
destroy_sc_t * destroy_SuperController;
360-
SuperController * sc;
361+
std::unique_ptr<SuperController> sc;
361362

362363
// MPI related book keeping for all processors containing turbines
363364
//! Number of processors in a fastMPIGroup
@@ -486,8 +487,8 @@ class OpenFAST {
486487
void getBladeRloc(double * bldRloc, int iTurbGlob);
487488
//! Get the blade reference positions array 'bldRefPos' of turbine number 'iTurbGlob'
488489
void getBladeRefPositions(double* bldRefPos, int iTurbGlob, int nSize=6);
489-
//! Get the blade root reference positions array 'bldRootRefPos' of turbine number 'iTurbGlob'
490-
void getBladeRootRefPositions(double* bldRootRefPos, int iTurbGlob, int nSize=6);
490+
//! Get the blade root reference positions array 'bldRootRefPos' of turbine number 'iTurbGlob'
491+
void getBladeRootRefPositions(double* bldRootRefPos, int iTurbGlob, int nSize=6);
491492
//! Get the blade deflections array 'bldDefl' of turbine number 'iTurbGlob' at time step 't'
492493
void getBladeDisplacements(double* bldDefl, double* bldVel, int iTurbGlob, fast::timeStep t = fast::STATE_NP1, int nSize=6);
493494
//! Get the blade root deflections array 'bldRootDefl' of turbine number 'iTurbGlob' at time step 't'

glue-codes/openfast-cpp/src/OpenFAST.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fast::fastInputs::fastInputs():
3434
fast::OpenFAST::OpenFAST()
3535
{
3636

37-
sc = new SuperController();
37+
sc = std::unique_ptr<SuperController>(new SuperController);
3838

3939
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"};
4040
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"};
@@ -160,7 +160,7 @@ void fast::OpenFAST::prepareRestartFile(int iTurbLoc) {
160160
const std::vector<int> twrDefLoadsDims{ncRstDimIDs_["n_tsteps"], ncRstDimIDs_["n_states"], ncRstDimIDs_["n_twr_data"]};
161161
const std::vector<int> bldDefLoadsDims{ncRstDimIDs_["n_tsteps"], ncRstDimIDs_["n_states"], ncRstDimIDs_["n_bld_data"]};
162162
const std::vector<int> bldRootDefsDims{ncRstDimIDs_["n_tsteps"], ncRstDimIDs_["n_states"], ncRstDimIDs_["n_bld_root_data"]};
163-
const std::vector<int> bldPitchDims{ncRstDimIDs_["n_tsteps"], ncRstDimIDs_["n_states"], ncRstDimIDs_["n_bld_pitch_data"]};
163+
const std::vector<int> bldPitchDims{ncRstDimIDs_["n_tsteps"], ncRstDimIDs_["n_states"], ncRstDimIDs_["n_bld_pitch_data"]};
164164
const std::vector<int> ptDefLoadsDims{ncRstDimIDs_["n_tsteps"], ncRstDimIDs_["n_states"], ncRstDimIDs_["n_pt_data"],};
165165

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

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

@@ -1053,7 +1053,7 @@ void fast::OpenFAST::predict_states() {
10531053
for (int k=0; k < 3; k++) {
10541054
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]);
10551055
}
1056-
}
1056+
}
10571057

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

18171817
std::vector<double> hubShftVec(3);
18181818
getHubShftDir(hubShftVec, iTurbGlob, fast::STATE_NP1);
1819-
1819+
18201820
int nfpts = get_numForcePtsBlade(iTurbLoc);
18211821
for (int k=0; k < get_numBladesLoc(iTurbLoc); k++) {
18221822
for (int j=0; j < nfpts; j++) {
@@ -2404,7 +2404,7 @@ void fast::OpenFAST::readRestartFile(int iTurbLoc, int n_t_global) {
24042404
const std::vector<size_t> twrDataDims{1, 1, static_cast<size_t>(6*nBRfsiPtsTwr)};
24052405
const std::vector<size_t> bldDataDims{1, 1, static_cast<size_t>(6*nTotBRfsiPtsBlade)};
24062406
const std::vector<size_t> bldRootDataDims{1, 1, static_cast<size_t>(6*nBlades)};
2407-
const std::vector<size_t> bldPitchDataDims{1, 1, static_cast<size_t>(nBlades)};
2407+
const std::vector<size_t> bldPitchDataDims{1, 1, static_cast<size_t>(nBlades)};
24082408
const std::vector<size_t> ptDataDims{1, 1, 6};
24092409

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

24312431
}
24322432

2433-
2433+
24342434

24352435
}
24362436

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

28322832
for (size_t j=0; j < 4; j++) { // Loop over states - STATE_NM2, STATE_NM1, STATE_N, STATE_NP1
@@ -2996,7 +2996,7 @@ void fast::OpenFAST::getBladeDisplacements(double* bldDefl, double* bldVel, int
29962996
<< brFSIData[iTurbLoc][t].bld_vel[iRunTot*6+3] << ","
29972997
<< brFSIData[iTurbLoc][t].bld_vel[iRunTot*6+4] << ","
29982998
<< brFSIData[iTurbLoc][t].bld_vel[iRunTot*6+5] << std::endl;
2999-
2999+
30003000
for (int k=0; k < nSize; k++) {
30013001
bldDefl[iRunTot*6+k] = brFSIData[iTurbLoc][t].bld_def[iRunTot*6+k];
30023002
bldVel[iRunTot*6+k] = brFSIData[iTurbLoc][t].bld_vel[iRunTot*6+k];
@@ -3140,7 +3140,7 @@ void fast::OpenFAST::setUniformXBladeForces(double loadX) {
31403140
int nBldPts = turbineData[iTurb].nBRfsiPtsBlade[iBlade];
31413141
dr[iNode] = 0.5*(brFSIData[iTurb][3].bld_rloc[iNode+1] - brFSIData[iTurb][3].bld_rloc[iNode]);
31423142
iNode++;
3143-
3143+
31443144
for(int i=1; i < nBldPts-1; i++) {
31453145
dr[iNode] = 0.5*(brFSIData[iTurb][3].bld_rloc[iNode+1] - brFSIData[iTurb][3].bld_rloc[iNode-1]);
31463146
iNode++;

0 commit comments

Comments
 (0)