# Ratio between concentrations in different materials

**URL:** <https://festim.discourse.group/t/ratio-between-concentrations-in-different-materials/86>\
**Category:** User Support\
**Created:** [November 26, 2024, 11:30am UTC](https://festim.discourse.group/t/ratio-between-concentrations-in-different-materials/86 "2024-11-26T11:30:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cruiseraurora](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@cruiseraurora](https://festim.discourse.group/u/cruiseraurora)\
**Post date:** [November 26, 2024, 11:30am UTC](https://festim.discourse.group/t/ratio-between-concentrations-in-different-materials/86/1 "2024-11-26T11:30:30Z")

</div>

Hello! Could you please tell me how the concentration jump between different materials is calculated in festim? I expected something like  
Ca = Sa/Sb \* Cb,  
where a, b - different materials, C - concentration at the material boundary, S - “a” and “b” solubility.  
Or another ratio is used? I specify only D\_0 and E\_D values for 2 different materials and festim still solves the problem (without S\_0 and E\_S).

---

<div class="post-metadata">

**Author:** ![VVKulagin](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/vvkulagin/32/51_2.png) [@VVKulagin](https://festim.discourse.group/u/VVKulagin)\
**Post date:** [November 26, 2024, 12:17pm UTC](https://festim.discourse.group/t/ratio-between-concentrations-in-different-materials/86/2 "2024-11-26T12:17:26Z")

</div>

Hi @cruiseraurora

> I specify only D\_0 and E\_D values for 2 different materials and festim still solves the problem (without S\_0 and E\_S).

Do you set `chemical_pot=True` in your model [settings](https://festim.readthedocs.io/en/latest/api/settings.html) to account for the chemical potential conservation at interfaces? When this flag is True, you will have to provide either Sieverts’ or Henry’s constant for each material.

> Could you please tell me how the concentration jump between different materials is calculated in festim?

Please, check the corresponding [theory section](https://festim.readthedocs.io/en/latest/theory.html#conservation-of-chemical-potential-at-interfaces) for additional information or [the paper](https://iopscience.iop.org/article/10.1088/1741-4326/abd95f) about the implementation by @remidm et al.

Please, let me know if it helps

---

<div class="post-metadata">

**Author:** ![cruiseraurora](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@cruiseraurora](https://festim.discourse.group/u/cruiseraurora)\
**Post date:** [November 26, 2024, 12:33pm UTC](https://festim.discourse.group/t/ratio-between-concentrations-in-different-materials/86/3 "2024-11-26T12:33:08Z")

</div>

> [@VVKulagin](#):
>
> chemical\_pot=True

I try to set  
chemical\_pot = True  
and I have the same result (and set S\_0 and E\_S for each material). But why does it work even without that flag?

---

<div class="post-metadata">

**Author:** ![VVKulagin](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/vvkulagin/32/51_2.png) [@VVKulagin](https://festim.discourse.group/u/VVKulagin)\
**Post date:** [November 26, 2024, 12:51pm UTC](https://festim.discourse.group/t/ratio-between-concentrations-in-different-materials/86/4 "2024-11-26T12:51:39Z")

</div>

Could you, please, provide your input script for further assistance?

Running FESTIM v1.3.1 without solubilities and with `chemical_pot=True` produces errors.

```auto
  File "/home/vvkulagin/anaconda3/envs/festim-env/lib/python3.11/site-packages/festim/materials/materials.py", line 325, in solubility_as_function
    F += mat.S_0 * f.exp(-mat.E_S / k_B / T) * vS * dx(mat.id)
                         ^^^^^^^^
TypeError: bad operand type for unary -: 'NoneType'

```

Consider this MWE:

```auto
import festim as F
import numpy as np

model = F.Simulation()

model.mesh = F.MeshFromVertices(vertices=np.linspace(0,1,num=100))

# Define material properties
mat1 = F.Material(
    id=1,
    D_0=1,
    E_D=1,
    #E_S=1,
    #S_0=1,
    borders=[0,0.5]
)
mat2 = F.Material(
    id=2,
    D_0=2,
    E_D=2,
    #E_S=2,
    #S_0=2,
    borders=[0.5,1.0]
)

model.materials = F.Materials([mat1, mat2])
model.T = 300

model.settings = F.Settings(
    absolute_tolerance=1e12,
    relative_tolerance=1e-8,
    transient=False,
    chemical_pot=True
)

model.initialise()
model.run()

```

You can uncomment solubilities to run the script without errors.

---

<div class="post-metadata">

**Author:** ![cruiseraurora](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@cruiseraurora](https://festim.discourse.group/u/cruiseraurora)\
**Post date:** [November 26, 2024, 12:59pm UTC](https://festim.discourse.group/t/ratio-between-concentrations-in-different-materials/86/5 "2024-11-26T12:59:47Z")

</div>

Sorry, I meant that I get the reliable calculation results (TDS spectrum) without solubilities and without a “chemical\_pot=True” in my code. In this case I don’t understand how festim calculates concentration jumps at the boundaries of materials without knowing their solubilities

---

<div class="post-metadata">

**Author:** ![remidm](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/remidm/32/4_2.png) [@remidm](https://festim.discourse.group/u/remidm)\
**Post date:** [November 26, 2024, 1:11pm UTC](https://festim.discourse.group/t/ratio-between-concentrations-in-different-materials/86/6 "2024-11-26T13:11:20Z")

</div>

If you don’t set `chemical_pot=True` then FESTIM will assume continuity of concentration at interfaces and the solubilities in `Material` will simply be ignored.

The reason why we have `chemical_pot` defaulting to False is because it is - slightly - less efficient and not needed for one-material simulations.

---

<div class="post-metadata">

**Author:** ![VVKulagin](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/vvkulagin/32/51_2.png) [@VVKulagin](https://festim.discourse.group/u/VVKulagin)\
**Post date:** [November 26, 2024, 1:18pm UTC](https://festim.discourse.group/t/ratio-between-concentrations-in-different-materials/86/7 "2024-11-26T13:18:13Z")

</div>

> [@remidm](#):
>
> If you don’t set `chemical_pot=True` then FESTIM will assume continuity of concentration at interfaces and the solubilities in `Material` will simply be ignored.

small remark  
@cruiseraurora if you observe “jumps” in the concentration field, I guess, it is just the result of solving the diffusion equation with different diffusivities in materials

---

<div class="post-metadata">

**Author:** ![cruiseraurora](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@cruiseraurora](https://festim.discourse.group/u/cruiseraurora)\
**Post date:** [November 26, 2024, 1:23pm UTC](https://festim.discourse.group/t/ratio-between-concentrations-in-different-materials/86/8 "2024-11-26T13:23:29Z")

</div>

I just wanted to understand how concentration calculations work in different materials in festim. Now it is clear to me, thank you both!
