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.
querying fem structure components
Posted 24 sept. 2009, 14:54 UTC−4 8 Replies
Please login with a confirmed email address before reporting spam
I am just getting into scripting and I have a pretty basic question which I couldn't resolve looking at the manuals (maybe I overlooked the relevant section).
Once a fem structure is defined in a Matlab m file, how do I later query its components of interest? What is the right syntax and/or appropriate functions for doing that?
For example, having defined constants as
fem.const = {'Tm','0[degC]', ...
'dT','0.1[K]', ...
'ld','334[J/g]', ...
'Cp_ice','2.108[kJ/kg/K ]'};
how do I later access the numerical value of, say, Tm? I tried obvious things like myvalue=fem.const.Tm which didn't work. Similarly, assuming I can query this constant, how should I extract or get rid of its units and work with only the numeric value? Is there a COMSOL scripting specific method for doing this or should I use usual Matlab's string manipulation functions...
Thanks much,
Ozgur
Please login with a confirmed email address before reporting spam
To access the numerical value of a constant at the command prompt I have used this line;
Tm = str2double(fem.const{find(strcmp(fem.const,'Tm'))+1});
Now if your value contains units I'm not aware of any command to handle this at matlab command prompt. I've simply avoided using units when scripting.
Cheers
Lars Ottar Kvale
Please login with a confirmed email address before reporting spam
thank you for your response. I also heard from COMSOL support with the following suggestion which is very similar to your approach, FYI.
postglobaleval can be used (after model is updated with meshextend)
fem.xmesh = meshextend(fem);
.
.
Tm = postglobaleval(fem,{'Tm'});
Cheers,
Ozgur
Please login with a confirmed email address before reporting spam
for a slightly different case I have found an expression too, see the second last (of today) reply to Noemi' Petra's demand : "exporting data from the boundaries",
Use the search field, its the quickest to get there try the keyword strmatch
By the way the "Advanced Search" feature is quite nice to scan the discussions, and to find relevant data, there start to be quite a lot of knowledge in here
Good luck
Ivar
Please login with a confirmed email address before reporting spam
I found that the postglobaleval method I quoted previously in this thread works only after the solution is evaluated, so I reverted back to parsing the values of interest directly from the fem.const structure using Matlab functions.
For your reference, I am including below a little function I wrote that trims the units and extracts the numerical value of the constant of interest.
-- In the Script file:
.
.
fem.const = {'Tm','0[degC]', ...
'dT','0.1[K]', ...
'ld','334[J/g]'};
.
.
% This is the function call to evaluate the numerical value of constant of interest from fem.const
constval=numconst('dT',fem.const)
.
.
-- and here is the function m file numconst.m
function strval=numconst(whichconst,femc)
mystr=(femc{find(strcmp(femc,whichconst))+1}); % find the string
% check if there is a bracket indicative of units
if isempty(strfind(mystr,'['))
strval=str2double(mystr); % no bracket found, convert to number directly
else
strval=str2double(mystr(1:strfind(mystr,'[')-1)); % trim the unit before conversion
% Note there is no unit conversion done here - must ensure that constant
% was already provided in the base units, or extend the function to detect
% units and carry out conversions
end
Please login with a confirmed email address before reporting spam
I have a similar question.
However, I'd like to access the value of constant when it is specified as an expression dependent on other constants.
For instance:
fem.const = {'you','60', ...
'me','sqrt(phi)};
How to get value of me instead of expression?
Thanks a lot for your help
Sorry, I already got it - postmax(fem,'me')
Please login with a confirmed email address before reporting spam
Interesting post. Do you guys have any recommendations for my very similar problem?
www.comsol.com/community/forums/general/thread/1343/
Regards,
Tom
Please login with a confirmed email address before reporting spam
www.comsol.com/community/forums/general/thread/2069/
regards
Thomas
Please login with a confirmed email address before reporting spam
www.comsol.com/community/forums/general/thread/2069/
regards
Thomas
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.
Suggested Content
- KNOWLEDGE BASE Segregated solver steps do not involve all components
- BLOG Modeling Speaker Drivers: Which Coupling Feature to Use
- KNOWLEDGE BASE Solving Wave-Type Problems with Step Changes in the Loads
- FORUM querying fem structure components
- KNOWLEDGE BASE Matrix Has Zero on Diagonal
