# Desorption modelling

**URL:** <https://forum.cadet-web.de/t/desorption-modelling/1185>\
**Category:** CADET Troubleshooting\
**Created:** [March 19, 2025, 11:56am UTC](https://forum.cadet-web.de/t/desorption-modelling/1185 "2025-03-19T11:56:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zubinkm](https://forum.cadet-web.de/letter_avatar_proxy/v4/letter/z/34f0e0/32.png) [@zubinkm](https://forum.cadet-web.de/u/zubinkm)\
**Post date:** [March 19, 2025, 11:56am UTC](https://forum.cadet-web.de/t/desorption-modelling/1185/1 "2025-03-19T11:56:44Z")

</div>

Hello again,

I had previously sought out help to [model desorption in CADET](https://forum.cadet-web.de/t/desorption-modelling-in-cadet/1160/6), and I am presently using MPM for simulating my adsorption-desorption cycle

I have some issues I was hoping that the CADET team can help me with.

Firstly, from experiments, I know that I have an overshoot of the adsorbate concentration once I switch from adsorption to desorption. I got this overshoot in the simulation by adjusting the beta value. I was also hoping to add this ‘change’ by using events, and specifying a new, and lower adsorption rate and capacity, in the presence of highly concentrated ethanol. But unfortunately, I got an error that said these are not valid event parameters. Is there any other way to do this?

Secondly, when I am trying to fit my experimental data to the simulation, I get this error while using the comparator : **Unknown components**

The code is given below:

```auto
from CADETProcess.comparison import Comparator
comparator = Comparator()
comparator.add_reference(reference)
comparator.add_difference_metric('SSE', reference, 'outlet.outlet')
comparator = Comparator()
comparator.add_reference(reference)
comparator.add_difference_metric(
'SSE', reference, 'outlet.outlet', start=60*60, end=2850*60, components=["EA"]
)
_ = comparator.plot_comparison(simulation_results)

```

Without the argument of ‘components’, I get an error that shapes do not match, which I assume is because CADET stored all the results as a 2D array.

Components are defined as follows, in my simulation:

```auto
component_system = ComponentSystem()
component_system.add_component('Ethanol')
component_system.add_component('EA')

```

Is there another way to do this?  
Any help is highly appreciated. Thank you 🙂

---

<div class="post-metadata">

**Author:** ![h.lanzrath](https://forum.cadet-web.de/user_avatar/forum.cadet-web.de/h.lanzrath/32/1186_2.png) [@h.lanzrath](https://forum.cadet-web.de/u/h.lanzrath)\
**Post date:** [March 20, 2025, 2:16pm UTC](https://forum.cadet-web.de/t/desorption-modelling/1185/2 "2025-03-20T14:16:45Z")

</div>

Hi zubinkm,

Thanks for your post!

In the future for issues with implementing CADET please use the _CADET Troubleshooting_ Category, which provides a detailed explanation on how to provide a **minimum reproducible example (MRE)** and export your environment.

I noticed in the code snippet you posted that you define a `Comparator` object twice, effectively overwriting the first instance with the second one. Was this intentional? If not, I would expect something more like this:

```auto
from CADETProcess.comparison import Comparator

comparator1 = Comparator()
comparator1.add_reference(reference)
comparator1.add_difference_metric('SSE', reference, 'outlet.outlet')

comparator2 = Comparator()
comparator2.add_reference(reference)
comparator2.add_difference_metric(
    'SSE', reference, 'outlet.outlet', start=60*60, end=2850*60, components=["EA"]
)

_ = comparator1.plot_comparison(simulation_results)

```

Your usage of the `components` keyword argument in `add_difference_metric` looks correct. However, to better assist you it would be great if you could provide a full working MRE instead of a code snippet. This would help us verify whether the components are correctly defined and registered in the process before being added to the `Comparator`, as this is not clear from the snippet alone.

Looking forward to your response!

Best,  
Hannah

---

<div class="post-metadata">

**Author:** ![zubinkm](https://forum.cadet-web.de/letter_avatar_proxy/v4/letter/z/34f0e0/32.png) [@zubinkm](https://forum.cadet-web.de/u/zubinkm)\
**Post date:** [March 20, 2025, 3:22pm UTC](https://forum.cadet-web.de/t/desorption-modelling/1185/3 "2025-03-20T15:22:55Z")

</div>

Hi Hannah,

Thanks for helping and apologies for not posting in the right category.

I have attached both the code and the .csv with experimental data here

[destrial\_new.ipynb](https://forum.cadet-web.de/uploads/short-url/Awe6nbrU6Wbu948G4Jnw7nWmypi.ipynb) (158.3 KB)

[btdsdata\_EA.csv](https://forum.cadet-web.de/uploads/short-url/937oPze9Bfqr4tXSCyRWTeTlbEc.csv) (482 Bytes)

Thanks again, and best,  
Zubin

---

<div class="post-metadata">

**Author:** ![h.lanzrath](https://forum.cadet-web.de/user_avatar/forum.cadet-web.de/h.lanzrath/32/1186_2.png) [@h.lanzrath](https://forum.cadet-web.de/u/h.lanzrath)\
**Post date:** [March 20, 2025, 4:50pm UTC](https://forum.cadet-web.de/t/desorption-modelling/1185/4 "2025-03-20T16:50:25Z")

</div>

Hey zubinkm,

No worries at all, and thanks for sharing the MRE!

The underlying issue here is that `ReferenceIO` needs to have the same shape as `SolutionIO`, meaning `(n_time, n_comp)`. When you remove the  
keyword argument `components` from `add_difference_metric()` you get the mismatch in shape error since it tries to compare against the `SolutionIO`.

To fix this, you pass your component system to `ReferenceIO`. You’ll see that it complains about a shape mismatch again then, since you only provided a reference for one component. If you’re not interested in comparing Ethanol, a simple workaround is just adding an array of zeros as a placeholder for that component. That way, the difference metric will work as expected.

For example

```auto
from CADETProcess.reference import ReferenceIO
import numpy as np

# Create a reference with zeros for Ethanol and reference values for EA
reference_data = np.column_stack((np.zeros_like(EA_conc), EA_conc))
reference = ReferenceIO(
    'EA btds', time * 60, reference_data, component_system=component_system
)
_ = reference.plot()

```

You can then use the `Comparator` as you were

```auto
from CADETProcess.comparison import Comparator

comparator = Comparator()
comparator.add_reference(reference)

# Specify the difference metric only for the EA component
comparator.add_difference_metric(
    'SSE', reference, 'outlet.outlet', start=40*60, end=2100*60, components=['EA']
)
_ = comparator.plot_comparison(simulation_results)

```

to specify the specific metric and component you are interested in, in your case `'EA`.

Best,  
Hannah

---

<div class="post-metadata">

**Author:** ![h.lanzrath](https://forum.cadet-web.de/user_avatar/forum.cadet-web.de/h.lanzrath/32/1186_2.png) [@h.lanzrath](https://forum.cadet-web.de/u/h.lanzrath)\
**Post date:** [March 24, 2025, 10:22am UTC](https://forum.cadet-web.de/t/desorption-modelling/1185/5 "2025-03-24T10:22:38Z")

</div>

Hello zubinkm,

After checking back with @j.schmoelder (thanks!) I learned that there is a bit more elegant solution, which is creating a separate `ComponentSystem()` Object containing just the component you are interested in and then give that as a key word argument to the `ReferenceIO`.

I think this aligns better with your original approach.

So here we create a `reference_component_system ` with your component of interest `'EA'`.

```auto
from CADETProcess.reference import ReferenceIO

reference_component_system = ComponentSystem(['EA'])

reference = ReferenceIO('EA btds', time*60, EA_conc, component_system=reference_component_system)
_ = reference.plot()

```

And then the Comparator works as you were already using it.

Best,  
Hannah

---

<div class="post-metadata">

**Author:** ![zubinkm](https://forum.cadet-web.de/letter_avatar_proxy/v4/letter/z/34f0e0/32.png) [@zubinkm](https://forum.cadet-web.de/u/zubinkm)\
**Post date:** [March 24, 2025, 11:41am UTC](https://forum.cadet-web.de/t/desorption-modelling/1185/6 "2025-03-24T11:41:14Z")

</div>

Dear Hannah,

Thank you! That fixed my issue.  
Thanks to you too Jo @j.schmoelder

Best,  
Zubin

---

<div class="post-metadata">

**Author:** ![system](https://forum.cadet-web.de/uploads/default/original/2X/4/4ec43a357aeb35dcb4e6620649f54e8e6591b258.png) [@system](https://forum.cadet-web.de/u/system)\
**Post date:** [January 27, 2026, 11:43am UTC](https://forum.cadet-web.de/t/desorption-modelling/1185/7 "2026-01-27T11:43:06Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
