Handling Geometry or Meshing Failures in MATLAB-COMSOL Model

Please login with a confirmed email address before reporting spam

Hi all,

I’m running a MATLAB-COMSOL model where I update my design variables using a command like:

% Set the variables nPoints = size(xy, 1); % Number of point pairs for i = 1:nPoints xi = xy(i,1); % x-coordinate yi = xy(i,2); % y-coordinate

model.param.set(sprintf('x%d', i), sprintf('%0.4f [mm]', xi));
model.param.set(sprintf('y%d', i), sprintf('%0.4f [mm]', yi));

end

However, in some cases, certain combinations of design variables lead to non-viable geometries. As a result, the model fails either during geometry generation or meshing, and I get an error when trying to evaluate:'

mphglobal(model, 'solid.LFcrit');

To handle this, I would like to check whether the geometry and mesh were successfully generated before calling mphglobal. If they weren’t, I want to skip that part so that MATLAB can continue iterating without crashing the whole optimization loop.

Is there a recommended way to check the status of geometry and mesh generation in COMSOL via the MATLAB API?

Any suggestions would be much appreciated!

Best regards, Mirhan


0 Replies Last Post 2025年4月17日 GMT+8 04:42
COMSOL Moderator

Hello Mirhan Özdemir

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.

Reply

Please read the discussion forum rules before posting.

Please log in to post a reply.

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.