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.
Running *.class file from Eclipse without opening COMSOL
Posted Sep 26, 2011, 12:22 p.m. EDT Version 4.1, Version 4.2 1 Reply
Please login with a confirmed email address before reporting spam
Ive attached code for a *.class file that runs a 2D heat problem and sets up everything to export a surface plot at the end but I do not know how to tell Eclipse to tell COMSOL to 'Click export' at the end. I have to open the *.class file with COMSOL, and click export. Any suggestions as to how to tell COMSOL to click 'export'?
Im starting the server before running in Eclipse (>COMSOL4.1>Client Server>COMSOL Multiphysics 4.1 Server). When I click 'run' in Eclipse, Im seeing that I connect but the plot does not appear on my desktop. At the end, it disconnects.
(To open file in COMSOL, remove lines 12 and 14)
Thanks
Alex
/*
* Exporter.java
*/
import com.comsol.model.*;
import com.comsol.model.util.*;
/* Model exported by COMSOL 4.1.0.88. */
public class Exporter {
public static void main(String[] args) {
ModelUtil.connect("localhost", 2036);
run();
ModelUtil.disconnect();
}
public static Model run() {
Model model = ModelUtil.create("Model");
model.modelPath("C:\\Users\\adw88\\Desktop");
model.modelNode().create("mod1");
model.geom().create("geom1", 2);
model.mesh().create("mesh1", "geom1");
model.physics()
.create("ht", "HeatTransfer", "geom1", new String[]{"I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10", "I11", "I12"});
model.study().create("std1");
model.study("std1").feature().create("time", "Transient");
model.geom("geom1").feature().create("r1", "Rectangle");
model.geom("geom1").feature("r1").setIndex("size", ".1", 0);
model.geom("geom1").feature("r1").setIndex("size", ".05", 1);
model.geom("geom1").runAll();
model.geom("geom1").run();
model.physics("ht").feature("solid1").set("k_mat", 1, "userdef");
model.physics("ht").feature("solid1")
.set("k", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
model.physics("ht").feature("solid1").set("rho_mat", 1, "userdef");
model.physics("ht").feature("solid1").set("rho", 1, "1000");
model.physics("ht").feature("solid1").set("Cp_mat", 1, "userdef");
model.physics("ht").feature("solid1").set("Cp", 1, "4180");
model.physics("ht").feature().create("temp1", "TemperatureBoundary", 1);
model.physics("ht").feature("temp1").selection().set(new int[]{2, 3});
model.physics("ht").feature("temp1").set("T0", 1, "350[K]");
model.physics("ht").feature().create("hf1", "HeatFluxBoundary", 1);
model.physics("ht").feature("hf1").selection().set(new int[]{4});
model.physics("ht").feature("hf1").set("q0", 1, "10*(350-T)");
model.mesh("mesh1").feature().create("map1", "Map");
model.mesh("mesh1").feature("map1").feature()
.create("dis1", "Distribution");
model.mesh("mesh1").feature("map1").feature("dis1").selection()
.set(new int[]{1, 2});
model.mesh("mesh1").feature("map1").feature("dis1").set("numelem", "50");
model.mesh("mesh1").run();
model.study("std1").feature("time").set("rtolactive", "on");
model.study("std1").feature("time").set("plot", "on");
model.study("std1").feature("time").set("tlist", "range(0,10,180)");
model.sol().create("sol1");
model.sol("sol1").study("std1");
model.sol("sol1").feature().create("st1", "StudyStep");
model.sol("sol1").feature("st1").set("study", "std1");
model.sol("sol1").feature("st1").set("studystep", "time");
model.sol("sol1").feature().create("v1", "Variables");
model.sol("sol1").feature().create("t1", "Time");
model.sol("sol1").feature("t1").set("plot", "on");
model.sol("sol1").feature("t1").set("plotfreq", "tout");
model.sol("sol1").feature("t1").set("probesel", "all");
model.sol("sol1").feature("t1").set("probes", new String[]{});
model.sol("sol1").feature("t1").set("probefreq", "tsteps");
model.sol("sol1").feature("t1").set("estrat", "exclude");
model.sol("sol1").feature("t1").set("maxorder", 2);
model.sol("sol1").feature("t1").set("control", "time");
model.sol("sol1").feature("t1").feature().create("fc1", "FullyCoupled");
model.sol("sol1").feature("t1").feature("fc1").set("jtech", "once");
model.sol("sol1").feature("t1").feature("fc1").set("maxiter", 5);
model.sol("sol1").feature("t1").feature().create("d1", "Direct");
model.sol("sol1").feature("t1").feature("d1").set("linsolver", "pardiso");
model.sol("sol1").feature("t1").feature("fc1").set("linsolver", "d1");
model.sol("sol1").feature("t1").feature("fc1").set("jtech", "once");
model.sol("sol1").feature("t1").feature("fc1").set("maxiter", 5);
model.sol("sol1").feature("t1").feature().remove("fcDef");
model.sol("sol1").attach("std1");
model.sol("sol1").feature("t1").set("control", "user");
model.sol("sol1").feature("t1").set("atolglobal", "1e-6");
model.sol("sol1").feature("t1").set("maxstepbdfactive", "on");
model.sol("sol1").feature("t1").set("maxstepbdf", "1");
model.sol("sol1").feature("t1").set("tstepsbdf", "free");
model.sol("sol1").feature("t1").set("initialstepbdfactive", "on");
model.sol("sol1").feature("t1").set("initialstepbdf", "1e-6");
model.result().create("pg1", 2);
model.result("pg1").set("data", "dset1");
model.result("pg1").feature().create("surf1", "Surface");
model.result("pg1").feature("surf1").set("expr", "T");
model.result("pg1").feature("surf1").set("descr", "Temperature");
model.sol("sol1").runAll();
model.result("pg1").set("windowtitle", "Graphics");
model.result("pg1").run();
model.result("pg1").set("windowtitle", "Graphics");
model.result("pg1").run();
model.result("pg1").run();
model.result("pg1").set("solnum", "8");
model.result("pg1").run();
model.result("pg1").run();
model.result("pg1").run();
model.result("pg1").feature().create("mesh1", "Mesh");
model.result("pg1").feature().remove("mesh1");
model.result("pg1").run();
model.result().export().create("img1", "Image2D");
model.result("pg1").set("window", "graphics");
model.result("pg1").run();
model.result("pg1").set("window", "graphics");
model.result("pg1").set("windowtitle", "Graphics");
model.result("pg1").set("window", "graphics");
model.result("pg1").run();
model.result("pg1").set("window", "graphics");
model.result("pg1").set("windowtitle", "Graphics");
model.result().export("img1").set("imagetype", "jpeg");
model.result().export("img1")
.set("jpegfilename", "C:\\Users\\adw88\\Desktop\\HelloWorld.jpg");
model.result("pg1").run();
model.result("pg1").run();
model.result("pg1").set("solnum", "19");
model.result("pg1").set("window", "graphics");
model.result("pg1").run();
model.result("pg1").set("window", "graphics");
model.result("pg1").set("windowtitle", "Graphics");
model.result().export("img1").set("options", "on");
model.result().export("img1").run();
return model;
}
}
Im starting the server before running in Eclipse (>COMSOL4.1>Client Server>COMSOL Multiphysics 4.1 Server). When I click 'run' in Eclipse, Im seeing that I connect but the plot does not appear on my desktop. At the end, it disconnects.
(To open file in COMSOL, remove lines 12 and 14)
Thanks
Alex
/*
* Exporter.java
*/
import com.comsol.model.*;
import com.comsol.model.util.*;
/* Model exported by COMSOL 4.1.0.88. */
public class Exporter {
public static void main(String[] args) {
ModelUtil.connect("localhost", 2036);
run();
ModelUtil.disconnect();
}
public static Model run() {
Model model = ModelUtil.create("Model");
model.modelPath("C:\\Users\\adw88\\Desktop");
model.modelNode().create("mod1");
model.geom().create("geom1", 2);
model.mesh().create("mesh1", "geom1");
model.physics()
.create("ht", "HeatTransfer", "geom1", new String[]{"I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10", "I11", "I12"});
model.study().create("std1");
model.study("std1").feature().create("time", "Transient");
model.geom("geom1").feature().create("r1", "Rectangle");
model.geom("geom1").feature("r1").setIndex("size", ".1", 0);
model.geom("geom1").feature("r1").setIndex("size", ".05", 1);
model.geom("geom1").runAll();
model.geom("geom1").run();
model.physics("ht").feature("solid1").set("k_mat", 1, "userdef");
model.physics("ht").feature("solid1")
.set("k", new String[]{"1", "0", "0", "0", "1", "0", "0", "0", "1"});
model.physics("ht").feature("solid1").set("rho_mat", 1, "userdef");
model.physics("ht").feature("solid1").set("rho", 1, "1000");
model.physics("ht").feature("solid1").set("Cp_mat", 1, "userdef");
model.physics("ht").feature("solid1").set("Cp", 1, "4180");
model.physics("ht").feature().create("temp1", "TemperatureBoundary", 1);
model.physics("ht").feature("temp1").selection().set(new int[]{2, 3});
model.physics("ht").feature("temp1").set("T0", 1, "350[K]");
model.physics("ht").feature().create("hf1", "HeatFluxBoundary", 1);
model.physics("ht").feature("hf1").selection().set(new int[]{4});
model.physics("ht").feature("hf1").set("q0", 1, "10*(350-T)");
model.mesh("mesh1").feature().create("map1", "Map");
model.mesh("mesh1").feature("map1").feature()
.create("dis1", "Distribution");
model.mesh("mesh1").feature("map1").feature("dis1").selection()
.set(new int[]{1, 2});
model.mesh("mesh1").feature("map1").feature("dis1").set("numelem", "50");
model.mesh("mesh1").run();
model.study("std1").feature("time").set("rtolactive", "on");
model.study("std1").feature("time").set("plot", "on");
model.study("std1").feature("time").set("tlist", "range(0,10,180)");
model.sol().create("sol1");
model.sol("sol1").study("std1");
model.sol("sol1").feature().create("st1", "StudyStep");
model.sol("sol1").feature("st1").set("study", "std1");
model.sol("sol1").feature("st1").set("studystep", "time");
model.sol("sol1").feature().create("v1", "Variables");
model.sol("sol1").feature().create("t1", "Time");
model.sol("sol1").feature("t1").set("plot", "on");
model.sol("sol1").feature("t1").set("plotfreq", "tout");
model.sol("sol1").feature("t1").set("probesel", "all");
model.sol("sol1").feature("t1").set("probes", new String[]{});
model.sol("sol1").feature("t1").set("probefreq", "tsteps");
model.sol("sol1").feature("t1").set("estrat", "exclude");
model.sol("sol1").feature("t1").set("maxorder", 2);
model.sol("sol1").feature("t1").set("control", "time");
model.sol("sol1").feature("t1").feature().create("fc1", "FullyCoupled");
model.sol("sol1").feature("t1").feature("fc1").set("jtech", "once");
model.sol("sol1").feature("t1").feature("fc1").set("maxiter", 5);
model.sol("sol1").feature("t1").feature().create("d1", "Direct");
model.sol("sol1").feature("t1").feature("d1").set("linsolver", "pardiso");
model.sol("sol1").feature("t1").feature("fc1").set("linsolver", "d1");
model.sol("sol1").feature("t1").feature("fc1").set("jtech", "once");
model.sol("sol1").feature("t1").feature("fc1").set("maxiter", 5);
model.sol("sol1").feature("t1").feature().remove("fcDef");
model.sol("sol1").attach("std1");
model.sol("sol1").feature("t1").set("control", "user");
model.sol("sol1").feature("t1").set("atolglobal", "1e-6");
model.sol("sol1").feature("t1").set("maxstepbdfactive", "on");
model.sol("sol1").feature("t1").set("maxstepbdf", "1");
model.sol("sol1").feature("t1").set("tstepsbdf", "free");
model.sol("sol1").feature("t1").set("initialstepbdfactive", "on");
model.sol("sol1").feature("t1").set("initialstepbdf", "1e-6");
model.result().create("pg1", 2);
model.result("pg1").set("data", "dset1");
model.result("pg1").feature().create("surf1", "Surface");
model.result("pg1").feature("surf1").set("expr", "T");
model.result("pg1").feature("surf1").set("descr", "Temperature");
model.sol("sol1").runAll();
model.result("pg1").set("windowtitle", "Graphics");
model.result("pg1").run();
model.result("pg1").set("windowtitle", "Graphics");
model.result("pg1").run();
model.result("pg1").run();
model.result("pg1").set("solnum", "8");
model.result("pg1").run();
model.result("pg1").run();
model.result("pg1").run();
model.result("pg1").feature().create("mesh1", "Mesh");
model.result("pg1").feature().remove("mesh1");
model.result("pg1").run();
model.result().export().create("img1", "Image2D");
model.result("pg1").set("window", "graphics");
model.result("pg1").run();
model.result("pg1").set("window", "graphics");
model.result("pg1").set("windowtitle", "Graphics");
model.result("pg1").set("window", "graphics");
model.result("pg1").run();
model.result("pg1").set("window", "graphics");
model.result("pg1").set("windowtitle", "Graphics");
model.result().export("img1").set("imagetype", "jpeg");
model.result().export("img1")
.set("jpegfilename", "C:\\Users\\adw88\\Desktop\\HelloWorld.jpg");
model.result("pg1").run();
model.result("pg1").run();
model.result("pg1").set("solnum", "19");
model.result("pg1").set("window", "graphics");
model.result("pg1").run();
model.result("pg1").set("window", "graphics");
model.result("pg1").set("windowtitle", "Graphics");
model.result().export("img1").set("options", "on");
model.result().export("img1").run();
return model;
}
}
1 Reply Last Post Sep 28, 2011, 3:24 a.m. EDT