[go: up one dir, main page]

0% found this document useful (0 votes)
12 views44 pages

Introduction To Live Link For Excel

Comsol live link to excel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views44 pages

Introduction To Live Link For Excel

Comsol live link to excel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

INTRODUCTION TO

LiveLink for Excel


™ ®
Introduction to LiveLink™ for Excel®
© 2012–2023 COMSOL
Protected by patents listed on www.comsol.com/patents, or see Help>About COMSOL Multiphysics on the File
menu in the COMSOL Desktop for less detailed lists of U.S. Patents that may apply. 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. Microsoft, Excel, Visual Basic and
Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other
countries. 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 or the above non-COMSOL
trademark owners. For a list of such trademark owners, see www.comsol.com/trademarks.
Version: COMSOL 6.2

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:

• Support Center: www.comsol.com/support


• Product Download: www.comsol.com/product-download
• Product Updates: www.comsol.com/product-update
• COMSOL Blog: www.comsol.com/blogs
• Discussion Forum: www.comsol.com/forum
• Events: www.comsol.com/events
• COMSOL Video Gallery: www.comsol.com/videos
• Support Knowledge Base: www.comsol.com/support/knowledgebase

Part number: CM023402


Contents

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®

LiveLink™ for Excel® enables direct access of model definitions such as


parameters, variables, and functions by using the tools from the COMSOL ribbon
tabs in Excel. You can also modify and update the model, recompute the solution,
and extract results to a worksheet. The step-by-step instructions below detail how
to work with a model in Excel spreadsheets, covering the stages of:
• Opening and saving COMSOL models
• Retrieving and updating Model Parameters
• Computing the solution and extracting results
• Updating existing data in a linked workbook
The example is based on a modified version of the model, Electrical Heating in a
Busbar, from the COMSOL Multiphysics application library. The model analyzes
the resistive heating of a busbar designed to conduct direct current; for details, see
the Introduction to COMSOL Multiphysics.
Note: The step-by-step instructions below are designed to be carried out in a
sequence. Skipping any of the sections might result in data not being available for
the following sections. Start with Opening a Model and work through the sections
until reaching the last section, Opening a Worksheet Linked to a Model.

Ope n ing a Mode l

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.

After this you can load a COMSOL model.

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.

The cell A1 contains a comment represented by a red


triangle at the upper-right corner of the cell. This
comment links the workbook to the model file even if
you save and reopen the workbook. How to open a
linked model is described in the last section of this tutorial, Opening a Worksheet
Linked to a Model. Do not remove this comment unless you want to break the link
between the files.
Note: A workbook can be linked to only one COMSOL model at a time.

|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.

Note: You may retrieve parameters to several locations in a worksheet or


workbook. Each time you extract model parameters, a link is created for that cell
range, so that you can update the model with the selected parameter list.

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.

Note: If you prefer a manual parameter update, go to the COMSOL preferences


in the Backstage view and clear Automatic update check box. Then you can use
the update button to update the Parameters node linked to the selected cell
by the comment. You can update several model definitions, such as parameters,
variables, and functions, contained in the same worksheet with the Update All
button located under Update. When several Parameter table are available in
the worksheet, click Update Multiple , located under Update, to select which
parameter to update with the other model definitions.
To visualize the change in the model geometry due to the edited length
parameter, you can display the updated geometry:
6 In the Graphics group, click the Geometry button and select Geometry 1.
The graphics window should now display the geometry as shown in the figure
below:

| 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

The model loaded on the COMSOL Multiphysics server already contains a


solution. It also contains an operator to evaluate the maximum in the busbar
domain. Continue with the steps below to import the maximum temperature of
the busbar to the worksheet.

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.

Displaying the Solution

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:

The plot represents the solution from the saved model.


Note: For time dependent solutions or parametric sweeps, you can select the
solution to display by selecting the Plot Group > Plot Data from the Graphics
group on the ribbon tab.

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.

