Livelink for MATLAB User's Guide
Total Page:16
File Type:pdf, Size:1020Kb
LiveLink™ for MATLAB® User’s Guide LiveLink™ for MATLAB® User’s Guide © 2009–2020 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;; 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. MATLAB and Simulink are registered trademarks of The MathWorks, Inc.. 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 5.6 Contact Information Visit the Contact COMSOL page at www.comsol.com/contact to submit general inquiries, contact Technical Support, 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 at 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/support/updates • COMSOL Blog: www.comsol.com/blogs • Discussion Forum: www.comsol.com/community • Events: www.comsol.com/events • COMSOL Video Gallery: www.comsol.com/video • Support Knowledge Base: www.comsol.com/support/knowledgebase Part number: CM020008 Contents Chapter 1: Introduction About This Product 12 Help and Documentation 14 Getting Help . 14 Where Do I Access the Documentation and the Application Libraries? . 18 Chapter 2: Getting Started The Client/Server Architecture 24 Running COMSOL Models at the Command Line 26 Starting COMSOL® with MATLAB® on Windows ®/ Mac OSX / Linux®. 26 Connecting a COMSOL Server and MATLAB® Manually . 28 Connecting to COMSOL Server™ . 30 Changing the MATLAB® Version . 32 The COMSOL Apps 34 Installing Apps in the MATLAB Apps Ribbon . 34 Removing Apps in the MATLAB Apps Ribbon.. 34 The COMSOL Apps . 35 Calling External Functions From Within the Model 36 Chapter 3: Building Models The Model Object 38 Important Notes About the Model Object . 38 CONTENTS | 3 The Model Object Methods. 39 The General Utility Functionality . 39 The Model History . 40 Loading and Saving a Model . 41 Sharing the Model Between the COMSOL Desktop® and the MATLAB® Prompt . 46 Working with Geometries 50 The Geometry Sequence Syntax . 50 Displaying the Geometry . 51 Working with Geometry Sequences . 52 Retrieving Geometry Information . 62 Modeling with a Parameterized Geometry . 64 Images and Interpolation Data . 67 Measuring Entities in Geometry . 75 Working with Meshes 76 The Meshing Sequence Syntax . 76 Displaying the Mesh. 77 Mesh Creation Functions. 78 Importing External Meshes and Mesh Objects . 103 Measuring Mesh Quality . 105 Getting Mesh Statistics Information . 106 Getting and Setting Mesh Data. 109 Modeling Physics 114 The Physics Interface Syntax . 114 The Material Syntax . 117 Modifying the Equations . 119 Adding Global Equations . 120 Defining Model Settings Using External Data File . 122 Access the User-Defined Physics Interface . 123 Creating Selections 125 The Selection Node. 125 Coordinate-Based Selections . 126 Selection Using Adjacent Geometry. 130 Displaying Selections . 131 4 | CONTENTS Computing the Solution 134 The Study Node . 134 The Solver Sequence Syntax . 135 Run the Solver Sequence . 136 Adding a Parametric Sweep . 137 Adding a Job Sequence. 137 Plot While Solving . 138 Analyzing the Results 140 The Plot Group Syntax . 140 Displaying The Results . 141 The Dataset Syntax . 148 The Numerical Node Syntax . 149 Exporting Data . 150 Generating Report . 152 Chapter 4: Working With Models Using Workspace Variables in Model Settings 156 The Set and SetIndex Methods . 156 Using a MATLAB® Function to Define Model Properties . 157 Extracting Results 159 Extracting Data at Arbitrary Points . 159 Evaluating a Minimum of Expression. 163 Evaluating a Maximum of Expression . 165 Evaluating an Integral . 168 Evaluating an Expression Average . 170 Extracting Data at Node Points . 173 Evaluating an Expression at Geometry Vertices . 176 Evaluating Expressions on Particle/Ray Trajectories . 179 Evaluating a Global Expression. 180 Evaluating a Matrix Expression at Points . 182 Evaluating a Global Matrix . 184 Extracting Data From Tables . 186 CONTENTS | 5 Running Models in a Loop 187 The Parametric Sweep Node . 187 Running Model in a Loop Using the MATLAB® Tools . 187 Running Models in Batch Mode 190 The Batch Node . 190 Running an M-File in Batch Mode. 190 Running an M-File in Batch Mode Without Display . 191 Working with Matrices 192 Extracting System Matrices . 192 Set System Matrices in the Model . 198 Extracting State-Space Matrices . 204 Extracting Reduced Order State-Space Matrices . 212 Extracting Solution Information and Solution Vectors 220 Obtaining Solution Information . 220 Retrieving Solution Information and Solution Datasets Based on Parameter Values . 222 Extracting Solution Vector . 225 Retrieving Xmesh Information 228 The Extended Mesh (Xmesh) . 228 Extracting Xmesh Information . 228 Navigating the Model 231 Navigating the Model Object Using a GUI . 231 Navigating The Model Object At The Command Line . 237 Finding Model Expressions . 237 Evaluating the Model Parameters . 239 Getting Feature Model Properties . 240 Getting Parameter and Variable Definitions . 241 Getting Selection Information . 241 Handling Errors and Warnings 242 Errors and Warnings . 242 Using MATLAB® Tools to Handle COMSOL® Exceptions . 242 Displaying Warnings and Errors in the Model . 242 6 | CONTENTS Improving Performance for Large Models 244 Allocating Memory . 244 Disabling Model Feature Update . 245 Disabling The Model History . 246 Creating a Custom GUI 247 Chapter 5: Calling External Functions Running External Function 250 Allowing External MATLAB Functions . 250 Disabling MATLAB® Splash Screen at Start-Up . 251 Running a MATLAB® Function in Applications . 251 The MATLAB® Function Feature Node 252 Defining a MATLAB® Function in the COMSOL® Model . 252 Setting the Function Directory Path in MATLAB® . 257 Adding a MATLAB® Function with the COMSOL® API Syntax . 257 Function Input/Output Considerations . 258 Updating Functions . 259 Defining Function Derivatives . 259 Chapter 6: Command Reference Summary of Commands 262 Commands Grouped by Function 263 colortable . 266 mphaddplotdata . 268 mphapplicationlibraries . 269 mphcd . 270 mphdoc . 271 mpheval . 271 mphevalglobalmatrix . 275 mphevalpoint . 277 CONTENTS | 7 mphevalpointmatrix . 279 mphevaluate . 280 mphgeom. 281 mphgetadj . 284 mphgetcoords . 285 mphgetexpressions . 286 mphgetproperties . 286 mphgetselection . 287 mphgetu . 288 mphglobal . 290 mphimage2geom . 292 mphinputmatrix . 294 mphint2 . 296 mphinterp . 298 mphinterpolationfile. 304 mphlaunch . 305 mphload . 306 mphmatrix . 307 mphmax . 311 mphmean. 314 mphmeasure . 316 mphmesh. 317 mphmeshstats . 319 mphmin . 321 mphmodel . 324 mphnavigator . 325 mphopen . 327 mphparticle . 328 mphplot . 330 mphquad2tri . 332 mphray . 333 mphreadstl . ..