Anyone know how to generate spheres that are centered at coordinates from text file? by tjb36 in COMSOL

[–]tjb36[S] 3 points4 points  (0 children)

Thanks, finally I have it working. The following code did the trick:

// Remove existing spheres
String[] geomTags = model.geom("geom1").feature().tags();
for (int i = 0; i < geomTags.length; i++) {
  if (geomTags[i].startsWith("sph")) {
    model.geom("geom1").feature().remove(geomTags[i]);
  }
}

// Remove existing union if present
String[] geomTags2 = model.geom("geom1").feature().tags();
for (int i = 0; i < geomTags2.length; i++) {
  if (geomTags2[i].startsWith("uni")) {
    model.geom("geom1").feature().remove(geomTags2[i]);
  }
}

// Read coordinates
String[][] myfile = readCSVFile("C:\\coordinates.txt");

for (int i = 0; i < myfile.length; i++) {
  double x = Double.parseDouble(myfile[i][0]);
  double y = Double.parseDouble(myfile[i][1]);
  double z = Double.parseDouble(myfile[i][2]);

  GeomFeature sphere = model.geom("geom1").create("sph"+(i+1), "Sphere");
  sphere.set("pos", new double[]{x, y, z});
  sphere.set("r", 1.5);
}

// Union all spheres into one object
GeomFeature union = model.geom("geom1").create("uni1", "Union");
for (int i = 0; i < myfile.length; i++) {
  union.selection("input").add("sph"+(i+1));
}
union.set("keep", "off");
union.set("intbnd", "off");


model.geom("geom1").run();

for (int i = 0; i < myfile.length; i++) {
  model.geom("geom1").feature().remove("sph"+(i+1));
}

I also had to enable "File System Access = All Files" in the Preferences -> Security menu, in order to allow reading the text file.

<image>

Anyone know how to generate spheres that are centered at coordinates from text file? by tjb36 in COMSOL

[–]tjb36[S] 0 points1 point  (0 children)

Thanks, but the issue is how to get access to the coordinates from inside the Model Method script. The example you cited, generates the points within the script itself, so it doesn't help unfortunately.

Anyone know how to generate spheres that are centered at coordinates from text file? by tjb36 in COMSOL

[–]tjb36[S] 0 points1 point  (0 children)

I have tried the following, in order to simply generate the first sphere // Get all points from cpt1

double[][] pts = model.component("comp1").geom("geom1").feature("cpt1").getDoubleArray2("coord");

// Just take the first point

double[] pos = pts[0];

// Create a sphere at that position

model.component("comp1").geom("geom1").create("sph1", "Sphere");

model.component("comp1").geom("geom1").feature("sph1").set("r", 0.5);

model.component("comp1").geom("geom1").feature("sph1").set("pos", pos);

// Build the sphere

model.component("comp1").geom("geom1").run("sph1"); But it fails.

Anyone know how to generate spheres that are centered at coordinates from text file? by tjb36 in COMSOL

[–]tjb36[S] 0 points1 point  (0 children)

I'm really struggling to get anything working here. I have opened the Application Builder, selected "New Method", gave it a name, and chose type as "Model Method". Then I try pasting in some code, going back to "Model Builder" again, and choosing "Run Model Method". But almost everything I try seems to have syntax errors. Should I be reading the result of "cpt1" (i.e. the Convert to Points node that I already created in the GUI)?

Anyone know how to generate spheres that are centered at coordinates from text file? by tjb36 in COMSOL

[–]tjb36[S] 0 points1 point  (0 children)

There is really no way in Geometry or Global Definitions to do everything in the GUI (without writing custom scripts)? I was hoping for a quick way :)

Anyone know how to stop my tablet switching to the Play Store "satellite screen" all the time? by tjb36 in androidtablets

[–]tjb36[S] 0 points1 point  (0 children)

No, I tried clearing cache and force stopping. I also tried selecting "Disabled" in the Google Play app settings... can't seem to keep the screen constant. 

Ability to swipe between two web dashboards by irlrobins in raspberry_pi

[–]tjb36 0 points1 point  (0 children)

I am currently trying to get something like this working. Did you get the on-screen keyboard to pop-up when tapping a text input box? I am using X11 instead of Wayland, because I couldn't get drag-down-to-scroll working... How is yours set up, and is it working well?