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.

Set point source programmatically

Please login with a confirmed email address before reporting spam

Hi everyone,

I'm experimenting with COMSOL's livelink to Matlab. In general, this is quite useful to programmatically set and run the models etc., but a few things I just cannot figure out. One of them: I would like to programmatically create a number of point sources (pressure acoustics module) given user-defined source amplitudes. However, I cannot assign the point source to the desired point in the geometry programmatically, because the identifier for the point changes.

Here is what I do (in Matlab) create a point in the geometry: model.component('comp1').geom('geom1').create('pt1', 'Point'); model.component('comp1').geom('geom1').feature('pt1').label('my_label'); model.component('comp1').geom('geom1').feature('pt1').setIndex('p', x_cord, 0); model.component('comp1').geom('geom1').feature('pt1').setIndex('p', y_cord, 0); model.component('comp1').geom('geom1').run('fin');

create a used defined function table: model.component('comp1').func.create(int2, 'Interpolation'); model.component('comp1').func(int2).set('funcname','my_func'); model.component('comp1').func(int2).label('my_func_label'); model.component('comp1').func(int2).set('argunit', 's'); model.component('comp1').func(int2).set('fununit', 'Pa');

create a point source: model.component('comp1').physics('actd').create(mls1, 'TransientMonopoleLineSource', 0); model.component('comp1').physics('actd').feature(mls1).set('Type', 'UserDefined'); model.component('comp1').physics('actd').feature(mls1).set('S', 'my_func(t)']); model.component('comp1').physics('actd').feature(mls1).label('my_ps_label'); model.component('comp1').physics('actd').feature(mls1).selection.set([6]);

The last line is the problem: I have to manually figure out which identifier (or however it's called) was assigned to point 'pt1' (which is '6' in my example). Is there a way of specifying the desired point using the name I gave it (i.e., 'pt1')? This would be much more robust and also intuitive, but I simply cannot figure out how to do this.

Thanks a lot,

Theo

Edit: Alternatively: Is there a way to programmatically ready out which identifier was assigned to 'pt1' after building the geometry, such that I retrieve '6' as an answer? That would be an unneccessary extra step imho, but an alternative solution.


2 Replies Last Post 21.05.2020, 01:02 GMT-4
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 5 years ago 20.05.2020, 10:20 GMT-4

Hi Theodor

Sure there is. I wrote series of blog posts on this subjects a few years ago:

https://www.comsol.com/blogs/best-practice-working-model-m-files

The things you are asking about is in part 2. You should use the mphselectcoords function to get the entity numbers you're looking for.

-------------------
Lars Gregersen
Comsol Denmark
Hi Theodor Sure there is. I wrote series of blog posts on this subjects a few years ago: https://www.comsol.com/blogs/best-practice-working-model-m-files The things you are asking about is in part 2. You should use the mphselectcoords function to get the entity numbers you're looking for.

Please login with a confirmed email address before reporting spam

Posted: 5 years ago 21.05.2020, 01:02 GMT-4

Hi Lars,

Great, that seems to work well - thanks a lot! I have a different question related to LiveLink with Matlab related to creating interpolation functions using a local table. Maybe you have an answer to this too, but it seems to make more sense to open a separate thread for that.

Thanks again,

Theo

Hi Lars, Great, that seems to work well - thanks a lot! I have a different question related to LiveLink with Matlab related to creating interpolation functions using a local table. Maybe you have an answer to this too, but it seems to make more sense to open a separate thread for that. Thanks again, Theo

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.