I want to perform the inverse fit for a system consisting of two CSTRs and one column. The sequence of two CSTRs and one column is CSTR-column-CSTR. For the column I want to use lumped rate mode without pores as column model. The inverse fit is performed for three parameters: ka, kd, and column dispersion, in this case. Based on the “parest” folder given in the new CADET I created a MATLAB for performing the inverse fit. I am facing problem in how to incorporate the two CSTRs using “singleCSTR”.
Can I get an example for inverse fit for a system of CSTRs and column.
function singleExpSeparateComponents()
% Create simulation and obtain artificial data
sim = createSimulation();
res = sim.run();
% Set model parameters and enable sensitivities
params = cell(3, 1);
params{1} = makeSensitivity([0], {'MCL_KA'}, [1], [-1], [0], [-1]);
params{1} = makeSensitivity([0], {'MCL_KD'}, [2], [-1], [0], [-1]);
params{2} = makeSensitivity([0], {'COL_DISPERSION'}, [3], [-1], [0], [-1]);
sim.setParameters(params, true(3, 1));
% Create fit object
pf = ParameterFit();
% Collect data of first experiment in cell array (one cell per observed component / wavelength)
% Note that time points of the measurements are given in sim.solutionTimes
data = cell(1, 1);
data{1} = res.solution.outlet{1}(:, 2);
% Specify which components are observed in which factor for each observation / wavelength
idxComp = cell(1, 1);
idxComp{1} = [0 1]; % First observation is component 2 (or 1 if read as 0-based) with factor 1
%idxComp{2} = [0 1]; % Second observation is component 3 (or 2 if read as 0-based) with factor 1
%idxComp{3} = [0 0 0 1]; % Third observation is component 4 (or 3 if read as 0-based) with factor 1
% Add the experiment to the fit (unit operation 0 is observed, which is the GRM) including name
% of the experiment and the different observations / wavelengths
pf.addExperiment(data, sim, [0], idxComp, [], 'Frontal run', {'mAb'});
% Specify initial parameters and their lower and upper bounds
initParams = [5, 0.1, 5.75e-8];
loBound = 1e-1 * ones(1, 3);
upBound = 1e2 * ones(1, 3);
% This variable serves as storage for the plot handles returned by the plot function of ParameterFit
% in the OutputFcn below.
plotHd = [];
% Set some options (tolerances, enable Jacobian) and request some output (iteration statistics, plots)
opts = optimset('TolFun', 1e-8, 'TolX', 1e-8, 'MaxIter', 100, 'Jacobian', 'on', 'Diagnostics', 'off', 'Display', 'iter', 'OutputFcn', @progressMonitor);
% Invoke optimizer lsqnonlin
[optimalParams, optimalRes, ~, exitflag] = lsqnonlin(@residual, initParams, loBound, upBound, opts);
success = (exitflag > 0);
function [varargout] = residual(x)
%RESIDUAL Residual function that is passed to lsqnonlin, just forwards to ParameterFit object
varargout = cell(nargout,1);
[varargout{:}] = pf.residualVector(x);
end
function stop = progressMonitor(x, optimValues, state)
%PROGRESSMONITOR Callback function for progress report invoked by lsqnonlin, just calls ParameterFit's plot function
stop = false;
if strcmp(state, 'iter')
% Call plot function and reuse plot handles from previous call (storage outside this function in captured variable plotHd)
plotHd = pf.plot(plotHd, optimValues.iteration, [optimValues.resnorm, optimValues.stepsize]);
end
end
end
function sim = createSimulation()
% Lumped rate model without pores
model = SingleLRM();
model.nComponents = 2; %
model.nCellsColumn = 16; % Attention: This is very low and only used for illustration (short runtime)
model.nBoundStates = ones(model.nComponents, 1);
% Initial conditions
model.initialBulk = [ 176 0.0];
model.initialSolid = [1.2e3 0.0];
% Transport
model.dispersionColumn = 5.75e-8;
model.interstitialVelocity = 3e-3;
% Geometry
model.columnLength = 0.014;
model.porosity = 0.37;
% Adsorption
mLangmuir = LangmuirBinding();
mLangmuir.kineticBinding = true;
mLangmuir.kA = 2.44;
mLangmuir.kD = 0.03;
mLangmuir.qMax = 1.4;
model.bindingModel = mLangmuir;
% Inlet
%mIn = PiecewiseCubicPolyInlet();
model.constant = zeros(1, model.nComponents);
model.linear = zeros(1, model.nComponents);
model.quadratic = zeros(1, model.nComponents);
model.cubic = zeros(1, model.nComponents);
% Sec 1:Loading phase
model.constant(1,1) = 176.0;
model.constant(1,2) = 0.003013; % component 1
% Model system
% mSys = SingleCSTR();
% mSys.models = [model, mIn];
% mSys.connectionStartSection = [0];
% mSys.connections = {[1, 0, -1, -1, 1.0]};
% Configure simulator
sim = Simulator.create();
sim.sectionTimes = [0.0 3776];
sim.sectionContinuity = [];
sim.solutionTimes = linspace(0, 3776, 1000);
% Assign model
sim.model = model;
end