Discussion Forum

Matlab script for effective modal mass extraction

Thread index  |  Previous thread  |  Next thread  |  Start a new discussion

RSS FeedRSS feed   |   Email notificationsTurn on email notifications   |   17 Replies   Last post: November 20, 2011 4:57am UTC
Lars Tiedemann

Lars Tiedemann

January 15, 2010 1:15pm UTC

Matlab script for effective modal mass extraction

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

Attachments:   effective_mass_analysis.m  

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Marc Jouan

Marc Jouan

January 15, 2010 4:26pm UTC in response to Lars Tiedemann

Re: Matlab script for effective modal mass extraction

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

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Lars Tiedemann

Lars Tiedemann

January 18, 2010 9:12am UTC in response to Marc Jouan

Re: Matlab script for effective modal mass extraction

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

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Marc Jouan

Marc Jouan

January 18, 2010 9:41am UTC in response to Lars Tiedemann

Re: Matlab script for effective modal mass extraction

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

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Ivar Kjelberg

Ivar Kjelberg
Moderator

January 18, 2010 4:41pm UTC in response to Marc Jouan

Re: Matlab script for effective modal mass extraction

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

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Marcin Hurkala

Marcin Hurkala

May 6, 2010 9:06am UTC in response to Lars Tiedemann

Re: Matlab script for effective modal mass extraction

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.

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Lars Tiedemann

Lars Tiedemann

May 6, 2010 9:17am UTC in response to Marcin Hurkala

Re: Matlab script for effective modal mass extraction

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.

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Marcin Hurkala

Marcin Hurkala

May 6, 2010 9:36am UTC in response to Lars Tiedemann

Re: Matlab script for effective modal mass extraction

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.

Attachments:   Script_tester.mph  

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Ivar Kjelberg

Ivar Kjelberg
Moderator

May 6, 2010 9:38am UTC in response to Marcin Hurkala

Re: Matlab script for effective modal mass extraction

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

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Marcin Hurkala

Marcin Hurkala

May 6, 2010 9:56am UTC in response to Ivar Kjelberg

Re: Matlab script for effective modal mass extraction


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

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Lars Tiedemann

Lars Tiedemann

May 6, 2010 11:50am UTC in response to Marcin Hurkala

Re: Matlab script for effective modal mass extraction

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

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Marcin Hurkala

Marcin Hurkala

May 6, 2010 12:40pm UTC in response to Lars Tiedemann

Re: Matlab script for effective modal mass extraction

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.

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Ivar Kjelberg

Ivar Kjelberg
Moderator

May 7, 2010 10:03am UTC in response to Lars Tiedemann

Re: Matlab script for effective modal mass extraction

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

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

dnh37

dnh37

June 21, 2011 8:26pm UTC in response to Ivar Kjelberg

Re: Matlab script for effective modal mass extraction

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

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

dnh37

dnh37

June 21, 2011 8:30pm UTC in response to dnh37

Re: Matlab script for effective modal mass extraction

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

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Lars Gregersen

Lars Gregersen
COMSOL Employee

June 22, 2011 2:52pm UTC in response to dnh37

Re: Matlab script for effective modal mass extraction


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

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Lars Tiedemann

Lars Tiedemann

July 11, 2011 7:39am UTC in response to dnh37

Re: Matlab script for effective modal mass extraction

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.

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

flute  acoustics

flute acoustics

November 20, 2011 4:57am UTC in response to Marcin Hurkala

Re: Matlab script for effective modal mass extraction

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!

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse


Rules and guidelines