Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

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.

Matlab script for effective modal mass extraction

Please login with a confirmed email address before reporting spam

Hi everbody,

as posted frequently in this forum, COMSOL does not provide effective modal masses in eigenfrequency analysis for structural analysis. But since effective masses are a very convenient way to determine critical modes from less critical ones, and since this information is often required for documentation, I wrote a Matlab script that extracts the effective masses from an eigenfrequency solution and exports them to an Excel file.

This is how it works:
1. Copy the attached matlab script to your disk (preferably to a directory that is already in the Matlab include path, e.g. C:\Users\...\Documents\MATLAB on windows).
2. Run COMSOL and do the eigenfrequency analysis there.
3. Save your COMSOL eigenfrequency analysis to an .mph file of your choice.
4. Connect COMSOL to Matlab (you don't need to export the fem object to Matlab though).
5. In Matlab, execute the attached effective_mass_analysis.m script (open/run or if located in the Matlab workspace simply type 'effective_mass_analysis' in the command window).
6. The script asks you which .mph file to open, calculates the effective masses and saves them to a Microsoft Excel spreadsheet (you will be prompted where to save it).

In the Excel file there are four different sheets: 'Total Masses', 'Effective Masses', 'Mass Fraction' and 'Cumulative Mass Fraction'. These results resemble the standard output of other FEM software, such as Ansys that provide effective mass output by default.

Unfortunately, this script does not work for large models since the matrix size that Matlab can handle is limited and it may also fail when more than one application mode is used. I have cross-checked the results with only one reference case from Ansys, so there is no guarantee that the script works correctly with all models. Any comments and suggestions are greatly appreciated.

Cheers,
Lars


17 Replies Last Post 19.11.2011, 23:57 GMT-5

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 15.01.2010, 11:26 GMT-5
i have tried your file for a 3D model and strangely it give me 4 for the Number of independent variables. when i write 3 for k in your file ;it works could you explain this or do you have faced the same problem?
is it possible to explain it?
otherwise it seems to be a goo job so congratulation
PS: i use the structural mechanic module with matlab R 2009 a and comsol 35 a
i have tried your file for a 3D model and strangely it give me 4 for the Number of independent variables. when i write 3 for k in your file ;it works could you explain this or do you have faced the same problem? is it possible to explain it? otherwise it seems to be a goo job so congratulation PS: i use the structural mechanic module with matlab R 2009 a and comsol 35 a

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 18.01.2010, 04:12 GMT-5
Louvet,

The script extracts the number of indepent variables from the application mode fem.appl(1,i).dim . The structural mechanics module uses 4 independent variables: u, v, w, p , so 4 is correct. Of course, the p-column does not give you effective masses. But the script probably does not provide correct results if you manually change it to 3. So you should leave as is and just ignore the p-column.

The problem with this is: I have not yet found a way to link the entries in the mass matrix and result vector to the specific independent variables. If anyone knows how to do this (even with multiple application modes), I could limit the columns to u, v, w, since these are the only ones of interest.

Anyway, does anyone know if modal mass analysis is foreseen in a future release of the structural mechanics module?

Cheers,
Lars
Louvet, The script extracts the number of indepent variables from the application mode fem.appl(1,i).dim . The structural mechanics module uses 4 independent variables: u, v, w, p , so 4 is correct. Of course, the p-column does not give you effective masses. But the script probably does not provide correct results if you manually change it to 3. So you should leave as is and just ignore the p-column. The problem with this is: I have not yet found a way to link the entries in the mass matrix and result vector to the specific independent variables. If anyone knows how to do this (even with multiple application modes), I could limit the columns to u, v, w, since these are the only ones of interest. Anyway, does anyone know if modal mass analysis is foreseen in a future release of the structural mechanics module? Cheers, Lars

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 18.01.2010, 04:41 GMT-5
hi lars,
thank you for your reply
in the next comsol V 4.0 there will be a modal (ie frequency and temporal response with the mode)
it means that comsol will cope with a modal superposition method. To implement this method, i assume that comsol must normalise the eigenmode in a way that look like yours but i don't know if the information on the mass participation factors will be available. if you are interested, i have got a matlab script which implement this method. The following script is :

% Solves frequency response problems using modal decomposition method.
% for instance without damping for 6 modes :
% fem=femmodalfreq(fem,fem1,zeros(6,1),[10:1:100]);
% fem=freqmodalfreq(fem,fem1,zeros(6,1),[10:1:100]);
% Manipulate eigenvectors

fi=femold.sol.u;
[K,Force,M,N,D,E]=assemble(femold,'eigname','lambda');
fiMfi=fi'*E*fi;
% create scaled eigenmodes
sFac=diag(fiMfi);
for i=1:nbeigen
eigModes(:,i)=fi(:,i)./sqrt(sFac(i));
end

q=zeros(length(femold.sol.lambda),length(freq));

omegaEig=abs(imag(femold.sol.lambda));

i=sqrt(-1);
% Force is not frequency dependent
Force = assemble(fem,'out',{'L'}, 'const',{'freq_smsld', 0});


% calculate generalized coordinates
for ifreq=1:length(freq)
omega = freq(ifreq)*2*pi;
q(:,ifreq) = eigModes'*Force.*(1./...
(2.*dampRatio(:).*omega.*omegaEig(:).*i-omega.^2+omegaEig(:).^2));



