Desorption modelling

Hello again,

I had previously sought out help to model desorption in CADET, 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:

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:

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 :slight_smile:

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:

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

1 Like

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 (158.3 KB)

btdsdata_EA.csv (482 Bytes)

Thanks again, and best,
Zubin

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

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

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

2 Likes

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'.

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

4 Likes

Dear Hannah,

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

Best,
Zubin

1 Like