How to fix Error for Multiple model definitions found! in Reliability Analysis Using MCS and FORM

Hello everyone,

I am working on evaluating the reliability index (β) and the probability of failure (pf) of a beam using both the Monte Carlo Simulation (MCS) and the First Order Reliability Method (FORM) with the following limit state function:

g(P, L, W, T) = W * T - (P * L) / 4

The random variables and their properties are defined as follows:

  • Beam length (L) : Normal distribution (8m, 0.1m)
  • Force (P): ∼ N(10 kN, 2kN)
  • Plastic section modulus (W): ∼ N(100*10^-6 m^3, 2.10^-5 m^3)
  • Yield stress (T):∼ N(600*10^3 kN/m^2, 10^5 kN/m^2)

I implemented the following MATLAB code to set up the reliability analysis in UQLab:

%% Initialize UQLab
uqlab;

% Remove existing models and inputs to avoid the "Multiple model definitions" error
uq_removeModel('all');  % Remove all existing models
uq_removeInput('all');  % Remove all existing input objects

%% Define the probabilistic model (INPUT object)
InputOpts.Marginals(1).Name = 'L';  % Beam length
InputOpts.Marginals(1).Type = 'Gaussian';
InputOpts.Marginals(1).Parameters = [8, 0.1];  % Mean 8m, Std 0.1m

InputOpts.Marginals(2).Name = 'P';  % Force
InputOpts.Marginals(2).Type = 'Gaussian';
InputOpts.Marginals(2).Parameters = [10, 2];  % Mean 10kN, Std 2kN

InputOpts.Marginals(3).Name = 'W';  % Plastic section modulus
InputOpts.Marginals(3).Type = 'Gaussian';
InputOpts.Marginals(3).Parameters = [100e-6, 2e-5];  % Mean 100x10^-6, Std 2x10^-5

InputOpts.Marginals(4).Name = 'T';  % Yield stress
InputOpts.Marginals(4).Type = 'Gaussian';
InputOpts.Marginals(4).Parameters = [600e3, 1e5];  % Mean 600x10^3 kN/m^2, Std 10^5 kN/m^2

% Create the INPUT object
myInput = uq_createInput(InputOpts);

%% Define the limit state function (MODEL object)
ModelOpts.mString = 'X(:,3) .* X(:,4) - (X(:,2) .* X(:,1)) / 4';  % MATLAB function for g(P, L, W, T)
ModelOpts.isVectorized = true;  % To handle vectorized operations

% Create the MODEL object
myModel = uq_createModel(ModelOpts);

%% Set up the reliability analysis (ANALYSIS object)

% Monte Carlo Simulation (MCS) setup
ReliabilityOpts.Type = 'Reliability';
ReliabilityOpts.Method = 'MCS';  % Monte Carlo Simulation
ReliabilityOpts.Simulation.BatchSize = 1e4;  % Number of samples per batch
ReliabilityOpts.Simulation.MaxSampleSize = 1e6;  % Maximum number of samples

% Assign the limit state function and input
ReliabilityOpts.Model = myModel;
ReliabilityOpts.Input = myInput;

% Run the reliability analysis using MCS
MCSAnalysis = uq_createAnalysis(ReliabilityOpts);

%% Output the MCS results
uq_print(MCSAnalysis);
uq_display(MCSAnalysis);

%% Set up FORM analysis
ReliabilityOpts.Method = 'FORM';  % First Order Reliability Method

% Run the reliability analysis using FORM
FORMAnalysis = uq_createAnalysis(ReliabilityOpts);

%% Output the FORM results
uq_print(FORMAnalysis);
uq_display(FORMAnalysis);

However, I encounter the following error:

Error using uq_initialize_uq_default_model
Multiple model definitions found!

Error in uq_core_module/run_initialization_script (line 201)
                            initHandle(obj);

Error in uq_core_model/add_module (line 91)
                success = this.run_initialization_script(obj);

Error in uq_createModel (line 107)
eval(str);

Error in Question_5_MC_FORM (line 35)
myModel = uq_createModel(ModelOpts);

I have attempted to remove existing models and inputs using uq_removeModel and uq_removeInput, but the error persists. Could anyone advise me on how to resolve this issue?

Thank you in advance for your help!

Dear @Bini_Yoni,

I cannot reproduce the error with the code you provided. This suggests to me that there may be interference with the active MATLAB workspace. What happens if you do a clear all before executing your code?

Best regards,
Styfen

Dear @Bini_Yoni ,
the error you are getting is because you have multiple model definitions in the ModelOpts variable, e.g. if you have both ModelOpts.mFile and ModelOpts.mString fields in the structure.
You can easily fix it by simply typing clear ModelOpts

About the other two lines:

they are not necessary, as the uqlab command at the beginning clears the UQLab session.

Have fun with UQLab,
Stefano