Various .m files of code in MATLAB® for automating COMSOL Multiphysics®
This series of automation .m files were applied to superconducting 1d wire COMSOL model. This particular model was created by implementing the set of Ginzburg-Landau equations into COMSOL’s time-dependent equation based module with the general coefficient PDE form. Linking Comsol with MATLAB allowed us to automate several tasks for finding solutions and each task is described below and in the .m files.
Make sure all other programs, even COMSOL and MATLAB standalones, are closed. This singular program will control both.
Ensure that you are in the same directory/folder as your COMSOL file.
model = mphload('ModelName.mph')
mphlaunch will launch your model in the COMSOL user interface. This can be useful as you learn more about the mphnavigator settings and how to extract m file code for automating.
mphnavigator allows you access to the elements and subproperties of your model. Here is where you will find the tags for your model and can vary this code according to your model’s tags. There are many useful lines of code that can be extracted using the ‘Copy Get’ or ‘Copy Set’ options in this window.
Setting values for parameters
L= 10; %Set variable value model.param.set('L0', L); %Set parameter 'L0' to value of L
Run the study
Generate a plot
Export an animation/video
Clearing the solution
model.sol('sol1').clearSolutionData(); %Clear solution 1
This file sets a start value for two parameters. A while loop sets an upper limit for one particular parameter.
The AutomationMinimaCount.m file automated the following tasks:
The MinimaLocations.m file automated the following tasks: