Run Comsol headless
For more details, read the complete section about Structural mesh generator.
Prerequisites
Caution
You need to specify the path for the Comsol server installation and the Matlab installation in mesher.py (located in ../myAceplaque/mesher.py).
matlabPath = '/Applications/MATLAB_R2023b.app/bin/matlab'
comsolPath = '/Applications/COMSOL61/Multiphysics/bin/comsol'
Start at least once the Comsol with Matlab environment and register the server. Ensure Matlab can connect to the Comsol server and run Comsol scripts.
Run Comsol headless using Matlab script
The create_mph_mesh() function automatically assembles a script containing the path and mesh desired properties and then runs the Comsol script using Matlab. In particular:
def create_mph_mesh(self, block_height_multiplier, hmax, hmin):
self.save_wall_mesh()
self.prepare_matlab_script(block_height_multiplier, hmax, hmin)
comsol_command = [comsolPath, 'mphserver', '-port', '2036']
subprocess.Popen(comsol_command)
script_path = os.path.join(self.outPath, 'script.m')
# Construct the MATLAB command
matlab_command = [
matlabPath,
'-batch',
f"run('{script_path}')" # Run the script
]
subprocess.run(matlab_command, check=True)
Where save_wall_mesh() ensures that the previously defined mesh (check, scaled, etc. see myAceplaque docs) is saved as an STL file named vessel_wall.stl. It represents the entire wall structural (surface) mesh.
The comsol_command is a bash command that starts the Comsol server:
/Applications/COMSOL61/Multiphysics/bin/comsol mphserver -port 2036
While the matlab_command runs the Matlab scripts headless:
/Applications/MATLAB_R2023b.app/bin/matlab -batch /path/to/script.m
Matlab variable assembling
A Matlab script.m is automatically created by create_matlab_script() as follows:
addpath('{common_path}');
modelPath = '{model_path}';
blockHeightMultiplier = {block_height_multiplier};
hmax = '{hmax}';
hmin = '{hmin}';
% Set the STL file path
stl_path = '{stl_path}';
% Call the function defined in Untitled2.m
createMPHmesh(modelPath, stl_path, blockHeightMultiplier, hmax, hmin);
% Optionally, remove the path afterward to keep the environment clean
rmpath('{common_path}');
This is run automatically by calling the createMPHmesh.m script, which generates the mesh.
Comsol script
Full script here.
Logic:
Load the mesh from the STL (full structural wall)
Create the block
Boolean intersect
Generate the mesh with assigned sizes
Export the
mesh.mphtxtfile