Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

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.

Finding the Domain number/Creating an entity of a feature created with the Comsol Java API

Please login with a confirmed email address before reporting spam

Hi everyone,

I am using the Java API with Comsol and I really like it's abilities overall. I would like to be able to (in a for loop) create a 3D geometrical object (a cylinder) and then make that cylinder into it's own entity. This would be much like if you were to in the GUI create a cylinder, create an Explicit Entity, Change the geometric entity level to "Domain," click on the cylinder, then right click to select that domain, then change Output Entities to Adjacent Boundaries with either Exterior or Interior boundaries selected. Then create a Floating Potential, or really any other Boundary Condition, then set that Boundary Condition to be set to the Entity that was just made.

Here are some lines of the code:

model.geom("geom1").feature().create("cyl1", "Cylinder"); //creates the cylinder
model.geom("geom1").feature("cyl1").set("pos", new String[]{"0", "0", "0"}); // sets position
model.geom("geom1").feature("cyl1").set("h", "length"); // sets the length of the cylinder

model.selection().create("sel1", "Explicit");
model.selection("sel1").geom("geom1", 3, 2, new String[]{"exterior", "interior"});
model.selection("sel1").set(new int[]{5}); // HOW DO YOU FIGURE OUT WHAT DOMAIN TO PUT HERE.

// later in the code:
model.physics("ec").feature().create("fp1", "FloatingPotential", 2);
model.physics("ec").feature("fp1").selection().named("sel1");


Hopefully you got a pretty good idea of what I'm trying to accomplish above. Just trying to be able to find out what domain number "cyl1" is in this case. Eventually, this will be implemented into a code with 100-10000 cylinders and an individual floating potential can be assigned to each cylinder.

Thanks in advance for your help,
John

5 Replies Last Post Jun 17, 2015, 1:30 a.m. EDT

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Apr 23, 2013, 5:35 a.m. EDT
I think instead of an "Explicit" selection object, you should use a selection of the "Cylinder" type (or "Ball" or "Box" for that matter). I guess in your code you keep track of the coordinates of each cylinder already, but even if you didn't you could access the properties of the "cyl1" geometry object to find explicit coordinates, then set up the "Cylinder" selection accordingly.
I think instead of an "Explicit" selection object, you should use a selection of the "Cylinder" type (or "Ball" or "Box" for that matter). I guess in your code you keep track of the coordinates of each cylinder already, but even if you didn't you could access the properties of the "cyl1" geometry object to find explicit coordinates, then set up the "Cylinder" selection accordingly.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Apr 23, 2013, 3:14 p.m. EDT
Thanks!

I got it to work based on what you hinted to me about a cylinder selection. I've updated my code to show what I did:

model.geom("geom1").feature().create("cyl1", "Cylinder");
model.geom("geom1").feature("cyl1").set("pos", new String[]{"cylinder_x_posiiton", "cylinder_y_position", "cylinder_z_position"});
model.geom("geom1").feature("cyl1").set("h", "length");

model.selection().create("cyl1", "Cylinder");
model.selection("cyl1").set("entitydim", "2");
model.selection("cyl1").set("condition", "allvertices");
model.selection("cyl1").set("axis", new String[]{"1", "0", "0"});
model.selection("cyl1").set("pos", new String[]{"cylinder_x_posiiton", "cylinder_y_position", "cylinder_z_position"});

// later in the code:
model.physics("ec").feature().create("fp1", "FloatingPotential", 2);
model.physics("ec").feature("fp1").selection().named("cyl1");


This fits the bill for what I'm trying to do very well. However, I would still like to figure out how to find the domain of an object if all I give it is that it's a feature("cyl1"). What if I were to have to include a randomly formed object (not necessarily a perfectly formed cylinder, box, or ball) into an entity. Maybe it's not possible to include something in an entity by using feature("cyl1"), in which case I'd have to use a "box" or "Ball" entity type, as you said.

What commands would you use to find the coordinates/information of a geometry object (such as "cyl1")?

Thanks again,

John
Thanks! I got it to work based on what you hinted to me about a cylinder selection. I've updated my code to show what I did: model.geom("geom1").feature().create("cyl1", "Cylinder"); model.geom("geom1").feature("cyl1").set("pos", new String[]{"cylinder_x_posiiton", "cylinder_y_position", "cylinder_z_position"}); model.geom("geom1").feature("cyl1").set("h", "length"); model.selection().create("cyl1", "Cylinder"); model.selection("cyl1").set("entitydim", "2"); model.selection("cyl1").set("condition", "allvertices"); model.selection("cyl1").set("axis", new String[]{"1", "0", "0"}); model.selection("cyl1").set("pos", new String[]{"cylinder_x_posiiton", "cylinder_y_position", "cylinder_z_position"}); // later in the code: model.physics("ec").feature().create("fp1", "FloatingPotential", 2); model.physics("ec").feature("fp1").selection().named("cyl1"); This fits the bill for what I'm trying to do very well. However, I would still like to figure out how to find the domain of an object if all I give it is that it's a feature("cyl1"). What if I were to have to include a randomly formed object (not necessarily a perfectly formed cylinder, box, or ball) into an entity. Maybe it's not possible to include something in an entity by using feature("cyl1"), in which case I'd have to use a "box" or "Ball" entity type, as you said. What commands would you use to find the coordinates/information of a geometry object (such as "cyl1")? Thanks again, John

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Nov 7, 2013, 11:19 a.m. EST
Hi John,
I am wondering if you found a solution to this problem. I don't really like the method of selecting domains and boundaries by some internal numbers, since these can change if you change your code.
Thanks
Daniel
Hi John, I am wondering if you found a solution to this problem. I don't really like the method of selecting domains and boundaries by some internal numbers, since these can change if you change your code. Thanks Daniel

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Aug 31, 2014, 1:48 p.m. EDT
I think with mphgetselection you will find adequate information about your selection
I think with mphgetselection you will find adequate information about your selection

Please login with a confirmed email address before reporting spam

Posted: 9 years ago Jun 17, 2015, 1:30 a.m. EDT

I think with mphgetselection you will find adequate information about your selection


What is this "mphgetselection"? I don't see anything about it in the Java API documentation.
[QUOTE] I think with mphgetselection you will find adequate information about your selection [/QUOTE] What is this "mphgetselection"? I don't see anything about it in the Java API documentation.

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.