Including operators and expressions in a multiphysics simulation is easier than you think.
Posted: 8 months ago by: Linus Andersson, COMSOL Employee | 8 Comments |
As most skilled COMSOL users, I am sure you know that you are not limited to just selecting what is in our drop-down lists. Say that you have invented your own measure of structural stress. You want it to be equal to the quadratic mean of the Tresca and von Mises stresses. Go to Plot Parameters to find out what these predefined stresses are called (tresca_smsld and mises_smsld if you are modeling in 3D with the Structural Mechanics Module). Now all you need to do is enter sqrt(0.5*(tresca_smld^2+mises_smld^2)) in any of the Expression fields and click OK to see your new stress distribution.
You probably didn't think of it, but in the expression I just mentioned, sqrt, ^, and even + are all examples of operators. COMSOL offers a whole range of useful ones, not all equally obvious. Did you for instance know that the letter d will differentiate any variable or expression with respect to time or space? d(c,z) gives the derivative of a concentration c with respect to the z-coordinate. d(sqrt(0.5*(tresca_smld^2+mises_smld^2)),t) is the time-derivative of your stress. If you have created your own subdomain expression my_stress containing your stress definition, d(my_stress,t) gives the same results.
The at operator lets you access the solution at any time in postprocessing. This is handy if you want to see changes over a time interval. Plotting the expression at(20,p)-at(10,p) overrides the Solution at time setting and shows you the pressure increase between 10 and 20 seconds. The with operator lets you postprocess more than one parametric or eigensolution in a similar fashion.
Another handy pair of operators is up and down. They live on boundaries and help you evaluate anything with discontinuities. Consider for example a temperature gradient on a boundary between two subdomains with different conductivities. gradT_ht will silently evaluate this gradient on both sides of the boundary and give you the average. With up(gradT_ht) and down(gradT_ht) however, you can decide which side you are interested in.
If you work with electromagnetics, you might have plotted the magnetic field in an eigenmode analysis only to find that it appears to be identically zero. Chances are it is non-zero but perfectly imaginary due to its 90-degree phase difference with a real-valued electric field. Use the imag operator to show its imaginary part, abs to plot the norm, or arg to see the phase angle. Note that the default plot for complex fields shows the real part.
This is just the tip of the iceberg. You can find the complete list of mathematical and other operators in the COMSOL Multiphysics Quick Start and Quick Reference.

Comments
Dec 19, 2009 at 11:20am UTC
Indeed there are very many things we can do with these operators,
my only remark is that I expect d(c,z) to give the derivative of z and NOT of x
;)
Ivar
Dec 19, 2009 at 11:20am UTC
Comment removed by Ivar KJELBERG.
Dec 21, 2009 at 8:43am UTC
Oops! Thanks Ivar, I've corrected it now.
Feb 3, 2010 at 11:05pm UTC
Hi
I was trying to use an expression in stop condition to stop solving when shear rate <1. I tried "sr_chns1-1" where sr_chns2 represents shear rate, this is obtained from equation system/subdomain variables of non-newtonian model with a moving mesh.
I got the error 9028. i am not sure why it could not evaluate "sr_chns2-1"
Feb 4, 2010 at 8:06am UTC
Hi Praveen. The stop condition may only contain global expressions. The computation stops when the real part of the expression gets negative.
Mar 6, 2010 at 1:38pm UTC
I just checked posteval(fem, 'd(Ex,y)') command in comsol 3.5 (RF-module, perpendicular waves) and it is not being recognized. Could it be a typo here or a conflict of standards between different versions?
Nevertheless, I tried posteval(fem, 'diff(Ex,y)') and it appears to be doing something right. Though not sure until I check out its function described in some official text. Any hint what is going on here?
Jul 8, 2010 at 2:13am UTC
Hi,
I am trying to calculate the derivate of B(magnetic flux) in different directions, to calculate the magnetic force in 3D modeling (magnetostatics)
I type, for example d(By_emqa,y) in expression box but it gives me zero, even though on the graph of By_emqa over y, the derivative of the graph is clearly not zero!
what am I doing wrong?
does anyboy have an idea?
thanks a lot
thnals a lot
Jul 29, 2010 at 9:36am UTC
Hi Lorainaa,
The emqa magnetostatics formulation uses vector elements. These support only first order coordinate derivatives of the solution variables, which in this case are the x-, y- and z-components of the magnetic vector potential. The flux density is already the curl of the vector potential, so your expression would involve second order derivatives of the solution variables.
If you get in touch with support@comsol.com, we can try to help you with a workaround.
You need to be logged in to COMSOL Access to be able to add a comment.