Platform: All Platforms Versions: All versions

Problem Description

How do I compute integrals over space or time? What if I want to use the result of these integrals elsewhere in my model?


The COMSOL Multiphysics architecture allows you to evaluate integrals in both space and time in several different ways, either purely for results evaluation or to introduce feedback into your model. This knowledgebase goes over all of these options.

Spatial Integrals

The most general approach to taking integrals is to add a Component Coupling of type Integration to the Component > Definitions branch. This feature adds an operator name that acts as a function and can be called anywhere else within the model. It can be used to define multiple different variables, as shown in the screenshot below. Note that integrating 1 over a domain is equivalent to evaluating the volume of that domain, integrating 1 over a boundary gives the surface area, and integrating 1 along an edge gives the length. If you add a component coupling after you have already computed the solution, you must Update Solution before the operator name will be available for results evaluation.

The integration component coupling and set of variables defined using it.

If you only want to integrate a single quantity then the Probe option can be preferred to the Component Coupling. It is a little bit easier to set up, and the results of a Probe will automatically be plotted. Each Probe defines a unique variable name that can be used anywhere else in the model. For time-dependent models probes will be plotted at all timesteps taken by the solver, by default. If you add a probe after you have already computed the solution, you will need to click the Update Results button within the Probe settings.

The probe interface.

If you do not want to use the results of the integral within your model, if you only want to evaluate integrals for results evaluation, then go to Results > Derived Values and add an integration feature, as shown in the screenshot below.

Taking an integral via Results > Derived Values

Time Integrals

For results evaluation only, use the timeint operator in results evaluation. For example, you can plot: timeint(1,2,T) to plot the integral of the expression T from 1-2 seconds. You can call integration operators within the timeint operator as well. See also the COMSOL Multiphysics Reference Manual for additional documentation on the timeint operator.

If, on the other hand, you want to make the results of a time integration available within a model, add a Domain, Boundary, Edge, or Point, or Global ODEs and DAEs interface. For example, suppose that you have defined the normalized Gaussian function via a Global Variable:

G = exp(-((t-0.5[s])/(0.1[s]*sqrt(2)))^2)/(0.1[s]*sqrt(2*pi))

If you want to take the time-integral of this variable, then you can do so via the Global ODES and DAEs interface, as shown in the screenshot below. Define the name of a variable, TimeInt that will store the time-integral. Define the equation as d(TimeInt,t)-G meaning that the time-derivative of TimeInt equals G. You will want to adjust the units of the dependent variable and the source term as appropriate for the quantities you're integrating. This equation is solved from the initial value TimeInt=0 and thus it computes the integral, from t=0 to the current time, of the expression G. Note that you can take a time integral of the results of a spatial integral, meaning that the expression G could be replaced with an integration operator, for example.

Taking a time integral via a global equation.