00001
00002 package gridlabd;
00003
00004 import java.util.Enumeration;
00005 import java.util.Hashtable;
00006
00018 public class GridlabD {
00019
00020 public static Hashtable<String, Long> proptype;
00021 public static final long TS_NEVER = Long.MAX_VALUE;
00022 public static final long TS_INVALID = -1;
00023 public static final long TS_ZERO = 0;
00024 public static final long TS_MAX = Long.MAX_VALUE;
00025 public static final long MINYEAR = 1970;
00026 public static final long MAXYEAR = 2969;
00027 public static final int PC_NOSYNC = 0;
00028 public static final int PC_PRETOPDOWN = 1;
00029 public static final int PC_BOTTOMUP = 2;
00030 public static final int PC_POSTTOPDOWN = 4;
00031 public static final double PI = 3.1415926535897932384626433832795;
00032 public static final double E = 2.71828182845905;
00033 public static final int NM_PREUPDATE = 0;
00034 public static final int NM_POSTUPDATE = 1;
00035 public static final int NM_RESET = 2;
00036 public static final int OF_NONE = 0;
00037 public static final int OF_HASPLC = 1;
00038 public static final int OF_LOCKED = 2;
00039 public static final int OF_RECALC = 8;
00040 public static final int OF_FOREIGN = 16;
00041 public static final int OF_SKIPSAFE = 32;
00042 public static final int OF_RERANK = 16384;
00043
00047 public static class Complex{
00048 public double re;
00049 public double im;
00051 public Complex(){
00052 re = 0.0;
00053 im = 0.0;
00054 }
00060 public Complex(double r, double i){
00061 re = r;
00062 im = i;
00063 }
00064 public String toString(){
00065 if(im >= 0.0)
00066 return Double.toString(re)+"+"+Double.toString(im)+"i";
00067 return Double.toString(re)+Double.toString(im)+"i";
00068 }
00069 }
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 Enumeration<Class> ec = ctable;
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 private static Hashtable<String, GModule> gmoduletable;
00253
00254 static
00255 {
00256 moduletable = new Hashtable<String, GridlabD.Module>();
00257 gmoduletable = new Hashtable<String, GModule>();
00258 proptype = new Hashtable<String, Long>();
00259 proptype.put("int16", new Long(2));
00260 proptype.put("int32", new Long(4));
00261 proptype.put("int64", new Long(8));
00262 proptype.put("double", new Long(8));
00263 proptype.put("char8", new Long(9));
00264 proptype.put("char32", new Long(33));
00265 proptype.put("char256", new Long(257));
00266 proptype.put("char1024",new Long(1025));
00267 proptype.put("complex", new Long(24));
00268 proptype.put("object", new Long(8));
00269 proptype.put("bool", new Long(4));
00270 proptype.put("timestamp", new Long(8));
00271 proptype.put("loadshape", new Long(256));
00272 proptype.put("enduse", new Long(256));
00273
00274 try{
00275 System.loadLibrary("glmjava");
00276 }
00277 catch(Throwable e){
00278 System.out.println(e);
00279 }
00280
00281 }
00282
00283 public static double clip(double x, double a, double b){
00284 if(x < a) return a;
00285 if(x > b) return b;
00286 return x;
00287 }
00288
00289 public static native int GetInt16(long block, long offset);
00290 public static native int GetInt32(long block, long offset);
00291 public static native long GetInt64(long block, long offset);
00292 public static native double GetDouble(long block, long offset);
00293 public static native double[] GetComplex(long block, long offset);
00294 public static native int SetInt16(long block, long offset, int value);
00295 public static native int SetInt32(long block, long offset, int value);
00296 public static native int SetInt64(long block, long offset, long value);
00297 public static native int SetDouble(long block, long offset, double value);
00298 public static native int SetComplex(long block, long offset, double r, double i);
00299
00300
00301 public static native int verbose(String str);
00302 public static native int output(String str);
00303 public static native int warning(String str);
00304 public static native int error(String str);
00305 public static native int debug(String str);
00306 public static native int testmsg(String str);
00307 public static native long malloc(int size);
00308
00309 public static native long get_module_var(String modulename, String varname);
00310 public static native String findfile(String filename);
00311 public static native long find_module(String modulename);
00312 public static native long register_class(long moduleaddr, String classname, int passconfig);
00313 public static native long create_object(long oclass_addr, long size);
00314 public static native long create_array(long oclass_addr, long size, int n_objects);
00315 public static native int object_isa(long obj_addr, String typename);
00316 public static native long publish_variable(long moduleaddr, long classaddr, String varname, String vartype, long offset);
00317 public static native long publish_function(String modulename, String classname, String funcname);
00318 public static native int set_dependent(long from_addr, long to_addr);
00319 public static native int set_parent(long child_addr, long parent_addr);
00320 public static native long register_type(long oclass_addr, String typename, String from_string_fname, String to_string_fname);
00321 public static native int publish_delegate();
00322 public static native long get_property(long objaddr, String propertyname);
00323 public static native long get_property_by_name(String objectname, String propertyname);
00324 public static native String get_value(long object_addr, String propertyname);
00325 public static native int set_value(long object_addr, String propertyname, String value);
00326 public static native double unit_convert(String from, String to, double invalue);
00327
00328 public static GridlabD.Complex get_complex(long object_addr, long property_addr){
00329 double r = get_complex_real(object_addr, property_addr);
00330 double i = get_complex_imag(object_addr, property_addr);
00331 return new GridlabD.Complex(r, i);
00332 }
00333 public static GridlabD.Complex get_complex_by_name(long object_addr, String propertyname){
00334 double r = get_complex_real_by_name(object_addr, propertyname);
00335 double i = get_complex_imag_by_name(object_addr, propertyname);
00336 return new GridlabD.Complex(r, i);
00337 }
00338 private static native double get_complex_real(long object_addr, long property_addr);
00339 private static native double get_complex_imag(long object_addr, long property_addr);
00340 private static native double get_complex_real_by_name(long object_addr, String propertyname);
00341 private static native double get_complex_imag_by_name(long object_addr, String propertyname);
00342 public static native long get_object(String oname);
00343 public static native long get_object_prop(long object_addr, long property_addr);
00344 public static native int get_int16(long object_addr, long property_addr);
00345 public static native int get_int16_by_name(long object_addr, String propertyname);
00346 public static native int get_int32(long object_addr, long property_addr);
00347 public static native int get_int32_by_name(long object_addr, String propertyname);
00348 public static native long get_int64(long object_addr, long property_addr);
00349 public static native long get_int64_by_name(long object_addr, String propertyname);
00350 public static native double get_double(long object_addr, long property_addr);
00351 public static native double get_double_by_name(long object_addr, String propertyname);
00352 public static native String get_string(long object_addr, long property_addr);
00353 public static native String get_string_by_name(long object_addr, String propertyname);
00354 public static native long[] find_objects(long findlist_addr, String[] args);
00355 public static native long find_next(long findlist_addr);
00356
00357 public static native long create_aggregate(String aggregator, String group_expression);
00358 public static native double run_aggregate(long aggregate_addr);
00359 public static native double random_uniform(double a, double b);
00360 public static native double random_normal(double m, double s);
00361 public static native double random_lognormal(double m, double s);
00362 public static native double random_bernoulli(double p);
00363 public static native double random_pareto(double m, double a);
00364 public static native double random_sampled(int n, double[] x);
00365 public static native double random_exponential(double l);
00366 public static native long parsetime(String value);
00367
00368 public static native int strtime(Object timestamp, String buffer, int size);
00369 public static native double todays(long t);
00370 public static native double tohours(long t);
00371 public static native double tominutes(long t);
00372 public static native int localtime(long t, Object datetime);
00373 public static native long global_create(String name, String args);
00374 public static native int global_setvar(String def, String args);
00375 public static native String global_getvar(String name);
00376 public static native long global_find(String name);
00377 public static native double clip(double x, double a, double b);
00378 public static native int bitof(long x);
00379 public static native String name(long myaddr);
00380 public static native long find_schedule(String name);
00381 public static native long schedule_create(String name, String def);
00382 public static native long schedule_index(long sch, long ts);
00383 public static native double schedule_value(long sch, long index);
00384 public static native long schedule_dtnext(long sch, long index);
00385 public static native long enduse_create();
00386 public static native int enduse_sync(long e, long t1);
00387 public static native long loadshape_create(long sched_addr);
00388 public static native double get_loadshape_value(long ls_addr)
00389
00390 public static native String strftime(long ts);
00391 public static native double lerp(double t, double x0, double y0, double x1, double y1);
00392 public static native double 1erp(double t, double x0, double y0, double x1, double y1, double x2, double y2);
00393 }