end



% calculate new solution
u=eigModes*q ;
% u=eigModes(:,3)*q(3,:);

femout=fem;
femout.sol=femsol(u,'pname','freq','plist',freq);


this script assume that you have already created a fem structure in comsol . create a function with this script


i don't know if this script will help you with the mass participation factor but anyway it give you a way to normalise the eigenmode in a different way
hi lars, thank you for your reply in the next comsol V 4.0 there will be a modal (ie frequency and temporal response with the mode) it means that comsol will cope with a modal superposition method. To implement this method, i assume that comsol must normalise the eigenmode in a way that look like yours but i don't know if the information on the mass participation factors will be available. if you are interested, i have got a matlab script which implement this method. The following script is : % Solves frequency response problems using modal decomposition method. % for instance without damping for 6 modes : % fem=femmodalfreq(fem,fem1,zeros(6,1),[10:1:100]); % fem=freqmodalfreq(fem,fem1,zeros(6,1),[10:1:100]); % Manipulate eigenvectors fi=femold.sol.u; [K,Force,M,N,D,E]=assemble(femold,'eigname','lambda'); fiMfi=fi'*E*fi; % create scaled eigenmodes sFac=diag(fiMfi); for i=1:nbeigen eigModes(:,i)=fi(:,i)./sqrt(sFac(i)); end q=zeros(length(femold.sol.lambda),length(freq)); omegaEig=abs(imag(femold.sol.lambda)); i=sqrt(-1); % Force is not frequency dependent Force = assemble(fem,'out',{'L'}, 'const',{'freq_smsld', 0}); % calculate generalized coordinates for ifreq=1:length(freq) omega = freq(ifreq)*2*pi; q(:,ifreq) = eigModes'*Force.*(1./... (2.*dampRatio(:).*omega.*omegaEig(:).*i-omega.^2+omegaEig(:).^2)); end % calculate new solution u=eigModes*q ; % u=eigModes(:,3)*q(3,:); femout=fem; femout.sol=femsol(u,'pname','freq','plist',freq); this script assume that you have already created a fem structure in comsol . create a function with this script i don't know if this script will help you with the mass participation factor but anyway it give you a way to normalise the eigenmode in a different way

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 18.01.2010, 11:41 GMT-5
Hi everyone,

I have been fighting (yes it has been a gentle fight) with COMSOL for 3 years to get them add the effective mass, so I expect that it will come (once), your scripts are good for simple cases, that is alread very nice.

Unfortunately I'm running heavy models >500kDoF and I have found no way yet.

If each user insists by COMSOL on the importance of the effective mass for modal analysis, I'm sure they will implement it, as its rather straitght forward (once programmed inside COMSOL)

In any case thanks for pushing this issue to support ;)
Ivar
Hi everyone, I have been fighting (yes it has been a gentle fight) with COMSOL for 3 years to get them add the effective mass, so I expect that it will come (once), your scripts are good for simple cases, that is alread very nice. Unfortunately I'm running heavy models >500kDoF and I have found no way yet. If each user insists by COMSOL on the importance of the effective mass for modal analysis, I'm sure they will implement it, as its rather straitght forward (once programmed inside COMSOL) In any case thanks for pushing this issue to support ;) Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 06.05.2010, 05:06 GMT-4
Very new with using Matlab, but getting this bunch of errors when trying to use the script:

>> effective_mass_analysis.m
??? Error using ==> flgetsparse
Function "mxGetIr_700" is obsolete in file ".\compat32.cpp", line 264.
(64-bit mex files using sparse matrices must be rebuilt with the "-largeArrayDims"
option. See the R2006b release notes for more details.)

