public class Simulation extends Object implements UpdateEventEmitter<NodeUpdatedEvent>
AutomatonGraph, a set of Modules and a set of ChemicalEntitys.
Additionally AssignmentRules can be used to assign concentrations to chemical entities based on rules
(functions). The Class SimulationExamples provides a set of examples where Simulations are being set up.
Principally the following steps should be taken:
// initialize simulation
Simulation simulation = new Simulation();
// initialize a graph
AutomatonGraph graph = AutomatonGraphs.useStructureFrom(Graphs.buildGridGraph(10, 10, defaultBoundingBox));
// add to simulation
simulation.setGraph(graph);
// initialize chemical entities
ChemicalEntity fructosePhosphate = ChEBIParserService.parse("CHEBI:18105");
// initialize their concentrations in the graph
graph.initializeSpeciesWithConcentration(fructosePhosphate, 0.1);
// add to simulation
simulation.getChemicalEntities().add(fructosePhosphate);
// set environmental simulation parameters (e.g. system diameter, temperature, viscosity)
EnvironmentalParameters.getInstance().setNodeSpacingToDiameter(Quantities.getQuantity(2500.0, NANO(METRE)), 10);
// add diffusion module (free diffusion will be simulated)
simulation.getModules().add(new FreeDiffusion(simulation));
Afterwards the simulation can be performed stepwise by calling the nextEpoch() method. For each
epoch the size of the time step will be adjusted with the TimeStepHarmonizer, to ensure numerical stability
up to a given epsilon. The method (TimeStepHarmonizer.setEpsilon(double)) sets the epsilon and the error
between two time steps will be kept below that threshold. Epsilons approaching 0 naturally result in very small time
steps and therefore long simulation times, at default epsilon is at 0.01. The time step will be optimized for each
epoch, resulting in many epochs for critical simulation regimes and large ones for stable regimes. Changes in
simulations can be observed by tagging AutomatonNodes of the AutomatonGraph. By setting AutomatonNode.setObserved(boolean) to true the simulation emits NodeUpdatedEvent for every observed node
and every time step to every registered UpdateEventListener (to register a listener use UpdateEventEmitter.addEventListener(UpdateEventListener) method). As a standard implementation there is the EpochUpdateWriter that can be added to the Simulation that will write log files to the specified file locations.
| Constructor and Description |
|---|
Simulation()
Creates a new plain simulation.
|
| Modifier and Type | Method and Description |
|---|---|
void |
applyAssignmentRules()
Apply all referenced assignment rules.
|
void |
emitNextEpochEvent(AutomatonNode node)
Emits the
NodeUpdatedEvent to all listeners. |
List<AssignmentRule> |
getAssignmentRules()
Returns the assignment rules.
|
Set<ChemicalEntity<?>> |
getChemicalEntities()
Returns the chemical entities.
|
javax.measure.Quantity<javax.measure.quantity.Time> |
getElapsedTime()
Returns the elapsed time after the deltas of the current epoch are applied.
|
long |
getEpoch()
Returns the current epoch number.
|
AutomatonGraph |
getGraph()
Returns the simulation graph.
|
CopyOnWriteArrayList<UpdateEventListener<NodeUpdatedEvent>> |
getListeners() |
Set<Module> |
getModules()
Returns the modules.
|
void |
nextEpoch()
Calculates the next epoch.
|
void |
setAssignmentRules(List<AssignmentRule> assignmentRules)
Adds a list of assignment rules, sorting them by their dependencies.
|
void |
setChemicalEntities(Set<ChemicalEntity<?>> chemicalEntities)
Sets all chemical entities at once.
|
void |
setGraph(AutomatonGraph graph)
Sets the simulation graph and adds all entities referenced in the graph to the chemical entities of the
simulation.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddEventListener, emitEvent, removeEventListenerpublic void nextEpoch()
public void applyAssignmentRules()
public AutomatonGraph getGraph()
public void setGraph(AutomatonGraph graph)
graph - The simulation graph.public List<AssignmentRule> getAssignmentRules()
public void setAssignmentRules(List<AssignmentRule> assignmentRules)
assignmentRules - The assignment rules.AssignmentRules.sortAssignmentRulesByPriority(List)public Set<ChemicalEntity<?>> getChemicalEntities()
public void setChemicalEntities(Set<ChemicalEntity<?>> chemicalEntities)
chemicalEntities - The chemical entities.public long getEpoch()
public javax.measure.Quantity<javax.measure.quantity.Time> getElapsedTime()
public void emitNextEpochEvent(AutomatonNode node)
NodeUpdatedEvent to all listeners.node - The observed node.public CopyOnWriteArrayList<UpdateEventListener<NodeUpdatedEvent>> getListeners()
getListeners in interface UpdateEventEmitter<NodeUpdatedEvent>Copyright © 2017. All rights reserved.