automatedcomsol

Various .m files of code in MATLAB® for automating COMSOL Multiphysics®

View the Project on GitHub irisdorn/automatedcomsol

automatedcomsol

Various .m files of code in MATLAB® for automating COMSOL Multiphysics®

Required Software

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.

Few tips for getting started

  1. Launch COMSOL Multiphysics® (Your Version) with MATLAB® Program

Make sure all other programs, even COMSOL and MATLAB standalones, are closed. This singular program will control both.

  1. Load model from command line or into .m file

Ensure that you are in the same directory/folder as your COMSOL file.

model = mphload('ModelName.mph')
  1. Access the properties of your model
mphlaunch

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.

or

mphnavigator

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.

Other Useful Code

Setting values for parameters

L= 10; %Set variable value
model.param.set('L0', L); %Set parameter 'L0' to value of L

Run the study

model.study('std1').run;

Generate a plot

 model.result("pg6").run();

Export an animation/video

model.result.export('anim2').run;

Clearing the solution

model.sol('sol1').clearSolutionData(); %Clear solution 1

Contents:

AutomationMinimaCount.m

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:

MinimaLocations.m

The MinimaLocations.m file automated the following tasks: