API for Developers

Base Structures

CellBasedModels.BaseParameterType
struct BaseParameter

Object containing the information of each field of the Community object that is fent to the different stepping functions as they appear in BASEPARAMETERS.

FieldDescription
dtype::SymbolType specifying between :Int and :Float dtype.
shape::TupleShape of the field. The dimensions can be (:Local,:Global,:Neighbors (number of neighbors), :Dims (0,1,2,3), :Cells or :Medium).
saveLevel::IntLevel specifying this variable at which level should be saved.
origin::SymbolOrigin of the parameter.
reassign::BoolIf to reupdate afte addign or removing agents of the Community.
protected::BoolIf protected, you cannot access it directly with Community.parameter or Community[:parameter]
reset::BoolIf reset, this parameters will be set to zero before each interactionStep!.
necessaryFor::Vector{Symbol}When declaring Community, if necessary this parameters will be asked if not declared.
initializeInitialize function that creates the parameter if not specified explicitely during Community.
source
CellBasedModels.UserParameterType
mutable struct UserParameter

Structure that contains the properties of each of the user declared parameters.

FieldDescription
dtype::DataTypeType of data
scope::SymbolIf :agent, :model or :medium parameter
update::BoolIf the variable is updated
variable::BoolWhether if this parameter is described with a Differential Equation
pos::IntPosition that ocupies at the integration matrix
source

Auxiliar - Agent

CellBasedModels.checkDeclaredFunction
function checkDeclared(a::Symbol, abm::ABM) 
function checkDeclared(a::Array{Symbol}, abm::ABM)

Check if a symbol is already declared in the model or inherited models.

source
CellBasedModels.changeFunction
function change(x,code)

Function called by update to add the .new if it is an update expression (e.g. x += 4 -> x.new += 4).

source
CellBasedModels.agentArgsFunction
function agentArgs(abm;sym=nothing,l=3,params=BASEPARAMETERS)

Function that returns the arguments to be provided to a kernel function. If sym is provided, it will return them as sym.argument.

source
CellBasedModels.agentArgsNeighborsFunction
function agentArgs(sym=nothing;params=BASEPARAMETERS)

Function that returns the arguments obervable for the constructed functions. If symbol is given, it substitutes by the fielnames in form of by sym.fieldname.

source
CellBasedModels.getPropertyFunction
function getProperty(dict::OrderedDict,property::Symbol)

For a Ordered dictionary of {Symbols, Structure} like BASEPARAMETERS, get a specific field of the structure.

source
CellBasedModels.getSymbolsThatFunction
function getSymbolsThat(dict::OrderedDict,property::Symbol,condition)
function getSymbolsThat(dict::OrderedDict,property::Symbol,condition::Array)

For a Ordered dictionary of {Symbols, Structure} like BASEPARAMETERS, and a specific field (property) of the structure. If the property has as value of the condition, returns that symbol.

source

Function generation

CellBasedModels.functionDEFunction
function functionDE(abm,scope,type)

Creates the final code for Differential Equation functions to be provided to DifferentialEquations.ODEProblem. scope is between agent, model and medium, type SDE or ODE.

source
CellBasedModels.functionRuleFunction
function functionRule(abm,scope)

Creates the final code provided to ABM in a Rule function and adds it to the ABM. scope is between agent, model and medium.

source

Auxiliar - Metaprogramming

CellBasedModels.makeSimpleLoopFunction
function makeSimpleLoop(code,abm;nloops=nothing)

Wrap code in loop iterating over the Community agents in the correct platform and dimensions (for medium).

source
CellBasedModels.addCudaFunction
function addCuda(code,platform::Symbol;oneThread=false)
function addCuda(code,agent;oneThread=false)

Add cuda macro to execute the kernel with the correspondent number of threads and blocks. If one thread, launches the kernel just with one thread.

source
CellBasedModels.cudaAdaptFunction
function cudaAdapt(code,platform)

Adapt specific CPU forms of calling parameters (e.g. Atomic) to CUDA valid code (Atomic -> size 1 CuArray).

source
CellBasedModels.vectorizeFunction
function vectorize(code,agent)

Function that transforms the code provided in Agent to the vectorized form for wrapping around an executable function.

source
CellBasedModels.cleanFunction
function clean(code,it=5)

Simplify code by removing multiplications by 1 or 0 and additions of 0 that appear sometimes when generating the integration code.

source

Auxiliar - Community

CellBasedModels.checkFormatFunction
function checkFormat(sym,args,prop,dict,agent)

Function that checks that the args provided to Community are from the same type that the ones provided by automatic initialization property in BASEPARAMETERS. If they are not, it gives an error.

source
CellBasedModels.checkLoadedFunction
function checkLoaded(com)

Function that give error if the Community has not been loaded. Called before any step function.

source
CellBasedModels.@kernelListSurvived!Macro
macro kernelListSurvived!()

Macro that constructs the kernel that listes the survived agents from the end of the list to fill the left gaps by removed agents.

Generates the code of the kernel function:

function kernelListSurvivedCPU!(community)
function kernelListSurvivedGPU!(community)
source
CellBasedModels.@kernelFillHolesParameters!Macro
macro kernelFillHolesParameters!()

Macro to generate the function to fill the holes left by dead agents with the survived agents listed by listSurvivedGPU! over all the parameters that have :Local dimension (are proportional to agents).

Creates the function:

kernelFillHolesBaseCPU!(community)
kernelFillHolesBaseGPU!(community)
source
CellBasedModels.@update!Macro
macro updateGPU!(arg,arg2)

Macro that constructs the function:

function updateGPU!(community)

Function groups together the functions:

  • listSurvivedGPU!
  • fillHolesGPU!
  • updateParametersGPU

And updates the number of agents and resets the corresponding parmaeters after update.

source

Neighbors

CellBasedModels.CBMNeighbors.@verletNeighborsMacro
macro verletNeighbors(platform, args...)

Macro to generate the code for the computation of Verlet lists for different platforms and dimensions.

Adds the following functions to the library:

verletNeighbors!(x::Array)
verletNeighbors!(x::Array,y::Array)
verletNeighbors!(x::Array,y::Array,z::Array)
verletNeighbors!(x::CuArray)
verletNeighbors!(x::CuArray,y::CuArray)
verletNeighbors!(x::CuArray,y::CuArray,z::CuArray)
source
CellBasedModels.CBMNeighbors.@neighborsVerletTimeMacro
macro neighborsVerletTime(platform, args...)

Macro to generate the code for the computation of Verlet lists updated by Verlet Time algorithm.

Adds the following functions to the library:

neighborsVerletTime1CPU!(community)
neighborsVerletTime2CPU!(community)
neighborsVerletTime3CPU!(community)
neighborsVerletTime1GPU!(community)
neighborsVerletTime2GPU!(community)
neighborsVerletTime3GPU!(community)
source
CellBasedModels.CBMNeighbors.@verletDisplacementMacro
macro verletDisplacement(platform, args...)

Macro to generate the code for the check of Verlet lists recomputation flag according to Verlet Displacement algorithm.

Adds the following functions to the library:

verletDisplacementCPU!(x)
verletDisplacementCPU!(x,y)
verletDisplacementCPU!(x,y,z)
verletDisplacementGPU!(x)
verletDisplacementGPU!(x,y)
verletDisplacementGPU!(x,y,z)
source
CellBasedModels.CBMNeighbors.@verletResetDisplacementMacro
macro verletResetDisplacement(platform, args...)

Macro to generate the code to store the positions of the agents in the last recomputation of Verlet lists for Verlet Displacement algorithm.

Adds the following functions to the library:

verletResetDisplacementCPU!(x)
verletResetDisplacementCPU!(x,y)
verletResetDisplacementCPU!(x,y,z)
verletResetDisplacementGPU!(x)
verletResetDisplacementGPU!(x,y)
verletResetDisplacementGPU!(x,y,z)
source
CellBasedModels.CBMNeighbors.@neighborsVerletDisplacementMacro
macro neighborsVerletDisplacement(platform, args...)

