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

Set point source programmatically

$
0
0

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.


Viewing all articles
Browse latest Browse all 5773

Trending Articles



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