Dear all, I have a corrosion model in COMSOL, that basically is a diffusion-reaction based model. I need to perform Kriging over the parameter estimation. As a first step I managed to operate COMSOL within matlab through “LiveLink”, which in principle will bring both UQLab and Comsol within the same matlab environment, but still have a problem in the navigation ! How I can exchange files between both of them so that I can perform my calculations through UQLab ?

Highly appreciate your help!

Thanks in advanced

Hi @TamadurAB,

I mentioned previously about the possibility of using UQLink to wrap COMSOL so you can use your model as a UQLab MODEL object. But indeed now knowing about LiveLink for MATLAB feature of COMSOL, UQLink may not be necessary.

I assume that LiveLink provide you with abilities—via MATLAB commands—to change the parameters in your model you’re interested in, run the COMSOL simulation, and post-process or get the results that you’re interested in (i.e., quantities of interest). Can you confirm this?

If so, you might not need to think about exchanging files and can simply create a MATLAB wrapper function around relevant LiveLink functionalities. You can find the details of creating a wrapper function in the Model Module User Manual Section 2.3 but below is the basic idea.

You need to create a MATLAB function with the following template:

```
function Y = myCOMSOLWrapper(X,P)
% LiveLink/MATLAB code that:
% 1. loads the COMSOL model (if necessary)
% 2. takes X as input variables and P as parameters to the model
% 3. runs the COMSOL simulation
% 4. post-processes the simulation results to get Y (the quantity of interest).
end
```

A note on terminology so as to not confuse them later on: UQLab makes a distinction between the terms *input variables* (`X`

) and *parameters* (`P`

). The former is used for inputs that are modeled probabilistically in the context of UQ (the ones that you create an INPUT object for). The latter is optional and used for *static* inputs; these inputs are kept constant during model evaluation, but you might still want to access them manually between simulation campaign, say, to change how the model is evaluated (e.g., time step size, setting for the numerical solver).

Once you successfully create this wrapper, you can proceed to create a UQLab MODEL object by assigning the wrapper function filename to the configuration option: `ModelOpts.mFile = 'myCOMSOLWrapper';`

and call `uq_createModel`

on the option (for an example, see Basic Modeling: Computational Model Definition).

I cannot be more concrete because I don’t know anything about LiveLink for MATLAB other than an assumption that such an API should be able to give you a control over the required steps I mentioned inside the wrapper.

Hope this helps.

Thanks so much @damarginal … LiveLink provide full control over the comsol model, so in basic you can operate … study … any numerical experiments in comsol using ATLAB commands.

I`ll check the wrapper and will update the answer with any outcomes I can get. Thanks!

Great to hear! I’d be glad to hear more about the outcome!