# Refactor compound density logic

Hello everyone,

While working on my global compound diffusion model, I realised that the gaseous compounds in the patches (nitrogen/dioxygen/carbon dioxyde) were encoded as proportions relative to one another, e.g. 70% N, 21% O_2, 9% CO_2, summing to 100%. This approach is very close to the one used in describing atmospheric composition (and you may note the proportions are roughly similar to Earth’s).

Note

I realized while writing this that people also mentionned it on the community forum, so I link it here for reference : Quick Question Thread - #1323 by hhyyrylainen - Current Game - Thrive Community Forum

Also, I use the term gas for dissolved compounds, although under specific temperature/pressure conditions they may not be in a gaseous state.

## The problem

However this falls short for our use cases: we are not describing atmospheric patches (mostly made of gas) but aquatic patches (mostly made of pure water, H_2O molecules). As such, while relative proportions work for atmosphere (because it is, in the end, a proportion relative to the total volume, sum of each gas’ volume), it does not for water (the total volume is, first and foremost, dependent on water volume).

In other words, 70% N might as well represent, at a given volume of water, 7 molecule of N per liter (if you have 10 gas molecules), or 7 billion (if you have 10 billions). As such, this proportion is not, of itself, sufficient to determine the influence of gases in the patch (this influence relies on the concentration of gases, i.e. how many molecules are in the immediate vicinity of a cell).

For this approach to work, we need another factor: the total amount of gas molecules. And the very reason why relative proportions have been working so long, is precisely because we assume a constant and similar total concentration of gases in every patch, a not very precise hypothesis: chemosynthesis, as an example, consumes both CO_2 and O_2 but does not produce N, effectively diminishing the total amount, and thus concentration.

18H_2S+6CO_2+3O_2 \rightarrow C_6H_{12}O_6+12H_2O+18S (chemosynthesis)

## How to fix this?

The obvious solution is to replace this proportion with the actual gas concentration. Note that absolute amount could be then obtained by multiplying the concentration by the volume of the patch. Given that there is no reason to assume similar volumes for patches (the estuary is probably smaller than the ocean), I therefore propose the following solution:

1. Introduce a measure of dissolved compounds related to their concentration (quantity/liter)
2. Introduce volume as a property of the patches

The reason why I propose a measure related to, and not equal to the concentration, is based on a remark from Buckly: 70% N means a 70% efficiency factor for N-based. As such, it is very convenient, both for display and settings, to have a percentage value, which we may call efficiency.

As such, we could still keep the current values system by decoupling the proportion values for dissolved compounds (which I think is not enforced in the code anyways?). This would mean that you could have 70% N, 70% O_2, 70% CO_2, as all three would be (initially) independent.

But the question is: what quantity of, say, N atoms would actually be 100% N efficiency? There is also probably no reason not to have efficiency going over 100% (because you may have more quantity than the organelle can process). So, we either have to add a cap or just say that base efficiency is not an upper limit, but just a necessary reference value.

## Fixed efficiency limit?

An answer could be, in accordance with our theorists, that we have a constant concentration x_N, so that a concentration \alpha x_N directly and linearly translates into efficiency \alpha (potentially over 100%). Depending on whether or not we want a hard cap on organelle efficiency, we could then, when running process computations, cap this to 100% if needed. This would still allow for an easier definition (linearity) and visibility (showing excess of a compound) to the player.

# Summary

To sum this up, I raised the issue of compound density not clearly reflecting an actual physico-chemical reality, hindering integration of parameters in populations. I proposed an alternative concentration-based measure, which we may call theoretical efficiency, reflecting a proportion (potentially greater) of a base concentration. This change, along with the addition of volumes to patches, would allow us to give our current parameters a clear relationship with real physical values, and therefore simplify integration of several simulation computations. Nonetheless, the use of an efficiency measure would still allow for a simple understanding of input and display values about concentration.

A few questions remain open:

1. Should process efficiency be capped? This answer would perhaps be the most important one given that it will influence following answers.
2. What base concentration should we choose? If we choose a cap concentration, after which process efficiency does not increase anymore, then what about several processes using the same compound with different cap concentration?
3. How to display efficiency to the player? Should we show the capped version (loosing information on whether this value may decrease easily or not)? If we don’t, how to tell the player that process efficiency will be capped?
4. How to integrate this dissolved compound logic with cloud compounds and sunlight? If this is possible, of course, especially for sunlight which is very particular a “compound” (and is actually labeled dissolved, but not distributed).
3 Likes

You bring up an interesting point that the game assumes the dissolved compounds to be uniform. I think for process efficiency in cells, that is entirely the right thing to do. As when the player swims around they are playing in real time. Because of that I doubt that the microbes can actually affect the concentration of compounds in a patch that much.
Of course I agree that we probably need to have a different model for auto-evo calculations and how the amount of available compounds change. From those we can then derive the concentrations for the player swimming around phase, I imagine. I like the idea of using a patch’s volume to determine the available compound amounts for auto-evo simulation, then the new amount can be reversed back to a concentration.
Another approach would be to flip this entirely: start from the total amount of a compound in a patch, and work out the concentration from that.
Unless some theorist jumps in, I think we should keep the process efficiency using the concentration values (percentage values, though maybe that also needs rethinking for the aquatic patches) as I think in the real world there are reactions that have their speed depend on the concentration of a catalyst / reactant.

So theres 2 things to take into account when calculating the density of gases in water
Temperature

