00001
00009 #ifndef _CLIMATE_H
00010 #define _CLIMATE_H
00011
00012 #include <stdarg.h>
00013 #include "gridlabd.h"
00014 #include "solar_angles.h"
00015 #include "weather_reader.h"
00016 #include "csv_reader.h"
00017 #include <vector>
00018
00019 typedef enum{
00020 CP_H = 0,
00021 CP_N = 1,
00022 CP_NE = 2,
00023 CP_E = 3,
00024 CP_SE = 4,
00025 CP_S = 5,
00026 CP_SW = 6,
00027 CP_W = 7,
00028 CP_NW = 8,
00029 CP_LAST = 9
00030 } COMPASS_PTS;
00031
00032 typedef enum{
00033 CI_NONE = 0,
00034 CI_LINEAR,
00035 CI_QUADRATIC
00036 };
00037
00038 typedef enum{
00039 CM_NONE = 0,
00040 CM_CUMULUS = 1
00041 } CLOUDMODEL;
00042
00043
00044 typedef struct s_tmy {
00045 double temp;
00046 double temp_raw;
00047 double rh;
00048 double dnr;
00049 double dhr;
00050 double ghr;
00051 double solar[CP_LAST];
00052 double solar_raw;
00053 double direct_normal_extra;
00054 double pressure;
00055 double windspeed;
00056 double rainfall;
00057 double snowdepth;
00058 double solar_azimuth;
00059 double solar_elevation;
00060 double solar_zenith;
00061 double global_horizontal_extra;
00062 double wind_dir;
00063 double tot_sky_cov;
00064 double opq_sky_cov;
00065 } TMYDATA;
00066
00067
00068 EXPORT int64 calculate_solar_radiation_degrees(OBJECT *obj, double tilt, double orientation, double *value);
00069 EXPORT int64 calculate_solar_radiation_radians(OBJECT *obj, double tilt, double orientation, double *value);
00070 EXPORT int64 calculate_solar_radiation_shading_degrees(OBJECT *obj, double tilt, double orientation, double shading_value, double *value);
00071 EXPORT int64 calculate_solar_radiation_shading_position_radians(OBJECT *obj, double tilt, double orientation, double latitude, double longitude, double shading_value, double *value);
00072 EXPORT int64 calculate_solar_radiation_shading_radians(OBJECT *obj, double tilt, double orientation, double shading_value, double *value);
00073 EXPORT int64 calc_solar_solpos_shading_deg(OBJECT *obj, double tilt, double orientation, double shading_value, double *value);
00074 EXPORT int64 calc_solar_solpos_shading_position_rad(OBJECT *obj, double tilt, double orientation, double latitude, double longitude, double shading_value, double *value);
00075 EXPORT int64 calc_solar_solpos_shading_rad(OBJECT *obj, double tilt, double orientation, double shading_value, double *value);
00076 EXPORT int64 calc_solar_ideal_shading_position_radians(OBJECT *obj, double tilt, double latitude, double longitude, double shading_value, double *value);
00077
00087 class tmy2_reader{
00088 private:
00089
00090 char data_city[75];
00091 char data_state[3];
00092 int lat_degrees;
00093 int lat_minutes;
00094 int long_degrees;
00095 int long_minutes;
00096
00097 double low_temp;
00098 double high_temp;
00099 double peak_solar;
00100
00101 FILE *fp;
00102
00103
00104 public:
00105 int tz_offset;
00106 char buf[500];
00107 tmy2_reader(){}
00108
00109 int elevation;
00110
00111 void close();
00112
00121 int open(const char *file);
00122
00126 int next();
00127
00138 int header_info(char* city, char* state, int* degrees, int* minutes, int* long_deg, int* long_min);
00139
00155 int read_data(double *dnr, double *dhr, double *ghr, double *tdb, double *rh, int* month, int* day, int* hour, double *wind=0, double *winddir=0, double *precip=0, double *snowDepth=0, double *pressure = 0, double *extra_terr_dni=0, double *extra_terr_ghi=0, double *tot_sky_cov=0, double *opq_sky_cov=0);
00156
00159 double calc_solar(COMPASS_PTS cpt, short doy, double lat, double sol_time, double dnr, double dhr, double ghr, double gnd_ref, double vert_angle);
00160
00161 };
00162
00163 typedef struct {
00164 double low;
00165 double low_day;
00166 double high;
00167 double high_day;
00168 double solar;
00169 } CLIMATERECORD;
00170
00171 typedef enum {
00172 RT_NONE,
00173 RT_TMY2,
00174 RT_CSV,
00175 };
00176
00177 class climate : public gld_object {
00178
00179
00180 GL_STRING(char32,city);
00181 GL_ATOMIC(double,temperature);
00182 GL_ATOMIC(double,humidity);
00183 GL_ATOMIC(double,wind_speed);
00184 GL_ATOMIC(double,tz_meridian);
00185 GL_ATOMIC(double,solar_global);
00186 GL_ATOMIC(double,solar_direct);
00187 GL_ATOMIC(double,solar_diffuse);
00188 GL_ATOMIC(double,solar_cloud_global);
00189 GL_ATOMIC(double,solar_cloud_direct);
00190 GL_ATOMIC(double,solar_cloud_diffuse);
00191 GL_ATOMIC(double,cloud_alpha);
00192
00193
00194
00195 GL_ATOMIC(double,cloud_num_layers);
00196 GL_ATOMIC(double,cloud_aerosol_transmissivity);
00197 GL_ATOMIC(double,ground_reflectivity);
00198 GL_STRUCT(CLIMATERECORD,record);
00199 GL_ATOMIC(double,rainfall);
00200 GL_ATOMIC(double,snowdepth);
00201 GL_STRING(char1024,forecast_spec);
00202 GL_STRING(char1024,tmyfile);
00203 GL_ATOMIC(OBJECT*,reader);
00204 GL_ATOMIC(double,temperature_raw);
00205 GL_ARRAY(double,solar_flux,CP_LAST);
00206 GL_ATOMIC(double,solar_raw);
00207 GL_ATOMIC(double,wind_dir);
00208 GL_ATOMIC(double,wind_gust);
00209 GL_ATOMIC(enumeration,interpolate);
00210 GL_ATOMIC(double,solar_elevation);
00211 GL_ATOMIC(double,solar_azimuth);
00212 GL_ATOMIC(double,solar_zenith);
00213 GL_ATOMIC(double,direct_normal_extra);
00214 GL_ATOMIC(double,pressure);
00215 GL_ATOMIC(double,tz_offset_val);
00216 GL_ATOMIC(double,global_horizontal_extra);
00217 GL_ATOMIC(double,tot_sky_cov);
00218 GL_ATOMIC(double,opq_sky_cov);
00219 GL_ATOMIC(double,cloud_opacity);
00220 GL_ATOMIC(double,cloud_reflectivity);
00221 GL_ATOMIC(double,cloud_speed_factor);
00222 GL_ATOMIC(enumeration,cloud_model);
00223 GL_ATOMIC(double,update_time);
00224
00225
00226 private:
00227 SolarAngles *sa;
00228 tmy2_reader file;
00229 weather_reader *reader_hndl;
00230 TMYDATA *tmy;
00231 public:
00232 enumeration reader_type;
00233 static CLASS *oclass;
00234 static climate *defaults;
00235 public:
00236 void update_forecasts(TIMESTAMP t0);
00237 void init_cloud_pattern(void);
00238 void update_cloud_pattern(TIMESTAMP dt);
00239 int get_solar_for_location(double latitude, double longitude, double *direct, double *global, double *diffuse);
00240 private:
00241 int calc_cloud_pattern_size(std::vector<std::vector<double> > &location_list);
00242 void build_cloud_pattern(int col_min, int col_max, int row_min, int row_max);
00243 void write_out_cloud_pattern(char pattern);
00244 void write_out_pattern_shift(int row_shift, int col_shift);
00245 void rebuild_cloud_pattern_edge( char edge_needing_rebuilt);
00246 void trim_pattern_edge( char rebuilt_edge);
00247 void erase_off_screen_pattern( char edge_to_erase);
00248 int get_fuzzy_cloud_value_for_location(double latitude, double longitude, double *cloud);
00249 int get_binary_cloud_value_for_location(double latitude, double longitude, int *cloud);
00250 double convert_to_binary_cloud();
00251 void convert_to_fuzzy_cloud( double cut_elevation, int num_fuzzy_layers, double alpha);
00252 TIMESTAMP prev_NTime;
00253 int MIN_LAT_INDEX;
00254 int MAX_LAT_INDEX;
00255 double MIN_LAT;
00256 double MAX_LAT;
00257 int MIN_LON_INDEX;
00258 int MAX_LON_INDEX;
00259 double MIN_LON;
00260 double MAX_LON;
00261 double global_transmissivity;
00262 public:
00263 climate(MODULE *module);
00264 int create(void);
00265 int init(OBJECT *parent);
00266 int isa(char *classname);
00267 TIMESTAMP presync(TIMESTAMP t0);
00268 inline TIMESTAMP sync(TIMESTAMP t0) { return TS_NEVER; };
00269 inline TIMESTAMP postsync(TIMESTAMP t0) { return TS_NEVER; };
00270 };
00271
00272 #endif
00273