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 COMSOL Java class file in batch mode

Please login with a confirmed email address before reporting spam

I'm writing a COMSOL model file using the Java COMSOL API, and I'm encountering a problem with running the files in batch mode. In particular, when I put in the code to import a CAD file:

...
model.geom("geom1").create("imp1", "Import");
model.geom("geom1").feature("imp1").set("filename", "C:\Path\to\File.sldprt");
model.geom("geom1").runPre("fin");
...

When I try to run the model in batch mode using

comsolbatch -inputfile <file.class> -outputfile <output.mph> -batchlog <log.txt>

it doesn't run successfully. The resulting model file is empty and the log file contains the following text:

/******************/
/*****Error********/
/******************/
access denied ("java.io.FilePermission" "PATH\testpart.SLDPRT" "read")
Saving model: PATH\importmodel_Model.mph
Save time: 0 s.
Total time: 4 s.

(where I have replaced my actual path with a placeholder). I don't understand why I am getting this error. It's even stranger considering that I can import a file and create a COMSOL model with no problem in the GUI, but then even when I record a Java macro based on that successful model, the code will encounter the same error when I try to compile and run it in batch mode.

3 Replies Last Post 3 ago 2016, 08:36 GMT-4
COMSOL Moderator

Hello Christopher Lioi

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.


Please login with a confirmed email address before reporting spam

Posted: 9 years ago 23 mag 2016, 03:49 GMT-4
I have exactly the same problem.... but in my case the java.io.filepermission displays the error when I try to export the results from the model into a .txt file (running from batch mode a .class file)

My .java file reads:
[...]
model.batch.run();

model.result().numerical("av1").setResult();
model.result().export("plot1").set("filename", "/PATH/ExportFileName.txt");
model.result().export("plot1").run();

return model;
}

The file is compiled with no problem but, when I try to run the model from shell (using comsol batch -inputfile M.class -outputfile Mo.mph -batchlog L.log) the .log file contains this error:

/******************/
/*****Error********/
/******************/
access denied ("java.io.FilePermission" "/PATH/ExportFileName.txt" "write")
Saving model: Mo.mph

If somebody knows how to deal with that please share.
I have exactly the same problem.... but in my case the java.io.filepermission displays the error when I try to export the results from the model into a .txt file (running from batch mode a .class file) My .java file reads: [...] model.batch.run(); model.result().numerical("av1").setResult(); model.result().export("plot1").set("filename", "/PATH/ExportFileName.txt"); model.result().export("plot1").run(); return model; } The file is compiled with no problem but, when I try to run the model from shell (using comsol batch -inputfile M.class -outputfile Mo.mph -batchlog L.log) the .log file contains this error: /******************/ /*****Error********/ /******************/ access denied ("java.io.FilePermission" "/PATH/ExportFileName.txt" "write") Saving model: Mo.mph If somebody knows how to deal with that please share.

Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 26 mag 2016, 03:34 GMT-4
Hi

I'm not sure if this suggestion fixes your problem, but you shouldn't use single back-slashes in Java code. Use double back-slashes instead.

--
Lars Gregersen
Comsol Denmark
Hi I'm not sure if this suggestion fixes your problem, but you shouldn't use single back-slashes in Java code. Use double back-slashes instead. -- Lars Gregersen Comsol Denmark

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 3 ago 2016, 08:36 GMT-4
It looks like the necessary permissions have not been granted to the comsolbatch executable. In the GUI of my comsol installation (on Linux) the relevant settings are found in "Options -> Preferences -> Security". Here "File system access" must be set to "All files".

I am not sure how to change these settings for the comsolbatch executable. Maybe come comsol people can enlighten us? :)
It looks like the necessary permissions have not been granted to the comsolbatch executable. In the GUI of my comsol installation (on Linux) the relevant settings are found in "Options -> Preferences -> Security". Here "File system access" must be set to "All files". I am not sure how to change these settings for the comsolbatch executable. Maybe come comsol people can enlighten us? :)

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.