Running Model in Sweep

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

Continue with solving the model.


1 In the Study group, click the Compute button .
In case the model contains several studies, you can select Compute > Study ,
then select the study to solve.
2 From the Graphics group, click the Plot Group button , then select
Temperature (ht) (pg3).
The Graphics window is updated with the temperature distribution in the
busbar for the first width parameter value in the recomputed sweep.

Updating Data in a Worksheet

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.

Importing 1D Plot Data

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.

Note that the number of properties remaining to be assigned is displayed in the


Instructions section.
11In the Material property settings table now select density (lb/in^3) from the
Name column.
12Under Valid properties (SI Units) in the Filter
field enter Density to search for all available
properties density type, and select Density - rho
[kg/m^3].
As density data in the worksheet are not defined in
SI unit (kg/m^3), you need to specify the material
properties unit.
13Below the valid properties list, locate the Unit
text field and enter lb/in^3.
14Click Assign to assign the properties and the unit
to the data in the spreadsheet.

| 29
15Repeat step 8 and 9 for the remaining material properties. Select valid
properties according to the table below:

PROPERTY NAMES VALID PROPERTIES (SI UNITS) UNIT

Cp (J/(kg*K)) Heat capacity at constant J/(kg*K)


pressure - Cp [J/(kg*K)]
Relative permittivity Relative permittivity - 1
epsilonr [1]
sigma (S/m) Electrical conductivity - S/m
sigma [S/m]

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.

1 In the workbook busbar_llexcel_data.xlsx, go to the worksheet Water,


liquid that contains the definitions for the dynamic viscosity, heat capacity at
constant pressure, density, and thermal conductivity of liquid water. The

| 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.

Note that the number of properties remaining to be assigned is displayed in the


Instructions section.

34 |
13Repeat steps 11 and 12 for the remaining material properties. Select valid
properties according to the table below:

PROPERTY NAMES VALID PROPERTIES (SI UNITS) UNIT

Cp (J/(kg*K)) Heat capacity at constant J/(kg*K)


pressure - Cp [J/(kg*K)]
rho(kg/m^3) Density - rho [kg/m^3] kg/m^3
k (W/(m*K)) Thermal conductivity - k W/(m*K)
[W/(m*K)]

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.

Exporting the Material 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

Ope n ing th e M o del

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®

1 In the Model Builder, find and


expand the Global Definitions
node, then select the Parameters 1
node.
As you can see, the model already
contains some parameters in the
table.
In order to illustrate the different
import capabilities we will replace
this list by a new one.
2 First clear the table by pressing the Clear Table button to prevent multiple
parameters with the same name.
3 To import parameters from an Excel file to the list, click Load from File
located below the table.
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 and click Open.

This opens the Excel Load dialog box.


The workbook contains a list of
parameters in the Parameters worksheet,
which is shown in the figure to the right.
If you compare this list to the parameters
defined in the model, you can see that
the heat transfer coefficient is not
included. The busbar width value is also
different; 10 cm in the Excel file instead of 5 cm in the model.

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.

6 Click Load. The parameter list is now imported to the model.

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.

8 Locate the section, Interpolation and Extrapolation. In the Interpolation list,


select Piecewise cubic.

| 41
9 Locate the section, Units. In the
Function text field enter W/
(m^2*K). in the Arguments text
field enter K.

10To display the interpolation curve, click Plot .

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).

Importing a Sweep List

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.

6 Finally, click Load.


The study is now set up to compute the solution for each of the specified voltage
values: 5 mV, 10 mV, 20 mV, 30 mV, and 40 mV.

Computing and Displaying the Solution

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.

11In the Results toolbar click 1D Plot Group .


12In the 1D Plot Group settings window, in Dataset list select Study 1/Parametric
Solutions 1.
13In the 1D Plot Group 6 toolbar, click Global and in the Global settings
window, enter maxop1(T) in the Expression field.
14Click Plot .

44 |

You might also like