Error in ==> flexchprop>l_flgetsparse at 89
vao=flgetsparse(tbl.getM,tbl.getN,tbl.getNnz,...

Error in ==> flexchprop at 30
[varargout{1:nout}] = l_flgetsparse(outprop, outstr);

Error in ==> solassign at 38
vao{k}=flexchprop('flgetsparse',outprop,outstr);

Error in ==> femsolver at 406
vao = solassign(fem,sol,outprop,out);

Error in ==> assemble at 60
varargout = femsolver(mfilename,'Assemble',fem,varargin{:});

Error in ==> effective_mass_analysis at 55
M = assemble(fem,'out',{'E'},'eigname','lambda');

I checked the script with very simple model (1x1x1m cube made of aluminium and calculated 10 first eigenfrequencies), but it seems that I get nowhere.
Very new with using Matlab, but getting this bunch of errors when trying to use the script: >> effective_mass_analysis.m ??? Error using ==> flgetsparse Function "mxGetIr_700" is obsolete in file ".\compat32.cpp", line 264. (64-bit mex files using sparse matrices must be rebuilt with the "-largeArrayDims" option. See the R2006b release notes for more details.) Error in ==> flexchprop>l_flgetsparse at 89 vao=flgetsparse(tbl.getM,tbl.getN,tbl.getNnz,... Error in ==> flexchprop at 30 [varargout{1:nout}] = l_flgetsparse(outprop, outstr); Error in ==> solassign at 38 vao{k}=flexchprop('flgetsparse',outprop,outstr); Error in ==> femsolver at 406 vao = solassign(fem,sol,outprop,out); Error in ==> assemble at 60 varargout = femsolver(mfilename,'Assemble',fem,varargin{:}); Error in ==> effective_mass_analysis at 55 M = assemble(fem,'out',{'E'},'eigname','lambda'); I checked the script with very simple model (1x1x1m cube made of aluminium and calculated 10 first eigenfrequencies), but it seems that I get nowhere.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 06.05.2010, 05:17 GMT-4
Marcin,

To be honest, I have no idea what these errors mean. Perhaps you could post your mph file here and give a step-by-step procedure of what you did, so I can try it myself.
Marcin, To be honest, I have no idea what these errors mean. Perhaps you could post your mph file here and give a step-by-step procedure of what you did, so I can try it myself.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 06.05.2010, 05:36 GMT-4
Sure, here's the whole process:
1) Create a 1x1x1m cube in Structural Mechanics Module - Solid, Stress-Strain (3D)
2) Set temperature to 20ºC, fix all edges in x,y and z-directions, and set material to aluminium
3) Solve the problem
4) Run the script, select the solved model as target
5) Get an error

Thanks for your time.
Sure, here's the whole process: 1) Create a 1x1x1m cube in Structural Mechanics Module - Solid, Stress-Strain (3D) 2) Set temperature to 20ºC, fix all edges in x,y and z-directions, and set material to aluminium 3) Solve the problem 4) Run the script, select the solved model as target 5) Get an error Thanks for your time.


Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 06.05.2010, 05:38 GMT-4
Hi

from my understanding there is a problem with the matlab <-> Comsol versions and mixed 32 and/or 64 bit mode, that is what I beleive is to be understood from the first message, then it cacades down

Sorry cannot do more just like that

Ivar
Hi from my understanding there is a problem with the matlab Comsol versions and mixed 32 and/or 64 bit mode, that is what I beleive is to be understood from the first message, then it cacades down Sorry cannot do more just like that Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 06.05.2010, 05:56 GMT-4

Hi

from my understanding there is a problem with the matlab <-> Comsol versions and mixed 32 and/or 64 bit mode, that is what I beleive is to be understood from the first message, then it cacades down

Sorry cannot do more just like that

Ivar


That would the the most reasonable reason, but my Matlab claims to be 64-bit version (Version 7.10.0.499 (R2010a), 64-bit (win64)), and I'm using comsol64.exe executable as well, so I _should_ be using 64-bit versions of both, right?

BR,
Marcin Hurkala
[QUOTE] Hi from my understanding there is a problem with the matlab Comsol versions and mixed 32 and/or 64 bit mode, that is what I beleive is to be understood from the first message, then it cacades down Sorry cannot do more just like that Ivar [/QUOTE] That would the the most reasonable reason, but my Matlab claims to be 64-bit version (Version 7.10.0.499 (R2010a), 64-bit (win64)), and I'm using comsol64.exe executable as well, so I _should_ be using 64-bit versions of both, right? BR, Marcin Hurkala

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 06.05.2010, 07:50 GMT-4
Marcin,

