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.

File access using Java API in batch mode

Please login with a confirmed email address before reporting spam

Hi,

I am currently experimenting with Java API for using COMSOL. I have discovered that I have a problem with external files when using comsolbatch.

The following code (see bottom of post) is for a simple model which opens a basic geometry from the file "SimpleSphere.mphbin" which is located in my model working directory D:\WK. If I compile this to a .class file and open this in the COMSOL interface the model works as expected. However if I open this in batch mode I get the error message below. However if I copy the the file "SimpleSphere.mphbin" to the file location of comsolbatch.exe then the .class file runs with no errors in batch mode.

I believe that COMSOL should be able to locate the file, since I have specified the model working directory with the line model.modelPath("D:\WK");

I also believe that there should be no problem with COMSOL security settings since I have unchecked "Enforce security restrictions".

Please could somebody knowlegable about this offer their opinion. You can assume that I don't know much about java programming.

Kind regards

< error message >


COMSOL 5.1.0.136 progress output file


Mon Oct 22 17:02:40 KST 2018 COMSOL 5.1 (Build: 136) starting in batch mode Running: D:\WK\Test_01.class

/******************/ /*****Error********/ /******************/ access denied ("java.io.FilePermission" "D:\WK\SimpleSphere.mphbin" "read") Saving model: D:\WK\Test_01_out_Model.mph Save time: 1 s. Total time: 4 s.

< end error message >

{ /* * Test_01.java */

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

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

model.modelPath("D:\\WK");

model.label("Test_01.mph");

model.comments("Untitled\n\n");

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

model.file().clear();

model.geom().create("geom1", 3);

model.mesh().create("mesh1", "geom1");

model.geom("geom1").create("imp1", "Import");
model.geom("geom1").feature("imp1").set("filename", "SimpleSphere.mphbin");
model.geom("geom1").feature("imp1").set("type", "native");
model.geom("geom1").feature("imp1").importData();

model.mesh("mesh1").run();

return model;

}

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

} }


0 Replies Last Post 2018年10月22日 GMT-4 04:33
COMSOL Moderator

Hello Liam Kelly

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.