Using External Function Feature

I’ve tried to specify the external functions for a test model using multi-component Langmuir, just so I can understand how to set up the dependent model parameters in CADET python (ver 3.1.2). When I tried to run the simulation, I received a warning:

“returncode=0, stdout=b’[Warning: setExternalFunctions::212] Index -1 exceeds number of passed external functions (0), external dependence is ignored\r\n[Warning: setExternalFunctions::212] Index -1 exceeds number of passed external functions (0), external dependence is ignored\r\n”

The simulation seemed to have worked, however the output shows that the simulation did not take into account the dependence on the external function. I’m not exactly sure if I have it set up correctly; please see attached for the .h5 file. I appreciate any advice and help!

ext_test.h5 (79.4 KB)

You need to assign the external function to the binding model:
Add the integer dataset EXTFUN with value 0 to the group /input/model/unit_001/adsorption. This tells the binding model that source_000 is assigned to all its parameters.
In Python, this corresponds to

myCadetModel.root.input.model.unit_001.adsorption.extfun = 0

You will still receive some warnings like

Index 0 exceeds number of passed external functions (0), external dependence is ignored

but these can be safely ignored.

Note that you’ll see the same chromatogram, though. Since you’re using a FILM_DIFFUSION of 0.0, the molecules cannot enter the particles. Hence, no binding occurs and you cannot see the effect of the external function.

2 Likes

Thank you! The adsorption parameters seemed to be linked to source_000 now.

This is tangentially related, but is there a way to plot source_XXX (or any model parameters that belong to the input group) vs. time in CADET? I’m a new user and am learning to navigate in Python.

There’s nothing built-in, as far as I know.

For the external functions, you can adapt this script:

import numpy as np
import scipy.interpolate as scip
import matplotlib.pyplot as plt

section_times = [0.0, 2.0, 5.0, 10.0]
const_coeff = [0.0, 1.0, 2.0]
lin_coeff = [0.5, -0.1, 0.2]
quad_coeff = [0.0, 0.0, 0.0]
cube_coeff = [0.0, 0.0, 0.0]
velocity = 0.1 
col_length = 0.12

# Evaluation point in column (axial coordinate between 0 and col_length)
z = 0.1

# Convert to piecewise polynomial in scipy format
c = np.array([cube_coeff, quad_coeff, lin_coeff, const_coeff])
p = scip.PPoly(c, section_times)

# Evaluate at point z
t = np.linspace(min(section_times), max(section_times), 1001)
extFun = p((1.0 - z / col_length) / velocity + t)

plt.plot(t, extFun)
plt.xlabel('Time [s]')
plt.ylabel('External Function at z = {}'.format(z))
plt.grid(True)
plt.show()
1 Like