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.

COMSOL 4.3b Java API question

Please login with a confirmed email address before reporting spam

Hello everyone!

I’m trying to solve a parametric optimization problem in 2D. Due to intricacies the API seems to be the only way.
I use a circle that represents “air” around the model. One of boundary conditions is Zero magnetic scalar potential defined on the circle’s borders (there are 4 borders, ¼ of circumference each). In COMSOL you just select those borders and it generates code like this:

model.physics("mfnc").feature().create("zsp1", "ZeroMagneticScalarPotential", 1);
model.physics("mfnc").feature("zsp1").selection().set(new int[]{23,24,25,27});

The problem is that IDs of the borders – 23,24,25,27 – often change as result of geometry changes and perhaps (I’m not sure) even when reordering some API calls. I guess there should be a way to get the IDs through API at runtime, but cannot understand how exactly from reading APIReferenceManual. Did anyone solve such problems?

2 Replies Last Post 2013年10月22日 GMT-4 04:27

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2013年10月22日 GMT-4 03:50
Hi Dmitry,

you can do the selection in the following way:

Selection 1: Explicit but check all domains

Selection 2: Adjacency of selection 1, ie the boundary of "all" is your circle.

That should give you a repesentation idependent of numbering. I find this method more stable then explicit picking, even when working in the GUI only

I don't know the exact API-functions, but you can try this in the GUI and inspect the java code that is exported.

Regards,

Jens
Hi Dmitry, you can do the selection in the following way: Selection 1: Explicit but check all domains Selection 2: Adjacency of selection 1, ie the boundary of "all" is your circle. That should give you a repesentation idependent of numbering. I find this method more stable then explicit picking, even when working in the GUI only I don't know the exact API-functions, but you can try this in the GUI and inspect the java code that is exported. Regards, Jens

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2013年10月22日 GMT-4 04:27
Jens, thanks a million. Your method helped.

1. Create explicit named selection and select the circle.
2. Create adjacent selection, use the explicit selection as input and adjacent borders as output.
3. Use the adjacent selection as input to the boundary condition.

No IDs involved, except the circle ID. The generated code looks this:


model.geom("geom1").feature().create("sel1", "ExplicitSelection");
model.geom("geom1").feature("sel1").selection("selection")
.set("c3", new int[]{1});


model.geom("geom1").feature().create("adjsel1", "AdjacentSelection");
model.geom("geom1").feature("adjsel1").set("entitydim", "2");
model.geom("geom1").feature("adjsel1").set("outputdim", "1");
model.geom("geom1").feature("adjsel1").set("input", new String[]{"sel1"});
model.geom("geom1").run();

model.physics("mfnc").feature("zsp1").selection().named("geom1_adjsel1");



Regards,
Dmitry
Jens, thanks a million. Your method helped. 1. Create explicit named selection and select the circle. 2. Create adjacent selection, use the explicit selection as input and adjacent borders as output. 3. Use the adjacent selection as input to the boundary condition. No IDs involved, except the circle ID. The generated code looks this: model.geom("geom1").feature().create("sel1", "ExplicitSelection"); model.geom("geom1").feature("sel1").selection("selection") .set("c3", new int[]{1}); model.geom("geom1").feature().create("adjsel1", "AdjacentSelection"); model.geom("geom1").feature("adjsel1").set("entitydim", "2"); model.geom("geom1").feature("adjsel1").set("outputdim", "1"); model.geom("geom1").feature("adjsel1").set("input", new String[]{"sel1"}); model.geom("geom1").run(); model.physics("mfnc").feature("zsp1").selection().named("geom1_adjsel1"); Regards, Dmitry

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.