Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

Replace NaN values with zero in COMSOL

Please login with a confirmed email address before reporting spam

Hello,

I use COMSOL to obtain eigenfrequencies of a 3D crystal with a point defect. I am a beginner with COMSOL.

For each eigenfrequency, I have a mode with a certain mode shape (amplitude). I only consider out-of-plane motion, i.e. w(x, y).

The COMSOL solution (the amplitude w) looks reasonable (from a physics point of view), but contains small numerical artefacts.

This is problematic as I want to calculate second-order derivates: d(d(w, x), x). In particular, evaluating this derivative yiels several NaN values.

My current solution is to export the data to Python, and process it there. I evaluate the derivative on a pretty large grid (5000x5000), so exporting all this data is cumbersome.

I have two ideas where I appreciate your input: Does COMSOL allow to replace NaN values with zeros without using a third-party program? I'm aware that the isnan() operator exists, but unsure if it suits the above purpose.

If not: What's the fastest way to export data from COMSOL (i.e. which program should I use)? I'm aware that links to Matlab and other languages exist, but wonder if they are faster.

Thanks


1 Reply Last Post Feb 7, 2024, 11:25 a.m. EST
Magnus Ringh COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 9 months ago Feb 7, 2024, 11:25 a.m. EST

Hi Leo,

You should be able to replace NaN values with zeros using an expression like:

if(isnan(d(d(w,x),x)),0,(d(d(w,x),x)))

An easier syntax for the second space derivative would be wxx.

A standard way to export data is to use the features under Results>Export to export the data to a text file, for example.

Best regards,

Magnus

Hi Leo, You should be able to replace NaN values with zeros using an expression like: `if(isnan(d(d(w,x),x)),0,(d(d(w,x),x)))` An easier syntax for the second space derivative would be `wxx`. A standard way to export data is to use the features under **Results>Export** to export the data to a text file, for example. Best regards, Magnus

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.