cellular_raza_concepts/reactions_old.rs
1use crate::CalcError;
2
3/// Defines how the cell uses the extracellular gradient.
4///
5/// This trait can also be derived with the [CellAgent](crate::CellAgent) derive macro.
6/// ```
7/// use cellular_raza_concepts::{reactions_old::InteractionExtracellularGradient,
8/// CalcError, CellAgent
9/// };
10///
11/// struct DoNothingGradient;
12///
13/// impl<C, G> InteractionExtracellularGradient<C, G> for DoNothingGradient {
14/// fn sense_gradient(
15/// cell: &mut C,
16/// gradient: &G,
17/// ) -> Result<(), CalcError> {
18/// Ok(())
19/// }
20/// }
21///
22/// #[derive(CellAgent)]
23/// struct MyAgent {
24/// #[ExtracellularGradient]
25/// gradient: DoNothingGradient,
26/// }
27/// ```
28pub trait InteractionExtracellularGradient<Cell, ConcGradientExtracellular> {
29 /// The cell-agent senses the gradient and changes the behaviour of the cell.
30 fn sense_gradient(
31 cell: &mut Cell,
32 gradient: &ConcGradientExtracellular,
33 ) -> Result<(), CalcError>;
34}
35
36/// Specify how cellular reactions are taking place.
37///
38/// This trait can also be derived with the [CellAgent](crate::CellAgent) derive macro.
39/// ```
40/// use cellular_raza_concepts::{reactions_old::CellularReactions, CellAgent, CalcError};
41/// struct MyReactions {
42/// intracellular: f64,
43/// half_time: f64,
44/// }
45///
46/// impl CellularReactions<f64> for MyReactions {
47/// fn get_intracellular(&self) -> f64 {
48/// self.intracellular
49/// }
50///
51/// fn set_intracellular(&mut self, intracellular: f64) {
52/// self.intracellular = intracellular;
53/// }
54///
55/// fn calculate_intra_and_extracellular_reaction_increment(
56/// &self,
57/// internal_concentration_vector: &f64,
58/// external_concentration_vector: &f64,
59/// ) -> Result<(f64, f64), CalcError> {
60/// Ok((-self.half_time * self.intracellular, self.half_time * self.intracellular))
61/// }
62/// }
63// #[derive(CellAgent)]
64// struct MyAgent {
65// #[Reactions]
66// reactions: MyReactions,
67// }
68/// ```
69pub trait CellularReactions<ConcVecIntracellular, ConcVecExtracellular = ConcVecIntracellular> {
70 /// Retrieves the current intracellular concentration.
71 fn get_intracellular(&self) -> ConcVecIntracellular;
72
73 /// Sets the intracellular concentration. This is used by the backend after values have been updated.
74 fn set_intracellular(&mut self, concentration_vector: ConcVecIntracellular);
75
76 /// Calculate the time-related change of the intracellular and extracellular concentrations.
77 /// This is not the increment itself (thus no parameter `dt` was specified) but rather the time-derivative.
78 /// Such an approach can be useful when designing addaptive solvers.
79 fn calculate_intra_and_extracellular_reaction_increment(
80 &self,
81 internal_concentration_vector: &ConcVecIntracellular,
82 external_concentration_vector: &ConcVecExtracellular,
83 ) -> Result<(ConcVecIntracellular, ConcVecExtracellular), CalcError>;
84}
85
86/// Obtain the current volume of the cell
87///
88/// This trait is used when updating extracellular reactions and processes.
89/// For more details see [domain](crate::Domain).
90pub trait Volume<F = f64> {
91 /// Obtain the cells current volume.
92 fn get_volume(&self) -> F;
93}