Pressure.

But i think you already know this.
I think density(grams) is a much better and simpler measure than number of molecules / liter imho.
Sooooooo, we can start with the current concetration of atmospheric gases in sea water.
Im too layse right now to calculate using henry’s law or whatever, but according to the graphs,
This

This

And this

We can get the average densities of atmospheric gases of seawater at 20C at the surface as a reference.
O2 ~ 8 mg/L
N2 ~ 16mg/L
CO2 ~ 0.3mg/L
Ar ~ 0.34mg/L
etc.
So we can use this as reference.
We could also update the current patches concentration of gases according to the second pic i posted.
EDIT:
I think that making microbes influence the gases in the atmosphere could make for some very interesting scenarios.

Actually, it isn’t. As hh put it, the speed of a reaction is dependent on the concentration (mol/L) of its reactants and products:

You may have an overlook of chemical kinetics on wikipedia, but essentially the reaction speed v is determined as:

v = \frac{dc}{dt} = k(T) \times {\Pi_{i} c_i^{m_i}};

c_i being the concentration of the molecule i (reactant or product) and m_i its so-called partial order. Partial orders are generally (as far as I can tell) positive for reactants (more reactant means more encounters of molecules, thus faster reaction) and negative for products (you saturate more, so slower reaction/opposite reaction happening). k(T) is a speed constant specific to the reaction. It has many factor, including pressure in gas phase (so not here), but the main one is usually considered to be temperature.

As we can see here, there is no need to consider density for reaction speed; and this is especially because the molecule does not care about the mass of molecules it receives, but about the quantity of molecules it has to run its reactions (basically, how many there are in their vicinity).Of course, we could use molar mass to convert between both, but I believe there is no point in using such an indirect measure.

However, it must indeed be pointed at that temperature should probably play a greater role at some point, given it’s general impact on reaction speed. But I believe this isn’t a necessary refinement for our models to currently yield realistic enough outputs.

Also, we have an oversimplification for partial orders: we assume that partial orders are 1 for reactants and 0 for products, which is far from being true in general. But I don’t know about the reactions considered in the game, and how much a gross simplification it is.

Now, more specifically on hh’s answer

I think it is as well, at least for the moment. This is a first approximation that probably isn’t widely inaccurate, especially as patches are defined as homogeneous environments.

Nonetheless, we might have non-contextual differences (that could occur within patches) due to specific distribution laws. In cells, you may observe nanoclusters of proteins that are argued to be due to anomalous diffusion, and such non-linear diffusion has been observed in atmosphere, especially impacting climate.

I’m not very knowledgeable on the topic, but we might want to reconsider these refinements later, especially when dealing with atmosphere, if our models do not produce what is expected.

I fully agree on that, and I think it would bring unnecessary complications to our models anyways. So I’m in favor of considering it constant & constantly distributed (if we decide to revise uniformity, which is probably unnecessary as of now, if ever) during gameplay phases.

Both approaches are indeed theoretically equivalent, but in terms of input from Biomes.json files, we probably want to use concentration as it is more directly related to the process. This means that the developper changing the values won’t have to care about another variable, that is the volume of the patch. Otherwise, both would affect the output while it could be summed up into a single one.

Just to be really formal, percentage aren’t concentration (because % are dimensionless proportions, while concentrations are matter per volume unit.), even though you can convert with other parameters. That’s especially what I propose, using proportion \alpha to derive concentration c = \alpha c_0 for the simulation, with c_0 defined in Constants.cs.

The current approach, based on atmospheric composition, derives concentration as c = (\beta \times n_{total})/V, with n_{total} being the total amount of matter in the patch (excluding water for aquatic patches). As such n_C = \beta\times n_{total}) is the quantity of matter for compound C. But as you see it from the formula this approach needs the player to consider other variables than \beta, when looking for a patch were concentration is advantageous. The GUI would thus be less intuitive with this approach.

This is one of the reason why I push for a change of logic (along with the fact that n_{total} would require some more input to be computed for simulation).

1 Like

Whyyyyyy

20% of the earths O2

I think we should at least in teh future.

We are talking about uniformly distributed within a patch. Patches are meant to be uniform conditions that species encounter. If the conditions are different then, the patch should actually be two patches.

We used to have even the gaseous compounds being compound clouds (so you would need to find oxygen clouds, and your cell would emit small CO2 clouds), but it was removed in order to improve the gameplay by having fewer resources the player needs to find by swimming around.

1 Like

Density and reaction speed will scale linearily. I think it can be still used.
Ci = mass/molar mass/V = mass/V/molMass = density / molar mass
So theres the density in the equation

We can still use density.

Yes we can use density, but that’s unnecessarily complicated, as you basically convert it into concentration.

And I think this was indeed the right thing to do. I wanted to point out our simplifications that could potentially be questioned, e.g. if our models ended up with unrealistic behaviors.

1 Like

So Why not show players that thing? OR ppm, since its more intuitive than moles/L for those not having a sciency background.The conversion isnt that complicated, we could make a method to easily do that. We can use the mole/V for our internal calculation if we so wish.

Have you read my first two messages? I specifically propose not to use concentration as a display/input measure, but rather an efficiency percentage. This would be far more intuitive than ppm or volumic mass in terms of values.

I thought you wanted to propose something like this, efficiency i think could be shown alongside the volumic mass, at least to me, it would give me a nicer picture in my head of what is going on.