Run COMSOL Multiphysics Using an Input File From a Command Prompt

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 do this.

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).

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 Java 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
"%p%\comsolcompile.exe" %f%.java
				
			

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

				
			

For more info see the following video:

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

More to explore

Leave a Comment