Including Operators and Expressions in a Multiphysics Simulation Is Easier Than You Think

December 11, 2009

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_smsldandmises_smsldif you are modeling in 3D with the Structural Mechanics Module). Now all you need to do is entersqrt(0.5*(tresca_smld^2+mises_smld^2))in any of the Expression fields and click OK to see your new stress distribution.

Operators in COMSOL Multiphysics

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 letterdwill differentiate any variable or expression with respect to time or space?d(c,z)gives the derivative of a concentrationcwith respect to thez-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 expressionmy_stresscontaining your stress definition,d(my_stress,t)gives the same results.

Theatoperator 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 expressionat(20,p)-at(10,p)overrides theSolution at timesetting and shows you the pressure increase between 10 and 20 seconds. Thewithoperator lets you postprocess more than one parametric or eigensolution in a similar fashion.

Another handy pair of operators isupanddown. 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_htwill silently evaluate this gradient on both sides of the boundary and give you the average. Withup(gradT_ht)anddown(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 nonzero but perfectly imaginary due to its 90-degree phase difference with a real-valued electric field. Use theimagoperator to show its imaginary part,absto plot the norm, orargto see the phase angle. Note that the default plot for complex fields shows the real part.

Next Steps

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 (13)

Leave a Comment
Log In | Registration
Loading...
Jing Zhou
Jing Zhou
September 6, 2012

Many thanks to the author for this useful information!
By the way, do you how to express an integral? Thank you!

Linus Andersson, COMSOL Employee
Linus Andersson, COMSOL Employee
September 7, 2012 COMSOL Employee

Hi Jing, glad you found it useful. To express an integral, just create and use an integration operator. This is done from Definitions > Model Couplings.

Jesus Lucio
Jesus Lucio
December 4, 2012

Hello, Linus,
Please, could you tell me how to access (for instance with the WITH() operator, or by means of the JOIN node for data) to any value of two different parameterized solutions (say in one solution the parameter goes from 0 to 1 and in the other the parameters goes form 1 to 2)? Each solution comes from one step function.
Thanks in advance.
Jesus.

Linus Andersson, COMSOL Employee
Linus Andersson, COMSOL Employee
December 5, 2012 COMSOL Employee

Hello Jesus,
I believe a Join data set should do the trick. Once you have created it, make sure that it has Data 1 set to Solution 1 and Data 2 set to Solution 2. Set “Solutions” to “One” in both the Data sections, and you will be able to pick any combination of parameter values. As usual, the Combination Method gives you various options for how to combine the solutions.
I hope this helps. If not, please contactsupport@comsol.comwith your model, and we should be able to give you some more specific advice.

Randhir Singh
Randhir Singh
July 3, 2013

Following up Jing Zhou: how to perform definite integral where the result is a field variable f(x,y) and where bounds are defined by the arbitrary space coordinates? say, integrating an field-expression within bounds of (x1,,y1) and (x,y) in a 2d model (x1

Linus Andersson, COMSOL Employee
Linus Andersson, COMSOL Employee
July 8, 2013 COMSOL Employee

Hi Randhir,
Suppose you have an integration operatorintop1and an expressionuthat you want to integrate over the rectanglex1,y1. The expression to evaluate then becomesintop1(u*(x>x1)*(xy1)*(y. The way this works is that comparisons evaluate to 1 if they are true and 0 if they are false.

Ciler Özen
Ciler Özen
March 10, 2020

Dear Andersson,

To my opinion above expression should be intop1(u*(x2>x>x1)*(y1

Hossein Mousavi
Hossein Mousavi
August 5, 2014

I really like the new COMSOL capability to join two separate solutions into one dataset using the Join functionality. However, it seems data2 special operator returns only the real part of its argument but data1 can handle both components. Is that a bug or it this meant to be?

Mahvash Afzal
Mahvash Afzal
September 29, 2016

Hi,

You’ve mentioned how the ‘d’ operator differentiates a variable wrt to time and space but how do we differentiate a variable wrt another dependent variable. I am using the d operator but it isn’t working for me.

Amir Hossein Kazemi
Amir Hossein Kazemi
July 27, 2018

Hello my freinds,
(^2) can change negetive sign to positive but why we should use ”abs” before for example; abs(ewfd.s11)^2 to calculate norm of S11?

Athena Serra
Athena Serra
February 22, 2019

Please: How to calculate this in Comsol 5.4:-8*Al*Al*integralof(dT/dz(r,0))*r*dr) from(0 to 1/2/Al). My Email:athenaserra@gmail.com

Brianne Christopher
Brianne Christopher
February 25, 2019 COMSOL Employee

Hello Athena,

For questions related to your modeling, please contact our Support team.

Online Support Center:https://www.comsol.com/support
Email:support@comsol.com

Thanks,
Brianne

Ailing Li
Ailing Li
June 30, 2023

Hello Linus, is there any operators having the same function as at( , t) but can be used in the model computation?

EXPLORE COMSOL BLOG
Baidu
map