Introduction To Live Link For Excel
Introduction To Live Link For Excel
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:
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Working with COMSOL® Models in Excel® . . . . . . . . . . . . . . . 6
Exporting Material Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Loading and Saving Excel® Files from the
COMSOL Desktop® . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
|3
4|
Introduction
Using the LiveLink™ for Excel®, you can take advantage of the capabilities and
structured simplicity offered by Microsoft® Excel® to extend your COMSOL
Multiphysics® modeling capacity. Parameters and variables that are defined and
modeled in COMSOL Multiphysics are instantly available in Excel and
automatically synchronized with your physics model.
Excel® files can be loaded and saved from COMSOL Desktop. This can be used
for handling parameters, variables, and interpolation data, for example, as well as
loading and saving Excel files from applications.
LiveLink™ for Excel® adds the capability to create a COMSOL® material library
from data stored in a worksheet and brings it into COMSOL Multiphysics.
Note: Connecting Excel to a COMSOL Multiphysics Server is only supported on
Windows®. Loading and saving files is supported on all platforms and does not
require Excel to be installed.
|5
Working with COMSOL® Models in Excel®
1 Start Excel.
2 The first time you start Excel after having installed COMSOL you may be met
with a dialog asking permission to install the COMSOL Add-in. Click OK to
do so. The first result of a successful installation it that the COMSOL 6.2
Ribbon tab appears in Excel.
6|
3 In the Excel File menu, select COMSOL to open the COMSOL backstage view.
Note: In the COMSOL backstage view you can manage the COMSOL
Multiphysics model, launch COMSOL Apps, connect manually to a server and
set the preferences.
|7
4 In the COMSOL backstage view click Open ( ) to expand the open options
list.
There you can choose to open a new model file ( ), open the model linked in
the current workbook, if available ( ), open a model from a Model Manager
database ( ), and open a recent file ( ).
5 As we start from blank worksheet and want to load a model from the COMSOL
Application library, click Open ( ).
6 In your COMSOL installation directory, find the folder
applications/LiveLink_for_Excel/Tutorials.
7 Select the file busbar_llexcel.mph and click the Open button.
8|
The model file is loaded onto a COMSOL Multiphysics server, which is
automatically started. A graphics window automatically displays the first plot
group available in the model.
Note: In case no solution is computed, the graphics window shows the model
geometry instead.
In the worksheet, the model path is automatically entered in cell B2.
|9
Retrieving and Updating Model Parameters
Extract selected parameters from the model that you have just opened to a
worksheet.
1 Select cell A4.
2 From the COMSOL 6.2 tab, Definitions group, click Parameters .
This imports all the model parameters to the worksheet and creates a direct link to
the Parameters nodes in the COMSOL model.
The link between the cell range in the worksheet and the COMSOL model is
represented by the comment in the cell A4.
In this example we only need to access the parameter L (the length of the busbar)
that is defined in the node Parameters 2.
3 To replace the imported parameters list by the one defined in Parameters 2 only,
select cell A4. From the COMSOL 6.2 tab, Definitions group, under
Parameters select Parameters > Parameters 2.
4 Click OK in the dialog box to replace the contents of the destination cell.
10 |
You may modify the parameters in the worksheet, for example by changing their
expression or description. You can also add new parameters to the list. Any change
to the list is transferred to the COMSOL model during the update operation,
which is by default done automatically.
You will now change the value of the L parameter to 5 cm:
5 In cell B6 enter 5, the parameter L is then automatically updated to 5 in
COMSOL Multiphysics.
| 11
7 You will now set the value of parameter L back to 9 cm, in cell B6 enter 9 and
press Enter. The graphics is not automatically updated so to display the newly
generated geometry, select again the Geometry > Geometry 1.
Extracting Results
P OINT E VALUATION
1 In Sheet1, select cell A13.
2 From the Numerical Results group, click the Point Evaluation button ( ).
3 In the dialog box that opens, select dset2 in the Dataset list. The solution
dataset dset2 contains the solution stored by the parametric solver.
4 Select point 1 from the Selection list and enter maxop1(T) in the Expression
text field; then click OK.
12 |
In the Excel spreadsheet, the cells containing the evaluated results are now linked
to the model and can be updated if you want to recompute the solution using
different parameter values.
I NTERPOLATION
Continue by calculating how much heat is produced
in the busbar at coordinates that you specify in the
worksheet.
1 Add a new sheet.
2 In the worksheet Sheet2, enter the coordinates as
shown in the figure to the right.
| 13
3 Select cell D4, then go to the Numerical Results group and click
Interpolation .
4In the Dataset menu list, select Study 1/
Parametric Solutions 1(dset2).
5In the Interpolation dialog box, in the
Expression text field, enter ht.Qtot, which
is the total heat source to be evaluated.
6In the Coordinates from cell range text
field, enter A4:C21. This is the range
containing the coordinates of the
interpolation points. You can also click the
Select Range button ( ) to select the cell
range.
7 Finally click OK.
The evaluation results are stored in a cell range of size 18 x 5, where 18 equals the
number of interpolation points and 5 is the number of parameter values contained
in the solution. In this case, the solution consists of a parameter sweep over the
applied voltage on the device, which varies from 5 mV to 40 mV.
14 |
8 You can format the worksheet for instance include column labels, insert cell at
your convenience. Make sure that the cell comment remains in the worksheet
to allow future updates.
You can display the solution using the plot group defined in the model. You can
find the plot groups available in the Plot Group list.
1 Click the Plot Group button , from the
Graphics group, to select the plot group to
display. Here, select Temperature (ht) (pg3).
| 15
The graphics window now displays the temperature distribution in the busbar as
in the figure below:
16 |
2 To insert the displayed image into the worksheet, switch to Sheet 1 and select
cell E13, then click Insert Screenshot from the Graphics group.
Note: While you can manually adjust the size of the image, you can also specify
the graphics scale when inserting the displayed image. You can find the settings
for inserting graphics in the Preferences window, which is accessible from the
COMSOL Backstage view.
This model of the busbar contains a Parametric Sweep node and a Stationary node
including an Auxiliary sweep. You can insert the sweep settings into a worksheet
to control the parameter values for the sweep from there.
1 Select cell A8 in Sheet 1 and from the Study group on the ribbon tab select
Compute > Sweep to open the Sweep dialog box. In the Sweep dialog box,
| 17
you can see that the current sweep node is defined with the busbar width
parameter (wbb) set to the value 10e-2.
2 Click Copy to Worksheet to insert the sweep parameter data starting at cell A8
and create a link between the cell range and the model.
3 To be able to edit the worksheet, first click Close to close the Sweep dialog box.
4 Add additional parameter values to the parametric sweep, in cell B9 enter 0.05,
in C9 enter 0.1 and in D9 enter 0.15.
5 You will now update the model with the additional parameter values, select A8
and click Compute > Sweep .
6 You may notice that the parameter value list and the range columns are updated
with the new values. Click Update Model to send these parameter values to the
model.
18 |
Computing the Solution
Now that you have a workbook containing model definitions and data evaluation
linked to a COMSOL model, you can easily modify and recompute the model
from the workbook, while keeping the evaluated results up to date.
Follow the steps below to update the results in Sheet1 and Sheet2.
| 19
1 Make sure that Sheet 1 is active, then on the ribbon tab, Numerical Results
group, click Update to update all the numerical results in the worksheet.
The point evaluation now includes results for different values of the busbar
width.
2 To update the image in Sheet 1, delete the existing image first, then insert it
again by clicking Insert Screenshot.
You can select Plot Group > Plot Data to display the solution for a different
value of the busbar width.
3 To update the total heat source interpolation only, switch to Sheet2, and select
the cell that contains the Interpolation comment, cell D3 if you did not change
the worksheet format.
20 |
4 In the Numerical Results group click Update .
Note that the new values correspond to the busbar width set to 5 cm. You need
to manually update the table header to reflect this.
5 You can continue to import data for other value of wbb, the easiest way is to
copy the cell that contains the interpolation comment (D4) and paste it at the
desired cell location, say I4.
6 Click the Interpolation button and select from the Parameter menu list the
second parameter value (wbb = 0.1) and click OK. A COMSOL dialog box
appears, click OK to confirm replacing the contents of the destination cells.
| 21
7 Finally repeat the two previous steps to insert the results for the third width
parameter value (wbb = 0.15) starting at cell N4.
If your model contains 1D plots you can in one step extract the plot data to a
worksheet and create an Excel chart.
The currently open model of the busbar contains a 1D plot of the maximum
temperature plotted against the applied voltage for the different width parameter
values.
1 From the Graphics group, click the Plot Group button , then select
1D Plot Group5 (pg5) to display it in the Graphics window.
Instead of inserting this plot as a static image, we will insert the plot data, and
create a scatter chart in the worksheet.
2 In Sheet 1 delete the previously inserted image, and select cell E13.
3 Click the 1D Plot Export button , and select 1D Plot Group 5 (pg5).
22 |
4This opens a dialog box where you can select the
data to be inserted into the worksheet.
Here it is possible to choose what plot features
should be imported in case the 1D plot contains
more than one plot. It is possible to control if a
plot should be generated in addition to imported
the numerical data. Note that the numerical data
have to be imported in order for Excel to be able
to generate a chart. Use the plot position to select
where the chart should be placed relative to the
imported data.
5In Plot position list, select Custom and enter
E19 in the Range field. Click OK.
The final chart looks like this when using the default settings:
| 23
Saving the Model and the Workbook
To keep the changes you have applied to the busbar model, save it to the
MPH-format. To avoid writing over the model from the Application Libraries, use
the Save As button.
1 Go to the Excel File menu and select COMSOL. In the COMSOL backstage
view click Save button and then select Save As , then save the file to a
location outside the COMSOL Application Libraries.
2 Continue with saving the Excel workbook, go to the File menu and select Save.
3 You can now exit Excel, which automatically closes the COMSOL Model
window as well.
Op e n i n g a W o rks h e et L i n ke d t o a Mo d e l
Once you have created a link to a COMSOL model in an Excel workbook and
saved the file, you can reopen the Excel file and update the link.
1 Start Excel and open the file you have saved in step 2 of the section Saving the
Model and the Workbook.
2 From the Main group of the COMSOL ribbon tab click Open linked .
Note: The path of the linked model is set in the COMSOL Model cell comment.
If necessary you can manually edit the cell comment to update the model path.
You can now continue your work with the model in Excel.
24 |
Automation Using VBA
Using Visual Basic for Application (VBA) you can write macros in Excel worksheet
that can automate operations between the worksheet and the COMSOL model.
For instance it is possible to generate a macro that does the operation above
automatically: update the sweep parameter, compute the solution and update the
results in the worksheet.
For more information please refer to LiveLink for Excel User’s Guide Manual.
You can also open the file busbar_llexcel.xlsm that you can find in your
COMSOL Multiphysics installation directory and in the folder
applications/LiveLink_for_Excel/Tutorials
| 25
Exporting Material Data
Using LiveLink™ for Excel® you can easily convert material properties saved in a
worksheet to a COMSOL material library. The Material Export group of the
COMSOL tab in Excel contains the tools to format and export the material data.
Follow the instructions below to create a user-defined material library that will be
available automatically in the Material Browser in the COMSOL Desktop.
In this section, step-by-step instructions show you how to export the data stored
in a spreadsheet to a material library in the COMSOL format. The first part of the
example shows how to define the export settings from constant data. The second
part of the example illustrates how to set the export from data field depending on
the physical quantity; you will consider temperature in this particular example.
Finally, in the last part, you will export the data from the spreadsheet to a
COMSOL material library.
D e f i n i n g M a t e r i a l E x p o r t S e t ti n g s fr o m C o n s t a n t D a t a
In this section, you will set up the material export using data stored as constants
in the spreadsheet.
Note: The export procedure described in this chapter assumes that the data are
stored in the spreadsheet with the material names in a single column and the
material property names in a single row. The data are placed at the intersection
cell of the material name and the property name.
1 Start Excel and open the file busbar_llexcel_data.xlsx that you can find in
your COMSOL Multiphysics installation directory and in the folder
applications/LiveLink_for_Excel/Tutorials.
2 Go to the worksheet Materials which contains the definitions of physical
properties for four different materials. The material properties listed are thermal
conductivity, density, heat capacity at constant pressure, relative permittivity and
26 |
electric conductivity. All properties are defined in SI units, except for density,
which has the unit lb/in3.
3 On the COMSOL 6.2 tab, click Settings to open the Material Export
Settings dialog box.
In the Settings dialog box you can select materials and properties to export. This
is also where you associate each material property from the worksheet with a
property recognized by COMSOL.
Export depends on the format of the data stored in the worksheet; you can have
material properties defined with constant values or ones that depend on field data,
such as temperature. In the worksheet Materials, you can see that the properties
are defined as constant.
| 27
4 In the Field Dependent Data page, make sure that the Sheet contains field
dependent data check box is not selected and go to the Material Properties
page.
5 You will now select the cells containing the material names. Click the Range
button ( ) next to the Material names range text field.
6 Select the range A2:A5 in the sheet and click OK.
7 Continue by selecting the cells with the property names. Click the Range
button ( ) to the right of the Property names range text field.
8 Select the range B1:F1 and click OK.
The properties are now listed in the table in the Material property settings section.
You now need to assign valid COMSOL properties to the material properties in
the spreadsheet.
9 From the Material property settings table select thermal conductivity (W/m/
K), then go to the Valid properties (SI Units) list and expand Basic Properties.
28 |
10Select Thermal conductivity -k [W/(m*K)] and click Assign.
| 29
15Repeat step 8 and 9 for the remaining material properties. Select valid
properties according to the table below:
Once there are no unassigned properties remaining, a check mark appears next
to the last step in the Instructions section.
30 |
16Click OK to save the settings, and to close the dialog box.
Note that comments now appear on the cells containing the material names and
properties.
These comments contain the configuration for the material data export that you
have just set up. Make sure not to remove them before completing the export.
To modify the settings you can return to the Settings dialog box.
You can also use these settings as a template to run the export in a batch.
D e f i n i n g M a t e r i a l E x p o r t Se t ti n g s fr o m F i e l d D a t a
In this section you will continue to define the material export settings, but this
time using data defined as fields that depend on a variable. A valid field variable
corresponds to model inputs in the COMSOL model. Typical examples include
physical quantities such as temperature, concentration, and frequency. See About
Model Inputs in the COMSOL Multiphysics Reference Manual to get a complete
list of valid model inputs.
You can choose to export the material properties as tabulated data or constant
values.
Note: The export procedure described in this chapter assumes that data is stored
in the spreadsheet with the field variable data in a single column and the material
property names in a single row. The data are placed at the intersection cells of the
field data and the property name. It also assumes one material per sheet.
| 31
spreadsheet includes property data in the temperature range 273.15 K to
518.15 K.
2 On the COMSOL 6.2 tab, click Settings to open the Material Export
Settings dialog box.
3 In the Field Dependent Data page, select Sheet contains field dependent data
check box.
4 Now select the range where the field variable is defined. Click the Range button
( )next to the Field variable name range text field and select the range A2 in
the sheet. Click OK to validate the selection.
32 |
5 In the next step, assign a valid model input to the selected variable field. In the
Assigned model input list, select Temperature, T.
Note: If the data stored in the worksheet are not defined in SI units, you need to
update the Unit text field.
You can verify that all requirements in the field dependent page are set when the
instructions list only contains green check marks ( ).
6 Go to the Material properties page to continue with the material library export
settings.
7 You will now select the cells containing the material names. Click the Range
button ( ) next to the Material names range text field.
8 Select cell A1 in the sheet and click OK.
9 Continue by selecting the cells with the property names. Click the Range
button ( ) to the right of the Property names range text field.
10Select the range B2:E2 and click OK.
The properties are now listed in the table in the Material property settings section.
You now need to assign valid COMSOL properties to the material properties in
the spreadsheet.
| 33
11From the Material property settings table select eta (Pa*s), then go to the Valid
properties (SI Units) list and expand Basic Properties.
12Select Dynamic viscosity - mu [Pa*s] and click Assign.
34 |
13Repeat steps 11 and 12 for the remaining material properties. Select valid
properties according to the table below:
Once there are no unassigned properties remaining, a check mark appears next
to the last step in the Instructions section.
Note: Select Constant dialog box to export a specific property as constant. For
constant export, select the cell range of the property values in the Property name
range.
14Click OK to save the settings, and to close the dialog box.
| 35
15Note that comments now appear on the cells containing the material names and
properties.
Now that you have defined the material export settings for data stored in the
workbook you can finalize the export to a new material library.
1 Go to Materials worksheet.
2 To create a material library using the selected data in the spreadsheet, click
New in the Material Export group. This automatically starts the COMSOL
Multiphysics Server, if not already started, and the Save Material Library
window.
3 In the Save Material Library window browse to the folder
.comsol/v62/materials available in the user local directory.
4 In File name text field, enter a name for the material library. For this example,
enter My_Materials and click Save.
5 Now go to the Water, liquid worksheet.
6 To append the material to the library created previously, click the Append ( )
button.
7 In the Open Material Model window, select My_Materials.mph and click Open.
The next time you start the COMSOL Desktop, the Material Browser will be
automatically updated with the new library saved in the .comsol/v62/materials
folder.
36 |
Loading and Saving Excel® Files from the
COMSOL Desktop®
LiveLink™ for Excel® adds the Excel XLSX format in the list of supported file
formats for loading and saving data while setting up applications in the COMSOL
Desktop. Feature nodes that support this functionality include Parameters,
Variables, Interpolation functions, Piecewise functions, Parametric Sweep, the
continuation section of the Stationary node, and the auxiliary sweep section. The
data formats used by these features may differ. The easiest way to find out how to
organize data in the Excel file is to enter some settings in a table in the COMSOL
Desktop and save it to the Excel format.
In the current example, you will modify an existing model by importing model
definitions from an Excel file. You will start by loading the model, Electrical
Heating in a Busbar, from the COMSOL Multiphysics application library. This
model analyzes the resistive heating of a busbar designed to conduct direct
current. For details, see the booklet Introduction to COMSOL Multiphysics.
The tutorial walks you through how to import Excel files for three feature nodes,
each with a different requirement on the data format. The feature nodes that are
covered are:
• Parameters
• Interpolation function
• Continuation section of the Stationary study step node
1 If it is not already open, start a new COMSOL Desktop. From the File toolbar,
select Application Libraries .
2 In the Application Libraries window, choose COMSOL
Multiphysics>Multiphysics>busbar and click Open .
| 37
Importing Parameters from Excel®
38 |
5 In the Excel Load dialog box, specify the sheet and cell range to use for the
import. Enter Parameters in the Sheet text field, and enter A3 in the Range
text field to import all parameters from the third row. Note that the range
should not include the column headers.
To keep the existing parameters in a model unmodified by the import, you can
clear the Overwrite check box in the Excel Load dialog box before the import.
In this case, imported parameters will be appended to the table and you will
need to resolve any conflicts between similar parameter names yourself.
Note: COMSOL does not support multiple parameters with the same name.
Only the first parameter definition, from the top, is kept in the table if multiple
entries with the same name are present when you leave the Parameters node.
7 In the Home toolbar, click Parameters and select Add>Parameters.
8 In Parameters 2 Settings window, click Load from File .
9 In the Load from File dialog box, select the Microsoft Excel Workbook (*.xlsx)
file type and navigate to the COMSOL installation directory. In the folder
applications/LiveLink_for_Excel/Tutorials, select the file
busbar_llexcel_data.xlsx and click Open.
10In the Excel Load dialog box, specify the sheet and cell range to use for the
import. Enter Parameters in the Sheet text field, and enter A2:C2 in the Range
text field to import only the parameter at the second row (L, the length of the
busbar).
| 39
Here we use a second parameters node only to show how you can link a specify
group of parameters with a spreadsheet when running a model from within Excel.
See the section Retrieving and Updating Model Parameters.
11In the Geometry toolbar, click Build All and go to Geometry 1 node to
visualize the geometry with the new parameters value.
D e f i n i n g a n I n t e r p o l a t i o n Fu n c t i o n U s i n g a n E x c e l ® F i l e
You will now import data stored in a workbook to define an interpolation function
in the model. The function defines the temperature dependency of the heat
transfer coefficient between the busbar and the surrounding air.
1 In the Home toolbar, click Functions in the Definitions group. Under the
Local section, select Interpolation . On Linux and Mac, the Home toolbar
refers to the specific set of controls near the top of the Desktop.
2 In the Settings window, under the Definition section, in the Function name text
field, enter htc.
3 Now click Load from File .
40 |
4 In the Load from File dialog box, select the Microsoft
Excel Workbook (*.xlsx) file type, and navigate to the
COMSOL installation directory. In the folder
applications/LiveLink_for_Excel/Tutorials,
select the file busbar_llexcel_data.xlsx, then click
Open.
The interpolation data is stored in the workbook in a
worksheet named htc(T). The temperature values and
the corresponding heat transfer coefficient values are
defined in two columns, as can be seen in the figure to the
right.
5 In the Settings window for Interpolation enter htc(T) in the Sheet text field.
6 In the Range field enter A2.
7 To import the data, click Load.
The interpolation table is filled using the data stored in the Excel file.
| 41
9 Locate the section, Units. In the
Function text field enter W/
(m^2*K). in the Arguments text
field enter K.
Now continue with changing the model settings to use the newly defined
function for the heat transfer coefficient in the heat flux boundary condition.
11In the Model Builder, under the Component 1 node, expand the Heat Transfer
in Solids nodes and then click Heat Flux 1.
12In the Settings window for Heat Flux replace the expression in the Heat transfer
coefficient text field with htc(T).
With the use of an auxiliary sweep, you can solve the model for a range of
parameter values, which enables you to vary, for example, a boundary condition.
Here, solve the model for different values of the applied voltage Vtot, imported
from the same Excel file used previously.
42 |
1 In the Model Builder, expand Study 1 and click Step 1: Stationary.
2 In the Settings window for Stationary expand Study Extensions.
3 Under the Study Extensions section, select Auxiliary sweep and then click the
Load from File button.
4 In the Load from File dialog box, select the Microsoft Excel Workbook (*.xlsx)
file type, and navigate to the COMSOL Multiphysics installation directory. In
the folder applications/LiveLink_for_Excel/Tutorials, select the file
busbar_llexcel_data.xlsx, then click Open.
The continuation parameter list can be found in the worksheet, Voltage, in the
file.
5 In the Excel Load dialog box, enter Voltage and A2, in the Sheet and Range
text fields, respectively.
As a last step, compute the solution that reflects the changes you have applied to
the model. But before you will add a maximum operator for postprocessing
purpose and a Parametric Sweep node to prepare the model to show how you can
link parametric and auxiliary sweep with a spreadsheet when running a model from
within Excel. See the section Running Model in Sweep.
1 In the Definitions toolbar, click Nonlocal Couplings and select Maximum
.
2 In the Maximum 1 settings windows, select Domain 1.
3 In the Study toolbar, click Parametric Sweep .
4 In the Parametric Sweep node window settings, click Add and select the
parameter wbb (Width of busbar). In the Parameter value list text field enter
10e-2.
| 43
5 In the Study 1 node Settings window, under Study Settings, clear Generate
default plots to avoid duplicate plot groups when computing the solution with
the parametric sweep.
6 In the Study toolbar, click Compute .
7 To view the temperature distribution in the busbar only, you need to add a
selection to the solution dataset. Under Results > Datasets, right-click
Study 1/Parametric Solutions 1 and select Selection.
8 In the Settings window for Selection set the Geometric entity level to Domain,
and select Domain 1.
9 To see the temperature distribution in the busbar for the last parameter value
(40 mV), select the Temperature (ht) node. In the 3D plot Group settings
window, in the Dataset list, select Study 1/parametric Solutions 1.
10Expand the Temperature (ht) node, and select Surface. In the Surface node
settings windows, expands the Range section and clear Manual color range.
44 |