├── AutomationMinimaCount.m ├── LICENSE ├── MinimaLocations.m ├── README.md └── _config.yml /AutomationMinimaCount.m: -------------------------------------------------------------------------------- 1 | MinimaList = []; % Empty list for sorting minima variables 2 | parameter1 = 1; %Starting values of parameter d 3 | parameter2 = 0.001; %Starting values of parameter j 4 | L=10; %Starting values of parameter L for length 5 | model = mphload('MyModel.mph');%load model 6 | model.param.set('L0', L); 7 | model.sol('sol1').clearSolutionData(); 8 | 9 | while (parameter1 <10.1) 10 | model = mphload('MyModel.mph');%load model 11 | model.sol('sol1').clearSolutionData(); 12 | model.param.set('d',parameter1); %set d value 13 | model.param.set('j',parameter2);%set j value 14 | model.study('std1').run; %run study 15 | model.result('pg6').run(); %run plot of Y(X) 16 | model.result.export('plot4').run; %export datafile 17 | B = importdata('YofX.txt', ' '); %import data 18 | x = B(:, 1); %separate column x 19 | Y = B(:, 2);%separate column Y 20 | TF = islocalmin(Y, 'MinProminence',0.99); %find local min 21 | n = numel(Y(TF)); %count local min 22 | plot(x,Y,x(TF),Y(TF),'r*') %plot minima for check 23 | axis tight 24 | title(['n=',num2str(n),' d= ',num2str(parameter1),' j= ',num2str(parameter2)]) 25 | drawnow; 26 | op=['n=',num2str(n),' d= ',num2str(parameter1),' j= ',num2str(parameter2)]; 27 | disp(op); 28 | if (n==0) 29 | parameter2=parameter2+0.003; 30 | model.sol("sol1").clearSolutionData(); 31 | elseif (n > 1) 32 | parameter2=parameter2-0.004; 33 | model.sol("sol1").clearSolutionData(); 34 | elseif (n==1) 35 | d = strrep(num2str(parameter1), '.', '_'); 36 | filename = strcat('YofXMinima',d); 37 | plot(x,Y,x(TF),Y(TF),'r*') %plot minima for check 38 | axis tight 39 | title(['d= ',num2str(parameter1),' j= ',num2str(parameter2)]) %create title with values 40 | fname = 'C:\Users\UserName\Desktop\MinimaResults'; 41 | saveas(gcf,fullfile(fname, filename),'png'); 42 | MinimaList(end+1,:)=[parameter1,parameter2]; %add d and j value to list 43 | parameter1 = parameter1 + 0.01; 44 | parameter2 = 0.001; 45 | model.sol("sol1").clearSolutionData(); 46 | end 47 | end 48 | 49 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Iris Dorn 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MinimaLocations.m: -------------------------------------------------------------------------------- 1 | xMinLocations = []; %Empty list for storing locations along line and parameters d, j 2 | load('Data.mat'); %Load stored data to reevaluate automatically 3 | A = Data; 4 | d = A(:,1); 5 | j = A(:,2); 6 | for i = 1:90 %length of your data, can use numel(j) or numel(d) 7 | model = mphload('MyModel.mph');%load model 8 | model.sol('sol1').clearSolutionData(); 9 | model.param.set('j0',j(i));%set j value 10 | model.param.set('d',d(i)); %set d value 11 | model.study('std1').run; %run study 12 | model.result('pg6').run(); %run plot 13 | model.result.export('plot4').run; %export plot data 14 | B = importdata('PlotData.txt', ' '); %import data 15 | TF = isempty(B); % Ensure plot is not empty 16 | dn = num2str(d(i)); %For printing error message if plot is empty 17 | if (TF == 1) 18 | ms =['Plot is empty for ',dn]; 19 | disp(ms); 20 | i=i+1; 21 | break 22 | end 23 | x = B(:,1); %separate column x 24 | Y = B(:,2);%separate column Y 25 | [TF1,P] = islocalmin(Y, 'MinProminence',0.99); %find local min with prominence of 0.99 26 | xall = x(TF1); % Store all minima in xall 27 | xmin = unique(xall); % Store for unique values of x 28 | disp(dn); % display parameter d 29 | disp(xmin); % display unique values of locations x 30 | plot(x,Y,x(TF1),Y(TF1), 'r*') %plot minima for check 31 | axis tight; 32 | for idx=1:numel(xmin) 33 | xMinLocations(end+1,:)=[d(i),j(i),xmin(idx)]; %add delta and j value to list 34 | end 35 | end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # automatedcomsol 2 | 3 | 4 | ## Automatization of COMSOL Multiphysics® Model utilizing LiveLink™ for MATLAB® 5 | 6 | Various .m files of code in MATLAB® for automating COMSOL Multiphysics® 7 | 8 | * __[Required Software](https://github.com/irisdorn/automatedcomsol#required-software "Required Software")__ 9 | * __[Few tips for getting started](https://github.com/irisdorn/automatedcomsol#few-tips-for-getting-started "Few tips for getting started")__ 10 | * __[Other Useful Code](https://github.com/irisdorn/automatedcomsol#other-useful-code "Other Useful Code")__ 11 | * __[Contents](https://github.com/irisdorn/automatedcomsol#contents "Contents")__ 12 | 13 | 14 | 15 | 16 | ## Required Software 17 | * [COMSOL Multiphysics®](https://www.comsol.com/comsol-multiphysics "COMSOL Multiphysics®") 18 | * With [LiveLink™ for MATLAB®](https://www.comsol.com/livelink-for-matlab "LiveLink™ for MATLAB®") 19 | * [MATLAB®](https://www.mathworks.com/products/matlab.html "MATLAB®") 20 | 21 | 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. 22 | Videos generated from COMSOL can be viewed at this link: 23 | [Phase Slip Center Videos](https://drive.google.com/open?id=1LHiltQ7Yn5N-5bT32BKTi9s9cc6MWQtE "PSC Videos") 24 | Linking Comsol with MATLAB allowed us to automate several tasks for finding solutions and each task is described below and in the .m files. 25 | 26 | ### Few tips for getting started 27 | 28 | 1. Launch COMSOL Multiphysics® (Your Version) with MATLAB® Program 29 | 30 | _Make sure all other programs, even COMSOL and MATLAB standalones, are closed. This singular program will control both._ 31 | 32 | 2. Load model from command line or into .m file 33 | 34 | _Ensure that you are in the same directory/folder as your COMSOL file._ 35 | 36 | ``` 37 | model = mphload('ModelName.mph') 38 | ``` 39 | 40 | 3. Access the properties of your model 41 | 42 | 43 | ``` 44 | mphlaunch 45 | ``` 46 | 47 | _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._ 48 | 49 | or 50 | 51 | ``` 52 | mphnavigator 53 | ``` 54 | 55 | _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._ 56 | 57 | 58 | #### Other Useful Code 59 | 60 | Setting values for parameters 61 | ``` 62 | L= 10; %Set variable value 63 | model.param.set('L0', L); %Set parameter 'L0' to value of L 64 | ``` 65 | 66 | Run the study 67 | ``` 68 | model.study('std1').run; 69 | ``` 70 | 71 | Generate a plot 72 | ``` 73 | model.result("pg6").run(); 74 | ``` 75 | 76 | Export an animation/video 77 | ``` 78 | model.result.export('anim2').run; 79 | ``` 80 | 81 | Clearing the solution 82 | ``` 83 | model.sol('sol1').clearSolutionData(); %Clear solution 1 84 | ``` 85 | 86 | ## Contents: 87 | [AutomationMinimaCount.m](https://github.com/irisdorn/automatedcomsol/blob/master/AutomationMinimaCount.m "AutomationMinimaCount.m") 88 | 89 | This file sets a start value for two parameters. A while loop sets an upper limit for one particular parameter. 90 | 91 | The AutomationMinimaCount.m file automated the following tasks: 92 | 93 | * Setting the new parameters 94 | * Running the study 95 | * Running the plot 96 | * Exporting the plot data (.txt file) 97 | * Loading the plot data into MATLAB 98 | * Finding local minima with a certain prominence. See documentation on: [islocalmin](https://www.mathworks.com/help/matlab/ref/islocalmin.html?searchHighlight=islocalmin&s_tid=doc_srchtitle "islocalmin") 99 | * Count local minima as n and display 100 | * Runs a set of if-else if conditions in which second parameter is varied, the model solution is cleared and study is rerun 101 | or 102 | * If particular minima condition is met, the parameter values are stored in a .mat file 103 | * A filename is created from the parameter values 104 | * The plot is created with title and marking of the minima in with red star marker 105 | * The plot is saved as a png and the parameters in the while loop is varied 106 | 107 | [MinimaLocations.m](https://github.com/irisdorn/automatedcomsol/blob/master/MinimaLocations.m "MinimaLocations.m") 108 | 109 | The MinimaLocations.m file automated the following tasks: 110 | 111 | * Loads a .mat data set and stores the columns/parameters 112 | * For loop over all elements 113 | * Load model and clear solution data 114 | * Set parameters 115 | * Run study 116 | * Run plot 117 | * Export plot data 118 | * Import plot txt file 119 | * Checks that plot is not empty and prints error message 120 | * Else finds locations of minima 121 | * Stores unique values of minima locations 122 | * Plots these locations 123 | * Stores each location in list with paramaters 124 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal --------------------------------------------------------------------------------