Macro to generate the code for the computation of Verlet lists updated by Verlet Displacement algorithm. This function puts together the action of:

  • verletDisplacement
  • resetVerletDisplacement
  • verletList

Adds the following functions to the library:

neighborsVerletDisplacement1CPU!(community)
neighborsVerletDisplacement2CPU!(community)
neighborsVerletDisplacement3CPU!(community)
neighborsVerletDisplacement1GPU!(community)
neighborsVerletDisplacement2GPU!(community)
neighborsVerletDisplacement3GPU!(community)
source
CellBasedModels.CBMNeighbors.cellPosFunction
cellPos(edge,x,xMin,xMax,nX)
cellPos(edge,x,xMin,xMax,nX,y,yMin,yMax,nY)
cellPos(edge,x,xMin,xMax,nX,y,yMin,yMax,nY,z,zMin,zMax,nZ)

Function that returns the position of the abm in a cell list given their coordinates and cell grid properties.

source
CellBasedModels.CBMNeighbors.cellPosNeighFunction
function cellPosNeigh(pos,i,nX)
function cellPosNeigh(pos,i,nX,nY)
function cellPosNeigh(pos,i,nX,nY,nZ)

Returns the position of the neighbors cells to the current cell i (pos in 1D = 1-3, in 2D 1-9...) and gives -1 is the pos is a boundary.

e.g.

grid =

1 2 3 4 5 6 7 8 9 10 11 12

cellPosNeigh(4,5,4,3) = -1 For i = 5 the outcomes of all the positions will be [-1,1,2,-1,5,6,-1,9,10]

source
CellBasedModels.CBMNeighbors.@assignCellsMacro
macro assignCells(platform, args...)

Macro to generate the code to assign abm to a cell.

Adds the following functions to the library:

assignCells1CPU!(community)
assignCells2CPU!(community)
assignCells3CPU!(community)
assignCells1GPU!(community)
assignCells2GPU!(community)
assignCells3GPU!(community)
source
CellBasedModels.CBMNeighbors.@sortAgentsInCellsMacro
macro sortAgentsInCells(platform, args...)

Macro to generate the code to sort agents in cells in cell order.

Adds the following functions to the library:

sortAgentsInCells1CPU!(community)
sortAgentsInCells2CPU!(community)
sortAgentsInCells3CPU!(community)
sortAgentsInCells1GPU!(community)
sortAgentsInCells2GPU!(community)
sortAgentsInCells3GPU!(community)
source
CellBasedModels.CBMNeighbors.@neighborsCellLinkedMacro
macro neighborsCellLinked(platform, args...)

Macro to generate the code to compute neighbors according to cell linked algorithm. This function puts together the action of: - assignCells - sortAgentsInCells

Adds the following functions to the library:

neighborsCellLinked1CPU!(community)
neighborsCellLinked2CPU!(community)
neighborsCellLinked3CPU!(community)
neighborsCellLinked1GPU!(community)
neighborsCellLinked2GPU!(community)
neighborsCellLinked3GPU!(community)
source
CellBasedModels.CBMNeighbors.@verletNeighborsCLVDMacro
macro verletNeighborsCLVD(platform, args...)

Macro to generate the code for the computation of Verlet lists going over CellLinked lists for different platforms and dimensions .

Adds the following functions to the library:

verletNeighborsCLVDCPU!(x)
verletNeighborsCLVDCPU!(x,y)
verletNeighborsCLVDCPU!(x,y,z)
verletNeighborsCLVDGPU!(x)
verletNeighborsCLVDGPU!(x,y)
verletNeighborsCLVDGPU!(x,y,z)
source
CellBasedModels.CBMNeighbors.@neighborsCLVDMacro
macro neighborsCLVD(platform, args...)

Macro to generate the code to compute neighbors according to CellLinked-VerletDistance algorithms.

Adds the following functions to the library:

neighborsCLVD1CPU!(community)
neighborsCLVD2CPU!(community)
neighborsCLVD3CPU!(community)
neighborsCLVD1GPU!(community)
neighborsCLVD2GPU!(community)
neighborsCLVD3GPU!(community)
source