Variables
You can add Variables () from either the Global Definitions node or the Definitions node under the Component (local) nodes.
From the Home (Windows users) or Main (macOS and Linux users) toolbar click Variables and choose Global Variables or Local Variables.
Right-click Global Definitions and choose Variables.
Under Component right-click Definitions and choose Variables, or click Local Variables in the Definitions toolbar (Windows users).
Use the Variables node to define expressions as user-defined variables. Global variables can be used in any context that accepts variable expressions, in all Components and on all geometric entities — provided that their expressions are also global expressions. In contrast, local variables have a specific geometric domain of definition. Such variables can only be used and evaluated in a specific Component, or on selected domains, boundaries, edges, or points.
Global variables are primarily useful for expressions involving parameters that do not depend on the geometry, such as time, or dependent variables in an ODE or algebraic equation. Whenever possible, define variables under Definitions in a Component to minimize the risk of variable name conflicts in the global namespace.
Which variables are available for evaluation in postprocessing is decided at the time a solution is created. This means that variables you define do not immediately show up as predefined quantities in results nodes or become available for use in expressions when postprocessing an existing solution. To access the new variables, you must solve the model or update an existing solution by right-clicking a Study node () and selecting Update Solution ().
Geometric Entity Selection (Local Definitions Only)
Select the geometric scope from the Geometric entity level list: Entire model, Domain, Boundary, Edge (3D only), or Point. For all levels except Entire model, you must also specify the variables domain of definition either by adding entities to a Manual selection or choosing All boundaries, for example, from the Selection list.
Variables defined in a Component but with Geometric entity level set to Entire model are in fact global; they can be used anywhere using their full name. For example, if you define variable a in Component 1 in this way, you can refer to it in another Component as comp1.a.
If a variable is defined on the boundary (with the same name as a variable defined in a domain), it will take precedence, when evaluated on a boundary, over the variable in the domain. If you define a variable v, for example, and the selection is Entire model, you actually define four different variables, representing v in domains, boundaries, edges (3D only), and points.
Variables
In the Variables table or the fields under the table, enter variables by defining a variable name under Name, an expression that define the variable under Expression (see  About Parameters, Variables, Variable Utilities, Physics Utilities, and Expressions), and (optionally) a description that explains the variable under Descriptions. Alternately, you can import variable definitions from a text file. For the expression, press Ctrl+Space or use the Insert Expression button () below the table to choose from a number of applicable variables, parameters, functions, operators, and constants that you can insert into the expression at the position of the cursor. Use other buttons underneath the table to move, insert, and remove rows and to clear the table. Also, use the Move To button () to move selected variables to any other available Variables node or to a new Variables node. You can right-click selected rows in the table to move or remove selected rows, or to insert a row above the selected rows. You can also cut, copy, and paste the selected contents.
It is only possible to move variables within Variable nodes in the same component or between global Variables nodes.
Click any column header to sort the table by that column alphabetically, in either an ascending or a descending order (indicated by downward and upward arrows, respectively). Click the header once to change from ascending to descending order, and click once more to return to the original order. Note that when the table is sorted the Move Up and Move Down buttons are not available.
Additionally, the Save to File button () saves variables to a text file (or to a Microsoft Excel Workbook spreadsheet if the license includes LiveLink™ for Excel®) for reuse in other models. The information is saved in space-separated columns in the same order as displayed on screen. When saving to Excel, an Excel Save dialog box appears where you can specify the sheet and range and whether to overwrite existing data, include a header, or use a separate column for units.
Using the Load from File button (), you can import or load data in text files created, for example, by a spreadsheet program. You can also click the downward arrow beside the Load from File button and choose Load From () to open the fullscreen Select File window. Data must be separated by spaces or tabs. If the license includes LiveLink™ for Excel® you can also load variables from a Microsoft Excel Workbook spreadsheet. Then an Excel Load dialog box appears where you can specify the sheet and range, whether to overwrite existing data, and declare if the data is stored using a separate column for units.
For an example of global variables, see Effective Diffusivity in Porous Materials: Application Library path COMSOL_Multiphysics/Diffusion/effective_diffusivity
Automotive Muffler: Application Library path COMSOL_Multiphysics/Acoustics/automotive_muffler
Tubular Reactor with Nonisothermal Cooling Jacket: Application Library path COMSOL_Multiphysics/Chemical_Engineering/tubular_reactor