close all
clearvars
uqlab
%2.1 SCALAR RANDOM VARIABLES
% Specify the marginals as follows:The SCALAR random variables includes 7 independent random variables.
%Material properties - Random field
Input.Marginals(1).Name = 'SMYS';  % Tensile Yield Strength
Input.Marginals(1).Type = 'Gaussian';
Input.Marginals(1).Parameters = [624.48 32.97];  % (MPa)
Input.Marginals(2).Name = 'UTS';  % Ultimate Tensile Strength
Input.Marginals(2).Type = 'Gaussian';
Input.Marginals(2).Parameters = [732 28.52];  % (MPa)
Input.Marginals(3).Name = 'D';  %  Outer Diameter
Input.Marginals(3).Type = 'Gaussian';
Input.Marginals(3).Parameters = [458.6 0.691];  % (mm)
Input.Marginals(4).Name = 't';  % Pipe wall thickness
Input.Marginals(4).Type = 'Gaussian';
Input.Marginals(4).Parameters = [7.98 0.071];  % (mm)
Input.Marginals(5).Name = 'Lc';  % Parameter 2 Effective corrosion cluster length
Input.Marginals(5).Type = 'Gaussian';
Input.Marginals(5).Parameters = [210 10.5];  % (mm)
Input.Marginals(6).Name = 'SL';  % Parameter 3 Interacting longitudinal distance
Input.Marginals(6).Type = 'Gaussian';
Input.Marginals(6).Parameters = [30 1.5];  % (mm)
Input.Marginals(7).Name = 'Sc';  % Parameter 4 Interacting circumferential distance
Input.Marginals(7).Type = 'Gaussian';
Input.Marginals(7).Parameters = [21.08 1.054];  % (mm)

%Create an INPUT object based on the specified marginals:
myScalarInput = uq_createInput(Input) ;
% RANDOM FIELDS:  corrosion growth
%BD2 dc
%Specify the type of input
RFInput.Type = 'RandomField' ;
%Specify the type of RF
RFInput.RFType = 'Gaussian' ;
%Specify the type of correlation
RFInput.Corr.Type = 'Separable' ;
%Specify the correlation family
RFInput.Corr.Family = 'Gaussian' ;
%Specify the correlation length
RFInput.Corr.Length = 60 ;
%Specify the expansion order
RFInput.ExpOrder = 10 ;
%Specify the mesh for the sampling of the random field
RFInput.Mesh = linspace(0,120,121)';
%Specify the mean and standard deviation of the random field
RFInput.Mean = 4.9464 ;
RFInput.Std = 0.1063;
%Specify the conditional data
RFInput.RFData.X = [0; 60; 120] ;
RFInput.RFData.Y = [4.8; 4.85; 4.90] ;
%Create an INPUT object based on the specified random field options
myRFInput = uq_createInput(RFInput);
myFullInput = uq_mergeInputs(myScalarInput, myRFInput.UnderlyingGaussian) ;

%3 - COMPUTATIONAL MODEL
%Insert developed PCE surrogate model .mat file
% Load Surrogate model by clicking on .mat file and select only model needed
%load'myPCE_LARSa'
%model as m-file, wrap the model in a function or the model as a function handle 
ModelOpts.mHandle = @(X) uq_evalModel(myPCE_LARSa, X);
%ModelOpts.isVectorized = true;
ModelOpts.Parameters = myRFInput ;
myModel = uq_createModel(ModelOpts);
%4. EXPERMENTAL DESIGN OVER DESCRITISATION DOMAIN (120mobths)
%Construct a surrogate based on 150 model runs
X = uq_getSample(myFullInput, 120, 'LHS') ;
%Xm1 = uq_getSample(myFullInput, 360, 'MC') ;
%Xm = uq_getSample(myFullInput, 360, 'Sobol') ;
%Xm = uq_getSample(myFullInput, 360, 'Halton') ;
%Evaluate the computational model
fprintf('Evaluating the experimental design...')
%Ym = uq_evalModel(myModel, Xm) ;
%Ym1 = uq_evalModel(myModel, Xm1) ;
Y = uq_evalModel(myModel, X) ;
fprintf(' done!\n\n')
