Close this search box.

Run COMSOL Multiphysics Using an Input File From a Command Prompt

Introduction - COMSOL Java API

I did not realize this until recently, but you can create a text-file (to be more precise, a java-file) that contains COMSOL Multiphysics commands. You can then run that file from a command prompt/terminal.  If you feel like it you can even suppress the GUI. This is really cool, and perhaps even more powerful than the input file formats used by most other FE solvers. I will use this approach to improve how MCalibration interacts with COMSOL Multiphysics. This short article (and video) outlines how you can use the COMSOL Java API

Step 1. Save Model Template

The easiest way to create a COMSOL Java API file is to create a model using the Multiphysics GUI. Then, save the model as a java-file (see image  below). Note that the COMSOL model can use any material model, include PolyUMod material models.

Step 2. Modify the Java File

The created java file is easy to read and edit. You can read the COMSOL Multiphysics documentation to learn more about the Java API.

Step 3. Compile the COMSOL Java API File

Here is an example Windows bat-file for compiling a java-file to a class-file.

					set p=C:\Program Files\COMSOL\COMSOL56\Multiphysics\bin\win64
set f=test
echo ## compile the java file

Step 4. Run the Class File

Once you have a class file you can open it from within the COMSOL Multiphysics GUI, or you can run it from a command window. Here is an example Windows bat-file as an example.

					set p=C:\Program Files\COMSOL\COMSOL56\Multiphysics\bin\win64
set f=test
rem echo ## run comsol
rem "%p%\comsolbatch.exe" -inputfile %f%.class -nosave


See the following video for more info about how to use the Java API:


More to explore

Best Material Model for PC

This article examines different material models for polycarbonate (PC), and finds the most accurate model for FEA use.

Leave a Comment