COMSOL Multiphysics¶
Introduction¶
COMSOL is a powerful environment for modelling and solving various engineering and scientific problems based on partial differential equations. COMSOL is designed to solve coupled or multiphysics phenomena. For many standard engineering problems, COMSOL provides add-on products (modules) such as electrical, mechanical, fluid flow, and chemical applications.
COMSOL also allows an interface support for equation-based modelling of partial differential equations.
Execution¶
There are two types of license:
-
Non commercial or so called EDU variant, which can be used for research and educational purposes.
-
Commercial or so called COM variant, which can used also for commercial activities. COM variant has only subset of features compared to the EDU variant available. More about licensing here.
By default, the EDU variant is loaded. If you needs other version or variant, load the particular version. To obtain the list of available versions, use:
$ ml av COMSOL
To prepare COMSOL jobs in the interactive mode, we recommend using COMSOL on the compute nodes.
Note
To run the COMSOL Desktop GUI on Windows, we recommend using the Virtual Network Computing (VNC).
Example for Karolina:
$srun --account=PROJECT_ID --partition=qcpu --nodes=1 --ntasks=128 --cpus-per-task=1 --x11
$ ml av COMSOL
------------------------------ /apps/modules/phys -----------------------------
COMSOL/5.2.0-COM COMSOL/5.2.0-EDU (D)
$ ml COMSOL/5.2.0-EDU
$ comsol -3drend sw
- If you receive errors at startup, for example, of the following type:
FL3D: error at line 814 in file fl3dglcontext_x11common.c:
PBuffers are not supported by the system.
FL3D: error at line 235 in file fl3dglcontext_x11common.c:
assert: x11Handle
you need to run COMSOL with additional parameters:
$ comsol -3drend sw
To run COMSOL in batch mode without the COMSOL Desktop GUI environment,
utilize the following (comsol.slurm
) job script and execute it via the salloc
command:
#!/bin/bash
#SBATCH --nodes=3
#SBATCH --ntasks-per-node=128
#SBATCH --cpus-per-task=1
#SBATCH --partition=qcpu
#SBATCH --job-name=JOB_NAME
#SBATCH --account=PROJECT_ID
cd /scratch/project/PROJECT_ID/ || exit
echo Time is `date`
echo Directory is `pwd`
echo '**SLURM_JOB_NODELIST***START*******'
scontrol show hostname $SLURM_JOB_NODELIST
echo '**SLURM_JOB_NODELIST***END*********'
# Assign the number of tasks
ntask=$(scontrol show hostname $SLURM_JOB_NODELIST | wc -l)
# Load COMSOL module
ml COMSOL/5.2.0-EDU
# Run COMSOL with SLURM options
comsol -3drend sw -nn ${ntask} batch -configuration /tmp \
–mpiarg –rmk –mpiarg slurm \
-tmpdir /scratch/project/PROJECT_ID/ \
-inputfile name_input_f.mph \
-outputfile name_output_f.mph \
-batchlog name_log_f.log
A working directory has to be created before sending the (comsol.slurm
) job script into the queue.
The input file (name_input_f.mph) has to be in the working directory
or a full path to the input file has to be specified.
The appropriate path to the temp directory of the job has to be set by the -tmpdir
command option.
Starting a COMSOL Server¶
Starting a COMSOL server on a compute node and then connecting to it through a COMSOL Desktop GUI environment is a convenient way of running calculations from GUI. To do so, you first need to submit a job with which you'll start the COMSOL server, for example:
Note
You may be prompted to provide username and password. These can be different from your IT4Innovations credentials, and will be used during the authentication when trying to connect to the server from GUI.
$ salloc --account=PROJECT_ID --partition=qcpu_exp --nodes=1 --ntasks=36 --cpus-per-task=1
salloc: Granted job allocation 694746
salloc: Waiting for resource configuration
salloc: Nodes cn58 are ready for job
$ ml COMSOL/5.2.0-COM
$ comsol server
COMSOL 5.2 (Build: 166) Multiphysics Server started listening on port 2036
Use the console command 'close' to exit the program
After that, start your COMSOL Desktop GUI session and fill required information under File -> Client Server -> Connect to Server
, where server will be the node where COMSOL server is running. Once you are done, your computational tasks will be offloaded to the COMSOL server.
LiveLink for MATLAB¶
COMSOL is a software package for the numerical solution of partial differential equations. LiveLink for MATLAB allows connection to the COMSOL API (Application Programming Interface) with the benefits of the programming language and computing environment of MATLAB.
LiveLink for MATLAB is available in both EDU and COM variant of the COMSOL release. On the clusters there is 1 commercial (COM) and 5 educational (EDU) licenses of LiveLink for MATLAB (see the ISV Licenses). The following example shows how to start COMSOL model from MATLAB via LiveLink in the interactive mode.
salloc --account=PROJECT_ID --partition=qcpu_exp --nodes=1 --ntasks=128 --cpus-per-task=1 --x11
$ ml <matlab_module> and <comsol_module>
$ comsol -3drend sw server MATLAB
On the first start of the LiveLink for MATLAB (client-MATLAB/server-COMSOL connection), the login and password is requested; this information is not requested again.
To run LiveLink for MATLAB in batch mode with (comsol_matlab.slurm
) job script,
you can utilize/modify the following script and execute it via the sbatch
command.
#!/bin/bash
#SBATCH --nodes=3
#SBATCH --ntasks-per-node=128
#SBATCH --cpus-per-task=1
#SBATCH --partition=qcpu
#SBATCH --job-name=JOB_NAME
#SBATCH --account=PROJECT_ID
cd /scratch/project/PROJECT_ID || exit
echo Time is `date`
echo Directory is `pwd`
echo '**SLURM_JOB_NODELIST***START*******'
scontrol show hostname $SLURM_JOB_NODELIST
echo '**SLURM_JOB_NODELIST***END*********'
# Assign the number of tasks
ntask=$(scontrol show hostname $SLURM_JOB_NODELIST | wc -l)
# Load modules
ml <matlab_module> and <comsol_module>
# Run with Slurm options
comsol -3drend sw -nn ${ntask} server -configuration /tmp -mpiarg -rmk -mpiarg slurm -tmpdir /scratch/project/PROJECT_ID &
cd $EBROOTCOMSOL/mli
matlab -nodesktop -nosplash -r "mphstart; addpath /scratch/project/PROJECT_ID; test_job"
This example shows how to run LiveLink for MATLAB with the following configuration:
3 nodes and 128 cores per node. A working directory has to be created
before submitting (comsol_matlab.slurm
) job script into the queue.
The input file (test_job.m
) has to be in the working directory
or a full path to the input file has to be specified.
The MATLAB command option (-r ”mphstart”
) created a connection with a COMSOL server using the default port number.