-
Notifications
You must be signed in to change notification settings - Fork 84
SSC Compute Modules
Janine edited this page May 15, 2018
·
10 revisions
Compute modules in SSC are a structure that contain complete functions calculating large sections of a model in SAM. They serve as the main access points from external applications, including the SAM user interface and the SAM SDK. . For example, each technology model and financial model has its own compute module. Cost models may also have their own compute module. If you’re unsure whether your function should be a new compute module or not, please contact the SAM team.
- Create a new file named
cmod_compute_module_name.cpp
in thessc
folder of thessc
project (you can do this by copying, pasting, and renaming another compute module that you wish to emulate). - Open the ssc project solution
ssc/build_vs2017/ssc_vs2017.sln
. - Add the new compute module to the project solution. In Visual Studio, you do this by right clicking on the
ssc
project in the Solution Explorer, then selecting “Add” > “Existing Item”. Add the compute module file you just created. - Compute modules must be listed twice in
sscapi.cpp
, once inextern module_entry_info
and once instatic module_entry_info *module_table[]
. Follow the formatting of the other compute modules in each list.
The easiest way to create a new compute module is to copy and edit an existing compute module. lib_windbos.cpp
provides a fairly simple example with most of the required features. In general, all compute modules have the following sections:
- License at the top of the file
#include “core.h”
- Variable table- contains inputs and outputs to the compute module
- Vartype- options are
SSC_INPUT
,SSC_OUTPUT
, orSSC_INOUT
for things that are both an input and output to the function - Datatype- options are
SSC_NUMBER
,SSC_ARRAY
,SSC_TABLE
,SSC_MATRIX
,SSC_STRING
. For the most part, you should only use number, array, or string. - Name- the variable name that will show up externally to the compute module. This should be fairly descriptive.
- Label- the description of the variable that will show up externally. This should be more descriptive.
- Units- the units of the variable, ex
“kW”
or“%/yr”
- Group- used in the user interface to sort variables. For the most part, this should be the name of the compute module.
- Required_if- automatically parsed to determine if all required variables are supplied to a compute module.
-
“*”
indicates a required variable -
“?”
or“”
indicates an optional variable -
“?=20”
indicates an optional variable, that if a value is not supplied, will default to a value of 20 -
“variable_xyz=1”
indicates that the current variable is required only ifvariable_xyz
is equal to 1
-
- Constraints- items that are automatically parsed to provide some level of input checking. You should utilize the constraints as much as possible. Possible options for variables of type
SSC_NUMBER
includeINTEGER
,BOOLEAN
,POSITIVE
,NEGATIVE
,MIN=5
,MAX=25
, and for variables of typeSSC_ARRAY
can specify length withLENGTH=12
, where all numbers are specified by the writer.
- Vartype- options are
- Declaration of instance of compute_module class
-
add_var_info
function to add the variable table to the compute module -
exec()
function as the main function that gets called when someone calls the compute module- Read in all inputs- make sure to perform any input checking that was not possible using the variable table constraints.
- Inputs are usually read in as
double x = (double) as_number(“input_variable_name”);
. Other options includeas_string
, oras_array
. Theas_array
function returns a pointer to an array and also requires an input to save the length of the array, used to check its length as needed.
- Inputs are usually read in as
- Model calculations- can call out to external functions located in libraries or defined above the
exec
function in the compute module - Assignation of all outputs
- Output assignations generally look like
assign( “output_variable_name”, var_data(previously_calculated_variable) );
- Output assignations generally look like
- Read in all inputs- make sure to perform any input checking that was not possible using the variable table constraints.
- Definition of compute module entry, including description of what the compute module accomplishes