Expand description
๐ถ๏ธ A modular, reusable, general-purpose backend
ยงUsage
In the following example, we provide an extremely short basic usage of the run_simulation
macro.
It performs the numerical integration of a well-defined problem.
We assume that the MyAgent
struct and MyDomain
have already been defined and implement the
Mechanics concept.
More details about how to use pre-existing building blocks or derive their functionality is
provided by the
cellular_raza_building_blocks
crate.
We will then solve our system for the
Mechanics
aspect.
// Initialize agents, domain, solving time and how to store results
let agents = (0..10).map(|n| MyAgent {
/* Define the agent's properties */
});
let domain = MyDomain {/* Define the domain*/};
let time = FixedStepsize::from_partial_save_interval(t0, dt, tmax, save_interval)?;
let storage = StorageBuilder::new().priority([StorageOption::Memory]);
// Group them together
let settings = Settings {
n_threads,
time,
storage,
show_progressbar: false,
};
// This will perform the numerical simulation
let storage_access = run_simulation!(
agents: agents,
domain: domain,
settings: settings,
aspects: [Mechanics],
core_path: cellular_raza_core,
)?;
// Use calculated results
let history = storage_access.cells.load_all_elements()?;
for (iteration, cells) in history {
// ...
}
This example cannot contain all the functionality which the chili backend provides. We encourage the user to look at the cellular-raza.com/guides and cellular-raza.com/showcase sections to get started.
ยงInternals
The chili backend uses procedural macros to generate code which results in a fully working simulation. The methods, functions and objects used in this way are formualted with generics. This enables us to write general-purpose solvers for a wide range of problems. The most important macro is the run_simulation macro which can be solely used to run simulations. This macro itself can be broken down into smaller pieces.
- prepare_types Defines types used in simulation
- build_aux_storage AuxStorage struct used to store intermediate values for update steps of aspects
- build_communicator Type which handles communication between threads
- test_compatibility Test compatibility of all types involved
- run_main Defines main loop and performs the simulation
These macros take a subset of keyword arguments of the run_simulation macro. The arguments are documented under the run_simulation macro.
ยงMain Loop
The run_main macro constructs the main loop of the simulation. It inserts functions depending on the given simulation aspects. They can be grouped into 6 steps Below, we show a list of all these functions and their corresponding aspects.
ยงStep 1 - Send Information
In this step, each sub
Aspects | Function | Purpose |
---|---|---|
Mechanics && Interaction | update_mechanics_interaction_step_1 | Send PosInformation between threads to get back ForceInformation |
DomainForce | calculate_custom_domain_force | Uses the SubDomainForce trait to add custom external force. |
ReactionsContact | update_contact_reactions_step_1 | Sends ReactionsContactInformation between threads. |
ReactionsExtra | update_reactions_extra_step_1 | Sends ReactionsExtraBorderInfo between threads. |
sync | Wait for threads to have finished until proceeding. |
ยงStep 2 - Calculate and Return
Aspects | Function | Purpose |
---|---|---|
Mechanics && Interaction | update_mechanics_interaction_step_2 | Calculate forces and return ForceInformation to the original sender. |
ReactionsContact | update_contact_reactions_step_2 | Calculates the combined increment and returns ReactionsContactReturn |
ReactionsExtra | update_reactions_extra_step_2 | Returns ReactionsExtraBorderReturn |
ยงStep 3 - Receive and Apply
Aspects | Function | Purpose |
---|---|---|
Mechanics && Interaction | update_mechanics_interaction_step_3 | Receives the ForceInformation and adds within the aux_storage . |
ReactionsContact | update_contact_reactions_step_3 | Receives the ReactionsContactReturn and adds within the aux_storage . |
ReactionsExtra | update_reactions_extra_step_3 | Receives the ReactionsExtraBorderReturn. |
ยงPure Local Functions - Perform Update
Aspects | Function | Purpose |
---|---|---|
Mechanics | local_mechanics_update | Performs numerical integration of the position and velocity. |
Interaction | local_interaction_react_to_neighbors | Performs changes due to neighbor counting. |
Cycle | local_cycle_update | Advances the cycle of the cell. This may introduce aCycleEvent |
Reactions | local_reactions_intracellular | Calculates increment from purely intracellular reactions. |
ReactionsContact | local_update_contact_reactions | Performs the update of the contact reactions. |
ReactionsExtra | local_subdomain_update_reactions_extra | Performs the update of the extracellular reactions. |
Reactions || ReactionsContact || ReactionsExtra | local_reactions_use_increment | Calculates increment from purely intracellular reactions. |
ยงStep 4 - Treat Cell Positions
Aspects | Function | Purpose |
---|---|---|
Mechanics | apply_boundary | Apply a boundary condition. |
Cycle | update_cell_cycle_4 | Performs cell-division and other cycle events. |
Mechanics | sort_cells_in_voxels_step_1 | Checks if cells need to be sent to different subdomain and sends them. |
ยงStep 5 - Include new Cells
Aspects | Function | Purpose |
---|---|---|
Mechanics | sort_cells_in_voxels_step_2 | Include newly received cells into correct subdomains. |
ยงReturn Type
After the simulation is done, we return a StorageAccess struct to interoperate with stored results.
Re-exportsยง
pub use crate::storage::StorageError;
Macrosยง
- Returns code which can be used to initialize a new empty AuxStorage.
- Allows for the creation of a general AuxStorage struct which functions via the defined Update traits in the chili backend.
- Automatically build communicator struct depending on simulation aspects.
- Inserts as many blanks as generics were used to create the communicator struct by build_communicator!.
- Prepare simulation types before executing the simulation via the run_main macro. Prepares communicator and auxiliary storage types with build_communicator! and build_aux_storage!.
- Runs a with user-defined concepts. Assumes that types have been prepared with prepare_types!.
- Performs a complete numerical simulation.
- Run a particularly structured test multiple times for combinations of aspects
- Checks if defined types and concepts are compatible before actually executing the simulation.
Structsยง
- Stores intermediate information about the cell cycle.
- Helper storage for number of neighbors of Interaction trait.
- Stores intermediate information about the mechanics of a cell.
- Helper storage for values regarding intracellular concentrations for the Reactions trait.
- Implementor of the UpdateReactionsContact trait.
- This very simple implementation uses the [hurdles::Barrier] struct which should in theory perform faster than the std::sync::Barrier struct from the standard library.
- Wrapper around the user-defined CellAgent
- Unique identifier which is given to every cell in the simulation
- Sender-Receiver Communicator based on [crossbeam_channel].
- Handles any error which is encountered and caught (i.e. no panics) during runtime.
- Return type to the requested PosInformation.
- Can occur internally when information is not present at expected place
- Send about the position of cells between threads.
- This information will be sent from one cell to another to determine their combined reactions.
- This informatino is returned after receiving ReactionsContactInformation and delivers the increment.
- Carries information about the border given by the ReactionsExtra trait between subdomains.
- Return information of border value after having obtained the SubDomainReactions::BorderInfo
- A ring Buffer with constant size. Makes use of a fixed-size array internally.
- Iterator of the RingBuffer struct.
- Produced by the iter method of the RingBuffer.
- Send cell and its AuxStorage between threads.
- Specify settings surrounding execution and storage
- Intermediate object which gets consumed once the simulation is run
- Struct containing all necessary information to construct a fully working simulation and run it.
- Gathers the StorageManager for cells and voxels of the previously run simulation
- Encapsulates a subdomain with cells and other simulation aspects.
- Identifier or subdomains
- Undirected graph
- Stores information related to a voxel of the physical simulation domain.
- Identifier for voxels used internally to get rid of user-defined ones.
Enumsยง
- Contains all events which can arise during the cell cycle and need to be communciated to the simulation engine (see also Cycle).
- Error during decomposition of a SimulationDomain into multiple subdomains
- Contains handling strategies for errors which can arise during the simulation process.
- Covers all errors that can occur in this Simulation The errors are listed from very likely to be a user error from almost certainly an internal error.
Traitsยง
- Construct a BTreeMap of the type from a graph
- Handles communications between different simulation processes.
- Used to construct initial (empty) AuxStorage variants.
- Handle any error which may occur as specified by SimulationError
- Constructs a collection of Items from a map (graph)
- Responsible for syncing the simulation between different threads.
- Trait which describes how to store intermediate information on the cell cycle.
- Interface to store intermediate information about interactions.
- Used to store intermediate information about last positions and velocities. Can store up to
N
values. - Interface to store intermediate information about cellular reactions.
- Used to update properties of the cell related to the ReactionsContact trait.
- Mathematical abstraction similar to the well-known
axpy
method.
Functionsยง
- Construct a new SimulationRunner from a given auxiliary storage and communicator object
- Advances the cycle of a cell by a small time increment
dt
. - Perform the Interaction::react_to_neighbors function and clear current neighbors.
- We assume that cells implement the Mechanics and Interaction traits. In this last step, all ForceInformation are gathered and used to update the cells positions and velocities.
- Calculates the increment from the Reactions trait.
- Ensures that intracellular increments have been cleared before the next update step.
- Performs the increment operation.
- Updates the cells intracellular values from the obtained contact informations
- Two-step Adams-Bashforth method.
- Three-step Adams-Bashforth method.
- Classical euler solver for the Mechanics trait.
- Calculates the increment introduced by the ReactionsContact aspect.
- Validates a given map.
Derive Macrosยง
- Derives the update traits UpdateCycle, UpdateMechanics, UpdateInteraction, UpdateReactions and UpdateReactionsContact
- Derives the Communicator trait.
- Derives the FromMap trait.