I cannot reproduce the error messages you posted. Using the script on your model produced some other error messages though, that I address to the number of independent variables (4 for smsld, see previous post in this thread by Louvet). Changing the application mode to sld (3 independent variables) seems to solve the problem. However, I am not 100% sure if the result is correct, but the script runs without errors. Attached you find the slightly modified model file and the results output file.

Cheers,
Lars
Marcin, I cannot reproduce the error messages you posted. Using the script on your model produced some other error messages though, that I address to the number of independent variables (4 for smsld, see previous post in this thread by Louvet). Changing the application mode to sld (3 independent variables) seems to solve the problem. However, I am not 100% sure if the result is correct, but the script runs without errors. Attached you find the slightly modified model file and the results output file. Cheers, Lars


Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 06.05.2010, 08:40 GMT-4
For some reason I'm getting the same error with your updated version of the test model as well. Thanks for trying to help, but I think I'll try to take a different approach to my problem.
For some reason I'm getting the same error with your updated version of the test model as well. Thanks for trying to help, but I think I'll try to take a different approach to my problem.

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 07.05.2010, 06:03 GMT-4
Hi again

I have made s simple test, you make two identical model in sld (u,v,w) and in in smsld (u,v,w,p) (both eigenfrequency) and run them through the script, I see the same dimension for "fem.sol.u" the solution here so I beleive that even in smsld mode "p" is not solved for and you should use a dimension of "3" for "k" on the smlsd model and then it works.

When I compare a simple steel flex beam 1x0.1x0.01 m in fixed-free mode I get < 1E-6 difference from the smsld and the sld models for all items of the effective mass matrices that you develop in yourmatlab script.

So obviosly we have a correct interpetation issue here on the way COMSOL stores the solution w.r.t. the different variables u,v,w and in particular "p".

Finally "p" is related with pressure and probably then also forces, but as most external forces are ignored in eigenfrequency mode (except if you load the model fist in static, save it and rerun from stored solution) it could be that "fe.sol.u" is not populated for "p"

Could be worth a mail to "support" to get it cleared out, hope only this will be implemented in V4 soon

I have found some more info, but I'm still not sure why the number of depedent variables is not 4 in the development of "fem.sol.u" for "smsld" (but in V4 i noted that "p" vas treated differently from u,v,w, so perhaps not always solved for). There are the commandes flngdof(fem) to get the number of dof (lines of fem.sol.u) ans solsize(fem.sol) gives the number of columns, but I have nothing more

Any comments ?

have fun Comsoling
Ivar
Hi again I have made s simple test, you make two identical model in sld (u,v,w) and in in smsld (u,v,w,p) (both eigenfrequency) and run them through the script, I see the same dimension for "fem.sol.u" the solution here so I beleive that even in smsld mode "p" is not solved for and you should use a dimension of "3" for "k" on the smlsd model and then it works. When I compare a simple steel flex beam 1x0.1x0.01 m in fixed-free mode I get < 1E-6 difference from the smsld and the sld models for all items of the effective mass matrices that you develop in yourmatlab script. So obviosly we have a correct interpetation issue here on the way COMSOL stores the solution w.r.t. the different variables u,v,w and in particular "p". Finally "p" is related with pressure and probably then also forces, but as most external forces are ignored in eigenfrequency mode (except if you load the model fist in static, save it and rerun from stored solution) it could be that "fe.sol.u" is not populated for "p" Could be worth a mail to "support" to get it cleared out, hope only this will be implemented in V4 soon I have found some more info, but I'm still not sure why the number of depedent variables is not 4 in the development of "fem.sol.u" for "smsld" (but in V4 i noted that "p" vas treated differently from u,v,w, so perhaps not always solved for). There are the commandes flngdof(fem) to get the number of dof (lines of fem.sol.u) ans solsize(fem.sol) gives the number of columns, but I have nothing more Any comments ? have fun Comsoling Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 21.06.2011, 16:26 GMT-4
Hi,

This doesn't seem to run when I try it with my v4.1 installation...? I put the .m file in my MATLAB path, make an eigenfreq simulation and save it as .mph (also in MATLAB path), then run the .m file in MATLAB and get the following error:

=========
??? Undefined function or method 'flload' for input arguments of type 'char'.

Error in ==> effective_mass_analysis at 32
flload([mph_path mph_file]);
=========

I checked the documentation for a command called flload and didn't find it -- I assume this is an old command that has been superseded by something else? Anyone that's not a newbie like me willing to get this script working with v4.1?

