Inlet profile from data

Hello everyone,

I was wondering if it is possible to generate an inlet profile from data (e.g. from a previous simulation or real data)?

I had a chat with Johannes and he was so kind to provide a script that transfers data points into individual sections.
However, is there a possibility to get this section independent? As this might cause issues if e.g. the flow path is changed subsequently.

Thanks for your help.

1 Like

Hey Lukas,

to create an inlet profile from experimental data, you need to configure the piecewise cubic polynomials of the Inlet Unit Operation. For this purpose, you create a separate section for every ‘piece’.

To automate that, you can use some helper function. Assuming some arrays for time and data_points,

import numpy as np

time = np.arange(5)
data_points = np.array([
    [0.0, 0.0],
    [0.0, 0.1],
    [0.5, 0.2],
    [1.0, 0.1],
    [0.5, 0.0],
    [0.0, 0.0]
    ])

you can write a helper function that adds them to the cadet config object.

def linear_interpolation(cadet, time, data_points):
    n_sections = len(time) - 1
    
    cadet.root.input.model.unit_000.unit_type = 'INLET'
    cadet.root.input.model.unit_000.ncomp = data_points.shape[1]
    cadet.root.input.model.unit_000.inlet_type = 'PIECEWISE_CUBIC_POLY'
    
    section_times = [time[0]]
    for i in range(n_sections):
        section_index = 'sec_{0:03d}'.format(i)
        cadet.root.input.model.unit_000[section_index].const_coeff = data_points[i,:]
        
        slope = (data_points[i+1,:] - data_points[i,:])/(time[i+1] - time[i])
        cadet.root.input.model.unit_000[section_index].lin_coeff = slope
        
        section_times.append(time[i+1])

    cadet.root.input.solver.sections.section_times = section_times

Instead of manually calculating the coefficients, you can also replace this section and use something like the splines module from scipy.

Then you would call this function later when actually doing the configuration.

from cadet import Cadet
cadet = Cadet()

#
# All of the regular config stuff
#

linear_interpolation(cadet, time, data_points)

Unfortunately, this is currently not possible and there is already an open issue on Github describing exactly this problem. The current implementation is still an artefact from the time when CADET could just simulate single columns but it has become cumbersome now that networks of unit operations are possible and CADET is generally used for more dynamic processes, and scheduling. I do agree that it would be good to overhaul the way in which sections are defined in CADET and replace it with something ‘per unit’. Then internally, CADET would have to construct its own time line of events by iterating over all units.
Alternatively, you can also develop some preprocessor which does exactly that for you. For many things, CADET-Process already provides functionality for defining events independently, but unfortunately Inlets (and dynamic flow rates) are still missing.

Hello together,

I had a similar problem as I have to use certain functions such as gaussian distributions as input pulses. I modified Johannes solution for my application using splines as he proposed:

from scipy import interpolate

cadet.root.input.model.unit_000.unit_type = 'INLET'
cadet.root.input.model.unit_000.ncomp = 1
cadet.root.input.model.unit_000.inlet_type = 'PIECEWISE_CUBIC_POLY'

def spline_interpolation(cadet, time, y):

    cu = interpolate.CubicSpline(time, y)
    n_sections=len(time)-1

    cadet.root.input.solver.sections.nsec = n_sections
    cadet.root.input.solver.sections.section_times = [x for x in cu.x] 

    for i in range(n_sections):
        section_index = 'sec_{0:03d}'.format(i)
        cadet.root.input.model.unit_000[section_index].cube_coeff = cu.c[:,i][0]
        cadet.root.input.model.unit_000[section_index].quad_coeff = cu.c[:,i][1]
        cadet.root.input.model.unit_000[section_index].lin_coeff = cu.c[:,i][2]
        cadet.root.input.model.unit_000[section_index].const_coeff = cu.c[:,i][3]

time=np.linspace(0,400,1000)
sigma=6.5
x0=73
y=(1/sigma*np.sqrt(2*np.pi))*np.exp(-(time-x0)**2/(2*sigma)**2)

spline_interpolation(cadet, time, y)

Cheers,
Hannah

1 Like