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.

Altern the geometry with help of constants

Please login with a confirmed email address before reporting spam

Hello!
I want to be able to modify the geometri by alterning the some constants in a m-file.
for exemple instead of entering the number 0.048 i want to create a constant, like
width=0.048;

But as soon as i put width instead of a number, matlab can run the last line?! why?
I tryed all diffrent ways. This did work in the old version 3.5 but I can't understand how in version 4?

% Geometry of a Rectangle
model.geom('geom1').feature.create('r1', 'Rectangle');
model.geom('geom1').feature('r1').setIndex('size', '0.048', 0);
model.geom('geom1').feature('r1').setIndex('size', '0.138', 1);
model.geom('geom1').feature('r1').set('base', 'center');
model.geom('geom1').feature('r1').setIndex('pos', '0.024', 0);
model.geom('geom1').run('r1');


Have a nice day

4 Replies Last Post 16 août 2010, 10:02 UTC−4
Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 16 août 2010, 05:25 UTC−4
Hi

I can only dvice you to ask also "support", but document well your case and give them the models so they can quickly reproduce the issue

--
Good luck
Ivar
Hi I can only dvice you to ask also "support", but document well your case and give them the models so they can quickly reproduce the issue -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 16 août 2010, 08:46 UTC−4

Hello!
I want to be able to modify the geometri by alterning the some constants in a m-file.
for exemple instead of entering the number 0.048 i want to create a constant, like
width=0.048;

But as soon as i put width instead of a number, matlab can run the last line?! why?
I tryed all diffrent ways. This did work in the old version 3.5 but I can't understand how in version 4?

% Geometry of a Rectangle
model.geom('geom1').feature.create('r1', 'Rectangle');
model.geom('geom1').feature('r1').setIndex('size', '0.048', 0);
model.geom('geom1').feature('r1').setIndex('size', '0.138', 1);
model.geom('geom1').feature('r1').set('base', 'center');
model.geom('geom1').feature('r1').setIndex('pos', '0.024', 0);
model.geom('geom1').run('r1');


Have a nice day


what is the error you're getting? the above code ran fine for me.

[QUOTE] Hello! I want to be able to modify the geometri by alterning the some constants in a m-file. for exemple instead of entering the number 0.048 i want to create a constant, like width=0.048; But as soon as i put width instead of a number, matlab can run the last line?! why? I tryed all diffrent ways. This did work in the old version 3.5 but I can't understand how in version 4? % Geometry of a Rectangle model.geom('geom1').feature.create('r1', 'Rectangle'); model.geom('geom1').feature('r1').setIndex('size', '0.048', 0); model.geom('geom1').feature('r1').setIndex('size', '0.138', 1); model.geom('geom1').feature('r1').set('base', 'center'); model.geom('geom1').feature('r1').setIndex('pos', '0.024', 0); model.geom('geom1').run('r1'); Have a nice day [/QUOTE] what is the error you're getting? the above code ran fine for me.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 16 août 2010, 09:14 UTC−4
Hi! yes, that code woks good untill I exchange the number 0.048 with a constant, like a,
so if I write

%Constants
a=0.048

% Geometry of a Rectangle
model.geom('geom1').feature.create('r1', 'Rectangle');
model.geom('geom1').feature('r1').setIndex('size', 'a', 0); % Put in the constant instaed of 0.048
model.geom('geom1').feature('r1').setIndex('size', '0.138', 1);
model.geom('geom1').feature('r1').set('base', 'center');
model.geom('geom1').feature('r1').setIndex('pos', '0.024', 0);
model.geom('geom1').run('r1');


MATLAB says:

??? Java exception occurred:
Exception:
com.comsol.util.exceptions.FlException: Unknown model parameter
Messages:
Unknown model parameter


Stack trace:

at com.comsol.nativeutil.properties.Property.a(Unknown Source)....

Shoulden't this be working?? And I have tryed without the ' '.

regards
Olivia
Hi! yes, that code woks good untill I exchange the number 0.048 with a constant, like a, so if I write %Constants a=0.048 % Geometry of a Rectangle model.geom('geom1').feature.create('r1', 'Rectangle'); model.geom('geom1').feature('r1').setIndex('size', 'a', 0); % Put in the constant instaed of 0.048 model.geom('geom1').feature('r1').setIndex('size', '0.138', 1); model.geom('geom1').feature('r1').set('base', 'center'); model.geom('geom1').feature('r1').setIndex('pos', '0.024', 0); model.geom('geom1').run('r1'); MATLAB says: ??? Java exception occurred: Exception: com.comsol.util.exceptions.FlException: Unknown model parameter Messages: Unknown model parameter Stack trace: at com.comsol.nativeutil.properties.Property.a(Unknown Source).... Shoulden't this be working?? And I have tryed without the ' '. regards Olivia

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 16 août 2010, 10:02 UTC−4
Hi Olivia,

Did you define it first in the global parameters section?

i.e.

model.param.set('a','0.2');
Hi Olivia, Did you define it first in the global parameters section? i.e. model.param.set('a','0.2');

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.