Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

Don't Understand how COMSOL component changes when parameters change

Please login with a confirmed email address before reporting spam

I am trying to change the parameters for my COMSOL program using loops in MATLAB. The parameters I wanted to change were set to be taken as parameters in the model function. Once I change the parameters I have the program find results of the simulation. My problem is that in MATLAB, the graphs of the results for the different parameter combinations were looking incorrect . I put the resulting parameters directly into COMSOL Multiphysics and ran it there and the results were fine. When I looked at the compact code of the new model for those new parameters I noticed that the numbers changed in two pieces of the geometry however I'm not sure how to automate the update of these numbers in the MATLAB code. I don't want to need to rely on plugging the values into COMSOL every time.


Here is the original piece code for the first set of parameters: (% is the line that changes) model.component('comp1').selection.create('sel2', 'Explicit'); model.component('comp1').selection('sel2').geom('geom1', 1); model.component('comp1').selection('sel2').set([22 23 24 28 29 30 31 32 33 34 36]);%%%%

model.component('comp1').selection.create('sel3', 'Explicit'); model.component('comp1').selection('sel3').geom('geom1', 1); model.component('comp1').selection('sel3').set([6 7 8 9 10 11 13 14 16 17 21]);%%%%

--

Here is the code after I change the parameters: model.component('comp1').selection.create('sel2', 'Explicit'); model.component('comp1').selection('sel2').geom('geom1', 1); model.component('comp1').selection('sel2').set([23 24 25 27 29 30 31 32 33 34 36]);%%%%

model.component('comp1').selection.create('sel3', 'Explicit'); model.component('comp1').selection('sel3').geom('geom1', 1); model.component('comp1').selection('sel3').set([6 7 8 9 10 11 13 14 16 17 20]);%%%%%%


I could really use some help understanding where these numbers come from and how to automate the update process in a loop so I can get reliable results. Thanks!


1 Reply Last Post Oct 16, 2021, 4:20 p.m. EDT

Please login with a confirmed email address before reporting spam

Posted: 2 years ago Oct 16, 2021, 4:20 p.m. EDT

For anyone who has a similar problem I've figured it out:

I had tried to add parameters to the compact history function I downloaded from COMSOL. The better way is to just load the model (using mphload) and then update parameters in a loop (using model.param.set) and then to run the model just use model.study('std1').run. This will run the model you want with the given parameters and it will automatically change the numbers I was confused about.

For anyone who has a similar problem I've figured it out: I had tried to add parameters to the compact history function I downloaded from COMSOL. The better way is to just load the model (using mphload) and then update parameters in a loop (using model.param.set) and then to run the model just use model.study('std1').run. This will run the model you want with the given parameters and it will automatically change the numbers I was confused about.

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.