1
- connector_comp_name (i:: Int ) = Symbol (" ConnectorComp$i " )
1
+ """
2
+ _substitute_views!(vals::Array{T, N}, comp_def) where {T, N}
2
3
4
+ For each value in `vals`, if the value is a `TimestepArray` swap in a new
5
+ TimestepArray with the same type parameterization but with its `data` field
6
+ holding a view of the original value's `data` defined by the first and last
7
+ indices of Component `comp_def`.
8
+ """
3
9
# helper function to substitute views for data
4
10
function _substitute_views! (vals:: Array{T, N} , comp_def) where {T, N}
5
11
times = [keys (comp_def. dim_dict[:time ])... ]
@@ -12,6 +18,13 @@ function _substitute_views!(vals::Array{T, N}, comp_def) where {T, N}
12
18
end
13
19
end
14
20
21
+ """
22
+ _get_view(val::TimestepArray{T_TS, T, N, ti, S}, first_idx, last_idx) where {T_TS, T, N, ti, S}
23
+
24
+ Return a TimestepArray with the same type parameterization as the `val` TimestepArray,
25
+ but with its `data` field holding a view of the `val.data` based on the entered
26
+ `first-idx` and `last_idx`.
27
+ """
15
28
function _get_view (val:: TimestepArray{T_TS, T, N, ti, S} , first_idx, last_idx) where {T_TS, T, N, ti, S}
16
29
17
30
idxs = Array {Any} (fill (:, N))
@@ -21,7 +34,12 @@ function _get_view(val::TimestepArray{T_TS, T, N, ti, S}, first_idx, last_idx) w
21
34
return TimestepArray {T_TS, T, N, ti} (val. data isa SubArray ? view (val. data. parent, idxs... ) : view (val. data, idxs... ))
22
35
end
23
36
24
- # Return the datatype to use for instance variables/parameters
37
+ """
38
+ _instance_datatype(md::ModelDef, def::AbstractDatumDef)
39
+
40
+ Return the datatype of the AbstractDataumDef `def` in ModelDef `md`, which will
41
+ be used to create ModelInstance instance variables and parameters.
42
+ """
25
43
function _instance_datatype (md:: ModelDef , def:: AbstractDatumDef )
26
44
dtype = def. datatype == Number ? number_type (md) : def. datatype
27
45
dims = dim_names (def)
@@ -51,6 +69,13 @@ function _instance_datatype(md::ModelDef, def::AbstractDatumDef)
51
69
return T
52
70
end
53
71
72
+ """
73
+ _instantiate_datum(md::ModelDef, def::AbstractDatumDef)
74
+
75
+ Return the parameterized datum, broadly either Scalar or Array, pertaining to
76
+ AbstractDatumDef `def` in the Model Def `md`, that will support instantiate of parameters
77
+ and variables.
78
+ """
54
79
# Create the Ref or Array that will hold the value(s) for a Parameter or Variable
55
80
function _instantiate_datum (md:: ModelDef , def:: AbstractDatumDef )
56
81
dtype = _instance_datatype (md, def)
@@ -106,7 +131,12 @@ function _instantiate_component_vars(md::ModelDef, comp_def::ComponentDef)
106
131
return ComponentInstanceVariables (names, types, values, paths)
107
132
end
108
133
109
- # Creates the top-level vars for the model
134
+ """
135
+ function _instantiate_vars(md::ModelDef)
136
+
137
+ Create the top-level variables for the Model Def `md` and return the dictionary
138
+ of the resulting ComponentInstanceVariables.
139
+ """
110
140
function _instantiate_vars (md:: ModelDef )
111
141
vdict = Dict {ComponentPath, Any} ()
112
142
recurse (md, cd -> vdict[cd. comp_path] = _instantiate_component_vars (md, cd); leaf_only= true )
@@ -207,7 +237,16 @@ function _get_leaf_level_epcs(md::ModelDef, epc::ExternalParameterConnection)
207
237
return leaf_epcs
208
238
end
209
239
210
- # Collect all parameters with connections to allocated variable storage
240
+ # generic helper function to get connector component name
241
+ connector_comp_name (i:: Int ) = Symbol (" ConnectorComp$i " )
242
+
243
+ """
244
+ _collect_params(md::ModelDef, var_dict::Dict{ComponentPath, Any})
245
+
246
+ Collect all parameters in ModelDef `md` with connections to allocated variable
247
+ storage in `var_dict` and return a dictionary of (comp_path, par_name) => ModelParameter
248
+ elements.
249
+ """
211
250
function _collect_params (md:: ModelDef , var_dict:: Dict{ComponentPath, Any} )
212
251
213
252
# @info "Collecting params for $(comp_def.comp_id)"
@@ -251,6 +290,12 @@ function _collect_params(md::ModelDef, var_dict::Dict{ComponentPath, Any})
251
290
return pdict
252
291
end
253
292
293
+ """
294
+ _instantiate_params(comp_def::ComponentDef, par_dict::Dict{Tuple{ComponentPath, Symbol}, Any})
295
+
296
+ Create the top-level parameters for the Model Def `md` using the parameter dictionary
297
+ `par_dict` and return the resulting ComponentInstanceParameters.
298
+ """
254
299
function _instantiate_params (comp_def:: ComponentDef , par_dict:: Dict{Tuple{ComponentPath, Symbol}, Any} )
255
300
# @info "Instantiating params for $(comp_def.comp_path)"
256
301
comp_path = comp_def. comp_path
@@ -263,7 +308,16 @@ function _instantiate_params(comp_def::ComponentDef, par_dict::Dict{Tuple{Compon
263
308
return ComponentInstanceParameters (names, types, vals, paths)
264
309
end
265
310
266
- # Return a built leaf or composite LeafComponentInstance
311
+ """
312
+ _build(comp_def::ComponentDef,
313
+ var_dict::Dict{ComponentPath, Any},
314
+ par_dict::Dict{Tuple{ComponentPath, Symbol}, Any},
315
+ time_bounds::Tuple{Int, Int})
316
+
317
+ Return a built leaf or composite LeafComponentInstance created using ComponentDef
318
+ `comp_def`, variables and parameters from `var_dict` and `par_dict` and the time
319
+ bounds set by `time_bounds`.
320
+ """
267
321
function _build (comp_def:: ComponentDef ,
268
322
var_dict:: Dict{ComponentPath, Any} ,
269
323
par_dict:: Dict{Tuple{ComponentPath, Symbol}, Any} ,
@@ -278,6 +332,16 @@ function _build(comp_def::ComponentDef,
278
332
return LeafComponentInstance (comp_def, vars, pars, time_bounds)
279
333
end
280
334
335
+ """
336
+ _build(comp_def::AbstractCompositeComponentDef,
337
+ var_dict::Dict{ComponentPath, Any},
338
+ par_dict::Dict{Tuple{ComponentPath, Symbol}, Any},
339
+ time_bounds::Tuple{Int, Int})
340
+
341
+ Return a built CompositeComponentInstance created using AbstractCompositeComponentDef
342
+ `comp_def`, variables and parameters from `var_dict` and `par_dict` and the time
343
+ bounds set by `time_bounds`.
344
+ """
281
345
function _build (comp_def:: AbstractCompositeComponentDef ,
282
346
var_dict:: Dict{ComponentPath, Any} ,
283
347
par_dict:: Dict{Tuple{ComponentPath, Symbol}, Any} ,
@@ -318,6 +382,11 @@ function _get_parameters(comp_def::AbstractCompositeComponentDef)
318
382
return parameters
319
383
end
320
384
385
+ """
386
+ _build(md::ModelDef)
387
+
388
+ Build ModelDef `md` (lowest build function called by `build(md::ModelDef)`) and return the ModelInstance..
389
+ """
321
390
function _build (md:: ModelDef )
322
391
323
392
# @info "_build(md)"
@@ -347,13 +416,23 @@ function _build(md::ModelDef)
347
416
return mi
348
417
end
349
418
419
+ """
420
+ build(m::Model)
421
+
422
+ Build Model `m` and return the ModelInstance.
423
+ """
350
424
function build (m:: Model )
351
425
# Reference a copy in the ModelInstance to avoid changes underfoot
352
426
md = deepcopy (m. md)
353
427
mi = _build (md)
354
428
return mi
355
429
end
356
430
431
+ """
432
+ build!(m::Model)
433
+
434
+ Build Model `m` for and dirty `m`'s ModelDef.
435
+ """
357
436
function build! (m:: Model )
358
437
m. mi = build (m)
359
438
m. md. dirty = false
@@ -384,6 +463,11 @@ function Base.run(mm::MarginalModel; ntimesteps::Int=typemax(Int))
384
463
run (mm. modified, ntimesteps= ntimesteps)
385
464
end
386
465
466
+ """
467
+ build!(mm::MarginalModel)
468
+
469
+ Build MarginalModel `mm` by building both its `base` and `modified models`.
470
+ """
387
471
function build! (mm:: MarginalModel )
388
472
build! (mm. base)
389
473
build! (mm. modified)
0 commit comments