OpenFAST
Wind turbine multiphysics simulator
SC.h
1 #ifndef OMPI_SKIP_MPICXX
2  #define OMPI_SKIP_MPICXX
3 #endif
4 #ifndef MPICH_SKIP_MPICXX
5  #define MPICH_SKIP_MPICXX
6 #endif
7 #include "FAST_Library.h"
8 #include <sstream>
9 #include <iostream>
10 #include <string>
11 #include <vector>
12 #include <map>
13 #include "mpi.h"
14 #include "hdf5.h"
15 #include "dlfcn.h"
16 
18 
19 public:
20  int nInpGlobal;
21  int nCtrl2SC;
22  int nSC2CtrlGlob;
23  int nSC2Ctrl;
24  std::vector<float> from_SCglob;
25  std::vector<std::vector<float>> from_SC;
26 };
27 
29 
30 public:
31 
32  // Data structures to interface with OpenFAST per turbine
33  // Unfortunately have to be public
34  std::vector<SC_DX_InputType_t> ip_from_FAST; // At time step 'n+1'
35  std::vector<SC_DX_OutputType_t> op_to_FAST; // At time step 'n'
36 
37 private:
38 
39  MPI_Comm fastMPIComm;
40 
41  int nTurbinesGlob;
42  int nTurbinesProc;
43  std::map<int, int> turbineMapProcToGlob;
44 
45  int nCtrl2SC;
46  int nSC2Ctrl;
47  int nInpGlobal;
48  int nSC2CtrlGlob;
49 
50  int nStatesGlobal; // Global states like time
51  std::vector<float> globStates;
52  std::vector<float> globStates_np1;
53 
54  int nStatesTurbine; // States for each turbine
55  std::vector<float> turbineStates ;
56  std::vector<float> turbineStates_np1 ;
57 
58  // Time 'n-1'
59  std::vector<float> from_SC_nm1; // # outputs from the supercontroller for turbines
60  std::vector<float> to_SC_nm1; // # inputs to the supercontroller from turbines
61  std::vector<float> from_SCglob_nm1; // # outputs from the supercontroller for glob
62  std::vector<float> to_SCglob_nm1; // # inputs to the supercontroller from glob
63  // Time 'n'
64  std::vector<float> from_SC_n; // # outputs from the supercontroller for turbines
65  std::vector<float> to_SC_n; // # inputs to the supercontroller from turbines
66  std::vector<float> from_SCglob_n; // # outputs from the supercontroller for glob
67  std::vector<float> to_SCglob_n; // # inputs to the supercontroller from glob
68  // Time 'n+1'
69  std::vector<float> from_SC_np1; // # outputs from the supercontroller for turbines
70  std::vector<float> to_SC_np1; // # inputs to the supercontroller from turbines
71  std::vector<float> from_SCglob_np1; // # outputs from the supercontroller for glob
72  std::vector<float> to_SCglob_np1; // # inputs to the supercontroller from glob
73 
74  int nParamGlobal;
75  std::vector<float> paramGlobal;
76  int nParamTurbine;
77  std::vector<float> paramTurbine;
78 
79  int ErrStat;
80  char ErrMsg[INTERFACE_STRING_LENGTH]; // make sure this is the same size as IntfStrLen in FAST_Library.f90
81 
82  float d2R = 0.01745329251 ; //Degrees to Radians
83 
84  //Supercontroller stuff
85  std::string scLibFile;
86  // Dynamic load stuff copied from 'C++ dlopen mini HOWTO' on tldp.org
87  void *scLibHandle ;
88  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);
89  sc_init_t * sc_init;
90  bool sc_library_loaded = false;
91 
92  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);
93  sc_getInitData_t * sc_getInitData;
94 
95  typedef void sc_updateStates_t(double * t, int * nTurbinesGlob, int * nParamGlobal, float * paramGlobal, int * nParamTurbine, float * paramTurbine, int * nInpGlobal, float * to_SCglob, int * nCtrl2SC, float * to_SC, int * nStatesGlobal, float * statesGlob_n, float * statesGlob_np1, int * nStatesTurbine, float * statesTurbine_n, float * statesTurbine_np1, int * ErrStat, char * ErrMsg);
96  sc_updateStates_t * sc_updateStates;
97 
98  typedef void sc_calcOutputs_t(double * t, int * nTurbinesGlob, int * nParamGlobal, float * paramGlobal, int * nParamTurbine, float * paramTurbine, int * nInpGlobal, float * to_SCglob, int * nCtrl2SC, float * to_SC, int * nStatesGlobal, float * statesGlob, int * nStatesTurbine, float * statesTurbine, int * nSC2CtrlGlob, float * from_SCglob, int * nSC2Ctrl, float * from_SC, int * ErrStat, char * ErrMsg);
99  sc_calcOutputs_t * sc_calcOutputs;
100 
101 
102 public:
103 
104  SuperController();
105 
106  ~SuperController() ;
107 
108  void init(scInitOutData & scio, int nTurbinesProc);
109  void init_sc(scInitOutData & scio, int inNTurbinesProc, std::map<int, int> iTurbineMapProcToGlob, MPI_Comm inFastMPIComm);
110 
111  void load(int inNTurbinesGlob, std::string inScLibFile, scInitOutData & scio);
112 
113  void updateStates(double t) ; //Make a prediction for states at 'n+1' based on inputs and states at 'n'
114 
115  void calcOutputs_n(double t) ;
116  void calcOutputs_np1(double t) ;
117 
118  void fastSCInputOutput() ; // Exchange input output information with OpenFAST turbines
119 
120  void advanceTime() ; //Advance states to time step 'n+1'
121 
122  int writeRestartFile(int n_t_global);
123 
124  int readRestartFile(int n_t_global);
125 
126  void end() {} ;
127 };
Definition: SC.h:17