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.

Apply physics to each object (Application builder)

Please login with a confirmed email address before reporting spam

Hello, I'm generating a vector of circle objects programmatically (2D), this works well, but I want to apply an acceleration to each generated circle (different in each one).

To apply the acceleration must indicate the indices of the segments of the circle, but when generating it programmatically I do not have them and they are not constant because in each execution the number of circles is changed, how can I obtain those indexes? Is there another solution?

The example code of the loop that generates the circles and tries to apply the acceleration is the following:

// LOOP (N = input value)
for (int i = 0; i < N; ++i) {
  // BUILD CIRCLE i
  String tag = "cloop"+(i+1);
  String pos = "aCol-d/2-d*"+i; // VERTICAL POSITION
  model.component("comp1").geom("geom1").create(tag, "Circle");
  model.component("comp1").geom("geom1").feature(tag).set("pos", new String[]{"0", pos});
  model.component("comp1").geom("geom1").feature(tag).set("r", "a/2");

  // ADD TO ACUMMULATIVE SELECTION FOR DIFFERENCE AFTER THE LOOP
  model.component("comp1").geom("geom1").feature(tag).set("contributeto", "csel1");

 // GET INDEX 
  int[] idx = Unknown(tag); // ??????

  // ACCELERATION
 String atag = "naccloop"+(i+1);
 model.component("comp1").physics("acpr").create(atag, "NormalAcceleration", 1);
 model.component("comp1").physics("acpr").feature(atag).set("nacc", "exp(iniDist*"+i+"/c0 * j*2*pi*frecMax)"); // ACCELERATION VALUE i
 model.component("comp1").physics("acpr").feature(atag).selection().set(idx); // APPLY ACCEL
 }

Thanks!


1 Reply Last Post 2019年3月18日 GMT-4 03:10

Please login with a confirmed email address before reporting spam

Posted: 6 years ago 2019年3月18日 GMT-4 03:10

Solved: I have created a cumulative selection in each iteration, I assign the current circle to the cumulative selection and I apply the physics.

for (int i = 0; i < N; ++i) {
  // Circle i
  String tag = "cloop"+(i+1);
  String pos = "aCol-d/2-d*"+i; 
  model.component("comp1").geom("geom1").create(tag, "Circle");
  model.component("comp1").geom("geom1").feature(tag).set("pos", new String[]{"0", pos});
  model.component("comp1").geom("geom1").feature(tag).set("r", "a/2");

  // New cumulative selection i with one circle i
  model.component("comp1").geom("geom1").selection().create(tag+"sel", "CumulativeSelection");
  model.component("comp1").geom("geom1").feature(tag).set("contributeto", tag+"sel"); // one per circle

  // Apply physic to cumulative selection i
  String atag = "naccloop"+(i+1);
  model.component("comp1").physics("acpr").create(atag, "NormalAcceleration", 1);
  model.component("comp1").physics("acpr").feature(atag).set("nacc", "exp(iniDist*"+i+"/c0 * j*2*pi*frecMax)");
model.component("comp1").physics("acpr").feature(atag).selection().named("geom1_"+tag+"sel"+"_bnd");  
}
Solved: I have created a cumulative selection in each iteration, I assign the current circle to the cumulative selection and I apply the physics. for (int i = 0; i < N; ++i) { // Circle i String tag = "cloop"+(i+1); String pos = "aCol-d/2-d*"+i; model.component("comp1").geom("geom1").create(tag, "Circle"); model.component("comp1").geom("geom1").feature(tag).set("pos", new String[]{"0", pos}); model.component("comp1").geom("geom1").feature(tag).set("r", "a/2"); // New cumulative selection i with one circle i model.component("comp1").geom("geom1").selection().create(tag+"sel", "CumulativeSelection"); model.component("comp1").geom("geom1").feature(tag).set("contributeto", tag+"sel"); // one per circle // Apply physic to cumulative selection i String atag = "naccloop"+(i+1); model.component("comp1").physics("acpr").create(atag, "NormalAcceleration", 1); model.component("comp1").physics("acpr").feature(atag).set("nacc", "exp(iniDist*"+i+"/c0 * j*2*pi*frecMax)"); model.component("comp1").physics("acpr").feature(atag).selection().named("geom1_"+tag+"sel"+"_bnd"); }

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.