API for Developers
Base Structures
CellBasedModels.BaseParameter
— Typestruct 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.
Field | Description |
---|---|
dtype::Symbol | Type specifying between :Int and :Float dtype. |
shape::Tuple | Shape of the field. The dimensions can be (:Local,:Global,:Neighbors (number of neighbors), :Dims (0,1,2,3), :Cells or :Medium). |
saveLevel::Int | Level specifying this variable at which level should be saved. |
origin::Symbol | Origin of the parameter. |
reassign::Bool | If to reupdate afte addign or removing agents of the Community. |
protected::Bool | If protected, you cannot access it directly with Community.parameter or Community[:parameter] |
reset::Bool | If 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. |
initialize | Initialize function that creates the parameter if not specified explicitely during Community. |
CellBasedModels.UserParameter
— Typemutable struct UserParameter
Structure that contains the properties of each of the user declared parameters.
Field | Description |
---|---|
dtype::DataType | Type of data |
scope::Symbol | If :agent, :model or :medium parameter |
update::Bool | If the variable is updated |
variable::Bool | Whether if this parameter is described with a Differential Equation |
pos::Int | Position that ocupies at the integration matrix |
CellBasedModels.SavingFile
— Typemutable struct SavingFile
Structure that stores the information of files used for saving Community information.
Auxiliar - Agent
CellBasedModels.checkDeclared
— Functionfunction 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.
CellBasedModels.change
— Functionfunction change(x,code)
Function called by update to add the .new if it is an update expression (e.g. x += 4 -> x.new += 4).
CellBasedModels.baseParameterToModifiable
— Functionfunction baseParameterToModifiable(sym)
Return sym coming from UserParameter.basePar changed to modifiable. (e.g. liNM_ -> liM_)
CellBasedModels.baseParameterNew
— FunctionbaseParameterNew(sym)
Return sym coming from UserParameter.basePar to new. (e.g. liM_ -> liMNew_)
CellBasedModels.agentArgs
— Functionfunction 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
.
CellBasedModels.agentArgsNeighbors
— Functionfunction 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.
CellBasedModels.getProperty
— Functionfunction getProperty(dict::OrderedDict,property::Symbol)
For a Ordered dictionary of {Symbols, Structure} like BASEPARAMETERS, get a specific field of the structure.
CellBasedModels.getSymbolsThat
— Functionfunction 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.
Function generation
CellBasedModels.functionDE
— Functionfunction 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
.
CellBasedModels.functionRule
— Functionfunction 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
.
Auxiliar - Metaprogramming
CellBasedModels.makeSimpleLoop
— Functionfunction makeSimpleLoop(code,abm;nloops=nothing)
Wrap code in loop iterating over the Community agents in the correct platform and dimensions (for medium).
CellBasedModels.addCuda
— Functionfunction 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.
CellBasedModels.cudaAdapt
— Functionfunction cudaAdapt(code,platform)
Adapt specific CPU forms of calling parameters (e.g. Atomic) to CUDA valid code (Atomic -> size 1 CuArray).
CellBasedModels.vectorize
— Functionfunction vectorize(code,agent)
Function that transforms the code provided in Agent to the vectorized form for wrapping around an executable function.
CellBasedModels.clean
— Functionfunction 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.
Auxiliar - Community
CellBasedModels.checkFormat
— Functionfunction 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.
CellBasedModels.checkLoaded
— Functionfunction checkLoaded(com)
Function that give error if the Community has not been loaded. Called before any step function.
CellBasedModels.@kernelListSurvived!
— Macromacro 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)
CellBasedModels.@kernelFillHolesParameters!
— Macromacro 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)
CellBasedModels.@kernelUpdateParameters!
— Macromacro kernelUpdateParameters!(platform)
Kernel to update agent parameters.
CellBasedModels.@update!
— Macromacro 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.
Neighbors
CellBasedModels.CBMNeighbors.@verletNeighbors
— Macromacro 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)
CellBasedModels.CBMNeighbors.@neighborsVerletTime
— Macromacro 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)
CellBasedModels.CBMNeighbors.@verletDisplacement
— Macromacro 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)
CellBasedModels.CBMNeighbors.@verletResetDisplacement
— Macromacro 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)
CellBasedModels.CBMNeighbors.@neighborsVerletDisplacement
— Macromacro 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)
CellBasedModels.CBMNeighbors.cellPos
— FunctioncellPos(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.
CellBasedModels.CBMNeighbors.cellPosNeigh
— Functionfunction 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]
CellBasedModels.CBMNeighbors.@assignCells
— Macromacro 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)
CellBasedModels.CBMNeighbors.@sortAgentsInCells
— Macromacro 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)
CellBasedModels.CBMNeighbors.@neighborsCellLinked
— Macromacro 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)
CellBasedModels.CBMNeighbors.@verletNeighborsCLVD
— Macromacro 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)
CellBasedModels.CBMNeighbors.@neighborsCLVD
— Macromacro 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)