FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gridlab-d/java/SampleClass.java at master · INFERLab/gridlab-d · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
INFERLab
/
gridlab-d
Public
forked from
gridlab-d/gridlab-d
Notifications
You must be signed in to change notification settings
Fork
2
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
gridlab-d
/
java
/
SampleClass.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
158 lines (148 loc) · 6.25 KB
Breadcrumbs
gridlab-d
/
java
/
SampleClass.java
Copy path
File metadata and controls
158 lines (148 loc) · 6.25 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import
gridlabd
.*;
import
java
.
util
.
Hashtable
;
public
class
SampleClass
{
/// similar to CLASS *SampleClass. Must only be used by SampleClass type objects.
private
static
GClass
oclass
;
/** the per-class objtable is needed to register and access object built in Java, or they
will be garbage collected at the end of create() **/
private
static
Hashtable
<
Long
,
SampleClass
>
objtable
=
new
Hashtable
<
Long
,
SampleClass
>();
/// OBJECT *this ... gives us hooks into core space.
protected
GObject
obj
;
/// Constructors should be private, since the build process can fail.
private
SampleClass
(
GObject
o
,
long
paddr
){
obj
=
o
;
obj
.
SetParent
(
paddr
);
}
/* "abstract" funcs */
/* public static void register(GModule mod)
Grabs the oclass object and publishes the variables
NOTE: the class has already been registered with the core by the Build call.
*/
public
static
void
register
(
GClass
c
){
/* catch oclass */
oclass
=
c
;
/* add properties */
oclass
.
AddProperty
(
"bingo"
,
"char8"
);
oclass
.
AddProperty
(
"zingo"
,
"int16"
);
oclass
.
AddProperty
(
"zango"
,
"complex"
);
oclass
.
AddProperty
(
"zingo"
,
"double"
);
}
/** public static long create(long paddr)
Users are expected to implement thier own GClass.create() in order to construct
objects in the core that can be accessed by Java.
1.) long oaddr = GObject.BuildSingle(oclass);
1.) "long oaddr = GridlabD.create_object(classaddr, size)"
2.) "GClass obj = new GClass(oaddr, paddr)"
3.) "objtable.put(oaddr, obj)"
4.) Perform any create-time initialization that is independent of file input and external
values, namely non-zero defaults. The object block is memcpy(0)'d by the time
GridlabD.create_object() returns the address value.
5.) "return oaddr"
Replace "GClass" from above with your class
Any deviation from the form "public static long create(long)" will cause the underlying
C/JNI code to not find the method, error, and fail the load process.
@return value of oaddr if construction was successful, 0 if failed
**/
public
static
long
create
(
long
paddr
){
GObject
o
=
GObject
.
BuildSingle
(
oclass
);
if
(
o
==
null
){
GridlabD
.
error
(
"GObject.BuildSingle() failed"
);
return
0
;
}
SampleClass
sc
=
new
SampleClass
(
o
,
paddr
);
objtable
.
put
(
new
Long
(
o
.
GetAddr
()),
sc
);
/* any overridable initial values here */
/* return o.GetAddr() */
return
o
.
GetAddr
();
}
/* public static int init(long oaddr, long paddr)
* The init function is an option step for classes to calculate derived values based on initial
* conditions, and reality check values entered into published variables.
* @return Nonzero if successful, zero if the object was initialized or constructed badly
*/
public
static
int
init
(
long
oaddr
,
long
paddr
){
SampleClass
sc
=
objtable
.
get
(
new
Long
(
oaddr
));
if
(
sc
==
null
){
GridlabD
.
error
(
"SampleClass.init(): not one of our objects at 0x"
+
Long
.
toHexString
(
oaddr
));
}
/* your code here */
System
.
out
.
println
(
"SampleClass.init()"
);
/* success */
return
1
;
}
/* public static int commit(long oaddr)
* The commit function is an optional step for classes to update or output any strictly
* internal states between timesteps. Commit() is not called between iterations, but
* between clock changes.
* Objects that call commit() should not refer to external objects during the commit step,
* as the rank order is not maintained.
* @return Nonzero if successful, zero if the object is in an inconsistant state.
*/
public
static
int
commit
(
long
oaddr
){
SampleClass
sc
=
objtable
.
get
(
new
Long
(
oaddr
));
if
(
sc
==
null
){
GridlabD
.
error
(
"SampleClass.commit(): not one of our objects at 0x"
+
Long
.
toHexString
(
oaddr
));
}
/* your code here */
System
.
out
.
println
(
"SampleClass.commit()"
);
/* success */
return
1
;
}
/* public static long sync(long oaddr, long t0, int pass)
* Users are expected to implement their own GClass.sync() in order to receive
* periodic attention from the core as to when events are happening to at least one
* object in the core, ranging from as minor as a recorder reading to having the
* feeder voltage double for three seconds.
* No particular actions are required from user-defined sync() calls in Java, but the core
* will only notice published variables. There are no restrictions on using classes and
* variables in Java space, just be sure to write the results when you're done with them.
* @return Timestamp for next event, GridlabD.TS_NEVER if we're steady-state or finished, -1 on error, and the current clock value for ???.
*/
public
static
long
sync
(
long
oaddr
,
long
t0
,
int
pass
){
SampleClass
sc
=
objtable
.
get
(
new
Long
(
oaddr
));
if
(
sc
==
null
){
GridlabD
.
error
(
"SampleClass.sync(): not one of our objects at 0x"
+
Long
.
toHexString
(
oaddr
));
}
/* your code here */
System
.
out
.
println
(
"SampleClass.sync("
+
t0
+
")"
);
/* return next event timestamp */
return
GridlabD
.
TS_NEVER
;
}
/* public static int notify(long oaddr, int msg)
* "can be implemented to receive notification messages before and after a variable is changed by
* the core (GridlabD.NM_PREUPDATE / GridlabD.NM_POSTUPDATE) and when the core needs the module to
* reset (GridlabD.NM_RESET)"
* @return Nonzero on success, but often ignored.
*/
public
static
int
notify
(
long
oaddr
,
int
msg
){
SampleClass
sc
=
objtable
.
get
(
new
Long
(
oaddr
));
if
(
sc
==
null
){
GridlabD
.
error
(
"SampleClass.notify(): not one of our objects at 0x"
+
Long
.
toHexString
(
oaddr
));
}
/* your code here */
return
0
;
}
/* public static int isa(long oaddr)
* Used to determine if the object pointed to be oaddr is of the type or subtype for this
* class.
* @return Nonzero if true, zero if not a valid subtype.
*/
public
static
int
isa
(
long
oaddr
){
if
(
objtable
.
containsKey
(
new
Long
(
oaddr
)))
return
1
;
else
return
0
;
}
/** public static long plc(long oaddr, long t1)
"can be implemented to create default PLC code that can be overridden by attaching a
child plc object"
PLC code is called during the GridlabD.PC_BOTTOMUP pass.
PLC code is NOT called if OF_HASPLC is set, which indicates that a child object has PLC code
that overrides ours.
@return Timestamp for next event, GridlabD.TS_NEVER if we're steady-state or finished, -1 on error,
and the current clock value for ???.
**/
public
static
long
plc
(
long
oaddr
,
long
t1
){
return
GridlabD
.
TS_NEVER
;
}
}
Back
|
FazBrowse Home
|
New Git URL