Question on using add_event to update k_film in CADET-Process

Hello Forum,

I observed some unexpected behavior when setting up a simple column model in CADET-Process while trying to use the add_event functionality to change the film diffusion coefficient (k_film) at some time point during the process. I am not sure if this is an issue or if I am just doing something wrong so I just figured I’d ask. An example to illustrate is below.

from CADETProcess.processModel import ComponentSystem
from CADETProcess.processModel import LumpedRateModelWithPores
from CADETProcess.processModel import Inlet, Outlet
from CADETProcess.processModel import FlowSheet
from CADETProcess.processModel import Process
from CADETProcess.simulator import Cadet

component_system = ComponentSystem(['1'])

feed = Inlet(component_system, name='feed')
feed.c = [24,]

column = LumpedRateModelWithPores(component_system, name='column')
column.length = 0.1
column.diameter = 0.016
column.particle_radius = 25e-6
column.bed_porosity = 0.4
column.particle_porosity = 0.93
column.axial_dispersion = 5e-8 # m^2/s

column.film_diffusion = [2.2e-5,]

outlet = Outlet(component_system, name='outlet')

flow_sheet = FlowSheet(component_system)


flow_sheet.add_connection(feed, column)
flow_sheet.add_connection(column, outlet)

flow_sheet.feed.flow_rate = 1e-7

process = Process(flow_sheet, 'fs')
process.cycle_time = 400

simulator = Cadet()

if __name__ == '__main__':
    simulation_results = simulator.simulate(process)
    _ = simulation_results.solution.outlet.inlet.plot()

However if I try to change k_film at some point in the process when there is only a single component as


I get this error message:

 File ~/opt/anaconda3/envs/CADET-env/lib/python3.9/site-packages/CADETProcess/dynamicEvents/ in add_event
    evt = Event(name, self, parameter_path, state, time=time, indices=indices)

  File ~/opt/anaconda3/envs/CADET-env/lib/python3.9/site-packages/CADETProcess/dynamicEvents/ in __init__
    self.indices = indices

  File ~/opt/anaconda3/envs/CADET-env/lib/python3.9/site-packages/CADETProcess/dynamicEvents/ in indices
    raise e

  File ~/opt/anaconda3/envs/CADET-env/lib/python3.9/site-packages/CADETProcess/dynamicEvents/ in indices
    _ = self.indices

  File ~/opt/anaconda3/envs/CADET-env/lib/python3.9/site-packages/CADETProcess/dynamicEvents/ in indices
    indices = generate_indices(self.parameter_shape, self._indices)

  File ~/opt/anaconda3/envs/CADET-env/lib/python3.9/site-packages/CADETProcess/dynamicEvents/ in generate_indices
    raise ValueError("Scalar parameters cannot have index slices.")

ValueError: Scalar parameters cannot have index slices.

where it looks like the error is just raised because the length of the list used to update k_film is 1. However should that not be the case when there is only one component in the system? When I run this example with two components it seems to work fine.

Thanks in advance for your help :slight_smile:

Hi Angela,

I believe this was fixed in d91adf9. Which version of CADET-Process are you running?

To check run the following in the command line

pip show cadet-process

or in Python:

import CADETProcess

Hi Johannes, thanks for the quick reply.
It says I am running 0.8.0, which I thought was the most current version…

I can reproduce the error with v0.8.0, but it works with the current master branch.

You can install that with

pip install git+

yeah, my bad. it was fixed in this commit.

We should also consider making another minor release.

Great, it worked. Thanks.

1 Like