How to Calculate Any Integral in COMSOL Multiphysics
Some results in COMSOL come ready-made. Open Heat Transfer in Solids, add a plot, and you already see heat flux. But what happens when you need something else? What if COMSOL has no built-in button for it?
This happens more often than you think. Post-processing shortcuts only cover a few standard results. For everything else, you need a general tool: the Integration operator. If you set it properly, it works with any physics, any expression, and any domain or boundary.
In this article, we build a simple example step by step.
Why You Need a General Integration Tool
Think about a simple case. You build a rectangle. Heat flows in on one side and out on the other. COMSOL's Heat Transfer interface shows you the heat flux by default. That is convenient.
But what if you switch to a different physics? Or what if you want to integrate your own custom expression? There is no ready button for that. You need to build your own integration once and reuse it anywhere in your model.
The Simple Way: Integration Under Local Definitions
Here is a small example. It uses Heat Transfer in Solids only.
Draw a simple 2D rectangle, for example 40 mm by 20 mm. Made from Aluminum.
Add the Heat Transfer in Solids physics interface.
Set a Temperature boundary condition on the left edge, and a lower Temperature on the right edge. Heat now flows through the rectangle, from left to right.
Mesh the geometry.
Right-click Definitions, choose Nonlocal Couplings, then Integration.
Under Source Selection, pick what you want to integrate over: the domain (the whole rectangle) or one boundary (one edge). Keep the default Operator name, intop1.
Compute the study.
Go to Results, then Derived Values, then Global Evaluation. Type intop1(1) in the Expression field.

That last step is the key idea. Integrating the dimensionless number 1 over your selection gives you its size — area for a domain, length for a boundary. This is the simplest possible integral, and it proves the operator works.
Now reuse the same operator for something useful. Change the selection to one boundary, and type intop1(ht.ntflux) in Global Evaluation. This integrates the heat flux across that edge — the same value the default post-processing already shows you. The difference is that you built it yourself. You can now integrate any expression, in any physics, even where COMSOL has no default plot.
Tip: the operator has a global destination. That means you can type intop1(...) anywhere in your model, not only in Global Evaluation — for example inside another boundary condition, or inside a different physics interface.
Alternative Way: Mass Properties
COMSOL also has a ready-made node for a specific group of integrals: volume, mass, center of mass, and moments of inertia. It is called Mass Properties.
You find it in the Definitions toolbar, under Physics Utilities. Or right-click Definitions and choose Mass Properties from the same submenu. Pick your domains, set a density — user-defined, or taken from your physics — and check which variables you want: volume, mass, center of mass, moments of inertia.

COMSOL builds an operator for you, for example mass1, and creates ready variables such as mass1.mass or the center-of-mass coordinates. You read them the same way as before: Results, Derived Values, Global Evaluation.
This method is faster for these specific properties. But it is less flexible than a plain Integration operator. You cannot use it for a custom expression — only for the fixed list of mechanical properties it offers.
Which One Should You Use?
Use Integration under Nonlocal Couplings for any expression, on any domain or boundary. It is the general tool, and it is worth learning once.
Use Mass Properties only when you need mass, volume, center of mass, or moments of inertia, and you don't want to build the formula by hand.
Once you know the Integration operator, you are no longer limited to what COMSOL shows by default. You can measure anything, anywhere in your model.
Need help setting up your own COMSOL model? Simulation Guys can help you choose the right physics, meshing, and post-processing for results you can trust. Get in touch with us.
