Closed Craig44 closed 6 years ago
Is anything like that possible?
@Craig44 : unfortunately not. STENCILA_DIM
is a convenience macro which generates code (so you don't have to do it) for an array dimension. The whole approach of the Stencila Arrays and Dimensions is that they have a fixed, known size at compile time. This makes them very fast (because they are contiguous in memory and the compiler can apply a bunch of optimisations to them). Generally, the more the "size: and "shape" of your model is fixed at compile time the faster it will be.
But with respect to lat/lon at least you may be able to keep the dimensions fixed but allow some user customisation to how that maps to reality (like we do for Length
) e.g. always have a 100 x 100 resolution spatial layer but allow the size and location to vary using parameters:
STENCILA_DIM(Lats,lats,lat,100);
// The following needs to go somewhere with access to parameters...
double lat_min = parameters.lat_min; // e,g, -45
double lat_max = parameters.lat_min; // e,g, -30
const double lat_size = (lat_max - lat_min)/100
int lat_mid(Stencila::Level<Lengths>& lat){
return lat_min + (lat.index() + 0.5) * lat_size;
}
I should also note that the Stencila Arrays are old code and there are probably better alternatives out there. Although It could be painful to swap them out for something else and I probably wouldn't recommend it unless they are causing real issues.
I am looking at generalizing the code base, and the most obvious is adding a parameter to change the the number of dimensions with a user input parameter. For example in here
changing
STENCILA_DIM(Regions,regions,region,3);
to
STENCILA_DIM(Regions,regions,region,parameters.number_of_regions);
Is anything like that possible?
This will relate to the preference movement stuff, as I was going to build lat and long dimensions to store preference attributes into a Stencilia array, but want that to be set based on an input parameter