Unable to run CADET simulation in MATLAB

Expected behavior.

I recently installed CADET v3 using the installCADET.m script, and I’m now trying to run a simulation using the system command in MATLAB. However, the simulation keeps failing to execute. One possibility is that the installation may not have completed correctly. I’m quite new to this, so I’d really appreciate any guidance or suggestions on how to troubleshoot the issue. Thanks!

Actual behavior

Error using CadetSimulation/simulate (line 81)
Simulation failed!

Error in forwardSim1>cadetSolve (line 337)
sim.simulate();

Error in forwardSim1 (line 65)
[cadetOutlet] = cadetSolve(tOut, cadetInlet,
cadetParams, fixedParams);

How to produce bug (including a minimal reproducible example)

This is the CadetSimulation object code:

classdef CadetSimulation < handle
%UNTITLED5 Summary of this class goes here
% Detailed explanation goes here

properties
    % Cadet input and output
    ci = CadetInput;
    co = CadetOutput;
    
    % Path variables guessed by CMake, override if necessary.
    % Directory of cadet-cs binary
    %  binpath = 'C:/Users/Vijesh.HP-PC/Documents/MATLAB/cadet-win-x64a/bin';
    binpath = '../bin';
    % Directory of generated input / output files (has to be writable). This will usually point to /tmp (Linux).
    iopath  = fileparts(tempname());
    % Directories of the SUNDIALS, HDF5 and CADET libs (separated by a colon ':')
    % libpath = 'C:/Users/Vijesh.HP-PC/Documents/MATLAB/cadet-win-x64a/lib';
    libpath = '../lib';
    % Misc options
    omp_num_threads = 1;
    show_result = false;
    
    % Suffix of the HDF5 file this class works on
    workfile_name = '_cadet.h5';
    
    % Name of the cadet-cs binary
    cadet_cs_name = 'cadet-cs';
    
end

methods
    
    function obj = CadetSimulation(loadCase)
        % Setup working file
        [~, fileName] = fileparts(tempname());
        obj.workfile_name = [fileName obj.workfile_name];
        
        % Load preset configuration
        if nargin > 0 
            obj.ci = CadetInput(loadCase);
        end
    end
    
    function simulate(obj)
        % Create fullfile strings for binaries and io-files
        cadet_cs  = fullfile(obj.binpath, obj.cadet_cs_name);
        workfile   = fullfile(obj.iopath,  obj.workfile_name);
        
        % Create the HDF5 file
        obj.ci.writeToH5(workfile);
        
        % Set linker path for hdf5 and cadet library on unix
        if ispc
            % Prepend libpath only if not present already
            curEnv = getenv('PATH');
            if (length(curEnv) < length(obj.libpath)) || any(curEnv(1:length(obj.libpath)) ~= obj.libpath)
                % Windows uses semicolons (;) to separate the PATH items
                setenv('PATH', [obj.libpath ';' curEnv]);
            end
        elseif isunix
            % Prepend libpath only if not present already
            curEnv = getenv('LD_LIBRARY_PATH');
            if (length(curEnv) < length(obj.libpath)) || any(curEnv(1:length(obj.libpath)) ~= obj.libpath)
                setenv('LD_LIBRARY_PATH', [obj.libpath ':' curEnv]);
            end
        elseif ismac
            % Prepend libpath only if not present already
            curEnv = getenv('DYLD_LIBRARY_PATH');
            if (length(curEnv) < length(obj.libpath)) || any(curEnv(1:length(obj.libpath)) ~= obj.libpath)
                setenv('DYLD_LIBRARY_PATH', [obj.libpath ':' curEnv]);
            end
        end
        setenv('OMP_NUM_THREADS', num2str(obj.omp_num_threads));
        
        % Call simulator
        [failed, result] = system([cadet_cs ' ' workfile]);
        if obj.show_result
            fprintf('%s',result);
        end
        if failed
            error('Simulation failed!');
        end
        
        % Load output from the HDF5 file
        obj.co.loadFromH5(workfile);
    end
end

end

Hi Tilottama and welcome to the CADET-Forum!

Note that CADET-Matlab is unfortunately no longer supported so we can no longer help you.
Please consider using CADET-Process.

Best regards

Thanks for reaching out with this issue. Please understand that both version 2 and 3 of CADET are long outdated and no longer supported. While newer versions offer much improved functionality and usability through a Python-based front end, they do no longer support the MATLAB interface.

The current CADET team exclusively uses Python and all developers who originally implemented and used the MATLAB interface have since moved on. Unfortunately, this means that we are unable to provide support for the MATLAB interface.

That said, some of the more seasoned CADET users in the community might be able to help in this case.