-
Notifications
You must be signed in to change notification settings - Fork 4
Simulator
###Simulator description
Cf. also http://herocoli.com/Doc/md__reaction_engine.html.
Hero.Coli's mechanics are not simply based on abilities linked to devices, but more deeply on a chemical simulator.
The chemical simulator is iterative: it computes step-by-step the concentration of chemicals, taking into account a list of reactions and a list of mediums.
The main C# class is ReactionEngine. It is instantiated on the Unity object ReactionEngine.
Its most important attributes are:
- a list of molecules
- a list of reactions
- a list of mediums
These lists are initialized by loading xml files located in Assets/Ressources/Parameters/ReactionEngine. The location of those files is determined in the Inspector panel of the ReactionEngine object in the Unity editor. The loading process can be seen in the Awake() method of the ReactionEngine.
The general update algorithm can be seen in the Update() method is as follows:
For each medium in the list of mediums, browse the list of chemical reactions of this medium.
For each reaction, check if there is enough available energy in the medium to activate the reaction. If there is, compute the amount of reactants consumed (in terms of concentrations) and update:
- the concentrations of reactants,
- the concentrations of products,
- the energy of the medium.
The browsing of reactions is randomized to prevent from artificially favoring a reaction over another reaction.
Each chemical is defined through an instance of the Molecule class, which contains the following main attributes:
- name,
- degradation rate,
- concentration,
- a negligibility threshold (below which this molecule can be considered as not present anymore),
- Fick factor (used in reactions that follow Fick's law of diffusion, cf. http://herocoli.com/Doc/class_fick.html).
The fields _concentration and _newConcentration are used in different cases: _concentration holds the current concentration while _newConcentration is an accumulator that enables the update of the concentration only once at the end of the update loop. This is work in progress, the "sequential mode" isn't functional yet.
Miscellaneous:
- how to add a new reaction: herocoli.com/Doc/md_add_reaction.html