Quantcast
Channel: Latest Discussions - COMSOL Forums
Viewing all articles
Browse latest Browse all 428

How to loop simulations in Comsol 4.2a with Matlab

$
0
0
Dear comsolers, here is an example on how to loop simulations. I'll let you decode it.

'Preprocessing' that I did before the loop:
1. Build a model in Comsol (attached).
2. Save As Model M-File (attached).
3. Open .m in Matlab and look for the line that needs to be modified on every loop. Note the line. Close .m.

The loop:
1. Start 'Comsol 4.2a with Matlab'.
2. Make sure that 'example.mph' is in the current folder.
3. Enter the following code and run it, it's an example of transient 1D heat transfer in solids where thermal conductivity is modified for each loop:

k = {'200[W/m/K]' '1000[W/m/K]' '2000[W/m/K]'}; % strings to pass to Comsol
for n = 1:length(k)
model = mphload('example.mph'); % load model
ModelUtil.showProgress(true) % display the progress bar
model.material('mat1').propertyGroup('def').set('thermalconductivity', {k{n} '0' '0' '0' k{n} '0' '0' '0' k{n}}); % this is the line I noted in the 'preprocessing', it's modified on every loop
model.sol('sol1').runAll; % solve
T(n) = mpheval(model,'T'); % extract and store data
kxx(n) = mpheval(model,'ht.kxx'); % extract and store data
ModelUtil.remove('model') % remove model because it will be reloaded on every loop
end



Viewing all articles
Browse latest Browse all 428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>