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.

Image export using COMSOL API

Please login with a confirmed email address before reporting spam

Hello,

I am currently trying to export 2D image using COMSOL API.
I made JAVA code, but image export part does not work.
Could any one please tell me where is wrong and how to fix it?

-------------------------------------------------------------------------------------------------------
import com.comsol.model.*;
import com.comsol.model.util.*;

public class jats11_00 {

public static void main(String[] args) {
run();
}

public static Model run() {
Model model = ModelUtil.create("Model");

model.modelPath("/home/user");


model.modelNode().create("mod1");

model.geom().create("geom1", 2);
model.geom("geom1").lengthUnit("mm");
model.geom("geom1").feature().create("r1", "Rectangle");
model.geom("geom1").feature("r1").setIndex("size", "0.2", 0);
model.geom("geom1").runAll();

model.material().create("mat1");
model.material("mat1").name("Water");
model.material("mat1").set("family", "water");
model.material("mat1").propertyGroup("def").set("dynamicviscosity", "eta(T[1/K])[Pa*s]");
model.material("mat1").propertyGroup("def").set("ratioofspecificheat", "1.0");
model.material("mat1").propertyGroup("def").set("electricconductivity", "5.5e-6[S/m]");
model.material("mat1").propertyGroup("def").set("heatcapacity", "Cp(T[1/K])[J/(kg*K)]");
model.material("mat1").propertyGroup("def").set("density", "rho(T[1/K])[kg/m^3]");
model.material("mat1").propertyGroup("def").set("thermalconductivity", "k(T[1/K])[W/(m*K)]");
model.material("mat1").propertyGroup("def").set("soundspeed", "cs(T[1/K])[m/s]");
model.material("mat1").propertyGroup("def").func().create("eta", "Piecewise");
model.material("mat1").propertyGroup("def").func("eta").set("funcname", "eta");
model.material("mat1").propertyGroup("def").func("eta").set("arg", "T");
model.material("mat1").propertyGroup("def").func("eta").set("extrap", "constant");
model.material("mat1").propertyGroup("def").func("eta").set("pieces", new String[][]{{"273.15", "413.15", "1.3799566804-0.021224019151*T^1+1.3604562827E-4*T^2-4.6454090319E-7*T^3+8.9042735735E-10*T^4-9.0790692686E-13*T^5+3.8457331488E-16*T^6"}, {"413.15", "553.75", "0.00401235783-2.10746715E-5*T^1+3.85772275E-8*T^2-2.39730284E-11*T^3"}});
model.material("mat1").propertyGroup("def").func().create("Cp", "Piecewise");
model.material("mat1").propertyGroup("def").func("Cp").set("funcname", "Cp");
model.material("mat1").propertyGroup("def").func("Cp").set("arg", "T");
model.material("mat1").propertyGroup("def").func("Cp") .set("extrap", "constant");
model.material("mat1").propertyGroup("def").func("Cp").set("pieces", new String[][]{{"273.15", "553.75", "12010.1471-80.4072879*T^1+0.309866854*T^2-5.38186884E-4*T^3+3.62536437E-7*T^4"}});
model.material("mat1").propertyGroup("def").func().create("rho", "Piecewise");
model.material("mat1").propertyGroup("def").func("rho").set("funcname", "rho");
model.material("mat1").propertyGroup("def").func("rho").set("arg", "T");
model.material("mat1").propertyGroup("def").func("rho").set("extrap", "constant");
model.material("mat1").propertyGroup("def").func("rho").set("pieces", new String[][]{{"273.15", "553.75", "838.466135+1.40050603*T^1-0.0030112376*T^2+3.71822313E-7*T^3"}});
model.material("mat1").propertyGroup("def").func().create("k", "Piecewise");
model.material("mat1").propertyGroup("def").func("k").set("funcname", "k");
model.material("mat1").propertyGroup("def").func("k").set("arg", "T");
model.material("mat1").propertyGroup("def").func("k").set("extrap", "constant");
model.material("mat1").propertyGroup("def").func("k").set("pieces", new String[][]{{"273.15", "553.75", "-0.869083936+0.00894880345*T^1-1.58366345E-5*T^2+7.97543259E-9*T^3"}});
model.material("mat1").propertyGroup("def").func().create("cs", "Interpolation");
model.material("mat1").propertyGroup("def").func("cs").set("sourcetype", "user");
model.material("mat1").propertyGroup("def").func("cs").set("source", "table");
model.material("mat1").propertyGroup("def").func("cs").set("funcname", "cs");
model.material("mat1").propertyGroup("def").func("cs").set("table", new String[][]{{"273", "1403"}, {"278", "1427"}, {"283", "1447"}, {"293", "1481"}, {"303", "1507"}, {"313", "1526"}, {"323", "1541"}, {"333", "1552"}, {"343", "1555"}, {"353", "1555"}, {"363", "1550"}, {"373", "1543"}});
model.material("mat1").propertyGroup("def").func("cs").set("interp", "piecewisecubic");
model.material("mat1").propertyGroup("def").func("cs").set("extrap", "const");
model.material("mat1").propertyGroup("def").addInput("temperature");
model.material("mat1").set("family", "water");


model.physics().create("spf", "LaminarFlow", "geom1");
model.physics("spf").feature().create("inl1", "Inlet", 1);
model.physics("spf").feature().create("out1", "Outlet", 1);
model.physics("spf").feature("wall1").set("BoundaryCondition", 1, "NoSlip");
model.physics("spf").feature("inl1").set("BoundaryCondition", 1, "LaminarInflow");
model.physics("spf").feature("inl1").set("LaminarInflowOption", 1, "Uav");
model.physics("spf").feature("inl1").set("Uav", 1, "0.002");
model.physics("spf").feature("inl1").set("Lentr", 1, "0.0005");
model.physics("spf").feature("inl1").set("ConstrainEndPointsToZero", 1, "1");

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

model.physics("spf").feature("inl1").selection().set(new int[]{2});
model.physics("spf").feature("out1").selection().set(new int[]{3});

model.mesh().create("mesh1", "geom1");
model.mesh("mesh1").feature().create("ftri1", "FreeTri");
model.mesh("mesh1").feature("size").set("table", "cfd");
model.mesh("mesh1").feature("size").set("hauto", "7"); //mesh_size
model.mesh("mesh1").run();

model.study().create("std1");
model.study("std1").feature().create("time", "Transient");
model.study("std1").feature("time").activate("spf", true);
model.study("std1").feature("time").set("tlist", "range(0,1e-6,1e-4)");

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("v1").set("control", "time");
model.sol("sol1").feature().create("t1", "Time");
model.sol("sol1").feature("t1").set("tlist", "range(0,1e-6,1e-4)");
model.sol("sol1").feature("t1").set("plot", "off");
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("atolglobalmethod", "scaled");
model.sol("sol1").feature("t1").set("atolglobal", 5.0E-4);
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", 6);
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", 6);
model.sol("sol1").feature("t1").feature().remove("fcDef");
model.sol("sol1").attach("std1");
model.sol("sol1").runAll();

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", new String[]{"spf.U"});
model.result("pg1").set("frametype", "spatial");
model.result("pg1").name("\u901f\u5ea6 (spf)");
model.result().create("pg2", 2);
model.result("pg2").set("data", "dset1");
model.result("pg2").feature().create("con1", "Contour");
model.result("pg2").feature("con1").set("expr", new String[]{"p"});
model.result("pg2").set("frametype", "spatial");
model.result("pg2").name("\u5727\u529b (spf)");
model.result("pg2").feature("con1").set("number", 40);
model.result("pg2").run();

model.result().export().create("img1", "Image2D");
model.result().export("img1").set("plotgroup", "pg2");
model.result().export("img1").set("imagetype", "png");
model.result().export("img1").set("bmpfilename", "/home/user/ajats2.png");
model.result().export("img1").run();

return model;

}
}

0 Replies Last Post 2014年7月1日 GMT-4 05:27
COMSOL Moderator

Hello Takumi Ono

Your Discussion has gone 30 days without a reply. If you still need help with COMSOL and have an on-subscription license, please visit our Support Center for help.

If you do not hold an on-subscription license, you may find an answer in another Discussion or in the Knowledge Base.

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.