I also made sure the .mph file had no spaces in case that was the problem. I am using MATLAB 2010
Hi, This doesn't seem to run when I try it with my v4.1 installation...? I put the .m file in my MATLAB path, make an eigenfreq simulation and save it as .mph (also in MATLAB path), then run the .m file in MATLAB and get the following error: ========= ??? Undefined function or method 'flload' for input arguments of type 'char'. Error in ==> effective_mass_analysis at 32 flload([mph_path mph_file]); ========= I checked the documentation for a command called flload and didn't find it -- I assume this is an old command that has been superseded by something else? Anyone that's not a newbie like me willing to get this script working with v4.1? I also made sure the .mph file had no spaces in case that was the problem. I am using MATLAB 2010

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 21.06.2011, 16:30 GMT-4
Also, the original poster notes: " this script does not work for large models". Not sure the limit, but the filesize I am trying is 20MB
Also, the original poster notes: " this script does not work for large models". Not sure the limit, but the filesize I am trying is 20MB

Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 22.06.2011, 10:52 GMT-4

This doesn't seem to run when I try it with my v4.1 installation...? I put the .m file in my MATLAB path, make an


No, the script only works with Comsol 3.5a.


Lars Gregersen
Comsol Denmark
[QUOTE] This doesn't seem to run when I try it with my v4.1 installation...? I put the .m file in my MATLAB path, make an [/QUOTE] No, the script only works with Comsol 3.5a. Lars Gregersen Comsol Denmark

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 11.07.2011, 03:39 GMT-4
Comsol V4.x supports modal mass extraction, so you don't need the Matlab workaround presented here anymore. Though it's not easy to find in the documentation, Comsol 4.x scales the Eigenvalue solution vectors to the mass matrix. In effect, you have new dependent variables: the participation factors for each mode. With these, you can deduce the effective modal masses and effective mass fractions.
Comsol V4.x supports modal mass extraction, so you don't need the Matlab workaround presented here anymore. Though it's not easy to find in the documentation, Comsol 4.x scales the Eigenvalue solution vectors to the mass matrix. In effect, you have new dependent variables: the participation factors for each mode. With these, you can deduce the effective modal masses and effective mass fractions.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 19.11.2011, 23:57 GMT-5
Hello anyone!
I also have the problems when I use assemble syntax.
the code are:

clear fem
fem.geom = circ2;
fem.mesh = meshinit(fem);
fem.shape = 2;
fem.equ.c = 1; fem.equ.f = 1;
fem.bnd.h = 1;
fem.xmesh = meshextend(fem);
[K,L,M,N] = assemble(fem);
n = size(N,1);
%%%which are from the Reference Guide of command on Page33
the err are :
Error using flgetsparse
Function "mxGetIr_700" is obsolete.
(64-bit mex files using sparse matrices must be rebuilt with the "-largeArrayDims" option. See the
R2006b release notes for more details.)

Error in flexchprop>l_flgetsparse (line 89)
vao=flgetsparse(tbl.getM,tbl.getN,tbl.getNnz,...

Error in flexchprop (line 30)
[varargout{1:nout}] = l_flgetsparse(outprop, outstr);

Error in solassign (line 38)
vao{k}=flexchprop('flgetsparse',outprop,outstr);

Error in femsolver (line 406)
vao = solassign(fem,sol,outprop,out);

Error in assemble (line 60)
varargout = femsolver(mfilename,'Assemble',fem,varargin{:});

Error in tess (line 9)
[K,L,M,N] = assemble(fem);
Thank you!
Hello anyone! I also have the problems when I use assemble syntax. the code are: clear fem fem.geom = circ2; fem.mesh = meshinit(fem); fem.shape = 2; fem.equ.c = 1; fem.equ.f = 1; fem.bnd.h = 1; fem.xmesh = meshextend(fem); [K,L,M,N] = assemble(fem); n = size(N,1); %%%which are from the Reference Guide of command on Page33 the err are : Error using flgetsparse Function "mxGetIr_700" is obsolete. (64-bit mex files using sparse matrices must be rebuilt with the "-largeArrayDims" option. See the R2006b release notes for more details.) Error in flexchprop>l_flgetsparse (line 89) vao=flgetsparse(tbl.getM,tbl.getN,tbl.getNnz,... Error in flexchprop (line 30) [varargout{1:nout}] = l_flgetsparse(outprop, outstr); Error in solassign (line 38) vao{k}=flexchprop('flgetsparse',outprop,outstr); Error in femsolver (line 406) vao = solassign(fem,sol,outprop,out); Error in assemble (line 60) varargout = femsolver(mfilename,'Assemble',fem,varargin{:}); Error in tess (line 9) [K,L,M,N] = assemble(fem); Thank you!

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.