IntroductionToApplicationBuilder 6.1
IntroductionToApplicationBuilder 6.1
Application Builder
Introduction to Application Builder
© 1998–2022 COMSOL
Protected by patents listed on www.comsol.com/patents, and U.S. Patents 7,519,518; 7,596,474; 7,623,991; 8,457,932;
8,954,302; 9,098,106; 9,146,652; 9,323,503; 9,372,673; 9,454,625; 10,019,544; 10,650,177; and 10,776,541. Patents
pending.
This Documentation and the Programs described herein are furnished under the COMSOL Software License
Agreement (www.comsol.com/comsol-license-agreement) and may be used or copied only under the terms of the
license agreement.
COMSOL, the COMSOL logo, COMSOL Multiphysics, COMSOL Desktop, COMSOL Compiler, COMSOL Server,
and LiveLink are either registered trademarks or trademarks of COMSOL AB. All other trademarks are the property
of their respective owners, and COMSOL AB and its subsidiaries and products are not affiliated with, endorsed by,
sponsored by, or supported by those trademark owners. For a list of such trademark owners, see www.comsol.com/
trademarks.
Version: COMSOL 6.1
Contact Information
Visit the Contact COMSOL page at www.comsol.com/contact to submit general inquiries or
search for an address and phone number. You can also visit the Worldwide Sales Offices page at
www.comsol.com/contact/offices for address and contact information.
If you need to contact Support, an online request form is located on the COMSOL Access page
at www.comsol.com/support/case. Other useful links include:
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
The Application Builder Desktop Environment . . . . . . . . . . . . . 12
The Application Builder and the Model Builder. . . . . . . . . . . . . 21
Parameters, Variables, and Scope . . . . . . . . . . . . . . . . . . . . . . 22
Running Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Running Applications in COMSOL Multiphysics . . . . . . . . . . 24
Running Applications with COMSOL Server . . . . . . . . . . . . 32
Compiling and Running Standalone Applications . . . . . . . . . 37
Publishing COMSOL Applications . . . . . . . . . . . . . . . . . . . . . 43
Getting Started with the Application Builder . . . . . . . . . . . . . . . 45
Themes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
The Form Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
The Individual Form Settings Windows . . . . . . . . . . . . . . . . . 53
Local Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Form Editor Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Form Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Editor Tools in the Form Editor . . . . . . . . . . . . . . . . . . . . . . . 63
Button. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Input Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Text Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Data Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
|3
Data Access in the Form Editor . . . . . . . . . . . . . . . . . . . . . . 106
Sketch and Grid Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Show Errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Copying Between Applications . . . . . . . . . . . . . . . . . . . . . . . 129
Using Forms in the Model Builder . . . . . . . . . . . . . . . . . . . . 130
Inputs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
The Main Window Editor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Menu Bar and Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Ribbon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Interactive Editing of Menus and Ribbon Tabs . . . . . . . . . . 144
Subwindows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Events at Startup and Shutdown. . . . . . . . . . . . . . . . . . . . . . 149
Global Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Form and Form Object Events . . . . . . . . . . . . . . . . . . . . . . . 153
Using Local Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Scalar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Array 1D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Array 2D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Choice List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Unit Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Shortcuts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Graphics Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
The Method Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Converting a Command Sequence to a Method . . . . . . . . 181
4|
Language Elements Window . . . . . . . . . . . . . . . . . . . . . . . . . 186
Editor Tools in the Method Editor . . . . . . . . . . . . . . . . . . . . 187
Data Access in the Method Editor . . . . . . . . . . . . . . . . . . . . 189
Recording Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Checking Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Find and Replace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Model Expressions Window . . . . . . . . . . . . . . . . . . . . . . . . . 196
Use Shortcut . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Syntax Highlighting, Code Folding, and Indentation . . . . . .198
Method Editor Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Ctrl+Space and Tab for Code Completion. . . . . . . . . . . . . 201
Creating Local Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Local Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Methods with Input and Output Arguments. . . . . . . . . . . .206
Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
The Model Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Language Element Examples . . . . . . . . . . . . . . . . . . . . . . . . . 211
Running Methods in the Model Builder . . . . . . . . . . . . . . . . 215
Creating Add-Ins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Add-In Libraries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Workflow when Creating and Editing Add-Ins . . . . . . . . . . 227
Libraries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Images. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Sounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Appendix A — Form Objects . . . . . . . . . . . . . . . . . . . . . . . . . . 232
List of All Form Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Check Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
|5
Toggle Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Combo Box. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Web Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
Progress Bar. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Gauge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Message Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Results Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
Form Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
Card Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
File Import . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
Information Card Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Array Input. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Radio Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Selection Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
List Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Slider. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Knob . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
Hyperlink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Spacer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
6|
Appendix B — Copying Between Applications . . . . . . . . . . . .321
Appendix C — File Handling and File Scheme Syntax . . . . . . 323
File Handling with COMSOL Server . . . . . . . . . . . . . . . . . . 323
File Scheme Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
File Import . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
File Export . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
Appendix D — Keyboard Shortcuts . . . . . . . . . . . . . . . . . . . . . 344
Appendix E — Built-In Method Library . . . . . . . . . . . . . . . . . . 347
Appendix F — Guidelines for Building Applications . . . . . . . . 365
Appendix G — The Application Library Examples . . . . . . . . . 368
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
|7
8|
Preface
The typical user of a simulation package is someone who holds a PhD or an MSc,
has several years of experience in modeling and simulation, and underwent
thorough training to use the specific package. He or she typically works as a
scientist in the R&D department of a big organization or as an academic
researcher. Because the theory of simulation is complicated and the typical
simulation package presents many options, it is up to the user to employ his or her
expertise to validate the model and the simulation.
This means that a small group of simulation experts is serving a much larger group
of people working in product development, production, or as students studying
physics effects. Simulation models are oftentimes so complicated that the person
who implemented the model is the only one who can safely provide input data to
get useful output. Hence the use of computer modeling and simulation creates a
bottleneck in product development, production, and education.
In order to make it possible for this small group to service the much larger group,
the Application Builder offers a solution. It enables simulation experts to create an
intuitive and very specific user interface for his or her otherwise general computer
model — a ready-to-use application. The general model can serve as a starting
point for several different applications, with each application presenting the user
with input and output options relevant only to the specific task at hand. The
application can include user documentation, checks for “inputs within bounds”,
and predefined reports at the click of a button.
Creating an application often requires a collaborative effort by experts within the
areas of: physics, numerical analysis, programming, user-interface design, and
graphic design.
To a reasonable extent, COMSOL’s Technical Support team can recommend
physics and numerical analysis settings for your application. In addition, the
COMSOL documentation and online resources can be of great help. For
programming and design, the Technical Support team can provide very limited
help. These are areas where your own development efforts are critical.
The Application Builder makes it easy for a team to create well-crafted applications
that avoid accidental user input errors while keeping the focus on relevant output
details.
We at COMSOL are convinced that this is the way to spread the successful use of
simulation in the world and we are fully committed to helping make this possible.
|9
Introduction
10 |
COMSOL applications by connecting to a COMSOL Server from your Android™
device via the COMSOL Client for Android™ app on the Google Play™ store.
COMSOL Server does not include the Application Builder, Physics Builder, or
Model Builder tools that come with the COMSOL Desktop environment. Any
application created with the Application Builder will automatically work with a
web browser or any client.
A DDITIONAL D OCUMENTATION
Additional documentation with information relevant to building applications can
be found in the books: Application Programming Guide, Application Builder
Reference Manual, and Programming Reference Manual.
| 11
The Application Builder Desktop Environment
APPLICATION BUILDER WINDOW — SETTINGS and EDITOR TOOLS WINDOWS — Click any application
The Application Builder window with the tree node or form object to see its associated Settings window.
application tree. The Editor Tools window is used to quickly create form objects.
The screenshot above is representative of what you will see when you are working
with the Application Builder. The main components of the Application Builder
desktop environment are:
• Application Builder window and ribbon tab
• COMSOL Desktop environment
• Form Editor (see page 53)
• Main Window Editor (see page 136)
• Method Editor (see page 181)
12 |
T HE A PPLICATION T REE
The application tree consists of the
following nodes:
• Inputs
• Themes
• Main Window
• Forms
• Events
• Declarations
• Methods
• Libraries
| 13
The Declarations node is used to declare global variables, which are used in
addition to the global parameters and variables defined in the model.
The Methods node contains subnodes that are methods. Methods contain code for
actions not included among the standard run commands of the model tree nodes
in the Model Builder. The methods may, for example, execute loops, process
inputs and outputs, and send messages and alerts to the user of the application.
Methods can modify the model object of a running application or the model
object represented by the Model Builder in the current session.
The Libraries node contains images, sounds, and files to be embedded in an
MPH-file so that you do not have to distribute them along with the
application. In addition, the Libraries node may contain Java® utility class
nodes and nodes for external Java ® and C libraries.
14 |
T HE F ORM E DITOR
FORM TAB — The Form tab in the ribbon FORM EDITOR WINDOW — The tabbed Form
gives easy access to the Form Editor. Editor window allows you to move objects around
by dragging. Click an object to edit its settings.
FORM OBJECTS — Each form contains form objects SETTINGS and EDITOR TOOLS WINDOWS —
such as input fields, check boxes, graphics, images, Click any application tree node or form object to see
buttons, and more. its associated Settings window. The Editor Tools
window is used to quickly create form objects.
Use the Form Editor for user interface layout by creating forms with form objects
such as input fields, graphics, and buttons.
The main components of the Form Editor are:
• Form ribbon tab
• Application Builder window with the application tree
• Form window
• Editor Tools window
• Settings window
| 15
Creating a New Form
To create a new form, right-click the Forms node of the application tree and select
New Form. You can also click New Form in the ribbon. Creating a new form will
automatically open the Form Wizard with a number of layout templates.
If your application already has a form, for example form1, and you would like to
edit it, you can open the Form Editor in either of two ways:
• In the application tree, double-click the form1 node.
• In the application tree, right-click the form1 node and select Edit.
You can also add forms that are local to other forms. When applicable, this option
is available as a menu option from the New Form button.
Use the Main Window Editor for menu and ribbon layout by creating menus with
menu items and ribbon tabs with ribbon items.
16 |
The main components of the Main Window Editor are:
• Menu editor
• File menu editor
• Ribbon tab editor
T HE M ETHOD E DITOR
METHOD TAB — The Method METHOD WINDOW — The tabbed SETTINGS WINDOW — Click any
tab in the ribbon gives easy ac- Method Window allows you to switch application tree node to see its asso-
cess to tools for writing and de- between editing different methods. ciated Settings window.
bugging code.
MODEL EXPRESSIONS, LANGUAGE ELEMENTS, and EDITOR TOOLS WINDOWS — These win-
dows display tools for writing code. The Model Expressions window shows all constants, parameters,
variables, and functions available in the model. The Language Elements window is used to insert template
code for built-in methods. The Editor Tools window is used to extract code for editing and running mod-
el tree nodes.
Use the Method Editor to write methods for actions not covered by the standard
use of the model tree nodes. A method is another name for what is known in other
programming languages as a subroutine, function, or procedure.
The main components of the Method Editor are:
• Method ribbon tab
| 17
• Application Builder window with the application tree
• Method window
• Model Expressions, Language Elements, Editor Tools, and Settings
windows (these are stacked together in the figure above)
Creating a new method will automatically open the Method Editor. Methods
created in this way are global methods and accessible from all methods, form
objects, and from the Developer tab in the Model Builder ribbon. By first clicking
a form node you also have the option of creating a Form Method which is local to
a form.
A sequence of commands associated with, for example, a button or menu
item can be automatically converted to a new method by clicking Convert
to Method. Open the new method by clicking Go to Method. You can also
create a method that is local to a form or form object by clicking Convert
18 |
to Form Method or Convert to Local Method, respectively. These options are shown
in the figure below.
If a method already exists, say with the name method1, then you can open the
Method Editor in any of these ways:
• In the application tree, double-click the method1 node.
• In the application tree, right-click the method1 node and select Edit.
• Below the command sequence in the Settings window of a form object or an
event, click Go to Method.
| 19
A PPLICATION B UILDER P REFERENCES
To access Preferences for the Application Builder, choose Preferences from the File
menu and select the Application Builder node.
You can configure the COMSOL Desktop environment so that the Application
Builder is displayed in a separate desktop window. Select the check box Use
separate desktop window for Application Builder.
You can use the keyboard shortcuts Ctrl+Shift+M and Ctrl+Shift+A to switch
between the Model Builder and Application Builder, respectively.
You can set an upper limit to the number of open Form Editor or Method Editor
window tabs. Select the check box Maximum number of editors before closing and
edit the number (default 15). Keeping this number low can speed up the loading
of applications that contain a large number of forms.
20 |
The Application Builder and the Model Builder
Use the Application Builder to create an application based on a model built with
the Model Builder. The Application Builder provides three important tools for
creating applications: The Form Editor, the Main Window Editor, and the
Method Editor. The Form Editor includes drag-and-drop capabilities for user
interface components such as input fields, graphics objects, and buttons. The
Main Window Editor lets you design a menu bar or a ribbon. The Method
Editor is a programming environment that allows you to modify the data
structures that represent the different parts of a model. The figures below show
the Model Builder and Application Builder windows.
| 21
The tools in the Application Builder can access and manipulate the settings in the
embedded model in several ways; For example:
• If the model makes use of parameters and variables, you link these directly
to input fields in the application by using the Form Wizard or Editor Tools.
In this way, the user of an application can directly edit the values of the
parameters and variables that affect the model. For more information, see
pages 63 and 95.
• By using the Form Wizard or Editor Tools, you can include a button in your
application that runs a study node and thereby starts the solver. In addition,
you can use this wizard to include graphics, numerical outputs, check boxes,
and combo boxes. For more information, see pages 45 and 63.
• The Data Access tool and the Editor Tools window can be used to directly
access low-level settings in the model for use with form objects or in
methods. For more information, see pages 63, 106, and 187.
• By using the Record Code and Record Method tools, you can record the
commands that are executed when you perform operations within the model
tree and its nodes. These will then be available in a method for further
editing. For more information, see page 191.
The model tree may contain both parameters and variables that are used to control
the settings of a model. The figure below shows the model tree of an application
with nodes for both Parameters and Variables.
Parameters are defined under the Global Definitions node in the model tree and are
user-defined constant scalars that are usable throughout the Model Builder. That
is to say, they are “global” in nature. Important uses are:
• Parameterizing geometric dimensions
22 |
• Specifying mesh element sizes
• Defining parametric sweeps
Variables can be defined in either the Global Definitions node or in the Definitions
subnode of any model Component node. A globally defined variable can be used
throughout a model, whereas a model component variable can only be used within
that component. Variables can be used for spatially or time-varying expressions,
including dependent field variables for which you are solving.
In the Model Builder, a parameter or variable is a string with the additional
restriction that its value is a valid model expression. For more information on the
use of parameters and variables in a model, see the book Introduction to
COMSOL Multiphysics.
An application may need additional variables for use in the Form Editor and the
Method Editor. Such variables are declared in the Application Builder under the
Declarations node in the application tree. The figure below shows the application
tree of an application with multiple declarations.
The declared variables in the Application Builder are typed variables, including
scalars, arrays, Booleans, strings, integers, and doubles. Before using a variable,
you have to declare its type.
The fact that these variables are typed means that they can be used directly in
methods without first being converted using one of the built-in methods. This
makes it easier to write code with typed variables than with parameters and
variables representing model expressions. However, there are several tools
available in the Application Builder for converting between the different kinds of
variables. For more information, see pages 157 and 347. For more information on
typed variables, see the Application Programming Guide.
| 23
Running Applications
T ESTING AN A PPLICATION
Test Application is used for quick tests. It opens a separate window with the
application user interface while keeping the Application Builder desktop
environment running. The figure below shows the Test section as it appears in the
Form tab of the ribbon.
While testing an application, you can apply changes to forms, methods, and the
embedded model at run time by clicking the Apply Changes button. Not all
changes can be applied at run time, and in such a case, you are prompted to close
the application and click Test Application again.
To preview the layout of a form without running the application, click Preview
Form in the ribbon.
24 |
When Test Application is used, all methods are automatically compiled with the
built-in Java® compiler. Any syntax errors will generate error messages and the
process of testing the application will be stopped. To check for syntax errors before
testing an application, click the Check Syntax button in the Method tab.
Check Syntax finds syntax errors by compiling the methods using the built-in Java®
compiler. Any syntax errors will, in this case, be displayed in the Method Errors and
Warnings window in the Method Editor. For more information, see “The Method
Editor” on page 181.
R UNNING AN A PPLICATION
Run Application starts the application in the COMSOL Desktop environment.
Select Run Application to use an application for production purposes. For example,
you can run an application that was created by someone else that is password
protected from editing, but not from running.
| 25
The option Edit application will open the application in the Application Builder.
The option Run application will open the application in runtime mode for
production purpose use. This option is similar to selecting Run Application in the
File menu with the difference that double-clicking an MPH-file will start a new
COMSOL Multiphysics session.
If you have installed the COMSOL Client for Windows®, the MPH-file extension
may instead be associated with the COMSOL Client, and double-clicking an
MPH-file will prompt you to log in to a COMSOL Server installation.
When selected, an application can be started even if all required licenses are not
available. It is still not possible to use the functionality of products for which the
license is not available. However, you can write methods to create an application
such that the functionality used is dynamically adapted to which types of licenses
are available.
You can choose which of the installed web browsers you would like the application
to launch in. Test in Web Browser opens a separate browser window with the
26 |
application user interface while keeping the Application Builder desktop
environment running.
The Server column represents the software components that perform the
CPU-heavy computations. The Client column represents the software tool or
component used to present the application user interface. In the case of executable
files, all computations are done locally. For more information on compiled
applications, see “Compiling and Running Standalone Applications” on page 37.
| 27
in which you may select the check box Ask to save application when closing, as
shown in the figure below.
As an alternative, you can add a button or menu item with a command to save the
application. For more information, see page 142.
A PPLICATION L IBRARIES
From the File menu, select Application Libraries to run and explore the example
applications that are included in the COMSOL installation. Many of the
screenshots in this book are taken from these examples.
28 |
You run an application, or open it for editing, by clicking the corresponding
buttons below the Application Libraries tree.
| 29
To set the thumbnail image, click the root node of the application tree. The
Settings window has two options for choosing the image: Set from Graphics
Window and Load from File. You can also Clear the image.
The Load from File option allows you to load images in the PNG or JPG file
formats. Choose an image size from 280-by-210 to 1024-by-768 pixels to ensure
that the image displays properly as a thumbnail in COMSOL Multiphysics and
COMSOL Server.
The Set from Graphics Window option automatically creates two thumbnail images:
• An image of size 280-by-210 pixels shown in the Settings window of the
application tree root node and in the Application Libraries.
• An image of size 1024-by-768 used as the default title page image in reports
and in the Application Libraries in COMSOL Server.
30 |
P ASSWORD P ROTECTION
An application can be password protected to manage permissions. You assign
separate passwords for editing and running in the Settings window, accessible by
clicking the root node of the application tree in the Application Builder window.
You must have permission to edit an application in order to create passwords for
running it.
S ECURITY S ETTINGS
When creating an application with the Application Builder, it is important to
consider the security of the computer hosting the application. Both COMSOL
Multiphysics and COMSOL Server provide a very similar set of security settings
for controlling whether or not an application should be allowed to perform
external function calls, contain links to C libraries, run MATLAB functions, access
external processes, and more.
| 31
The security settings in COMSOL Multiphysics can be found in the Security page
in the Preferences window accessed from the File menu. In COMSOL Server, they
are available in the Preferences page in the COMSOL Server web interface if you
are logged in as an administrator. If you are not sure what security settings to use,
contact your systems administrator.
32 |
When logged in, the Application Library page displays a list of applications to run.
Click Run in browser to run an application. Applications are run in separate tabs in
the browser.
| 33
Limitations When Running Applications in Web Browsers
When you create applications to run in a web browser, make sure you use the grid
layout mode in the Application Builder; See “Sketch and Grid Layout” on page
112. This will ensure that the user interface layout adapts to the size and aspect
ratio of the browser window. For low-resolution displays, make sure to test the
user interface layout in the target platform to check that all form objects are visible.
Applications that contain resizable graphics forms may not fit in low-resolution
displays. In such cases, use graphics with fixed width and height to make sure all
form objects fit in the target browser window. Depending on the type of web
browser and the graphics card, there may be restrictions on how many graphics
objects can be used in an application. You can get around such limitations by,
instead of using multiple graphics objects, reuse the same graphics object by
switching its source.
When running in a web browser, the LiveLink™ products for CAD software
packages are not supported.
When running COMSOL applications in web browsers for smartphones and
certain tablets, not all functionality is supported. Typical limitations include the
ability to play sounds or open documents. In addition, file upload and download
may not be supported.
If the application allows the user to make selections, such as clicking on boundaries
to set boundary conditions, running in a web browser is different from running in
COMSOL Multiphysics or the COMSOL Client for Windows®. In a web
browser, boundaries are not automatically highlighted when hovering. Instead, it
is required to click once to highlight a boundary. A second click will make the
selection. A third click will highlight for deselection and a fourth click will deselect.
The process is similar for domains, edges, and points.
Note that file browsing functionality is slightly different depending on the web
browser and depending on the version of the web browser. This may impact the
user experience when running an application that has functionality for saving files
to the client computer. For example, the location of the downloads folder can be
changed in the settings of many web browsers. A web browser may also allow the
user to manually specify the download location for each file. Please refer to the
documentation of your target web browsers for details.
34 |
applications that require a LiveLink™ product for CAD, provided that the
COMSOL Server you connect to has the required licenses. You can open an
application with the COMSOL Client for Windows® in two different ways:
• The COMSOL Server web interface will allow
you to choose between running an application
in a web browser or with the COMSOL
Client for Windows®.
If you try to run an application with the
COMSOL Client in this way, but it is not yet
installed, you will be prompted to download
and install it.
| 35
In the figure below, the COMSOL Server web interface is shown (top) with an
application launched in the COMSOL Client for Windows® (bottom).
36 |
Primary and Secondary Instances
Running COMSOL Server on multiple computers using primary and secondary
instances allows for more concurrent users and applications than a single computer
instance (or installation). The main COMSOL Server instance is called primary
and the other instances are called secondary. The primary server is used for all
incoming connections — for example, to show the web interface or to run
applications in a web browser or with COMSOL Client. The actual computations
are offloaded to the secondary server computers. This type of installation has a
major benefit: Applications do not need to be custom-built for a particular cluster.
Load balancing is managed automatically by the primary server, which distributes
the work load between the secondary servers. A COMSOL Server installation can
consist of multiple primary and secondary server installations without additional
license requirements. You can perform administrative tasks using the COMSOL
Server web interface without checking out license keys for users running
applications. License keys are only checked out when running applications.
| 37
Clicking this button will add a Compiler node to the application tree, shown in the
figure below.
C OMPILING A PPLICATIONS
To compile an application, you need to make a few selections in this window.
Specify an output Directory, where the executable files will be saved after
compilation.
The Runtime option can be left at Download for most situations. COMSOL
Runtime contains all the COMSOL Multiphysics software components needed to
run the application as a standalone program. The Runtime setting specifies how the
COMSOL Runtime environment will be acquired from the compiled application.
If this setting is Download then the first time a user is starting the compiled
application the COMSOL Runtime environment files will be downloaded (a
service provided by COMSOL). If the COMSOL Runtime environment already
exists on the computer, with a matching version number, then no download will
38 |
be performed. The option Embed will bundle the COMSOL Runtime files in the
executable file. Note that with this option, the file size may be several hundred
megabytes even for smaller applications.
The Platforms settings determine which target-platform executables should be
generated at compilation. The extensions of the executables for the Windows®
and Linux® operating systems will be .exe and .sh, respectively. For macOS, a
.tar archive is created; unpack this archive on macOS to extract the app.
The Icon for Windows lets you specify the desktop icon. The Splash setting lets you
specify a BMP-image file to be displayed at startup.
After compilation, in the Windows® operating system, the executable file will be
available in the output directory, as shown in the figure below.
As a next step, you can, for example, right-click the EXE file and create a shortcut
that you then place on the Windows® desktop. Note that the .exe file extension
might not be shown, depending on the operating system settings.
You can also compile an application from the operating system command line. For
more information, see the COMSOL Multiphysics Reference Manual.
| 39
It is recommended that you replace this with your own splash screen.
If this is the first time you are running an application on a particular computer,
then, in addition, a click-through agreement and an Initializing Installer progress
window will be displayed. The initialization progress window is shown below.
The COMSOL Runtime Installer and its click-through agreement are only shown
once, and the next time you start the same application, it will not be shown. The
click-through agreement and initialization progress window will also not be
shown if you run another application on the same computer that was generated
with the same COMSOL Compiler version (having the same version of the
COMSOL Runtime).
40 |
Click Next to select the location of the COMSOL Runtime files and the click
Install, as shown in the figure below.
The installation takes a few minutes and, when finished, the installer will prompt
the user to start the application.
An option for showing the COMSOL About dialog box is always available in a
compiled application. The author of the application controls how this information
| 41
is available from the Settings of the Main Window; see “About Dialog” on page 138.
The figure below shows the About dialog box.
In the About dialog box, the user of a compiled application can access the
Preferences by clicking the corresponding button. The Preferences dialog box for
a compiled application is shown below.
42 |
Here, the user can change settings for Visualization, Mouse, Temporary files,
Multicore, and LiveLink™ for MATLAB®. These settings represent a subset of the
Preferences available in COMSOL Multiphysics and more information can be
found in the COMSOL Multiphysics Reference Manual.
If the compiled application detects that OpenGL® graphics hardware
acceleration is not supported, then the application will automatically
switch to software rendering and exit. The next time the application starts,
software rendering will be used.
| 43
publish those modified applications for others to use, including commercially,
with certain restrictions spelled out in the Application License. This allows you to,
for example, use one of the applications in the Application Libraries as a starting
point for your own applications by adding or removing your own features.
If you wish to apply the Application License to applications that you create, the
Application License contains instructions on how to do so. The Application
License also addresses how you can use terms that you choose for modifications
you make to applications available in the Application Libraries, while the original
portions of those applications remain available under the Application License.
The results from a simulation software such as COMSOL Multiphysics can
shorten design times dramatically by, for example, reducing the number of
experiments or product tests. However, simulation software is not a substitute for
real-world testing. This is especially important if there are risks for physical or
environmental damage.
44 |
Getting Started with the Application Builder
The Form Wizard assists you with adding the most common user interface
components, so-called form objects, to the first draft of your application.
| 45
In the Form Wizard, the first page is the Select Template page.
The different templates listed here will help you quickly create an organized
application with different levels of sophistication and user-interface layouts for
desktop, table, and smartphone use.
For this example, you can load the busbar.mph model from the Application
Libraries at COMSOL Multiphysics > Multiphysics. This is one of the models used in
the Introduction to COMSOL Multiphysics manual.
Select the Basic layout template and click Content. The Select Content page has four
tabs:
• Inputs
• Outputs
46 |
• Graphics
• Ribbon buttons
Double-click a node or click the Add Selected button to move a node from the
Available area to the Selected area. The selected nodes will become form objects in
the application and a preview of the form will be shown in the Preview area to the
right.
The size as well as other settings for form objects can be edited after exiting the
wizard. You can also choose to exit the wizard at this stage by clicking Done, and
then manually add form objects.
| 47
In the figure below, three parameters, including Length, Width, and Applied
voltage, have been selected to serve as input fields.
In the figure below, a Derived Values node for the maximum temperature has been
selected from the Outputs tab to serve as a data display object.
After exiting the wizard, you can edit the size and font color as well as other
settings for input fields and data display objects.
48 |
node has been selected. When using the Basic layout template, this selection
determines the default plot shown when the app is started.
| 49
In the figure below, buttons have been added corresponding to the actions: Plot
Geometry, Plot Mesh, Compute Study, Plot Electric Potential, Plot Temperature, Plot
Current Density, and Reset Window Layout.
The Reset Window Layout option is available under GUI Commands > Main Window
Commands > Reset Window Layout. The application consists of two subwindows,
one for the inputs and outputs and one for the graphics. The Reset Window Layout
button will reset the two subwindows in the application to their original size. The
Subwindows template is similar to the Basic template but additionally enables you
to detach, move around, and dock the subwindows. In this case, the Reset Window
Layout operation will rearrange all subwindows to their original position and size.
Using the Form Editor, you can add buttons that run your own custom command
sequences or methods.
For an example of using the Single form template, see the Introduction to
COMSOL Multiphysics manual.
50 |
The figure below shows the running application.
S AVING AN A PPLICATION
To save an application, from the File menu, select File > Save As. Browse to a folder
where you have write permissions, and save the file in the MPH-file format. The
MPH-file contains all of the information about the application, including
information about the embedded model created with the Model Builder.
| 51
Themes
The Settings window for Themes is displayed when you click the Themes node in
the application tree. It lets you change the overall appearance of the user interface
and forms with settings for Application theme, Image export theme, Text color,
Background color, Font, Font size, Bold, Italic, and Underline.
The default is that all new forms and new form objects inherit these settings when
applicable.
52 |
The Form Editor
Use the Form Editor for user interface layout to create forms with form objects
such as input fields, graphics, buttons, and more.
The figure below shows the application tree node and Settings window for a form.
Each form has its own Settings window with settings for:
• Name used to reference the form in other form objects and methods.
• Form Title that is used in applications with several forms.
| 53
• Icon shown in the upper-left corner of a dialog box.
• Initial size of the form when used as a dialog box or when the Main Window is
set to have its size determined by the form.
• Margins with respect to the upper-left corner (Horizontal and Vertical).
• Choices of when to store changes in dialog boxes (Store changes), see also
“Showing a Form as a Dialog Box” on page 74.
• Choices of whether the form should be Resizable or not and Vertically
scrollable or not when used as a dialog box.
• Table with the formatting of all columns and rows included in the form (Grid
Layout for Contained Form Objects).
• Appearance with settings for Text color, Background color, and Background
image.
• Events that are triggered when a form is loaded or closed. ( On load and On
close.)
Double-click a form node to open its window in the Form Editor. Alternatively,
you can right-click a form node and select Edit. Right-click a form window tab to
see its context menu with options for closing, floating, and tiling form windows.
54 |
If you use the Single form template and follow the same steps as for the earlier
example using the Basic template, then the Form Editor will result in an form as
shown in the figure below, after dragging to reorganize the buttons.
In this case, no ribbon is created and you can freely position form objects, such as
buttons and edit fields, by dragging them. This is beneficial in some cases,
however, the size of the graphics object will be fixed when using the Single form
layout template. This is because for this template the sketch layout mode is used
and automatic resizing of an app is only supported with the grid layout mode. To
learn how to create resizable graphics objects, see “Automatic Resizing of
Graphics Objects” on page 123.
Note that any type of application that you create using templates can also be built
using manual steps by starting from a Blank form or Single form template, however,
using templates accelerates this process.
| 55
right or bottom border of the grid. For more information on grid layout
mode, see “Grid Layout” on page 115.
Local Forms
Forms can be local to other forms, which enables you to create a better structure
when developing your applications. For instance, a complicated global form made
up of many different subforms can have the auxiliary forms as local forms,
displayed as children in the application tree.
You can add a local form by, for example, right-clicking a global form and
selecting Local Form. A global form always appears directly under the Forms node
in the application tree.
56 |
F o r m E d i t o r P re f e r e n c e s
To access Preferences for the Form Editor, choose Preferences from the File menu
and select the Forms node in the tree.
The Forms node and its child nodes, Grid Mode and Sketch Mode, includes settings
for changing the defaults for layout mode, margins, sketch grid, and layout
templates.
Form Objects
| 57
• Hold and drag to move to the new position. Blue guidelines will aid in the
positioning relative to other objects.
• In sketch layout mode, you can also use the keyboard arrow keys to move
objects. Use Ctrl+arrow keys to fine tune the position.
In the figures below, a Plot button is being moved from its original position. Blue
guide lines show its alignment relative to the unit objects and the Compute button.
58 |
You can copy-paste an object by pressing Ctrl+C and Ctrl+V. Alternatively, you
can right-click an object to get menu options for Copy, Duplicate, Delete, and more.
To paste an already copied object, right-click an empty area in the form and
right-click again. Depending on the copied object, a Paste menu option will be
shown. In the figure below, an Input Field has previously been copied and as a
result, a Paste Input Field option is shown.
| 59
A DJUSTING P OSITION AND S IZE BY THE N UMBER OF P IXELS
When in sketch layout mode, you can adjust the position and size of an object by
typing the number of pixels in the Position and Size section of its Settings window:
• Click an object to select it. Make sure its Settings window is shown. If not,
double-click the object or click the Settings button in the Form tab.
• Edit the numbers in the Position and Size section.
The Position and Size section will have different options depending on the type of
form object. For grid layout mode, there are additional settings for the position of
the object with respect to rows and columns. For details, see “Sketch and Grid
Layout” on page 112.
60 |
In the figure below, the Settings window for a text label object is shown.
By using grid layout mode (see “Sketch and Grid Layout” on page 112) you can
gain further control over the size of form objects, such as setting an arbitrary size
for a button.
| 61
the most common form objects: Input Field, Button, Check Box, Text Label, Data
Display, and Graphics.
Additional form objects are available from the More Objects menu button.
The remainder of this section, The Form Editor, only describes the types of form
objects that are added by the Form Wizard. The form objects added by using the
wizard may include:
• Button
• Graphics
• Input Field
• Text Label (typically associated with Input Field)
• Unit (typically associated with Input Field)
• Data Display
62 |
However, when using Data Access (see page 106), the additional form objects may
be added, including:
• Check Box
• Combo Box
For more information on the check box, combo box, and other form objects, see
“Appendix A — Form Objects” on page 232.
The Editor Tools window is an important complement to the Form Wizard and the
Insert Object menu for quickly creating composite form objects. To display the
Editor Tools window, click the corresponding button in the Main group in the Form
tab.
| 63
You can right-click the nodes in the editor tree to add the same set of form objects
available with the Form Wizard.
When a node is selected, the toolbar below the editor tree shows the available
options for inserting an object. You can also right-click for a list of these options.
Depending on the node, the following options are available:
• Input
An Input Field, Check Box, Combo Box, or File Import object is inserted as follows:
- Inserts an Input Field using the selected node as Source. It is accompanied by
a Text Label and a Unit object, when applicable.
- Inserts a Check Box using the selected node as Source.
- Inserts a Combo Box using the selected node as Source. A choice list is
automatically created, corresponding to the list in the node. This option is
only available when used with Data Access (see page 106) to make the
corresponding node available in the editor tree.
- Inserts a File Import object using the selected node as File Destination.
64 |
• Output
- Inserts a Data Display object accompanied by a Text Label when applicable.
- Inserts a Results Table object when the selected node is a Table.
• Button
- Inserts a Button object with a command sequence running the selected node.
• Graphics
- Inserts a Graphics object using the selected node as Source for Initial Graphics
Content.
• Edit Node
- Brings you to the Settings window for the corresponding model tree node.
The Editor Tools window is also an important tool when working with the
Method Editor. In the Method Editor, it is used to generate code associated with
the nodes of the editor tree. For more information, see “Editor Tools in the
Method Editor” on page 187.
Button
| 65
• Add a Tooltip with text that is shown when hovering over the button.
• Add a Keyboard shortcut by clicking the input field and entering a
combination of the modifier keys Shift, Ctrl, and Alt together with another
keyboard key. Alt must be accompanied by at least one additional modifier.
Note that the settings for a ribbon button, defined as Item in a Ribbon Section, are
very similar to that of a button.
66 |
C HOOSING C OMMANDS TO R UN
The section Choose Commands to Run lets you control the action associated with a
button-click event. The figure below shows the Settings window for a button that
triggers a sequence of four commands.
A menu, ribbon, or toolbar item will also provide a Choose Commands to Run
section in its Settings window, and the functionality described in this section
applies. For more information on using menu, ribbon, and toolbar items, see
“Graphics Toolbar” on page 84, “The Main Window Editor” on page 136,
“Table” on page 307, and “Toolbar” on page 318.
To define a sequence of commands, in the Choose Commands to Run section, select
a node in the editor tree. Then click one of the highlighted buttons under the tree,
or right-click and select the command. In the figure below, the Geometry node is
selected and the available commands Run and Plot are highlighted. Click Run to
add a geometry-building command to the command sequence. Click Plot to add
| 67
a command that first builds and then plots the geometry. The option Edit Node
will take you to the corresponding node in the model tree or the application tree.
The command icons highlighted for selection are those applicable to the particular
tree node. This is a list of the command icons that may be available, depending
upon the node:
• Run
• Plot
• Set Value
• Show
• Show as Dialog
• Import File
• Enable
• Disable
Some commands, such as the various plot commands, require an argument. The
argument to a plot command, for example, defines which of the different graphics
objects the plot should be rendered in.
68 |
The example below shows the Settings window and command sequence for a
Compute button as created by the Form Wizard. This button has a command
sequence with two commands: Compute Study 1 and Plot Temperature.
| 69
To add or edit an input argument, click the Edit Argument button below the
command sequence, as shown in the figure below.
70 |
C ONVERTING A C OMMAND S EQUENCE TO A M ETHOD
A sequence of commands can be automatically converted to a new method, and
further edited in the Method Editor, by clicking Convert to Method.
| 71
You can also create a method that is local to a form or form object by
clicking Convert to Form Method or Convert to Local Method, respectively.
The method contains calls to built-in methods corresponding to the
commands in the commend sequence, as shown in the figure below.
runs the model tree node corresponding to the first study std1 (the first study
node is called Study 1 unless changed by the user). The second and third lines:
useGraphics(model.result("pg2"), "form1/graphics1");
useGraphics(model.result("pg1"), "form1/graphics2");
72 |
page 106). The figure below shows a command sequence used to initialize a set of
model parameters and a string variable.
To learn how to perform the same sequence of operations from a method, select
Convert to Method under the command table.
| 73
In the section Choose Commands to Run, you can select the Show command. The
figure below shows the command sequence for a button with a command Show
form3.
This command will leave the form associated with the button and make the
specified form visible to the user.
74 |
With these settings, clicking the button in the application will launch the following
dialog box corresponding to form2:
The form2 window in this example contains a text label object and an OK button,
as shown in the figure below.
In the Settings window, the Dialog Actions section has two check boxes:
• Close dialog
• Store changes
In the example above, the Close dialog check box is selected. This ensures that the
form2 window is closed when the OK button is clicked. Since form2 does not have
any user inputs, there is no need to select the Store changes check box.
Typical dialog box buttons and their associated dialog actions are:
| 75
A dialog box blocks any other user interaction with the application until it is
closed.
In order to control when data entered in a dialog box is stored, there is a list in
the Dialog Settings section of the Settings window of a form where you can select
whether to store data On request or Immediately when the change occurs, as shown
in the figure below.
When the Store changes option On request is selected, the variables that have been
changed by the user in the dialog box will not be updated until the OK button (or
similar) in the dialog box has been clicked. This requires that the check box Store
changes is selected, in the Settings window of the OK button. When the option
Immediately is selected, variables changed by the user in the dialog box is updated
immediately including while the dialog box is still open.
When Vertically scrollable is cleared, the form will never get any vertical scrollbar.
Instead, the scrollbar will appear on the form objects inside the form, if possible.
To obtain a satisfactory result, the form has to be created in grid mode. The form
object which should get the scrollbar must be in a row with setting Grow Row and
its alignment set to Fill Vertically.
76 |
A PPEARANCE
In the Settings window for a button, the Appearance section contains font settings
as well as settings that control the state of the button object.
Graphics
Each Graphics object gets a default name such as graphics1, graphics2, etc.,
when it is created. These names are used to reference graphics objects in command
| 77
sequences for buttons, menu items, and in methods. To reference graphics objects
in a specific form, use the syntax: form1/graphics2, form3/graphics1, etc.
In addition to Results plot nodes, you can also use Animation, Selection, Geometry,
and Mesh nodes as the Selected source.
Selecting the check box Zoom to extents on first plot ensures that the first plot that
appears in the graphics canvas shows the entire model (zoom extents). This action
is triggered once the first time that graphics content is sent to the graphics object.
In the section Data Picking, below Source for Initial Graphics Content, selecting the
check box Enable data picking makes the graphics object interactive so that you
can, for example, click on a plot at a particular point and retrieve a numerical value
for the temperature at that coordinate. For more information, see “Data Picking”
on page 93.
78 |
A PPEARANCE
For a graphics object, the Appearance section of the Settings window has the
following options:
• Include an Icon, such as a logo image, in the upper-right corner.
• Set the background Color for 2D plots.
• Set a flat or graded background color for 3D plots by choosing a Top color
and Bottom color.
In addition, the subsection State contains settings for the visible and enabled state
of the graphics object. For more information, see “Changing the Enabled and
Visible State of a Form Object” on page 77.
| 79
The figure below shows an application where the background Top color is set to
white and the Bottom color to gray. In addition, the standard plot toolbar is not
included.
80 |
G RAPHICS C OMMANDS
In the editor tree used in a command sequence of, for example, a button, the
Graphics Commands folder contains commands to process or modify a graphics
object. The figure below shows a command sequence with one command for
printing the contents of a graphics object.
| 81
• Print
- Prints the contents of the graphics object.
• Select All
- Selects all objects.
• Clear Selection
- Clear the selection of all objects.
• Show Selection Colors
- Enable visualization of selection colors.
• Show Material Color and Texture
- Enable visualization of material color and texture.
Note that the many of these commands have corresponding toolbar buttons in the
standard graphics toolbar. See the next section “Graphics Toolbar”.
You can include a method that calls the built-in sleep method for briefly
displaying graphics information before switching to displaying other types of
82 |
graphics. Insert it in a command sequence after a plot command, as shown in the
figure below.
For more information on the method sleep, see “sleep” on page 358.
In the command sequence above, the Plot Velocity command comes before the
Compute Study command. This ensures that the graphics object displays the
velocity plot while solving.
| 83
The example code below switches plot groups by reusing the same graphics object,
based on the value of a Boolean variable.
if (my_boolean) {
useGraphics(model.result("pg1"), "form1/graphics1");
my_boolean=!my_boolean; // logical NOT to change between true and false
} else {
useGraphics(model.result("pg2"), "form1/graphics1");
my_boolean=!my_boolean;
}
which clears the contents of the graphics object graphics1 in the form form1.
G RAPHICS T OOLBAR
The type of tree node used in the Source for Initial Graphics Content determines the
type of toolbar that is shown. The toolbar will be different depending on the space
dimension and whether the referenced source is a Geometry, Mesh, Selection, or
Plot Group node. For example, the Plot Group node displays an additional Show
Legends button.
In the Settings window of a graphics object, in the Toolbar section, you can control
whether or not to include the graphics toolbar, as well as its position (Below,
Above, Left, Right). In addition, you can choose between the options Small or Large
for Icon size, Background color, and whether to Include standard toolbar items or
not.
84 |
Graphics Toolbar for Geometry and Mesh
The figure below shows the standard graphics toolbar as it appears when the
Geometry or Mesh node, for a 3D model, is used as a Source for Initial Graphics
Content.
If the Source for Initial Graphics Content is set to an Animation node, then additional
buttons for playing the animation are added to the graphics toolbar, as shown in
the figure below.
| 85
The figure below shows the corresponding settings and table of graphics toolbar
items.
86 |
To edit the command sequence for a toolbar item, click the Edit button to open
the Edit Custom Toolbar Item dialog box.
This dialog box has settings that are similar to those of a button or a toolbar item
with the contents divided into two or three tabs depending on if the item is a
toggle item or not. For details, see “Button” on page 65 and “Toolbar” on page
318.
Views
In the graphics toolbar of an application, the Go to Default View button (for 3D
graphics only) will reset the current view to the default view. If you click the arrow
| 87
next to this button, a menu will be displayed with all applicable views. The
currently active view is indicated with a check mark.
In addition to a list of all views, there is an option Reset Current View that will reset
the currently active view to the state it had when the application was launched.
A NIMATIONS
You can display animations in an application by using a Results > Animation node
as the Source for Initial Graphics Content.
88 |
To run the animation, use the Form Wizard or the Editor Tools window to create
a command from, for example, a button that runs a Results > Animation node.
When using the Form Wizard or Editor Tools, the animation button will have the
following default appearance:
| 89
S ELECTIONS
90 |
shows an Explicit selection given the name Inlet Boundaries with an associated
boundary (1).
The figure below shows the Settings window for an Inlet boundary condition
where the Inlet Boundaries selection is used. In this example, there is also an Outlet
Boundaries selection.
For convenience, in addition to the Manual option, there is also a shortcut for All
boundaries.
| 91
Selections in the Application Builder
The Explicit selections, created under Definitions, or by geometry or mesh
sequences, let you group domains, boundaries, edges, or points based on entity
number, and the example below illustrates how to work with this type of selection.
Explicit selections can be made interactive in an application, but other types of
selections, such as a coordinate-based Box selection, are shown in read-only mode.
You can allow the user of an application to interactively change which entities
belong to an Explicit selection with a Selection Input object or a Graphics object. In
the example below, the embedded model has a boundary condition defined with
an Explicit selection. Both a Selection Input object and a Graphics object are used
to let the user select boundaries to be excited by an incoming wave.
The user can here select boundaries by clicking directly in the graphics window,
corresponding to the Graphics object, or by adding geometric entity numbers in a
list of boundary numbers corresponding to a Selection Input object.
To make it possible to directly select a boundary by clicking on it, you can link a
graphics object to an Explicit selection, as shown in the figure below. Select the
Explicit selection and click Use as Source. In the figure below, there are two Explicit
92 |
selections, Excitation Boundary and Exit Boundary, and the graphics object
graphics2 is linked to the selection Excitation Boundary.
When a graphics object is linked directly to a selection in this way, the graphics
object displays the geometry and the user can interact with it by clicking on the
boundaries. The boundaries will then be added (or removed) to the
corresponding selection.
To make it possible to select by number, you can link a Selection Input object to
an explicit selection. For more information, see “Selection Input” on page 298.
The Editor Tools window provides a quick way of adding a Graphics object or a
Selection Input object that is linked to an Explicit selection. To get these options,
right-click an Explicit selection node in the editor tree.
You can let a global Event be triggered by an Explicit selection. This allows a
command sequence or method to be run when the user clicks a geometry object,
domain, face, edge, or point. For more information on using global events, see
“Events” on page 148 and “Source For Data Change Event” on page 150.
For an example of how to use selections in an add-in, see the Application
Programming Guide.
D ATA P ICKING
In the Settings window for a graphics object, select the check box Data picking to
make the graphics object interactive so that you can, for example, click on a plot
at a particular point and retrieve a numerical value for the temperature at that
| 93
coordinate. In the figure below, in the section Target for Data Picking, a scalar
double variable Tvalue is selected. This variable is declared under the Declarations
node. In the running application, the value of the temperature at the pointer
position will be stored in the variable Tvalue.
If the Target for Data Picking is a 1D double array, then the stored value will instead
correspond to the x, y (2D) or x, y, and z coordinates at the clicked position.
The Target for Data Picking can be any one of the following:
• Scalar double variable
• 1D double array
• Domain Point Probe
• Boundary Point Probe
• Graphics Data declaration
For more information on Graphics Data declaration, see “Graphics Data” on page
178.
94 |
Input Field
An Input Field allows a user to change the value of a parameter or variable. In the
Form Wizard, when a parameter or variable is selected, three form objects are
created:
• A Text Label object for the parameter or variable description.
• An Input Field object for the value.
• A Unit object (if applicable) that carries the unit of measure.
By selecting a parameter or variable using the Editor Tools window, the same three
form objects are created.
Assuming you do not use the Editor Tools window: To insert an additional input
field, click the Input Field button in the Form Objects section of the ribbon Form
tab. In the Form Editor, you link an input field to a certain parameter or variable
by selecting it from the tree in the Source section and click Use as Source. In the
| 95
Source section of the Settings window, you can also set an Initial value. The figure
below shows the Settings window for an input field.
In addition to parameters and variables, input fields can use an Information node
as Source.
The default setting for the Initial value is From data source. This means that if the
source is a parameter, then the initial value displayed in the input field is the same
as the value of the parameter as specified in the Parameters node in the Model
Builder. The other Initial value option is Custom value, which allows an initial value
96 |
different from that of the source. If the Editable check box is cleared, then the
Initial value will be displayed by the application and cannot be changed. This
makes it possible to use an Input Field an alternative to, for example, a Text Label
object for displaying text.
You can add a Tooltip with text that is shown when hovering the mouse pointer
over the input field.
The header of the Source section contains buttons for easy access to tools that are
used to make additional properties and variables available as sources to the input
field.
The Create New Declaration and Use It as Source button can be used to add new
variables under the Declarations node. For more information, see “Declarations”
on page 157. The Create New Form Declaration and Use It as Source button can be
used to add new variables under the Declarations nodes local to forms, as shown
below.
The Switch to Model Builder and Activate Data Access button can be used to access
low-level model properties as described in the next section. For more information
on Data Access, see “Data Access in the Form Editor” on page 106.
| 97
D ATA V ALIDATION
The Data Validation section of the Settings window for an input field allows you to
validate user inputs with respect to units and values.
When creating an input field in the Form Wizard, the setting Append unit to
number is used when applicable. This setting assumes that a user enters a number
into the input field, but it can also handle a number followed by a unit using the
COMSOL square bracket [] unit syntax. If the Unit expression is mm, then 1[mm]
is allowed, as well as any length unit, for example, 0.1[cm]. An incompatible unit
type will display the Error message. A parameter that has the expression 1.23[mm],
and that is used as a source, will get the appended unit mm and the initial value
displayed in the edit field will be 1.23.
The Unit dimension check list has the following options:
• None
• Compatible with physical quantity
• Compatible with unit expression
• Append unit to number (default)
• Append unit from unit set
98 |
with unit expression. In addition, the user will see a tooltip explaining the unit
mismatch, as shown in the figure below.
Clicking this button will add a unit label to the right of the input field if there is
not already a unit label placed there.
The None option does not provide unit validation.
Numerical Validation
The options Append unit to number, Append unit from unit set, and None allow you
to use a filter for numerical validation of the input numbers.
The Filter list for the option None has the following options:
• None
• Double
• Integer
• Regular expression
The Filter list for the options Append unit to number and Append unit from unit set
only allows for the Double and Integer options.
| 99
The Double and Integer options filter the input based on the Lower bound and
Upper bound values. If the input is outside of these values, the Error message is
displayed. You may use global parameters in these fields. If global parameters are
used, you can define such parameters with or without units. If you use global
parameters without a unit, then only the numerical value of these parameters is
considered. For example, consider data validation of an input field for a length
parameter L with unit cm. Further, assume that a global parameter Lmax is used as
the Upper bound value. If you would like the maximum value of L to be 15 cm,
then the following values for the parameter Lmax will work: 15 (with no unit),
15[cm], 0.15[m], 150[mm], etc.
For the Append unit from unit set option, the Lower bound and Upper bound values
are always with respect to the Initial value for the unit set by the unit set. For more
information on unit sets, see “Unit Set” on page 170.
The Regular expression option, available when the Unit dimension check is set to
None, allows you to use a regular expression for matching the input string. For
more information on regular expressions, see the dynamic help. Click the help
icon in the upper-right corner of a window and search for “regular expression”.
For more advanced requirements, note that virtually any kind of validation of the
contents of an input field can be made by calling a method using the Events section
in the Settings window of an input field.
For additional information on how to use more advanced Data Validation features
and how to use method code to perform data validation, see the Application
Programming Guide.
Error Message
You can customize the text displayed by the Error message. During the
development and debugging of an application, it can sometimes be hard to deduce
from where such errors originate. Therefore, when using Test Application,
additional debugging information is displayed, as shown in the figure below.
The debugging information typically consists of the type of form object, the path
to the form object, and the reason for the failure; for example, 10<=x<=2500.
100 |
No debugging information is added when launching an application by using the
Run Application option or COMSOL Server.
N UMBER F ORMAT
The Number Format section contains a check box Use input display formatting. If
selected, it enables the same type of display formatting as a Data Display object.
A PPEARANCE
In addition to color and font settings, the Appearance section for an input field
contains a Text alignment setting that allows the text to be Left, Center, or Right
aligned.
Whether the input field should be Visible or Enabled is controlled from the check
boxes under the State subsection. For more information, see “Changing the
Enabled and Visible State of a Form Object” on page 77.
| 101
Unit
In the Settings window for a Unit object, you can set the unit to a fixed string, or
link it to an source, such as an input field. The figure below shows the Settings
window for a unit object.
When adding an input field using the Form Wizard, a unit object is automatically
added when applicable. By default, the unit is displayed using Unicode rendering.
As an alternative, you can use LaTeX rendering by selecting the LaTeX markup
check box. Then, the display of units will not depend upon the selected font.
T e x t La b e l
A Text Label object simply displays text in a form. When adding an input field using
the Form Wizard, a Text Label object is automatically added for the description
text of the associated parameter or variable. There is a check box allowing for
102 |
Multiline text. If selected, the Wrap text check box is enabled. The figure below
shows the Settings window for a Text Label object.
To insert an additional Text Label, click the Text Label button in the ribbon Form
tab, in the section Form Objects. The contents of the section Position and Size will
change depending on if you are working in sketch layout mode or grid layout
mode.
Data Display
A Data Display object is used to display the numerical values of scalars and arrays.
If there is an associated unit, it will be displayed as part of the Data Display object.
| 103
S OURCE
In the Settings window for a data display object, in the Source section, select a
node in the model tree. Then click the Use as Source button shown below. Valid
parameters, variables, and properties include:
• The output from a Derived Values node, such as a Global Evaluation or a Volume
Maximum node
• Variables declared under the Declarations > Scalar, 1D Array, and 2D Array
nodes
• Properties made available by using the Data Access tool; See “Data Access in
the Form Editor” on page 106
• One of the following Information node variables, which are under the root
node and under each Study node:
- Expected Computation Time
This is a value that you enter in the Expected field in the Settings window of
the root node.
- Last Computation Time (under the root node)
The is the last measured computation time for the last computed study.
- Last Computation Time (under a study node)
This is the last measured computation time for that study.
When you start an application for the first time, the last measured times are
reset, displaying Not available yet.
The settings for these form objects can subsequently be edited. To insert
additional data display objects, use the Insert Object menu in the ribbon and select
Data Display.
N UMBER F ORMAT
The Number Format section lets you set the Precision, Notation, Exponent, and Unit.
104 |
The figure below shows an example with data display objects for the variables Coil
resistance and Coil inductance. A formatted unit label is automatically
displayed as part of the object if applicable.
R ENDERING M ETHOD
By default, the unit of a data display object is displayed using Unicode rendering.
As an alternative, you can use LaTeX rendering by selecting the LaTeX markup
check box. Then, the data display does not rely on the selected font.
A formatted display of arrays and matrices is only supported with LaTeX
rendering. The figure below shows a 2D double array (see page 165) displayed
using a Data Display object with LaTeX markup selected.
| 105
You can add a Tooltip with text that is shown when hovering over the data display
object.
The Settings window of many types of form objects has a section that allows you
to select a node in a tree structure that includes the model tree, or parts of the
model tree, and parts of the application tree. Examples include the Source section
of an input field or the Choose Commands to Run section of a button. There are
many properties in the model and application trees that are not made available by
default, because there may be hundreds or even thousands of properties, and the
full list would be unwieldy. However, these “hidden” properties may be made
available to your application by a technique called Data Access.
The remainder of this section gives an introduction to using Data Access, with
examples for input fields and buttons.
You can also access it from the Application group of the Developer tab in the Model
Builder workspace
106 |
Then, when you click on a model tree node, check boxes appear next to the
individual settings. In the figure below, the check box for an Electric potential
boundary condition is selected:
| 107
The figure below shows the Settings window for an input field. The list of possible
sources for this field now contains the Electric potential.
In addition, as seen in the figure above, Data Access makes it possible to access the
check box Editable and the Tooltip text of the input field form object. In addition
to the settings of the Model Builder, Data Access lets you access certain properties
of the Application Builder.
Data Access can be used for buttons to set the value of a parameter, variable, or a
model property. For example, you can create buttons for predefined mesh element
sizes. The settings shown in the figure below are available when, in the Settings
window of the Mesh node, the Sequence type is set to User-controlled mesh. In this
108 |
example, the Predefined property for Element Size has been made available and then
selected.
| 109
The figure below shows the Settings window for a button used to create a mesh
with Element Size > Predefined set to Fine.
In the above example, a Set Value command is used to set the value of the
Predefined mesh size (hauto) property. The property Predefined mesh size (hauto)
corresponds to the following settings in the Size node shown earlier:
Extremely fine 1
Extra fine - Extra coarse 2-8
Extremely coarse 9
The value of the hauto property is a double and can take any non-negative value.
For non-integer values, linear interpolation is used for the custom mesh
110 |
parameters. You can, for example, let a slider object adjust the predefined mesh
size. For more information on the slider object, see “Slider” on page 312.
In general, for individual model tree properties, you can quickly learn about their
allowed values by recording code while changing their values and then inspecting
the automatically generated code. For more information, see “Recording Code”
on page 191.
You can also use a combo box object to give direct access to all of the options from
Extremely fine through Extremely coarse. For more information, see “Combo Box”
on page 239.
| 111
A global event, menu, ribbon, or toolbar item provides a Choose Commands to Run
section in its Settings window, to which the functionality described above in the
section on buttons also applies. Global events and many form objects provide a
Source section in its Settings window, and the functionality described above in the
section on input fields applies. For information on global events, menus, ribbons,
and toolbar items, see “Graphics Toolbar” on page 84, “The Main Window
Editor” on page 136, “Events” on page 148, “Table” on page 307, and
“Toolbar” on page 318.
The Form Editor provides two layout modes for positioning form objects: sketch
layout mode and grid layout mode. The default is sketch layout mode, which lets
you use fixed positions and sizes of objects in pixels. Use grid layout mode to
position and size objects based on a background grid with cells. In grid layout
mode, a form is divided into a number of intersecting rows and columns, with
at most one form object at each intersection. This layout mode is recommended
for designing a resizable user interface, such as when designing an application to
be run in a web browser on multiple platforms.
S KETCH L AYOUT
Switch between sketch and grid layout mode by clicking Sketch or Grid in the
Layout group in the ribbon Form tab.
112 |
The Sketch group in the Form tab has two options: Show Grid Lines and Arrange.
The Arrange menu allows you to align groups of form objects relative to each
other.
Sketch Grid
The Show Grid Lines option displays a sketch grid to which objects are snapped.
Note that the grid used in sketch layout mode is different from the grid used in
grid layout mode. The default setting for sketch layout mode is to show no grid
lines. Without grid lines visible, a form object being dragged is snapped relative to
the position of the other form objects.
If the Show Grid Lines option is selected, the upper left corner of a form object
being dragged is snapped to the grid line intersection points.
| 113
In the Settings window of the form, you can change the settings for the sketch
grid:
• Column width
• Row height
• Align grid to margin
• Snap zone
- A slider allows you to change the snap zone size from Small to Large
• Snap only to grid
- Clear this check box to snap both to the grid and the position of other form
objects
Form objects are allotted as much space as required or as specified by their Width
and Height values. Form objects are allowed to overlap, when working in sketch
layout mode.
114 |
Button and toggle button form objects have an Automatic and Manual option for
the Width and Height values. The Manual option allows for pixel-based input and
the Automatic option adapts the size of the button to the size of the Text string.
G RID L AYOUT
Switch to grid layout mode by clicking Grid in the Layout group in the ribbon.
The buttons and menus in the ribbon Grid group give you easy access to
commands for:
• Changing the row and column growth rules between Fit, Grow, and Fixed,
which determine the layout when the user interface is resized (Row Settings
and Column Settings).
• Inserting or removing rows and columns ( Insert and Remove).
• Aligning form objects within grid cells (Align).
• Merging and splitting cells (Merge Cells and Split Cells).
• Extracting a rectangular array of cells as a subform and inserting it into a new
form (Extract Subform).
• Defining the number of rows and columns (Rows & Columns).
| 115
The Form Settings Window and the Grid
After switching to grid layout mode, the form window shows blue grid lines.
To define the number of rows and columns, click the Rows & Columns button in
the ribbon.
116 |
The section Grid Layout for Contained Form Objects in the Settings window shows
column widths and row heights.
To interactively select a form, as displayed in the Form Editor, click the top-left
corner of the form.
A blue frame is now shown. To interactively change the overall size of a form, you
can drag its right and bottom border. The form does not need to be selected for
this to work.
Note that if you switch from sketch to grid layout mode, all rows and columns will
have the setting Fit and the handles for the frame will not be displayed. If any of
the rows and columns have the Height or Width setting set to Grow, then the frame
will display handles for resizing in the vertical or horizontal direction, respectively.
| 117
The size of the interactively resized frame will affect the initial size of the form only
if the Initial size setting is set to Automatic. The size of the frame will also affect the
initial size of the Main Window if its Initial size setting is set to Use main form’s size.
118 |
Similarly, to select a column, click the cell at the top. This cell cannot contain any
form objects. The figure below shows the third column highlighted. In this case,
the Column Settings menu is enabled in the ribbon tab.
The Row Settings and the Column Settings have the same three options:
• Fit sets the row height or column width to the smallest possible value given
the size of the form objects in that row or column.
• Grow sets the row height or column width to grow proportionally to the
overall size of the form.
• Fixed sets a fixed value for the number of pixels for the row height or column
width.
You can interactively change the row height and column width by dragging the
grid lines.
In this case, the number of pixels will be displayed and the Row Settings or Column
Settings growth policy will be changed automatically to Fixed.
| 119
As an alternative to changing the Row Settings or Column Settings from the ribbon,
you can right-click in a row or column (the light-blue area to the left or at the top
of the form) and select from a menu.
The menu shown when right-clicking a row or column also gives you options for
inserting, removing, copying, pasting, and duplicating rows or columns.
Cells
Click an individual cell to select it. A selected cell is shown with deeper blue grid
lines.
You can select Merge Cells and Split Cells to adjust the cell size and layout of your
form objects.
120 |
When in grid layout mode, you can specify the margins that are added between
the form object and the borders of its containing cell.
In the Settings window of a form object, the Position and Size section has the
following options for Cell margin:
• None
- No cell margins
• From parent form (default)
- The margins specified in the Settings window of the form; See “Inherit
Columns and Cell Margins” on page 127
• Custom
- Custom margins applied only to this form object
If the Horizontal alignment or Vertical alignment is set to Fill and the growth policy
of the column or row allows the form object to be resized, then you can specify a
minimum width or height, respectively. The minimum size can be set to Manual
or Automatic. The Manual option lets you specify a pixel value for the minimum
size. The Automatic option allows for a minimum size of zero pixels, unless the
form object contents require a higher value. The minimum size setting is used at
runtime to ensure that scroll bars are shown before the form object shrinks below
its minimum size.
Depending on the type of form object contained in a cell, the Width and Height
values can be set to Automatic or Manual, as described in “Position and Size” on
page 114.
You can click and drag a rubber box to select multiple cells.
| 121
Aligning Form Objects
The Align menu gives you options for aligning form objects within a cell. You can
also let a form object dynamically fill a cell horizontally or vertically.
As an alternative, you can right-click a form object and select from a context menu.
122 |
Drag and Drop Form Objects
You can drag and drop form objects to move them. Click a form object to select
it, and then drag it to another cell that is not already occupied with another form
object.
If you drop the object in an already occupied cell, then the objects switch places.
| 123
access. Then, change the Height setting in the Settings window of the form.
Alternatively, right-click and select Grow Row.
• Change the Width for any column covering the graphics object to Grow. To
change this, right-click the uppermost row of the column you would like to
access and select Grow Column.
• Select the graphics object and change both the Horizontal alignment and
Vertical alignment to Fill. You can do this from the Settings window or by
124 |
right-clicking the graphics object and selecting Align > Fill Horizontally and
Align > Fill Vertically.
Following the steps above, you may find it easier to make graphics objects
resizable by performing grid layout mode operations, such as adding empty rows
and columns as well as merging cells. If you are already in grid layout mode, then
a graphics object will default to Fill in both directions.
Extracting Subforms
You can select a rectangular array of cells in a form and move it to a new form.
First, select the cells by using Ctrl+click or Shift+click.
| 125
This operation creates a new form with the selected cells and replaces the original
cells with a form object of type Form. In the Settings window of the subform, the
Form reference points to the new form containing the original cells.
126 |
Inherit Columns and Cell Margins
By using subforms, you can organize your user interface, for example, by grouping
sets of input forms. The figure below shows part of a running application with two
subforms for Beam dimensions and Reinforcement bars.
For more information on adding subforms to a form, see the previous section and
“Form” on page 276.
When aligning subforms vertically, as in the example above, you may want to
ensure that all columns are of equal width. For this purpose, you can use the
Inherit columns option in the Settings window of a subform. The figure below
shows part of the Settings window for the Beam dimensions subform (left) with
Name geometry_beam and for the Reinforcement bars subform (right) with Name
| 127
geometry_rebars. The geometry_rebars subform has its Inherit columns set to
geometry_beam.
In the subsection Cell margins, you can specify the Horizontal and Vertical margins
that are added between form objects and the borders of their containing cells.
These settings will affect all form objects contained in the form, with their
individual Cell margins set to From parent form; See “Cells” on page 120.
128 |
Show Errors
When using the Form Editor or Main Window Editor, there is a toggle button
Show Errors in the ribbon.
When enabled, any object that is in an error or warning state, for example, a
missing source for an input field object, will show an icon in the corner of that
object. This makes it easy to locate errors in a form or main window design. By
default, the Show Errors button is disabled.
You can copy and paste forms and form objects between multiple COMSOL
Multiphysics sessions running simultaneously. You can also copy and paste within
one session from the current application to a newly loaded application.
In grid layout mode, a cell, multiple cells, entire rows, and entire columns may be
copied between sessions.
When you copy and paste forms and form objects between applications, the copied
objects may contain references to other forms and form objects. Such references
may or may not be meaningful in the application to which they are copied. For
more information on the set of rules applied when pasting objects, see “Appendix
B — Copying Between Applications” on page 321.
When copying and pasting between applications, a message dialog box will appear
if a potential compatibility issue is detected. In this case, you can choose to cancel
the paste operation.
| 129
Using Forms in the Model Builder
Forms without graphics form objects can be used in the Model Builder. You can
use this functionality to create customized Settings windows for, for example,
common or repetitive tasks.
To use a form, right-click Global Definitions and select the form under Settings
Forms.
You can control whether a form should be visible or not in the Model Builder as
a Settings Form via the check box Show in Model Builder. This check box is available
in the Application Builder in the Settings window of the corresponding form.
130 |
Once added to the model tree, the form is shown as a Settings window, shown in
the figure below.
For reusing a Settings Form between sessions, you can create an Add-in. For more
information, see “Creating Add-Ins” on page 222.
| 131
Inputs
When starting an application from the operating system command line, you can
provide input arguments. In the application tree, you specify such input
arguments under the Inputs node.
132 |
application in Windows®, an input argument freq is given that takes a (double)
value 400.
| 133
Alternatively, you can copy and paste the COMSOL Multiphysics 6.1 Windows®
Desktop shortcut icon (in order to keep the original shortcut), right-click the
icon, and select Properties; as shown in the figure below.
You can, for example, modify the Target text field to be:
"C:\Program Files\COMSOL\COMSOL61\Multiphysics\bin\win64\comsol.exe" -run
myapp.mph -appargnames freq -appargvalues 400
To provide input arguments with special characters, you need to use single quotes.
The following example of a compiled application shows how to provide a file path,
such as for a configuration file, as an input argument:
myapp.exe -appargnames configfile -appargvalues 'C:\\COMSOL\\my_conf.dat'
For COMSOL Server, you can provide the arguments directly in the address field
of your browser (URL); for example:
http://<host:port>/app/myapp_mph?appargnames=freq&appargvalues=400
You can also use a file declaration as an input argument. This is useful, for example,
when you want to let users supply input files. For example:
comsol.exe -run file_arguments.mph -appargnames interpfile -appargvalues
'C:\data\functions\simpleinterp.txt'
134 |
This example uses an application argument interpfile, which is linked to a file
declaration to read the interpolation file simpleinterp.txt when launching the
application. This file is then used in an interpolation function in the application’s
embedded model.
| 135
The Main Window Editor
In the application tree, the Main Window node represents the main window of an
application and is also the top-level node for the user interface. It contains the
window layout, the main menu specification, and optional ribbon, and
subwindow specifications. The Main Window Editor, visible whenever the Main
Window node is active, lets you design menu bars, ribbon tabs, and subwindows.
G ENERAL
The Settings window contains a General section with the following settings:
• Title
• Show filename in title
• Icon
• Menu type
• Main window type
• Status bar
The Title is the text at the top of the main window in an application, with the Icon
shown to the far left of this text. By default, the Title is the same as the title of the
model used to create the application. Keep the check box Show filename in title
selected if you wish to display the file name of the application to the left of the
Title.
In the Icon list, select an image from the library or add an image (*.png) from
the local file system to the library and use it as an icon. If you add a new image,
it will be added to the image library and thereby embedded into the application.
You can also export an icon by clicking the Export button to the right of the Add
Image to Library and Use Here button.
136 |
The Main Window node of the application tree has one child node, named Menu
Bar. Using the Menu type setting, you can change this child node from Classic menu
to Ribbon.
The Main window type setting lets you select the type of application layout:
Subwindows or Single window. The Subwindows option makes it possible to
organize forms into subwindows that, while the application is running, can be
detached and docked.
The Status bar list controls what is shown in the status bar. From the list, select
the Progress option to display a progress bar, otherwise, select None. Note that you
can also create custom progress bars by writing method code.
M AIN F ORM
The Main Form section is visible if the Main window type is set to Single window. It
contains a reference to the form that the main window displays.
W INDOW L AYOUT
The Window Layout section is visible if the Main window type is set to Subwindows.
Subwindows can be defined in the lower part of the Main Window Editor. You
work with subwindows in a way that is similar to forms when in grid mode. For
more information, see “Subwindows” on page 145.
| 137
S IZE
In the Size section, the Initial size setting determines the size of the main window
when the application is first started.
A BOUT D IALOG
The About Dialog section contains settings for customizing parts of the About This
Application dialog box, which contains legal information.
The Placement option lets you choose between Automatic, File menu, Ribbon,
Lower-right corner, or Lower-left corner. The Lower-right corner and Lower-left
corner options will place a hyperlink referencing the About This Application dialog
138 |
box in the corresponding corner of the application user interface. If selected, the
Show COMSOL information check box will display the COMSOL software version
and product information. Any text entered in the Custom text field will be
displayed above the legal text in the dialog box. In the Custom text field, words
containing https or www will be interpreted as hyperlinks, if possible. For example,
https://www.comsol.com or www.comsol.com will be replaced with a hyperlink.
L ANGUAGE L OCALIZATION
The Language Localization section contains settings for the localization of the
application.
| 139
M e n u B a r a n d T o o l b ar
The Menu Bar node can have Menu child nodes that represent menus at the top
level of the Main Window.
For the Menu Bar option, you can also add a Toolbar node. The Toolbar node and
the Menu nodes have the same type of child nodes.
140 |
M ENU , I TEM , AND S EPARATOR
The child nodes of the Menu and Toolbar nodes can be of type Menu, Item, Toggle
Item, or Separator, exemplified in the figure below:
A Menu node can have child Menu nodes that represent submenus.
A Separator displays a horizontal line between groups of menus and items, and has
no settings.
The Settings window for an Item node is similar to that of a button and contains a
sequence of commands. Just like a button, an item can have associated text, an
icon, and a keyboard shortcut. For more information, see “Button” on page 65.
In a similar way, the Settings window for a Toggle Item node is similar to that of a
toggle button.
| 141
The figure below shows the Settings window for an Item associated with a method
for saving an application using the command Save Application As.
You can enable and disable ribbon, menu, and main toolbar items from methods.
For more information, see “Appendix E — Built-In Method Library” on page
347.
R ibbon
You can opt to add a Ribbon node to the Main Window instead of a Menu Bar. The
Ribbon node contains the specifications of a ribbon with toolbars placed on one or
142 |
several tabs. For the Ribbon option, a File menu is made available directly under the
Main Window node.
| 143
Interactive Editing of Menus and Ribbon Tabs
When creating menu and ribbon items, you can interactively position them in the
Main Window Editor by dragging.
You can right-click the Main Window Editor, for example, a ribbon section, and
add additional items from a context menu.
144 |
Subwindows
You can organize your forms and form collections into subwindows that can be
resizable and detachable. In the Main Window node, if you change the Main window
type to Subwindows, the lower part of the Main Window Editor becomes a
workspace for the layout of subwindows.
Note that the New Form Wizard templates Basic and Subwindows will create
applications containing subwindows.
| 145
The Window Layout section is visible if the Main window type is set to Subwindows.
Working with subwindows is similar to working with forms in grid mode. You can
insert columns to the left and to the right of existing columns. Rows can also be
added above and below existing rows, and rows and columns can be deleted. Grid
cells can be merged and then split again. On the ribbon of the Main Window
Editor, there is a Rows & Columns button that enables you to quickly create a layout
with a specified number of rows and columns.
The sizes of the rows and columns can be specified interactively by dragging. They
can also be specified manually in the Window Layout section, in the Settings
window of the Main Window.
The column width and row height settings are not interpreted as absolute width
and height, but rather summed together, and each individual row and column size
is then interpreted as a fraction of the total size. A percentage value is displayed in
the column and row headers in the Subwindows layout area.
The Allow dragging between subwindows setting controls whether forms can be
dragged and moved between the different parts of the subwindow area.
The Show form header in subwindows with a single form setting controls whether
to the forms, which are alone in a subwindow, should have a header. This setting
is only available when dragging between subwindows is disabled.
Only one type of object can be placed in each of the grid cells used to define the
window layout. This is called a subwindow object and is automatically added to a
146 |
grid cell as soon as it is created. The Settings window for a subwindow object is
shown in the figure below.
This Settings window makes it possible to set which forms that are open in
different subwindows. In the table below the model tree in the Forms section, you
can specify if the form is Initially open in the subwindow, if it is Closeable, and if it
is Vertically scrollable. A form that is Closeable will have a cross icon in the window
title for closing it.
Since a form can only be shown in one subwindow, the Forms section, containing
the available forms, is filtered to only show forms that have not yet been added to
a subwindow. Also, the Forms section only shows global forms and not local forms.
When starting an application, each form that has been added to the Forms section,
and where the check box in the Initially open column is selected, is shown in the
corresponding subwindow. The Title of the form is used as the title on the
corresponding tab.
The Default form setting specifies which form is initially active in the subwindow
when launching the application.
| 147
Events
148 |
Events at Startup and Shutdown
A method run at a shutdown event can, for example, automatically save critical
data or prompt the user to save data. In addition, a method run at a shutdown
event may cancel the shutdown by returning a Boolean true value.
Global Events
Right-click the Events node and choose Event to add an event to an application.
An event listens for a change in a running application. If a change occurs, it runs
| 149
a sequence of commands. In the figure below, when the value of the string variable
SpanWidth is changed, the method setResultsStatus is run.
Note that since this type of event has global scope and is not associated with a
particular form, the full path: /form1/graphics1 needs to be used when
referencing graphics objects.
The following two sections describe the options available in the Settings window
of an event.
150 |
You can extend the list of available data nodes by clicking on the Switch to Model
Builder and Activate Data Access button in the header of the section Source For Data
Change Event.
For more information, see “Data Access in the Method Editor” on page 189.
Note that Explicit selections are also allowed as Source for Data Change Event. This
allows a command sequence or a method to be run when the user clicks a
geometry object, domain, face, edge, or point. The figure below shows a dialog
| 151
box for a global event that opens a form panel as a dialog box when the user
changes the contents of the Explicit selection named Outlet Boundaries.
C HOOSE C OMMANDS TO R UN
In the Settings window for an Event, the section Choose Commands to Run is similar
to that of a button and allows you to define a sequence of commands. For more
information, see “Button” on page 65.
152 |
F o r m a n d F o r m O b j e ct E v e n t s
Form and form object events are similar to global events, but are defined for forms
or individual form objects. These events can have an associated list of commands
in a command sequence, or refer directly to a global, form, or local method.
The drop-down list On data change contains None (the default), any available
methods under the Methods node of the application tree or under the Methods
node of the corresponding form, and a local method or command sequence
(optional).
The form objects supporting this type of event are:
• Input Field
• Check Box
• Combo Box
• Graphics
• File Import
• Array Input
• Radio Button
• Text
• List Box
• Table
• Slider
| 153
Buttons have associated events triggered by a click. Menu, ribbon, and toolbar
items have associated events triggered by selecting them. The corresponding
action is a command sequence defined in the Settings window of a button object
or item. Note, however, that such command sequences can also be used to run
methods. For more information on command sequences, see “Button” on page
65.
I NPUT A RGUMENTS
Clicking Create Global Method or Create Form Method will open a dialog box where
you can edit the name of the method to be created. Clicking Create Local Method
will create a local method with an automatically created name indicating the form
and type of event, see “Local Methods” on page 204. The method so created has
a first argument called newValue which is based on the form object type. The
argument added to the method will contain the new value in the form object when
the event is triggered. The newly created method is also selected in the application
tree and opened in the editor area.
For example, assume that you create a method based on an input field that links
to a global parameter, as shown in the figure below.
154 |
The Settings window for the method created in this way is shown in the figure
below.
The variable newValue will then contain the new value of the Mean velocity entered
by the user of the app. This functionality makes it possible to write method code
for processing input data and provides a general way of checking the input data in
an app.
This type of event is available in the Settings window of a form and is typically used
when a form is shown as a dialog box, or to activate forms used as panes in a form
collection. Note that a method that is used for initializing graphics, such as Zoom
Extents, needs to be run as an On load event for a form and not as a global On
startup event.
| 155
E VENTS T RIGGERED BY F OCUS
Certain form objects can have an On focus gained event, which is similar to an On
data change event. This type of event is triggered when the user control associated
with a form object comes into focus, for example, when clicking an input field. In
general, a form object comes into focus when it becomes the target of keyboard
input by the action of a mouse click or when cycling focus using the Tab-key.
Events can call local methods that are not displayed in the application tree. For
more information on local methods, see “Local Methods” on page 204.
156 |
Declarations
The Declarations node in the application tree is used to declare global variables and
objects, which are used in addition to the global parameters and variables already
defined in the model. Variables defined under the Declarations node are used in
form objects and methods. In form objects, they store values to be used by other
form objects or methods. Variables that are not passed between form objects and
methods, but that are internal to methods, do not need to be declared in the
Declarations node. In methods, variables defined under the Declarations node have
global scope and can be used directly with their name. For information on how to
access global parameters defined in the model tree, see “Accessing a Global
Parameter” on page 213.
You can create a Declarations node that is local to a form. Such Declarations for a
form can only be used in that particular form, including form objects and methods
that are local to the form.
These are the different types of global Declarations:
• Scalar
• Array 1D
• Array 2D
• Choice List
• File
• Unit Set
• Shortcuts
• Graphics Data
| 157
Right-click a Declarations node to access the declaration types or use the ribbon.
Note that Shortcuts are not created from this menu but by clicking the Create
Shortcut button next to the Name in the Settings window of a form object or by
using Ctrl+K for a selected form object.
To create Declarations that are local to a form, right-click the corresponding form
and select the variable type, as shown below.
Variables that are local to a form are organized under a Declarations node that is a
child node to the form, as shown below.
The first three types of declarations, Scalar, Array 1D, and Array 2D, can be of the
following data types:
• String
• Boolean
158 |
• Integer
• Double
In addition to right-clicking the Declarations node, you can click the Create New
Declaration and Use It as Source button in the Source section of many types of form
objects.
This will open a dialog box that lets you quickly declare scalar variables.
| 159
The figure below shows a command sequence that includes a Plot Temperature
command with an input argument form1/graphics.
T HE N AME OF A V ARIABLE
The Name of a variable is a text string without spaces. The string can contain
letters, numbers, and underscores. The reserved names root and parent are not
allowed and Java® programming language keywords cannot be used.
160 |
Scalar
S TRING
A scalar string variable is similar to a global parameter or variable in a model, but
there is a difference. A parameter or variable in a model has the restriction that its
value has to be a valid model expression, while a scalar string variable has no such
restrictions. You can use a string variable to represent a double, integer, or
Boolean by using conversion functions in a method. For more information, see
“Conversion Methods” on page 360. You can also use a string variable as a source
in many form objects, such as input fields, combo boxes, card stacks, and list
boxes.
The figure below shows the Settings window for the string variables
solutionState and meshSize.
String declarations, as well as other declarations, can be loaded and saved from or
to a file by using the Load from File and Save to File buttons below the List of
Variables table.
The Load from File and Save to File buttons are used to load and save from/to the
following file formats:
• Text File (.txt)
• Microsoft® Excel Workbook (.xlsx)
- Requires LiveLink™ for Excel®
| 161
The drop-down list where these file formats can be selected is shown in the figure
below.
To illustrate the use of declared strings, the figure below shows the Settings
window of a card stack object where the string variable viewCard is used as the
source (Active Card Selector).
For more information on using card stacks, see “Card Stack” on page 281.
162 |
B OOLEAN
You can use a Boolean variable as a source in check boxes, other form objects, and
methods. A Boolean variable can have two states: true or false. The default value
is false. The figure below shows the declaration of two Boolean variables.
Example Code
In the example code below, the Boolean variable bvar has its value controlled by
a check box. If bvar is true, then Plot Group 4 (pg4) is plotted in graphics1.
Otherwise, Plot Group 1 (pg1) is plotted.
if (bvar) {
useGraphics(model.result("pg4"),"graphics1");
} else {
useGraphics(model.result("pg1"),"graphics1");
}
| 163
A r r ay 1 D
The Array 1D node declares one or more named arrays of strings, Booleans,
integers, or doubles that you can access from form objects and methods. The
number of elements in a 1D array is not restricted in any way, and you can, for
example, use a 1D array to store a column in a table with a variable number of
rows. The Settings window contains a single table, where you specify one variable
array per row. In the figure below, two double arrays are declared, xcoords and
ycoords.
The values in the column New element value are assigned to new elements of the
array when a row is added to a table form object. Arrays for strings, Booleans, and
integers are similar in function to arrays of doubles.
I NITIAL V ALUES
The Initial values can be a 1D array of arbitrary length. To edit the initial values,
click the Edit Initial Values button below the List of Variables. This opens a dialog
box where the value of each component can be entered. See the figure below for
an example of a 1D array of doubles.
164 |
A RRAY S YNTAX
An array definition must start and end with curly braces ({ and }) and each
element must be separated with a comma. When you need special characters inside
an array element (spaces and commas, for example), surround the element with
single quotes ('). The table below shows a few examples of 1D arrays:
Array 2D
The Array 2D node declares one or more 2D arrays that you can access using form
objects and methods. In the figure below, the 2D double array xycoords is
declared.
I NITIAL V ALUES
The default (or initial) value can be a 2D array of arbitrary size. To edit the initial
values, click the Edit Initial Values button below the List of Variables. This opens a
| 165
dialog box where the value of each component can be entered. See the figure
below for an example of a 2D array of doubles.
A RRAY S YNTAX
The table below shows a few examples of 2D arrays:
Assuming that the above 2-by-3 matrix is stored in the 2D array variable arr, then
the element arr[1][0] equals 4.
To interactively define the Initial values of a 2D array, select the Undefined option
for the Number of columns. The Edit Initial Values button opens a dialog box where
166 |
the number of rows and columns can be interactively changed, as shown in the
figure below.
Choice List
The Choice List node contains lists that can be used by combo boxes, radio
buttons, or list boxes. The Settings window for a choice list contains a Label, a
Name, and a table with a Value column and a Display name column. Enter the
property value (Value) in the first column and the corresponding text to display to
the user (for example, in a combo box list) in the second column (Display name).
| 167
The Value is always interpreted as a string. In the example below, mat1 will become
the string "mat1" when returned from the combo box.
In addition you can click the adjacent Add New Form Choice List to create a choice
list local to the form.
A CTIVATION C ONDITION
You can right-click the Choice List node to add an Activation Condition subnode.
Use an activation condition to switch between two or more choice lists contingent
on the value of a variable. For an example of using choice lists with activation
conditions, see “Using a Combo Box to Change Material” on page 248.
168 |
File
File declarations are primarily used for file import in method code when using the
built-in method importFile. For more information on the method importFile
and other methods for file handling, see “File Methods” on page 348. However,
an entry under the File declaration node can also be used by a File Import object.
The figure below shows the Settings window of a file declaration.
The file chosen by the user can be referenced in a form object or method using
the syntax upload:///file1, upload:///file2, etc. The file name handle
(file1, file2, etc.) can then be used to reference an actual file name picked by
the user at run time.
For more information on file declarations and file handling, see “Appendix C —
File Handling and File Scheme Syntax” on page 323.
| 169
Unit Set
The Unit Set node contains lists that can be used by combo boxes, radio buttons,
or list boxes for the purpose of changing units. The Settings window for a unit set
contains two sections: Unit Groups and Unit Lists.
Each row in the Unit Groups table is a unit group that represents a collection of
units with a particular meaning in the context of the application user interface.
Each column represents a group of units labeled by a Value and a Display name.
Each row in the Unit Lists table is a unit list with columns containing units with
the same dimension, for example, mm, cm, dm, m, and km. The headings of the
Unit Lists table are Name and the Display names are defined in the Unit Groups
section. A unit list specifies the possible units that a form object that references the
Unit Set can switch between when running the application.
The figure above demonstrates the use of a Unit Set for an application that allows
for switching between metric and imperial units. In this example, two unit groups
are defined: SI and Imperial. The Label of the Unit Set has been changed to Unit
System.
The Value column contains string values that represent the current choice of unit
group. These string values can be manipulated from methods. The Display name
170 |
column is the string displayed in the user interface. The Initial value list contains
the default unit group (SI in the example above).
In the example above, the Unit Lists table has three columns: Name, SI, and
Imperial. The SI and Imperial columns are created dynamically based on the groups
in the Unit Groups section. Each row in the table corresponds to a physical quantity
such as, in this example, length and potential. Each column in the table
corresponds to the allowed units of length and units of potential, respectively.
The figure below shows an example application where a combo box form object
is used to choose between the SI and Imperial unit groups.
| 171
The figure below shows the Settings window of a combo box using the Unit Set of
the above example as the Source.
In this way, a Unit Set can be used instead of a Choice List to create a combo box
for unit selection. Instead of a combo box, you can use a list box or a radio button
object in a similar way.
172 |
The two figures below show the corresponding Settings windows for the two input
fields for Length and Applied voltage.
The Unit dimension check is set to Append unit from unit set. The Unit set is set to
Unit System {unitset1} (the user-defined label for the Unit Set declaration used in
this example). The Unit list is set to length and potential, respectively. When using
Append unit from unit set, the Numerical validation section (under Data Validation)
refers to the Initial value of a Unit Set; in this case, cm and mV, respectively. The
Lower bound and Upper bound values are scaled automatically when the application
is run and the unit is changed by the user of the application. For more information
on the settings for an input field object, see “Input Field” on page 95.
| 173
The figures below illustrate the use of two Unit Set declarations for separately
setting the unit for length and potential, respectively.
The figures below show the corresponding Settings window for the Unit Set
declarations.
Note that, in this example, by using three Unit Set declarations, you can have
individual length unit settings for the Length and Width input fields. The figure
174 |
below shows such an example, where three combo boxes have been used to
replace the unit labels and each combo box uses a separate Unit Set declaration as
its source.
When more flexibility is required, you can combine the use of a Choice List and a
Unit Set. For example, for a combo box, you can use the Unit Set as the Selected
source (string) and select a Choice List that is not a Unit Set.
Shortcuts
Form objects and other user interface components are referenced in methods by
using a certain syntax. For example, using the default naming scheme
form3/button5 refers to a button with the name button5 in form3 and
form2/graphics3 refers to a graphics object with the name graphics3 in form2.
You can also change the default names of forms and form objects. For example, if
form1 is your main form, then you can change its name to main.
To simplify referencing form objects as well as menu, ribbon, and toolbar items by
name, you can create shortcuts with a custom name. In the Settings window of an
object or item, click the button to the right of the Name field and type a name of
your choice.
To create or edit a shortcut, you can also use the keyboard shortcut Ctrl+K.
| 175
All shortcuts that you create are made available in a Shortcuts node under
Declarations in the application tree.
In the Settings window for Shortcuts below, two shortcuts, plot_temp and
temp_vis, have been created for a button and a graphics object, respectively.
The shortcuts can be referenced in other form objects or in code in the Method
Editor. The example below shows a shortcut, temp_vis, used as an input
argument to a temperature plot.
176 |
Shortcuts are automatically updated when objects are renamed, moved, copied,
and duplicated. They are available in methods as read-only Java® variables, just like
string, int, double, and Boolean declarations.
Using shortcuts is recommended because it avoids the need to adjust Method
Editor code when the structure of the application user interface changes.
Shortcuts are also available in the Model Builder, for use with the Application
Builder. In the Settings window of a model tree node, click the button to the right
of the Label field and type a name of your choice.
| 177
Graphics Data
A Graphics Data declaration node is used to pick data at a specific coordinate from
a graphics object based on mouse clicks by the user. The figure below shows the
corresponding Settings window.
The Initial Values section contains default values for the extracted data properties
Coordinate and Results evaluation. The section Initial Values for 3D Geometry Source
contains settings for the selection methods available when the Source for Initial
Graphics Content of a graphics object is set to a geometry node.
178 |
The different properties of a graphics data declaration are available from the Editor
Tools window as shown in the figure below.
To use a Graphics Data declaration node for data picking, select the Data picking
check box in the Settings window of a graphics object and select the Graphics Data
node as the Target for Data Picking, as shown in the figure below.
| 179
the coordinate at that position. Note that in the Model Builder, this corresponds
to the data displayed in the Evaluation 2D or Evaluation 3D tables.
The figure below shows a data display object where the Coordinate property is used
as Source.
You can also use the Coordinate property as the Source for an array input object.
The Results Evaluation property can be used as the Source for several form objects
including data display and input field objects.
180 |
The Method Editor
Use the Method Editor to write code for actions not included among the standard
run commands of the model tree nodes in the Model Builder. The methods may,
for example, execute loops, process inputs and outputs, and send messages and
alerts to the user of the application.
The Java® programming language is used to write COMSOL methods, which
means that all Java® syntax and Java® libraries can be used. In addition to the
Java® libraries, the Application Builder has its own built-in library for building
applications and modifying the model object. The model object is the data
structure that stores the state of the underlying COMSOL Multiphysics model
that is embedded in the application. More information about these built-in
methods can be found in “Appendix E — Built-In Method Library” on page 347
and in the Application Programming Guide.
The contents of the application tree in the Application Builder are accessed
through the application object, which is an important part of the model object.
You can record and write code using the Method Editor that directly accesses and
changes user interface aspects of the running application, such as button texts,
icons, colors, and fonts.
There are global methods, form methods, and local methods. Global methods are
displayed in the application tree and are accessible from all methods and form
objects. Form methods are displayed in the application tree as child nodes to the
form it belongs to. A local method is associated with a form object or event and
can be opened from the corresponding Settings window. For more information
about local methods, see “Local Methods” on page 204.
A number of tools and resources are available to help you create code for
methods. These are covered in the following sections and will make you
more productive by allowing you to copy-paste or autogenerate blocks of
code, for example.
In the Form Editor, select Convert to Method from the menu button displayed in
the Settings window below an existing command sequence. The command
sequence is automatically replaced by an equivalent method. In the same way you
can select Convert to Form Method and Convert to Local Method.
Consider a case where you have created a compute button and you want to be
alerted by a sound when the computation has finished. Now, we will see how this
| 181
could be done using the Method Editor (this can also be done without writing
code, see later in this section).
You will also learn how to do this without using the Method Editor later in this
section. The figure below shows the Settings window of the Compute button.
182 |
Select the Convert to Method option below the command sequence.
In the Method Editor, add a call to the built-in method playSound to play the
sound file success.wav, available in the COMSOL sound library, by using the
syntax shown in the figure below.
The newly added line is indicated by the green bar shown to the left.
| 183
Note that in the example above, you do not have to use the Method Editor. In
the command sequence, select the file success.wav under Libraries > Sounds and
click the Run command button under the tree, as shown in the figure below.
However, there are many built-in methods that do not have corresponding
command sequence nodes. For more information, see “Appendix E — Built-In
Method Library” on page 347.
184 |
F ORM O BJECT WITH A SSOCIATED M ETHOD
A form object that has an associated method is indicated with a special icon in the
Form Editor, as shown in the figure below. In this example, both the check box
called Find prong length and the Compute button have associated methods.
Performing Ctrl+Alt+Click on the form object opens the method in the Method
Editor. If there is no method associated with the form object, a new local method
associated with the form object will be created and opened in the Method Editor.
If the associated method has a compile error, then this is shown with a different
icon, as shown in the figure below.
| 185
Language Elements Window
The Language Elements window in the Method Editor shows a list of some
language constructs. Double-click or right-click one of the items in the list to
insert template code into the selected method.
186 |
Editor Tools in the Method Editor
To display the Editor Tools window, click the corresponding button in the Main
group in the Home tab.
When using the Editor Tools window in the Method Editor, you can right-click a
node in the editor tree to generate code associated with that node. Depending on
the node, up to eight different options are available:
• Get
• Set
• Set All
• Create
• Run
• Enable
• Disable
• Edit Node
Selecting one of the first seven options will add the corresponding code to the
currently selected method. The Edit Node option brings you to the Settings
window for the model tree node.
| 187
The figure below shows an example of a node with six options.
When a node is selected, the toolbar below the editor tree shows the available
options for generating code.
The Editor Tools window is also an important tool when working with the Form
Editor. For more information, see “Editor Tools in the Form Editor” on page 63.
K EYBOARD S HORTCUTS
Consider a method with a line of code that refers to a model object in the
following way:
model.result("pg3").feature("surf1").create("hght1", "Height");
If you position the mouse pointer in "surf1" and press F11 on the keyboard,
right-click and select Go to Node, or click Go to Node in the ribbon, then the
corresponding Surface plot note is highlighted in the Editor Tools window.
Click Edit Node to open its Settings window. For more information on keyboard
shortcuts, see “Appendix D — Keyboard Shortcuts” on page 344.
188 |
D a ta A c c e s s i n t h e M e t h o d E d i t o r
To access individual properties of a model tree node, click the Data Access button
either in the Main section of the Home tab, in the Application Builder, or in the
Application section of the Developer tab in the Model Builder ribbon.
Alternatively, for certain form objects, you can click the Data Access button in the
header of the Source section of the Settings window. See also “Data Access in the
Form Editor” on page 106.
Data Access needs to be enabled this way because a model typically contains
hundreds or even thousands of properties that could be accessed, and the list
would be too long to be practical.
When you click a model tree node, such as the Heat Flux node in the figure below,
check boxes appear next to the individual properties. This example is based on the
busbar tutorial model described in Introduction to COMSOL Multiphysics.
In the figure below, the check boxes for Heat transfer coefficient and External
temperature are selected:
| 189
If you switch to the Editor Tools window, you will see additional nodes appear
under the Heat Flux node. Right-click and use Get or Set to generate code in an
active method window, as shown in the figure below.
In the example above, Get and Set for the Heat transfer coefficient and the External
temperature properties will generate the following code:
model.component("comp1").physics("ht").feature("hf1").getString("Text");
model.component("comp1").physics("ht").feature("hf1").getString("h");
model.component("comp1").physics("ht").feature("hf1").set("Text",
"293.15[K]");
model.component("comp1").physics("ht").feature("hf1").set("h", "htc");
190 |
Recording Code
Click the Record Code button in the Code section of the Method Editor ribbon to
record a sequence of operations that you perform using the model tree, as shown
in the figure below.
Certain operations in the application tree can also be recorded, including methods
used to modify the user interface while the application is running such as changing
the color of a text label.
To record a new method, click the Record Method button. This button is also
available in the Main section of the Home tab of the Form Editor or Method Editor
ribbon.
In addition, you can click the Record Method button in the Developer tab of the
Model Builder ribbon.
| 191
While recording code, the COMSOL Desktop windows are surrounded by a red
frame:
192 |
To stop recording code, click one of the Stop Recording buttons in the ribbon of
either the Model Builder or the Application Builder.
The previous section on Data Access explained how to set the values of the Heat
transfer coefficient and the External temperature properties of the busbar tutorial
model. To generate similar code using Record Code, follow these steps:
• Create a simple application based on the busbar model (MPH-file) available
in the Application Libraries under COMSOL Multiphysics>Multiphysics.
• In the Model Builder window, click Record Method, or with the Method
Editor open, click Record Code.
• Change the value of the Heat transfer coefficient to 5.
• Change the value of the External temperature to 300[K].
• Click Stop Recording.
• If it is not already open, open the method with the recorded code.
Note that in File>Preferences you can enable the use of with() statements in order
to make the code more compact. For more information on the use of with(), see
“The With Statement” on page 213.
To generate code corresponding to changes to the application object, use Record
Code or Record Method, then go to the Form Editor and, for example, change the
appearance of a form object. The following code corresponds to changing the
color of a text label from the default Inherit to Blue:
app.form("form1").formObject("textlabel1").set("foreground", "blue");
For more information on modifying the model object and the application object,
see the Application Programming Guide.
Use the tools for recording code to quickly learn how to interact with the model
object or the application object. The autogenerated code shows you the names of
properties, parameters, and variables. Use strings and string-number conversions
to assign new parameter values in model properties. By using Data Access while
recording, you can, for example, extract a parameter value using get, process its
value in a method, and set it back into the model object using set. For more
information on Data Access, see “Data Access in the Method Editor” on page 189.
| 193
Checking Syntax
Click Check Syntax in the ribbon to see messages in the Method Errors and Warnings
window related to syntax errors or unused variables.
In addition to messages in the Method Errors and Warnings window, syntax errors
are indicated with a wavy red underline, as shown in the figure below.
194 |
Find and Replace
Click Find in the Quick Access Toolbar, or user the keyboard shortcut Ctrl+F, to
open a dialog box used to find and replace strings in methods, as shown in the
figure below.
The Quick Access Toolbar is located above the ribbon to the left, in the
COMSOL Desktop user interface.
| 195
Model Expressions Window
The Model Expressions window in the Method Editor shows a list of predefined
expressions used as input and output arguments. Double-click or right-click one
of the items in the list to insert an expression:
196 |
Use Shortcut
If you look at the example below, you will notice that the two last lines of code
begins with model.result(”pg1”).
The Use Shortcut button simplifies code by replacing these instances with a variable
name.
In the example above, the mouse pointer has been positioned at the first
occurrence of model.result(”pg1”). Click the Use Shortcut button to transform
the source code into what is shown in the figure below.
The code starting with the prefix model.result(”pg1”) has been replaced with
the variable pointplot. When you click the Use Shortcut button, a Use Shortcut
dialog box opens where you can enter a suitable variable name in the Name field,
in this case pointplot.
| 197
This variable is stored as a shortcut in the Declarations node, as shown in the figure
below together with the corresponding Settings window.
S y n ta x H i g h l i g h t i n g , C o d e F o l d i n g , a n d I n d e n t a t i o n
Different language elements in the code are displayed using different styles. Refer
to the figure below for an example:
198 |
You can customize the syntax highlighting theme in the Preferences dialog box.
See the next section Method Editor Preferences.
You can expand and collapse parts of the code corresponding to code blocks that
are part of for, while, if, and else statements. This feature can be disabled, as
described in the next section “Method Editor Preferences”.
When writing code, use the Tab key on your keyboard to automatically indent a
line of code and insert white spaces where needed. As an alternative, you can
right-click in the Method Editor and select Indent and Format, as shown in the
figure below.
T HE N AME OF A M ETHOD
The Name of a method is a text string without spaces. The string can contain
letters, numbers, and underscores. The reserved names root and parent are not
allowed and Java® programming language keywords cannot be used.
| 199
Method Editor Preferences
To access the Preferences for the methods, choose File > Preferences and select the
Methods node in the tree.
By default, the Method Editor only shows the most relevant code. To see all code
in a method, select the View all code check box.
The check box Close brackets automatically controls whether the Method Editor
should automatically add closing brackets, such as curly brackets {}, brackets [],
and parentheses ().
The check box Generate compact code using ‘with’ statements controls the
utilization of with statements in automatically generated code. For more
information, see “The With Statement” on page 213.
If the check box Enable code folding is selected, you can expand and collapse parts
of the code corresponding to code blocks associated with for, while, if, and else
statements.
Selecting the check box Indent and format automatically will ensure that code is
consistently indented and formated.
The Generate code using component syntax option will generate method syntax that
also includes the model component scope.
200 |
Clear the option Ask for confirmation before running methods in the Model Builder
if you do not want to confirm when running methods in this way.
Under the Syntax highlighting node, the Theme list contains a few predefined
themes. Choose User defined to define a syntax highlighting mode where the
colors can be assigned to individual language elements.
While typing code in the Method Editor, the Application Builder can provide
suggestions for code completions. The list of possible completions are shown in a
separate completion list that opens while typing. In some situations, detailed
information appears in a separate window when an entry is selected in the list.
Code completion can always be requested with the keyboard shortcut Ctrl+Space.
When accessing parts of the model object, you will get a list of possible
completions, as shown in the figure below:
Select a completion by using the arrow keys to choose an entry in the list and press
the Tab or Enter key to confirm the selection.
If the list is long, you can filter by typing the first few characters of the completion
you are looking for.
For example, if you enter he first few characters of a variable or method name and
press Ctrl+Space, the possible completions are shown:
| 201
In the example above, only variables that match the string iv are shown. This
example shows that variables local to the method also appear in the completion
suggestions.
You can also use Ctrl+Space to learn about the syntax for the built-in methods that
are not directly related to the model object. Type the name of the command and
use Ctrl+Space to open a window with information on the various calling
signatures available.
For a list of available built-in methods, you can use the Language Elements window
described on page 186 or see “Appendix E — Built-In Method Library” on page
347.
Similar information is displayed in a tooltip when hovering over the different parts
of a method call, property name, declaration, or shortcut.
202 |
The keyboard shortcut Ctrl+Space can also be used in the Model Builder. For
example, when typing in an Expression field in Results, use Ctrl+Space to see
matching variables, as shown in the figure below.
You can automatically set the type of a local variable. For example, you can type
x = model.geom()
and click the Create Local Variable button in the Code group of the Method tab in
the ribbon.
| 203
Local Methods
You can add local methods to buttons, menu items, and events. Local methods do
not have nodes displayed under the Methods node in the application tree. In the
method window for a local method, its tab displays the path to its associated user
interface component, as shown in the figure below for the case of a check box
object.
In the Form Editor, you can right-click a form object and select Create Local
Method from a menu, as shown in the figure below.
204 |
L OCAL M ETHODS FOR B UTTONS , M ENU I TEMS , AND G LOBAL E VENTS
For buttons, ribbons, menus, toolbar items, and global events, you can add a local
method by selecting Convert to Local Method from the toolbar menu button under
the sequence of commands, as shown in the figure below.
The function of this button is similar to the Convert to Method and Convert to Form
Method buttons, described in the section “Creating a New Method” on page 18.
The only difference is that it creates a local method not visible in the global
method list in the application tree. It also opens the new method in the Method
Editor after creating it. Ctrl+Alt+Click can be used as a shortcut for creating the
local method. Clicking the button Go to Method will open the local method. The
figure below shows a call to a local method associated with a button.
| 205
To avoid any risk of corrupting code in a local method, you are unable to use
Convert to Method when there is a local method present in the command sequence.
To open an existing local method in the Method Editor, click the Go to Source
button. Select Remove Local Method from the menu to delete the local method.
As an alternative to Ctrl+Alt+Click, you can right-click a form object and select
Edit Local Method from its context menu.
A method is allowed to have several input arguments and one output argument.
You define input and output arguments in the Settings window of an active
method window. If the Settings window is not visible, click Settings in the Method
tab of the ribbon. The figure below shows a method with two input arguments,
var and coords; and one output, coordsout. The method adds random values to
206 |
the array, coords. The degree of randomness is controlled by the input variable
var. The new values are stored in the array coordsout.
When you call another method from a method, Ctrl+Alt+double-click opens the
window for that method. A method is allowed to call itself for the purpose of
recursion.
| 207
Debu gging
For debugging purposes, click in the gray column to the left of the code line
numbers to set breakpoints, as shown in the figure below.
In the ribbon, the Debug group contains the tools available for debugging
methods. When you run the application, the method will stop at the breakpoints.
Click the Step button to go to the next line in the method. The figure above shows
a method currently stopped at the line highlighted in yellow. The Variables
window, seen to the right in the figure above, opens when a method is paused at
a breakpoint. Using the Variables window, you inspect and modify local variables,
declarations, and parameters, while debugging.
The Call Stack window, below the method window, as seen in the figure above,
also opens when a method is paused at a breakpoint. You can select a method in
the call stack see the corresponding variables in the Variables window.
Click Continue to run the method up until the next breakpoint. Click Stop to stop
running the method and exit. You can also stop the execution of a method while
208 |
testing an application by using the keyboard shortcut Ctrl+Pause. A dialog box
appears, as shown below.
Click Break to suspend method execution at the next reached line in method code,
as if there had been a breakpoint there. Click Step Into to step into the next
method, if possible. The option Step Out continues until the current method
returns. Use Remove All to remove all break points. Instead of removing, you can
disable all break points by clicking Disable All.
To get an overview of all breakpoints, you can open the Breakpoints window, as
seen in the figure below. To open this window, click the corresponding button in
the Method tab, in the ribbon section Breakpoints.
You can enable and disable individual breakpoints, either from the Breakpoints
window or by right-clicking a breakpoint in the gray column to the left of the code
line numbers, as shown below.
| 209
Click the Debug Log to display customized debugging messages in a separate Debug
Log window, as shown in the figure below.
As an alternative to using the Variables window, you can use the debugLog
command a to display the value of variables in the Debug Log window. The code
below illustrates using the debugLog command to display the values of strings and
components of a 1D double array.
int len=xcoords.length;
if (selected==0) {
for (int i = 0; i < len; i++) {
double divid=double(i)/len;
xcoords[i] = Math.cos(2.0*Math.PI*divid);
ycoords[i] = Math.sin(2.0*Math.PI*divid);
debugLog("x:");
debugLog(xcoords[i]);
debugLog("y:");
debugLog(ycoords[i]);
debugLog("selected is 0");
}
210 |
}
For more information on built-in methods for debugging, see “Debug Methods”
on page 356 and the Application Programming Guide.
The model object provides a large number of methods, including methods for
setting up and running sequences of operations. The Convert to Method, Record
Code, Editor Tools, and Language Elements utilities of the Method Editor produce
statements using such model object methods. For more information and example
code related to the model object and its methods, see “Appendix C—Language
Elements and Reserved Names” in the book Introduction to COMSOL
Multiphysics, the Application Programming Guide, as well as the Programming
Reference Manual.
| 211
PRECEDENCE LEVEL SYMBOL DESCRIPTION
212 |
Math.sin(double)
Math.cos(double)
Math.random()
Math.PI
T HE IF S TATEMENT
if(a<b) {
alert(toString(a));
} else {
alert(toString(b));
}
T HE F OR S TATEMENT
// Iterate i from 1 to N:
int N=10;
for (int i = 1; i <= N; i++) {
// Do something
}
T HE W HILE S TATEMENT
double t=0,h=0.1,tend=10;
while(t<tend) {
//do something with t
t=t+h;
}
T HE W ITH S TATEMENT
// Set the global parameter L to a fixed value
with(model.param());
set("L", "10[cm]");
endwith();
| 213
The evaluation is in this case with respect to the base Unit System defined in the
model tree root node.
To return the unit of the parameter L, if any, use:
String Lunit=model.param().evaluateUnit("L");
To return the value of a parameter in a different unit than the base Unit System,
use:
double Length_real = model.param().evaluate("L","cm");
If the parameter is complex valued, the real and imaginary part can be returned as
a double vector of length 2:
double[] realImag = model.param().evaluateComplex("Ex","V/m");
C OMPARING S TRINGS
Comparing string values in Java® has to be done with .equals() and not with the
== operator. This is due to the fact that the == operator compares whether the
strings are the same objects and does not consider their values. The below code
demonstrates string comparisons:
boolean streq=false;
String a="string A";
String b="string B";
streq=a.equals(b);
// In this case streq==false
streq=(a==b);
// In this case streq==false
b="string A";
streq=a.equals(b);
// In this case streq==true
214 |
String answer = confirm("Which solver do you want to use?",
"Solver Selection","Direct", "Iterative");
if(answer.equals("Direct")) {
alert("Using the direct solver will require about 4GB of memory when
solving.");
} else {
alert("Using the iterative solver will require about 2GB of memory when
solving.");
}
which will display the geometry and select the Geometry node.
The method selectNode has no function when used in an application.
| 215
G ENERATING A R EPORT A UTOMATICALLY AFTER C OMPUTING
As an example of using a method from the Model Builder, consider the process of
first computing the solution and then generating a report. This can be automated
by first recoding the corresponding operations in the Model Builder and then
running a method.
Let’s start from the busbar example described in the book Introduction to
COMSOL Multiphysics. You can load this example MPH-file from the
Application Libraries, as shown in the figure below.
216 |
• Click Write to generate and save the report to file.
• In the model tree, right-click the Study 1 node and select Compute (or use the
ribbon option for Compute).
• In the model tree, right-click the Report 1 node and select Write (if prompted
to overwrite, answer Yes). Close the Microsoft® Word document that was
automatically opened.
• Click the Developer tab in the ribbon and click the Stop Recording button.
| 217
• You can now switch over to the Application Builder, by clicking on the
Application Builder button in the ribbon, and see the recorded method in the
application tree and in the Method Editor.
For more information on code generated from the Study node, see the
Application Programming Guide.
• Here you can inspect and edit the generated code and also change the name
of the method to, for example, compute_and_report.
• Go back to the Model Builder by clicking on the Model Builder button in the
ribbon.
218 |
• In Global Definitions > Parameters, change the Length to 15[cm].
• In the ribbon, click on the Developer tab and select compute_and_report from
the Run Method menu (if prompted to confirm, answer Yes).
Depending on your security settings, you may get an error message. To avoid this
error, open File>Preferences, go to the Security page, and change File system access
to All files. You can change this back to its default setting after running this
example.
Note that you can create multiple methods and call them from the Model Builder.
M ETHOD C ALLS
A call, in the Model Builder, to a method for a specific set of input argument
values can be made by adding a Method Call node under Global Definitions. To add
a Method Call node, right-click Global Definitions and select one of the methods that
| 219
you have created. The figure below shows a Method Call to a method for creating
a geometric array.
The user interface layout of a Method Call cannot be customized. Instead, for
customizing use a Settings Form, see “Using Forms in the Model Builder” on page
130.
You can run, stop, or edit a Method Call by clicking the corresponding toolbar
button in the Settings window, as shown in the figure below.
This functionality is also available from the Developer tab in the ribbon of the
Model Builder, as shown in the figure below.
220 |
The figure below show the corresponding method’s Settings window in the
Application Builder with the definitions of the input arguments.
You can add multiple Method Call nodes for the same method where each call can
contain a different set of input argument values.
There is no direct way of using output arguments from a method in the Model
Builder. However, you can use calls to the built-in method message to display
variables used in a method in the Messages window in the COMSOL Desktop
environment. The following example shows how to display the value of two
double variables width and depth in the Messages window:
message("Width: "+toString(width));
message("Depth: "+toString(depth));
For debugging, you use the general techniques outlined in the section
“Debugging” on page 208.
For reusing a Settings Form between sessions, you can create an Add-in. For more
information, see “Creating Add-Ins” on page 222.
| 221
Creating Add-Ins
To customize the workflow in the Model Builder, you can use a Method Call or a
Settings Form. However, these are associated with a specific MPH-file, and you
may want to reuse them between sessions or share them with colleagues. To make
this possible, you can create an add-in based on a Method Call or Settings Form.
Such add-ins can then be stored in a user-defined add-in library. In addition,
COMSOL Multiphysics comes with built-in add-in libraries. For the add-ins in the
built-in library, you can review their Application Builder settings, including forms
and methods, to quickly learn how to build your own add-ins. Creating an add-in
is similar to creating an application, with a few differences. Add-ins do not have
their own graphics window, but instead use the main Graphics window in the
Model Builder. An add-in should work, or give controlled error messages, for any
type of model.
To create an add-in, start from a form that you have created in the Application
Builder and click Add-in Definitions in the Home tab of the ribbon, as shown below.
Right-click the Add-in Definitions node in the application tree and select Form
Definition.
The figure below shows the Settings window for the Form Definition. Here, you can
type a Label for the add-in form as well as select which form to use for the add-in.
The Label will be displayed in the user-defined add-in library. You can select
222 |
whether the form should be displayed as a Settings form in the model tree or as a
Dialog box. The Allow multiple settings forms check box is used to allow for more
than one instance of the Settings form in the model tree. The Description is
displayed in the add-in library and as a tooltip when choosing among add-ins in
the ribbon.
| 223
Click the Add-in Definition node to see its Settings window, as shown below.
The Filename is the location of the add-in MPH-file in the user-defined add-in
library. This location can be on a shared network drive if you wish to share the
add-in with your colleagues. The Label will be displayed in the Add-in Libraries
window. The Unique identifier is what identifies the add-in and is intended to be
unique for any COMSOL Multiphysics session. The unique identifier is
recommended to be in a format similar to <company name>.<Add-in name> ;for
example, my_company.my_add-in. The Editing password will be applied to the
created add-in and is different from the editing password that you can specify in
the root node Settings window of the MPH-file used to create the add-in.
224 |
To create the add-in, which is a special type of MPH-file, click the Create Add-in
button.
Add-In Libraries
To use an add-in from the Add-in Libraries, you first need to enable it. In the
Developer tab in the Model Builder, click Add-in Libraries.
In the list of add-ins, select the check boxes of those add-ins that you want to
enable.
| 225
Once enabled, the corresponding add-ins will be displayed when clicking the
Add-ins button in the Developer tab.
The figure below shows the Settings Form for one of the built-in add-ins.
If you want to review and edit the Application Builder settings for a built-in
add-in, you can open the corresponding MPH-file. In a typical Windows®
installation, the built-in add-in library is located at:
C:\Program Files\COMSOL\COMSOL\Multiphysics\addins
You can browse to a user-defined add-in library by clicking the Add User Add-in
Library button at the bottom of the Add-in Libraries window.
226 |
The user-defined add-in library will be displayed alongside the built-in add-in
libraries, as shown below.
When creating and editing add-ins, you will find it useful to have two sessions of
COMSOL Multiphysics open at the same time: one session for the original add-in
MPH-file where you work mostly in the Application Builder, and one session for
testing the add-in in the Model Builder. When testing an add-in using the Model
Builder, make sure to test for a great variety of models, including models of
different spatial dimensions as well as models with more than one model
component. Use the Refresh Add-ins button to make sure you always use an
updated version of the add-in you are editing.
| 227
Libraries
In the application tree, the Libraries node contains images, sounds, and files to be
embedded in an MPH-file so that you do not have to distribute them along with
the application. In addition, the Libraries node may contain Java® utility class
nodes and nodes for external Java® and C libraries, as well as Add-ins. For
more information on using utility classes and external libraries, see the
Application Builder Reference Manual.
228 |
Images
The Images library contains a number of preloaded sample images in the PNG file
format to be used as icons in apps. If you wish to embed other image files, click
the Add File to Library button below the List of Images. A large selection of icons
is available in the COMSOL installation folder in the location data/icons.
Images can be referenced in image form objects, in methods, or, in the form of
icons, in various form objects. For images used as icons, two sizes are available:
16-by-16 pixels (small) and 32-by-32 pixels (large).
Sounds
The Sounds library contains a few preloaded sounds in the WAV-file format. If you
wish to embed other sound files, click the Add File to Library button below the List
| 229
of Sounds. A larger selection of sounds is available in the COMSOL installation
folder in the location data/sounds.
To play a sound, click the name of the sound and then click the Preview button
below the List of Sounds.
Click the Export Selected Sound File button to the right of the Preview button to
export a selected sound.
To play a sound in an application, add a command in the Settings window of a
button, ribbon, menu, or toolbar item. In the Choose Commands to Run section,
select the sound and click the Run button below the tree. This adds a Play
command to the command sequence, as shown in the figure below.
In methods, you can play sounds using the built-in method, playSound, such as:
playSound("success.wav");
230 |
Files
The Files library is empty by default. Click the Add File to Library button to embed
files of any type in your application.
Click the Export Selected File button to the right of the Add File to Library button
to export a selected file.
| 231
Appendix A — Form Objects
This appendix provides information about forms and form objects and expands
upon the section “The Form Editor” on page 53. The items followed by a * in the
following list have already been described in detail in that section. The remaining
items are discussed in this appendix.
• Input
- Input Field*
- Button*
- Check Box
- Toggle Button
- Combo Box
• Labels
- Text Label*
- Unit*
- Equation
- Line
• Display
- Data Display*
- Graphics*
- Web Page
- Image
- Video
- Progress Bar
- Gauge
- Log
- Message Log
- Results Table
232 |
• Subforms
- Form
- Form Collection
- Card Stack
• Composite
- File Import
- Information Card Stack
- Array Input
- Radio Button
- Selection Input
• Miscellaneous
- Text
- List Box
- Table
- Slider
- Knob
- Hyperlink
- Toolbar
- Spacer
Che c k Bo x
A Check Box has two values: on for selected and off for cleared. The state of a
check box is stored in a Boolean variable in the Declarations node.
| 233
The screenshot on the left shows the running application. The screenshot on the
right shows the corresponding form objects in grid layout mode.
In the example below, the state of the check box is stored in a Boolean variable
deformation, whose Settings window is shown in the figure below.
234 |
The figure below shows the Settings window for the check box.
You associate a check box with a declared Boolean variable by selecting it from the
tree in the Source section and clicking Use as Source.
The text label for a check box gets its name, by default, from the Description field
of the Boolean variable with which it is associated.
The Initial value of the variable deformation is overwritten by the Value for
selected (on) or the Value for cleared (off) and does not need to be edited. When
used in methods, the values on and off are aliases for true and false, respectively.
These values can be used as Booleans in if statements, for example.
The code statements below come from a local method that is run for an On data
change event when the value of the Boolean variable deformation changes.
model.result("pg1").feature("surf1").feature("def").active(deformation);
useGraphics(model.result("pg1"), "graphics1");
| 235
U SING A C HECK B OX TO E NABLE AND D ISABLE F ORM O BJECTS
The figure below shows a part of an application where certain input fields are
disabled or enabled, depending on if the check box is selected.
The figure below shows the Settings window for a check box associated with a
Boolean variable findlength used to store the state of the check box.
The code statements below come from a local method that is run for an On data
change event when the value of the Boolean variable findlength changes.
setFormObjectEditable("main/inputfield1", !findlength);
setFormObjectEditable("main/inputfield5", findlength);
setFormObjectEnabled("main/inputfield5", findlength);
setFormObjectEditable("main/inputfield6", findlength);
setFormObjectEnabled("main/inputfield6", findlength);
solution_state = "inputchanged";
236 |
Toggle Button
A Toggle Button object is a button with two states: selected and deselected, as
shown in the figure below.
The information in this section is also applicable to Menu Toggle Item and Ribbon
Toggle Item.
| 237
Enabled corresponds to the Boolean variable heat_source being equal to true,
which in turn corresponds to the toggle button being selected. Disabled
corresponds to the Boolean variable heat_source being equal to false, which in
turn corresponds to the toggle button being deselected. The Icon is displayed
when the toggle button is not selected. When the toggle button is selected, the
Selected icon is displayed.
Below the Source section is the Choose Commands to Run section, with a choice for
Action that represents two different commands for Select and Deselect. The figure
below shows the Settings window for Deselect with a command Disable Heat Source.
238 |
The next figure shows the command sequence for Select with a command Enable
Heat Source.
C ombo B o x
A Combo Box can serve as either a combination of a drop-down list box and an
editable text field or as a drop-down list box without the capability of editing.
| 239
These six mode shapes correspond to six different eigenfrequencies that the user
selects from a combo box:
In this example, the combo box is used to control the value of a string variable
mode. The figure below shows the Settings window for this variable.
240 |
Selecting the Source
The figure below shows the Settings window for this combo box.
In the Source section, you select a scalar variable that should have its value
controlled by the combo box and click Use as Source. In the Initial values list of the
Settings window of the combo box, choose a method to define a default value for
the combo box. The options are First allowed value (the default) and Custom
default. For the Custom default option, enter a default value in the associated field.
The default value that you enter must exist among the allowed values.
Choice List
The vibrational modes 1–6 correspond to trivial rigid body modes and are not of
interest in this application, hence the first mode of interest is 7. A choice list allows
you to hide the actual mode values in the model from the user by only displaying
the strings in the Display name column; the first nonrigid body modes are named
Fundamental tone, Overtone 1, Overtone 2, etc.
| 241
In the section for Choice List, you can add choice lists that contribute allowed
values to the combo box. The Choice List declaration associated with this example
is shown in the figure below.
The string variable mode is allowed to have one of these six values: 7, 8, 9, 10, 11,
or 12. The text strings in the Display name column are shown in the combo box.
In the Settings window of the combo box, you can select the Allow other values
check box to get a combo box where you can type arbitrary values. Such combo
boxes can accept any value and are not restricted to the values defined by the
choice lists. In this example, however, only six predefined values are allowed.
For more information on choice lists, see “Choice List” on page 167.
Events
In the Events section, specify a method to run when the value of the combo box,
and thereby the string variable used as the source, is changed by the user. In the
present case, the value of the variable mode is changed, and a local method is run,
as shown below.
242 |
This code links the value of the string mode to the Eigenfrequency setting in the
Plot Group pg1. In this case, the string svar takes the values "7", "8", "9", "10",
"11", or "12".
The code above can be generated automatically by using the recording facilities of
the Method Editor:
• Go to the Model Builder and, in the Developer tab, click Record Method.
• By default, when using an Eigenfrequency study for a structural mechanical
analysis, a Mode Shape plot group is created. In this plot group, change the
Eigenfrequency from mode 7 to mode 8. In the figure below, this corresponds
to changing from 440 Hz to 633.52 Hz in the Settings window for the Mode
Shape plot group.
Now change the string "8" with the variable mode to end up with the code listing
above. This will be stored in a method, say, method1. To create the local method
associated with the combo box, copy the code from method1. Then, delete
method1.
| 243
Using Data Access
A quicker, but less general way, of using a combo box is to use Data Access in
combination with Editor Tools. For the example used in this section, you start by
enabling Data Access and, in the Settings window of the Mode Shape plot group,
select the Eigenfrequency, as shown in the figure below.
In the Editor Tools window, the Eigenfrequency parameter is visible as Loop Level.
To create a combo box, right-click Loop Level and select Input.
The generic name Loop Level is used for a solution parameter. If a solution has two
or more parameters, then there are two or more loop levels to choose from.
244 |
The figure below shows the Settings window of the corresponding combo box.
The choice list Loop Level is automatically generated when inserting a combo box
using Editor Tools. Note that a choice list generated in this way is not displayed
under the Declarations node and cannot be modified by the user. For greater
flexibility, such as giving names to each parameter or eigenfrequency value, you
need to declare the choice list manually, as described in the previous section.
| 245
In the Settings window in the figure below, Data Access has been used to access the
Time parameter list in a temperature plot.
In Editor Tools, a handle to the Time list is now available, as shown in the figure
below.
246 |
By selecting Input, you can create a combo box using it as Source, as shown in the
figure below.
The combo box can be used for multiple purposes, for example, to update a plot
corresponding to a different time parameter. In order for a plot to automatically
update when a user uses the combo box to select a new time parameter, add an
event to the combo box at the bottom of its Settings window. In the figure below,
a method plotT is called for updating a temperature plot.
The line of code below shows the contents of the method plotT:
model.result("pg1").run();
| 247
The end result is a combo box in the application user interface, shown in the figure
below, which automatically updates a temperature plot when the user selects a new
value for the Time list.
248 |
The material choice is implemented in the embedded model using global materials
and a material link, as shown below.
Each material is indexed with a string: mat1, mat2, ..., mat5. An event listens for
changes to the value of the global variable alloy, where the value is controlled by
a combo box. When the value is changed, the method listed below is run.
with(model.material("matlnk1"));
set("link", alloy);
endwith();
| 249
The figure below shows the declaration of two string variables, material and
alloy, which are controlled by the Material and Alloy combo boxes, respectively.
The application utilizes three choice lists: Aluminum Alloys, Steel Alloys, and
Material.
Activation Condition
An activation condition is used for the Aluminum Alloys and Steel Alloys choice lists,
as shown in the figure below.
250 |
The Settings window for the Material combo box is shown below.
Note that the Material combo box uses the material string variable as its source.
The Material choice list is used to define a discrete set of allowed values for the
| 251
material string variable. The Settings window for the Material choice list is shown
below.
252 |
The Settings window for the Alloy combo box is shown in the figure below.
| 253
Note that the Alloy combo box uses both the Aluminum Alloys and the Steel Alloys
choice lists. The choice list for Aluminum Alloys is shown in the figure below.
254 |
The activation condition for the Aluminum Alloys choice list is shown in the figure
below.
| 255
example, consider an application where a combo box is used to change the
element size in a mesh, as in the figure below.
Switch to the Model Builder and select the Mesh node (we assume here that the
model has just a single mesh). In the Settings window of the Mesh node, select
User-controlled mesh (if not already selected). In the Size node, directly under the
Mesh node, select the option Predefined. Click Data Access in the ribbon. This gives
access to the combo box for a predefined element size, as shown in the figure
below.
Select the green check box to the left of the list to make it available as a source for
a combo box in the Application Builder. Then, when you return to the Application
Builder, you will find that the choice list for mesh size is now revealed as a
potential Source in the Settings for a new combo box.
256 |
To insert the combo box object, you have two alternatives:
• Select Combo Box from the Insert Object menu in the ribbon. In the Settings
window for the combo box, select the node Predefined size (hauto) in the
Source section and then click the Use as Source button.
• In the Editor Tools window, select the node Predefined size (hauto) under the
Mesh > Size node. Then right-click and select Input, as shown in the figure
below.
| 257
The corresponding Settings window for the combo box is shown in the figure
below.
Changing the Initial value to From data source ensures that the element size setting
of the model, in this case Normal, is used as the default element size in the
application. The choice list, Predefined size (hauto), from the Model Builder is now
selected as the choice list for your combo box in the Application Builder. This
choice list does not appear as a choice list under the Declarations node of the
application tree because it is being referenced from the Model Builder. Therefore,
if you want a list with a more limited set of choices, you cannot edit it. Instead,
you have to remove the predefined list as the Source of your combo box and create
a new choice list of your own by declaring it under the Declarations node. For
258 |
example, you can create a choice list with three entries, as shown in the figure
below.
To learn which values are used by the Element size list in the model, use Record a
New Method and change the value from Normal to Fine, then to Coarse, and then
back to Normal. Click Stop Recording and read the values in the autogenerated
code. The Element size property name is hauto and the values for Fine, Normal, and
Coarse are 4, 5, and 6, respectively, as implied by the automatically generated code
shown in the lines below.
with(model.mesh("mesh1").feature("size"));
set("hauto", "4");
set("hauto", "6");
set("hauto", "5");
endwith();
The hauto property can also take non-integer values. For more information on
Element size, see “Data Access for Input Fields” on page 106.
| 259
E qu at io n
An Equation object can display a LaTeX equation by entering the expression in the
Enter equation in LaTeX syntax field.
A preview is shown of the rendered LaTeX syntax after leaving the text field.
260 |
Line
Use the Line form object to add a horizontal or vertical line to a form, which can
be used, for example, to separate groups of form objects. For the horizontal line
option, you can also add text that appears within the line.
| 261
Web Page
A Web Page object can display the contents of a web page as part of the user
interface.
You can specify the page source in four different ways from the Source list:
• Use the default option Page to enter HTML code in a text area below the
list, enclosed by the <html> and </html> start and end tags.
• Use the URL option to link to a web page on the Internet.
• Use the File option to point to a local file resource containing HTML code.
Type the name of the file in the File field or click Browse to locate the file on
the local file system.
• Use the Report option to embed an HTML report. The Browser preview is
not active for this option.
Use the setting Native browser on Windows to control which browser is used in the
Windows® version of COMSOL Multiphysics.
262 |
Image
Use an Image form object to add an image to a form. An image object is different
from a graphics object in that an image object is not interactive. Choose an image
file from one of the library images, accessible from a drop-down list, or by clicking
the Add Image to Library and Use Here button to select a file from the local file
system. The figure below shows the Settings window for an image object
referencing the image comsol_32.png, defined in the Libraries node.
If you select an image file from your file system, this file will be embedded in the
application and added to the list of Images under the Libraries node.
While you can change the x- and y-position of the image, the width and height
settings are determined by the image file. However, if you use the grid layout
mode, then there is an additional setting Stretch image which, if activated, will
automatically scale the image to fill the available grid cell space.
You can paste images from the clipboard to a form window by using
Ctrl+V. For example, you can copy and paste images from the
PowerPoint® slide presentation software. Such images will be added
automatically to the Images library and embedded in the application. The
names for pasted images are automatically set to: pasted_image_1.png,
pasted_image_2.png, etc.
| 263
Video
A Video object embeds a video file in a form. The supported video file formats are
MP4 (.mp4), OGV (.ogv), and WebM (.webm). However, not all video file
formats are supported on all platforms. When running an application by
connecting to COMSOL Server from a web browser, which formats are supported
depend on the web browser and may vary with different versions of the same web
browser. When running an application with the COMSOL Client and with
COMSOL Multiphysics, the Internet Explorer version installed on your computer
is used as a software component for displaying the video object.
After added to a form, the Video object is represented, in the Form Editor by an
image, as shown in the figure below.
The figure below shows the Settings window for the Video object.
264 |
• Start automatically
• Repeat
• Initially muted
The option Show video controls enables the video controls such as Play and Stop.
The option Initially muted is intended for the case where you want to play a video
with the sound initially turned off. For example, if the video is set to start
automatically, it can be useful to let the user choose whether the sound should be
on. The user can enable the sound either from the video controls, if the check box
Show video controls is selected, or by right-clicking in the video player.
Use the setting Native browser on Windows to control which browser is used in the
Windows® version of COMSOL Multiphysics.
Pr ogr ess B ar
A Progress Bar object displays a customized progress bar, or set of progress bars,
based on a value that is updated by a method. Use a progress bar to provide
feedback on the remaining run time for an application. The figure below shows
the Settings window of a progress bar object with one progress level.
Note that the built-in progress bar that is visible in the status bar of an application
is controlled by the Settings window of the Main Window node. By default, the
built-in progress bar shows the progress of the built-in COMSOL Multiphysics
core algorithms, such as geometry operations, meshing, and solving. By using the
| 265
setProgress method, you can customize the information shown in the built-in
progress bar. For more information, see “Progress Methods” on page 358 and the
Application Programming Guide.
The figure below shows the Settings window of a progress bar object with two
progress levels.
In this example, the progress bar object is part of a form progressform used to
present a two-level progress bar and a message log.
The figure below shows the corresponding progress dialog box in the running
application.
266 |
The figure below shows the form progressform.
The code segments below show typical built-in methods used to update the
progress bar and the message log.
// show progress dialog box:
dialog("progressform");
setProgressBar("/progressform/progress1", 0, "Computing prong length.");
// finished iterating:
setProgressBar("/progressform/progress1", 100);
closeDialog("progressform");
In the example above, the central functionality for updating the two levels of
progress bars lies in the call
setProgressInterval("Computing frequency", lastProgress,
k*100/MAXITERATIONS).
| 267
For detailed information on the built-in methods and their syntax, see “Progress
Methods” on page 358 and the Application Programming Guide.
G a ug e
The Gauge form object is similar to the knob form object but is read-only and used
to display a value by the position of a needle or arrow of a gauge. Optional tick
marks and labels are used to indicate the range of values that the gauge can display.
In addition to tick marks and labels, you can optionally configure a color scale to
indicate the values. The figure below shows a gauge object together with a data
display object, displaying the maximum stress in a structural mechanics
application.
268 |
The Settings window for a gauge object is similar to that of a knob object.
However, there are some differences. For example, there is no Events section for a
gauge object. The figure below shows the Settings window for a gauge object.
You can select any parameter, variable, or declared scalar variable as a source.
Select from the application tree and click Use as Source.
You determine the range of values for the data source by defining the Minimum
value, Maximum value, and Number of steps for the gauge.
| 269
You can enter a Tooltip that is shown when hovering over the gauge. The settings
for units are similar to that of a slider or knob.
In the Initial value list, select From data source or Custom value for the initial value
for the gauge.
The figure below shows the Unit, Number Format, and Position and Size sections.
270 |
The figure below shows the Appearance section.
The Needle color takes its Default value from the current color theme.
You can specify a sequence of color ranges for the gauge. Click the Add button in
the table toolbar to add another color range, which opens a dialog box.
In this dialog box you give the start and end values for a color range as well as the
start and end color. To edit an existing color range, select its row in the table and
click the Edit button. The Move up and Move down buttons can be used to reorder
the color ranges and the Delete button deletes the color ranges in the selected
rows.
The Start color and End color can take the value Transparent which means that they
get the same color as the current background color.
If the End value is less than the Start value, then the color range is rendered
backwards.
Log
The Log form object adds a log window that displays messages from the built-in
COMSOL Multiphysics core algorithms, such as geometry operations, meshing,
and solving.
| 271
The Include standard log toolbar check box is selected by default. When selected,
the toolbar in the Log window that you see in the COMSOL Desktop is included
in the application.
The figure below shows a part of an application user interface containing a log
window.
Me ssage Log
The Message Log object adds a window where you can display messages to inform
the user about operations that the application carries out. Implement this feature
272 |
using the built-in message method with syntax: message(String message). See
also “GUI-Related Methods” on page 353.
You can also display the value of a variable, for example: message(double
xcoordinate).
The Include standard message log toolbar check box is selected by default. When
selected, the toolbar in the Messages window that you see in the COMSOL
Desktop is included in the application. The Show COMSOL messages check box is
selected by default to enable messages from the built-in COMSOL Multiphysics
core algorithms, such as geometry operations, meshing, and solving. Clear the
check box to only allow messages from the application itself. You can include time
stamps to message by selecting the check box Add timestamps to messages.
| 273
The figure below shows a customized message window with convergence
information from a method (left) and the corresponding Message Log form object
(right).
Results Table
The source of the results table data is taken from Results and can be a child node
of Derived Values, a Table, or an Evaluation Group. In the figure below, a Table node
274 |
is used as the source (by selecting this option in the tree and then clicking Use as
Source.)
By clearing the check box Show headers, you can choose to hide the column
headers of the results table.
| 275
• Microsoft® Excel Workbook (.xlsx)
- Requires LiveLink™ for Excel®
Form
A form object of the type Form is used to organize a main form in one or more
subforms. To embed a subform, you create a link to it by selecting the form you
would like to link to from the Form reference of the Settings window for the
276 |
subform. The figure below shows an example where one of the cells of a form
mainComputer has a link to the subform form1.
The figure below shows the referenced form form1, which is a local form to the
form mainComputer.
If you are using grid layout mode, then you can quickly create subforms using the
Extract Subform button in the ribbon. See “Extracting Subforms” on page 125.
| 277
Form Collection
There are four different layout options. From the Type list, choose between:
• Tabs, the default setting, which displays the forms using tabbed panes.
• List, which displays a list to the left of the form panes, where you can select
the form to display.
• Sections, which displays each form in a separate section.
• Tiled or tabbed, which displays the forms in one of two ways depending on
the value of a Boolean variable. For more information, see the description
later in this section.
In the Forms section you can select which forms to display in the Form Collection.
These will be displayed in the app in the order they appear in the list. You can
change the order by clicking the Move Up and Move Down buttons.
The Default form list specifies which form to be shown by default. This setting is
not available for the option Sections.
278 |
You can control which tab (or list entry) is active by linking to a string variable in
the section Active Form Selector.
The string variable needs to be equal to one of the form names in the form
collection, such as temperature or conversion in the example above. Otherwise,
it will be ignored.
If you change the value of the form selector activePlot in the above example, in
a method that will be run at some point (a button method, for example), then the
form with the new value will be activated, as shown in the example below.
activePlot=”conversion”; /* Activate the conversion form on completion of
this method */
For a form collection with the Type set to Sections, the Active Form Selector has no
effect. Using an Active Form Selector is optional and is only needed if you wish to
control which tab is active by some method other than clicking its tab. To remove
a string variable used as an Active Form Selector, click the Clear source toolbar
button under the tree.
| 279
The Tiled or tabbed option displays the forms in one of two ways depending on
the value of a Boolean variable used as source in a Tiled or Tabbed section at the
top of the Settings window.
The tabbed mode is identical to a form collection with the Type set to Tabs. In
tiled mode, all the forms are shown simultaneously in a grid. The layout for
the tiled mode can be controlled by the settings in the subsection Tiled mode
settings.
In the table below the Forms section you can select which forms should be
Visible, by selecting the corresponding check box. For a form collection of the
280 |
type Sections, you can, in addition, control which forms should be Collapsible
and Expanded.
Card Stack
A Card Stack is a form object that contains cards. A Card is another type of form
object, one that is only used in the context of a card stack. Flip between cards in
a card stack to show one at a time. You associate a card stack with a data source
that controls which card to show. Each card specifies a value that is compared
against the data source of the card stack. The card stack shows the first card with
the matching value. If no cards match, nothing is shown.
| 281
The figure below shows the card stack object in the Form Editor.
In this example, the card stack contains cards with graphics objects.
The figure below shows a card stack Settings window with five cards and a string
variable display as its Active Card Selector.
By clicking a row in the table of cards in the Cards section, followed by clicking
one of the toolbar buttons below the table, you can perform the following
operations on cards:
• Delete
• Edit
282 |
• Add Card
• Duplicate
Each row in the table contains the name of the card in the Card column and their
associated activating values in the Activating value column. The stack decides
which cards to display based on their activating values. In this example, the
activating value is a Boolean variable.
Clicking the Add Card button displays the following dialog box.
By default, the Card type is set to Local, which means that the card is defined locally
in its containing card stack object. If the Card type is set to Existing form, then you
can instead select one of the existing forms. The settings for an Existing form are
accessed directly from the Form Editor by clicking its node or by clicking the Edit
button in the Card section of the corresponding card stack Settings window.
The figure below shows the Settings window of a Card as shown after clicking Edit
in the table in the section Cards.
| 283
To access locally defined cards, right-click the card stack in a form window to
select between the different cards in the card stack, as shown in the figure below.
284 |
The figure below shows card1 of the card stack resultsCardstack with a
graphics form object.
In the Position and Size section you can change the alignment and size of the card
stack and cards.
When selected, the check box Adjust size to selected card makes it possible to have
the card stack adjust its size to the currently selected card. When not selected, the
card stack will be as large as the largest card, regardless of which card is selected.
Before version 5.6, the card stack always took the size of its largest individual card,
which meant that even small or empty cards still took up space in the layout. Now,
| 285
when a card is empty, the card stack will disappear, which is a desirable feature in
many cases. Using it you can for example have a dynamic documentation card
stack appear and disappear depending on the user’s actions.
File Import
A File Import object is used to display a file browser with an associated input field
for browsing to a file or entering its path and name. It is used to enable file import
by the user of an application at run time, when the file is not available in the
application beforehand.
Consider an application where a CAD file can be selected and imported at run
time, as shown in the figure below.
286 |
The Settings window for the File Import object has a section File Destination. In this
section, you can select any tree node that allows a file name as input. This is shown
in the figure below, where the Filename for a geometry Import node is selected.
| 287
In this application, the File types table
specifies that only CAD files are allowed.
You can further control which File types are
allowed by clicking the Add and Delete
buttons below the list of File types. Clicking
the Add button displays the dialog box
shown to the right:
288 |
can use a menu, ribbon, toolbar item, or a button to open a file browser. The
figure below shows the Settings window of a button used to import a CAD file.
A File Import object can also reference a File declaration. For more information, see
“File” on page 169. For more information on file handling in general, see
“Appendix C — File Handling and File Scheme Syntax” on page 323.
The built-in method that corresponds to the command Import file is importFile.
For example, for importing an image you can use:
success=importFile("file1",new
String[]{"ALL_IMPORTABLE_IMAGES","PNG","JPEG","BMP","GIF"});
| 289
Information Card Stack
An Information Card Stack object is a specialized type of Card Stack object used to
display information on the relationship between the inputs given by the user to an
application and the solution. The figure below shows a portion of a running
application in which an information card stack is used together with information
on the expected computation time.
290 |
The figure below shows the Settings window where a string variable
solutionState is used as the source.
There are similarities with a Card Stack object, but for the Information Cards, each
card has an icon and text. In the figure above, the string variable values
nosolution, inputchanged, and solutionexists control which information
card is shown.
| 291
In this example, the information card stack is accompanied by a data display object
where a model tree information node for the Expected Computation Time is used
as the source. The figure below shows its Settings window.
Note that information nodes in the model tree are only shown when working with
the Application Builder. They are made available in the Source section in the
Settings window for form objects, when applicable.
You can also find information nodes with Last Computation Time under each study.
The information node Last Computation, found directly under the Model node, will
correspond to the computation time for the last computed study.
Information nodes can be used as a source for input field objects, text objects, and
data display objects. For input field objects and text objects, in order for the
information nodes to be accessible, the Editable check box has to be cleared.
292 |
The Expected Computation Time take its data from the root node of the application
tree, as shown below.
Array Input
An Array Input object has an input table used to enter array or vector-valued input
data. An array input object supports string arrays as data sources. You can add an
optional label, symbol, and unit.
| 293
U SING AN A RRAY I NPUT O BJECT FOR 3D P OINT C OORDINATE I NPUT
Consider an application where the user enters 3D coordinates for a point where
the stress is evaluated. The figure below shows a screenshot from an application
with an array input, button, text label, and data display object.
294 |
The figure below shows the Settings window of the array input object.
| 295
The Array Input form object uses a Source named sampleCoords, which is a 1D
Array of type Double. This array is created prior to the creation of the Array Input
object by declaring an Array 1D Double with the following Settings.
where the values pointx, pointy, and pointz will be used subsequently as
coordinates in the evaluation of the stress.
Radio Button
A Radio Button object has a fixed number of options from which you can choose
one. It is most useful when you have just a handful of options.
296 |
U SING R ADIO B UTTONS TO S ELECT A L OAD
Consider an application where the user can select one of three predefined loads,
as shown in the following figure.
The corresponding Settings window is shown below, where the global parameter
F is used as the source.
| 297
In the Choice List section, you can add choice lists that contribute allowed values
to the radio button object, where each valid value represents one radio button.
The radio button names are taken from the Display name column of their
associated choice list. The figure below shows the choice list used in this example.
Selection Input
In the Application Builder, you can allow the user of an application to interactively
change which entities belong to an Explicit selection with a Selection Input object
or a Graphics object. For more information on selections, see “Selections” on page
90.
You can choose to use a graphics object as the source of a selection without
having any selection input object. You can also link both a graphics object
and a selection input object to the same explicit selection.
298 |
In the example below, the embedded model has a boundary condition defined
with an Explicit selection. Both a Selection Input object and a Graphics object are
used to let the user select boundaries to be excited by an incoming wave.
The user can select boundaries here by clicking directly in the graphics window
corresponding to the Graphics object or by adding geometric entity numbers in a
list of boundary numbers corresponding to a Selection Input object.
To make it possible to directly select a boundary by clicking on it, you can link a
graphics object to an explicit Selection used to group boundaries, as shown in the
figure below. Select the explicit selection and click Use as Source.
| 299
In the figure below, there are two explicit selections, Excitation Boundary and Exit
Boundary, and the graphics object graphics2 is linked to the selection Excitation
Boundary.
When a graphics object is linked directly to an explicit selection in this way, the
graphics object displays the geometry and the user can interact with it by clicking
on the boundaries. The boundaries will then be added (or removed) to the
corresponding explicit selection.
300 |
To make it possible to select by number, you can link a selection input object to
an explicit selection, as shown in the figure below.
In a selection input object, you can copy, paste, remove, clear, and zoom into
selections.
You can have events associated with selections. The On data change event will be
triggered when the selection is changed. If you have a local method associated
with this event, you will get a method with an integer array argument. The
method is called with the new entities of the selection. The On activate event will
be triggered when the Activate Selection button is clicked.
| 301
Text
A Text object is a text field with default text that is taken from a string variable or
an Information node. The Settings window for a text object is shown below.
Select a string variable or Information node from the tree in the Source section and
then click Use as Source. In the Value field, enter the initial text. By default, the
Initial value text is taken from this field. To instead use the string variable for the
Initial value text, change the Initial value setting to From data source.
The check box Editable is cleared by default. If selected, the text object can be
used, for example, to type comments in a running application. If the text is
changed by the user, it is stored in the string variable that is used as the data
source, regardless of the Initial value setting.
The check box Wrap text is selected by default. Clear this check box to disable
wrapping of the text. A scroll bar appears if the text does not fit.
For more information on Information nodes, see “Data Display” on page 103.
Lis t B ox
A List Box object is similar to a radio button object, except that it allows for the
simultaneous selection of multiple options.
302 |
U SING A L IST B OX TO S UPERIMPOSE V IBRATIONAL M ODES
Consider an application where the first six vibrational modes of a mechanical part
can be superimposed and visualized by selecting them from a list box, as shown in
the figure below.
As an alternative, the following figure shows that a list can be displayed as a dialog
box.
| 303
The Settings window for the list box of this example is shown in the figure below.
The Select values in list allows you to choose between two alternatives, List box or
Dialog, for displaying the list.
You can use any scalar or array declaration as a source. Select from the tree and
click Use as Source. If you use a string array as the source, you can, in the running
application, select more than one item in the list using Shift+Click or Ctrl+click.
304 |
For other sources, you can only select one value from the list. This example uses a
1D string array svar1D. Its Settings window is shown below.
In the Choice List section, you can add choice lists that contribute allowed values
to the list box. The figure below shows the choice list used in this example.
The vibrational modes 1–6 correspond to trivial rigid body modes and are not of
interest in this application, hence the Value column starts at 7. The choice list
allows you to hide the actual mode values in the model from the user by only
displaying the strings in the Display name column. The first nonrigid body modes
are named Mode 1, Mode 2, etc.
The method below uses the COMSOL Multiphysics operator with() to visualize
the superimposed modes. This example is somewhat simplified, since it ignores the
effects of amplitude and phase for the modes.
String withstru="0";
String withstrv="0";
String withstrw="0";
| 305
for(int i=0;i<svar1D.length;i++){
withstru=withstru + "+" + "with(" + svar1D[i] + ",u)";
withstrv=withstrv + "+" + "with(" + svar1D[i] + ",v)";
withstrw=withstrw + "+" + "with(" + svar1D[i] + ",w)";
}
with(model.result("pg7").feature("surf1").feature("def"));
setIndex("expr", withstru, 0);
setIndex("expr", withstrv, 1);
setIndex("expr", withstrw, 2);
endwith();
useGraphics(model.result("pg7"),"/form1/graphics8");
zoomExtents("/form1/graphics8");
Assuming the user selected the modes 1, 3, and 5 by using the list box, the method
creates an expression with(1,u)+with(3,u)+with(5,u). This expression is then
used for the x-displacement (dependent variable u) in a displacement plot. In a
similar way, the method automatically creates expressions for the variables v and w
associated with the y- and z-displacement, respectively. Note that the command
with(), used in the results in the example above, is different from the built-in
with() command used to shorten syntax that is described in “With, Get, and Set
Methods” on page 362.
306 |
Table
A Table Object represents a table with rows and columns that can be used to define
input or output. The figure below shows an example of a running application with
a table object used to accept input in three columns.
The figure below shows the corresponding form object and its Settings window.
| 307
In this example, the data source references three 1D string arrays. You can select
any type of array as the source and then click Add to Table.
Three check boxes control the overall appearance of the table:
• Show headers
• Automatically add new rows
• Sortable
The Automatically add new rows check box ensures that an additional empty row
is always available when a user is filling out a table. If all of the 1D string arrays,
which are used as a source to the table, have nonempty values for New element
value in their declaration Settings window, then this functionality is deactivated. In
this case, new rows can only be added by clicking the Add button in the associated
table toolbar, if such a button has been made available.
The Sortable check box makes it possible to sort the table with respect to a
particular column by clicking the corresponding column header.
The Sources section contains a table with five columns:
• Header
• Width
• Grow
• Editable
• Alignment
• Data source
Each row in this table defines a column in the table object. The option Grow allows
individual columns to grow when a form is resized. This option is only applicable
to grid mode and if the Horizontal alignment of the table is set to Fill.
308 |
In the example, the string arrays define the initial values for the rows
corresponding to the three columns, as shown in the figure below:
You can control which source that determines the number of rows in the table. To
set this, right-click the corresponding array declaration in the Sources section and
select Set as Synchronizing Source.
T OOLBAR
In this section, you can select which toolbar items (buttons) should be used to
control the contents of the table. The Position list defines the location of the
toolbar relative to the table and provides the following options:
• Below
| 309
• Above
• Left
• Right
The Icon size setting allows you to choose Small or Large icons.
To add an item to the toolbar, click the Add Toolbar Item button below the table.
310 |
• Delete
• Load from File
• Save to File
• Clear Table
• Clear Table and Load from File
In addition, you can add customized items by clicking Custom Item or Custom
Toggle Item in the Toolbar Items dialog box. The figure below shows the Edit
Custom Toolbar Item dialog box used to define a customized button. The dialog
box has two tabs for a regular item and three tabs for a toggle item.
The Choose commands to run tab is similar to that of menu, ribbon, and toolbar
items, as well as buttons.
The Load from File and Save to File buttons are used to load and save from/to the
following file formats:
• Text File (.txt)
• Microsoft® Excel Workbook (.xlsx)
- Requires LiveLink™ for Excel®
| 311
This is shown in the figure below.
The allowed separators are comma, semicolon and tab for CSV files, and space and
tab for DAT and TXT files.
Slider
A Slider is a form object for choosing numerical input using a slider control.
In this example, the slider is accompanied by an input field that is used to display
the selected value.
312 |
The Settings window of the slider is shown in the figure below.
In this example, the slider uses a global parameter F as its source. You can select
any parameter, variable, or declared scalar variable as a source. Select from the
application tree and click Use as Source.
You determine the range of values for the data source by defining the Minimum
value, Maximum value, and Number of steps for the slider. The Orientation can be
Horizontal or Vertical. You can also set a Tooltip that is shown when hovering over
the slider. The Append unit to number option lets you associate a unit with the
slider. This unit is appended to the number using the standard bracket notation,
such as [N], before being passed as a value to the source variable. In the example
above, the input field and the slider both have the setting Append unit to number
activated. As an alternative to Append unit to number, you can choose Append unit
from unit set. See “Unit Set” on page 170 for more information.
| 313
In the Initial value list, select From data source or Custom value for the initial value
for the slider.
In the Events section, in addition to specifying which method to call for an On data
change event, you can select the check box Trigger while dragging. This setting
determines if the event method should be called continuously while the slider is
being dragged or only upon its release.
This setting can be useful if the method that is called by the On data change event
is computationally heavy, so that there is a lag when dragging the slider.
Knob
A Knob is a form object for choosing numerical input using a control knob, similar
to a slider.
U SING A K NOB TO C HANGE THE A NGLE OF A C RANE A RM
Consider an application where the angle of a truck mounted crane arm can be
changed by control knobs, such as in the figure below (which uses a dark theme).
In this example, the knobs are accompanied by input fields that are used to display
the selected value.
314 |
The Settings window of one of the knobs is shown in the figure below.
In this example, the knob uses a string variable Angle1 as its source. You can select
any parameter, variable, or declared scalar variable as a source. Select from the
application tree and click Use as Source.
You determine the range of values for the data source by defining the Minimum
value, Maximum value, and Number of steps for the knob.
The Mouse movement can be Distance, Vertical, or Circular. Distance changes the
value with a linear mouse movement in any direction. Vertical changes the value
when you move the mouse vertically. Circular changes the value when you make a
circular mouse movement. A physical control knob is usually controlled with a
circular movement. However, when using a mouse this is usually not the most
convenient way. Instead, use a linear mouse movement by selecting Distance or
Vertical.
You can also set a Tooltip that is shown when hovering over the knob. The settings
for units are similar to that of a slider.
In the Initial value list, select From data source or Custom value for the initial value
for the knob.
| 315
In the Events section, in addition to specifying which method to call for an On data
change event, you can select the check box Trigger while dragging. This setting
determines if the event method should be called continuously while the knob is
being dragged or only upon its release.
This setting can be useful if the method that is called by the On data change event
is computationally heavy, so that there is a lag when dragging the knob.
Hyperlink
316 |
The figure below show the corresponding Settings window.
The Hyperlink object supports the types of URLs that you can use in a web
browser, including:
• Web Page: When a user clicks the hyperlink for a web page, it opens in the
user’s default browser. The URL string needs to be on the form
protocol://address, where protocol is the transmission protocol; for
example, HTTP or HTTPS. The web address can be partial or complete, but
it is recommended to use a complete web address.
• Email: An email address is specified on the form mailto:emailaddress. This
will launch the user’s default email application program and prepare a new
message where the To field is set to the address specified. This way of
interactively sending an email from a COMSOL application is different from
using the built-in method. For more information on the built-in methods
for email, see “Email Methods” on page 350.
| 317
Toolbar
A Toolbar object contains the specifications of a toolbar with toolbar buttons. The
figure below shows a toolbar with buttons for Save as, Compute, and Plot.
The Settings window for this toolbar is shown in the figure below.
Each row in the Toolbar Items table contains either an Item or Toggle Item
corresponding to a toolbar button or toggle button, respectively, or a Separator.
Use the buttons below the table to add items or separators, change the row order,
or delete a row. Click the Edit button to display the Settings window associated
318 |
with each row. The figure below shows the Settings window of item1, the Save As
item.
The text in the Tooltip field will be shown as a tooltip when hovering over the
toolbar button. The text in the Text field will be shown next to the icon, if any;
otherwise just the text is shown. The Icon list, the Keyboard shortcut field, and the
Choose commands to run tree represent the same functionality as a button object.
For more information, see “Button” on page 65.
Spacer
A Spacer object is invisible in the user interface and is only used when working in
grid layout mode. It defines a space of fixed size that you can use to ensure that
neighboring form objects have enough space to show their contents. Typically,
you would use a spacer next to a table or graphics object to ensure that they are
rendered properly. If the user resizes the window so that it becomes smaller than
| 319
the size of the spacer, the effective size of the window is maintained by displaying
scroll bars. The figure below shows the Settings window of a spacer object.
320 |
Appendix B — Copying Between Applications
Many nodes in the application tree can be copied and pasted between applications,
including: forms, form objects, menu items, methods, Java® utility methods,
external libraries, file declarations, choice list declarations, menus, menu items,
ribbon sections, ribbon tabs, and ribbon items.
When you copy and paste forms, form objects, and items between applications, the
copied objects may contain references to other objects and items. Such references
may or may not be meaningful in the application to which it is copied. The
following set of rules apply when objects are pasted from the clipboard:
• A declaration referenced in a form object or menu item is included when
copying the object, but is not necessarily pasted. It is only pasted if there is
no compatible declaration present. If a compatible declaration exists, that is
used instead. A compatible declaration is defined as one having the same
name and type. For example, a string declaration is not compatible with an
integer declaration. An existing declaration may have an invalid default, but
no such check is done when pasting.
• A referenced global parameter may have a different unit, but will still be
considered compatible.
• A form or form object directly referenced from another form object is not
included automatically when copying objects. The direct reference will point
to an existing object if it has the same name. If the original reference is
among the copied objects, then that object will be used in the reference
instead of any existing objects having the same name. The name of the
copied reference will be changed to avoid name collisions.
• No objects in the model tree will be automatically copied, for example, a
graphics object referring to a geometry or an input field referring to a
low-level setting exposed by Data Access. If the reference points to an object
that exists in the model tree of the target application, then that reference will
be used.
• References to nonexisting objects will be attempted to be removed when
pasted. An exception is command sequences in buttons, where all commands
are kept and marked as invalid if they point to a nonexisting reference.
• Local methods are included in the copy-paste operation. However, no
attempt is made to update the code of the method. This also applies when
copying a global method.
• Arguments to commands in the command sequence of a button or a menu
item will be left as is.
| 321
• All image references are automatically copied and added to the image library
when applicable. If there is an existing image with the same name, it will be
used instead of the copied version.
• No files, sounds, or methods are automatically copied if referenced to.
However, methods can be copied and pasted manually.
• All pasted objects that have a name that conflicts with that of an existing
object will be renamed. Any references to the renamed object from other
pasted objects will be updated.
322 |
Appendix C — File Handling and File Scheme Syntax
In general, you cannot read and write files to local directories when running
applications with a web browser or the COMSOL Client for Windows®. The
application and its methods are run on the server and have no knowledge of the
client file system (where the web browser or COMSOL Client is run).
However, there are techniques for transferring files to and from the client file
system when running an application both with a web browser and the COMSOL
Client.
A File Import object can be used to ask the user for a file. The user then browses
to a file on the client file system, which is then uploaded to the COMSOL Server
file system and becomes available to the application and its methods. This can be
used, for example, to provide a CAD file or an experimental data file from the user
at run time. This is covered in the section “File Import” on page 328.
In a command sequence of, for example, a button, you can export data generated
by the embedded model by running a subnode of the Export or Report nodes. This
is covered in the section “File Export” on page 335.
| 323
S AVING AND O PENING F ILES USING F ILE C OMMANDS
In the editor tree used in a command sequence, the File Commands folder contains
commands to save and load applications and files, as well as exiting an application.
The command Open File will pick any file from the server produced by a method,
the model, or embedded with the application, and open it using the associated
application on the client. This can be used, for example, to open a PDF file in the
client file system, or show a text file or an image exported from the model on the
client side. In the figure above, an Open File command is used to open the PDF
documentation for an application. The corresponding PDF file is embedded in the
application by being stored in the Libraries > Files node. Files located there are
referenced using the embedded:/// file scheme syntax described in the next
section, “File Scheme Syntax” on page 326.
324 |
To open files from a method, use the built-in method fileOpen; see also
“Operating System Methods” on page 350.
To save a file, use the command Save File As, which is similar to Open File. It will
take any file from the server file system and display a Save As dialog box to the user
where the user can browse to a client location to save the file. This is similar to
downloading files from a link within a web browser. In the figure below, a Save
File As command is used to save a CAD model that is stored in the Libraries > Files
node.
To save files from a method, use the built-in method fileSaveAs; See also “GUI
Command Methods” on page 356. For more information on saving and exporting
files, see “File Export” on page 335.
The Save Application and Save Application As commands are available for use in the
command sequence for certain form objects. The Save Application As command
will display a Save As dialog box where the user can specify a client path where the
entire application will be saved.
Similarly, the Save Application on Server and Save Application on Server As
commands are available to save the entire application on the server file system. For
information on the corresponding built-in methods, see “GUI Command
Methods” on page 356.
In summary, both uploading and downloading files from the client file system is
supported, but, due to web browser and system security settings, the application
can never do it silently in the background without the user browsing to the source
or destination location of the file.
| 325
M ODEL C OMMANDS
In the editor tree used in a command sequence, the Model Commands folder
contains two commands: Clear all solutions and Clear all meshes. Use these
commands to make the MPH-file size smaller before saving an application by
erasing solution and mesh data, respectively.
To make applications portable, the Application Builder allows you to use virtual
file locations using file schemes. A file scheme can be seen as a pointer to a file on
the file system, but the application does not need to know where the file is actually
stored (this is set in the Preferences dialog box, see below.)
Different file schemes exist for different purposes:
• The user file scheme is for files that should be persistent between different
runs of an application by the same user.
• The common file scheme behaves in the same way, but is for files that should
be shared between all users.
• The temp file scheme is for files that should be removed as soon as the
application is closed.
326 |
• The embedded file scheme is used to store files in the application itself. This
can be useful if you want to make the application self-contained and send it
to someone else.
• The upload file scheme is for files that are uploaded to the application by the
user at runtime, such as a CAD file to which the user browses.
The table below summarizes all available file schemes.
| 327
USAGE EMBEDDED UPLOAD TEMP USER COMMON
File Import
CAD I MPORT USING THE M ODEL T REE AND A F ILE I MPORT O BJECT
A File Import object is used to display a file browser with an associated input field
for browsing to a file or entering its path and name. It is used to enable file import
by the user of an application at run time, when the file is not available in the
application beforehand. You can directly link a File Import object to a file Import
node in the model tree; for example, a CAD Import node. Consider an application
328 |
where a CAD file can be selected and imported at run time, as shown by the figure
below.
The Settings window for the File Import object has a section File Destination. In this
section, you can select any tree node that allows a file name to be input. This is
shown in the figure below, where the Filename for the Import node is selected.
| 329
If you do not wish to use a File Import object, you can directly reference a Filename
from a button or an item in a menu, ribbon, or toolbar, or alternatively create a
method that calls the built-in method importFile as an event, for example
importFile("file1");
330 |
In the Settings window above, the command Import file to Import 1 will open a file
browser for the user to select a file, as shown in the figure below.
The preceding command Set Type of Import allows you to filter the file extensions
displayed in the file browser. The available arguments are: file, mesh, native,
cad, and ecad.
The subsequent commands build and plot the geometry and zoom out using
zoom extents.
For more information on the File Import object, see “File Import” on page 286.
The first line illustrates using the built-in method importFile. For more
information on the method importFile and other methods for file handling, see
“File Methods” on page 348 and the Application Programming Guide.
| 331
using:). The figure below shows an example where a File Destination and Filename
are used.
However, a quicker way is to link a file import object directly to the Filename field,
as described previously in the section “CAD Import using the Model Tree and a
File Import Object” on page 328.
332 |
I MPORTING E XPERIMENTAL D ATA
Consider an application where the user is providing a file with experimental data
at run time. The figure below shows the file import object of such an application
as it appears in grid layout mode.
The figure below shows the Settings window of the corresponding file import
object and its link to a file declaration.
| 333
In this application, the File types table specifies that only CSV files are allowed. The
Settings window for the File declaration is shown in the figure below.
The file declaration serves as the “destination” of the imported data, which is
written to the file upload:///experimental.csv.
Note that the file extension .csv used in the declaration is optional and that the
file picked by the user at run time can have any name. For example, the file name
picked at run time can be my_data.csv, but when referenced in method code, the
abstract file handle name experimental.csv is always used.
In order to make it possible to run the application without having to first provide
experimental data, a file containing default experimental data is embedded in the
application. This default data file is used by the application by accessing it with the
embedded:/// file scheme syntax, as shown in the figure below.
In this example, which uses the Optimization Module, the application performs a
least-squares fit to the experimental data.
334 |
The following method handles the logic to determine if user-provided
experimental data files exist or if the default data set should be used.
if (exists("upload:///experimental.csv")) {
with(model.physics("opt").feature("glsobj1"));
set("fileName", "upload:///experimental.csv");
endwith();
}
else{
String s_data = confirm("No experimental data file was uploaded. Do you
want to use the embedded data?", "Experimental Data", "Yes", "Cancel
Parameter Estimation");
if(s_data.equals("Cancel Parameter Estimation")){
return;
}
}
File Export
| 335
The Settings window for each of these nodes contains an Output section with a
field for Filename. The figure below shows the Settings window for an Export > Plot
node.
You can leave the Filename field blank, as shown in the figure above. In the
command sequence of, for example, a button, you can run the corresponding
Export > Plot node and, at run time, it will open a file browser window for the user
to select a location and file name, as seen in the figure below.
While developing an application, you may need to use the Model Builder
repeatedly to check the exported data. In this case, you can use the Filename field
for a test file and, by selecting the Always ask for filename check box, a file browser
will still be opened at run time.
336 |
In a similar way to the Export subnodes, each Report subnode has a Format section
with a Filename field, as seen in the figure below.
By running a Report subnode, a file browser window is opened for the user to
select a location and file name for the report.
For more detailed control over file import and export, you can instead use a file
scheme.
| 337
The example below shows the Settings window of an Export > Plot node that is
used to export plot data as numerical values.
338 |
In the Output section of the button Settings, set the filename to the name of the
temporary file created by the Export Plot command, in this case,
temp:///lineplot.txt.
| 339
The Save File As command provides a dedicated Edit Argument dialog box
with easy access to all embedded files as well as shortcuts for all file
schemes.
340 |
The example below shows an application where a report in the Microsoft® Word
format (.docx) can be saved by the user. The figure below shows a tab in the
ribbon of the application. In this tab, there is a Report button in the Documentation
section.
| 341
The following figure shows how the syntax user:/// was used in the Filename
field in the Settings window of the Report node of the Model Builder.
In this application, the check box Open finished report is selected, which means
that the Word® document will open after the report has been created. The user of
the application can then save the report from the Word® file menu.
In this example, the file scheme common:/// could have been used in the same
way. The user and common file schemes are primarily useful when the same files
are used repeatedly by an application.
342 |
The figure below shows the Settings window of the Report ribbon item.
The file scheme syntax can also be used directly in methods. The code below is
from a method used to export an HTML report.
String answerh = request("Enter file name","File Name", "Untitled.html");
if(answerh != null){
model.result().report("rpt1").set("format","html");
model.result().report("rpt1").set("filename","user:///"+answerh);
model.result().report("rpt1").run(); }}
| 343
Appendix D — Keyboard Shortcuts
The table below lists the keyboard shortcuts available in the Application Builder.
For a list of additional keyboard and mouse shortcuts, see the book Introduction
to COMSOL Multiphysics.
344 |
SHORTCUT ACTION APPLICATION FORM METHOD
BUILDER EDITOR EDITOR
| 345
SHORTCUT ACTION APPLICATION FORM METHOD
BUILDER EDITOR EDITOR
346 |
Appendix E — Built-In Method Library
This appendix lists all of the built-in methods available in the Method Editor,
except for methods that operate on the model object and the application object.
For detailed information on using the built-in methods and for full information
on the syntax used, see the Application Programming Guide and the
Programming Reference Manual.
As an alternative method of learning the syntax of these methods, you can use
code completion by typing the name of the method and then use Ctrl+Space. A
window will open with information on the syntax and method signature.
NAME DESCRIPTION
clearModel Clears the model object contents.
createModel Creates a new model with a given tag.
removeModel Removes a model. The embedded model cannot be removed.
modelTags Returns an array of model tags for all loaded models, including the
embedded model.
uniqueModeltag Returns a model tag that is not in use.
getModel Returns a model with a specified tag.
loadModel Loads a model with a specified tag from a file.
loadProtectedModel Loads a password protected model with a specified tag from a file.
loadRecoveryModel Loads a model from a recovery directory/folder structure.
saveModel Saves a model to a file. The filename can be a file scheme path or,
if allowed by security settings, a server file path.
getComsolVersion Returns the current software version as a string.
| 347
File Methods
NAME DESCRIPTION
readFile Returns the contents in a given file as a string.
openFileStreamReader Returns a CsReader object that can be used to read
line-by-line or character-by-character from a given file
name.
openBinaryFileStreamReader Returns a CsBinaryReader object that can be used to
read from a given file byte-by-byte.
readMatrixFromFile Reads the contents of the given file into a double matrix.
The file has the same spreadsheet-type format as available
in the model tree Export node.
readStringMatrixFromFile Reads the contents of the given file into a string matrix.
The file has the same spreadsheet-type format as available
in the model tree Export node.
readCSVFile Reads a file with comma-separated values (CSV file) into
a string matrix. It expects the file to use the RFC 4180
format for CSV.
writeFile Writes array data to a given file. If the spreadsheet
format is used, then the data can be read by
readMatrixFromFile or
readStringMatrixFromFile.
openFileStreamWriter Returns a CsWriter object that can write to a given file.
openBinaryFileStreamWriter Returns a CsBinaryWriter object that can be used to
write to a given file byte-by-byte.
writeCSVFile Writes a given double or string array to a CSV file. The
RFC 4180 format is used for the CSV.
exists Tests whether a file with a given name exists.
deleteFile Deletes a file with a given name if it exists. The file is
deleted on the server.
copyFile Copies a file on the server. Both the source and target
names can use file scheme paths.
importFile Displays a file browser dialog box and uploads the
selected file to the file declaration with the given name.
Alternatively, it uploads the selected file to the Filename
text field in a given model object entity.
writeExcelFile Writes the given string array data starting from a
specified cell in a specified sheet of an Excel file.
readExcelFile Reads a specified sheet of an Excel file, starting from a
specified cell, into a 2D string array.
348 |
NAME DESCRIPTION
getFilePath Returns the absolute server file path of the server proxy
file corresponding to a certain file scheme path, or null if
the server proxy file for the given path does not exist.
This method can be used to pass the path to, for
example, a file using the temp:/// scheme to external
code or an application.
getClientFileName Returns the original name of an uploaded file on the client
file system (or null if there is no uploaded file matching
the given file scheme path).
This method is only useful for providing user interface
feedback; for example, to get information on which
uploaded file is being used. There is no guarantee that the
original file would still exist on the client or even that the
current client would be the same as the original client.
getClientFilePath Returns the original path of an uploaded file on the client
file system (or null if there is no uploaded file matching
the given file scheme path).
This method is only useful for providing user interface
feedback; for example, to get information on which
uploaded file is being used. There is no guarantee that the
original file would still exist on the client or even that the
current client would be the same as the original client.
| 349
Operating System Methods
NAME DESCRIPTION
executeOSCommand Executes the OS command with a given command (full path) and
parameters. When applicable, the command is run server side.
fileOpen Opens a file with the associated program on the client. See also
the section “File Methods”.
getUser Returns the username of the user that is running the application. If
the application is not run from COMSOL Server, then the value
of the preference setting General>Username>Name is returned.
openURL Opens a URL in the default browser on the client.
playSound Plays a sounds on the client.
Email Methods
NAME DESCRIPTION
emailFromAddress Returns the email from address from the COMSOL Server or
preferences setting.
sendEmail Sends an email to the specified recipient(s) with the specified
subject, body text, and zero or more attachments created from
Report, Export, and Table nodes in the embedded model.
userEmailAddress Returns the user email address(es) corresponding to the currently
logged in user, or an empty string if the user has not configured an
email address.
NAME DESCRIPTION
EmailMessage Creates a new EmailMessage object.
EmailMessage.setServer Sets the email (SMTP) server host and port to
use for this email message.
EmailMessage.setUser Sets the username and password to use for email
(SMTP) server authentication. This method must
be called after the setServer method.
EmailMessage.setSecurity Sets the connection security type for email
(SMTP) server communication.
EmailMessage.setFrom Sets the from address.
350 |
NAME DESCRIPTION
EmailMessage.setTo Sets the to addresses.
EmailMessage.setCc Sets the cc addresses.
EmailMessage.setBcc Sets the bcc addresses.
EmailMessage.setSubject Sets the email subject line. Note that newline
characters are not allowed.
EmailMessage.setBodyText Sets the email body as plain text. An email can
contain both a text and an HTML body.
EmailMessage.setBodyHtml Sets the email body as HTML text. An email can
contain both a text and an HTML body.
EmailMessage.attachFile Adds an attachment from a file. The attachment
MIME type is determined by the file name
extension.
EmailMessage.attachFile Adds an attachment from a file with a specified
MIME type.
EmailMessage.attachFromModel Adds an attachment created from a report,
export, or table feature in the model.
EmailMessage.attachText Adds a text attachment with a specified
sub-MIME type, such as plain or HTML.
EmailMessage.attachBinary Adds an attachment from a byte array with a
specified MIME type.
EmailMessage.send Sends the email to the email (SMTP) server. An
email object can only be sent once.
| 351
E MAIL P REFERENCES
To set preferences for an outgoing email (SMTP) server, open the Email page of
the Preferences dialog box, as shown in the figure below.
352 |
GUI-Related Methods
NAME DESCRIPTION
Call a method directly Call a method from the Methods list by using its name; for
example, method1(), method2().
callMethod Alternate way to call a method from the Methods list;
used internally and in cases of name collisions.
useGraphics Plots a given entity (Plot Group, Geometry, Mesh, or
Explicit Selection) in the graphics form object given by a
name or name path in the second argument.
openForm Shows the form with the given name in the current main
window. In a single window application, the form replaces
the current one. In an application with subwindows, the
form must exist in the main window layout. If not, it will
not be opened. Showing a form that is already open will
only activate the form.
closeForm Closes the form with the given name. Closing forms is
only possible in applications using subwindows. This
method is not applicable for single window applications.
closeDialog Closes the form, shown as a dialog box, with a given
name.
dialog Shows the form with a given name as a dialog box.
Equivalent to the dialog method of a Form object; see
below.
alert Stops execution and displays an alert message with a
given text.
alert Stops execution and displays an alert message with a
given text and title.
confirm Stops execution and displays a confirmation dialog box
with a given text and title. It also displays two or three
buttons, such as “Yes”, “No”, and “Cancel”.
error Stops execution and opens an error dialog box with a
given message.
request Stops execution and displays a dialog box with a text field,
requesting input from the user.
message Sends a message to the message log.
clearLog Clears the log window.
clearMessageLog Clears the message log window.
| 353
NAME DESCRIPTION
evaluateToResultsTable Evaluates a given entity, a Derived Value, in the table
object given by the name or name path in the second
argument, which will then be the default target for the
evaluations of the Derived Value. If the third argument is
true, the table is cleared before adding the new data.
Otherwise, the data is appended.
evaluateToDoubleArray2D Evaluates the given entity, a Derived Value, and returns
the nonparameter column part of the real table that is
produced as a double matrix. All settings in the numerical
feature are respected but those in the current table
connected to the numerical feature are ignored.
evaluateToIntegerArray2D Evaluates the given entity, a Derived Value, and returns
the nonparameter column part of the real table that is
produced as an integer matrix. All settings in the
numerical feature are respected, but those in the current
table connected to the numerical feature are ignored.
evaluateToStringArray2D Evaluates the given entity, a Derived Value, and returns
the nonparameter column part of the potentially complex
valued table that is produced as a string matrix. All
settings in the numerical feature are respected, but those
in the current table connected to the numerical feature
are ignored.
useResultsTable Shows the values from the tableFeature in the
resultsTable form object.
getChoiceList Returns an object of the type ChoiceList, representing
a choice list node under the declarations branch. The type
ChoiceList has associated methods that make it easy
to change values and display names, see the Application
Programming Guide.
setFormObjectEnabled Sets the enable state for the form object specified by the
name or name path.
setFormObjectVisible Sets the visible state for the form object specified by the
name or name path.
setFormObjectText Sets the text for the form object specified by the name or
name path in the second argument. This method throws
an error if it is impossible to set a text for the specified
form object.
setFormObjectEditable Sets the editable state for the form object specified by the
name or name path. This functionality is only available for
text field objects.
354 |
NAME DESCRIPTION
setMenuBarItemEnabled Sets the enable state for the menu bar item specified by
the name or name path (from the menu bar) in the first
argument.
setMainToolbarItemEnabled Sets the enable state for the main toolbar item specified
by the name or name path (from the main toolbar) in the
first argument.
setFileMenuItemEnabled Sets the enable state for the file menu item specified by
the name or name path (from the file menu) in the first
argument.
setRibbonItemEnabled Sets the enable state for the ribbon item specified by the
name or name path (from the main window) in the first
argument.
setToolbarItemEnabled Sets the enable state for the toolbar form object item
specified by the name or name path in the first argument.
useView Applies a view to the graphics contents given by the name
or name path in the second argument.
resetView Resets the view to its initial state in the graphics contents
given by the name or name path in the second argument.
getView Returns the view currently used by the graphics contents
given by the name or name path in the second argument.
goToView Goes to one of the “xy”, “xz“, “yx“, “yz“, “zx“, or “zy”
views in the main graphics window or in the graphics
window of a form object.
setWebPageSource Sets the source for the form object specified by the name
or name path in the first argument.
getScreenHeight Returns the height in pixels of the primary screen on the
client system, or of the browser window if Web Client is
used.
getScreenWidth Returns the width in pixels of the primary screen on the
client system, or of the browser window if Web Client is
used.
| 355
GUI Command Methods
NAME DESCRIPTION
clearAllMeshes Clears all meshes.
clearAllSolutions Clears all solutions.
clearSelection Clears the selection in the given graphics object.
exit Exits the application.
fileOpen Opens a file with the associated program on the client.
fileSaveAs Downloads a file to the client. See also the section “File Methods”.
printGraphics Prints the given graphics object.
saveApplication Saves the application.
saveApplicationAs Saves the application under a different name. (Or as an MPH-file.)
scenelight Toggles scene light in the given graphics object.
selectAll Selects all objects in the given graphics object.
transparency Toggles transparency in the given graphics object.
zoomExtents Makes the entire model visible in the given graphics object.
zoomToSelection Zooms to the current selection.
Debug Methods
NAME DESCRIPTION
clearDebugLog Clears the Debug Log window.
debugLog Prints the value of an input argument to the Debug Log window.
The input argument can be a scalar, 1D array, or 2D array of the
types string, double, integer, or Boolean.
E XTERNAL M ETHOD
NAME DESCRIPTION
external Returns an interface to an external C (native) library given by the
name of the library feature. The External class uses the Java
Native Interface (JNI) framework. For more information, see the
Application Programming Guide.
356 |
M ETHODS R ETURNED BY THE E XTERNAL M ETHOD
The external method returns an object of type External with the following
methods:
NAME DESCRIPTION
invoke Invokes a named native method in the library with the supplied
arguments.
invokeWideString Invokes the named native method in the library with the supplied
arguments.
close Releases the library and frees resources. If you do not call this
method, it is automatically invoked when the external library is no
longer needed.
| 357
Progress Methods
NAME DESCRIPTION
setProgressInterval Sets a progress interval to use for the top-level progress and
display message at that level.
Calling this method implicitly resets any manual progress
previously set by calls to setProgress().
setProgress Sets a value for the user-controlled progress level.
resetProgress Removes all progress levels and resets progress to 0 and the
message to an empty string.
showIndeterminatePr Shows a progress dialog box with an indeterminate progress bar,
ogress given message, and an optional cancel button.
showProgress Shows a progress dialog box with an optional cancel button,
optional model progress, and one or two levels of progress
information.
closeProgress Closes the currently shown progress dialog box.
startProgress Resets the value of a given progress bar form object name to 0.
setProgressBar Sets the value of a given progress bar form object name in the
range 0 –100 and the associated progress message.
NAME DESCRIPTION
currentDate Returns the current date as a string (formatted according to the
server's defaults) for the current date.
currentTime Returns the current time as a string (not including date and formatted
according to the server's defaults).
formattedTime Returns a formatted time using the given format. The format can
either be a time unit or text describing a longer format.
sleep Sleep for a specified number of milliseconds.
timeStamp Current time in milliseconds since midnight, January 1, 1970 UTC.
getExpectedComp Returns a string describing the approximate computation time of the
utationTime application. The string can be altered by the method
setExpectedComputationTime.
358 |
NAME DESCRIPTION
setLastComputat Set the last computation time, overwriting the automatically
ionTime generated time.
You can use the timeStamp method to record time differences and
then set the measured time in ms (a long integer).
getLastComputat Returns the last computation time in the given format. The format can
ionTime either be a time unit or text describing a longer format. This format is
localized and the output is translated to the current language setting.
| 359
License Methods
NAME DESCRIPTION
checkoutLicense Checks out one license for each specified product.
checkoutLicenseForFil Checks out one license for each product required to open an
e MPH-file.
checkoutLicenseForFil Checks out one license for each product required to open an
eOnServer MPH-file.
getLicenseNumber Returns a string with the license number for the current
session. Example: licensenumber=getLicenseNumber()
hasProduct Returns true if the COMSOL installation contains the
software components required for running the specified
products.
hasProductForFile Returns true if the COMSOL installation contains the
software components required for running the specified
MPH-file.
hasProductForFileOnSe Returns true if the COMSOL installation contains the
rver software components required for running the specified
MPH-file.
Conversion Methods
NAME DESCRIPTION
toBoolean Converts strings and string arrays to Booleans. (‘true’ returns true, all
other strings return false).
toDouble Converts floats, float arrays, strings, and string arrays to doubles.
toInt Converts strings and string arrays to integers.
toString Converts Booleans, integers, and doubles, including arrays, to strings.
Array Methods
NAME DESCRIPTION
getColumn Returns a string, double, integer, or Boolean array for a specified column
in a 2D array (matrix). This is, for example, useful when values have been
read from a file and only certain columns should be shown in a table.
getSubMatrix Returns a rectangular submatrix of an input matrix. Available for string,
double, integer, or Boolean 2D arrays.
insert Inserts one or more elements in an array and returns the expanded array.
Available for string, double, integer, or Boolean arrays.
360 |
NAME DESCRIPTION
append Adds one or more elements to the end of an array and returns the
expanded array. Available for string, double, integer, or Boolean arrays.
remove Removes one or more elements from an array and returns the shortened
array. Available for string, double, integer, or Boolean arrays.
insertRow Inserts one or more rows into a rectangular 2D array and returns the
expanded array. Available for string, double, integer, or Boolean arrays.
appendRow Adds one or more rows to the end of a rectangular 2D array and returns
the expanded array. Available for string, double, integer, or Boolean arrays.
removeRow Removes one or more rows from a 2D array and returns the reduced
array. Available for string, double, integer, or Boolean arrays.
replaceRow Replaces one or more rows in a rectangular 2D array and returns the
array. Available for string, double, integer, or Boolean arrays.
insertColumn Adds one or more columns into a rectangular 2D array and returns the
expanded array. Available for string, double, integer, or Boolean arrays.
appendColumn Adds one or more columns at the end of a rectangular 2D array and
returns the expanded array. Available for string, double, integer, or
Boolean arrays.
removeColumn Removes one or more columns from a rectangular 2D array and returns
the smaller array. Available for string, double, integer, or Boolean arrays.
replaceColumn Replaces one or more columns in a rectangular 2D array and returns the
array. Available for string, double, integer, or Boolean arrays.
matrixSize Returns the number of rows and columns of a matrix as an integer array
of length 2. Available for string, double, integer, or Boolean arrays.
| 361
String Methods
NAME DESCRIPTION
concat Concatenates a given array or matrix of strings into a single string using
the given separators.
contains Returns true if a given string array contains a given string.
find Returns an array with the indices to all occurrences of a string in a string
array.
findIn Returns the index to the first occurrence of a string in a string array or the
first occurrence of a substring in a string.
length Returns the length of a string.
replace Returns a string where a string has been replaced with another string.
split Returns an array of strings by splitting the given string at a given separator.
substring Returns a substring with the given length starting at the given position.
unique Returns an array of strings with the unique values in the given array of
strings.
Collection Methods
NAME DESCRIPTION
copy Returns a copy of the given array or matrix. Available for string, double,
integer, or Boolean arrays.
equals Returns true if all elements in the given array are equal and they have the
same number of elements. Available for string, double, integer, or Boolean
arrays. For doubles, comparisons are made using a relative tolerance.
sort Sorts the given array. Note: The array is sorted in place. Available for
string, double, or integer arrays. If the array is two-dimensional (a matrix),
the columns are sorted by their row values from top to bottom.
merge Returns an array with all of the elements merged from the given arrays.
Available for string, double, or integer arrays.
NAME DESCRIPTION
with Used to make code more compact.
endwith The ending of a with statement.
set Sets a Boolean, integer, double, or string property value. Allows
for a scalar, array, or matrix property.
362 |
NAME DESCRIPTION
setIndex Sets a string, double, or integer property value for a matrix or
vector at a given index.
getIntArray Gets an integer vector property.
getIntMatrix Gets an integer matrix property.
getBoolean Gets a Boolean property.
getBooleanArray Gets a Boolean vector property.
getBooleanMatrix Gets a Boolean matrix property.
getDouble Gets a double property.
getString Gets a string scalar, vector, or matrix property.
getDoubleArray Gets a double vector property or parameter.
getDoubleMatrix Gets a double matrix property or parameter.
getStringArray Gets a string vector property or parameter.
getStringMatrix Gets a string matrix property or parameter.
getDblStringArray Returns the value as a matrix of strings.
getInt Gets an integer property.
get Returns a variable expression.
descr Returns a variable description.
NAME DESCRIPTION
getCurrentComponent Returns an object of the type ModelNode for the current
component.
getCurrentPhysics Returns an object of the type Physics for the current physics
interface.
getCurrentMesh Returns an object of the type MeshSequence for the current
mesh.
getCurrentStudy Returns an object of the type Study for the current
component.
getCurrentPlotGroup Returns an object of the type ResultFeature for the current
component.
| 363
NAME DESCRIPTION
getCurrentNode Returns an object of the type ModelEntity for the current
component.
selectNode Select a particular model tree node.
These methods return the corresponding entity such that the method code in an
add-in can operate on it. When called from an application a method in this
category returns null. Also, null is returned if no entity of the corresponding
type exists such that nothing is current.
364 |
Appendix F — Guidelines for Building Applications
General Tips
• Include reports to files with input data and corresponding output data.
• Make it intuitive. Provide help, hints, and documentation as necessary.
• Make it foolproof: “Safe I/O”, “Reset to default data”, etc.
• Save a thumbnail image with the model.
• Include a description text (It will be visible in the COMSOL Server library).
• Test the application on the computer platforms for which it is intended.
• Be minimalistic. From the developer’s point of view, it is much easier to
make sure logic works, organize, debug, maintain, and further develop the
app. From a user’s point of view, it is easier to use the application. The
minimalistic approach requires more care while developing but much less
maintenance later on and much higher adoption among users.
• Embed libraries in the model if they are of manageable size.
• Display the expected computation time and, after the computation, the
actual computation time.
• When a computation is canceled, output data from the previous
computation should be cleared.
• Password protect as needed. (Remember: No one can help you if you forget
the password.)
Naming Conventions
In the demo applications in the Application Libraries, all forms, events,
declarations and methods use camelCase. You can adopt this convention also in
your own applications. Following this convention, a name should be composed of
a number of words joined without spaces, with each word's initial letter in capitals
except the first letter that should be lowercase. Use a descriptive name and long
names are better than hard-to-understand short names.
Examples of names for forms:
• main
• inputParameters
• geometryTab
| 365
Examples of names for events:
• updatePlot
• moveToVelocityTab
Methods
• Do not create more methods than necessary.
Fewer methods give you a shorter list of methods to browse through when
looking for something. Fewer methods usually mean fewer lines of code to
worry about.
- If several methods you wrote do essentially the same thing, consider merging
them into one method and dealing with the different cases by input
arguments.
- Do not create a method if it is only called from one place. Insert the code
right into that place instead.
• Create a local method if it is only used in a form, or triggered by a form
event or a form object event.
• Give methods descriptive names and name them so that similar methods are
grouped together when sorted alphabetically. You will have less to
remember and you will find what you are looking for easier. Long names are
better than hard-to-understand short names.
• The points above apply to method code as well: be minimalistic, use as few
lines of code and variables as possible, use descriptive names for variables,
use long names instead of hard-to-understand short names, and optimize
code to run efficiently.
366 |
• The above points apply to declarations as well: use good names, don't use
more than necessary, and declare variables where they are used (in forms and
methods or in the model).
Forms
• Do not create more forms than necessary.
• Use the Form Wizard templates to get started with creating forms.
• Consider using subwindows instead of form collections.
• Give forms descriptive names. Same reasoning as for methods.
• Make good use of the many different types of form objects. Some are good
for some things, while some are good for others.
• Do not insert more form objects than necessary. Too many options for input
data may make the application hard to use. Too much output data makes it
hard to find important information.
• Insert a text field for the user to leave comments to save with the user’s set
of input and output data when saving the application.
• Consider inserting a button with a method to reset to default data.
• Apply “Safe I/O”:
- For input fields, alert the user about input data that is out of bounds. You can
do that either by an alert triggered by an On Data Change event for an input
field, or by setting limits in the form objects settings window, which then sets
hard limits. In a method generating the alert, you may just warn the user and
then allow the input data if the user chooses to go ahead anyway.
- On output fields, give the precision that makes sense. If current results are
not based on current input data, show it. If the computation failed, show it.
• Include tooltips, help, documentation, hints, and comprehensive reports.
• Provide the user with information about how long it takes to run the
simulation with default input data on a typical computer. It could be
seconds, hours, or even days depending on the application, so that is
something the user would like to know before hitting the compute button.
Consider playing a sound to alert the user when the computation has
finished. The user may be doing something else while waiting for results.
(Sending an email message with a report to the user or some other place
when the computation is done may be a better alternative if the computation
is really long.)
• Spend some time on the layout of a form. A good-looking form makes it
easier and more fun to use the application.
Consider setting keyboard shortcuts for buttons and menu items.
| 367
Appendix G — The Application Library Examples
In the Application Libraries, you can find example applications that showcase the
capabilities of the Application Builder. They are collected in folders with the name
Applications and are available for many of the add-on products. You can edit these
applications and use them as a starting point or inspiration for your own
application designs. Each application contains documentation (PDF) describing
the application and an option for generating a report.
Below is a partial list of the available application examples organized as they appear
in the Application Libraries tree. Note that some applications may require
additional products to run.
368 |
NAME APPLICATION LIBRARY
| 369
• Dark theme
• The use of subwindows
• Material appearance visualization with environment reflections
• Report generation for both Microsoft® Word and Microsoft® PowerPoint
• Options for setting different mesh sizes
• Improved graphics visualization when showing and hiding different
geometry objects
• Enabling and disabling ribbon items based on the solution state.
Helical static mixers are often used to mix monomers and initiators which then
react during a polymerization process. The concentration field is included in the
analysis in order to compute the extent of mixing between two streams injected
into the static mixer through semicircle-shaped inlets.
The app can be used to estimate the degree of mixing in a system including one
to five helical blades whose dimensions can also be varied. The monomers' liquid
properties and inlet velocity can also be varied.
This application does not require any add-on products.
370 |
• Dynamically hiding forms using card stacks to minimize the space required
by the app
• Changing appearance by using different background colors.
| 371
Tubular Reactor
This app demonstrates the following:
• Sending an email with a report when the computation is finished
• User-defined email server settings
• Playing a sound when the computation is completed
• Language localization
• Options to visualize plots tiled or tabbed.
The app exemplifies how students in chemical engineering can model nonideal
tubular reactors (radial and axial variations) and investigate the impact of different
operating conditions. It is also a great example of how teachers can build tailored
interfaces for problems that challenge the students’ imaginations.
The model describes a tubular reactor where propylene oxide (A) reacts with water
(B) to form propylene glycol (C):
A + B -> C
Since water is the solvent and present in abundance, the reaction kinetics may be
described as first order with respect to propylene oxide
R = k*C_A
Alternatively, a second-order reaction can also be implemented according to
R = kf*C_A*C_B - kr*C_C
The reaction is exothermic and a cooling jacket is used to cool the reactor. The
reactor is modeled in 2D axisymmetry and the simulation results yield
composition and temperature variations in both the radial and axial directions.
372 |
This application does not require any add-on products.
Tuning Fork
This app demonstrates the following:
• Playing a sound at a specific computed frequency
• Selecting different materials from a combo box
• Visualizing material appearance, color, and texture
• Choice of three different user interface layouts for computer, tablet, or
smartphone
• Custom implementation of the secant method
• Custom window icon.
When a tuning fork is struck, it vibrates in a complex motion pattern that can be
described mathematically as the superposition of resonant modes, also known as
eigenmodes. Each mode is associated with a particular eigenfrequency. The tuning
fork produces its characteristic sound from the specific timbre that is created by
the combination of all of the eigenfrequencies.
The app computes the fundamental resonant frequency of a tuning fork where you
can change the prong length. Alternatively, you can provide a user-defined target
frequency and the application will find the corresponding prong length using an
algorithm based on a secant method.
| 373
This application does not require any add-on products.
The app can be used to verify and optimize B-H curves using experimental data.
It also generates curve data in the over-fluxed region, where measurement are
difficult to perform. It removes the unphysical ripples of the slope of the B-H
curve that might cause numerical instability.
The original B-H curve is evaluated from two aspects. Firstly, to verify that the
extrapolation of the curve is reasonable from the physical point of view. Secondly,
to check if the slope of the curve is smooth. The optimization algorithms are
mainly based on the simultaneous exponential extrapolation method and the
linear interpolation method, respectively.
The app requires the original curve data defined in a text input file. Once the curve
is imported, the application checks if optimization is required. By clicking the
Optimize Curve button, the user can generate the optimized curve data, which can
be exported to a text file.
374 |
This application does not require any add-on products.
| 375
This application requires the AC/DC Module.
376 |
effective material properties can be exported as a COMSOL Material Library file
and be further used in a model with the Magnetic Fields interface.
This application does not require any add-on products.
The app allows you to study the design of an organ pipe and then play the sound
and pitch of the changed design. The pipe sound includes the effects of different
harmonics with different amplitudes.
The organ pipe is modeled using the Pipe Acoustics, Frequency Domain interface.
The app allows you to analyze how the first fundamental resonance frequency
varies with the pipe radius and wall thickness, as well as with the ambient pressure
and temperature.
Using the app, you can find the full frequency response, including the
fundamental frequency and the harmonics. With a method written in Java®code,
the app detects the location and amplitude of all harmonics in the response, thus
extending the analysis beyond the built-in functionality of the COMSOL
Multiphysics user interface.
| 377
This application requires the Acoustics Module.
378 |
The app also computes the battery temperature (assuming an uniform internal
battery temperature), based on the generated heat and the thermal mass. Cooling
is defined using an ambient temperature parameter and a heat transfer coefficient.
| 379
• Visualizing results with animations
• Custom window icons.
It is a tool for investigating the dynamic voltage and thermal behavior of a battery
pack, using load cycle and SOC vs OCV dependence experimental data.
Parameter estimation of various parameters such as the ohmic overpotential, the
diffusion time constant, and the dimensionless exchange current can be performed
by the app. The app may then be used to compute a battery pack temperature
profile based on the thermal mass and generated heat associated with the voltage
losses of the battery.
Various battery pack design parameters (packing type, number of batteries,
configuration, geometry), battery material properties, and operating conditions
can be varied.
This application requires the Battery Design Module and the Optimization
Module.
380 |
The app takes measurements from an EIS experiment and uses them as inputs. It
then simulates these measurements and runs a parameter estimation based on the
experimental data.
The control parameters are: the exchange current density, the resistivity of the
solid electrolyte interface on the particles, the double-layer capacitance of NCA,
the double-layer capacitance of the carbon support in the positive electrode, and
the diffusivity of the lithium ion in the positive electrode. Fitting is done to the
measured impedance of the positive electrode at frequencies ranging from 10
mHz to 1 kHz.
The application requires the Optimization Module and the Battery Design
Module.
| 381
Water Treatment Basin
This app demonstrates the following:
• Parameterized geometry containing a geometry sequence with if-statements
to produce different types of designs
• Options to set the mesh size
• Light Theme
• A graphical user interface that includes different windows that can be shown
or hidden.
Water treatment basins are used in industrial-scale processes in order to remove
bacteria or other contaminants.
The app exemplifies modeling turbulent flow and material balances subject to
chemical reactions. You can specify the dimensions and orientation of the basin,
mixing baffles, and inlet and outlet channels. You can also set the inlet velocity,
species concentration, and reaction rate constant in the first-order reaction.
The app solves for the turbulent flow through the basin and presents the resulting
flow and concentration fields as well as the space-time, half-life, and pressure drop.
The application requires the CFD Module.
382 |
Reaction Equilibrium—Gas Phase Conversion of Ethylene to Ethanol
This app demonstrates the following:
• How an app can be used as a teaching tool
• An 8 question multiple choice quiz where the answers can be sent to the
grader by email
This app calculates the equilibrium compositions in gas phase conversion of
ethylene to ethanol. It allows you to study how the initial conditions and the
operating conditions affect the ethanol production.
The app is designed to teach you how to compute quantitative results for the
equilibrium composition and provide an understanding for the dynamics of a
chemical equilibrium.
The application requires the Chemical Reaction Engineering Module.
Cyclic Voltammetry
The purpose of the app is to demonstrate and simulate the use of cyclic
voltammetry. You can vary the bulk concentration of both species, transport
properties, kinetic parameters, as well as the cycling voltage window and scan rate.
Cyclic voltammetry is a common analytical technique for investigating
electrochemical systems. In this method, the potential difference between a
working electrode and a reference electrode is swept linearly in time from a start
| 383
potential to a vertex potential, and back again. The current-voltage waveform,
called a voltammogram, provides information about the reactivity and mass
transport properties of an electrolyte.
The application requires one of the Battery Design Module, Electrochemistry
Module, Electrodeposition Module, Corrosion Module, or Fuel Cell &
Electrolyzer Module.
384 |
The application requires one of the Battery Design Module, Electrochemistry
Module, Electrodeposition Module, Corrosion Module, or Fuel Cell &
Electrolyzer Module.
| 385
Concentric Tube Heat Exchanger
This app demonstrates the following:
• Selecting predefined or user-defined materials
• User option to switch between laminar flow or turbulent flow
• Changing boundary conditions using methods
• Visualizing temperature dependent material properties as graph plots
• User option to set the solver tolerance.
Finding the right dimensions for a heat exchanger is imperative to ensure its
effectiveness. Other properties must also be considered in order to design a heat
exchanger that is both of the right size and provides heated or cooled fluid of the
right temperature.
The app computes these quantities for a heat exchanger made of two concentric
tubes. The fluids can flow either in parallel or in counter current flow.
The fluid properties, heat transfer characteristics, and dimensions of the heat
exchanger can all be varied. The Nonisothermal Flow multiphysics interface is
used to model the heat transfer.
This application requires the Heat Transfer Module.
386 |
Equivalent Properties of Periodic Microstructures
This app demonstrates the following:
• Visualization of a periodic structure from a unit cell
• Resetting some or all input parameters
• Export the resulting material properties as an MPH-file or an XML file that
can be imported to a COMSOL Multiphysics session.
Periodic microstructures are frequently found in composite materials, such as
carbon fibers and honeycomb structures. They can be represented by a unit cell
repeated along three directions of propagation.
To reduce computational costs, simulations may replace all of the microscopic
details of a composite material with a homogeneous domain with equivalent
properties. This app computes the equivalent properties for a geometrical
configuration and the material properties of a unit cell to be used in a macroscopic
model that uses these composite materials.
Nine different microstructures are given, with dimensional characteristics that are
modifiable by the user, as well as thirteen predefined materials. The app calculates
the equivalent density, heat capacity, and thermal conductivity or diffusivity of the
composite materials.
This application does not require any add-on products.
| 387
Finned Pipe
This app demonstrates the following:
• Geometry parts and parameterized geometry
• A results table form object containing outputs.
Finned pipes are used for coolers, heaters, or heat exchangers to increase heat
transfer. They come in different sizes and designs depending on the application
and requirements.
When the fins are placed outside the pipe, they increase the heat exchange surface
of the pipe so that a cooling or heating external fluid can exchange heat more
efficiently. When placed inside the pipe, it is the inner fluid that benefits from an
increased heat exchange surface. Instead of fins, grooves can also increase the heat
exchange surface, particularly inside the pipe where space is limited.
With this app, you can customize a long cylindrical pipe with predefined inner and
outer fins or grooves to observe and evaluate their cooling effects. The app
calculates the thermal performance of a pipe that is filled with water and then
cooled or heated by surrounding air with forced convection.
Various geometric configurations are available for the outer structure
(disk-stacked blades, circular grooves, helical blades, helical grooves, or none) and
for the inner structure (straight grooves or none).
The app computes the dissipated power and the pressure drop as functions of the
geometry and air velocity.
388 |
This application requires the Heat Transfer Module
Heat sinks are usually benchmarked with respect to their ability to dissipate heat
for a given fan curve. One possible way to carry out this type of experiment is to
place the heat sink in a rectangular channel with insulated walls.
The temperature and pressure at the channel’s inlet and outlet, as well as the
power required to keep the heat sink base at a given temperature, is then
measured. Under these conditions, it is possible to estimate the amount of heat
dissipated by the heat sink and the pressure loss over the channel.
The purpose of the app is to carry out investigations of such benchmarking
experiments. You can vary the type of heat sink as well as the number of fins or
| 389
pins and their dimensions to find the optimal design for a given pressure loss over
the channel.
Air velocities and heat source rates can be varied and the app solves for
nonisothermal flow, assuming turbulence as described by the algebraic yPlus
model.
This application requires the Heat Transfer Module.
390 |
Ferritic stainless steels become more and more used in food processing due to their
relatively low and stable price, and their magnetic properties that allow using new
heating techniques.
A circular electromagnetic coil is wound around a set of pipes in which a fluid
flows. The alternating current passing through the coil generates an alternating
magnetic field that penetrates the pipes, generates eddy currents inside them, and
heats them up. Then heat is transferred to the fluid essentially by conduction.
Various configurations are available for the set of pipes (number, length, thickness,
material) and for the coil (number of turns, wire radius, current density, and
excitation frequency) to optimize the heat exchange with the fluid, while ensuring
homogeneous temperatures within it for a given flow rate.
This application requires the Heat Transfer Module and the AC/DC Module.
Thermoelectric Cooler
This app demonstrates the following:
• Visualizing material appearance, color, and texture
• Showing info below the graphics about geometry parameters, results and
performance depending on the selected plot action
Thermoelectric coolers are widely used for electronics cooling in various
application areas, ranging from consumer products to spacecraft design. A
| 391
thermoelectric module is a common type of component used in thermoelectricity
applications. A typical module consists of several thermoelectric legs sandwiched
between two thermally conductive plates, one cold and one hot. The device that
needs to be cooled down must be attached to the cold face.
Due to the variety of applications, there can be many different thermoelectric
cooler configurations. This app covers the basic design of a single-stage
thermoelectric cooler of different sizes with different thermocouple sizes and
distributions. It also serves as a starting point for more detailed calculations with
additional input options and can be extended to multistage thermoelectric
coolers.
This application requires the Heat Transfer Module, AC/DC Module, and
Optimization Module. Instead of the AC/DC Module you could alternatively use
the MEMS Module or the Plasma Module.
392 |
Mixer
This app demonstrates the following:
• Multiple tabs in the ribbon
• Geometry parts and parameterized geometries
• Parts and cumulative selections can be used to automatically set domain and
boundary settings in the embedded model
• Adding or removing geometry parts with different geometrical
configuration
• Options for creating different mesh sizes
• Sending an email with a report when the computation is finished
• User-defined email server settings which is useful when running compiled
standalone applications
• Sliders to control the visualization of a slice plot.
The app provides a user-friendly interface where scientists and process engineers
can investigate the influence that vessels, impellers, baffles, and operating
conditions have on the mixing efficiency and on the power that is required to drive
the impellers. You can use this application to understand and optimize the design
and operation of a mixer for a given fluid.
You can specify the dimensions of the vessel from a list of three types and the
dimensions and configuration of the impellers from a list of eleven types. The
vessels can also be equipped with baffles. You can further specify the impeller
speed and the properties of the fluid that is being mixed.
| 393
The application requires either the CFD Module or the Polymer Flow Module.
394 |
This application requires the Particle Tracing Module and the Molecular Flow
Module.
Many trucks are equipped with cranes for handling loads and such cranes have a
number of hydraulic cylinders that control the motion of the crane. These
cylinders and other components that make up the crane are subjected to large
forces when handling heavy loads. In order to determine the load-carrying
capacity of the crane, these forces must be computed.
In the app, a rigid-body analysis of a crane is performed in order to find the
payload capacity for the specified orientation and extension of the crane.
Inputs include the angle between the booms, the total extension length, the
capacity of the inner and outer boom cylinders, and the capacity extension
cylinders. Results from the app include the payload capacity and hydraulic cylinder
usage.
| 395
The application requires the Multibody Dynamics Module.
The app can be used to estimate parameters in models without any physics. Data
can be imported from a file or the built-in functionality for data generation can be
utilized.
The models include linear, quadratic, sigmoid, sloped Gaussian, and a custom
model with up to 5 parameters.
The Levenberg–Marquardt solver computes confidence intervals for the estimated
parameters, while the other solvers (MMA, SNOPT, and BOBYQA) allow for
specification of parameter bounds. MMA and BOBYQA allow for minimization
of the maximum square instead of the sum.
396 |
The application requires the Optimization Module.
| 397
The heater can also be turned off if the daily heat demand is achieved, and then
turned on again after 24 hours. The temperature at the pipe’s outlet can be
controlled and compared to the minimum temperature required in the heat
exchanger specifications.
This application requires the Pipe Flow Module.
398 |
You can learn more about this example in a related blog post: “Efficiently
Optimizing Solar Dish Receiver Designs”:
https://www.comsol.com/blogs/efficiently-optimizing-solar-dish-receiver-designs/.
This application requires the Ray Optics Module.
The excited TE mode from a circular waveguide passes along the corrugated inner
surface of a circular horn antenna where a TM mode is also generated. When
combined, these two modes give lower cross-polarization at the antenna aperture.
By using this app, the antenna radiation characteristics, as well as aperture
cross-polarization ratio can be improved by modifying the geometry of the
antenna.
| 399
This application requires the RF Module.
400 |
Frequency Selective Surface Simulator
This app demonstrates the following:
• Designing an app for small screens such as smartphones
• User-interface navigation with a top menu typically used on websites
• Geometry parts and parameterized geometries
• Visualizing periodicity of a geometry with material rendering
• Warning messages on icons when properties are not updated
• Sending an email with a report attached when the computation is finished
Frequency selective surfaces (FSS) are periodic structures that generate a bandpass
or a bandstop frequency response. They are used to filter or block RF, microwave,
or, in fact, any electromagnetic wave frequency. For example, you see these
selective surfaces on the doors of microwave ovens, which allow you to view the
food being heated without being heated yourself in the process.
The app simulates a user-specified periodic structure chosen from the built-in unit
cell types. It provides five unit cell types popularly used in FSS simulations along
with two predefined polarizations in one fixed direction of propagation that has
normal incidence on the FSS. The analysis includes the reflection and transmission
spectra, the electric field norm on the top surface of the unit cell, and the
dB-scaled electric field norm shown on a vertical cut plane in the unit cell domain.
You can change the polarization, center frequency, bandwidth, number of
frequencies, substrate thickness and its material properties, and unit cell type
(circle, ring, split ring, etc.) as well as their geometry parameters, including
periodicity (cell size).
| 401
This application requires the RF Module.
402 |
Microstrip Patch Antenna Array Synthesizer
This app demonstrates the following:
• Parameterized geometries
• Visualizing material appearance, color, and texture
• Multiple plots in the same window to visualize the results
• Options to visualize the results with different views using check boxes
| 403
This application requires the RF Module.
The app simulates a rotor bearing system consisting of disks and bearings mounted
on a rotating shaft. An eigenfrequency analysis is performed for a range of angular
speeds, to identify critical speeds of the system.
An app of this kind is useful at an early design stage where design modifications
can be made to move critical speeds away from the operating speed of the system.
Results include whirl modes, a Campbell plot, and a list of critical speeds.
404 |
This application requires the Structural Mechanics Module and the
Rotordynamics Module.
The app combines the Ray Optics Module and the Semiconductor Module to
illustrate the operation of a silicon solar cell at a location specified by the user. The
Ray Optics Module computes the average illumination over a day of the year. The
Semiconductor Module computes the normalized output characteristics of a solar
cell with design parameters specified by the user. The normalized output
characteristics is then multiplied by the computed average illumination to obtain
| 405
the output characteristics of the cell at the specified date and location, assuming
simple linear relationship between the output and the illumination.
406 |
Beam Section Calculator
This app demonstrates the following:
• Reading and importing data from an Microsoft® Excel file
• Exporting data to an Microsoft ® Excel file
The app computes the beam section properties and true stress distribution in a
designated steel beam section. A broad range of American and European beam
standards are available. It uses LiveLink™ for Excel® to read and store the beam
data in Excel® worksheets.
This application requires the Structural Mechanics Module and LiveLink™ for
Excel®. A version of this app is also provided without Microsoft® Excel
functionality.
The app computes the stress distribution and the deformation of a bike frame
based on user configurable loads and constraints. It leverages LiveLink™ for
| 407
SOLIDWORKS® to load the geometry, and to update the frame dimensions for
studying their effect on the results.
This application requires the Structural Mechanics Module and LiveLink™ for
SOLIDWORKS®.
408 |
Fiber Simulator
For almost all commercial optical fiber types, the design consists of a concentric
layer structure with the inner layer(s) forming the core and the outer layer(s)
forming the cladding. Since the core has a higher refractive index than the
cladding, guided modes can propagate along the fiber.
This application performs mode analyses on concentric circular dielectric layer
structures. Each layer is described by an outer diameter and the real and imaginary
parts of the refractive index. The refractive index expressions can include a
dependence on both wavelength and radial distance. Thus, the simulator can be
used for analyzing both step-index fibers and graded-index fibers. These fibers can
have an arbitrary number of concentric circular layers. Computed results include
group delay and dispersion coefficient.
This application requires the Wave Optics Module.
| 409
Plasmonic Wire Grating
This app demonstrates the following:
• Choice of different user interface layouts for computer/tablet or
smartphone
• Custom background image and color
• Graphics appearance with custom top color and bottom color
• Custom position of the graphics toolbar
This application computes diffraction efficiencies for the transmitted and reflected
waves (m = 0) and the first and second diffraction orders (m = ±1 and ±2) as
functions of the angle of incidence for a wire grating on a dielectric substrate. The
incident angle of a plane wave is swept from normal incidence to grazing
incidence. The application also shows the electric field norm plot for multiple
grating periods for a selected angle of incidence.
This application requires the Wave Optics Module.
410 |
orthogonal to the plane of incidence) will be reflected. Changing the spot radius
for the Gaussian beam modifies the polarization discrimination.
The reflectance and transmittance spectra are calculated for different Gaussian
beam spot radii.
The app automatically calculates the phase expressions necessary for the
Electromagnetic Waves, Beam Envelopes interface, when the user changes the
design parameters.
This application requires the Wave Optics Module.
| 411
412 |
Index
Add New Form Choice List 168 helical static mixer 369
append unit to number 98, 313 Application Libraries 10, 28, 29, 45, 368
| 413
apply changes 24 card 281
arguments card stack object 111, 161, 162, 281,
input and output 206 290
arranging form objects 113 cell margins 121, 128
array 164 cells
1D 164 merging 120
2D 165 splitting 120
2D, interactively defining 166 check box object 111, 153, 156, 163,
syntax 165 185, 204, 233
array input object 153, 156, 293 check syntax 194
auto complete 201 choice list 64, 157, 167, 168, 241, 245,
Automatic Notation 275 250, 258, 259, 297, 298, 305, 306,
354
B background color 54
clear selection
background image 54
graphics 82
Blank form template 55
click-through agreement 40
BMP file 229
clipboard 263, 275, 321
Boolean variable 161, 163, 164, 233
close application icon 149
conversion 360
Close brackets automatically 200
Boundary Point Probe 94, 180
code completion 201
Break 209
tooltip 202
breakpoint 208
code folding 200
browser
color
web 32, 134
material 82
built-in method library 347
selection 82
button 65, 78, 111, 204
column settings 119, 127
command sequence 67
combo box object 111, 153, 161, 167,
icon 65
170, 239
keyboard shortcut 66
command line 132
on click event 65, 67
command sequence 18, 49, 50, 67, 70,
size 65, 115
71, 77, 87, 141, 148, 152, 153, 181,
style 65
205, 206, 230, 311, 319
text 115
comments
tooltip 66
toggle on and off 199
C C libraries
common, file scheme 327, 342
external 356
compatible with physical quantity, unit
CAD-file import 286, 327, 329
dimension check 98
Call Stack window 208
compatible with unit expression, unit
cancel shutdown 149
dimension check 98
414 |
Compiler Create Local Variable 203
button 37 Create New Declaration and Use It as
node 38 Source 97
compiler 10, 24, 37 Create New Form Declaration and Use
complex numbers 275 It as Source 97
component syntax 200 creating
computation time 293 forms 16, 45
expected 104, 290, 292 methods 18
last 104, 292, 359 CSV file 161, 276, 311, 312
COMSOL Client 10, 26, 27, 32, 34 curly brackets 200
file handing 323 custom settings window 130
running applications in 34, 323
D DAT file 161, 276, 311, 312
COMSOL Compiler 10, 24, 37
Data Access 108, 189, 193
COMSOL Desktop environment 12,
data change 63, 153, 206, 235, 236, 367
20
data display object 101, 103, 111
COMSOL Multiphysics 10, 24, 25, 30,
information node 292
31, 34, 129, 181, 211, 265, 271, 273
tooltip 106
COMSOL Runtime 38
data file 161, 276, 311
COMSOL Server 10, 24, 26, 27, 29, 31,
Data picking 179
32, 34, 35, 327
data picking 94, 179
manual 37
data validation 98, 173
COMSOL Software License Agree-
date 358
ment 43
Debug Log 210
confirm 214, 353
debug log window 210, 356
Continue 208
debugging 208, 356
Convert to Form Method 18, 72, 181,
Decimal Notation 275
205
Declaration and Use it as Source 159
Convert to Local Method 19, 72, 181,
Declarations 14, 157, 159
205
form 97, 157, 158
Convert to Method 18, 71, 73, 181, 183,
global 97
205, 331
local 97
Coordinate 178, 179
declarations node 233
Copy Table and Headers to Clipboard
delete button 58, 70, 288
275
deleting an object 58
copying
Depth Along Line 180
forms and form objects 129, 321
derived values 104, 274
objects 58
description text
rows or columns 120
Boolean variable 235
Create Local Method 204
derived value 102
| 415
desktop icon 25, 39, 134 Enable code folding 200
desktop shortcut 25, 134 enable form object 354
Developer tab 18, 106, 131, 191, 217 enabled state, for form objects 77
dialog box 353 Engineering Notation 275
Disable All 209 equation object 260
disable form object 354 error message, data validation 98, 100
display name, for choice list 167, 170, Evaluation 2D 180
242, 298, 305, 354 Evaluation 3D 180
displayed text 60 evaluation tables 180
Domain Point Probe 180 event 63, 148, 153, 204, 206, 247
domain point probe 94 About to shutdown 149
double variable 161, 163, 164 button on click 67
conversion 360 for multiple form objects 61, 155
double, data validation 99 form 153
download form object 153
option for compiling 38 global 13, 111, 148
drag and drop, form objects 58 keyboard shortcut 66
duplicating knob 316
rows or columns 120 local 148
duplicating an object 58 node 149
on close 155
E edit local method 206
on data change 63, 153, 206, 235,
edit node 68, 187, 188
236, 367
Editor Tools 187
on load 63, 155
editor tools 63, 190, 244, 245
on startup 149
window 18
slider 314
editor tree 64, 67, 81, 187, 324, 326
Events 13
element size 110
example application
change 256
bike frame analyzer 407
email 317
charge exchange cell simulator 394
class 350
corrugated circular horn antenna 399
methods 350
effective nonlinear magnetic curves
email attachment
calculator 376
export 350
finned pipe 388
report 350
forced air cooling with heat sink 389
table 350
general parameter estimation 396
embed
geothermal heat pump 397
option for compiling 39
inline induction heater 390
embedded, file scheme 228, 231, 327,
polarizing beam splitter 410
334
416 |
rotor bearing system simulator 404 upload 169, 327, 332, 335
solar dish receiver designer 398 user 327, 342
thermoelectric cooler 391 filename 287, 329, 348
Excel® file 161, 276, 311 files library 231
executable 10, 24, 37 Find 195
explicit selection 90, 92 fit, row and column setting 115, 119
exponent, number format 104 fixed, row and column setting 115, 119
export for statement 213
email attachment 350 form 15, 53
export button, results table 275 Declarations 157
export node 323, 335 local 56
Export Selected Image File 229 form collection 111, 137, 278
exporting Form Editor 21
results 323, 335 desktop location 12
external C libraries 356 overview 15
extracting subform 115 preferences 20, 57
using 53
F file
form event 153
commands 324
form method 18, 148, 153, 181
declaration 169
form object 15, 57, 63, 232
destination 287, 329
event 153
download 34, 325
with associated methods 185
import 68, 153, 156, 169, 228
form reference 278
menu 142
Form tab, in ribbon 15
methods 348
form window 15
opening 324
Form wizard 63, 64, 102
saving 325
Forms 13
types 288
Full Precision 275
upload 34, 325
function 17
file browser 340
file import object 153, 156, 169, 228, G gauge object 268
286, 323, 328 parameter 269
File menu editor 17 scalar variable 269
file open variable 269
system method 350 geometry 31, 48, 67, 78, 84, 93, 300,
file scheme 321, 330, 332, 353
common 327, 342 import 286, 327, 329
embedded 228, 231, 327, 334 operations 265, 271, 273
syntax 228 Geometry Entity Level 180
temp 327 geometry node 67
| 417
get 363 help 100
GIF file 229 main window 136
global evaluation 104, 281 menu item 141
global event 13, 148 method 185
global method 18, 153, 181 ribbon item 141
global parameter 213 toolbar 319
go to method 18, 71, 183 if statement 213
graphics 72 ignore license errors 26
clearing contents 84 image
commands 81 background 54
hardware acceleration 43 formats 229
hardware limitations 83 object 263
object 47, 48, 77, 78, 153, 353 Preview 229
plot group 84 scaling 263
Source for Initial Graphics Content thumbnail 29
178 Images library 229
source for initial graphics content 78 Immediately
tab, New Form wizard 48 Store changes 76
toolbar 84, 111 import
using multiple objects 83 file 68, 153, 156, 169, 228, 287, 329
view 81, 88, 355 Indent and Format 199
graphics data 94, 157, 178 Indent and format automatically 200
grid layout mode 34, 54, 103, 112 information card stack object 111, 290
grid lines, sketch layout mode 113 information node 292
grow, row and column setting 115, 119 inherit columns 127
growth rules 115 initial size, of main window 138
initial values, of array 164
H Home tab, in ribbon 45
initialize
HTML
parameter 73
code 262
variable 73
report 262, 343
Initializing Installer progress window 40
HTTP and HTTPS protocols 317
input arguments 132, 206
hyperlink object 316
input field object 95, 111, 153, 156, 161,
I icon 229, 319
173
button 65
adding 95
close application 149
information node 292
command 68
text object 102
desktop 25, 39, 134
tooltip 97
graphics 79
unit object 102
418 |
Inputs 13, 132 ignoring 26
inputs tab, outputs tab, New Form wiz- Line Entry Method 180
ard 47 line object 261
inserting list box object 111, 153, 156, 161, 167,
form objects 61, 63 170, 302
rows and columns 115, 118 LiveLink™ for Excel® 161, 276, 311
rows or columns 120 LiveLink™ products 35
integer local event 148
data validation 99 local form 56
variable 161, 163, 164 local method 18, 63, 72, 148, 153, 156,
variable conversion 360 181, 185, 204, 206, 235, 242, 321
interactive editing local variable 203
menus and ribbon items 144 Localization 139
item log object 271
menu 141, 204 logo image 79
ribbon 143 low-resolution displays 34
toolbar 318
M Main Form 137
J Java utility class 228 Main Window 13, 16, 137, 265
Java® programming language 181, 211 node 136, 145
JPG file 30, 229 Main Window Editor 21, 144
desktop location 12
K keyboard shortcut 20, 63, 148, 188, 201,
overview 16
203, 209, 344
Main window type 137
event 66, 141, 319
margins
knob object 314
cell 121, 128
parameter 315
material 248
scalar variable 315
material color and texture 82
variable 315
math functions 212
L Language 139
menu 141, 143
language elements window 18, 186, 211
bar 137, 140
language localization 139
item 78, 111, 141, 204
LaTeX 102, 105, 260
toggle item 141, 237
layout mode 54, 112
Menu editor 17
layout options, form collection 278
menu toggle item 111
layout template 16, 46, 57
merging cells 115, 120
Libraries 14
mesh 48, 78, 84, 110
libraries node 228, 263
change element size 256
license agreement 43
size 110
license errors
meshing 265, 271, 273
| 419
message log object 272, 353 command sequence 70
method 14, 17, 61, 71, 78, 157, 181, 347 table 310
event 149, 153 MP4 file 264
form 18, 148, 153, 181 MPH-file 14, 24, 25, 27, 31, 45, 51, 228,
form object 185 326, 356
global 18, 153, 181 multiline text 103
local 18, 63, 72, 148, 153, 156, 181, multiple form objects
185, 204, 235, 242, 321 selecting 61, 155
Model Builder 215
N name
window 18
button 65
Method Call 215, 222
check box 235
Method Editor 21, 347
choice list 167
desktop location 12
form 53
overview 17
form object 61
Preferences 200
graphics object 77
using 181
menu 141
Method Errors and Warnings window
method 199
194
shortcut 175
Method tab, in ribbon 17
variable 160
method, called from the Model Builder
named selection 90
215
new element value 164
Methods 14
new form 16
Microsoft® Word® format 341
New Form wizard 62, 102
minimum size
graphics tab 48
form objects 121
inputs and outputs tabs 47
Model Builder
ribbon buttons tab 49
method 201, 215
new method 18
model commands 326
notation
model data access 111, 151, 321
data display number format 104
Model Expressions 196
unit 104
model expressions window 18
number format 101, 104
model object 181, 211, 347
number of rows and columns 115
model tree node, controlling if active
numerical validation 99, 173
215
O OGV file 264
model utility methods 347
on click event, button 65
move down
on close event 155
command sequence 70
on data change event 63, 153, 206, 235,
table 310
236, 367
move up
420 |
on load event 63, 155 Point Being Modified 180
On request Polar Complex Numbers 275
Store changes 76 position and size 60, 112, 114
on startup event 149 multiple form objects 61
open file 324 positioning form objects 57
OpenGL graphics hardware accelera- precedence, of operators 212
tion 43 precision 275
operating system command line 132 precision, number format 104
operators 211, 212 preferences 20, 57, 200, 327, 328
optimization 381 for compiled applications 42
orthographic projection 81 security 31
OS commands 350 Preview
output arguments 206 image 229
Output directory preview form 24
for compiled applications 38 printing
graphics 82, 356
P panes 278
Probe 180
parameter 17, 48, 72, 96, 98, 161, 213,
procedure 17
321, 363
Programming Reference Manual 11
combo box object 239
progress 265, 358
declarations 14, 157
progress bar 137
events 13, 148
progress bar object 265, 358
input field object 95
progress bar, built in 265
method 193, 213
progress dialog box 267, 358
slider object 313
publishing applications 43
text label object 102
parentheses 200 Q Quick Access Toolbar 24
password protected application 31 Find 195
pasting
R radio button object 111, 153, 167, 170,
form objects 58
296
forms and form objects 129
Record Code 191
image 263
recording code 191
rows or columns 120
Rectangular Complex Numbers 275
pixels 60, 112
recursion 207
play sound 34, 230, 350
regular expression 100
plot 48, 49, 67, 68, 78, 84, 163, 233, 243,
Remove All 209
306, 318, 331, 339, 353
removing
plot geometry command 68
password protection 31
plot group 72, 163
rows and columns 115, 118
PNG file 30, 229
| 421
rows or columns 120 scalar variable 161, 241, 281, 313
report 365, 368 scene light 81, 356
creating 323, 335, 341, 342 Scientific Notation 275
creating automatically 216 security settings 31
email attachment 350 select all
embedding 262 graphics 82
HTML 262, 343 selection 48, 78, 84
image 30 explicit 92
node 323, 335, 342 selection colors 82
request 214, 353 selection input object 92, 299
reset current view 81, 88 selections 90
Reset Window Layout 50 add-in 93
resizable graphics 34 selectNode method 215
resizing form objects 58 separator
Results Evaluation 178, 179 menu 141
results table object 274, 354 ribbon 143
ribbon 137, 142 toolbar 141, 318
item 111, 143 separators
section 143 CSV, DAT, and TXT files 312
tab 143 set value command 110
toggle item 111, 143, 237 Settings Form 131, 215, 222
Ribbon button 66 Settings Forms 130
ribbon buttons tab, New Form wizard settings window
49 customized 130
Ribbon tab editor 17 Form editor 12, 15
row settings 118 Method editor 18
run application 24, 26 shortcut
running applications desktop 25, 134
compiled 37 shortcuts 157, 175
in a web browser 32, 323 use 197
in the COMSOL Client 34 Show as Dialog command 73
runtime 38 Show Dialog 131
Show Errors 129
S save
show form command 74
application 51
Show in Model Builder 130
running application 27
shutdown
save application command 325
cancel 149
save as 356
Single form template 55
save file 325
Single window 137
Scalar 161
422 |
sketch grid 113 system methods 350
sketch layout mode 54, 103, 112 OS commands 350
slider object 111, 153, 312
T table
smartphones
email attachment 350
running applications on 34
table object 153, 164, 307, 354
software rendering 43
add to table 308
solving 265, 271, 273
source 308
sound
tables, model tree 274
play 230
tablets
Sounds library 229
running applications on 34
Source for Initial Graphics Content 178,
Target for Data Picking 94, 179
179
temp, file scheme 327
spacer object 319
template 16, 46, 57
special characters 134
temporary file 340
splash screen 39
test application 24, 26
splitting cells 115, 120
test in web browser 24
state
text 141
enabled, for form objects 77
text color 54
visible, for form objects 77
text file 161, 275, 311
Status bar 137
text label object 95, 102, 104
status bar 265
text object 111, 153, 156, 302
Step 208
information node 292
Step Into 209
Theme 201
Step Out 209
Themes 13
Stop 208
Themes node 52
Stop Recording 193
thumbnail image 29, 30
stopping a method 208
time 358
Store changes 76
time parameter
Stretch image 263
combo box object 245
string variable 13, 73, 148, 150, 161, 164,
timestamps 273
240, 242, 250, 279, 291, 302
title
conversion 360
form 53
methods 362
main window 136
subroutine 17
menu 141
Subwindows 137
toggle button 111, 237
Switch to Model Builder and Activate
size 115
Data Access 97
text 115
syntax errors 194
toggle item
syntax highlighting 199, 201
menu 111, 141, 237
| 423
ribbon 111, 143, 237 combo box object 241
toolbar 318 data display object 104
toolbar 140, 275, 318 declaration 159
button, table object 311 explicit selection 92, 299
graphics 84, 111 gauge object 269
item 111, 318 graphics object 78
separator 141, 318 information card stack object 291
tooltip input field object 95
button 66 knob object 315
data display object 106 list box object 304
input field object 97 radio button object 297
knob object 315 results table object 275
method editor 202 selection input object 92, 299
slider object 270, 313 slider object 313
toolbar button 319 text object 302
unit mismatch 99 Use component syntax 200
transparency 81, 356 use shortcuts 197
TXT file 161, 275, 311, 312 user
file scheme 327, 342
U Unicode 102, 105
user interface layout 15
unit
username 350
changing using unit set 170
data display 104 V Value 167, 170
dimension check 98, 99, 173 variable 14, 157, 193
expression 98 accessing from method 212
groups 170 activation condition 168
lists 170 Boolean 163, 164, 233
object 95, 102 declaration 14, 157
Unit Groups 170 derived values 104
Unit Lists 170 double 163, 164
Unit Set 170 events 13, 148, 150
unit set 100, 157, 259, 298, 306 input field object 95
Untitled.mph 27 integer 163, 164
upload name completion 201
file scheme 169, 327, 332, 335 scalar 241, 281, 313
URL 134, 262, 317 slider object 313
use as source string 161, 164, 240, 242, 279, 291,
array input object 295 302
card stack object 282 text label object 102
check box object 235 Variables window 208
424 |
video
controls 265
player 265
video object 264
view
go to default 3D 87
graphics 81, 88, 355
reset current 81, 88
View all code 200
visible state, for form objects 77
volume maximum 104
| 425
426 |