You are on page 1of 436

Š

8VHU·V*XLGHDQG,QWURGXFWLRQ

) 2 5  8 6 (  : , 7 +  0 $7 / $ %

:,1'2:6

81,;

/,18;

0$&,1726+

9(56,21
+RZWRFRQWDFW&2062/

&2062/$% &2062/,QF 0DLODQGYLVLW


7HJQpUJDWDQ 1HZ(QJODQG
6(672&.+2/0 ([HFXWLYH3DUN
6ZHGHQ %XUOLQJWRQ0$
86$

    3KRQH

    )D[

http://www.femlab.com )(0/$%KRPHSDJH
ftp://ftp.femlab.com )73VHUYHU
http://www.comsol.se http://www.comsol.com &RPSDQ\KRPHSDJH

support@femlab.com support@comsol.com 7HFKQLFDOVXSSRUW


suggest@femlab.com 3URGXFWHQKDQFHPHQW
info@femlab.com info@comsol.com 6DOHVSULFLQJDQG
JHQHUDOLQIRUPDWLRQ

FEMLAB User’s Guide and Introduction


 COPYRIGHT 1994 - 2002 by COMSOL AB. All rights reserved
Patent pending
The software described in this document is furnished under a license agreement. The software may be used or copied only under the
terms of the license agreement. No part of this manual may be photocopied or reproduced in any form without prior written consent
from COMSOL AB.
FEMLAB is a registered trademark of COMSOL AB.
MATLAB, Simulink, and Handle Graphics are registered trademarks of The MathWorks, Inc.
Other product or brand names are trademarks or registered trademarks of their respective holders.
Printing History: October 2000 First printing FEMLAB 2.0
November 2001 Second printing FEMLAB 2.2
C O N T E N T S

U s e r ’s G u i d e a n d I n t r o d u c t i o n

Preface 1-2

Introduction 1-5
What is FEMLAB? . . . . . . . . . . . . . . . . . . . . . . 1-6
The FEMLAB Environment . . . . . . . . . . . . . . . . . . . 1-8
The FEMLAB Documentation Set . . . . . . . . . . . . . . . 1-10
Optional Modules for Specific Disciplines. . . . . . . . . . . . . 1-12
Installing FEMLAB . . . . . . . . . . . . . . . . . . . . . 1-16
New Features in FEMLAB 2.2 . . . . . . . . . . . . . . . . . 1-16
New Features in FEMLAB 2.3 . . . . . . . . . . . . . . . . . 1-17
New Features in Chemical Engineering Module 2.1 . . . . . . . . . 1-19
New Features in Chemical Engineering Module 2.3 . . . . . . . . . 1-20
New Features in Electromagnetics Module 2.0 . . . . . . . . . . . 1-21
New Features in Electromagnetics Module 2.3 . . . . . . . . . . . 1-22
New Features in Structural Mechanics Module 2.3 . . . . . . . . . 1-24

The FEMLAB Quick Start Guide 1-26


Forced and Free Convection Heat Transfer . . . . . . . . . . . . 1-26
Advanced Postprocessing. . . . . . . . . . . . . . . . . . . 1-44
Boundary and PDE Coefficient Views . . . . . . . . . . . . . . 1-49
Model M-files . . . . . . . . . . . . . . . . . . . . . . . 1-51
Time-dependent Simulation . . . . . . . . . . . . . . . . . . 1-54

The Model Navigator and the Model Library 1-63


The Model Navigator . . . . . . . . . . . . . . . . . . . . 1-63
New Page . . . . . . . . . . . . . . . . . . . . . . . . 1-64
Model Library Page . . . . . . . . . . . . . . . . . . . . . 1-65
User Models Page . . . . . . . . . . . . . . . . . . . . . 1-68
Multiphysics Page . . . . . . . . . . . . . . . . . . . . . . 1-69
Preferences Page . . . . . . . . . . . . . . . . . . . . . . 1-69

&217(176 | L

The FEMLAB Graphical User Interface 1-71
The Menus . . . . . . . . . . . . . . . . . . . . . . . . 1-72
The Toolbars . . . . . . . . . . . . . . . . . . . . . . . 1-74
The GUI Modes . . . . . . . . . . . . . . . . . . . . . . 1-78
Object Selection Methods in 2D . . . . . . . . . . . . . . . . 1-80
Display Additional Information. . . . . . . . . . . . . . . . . 1-80
Entering MATLAB® Expressions in the GUI. . . . . . . . . . . . 1-81
The FEMLAB Data Formats . . . . . . . . . . . . . . . . . . 1-81
The 3D Graphical User Interface . . . . . . . . . . . . . . . . 1-82
Visualization in 3D . . . . . . . . . . . . . . . . . . . . . 1-86
The 3D View . . . . . . . . . . . . . . . . . . . . . . . 1-92
Object Selection Methods in 3D . . . . . . . . . . . . . . . . 1-95
Suppression of Objects in 3D . . . . . . . . . . . . . . . . . 1-106

Modeling with FEMLAB 1-108


Style Conventions for the Model Descriptions. . . . . . . . . . . 1-108
Thermo-Electric Heating in a Bus Bar . . . . . . . . . . . . . . 1-109
Thermo-Electric Heating in a Bus Bar with Multiphysics . . . . . . . 1-138
Controlling Temperature, Exporting to Simulink® . . . . . . . . . 1-153

Geometry Modeling 1-170


Creating a 2D Geometry Model . . . . . . . . . . . . . . . . 1-171
Creating a 3D Geometry Model . . . . . . . . . . . . . . . . 1-186
Creating a 1D Geometry Model . . . . . . . . . . . . . . . . 1-207
Importing CAD Models . . . . . . . . . . . . . . . . . . . 1-209
Image and MRI Import . . . . . . . . . . . . . . . . . . . . 1-220
Spline Interpolation for Creating Geometry Objects . . . . . . . . 1-225
Surface Interpolation . . . . . . . . . . . . . . . . . . . . 1-228
Insertion of Points in Geometry Models . . . . . . . . . . . . . 1-232
Parameterization of Curves and Faces . . . . . . . . . . . . . . 1-235
Associative Geometry . . . . . . . . . . . . . . . . . . . . 1-238

The Application Modes 1-239


The Physics Modes . . . . . . . . . . . . . . . . . . . . . 1-240
Heat Transfer . . . . . . . . . . . . . . . . . . . . . . . 1-243
Diffusion . . . . . . . . . . . . . . . . . . . . . . . . . 1-246
Electromagnetics . . . . . . . . . . . . . . . . . . . . . . 1-248
Structural Mechanics . . . . . . . . . . . . . . . . . . . . 1-264

LL | &217(176
Fluid Mechanics . . . . . . . . . . . . . . . . . . . . . . 1-271

Extended Multiphysics 1-276


Coupling Variables . . . . . . . . . . . . . . . . . . . . . 1-276
Specifying Non-Local Couplings . . . . . . . . . . . . . . . . 1-277
Scalar Couplings . . . . . . . . . . . . . . . . . . . . . . 1-277
Extrusion Couplings. . . . . . . . . . . . . . . . . . . . . 1-280
Projection Couplings . . . . . . . . . . . . . . . . . . . . 1-283
The Weak Solution Form and the Solvers . . . . . . . . . . . . 1-285
Sparsity of Jacobian . . . . . . . . . . . . . . . . . . . . . 1-285
Non-Local Dirichlet Boundary conditions . . . . . . . . . . . . 1-286

Interpolation of Measured Data 1-287


Interpolation of Measured Material Properties . . . . . . . . . . . 1-287

The Programming Language 1-301


The FEM Structure . . . . . . . . . . . . . . . . . . . . . 1-301
The FEMLAB Functions . . . . . . . . . . . . . . . . . . . 1-303
Example: Solving Poisson’s Equation . . . . . . . . . . . . . . . 1-305
The Application Structure . . . . . . . . . . . . . . . . . . 1-314
Example: Thermo-Electric Heating . . . . . . . . . . . . . . . 1-319
Advanced Visualization and High-Resolution Images. . . . . . . . . 1-329
Hints and Suggestions for Using the Programming Language. . . . . . 1-334

The FEMLAB PDE Language 1-336


Overview of PDE Models. . . . . . . . . . . . . . . . . . . 1-336
Interpreting PDE Coefficients . . . . . . . . . . . . . . . . . 1-348
Classical PDEs . . . . . . . . . . . . . . . . . . . . . . . 1-349
Expressions in Dialog Boxes. . . . . . . . . . . . . . . . . . 1-350
Variable Classification and Geometric Scope . . . . . . . . . . . 1-351
Constants . . . . . . . . . . . . . . . . . . . . . . . . 1-352
Geometric Variables . . . . . . . . . . . . . . . . . . . . 1-352
Field Variables . . . . . . . . . . . . . . . . . . . . . . . 1-355
Variables for PDEs in Coefficient Form . . . . . . . . . . . . . 1-356
Variable Naming Convention . . . . . . . . . . . . . . . . . 1-366
Variables for PDEs in General Form. . . . . . . . . . . . . . . 1-366
Weak Form Meta Variables . . . . . . . . . . . . . . . . . . 1-372
Variable Name Suffixes For Multiphysics . . . . . . . . . . . . . 1-374

& 2 1 7 ( 1 7 6 | LLL

Special Variables . . . . . . . . . . . . . . . . . . . . . . 1-375

Equation-Based Modeling 1-378


Tubular Reactor . . . . . . . . . . . . . . . . . . . . . . 1-378
Cylindrical Tubular Reactor with Cooling. . . . . . . . . . . . . 1-385

Modeling Approaches 1-394


Multiphysics Modeling Approaches . . . . . . . . . . . . . . . 1-394
Iteration Techniques for Solving Multicomponent Systems . . . . . . 1-395
Scaling of the Geometry . . . . . . . . . . . . . . . . . . . 1-395
Scaling of the Variables and Equations . . . . . . . . . . . . . . 1-397
Point and Edge Constraints and Loads . . . . . . . . . . . . . . 1-398
Weak Constraints, Their Uses and Limitations. . . . . . . . . . . 1-398
Accurate Flux Computation. . . . . . . . . . . . . . . . . . 1-402
Using Weak Coefficients or the Weak Modes . . . . . . . . . . . 1-404

The Solvers 1-406


Solver Types . . . . . . . . . . . . . . . . . . . . . . . 1-406
Selecting Solution Form . . . . . . . . . . . . . . . . . . . 1-407
Using Submodes . . . . . . . . . . . . . . . . . . . . . . 1-407
Which Models are Nonlinear? . . . . . . . . . . . . . . . . . 1-407
Direct Solvers vs. Iterative Solvers . . . . . . . . . . . . . . . 1-408
Selecting Iterative Solver . . . . . . . . . . . . . . . . . . . 1-408
Tuning the Parameters to the Iterative Solvers . . . . . . . . . . . 1-409
Adaptive Meshing. . . . . . . . . . . . . . . . . . . . . . 1-411

INDEX I-1

LY |&217(176
1

User’s Guide and Introduction


Preface
FEMLAB 2.2
FEMLAB® was the first engineering tool for PDE-based multiphysics modeling in
an interactive environment—MATLAB®. Our goals are ambitious. We are
committed to lead the development in our field, and the new features in FEMLAB
2.2 prove this commitment. Despite its modest version number increment, version
2.2 is a major upgrade. We anticipate significant upgrades once per year for the
foreseeable future.

Version 2.2 includes three major functionality additions and three major
improvements. The three major additions are higher-order elements, the weak form,
and extended multiphysics. The three major improvements are 3D CAD and image
data import, powerful visualization tools, and automatic tuning of 3D solvers.

The higher-order elements significantly broaden the scope in the modeling process of
physics phenomena. The higher-order elements are part of the new element library,
which is designed to maintain the flexibility of equation-based modeling, while still
allowing the addition of virtually any element type. The element library is open and
extensible—you can add the element of your choice.

With the introduction of extended multiphysics and the weak form, we lay a profound
foundation for a truly unique tool for modeling in engineering and science. We are
confident that these new features will eventually prove even more useful than the
original multiphysics concept. The Model Library shows how the weak constraint
gives optimal accuracy in flux computations, and how extended multiphysics gives
you the ability to post process on the full geometry while using symmetries to
perform the computations on only a part of the geometry. The full capability of
extended multiphysics with non-local couplings on multiple geometries is
demonstrated in the thermal controller and packed bed reactor models. We are always
impressed by the ingenuity of our users and by the way they utilize FEMLAB, and I
rest assured that these inventions will be used in ways we never imagined.

CAD models in 3D can be imported in the IGES file format, the most common
standard for product geometry data. The IGES translator includes a geometry
repairing facility for increasing the quality of models. Utilities for the conversion of
2D images (JPG, GIF, TIF, BMP, etc.) and 3D MRI data to FEMLAB geometry
objects have also been added.

1-2 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
You can now easily create cross-section plots in a number of ways. Choose between
plotting the time evolution at a point or on a boundary or visualizing arbitrary
expressions on cross-sections (lines in 2D and surfaces in 3D). An object can be sliced
using the GUI and programming functions, and “probes” can be inserted anywhere
in the geometry—a virtual test lab!

The new algebraic multigrid (AMG) preconditioner provides automatic tuning of


the iterative solver parameters for large 3D models, reducing the need for manual
interaction significantly.

The specialized modules provide comfortable working environments for particular


fields of physics. They use standardized terminology, material libraries, specialized
solvers and elements, and appropriate visualization tools. They all come with their
own separate manuals and model libraries, which provide completed solutions to a
variety of field-specific problems. The Chemical Engineering Module, the
Electromagnetics Module, and the Structural Mechanics Module are available. In this
release the Electromagnetics Module has been upgraded to include 3D support and
vector elements. We planned to release the new Structural Mechanics Module with
this version, but we had to postpone this release to version 2.3.

FEMLAB 2.3, due in the summer of 2002, will include improvements mainly to the
add-on modules. Turbulence models for fluid dynamics will be included in the
Chemical Engineering Module, as well as specialized solution methods for fluid
dynamics. The new version of the Structural Mechanics Module will be fully
integrated with FEMLAB multiphysics, and it will use the element library and other
elements specific to structural mechanics: beam elements and shell elements—all in
3D. A pre-release version of the module is already available with version 2.2.

FEMLAB has been designed as a single platform for all physics-based modeling and
analysis. It is already an industry-proven engineering tool, and with the future
development that we envision, FEMLAB will grow to become the engineering
standard for multiphysics modeling.

FEMLAB 2.3
FEMLAB 2.3 features new releases of the Structural Mechanics Module, the
Chemical Engineering Module, and the Electromagnetics Module. FEMLAB 2.3
extends the versatility of the FEMLAB product line by introducing a set of new
solvers for parametric analysis, modeling of large vector field models in
electromagnetics and structural mechanics as well as transport processes in chemical

PREFACE | 1-3
engineering. It also introduces new eigenvalue solvers for large models in
eigenfrequency and eigenmode analyses.

The new Structural Mechanics Module is now fully incorporated with FEMLAB and
includes new application modes for shells, beams, and solids. In the Chemical
Engineering Module, new application modes are introduced to study
non-Newtonian fluids, compressible flow, multi-component transport, and
turbulence. Furthermore, the Electromagnetics Module includes new application
modes for optoelectronics and photonics, as well as new models in the fields of radio
frequency and microwave engineering.

The new parametric solver offers an ideal way to examine a parameterized series of
models —an important part of the multiphysics simulation procedure. The varied
parameter typically represents a material property, frequency or reaction rate. The
information obtained for one set of variables is then used for the following sets for
fast and efficient parameter sweeping.

For highly nonlinear models, parameter sweeping may also be used for smooth
convergence. The idea is to solve a series of increasingly difficult nonlinear problems.
The solution of a slightly nonlinear problem, which is easy to solve, is used as the
input to a more difficult nonlinear problem by increasing a parameter that represents
the degree of nonlinearity. In this way, very difficult nonlinear problems can be solved
without manual interaction.

The geometric multigrid (GMG) preconditioner significantly improves FEMLAB's


ability to handle large models in structural mechanics. Moreover, in chemical
engineering, this solver may be used to solve large diffusion-convection-reaction
problems.

The new iterative eigenvalue solver allows one to solve large eigenfrequency
problems in structural mechanics. It also extends FEMLAB's capabilities of handling
analysis of cavities and other resonance structures in microwave engineering and
photonics.

Enjoy!

May 5, 2002

Lars Langemyr, Vice President of Development

1-4 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
Introduction
Welcome to FEMLAB—your multiphysics solution in MATLAB®. This guide is
intended to acquaint users with the full array of multiphysics capabilities within
FEMLAB. Tutorials and examples step through FEMLAB’s powerful functions and
capabilities. You will learn how to set up a model in the FEMLAB graphical user
interface (GUI), an environment that unleashes the power of the latest modeling
techniques with the click of a mouse.

This User’s Guide and Introduction is ideal for those who want to explore specific
models as well as those who want a general overview of FEMLAB’s cutting-edge
multiphysics technology. We have structured this manual so that users can quickly
and easily learn how to access FEMLAB’s considerable power. It begins with a Quick
Start Guide (page 1-26) that examines a typical problem in a step-by-step fashion to
introduce you to FEMLAB’s wide range of features and capabilities.

This manual contains a series of in-depth tutorials that explain how to:

• initialize new models and define their parameters through the Model Navigator as
well as open prewritten models from the Model Library
• work with the FEMLAB GUI
• perform efficient modeling within the graphical interface
• enhance the capabilities of the graphical interface by working with FEMLAB
functions in programming
• perform equation-based modeling using partial differential equations (PDE).

After reviewing the material in this manual, you will be ready to start creating your
own models for your specific projects. Creating more advanced models generally
requires that you become more familiar with FEMLAB’s subtleties. For this reason,
FEMLAB’s documentation set includes several supplementary manuals. Specifically,
the Reference Manual details the package’s underlying concepts and shows how to
take full advantage of its data structures and capabilities from the MATLAB prompt.
The Model Library provides many examples from science and engineering that
illustrate how to employ FEMLAB to solve real-world problems. For your
convenience, the complete documentation can be found on your hard-drive after
installation (PDF and HTML versions). Occasionally, the electronic version is more
useful than the printed copy, such as when searching for key words.

INTRODUCTION | 1-5
What is FEMLAB?
FEMLAB is a powerful, interactive environment for modeling and solving scientific
and engineering problems based on partial differential equations [1,2]. With it you
can easily extend conventional models that address one branch of physics to
state-of-the art multiphysics models that simultaneously involve multiple branches of
science and engineering. Accessing this power, however, does not require that you
have in-depth knowledge of mathematics or numerical analysis. Indeed, you can
build many useful models simply by defining the relevant physical quantities rather
than defining the equations directly. FEMLAB then internally compiles a set of PDEs
representing the problem. FEMLAB also allows you to create equation-based
models. Besides providing these multiple modeling approaches, FEMLAB offers
multiple ways to harness this power: either through a flexible self-contained graphical
user interface or from the MATLAB prompt.

The underlying mathematical structure with which FEMLAB operates is a system of


partial differential equations. In FEMLAB you can represent PDEs in three ways:
coefficient form (suitable for linear or nearly linear problems), general form (intended
for nonlinear problems), and weak form (that works as a high-level finite element
modeling language). Furthermore, it is possible to set up models as stationary or
time-dependent, linear or nonlinear, scalar or multicomponent. The package also
performs eigenfrequency or eigenmode analyses.

When solving the PDEs that describe a model, FEMLAB applies the finite element
method (FEM). FEMLAB runs that method in conjunction with adaptive meshing
and error control as well as with a variety of numerical solvers. A more detailed
description of this mathematical and numerical foundation appears both in this
manual and in the Reference Guide.

PDEs are the fundamental basis for the laws of science, hence they can and should be
used to model scientific phenomena. FEMLAB has an extremely broad applicability,
and it can model a large number of physical phenomena in many disciplines
including:

• acoustics
• bioscience
• chemical reactions
• diffusion
• electromagnetics

1-6 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
• fluid dynamics
• fuel cells
• general physics
• geophysics
• heat transfer
• micro-electromechanical systems (MEMS)
• microwave engineering
• optics
• photonics
• porous media flow
• quantum mechanics
• radio-frequency components
• semiconductor devices
• structural mechanics
• transport phenomena
• wave propagation.

To show how FEMLAB solves familiar and interesting problems in many of these
areas, this documentation set includes a Model Library. This separate volume
contains an extensive selection of complete, ready-to-run models. Examining them is
an excellent way to learn how to work with FEMLAB and to see how it applies to
various application areas. Further, you can adapt, expand, or otherwise modify these
models to suit your own requirements. They represent a handy starting point that can
save considerable time in many instances.

Many real-world applications involve the simultaneous application of PDEs from


several areas of science or engineering. Researchers now refer to this type of analysis
as multiphysics modeling. For instance, the electrical resistance of a conductor often
varies with temperature; thus a model of a conductor carrying current involves
thermoelectric effects. This manual introduces you to FEMLAB’s unique power in
handling multiphysics (see “Forced and Free Convection Heat Transfer” on page
1-26 as well as “Thermo-Electric Heating in a Bus Bar” on page 1-109). Further, the
Model Library devotes a separate chapter to the study of several interesting
multiphysics examples.

INTRODUCTION | 1-7
Even in its base configuration FEMLAB offers enormous modeling and analytical
power for many disciplines. However, the product has proven particularly useful in
several of these areas. Thus we created optional discipline-specific application modules
that make it easy to create and analyze models using terminology and solution
methods appropriate for those disciplines. We presently offer the Chemical
Engineering Module, the Electromagnetics Module, and the Structural Mechanics
Module.

Despite all these aids, we recognize that it is impossible to anticipate every possible
application area and every user’s potential requirements. To give users the ultimate
flexibility, the FEMLAB user interface integrates seamlessly with MATLAB, the
package that provides the computational engine behind FEMLAB. Indeed,
FEMLAB frequently uses MATLAB’s syntax and data structures. An enormous
benefit of this tight integration is that you can save and export FEMLAB models as
MATLAB programs that run directly in that environment or incorporate them with
still other products in the MATLAB family. Thus you gain the freedom to combine
FEM-based modeling, simulation, and analysis with numerous other techniques in
engineering and science. For instance, it is possible to create a finite-element model
in FEMLAB and then export it to Simulink® or to the Control System Toolbox,
where the model becomes an integral part of the simulation of a dynamic system. We
refer to such applications of FEMLAB as multidisciplinary.

We are glad that you have chosen FEMLAB for your modeling needs, and we hope
that FEMLAB will perform up to your expectations. If any difficulties arise in your
FEMLAB modeling experience, please contact our support team at
support@femlab.com. Thanks again for using FEMLAB!

REFERENCES
[1] S. Littmarck, et. al., Solving differential equations, Industrial Physicist,
American Institute of Physics, Feb/Mar 2001.
URL: http://www.aip.org/tip/pastiss.html

[2] S. Littmarck, et. al., Math, models, motion and more, PT Design Magazine,
Penton Media (Cleveland, OH), May 2000.

The FEMLAB Environment


To understand the discussions in this manual, as well as other elements of the
documentation set, you need to be familiar with some basic terminology. At the
top-most level, the FEMLAB environment consists of the following parts:

1-8 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
The Graphical User Interface (GUI) In this environment you create and manipulate
models in two ways: by using one of several predefined physics modes where you work
with familiar scientific laws and relationships, or in one of the predefined PDE modes
where you work directly with a model’s underlying partial differential equations. You
can also perform multiphysics modeling by combining any of these physics modes
and PDE modes.

The physics modes designed to run under FEMLAB’s graphical interface address
common application areas such as heat conduction, electromagnetics, fluid
dynamics, and structural mechanics. Each mode, in turn, relies on a specific PDE
model for which you define commonly used parameters, variables, and their values.
Because of the predefined nature of these physics modes, you can set up a model
without the need of explicitly stating the governing PDE.

The FEMLAB GUI contains a set of geometry tools (CAD) for modeling in 1D, 2D,
and 3D, as well as tools for importing DXF and IGES files, with geometry repair. A
built-in mesh generator automatically creates the mesh for any geometry. If your
geometry is represented on an image file format or as magnetic resonance imaging
(MRI) data, you can convert this data to a FEMLAB geometry object.

Recognizing the necessity of being able to visually examine results of model


simulations, FEMLAB provides several tools that make it quick and easy to visualize
virtually any interesting quantity or parameter. Among the choices available are
surface plots, slice plots, isosurfaces, contour plots, cross-section plots, and
animations.

Extensive export facilities in the graphical interface enable you to perform


postprocessing from the MATLAB prompt using any FEMLAB or MATLAB
function. Dialog boxes guide you through the process of exporting models to other
tools in the MATLAB family, such as Simulink or the Control System Toolbox. You
can save a GUI-built model as a Model MAT-file, handled by the Model Navigator,
or a Model M-file. See below for details.

The Model Navigator This user interface tool is a multi-purpose dialog box in which
you control the overall settings of a FEMLAB session. The New page initializes
models in the various application modes, while the Multiphysics page lets you add
additional application modes to create a multiphysics model. The Model Library
page loads complete models supplied with FEMLAB. On the New page, you also
choose to create a 1D, 2D, or 3D model. On the User Models page, you can browse
your own set of saved models. If you have saved a model together with a model image

INTRODUCTION | 1-9
and a model description, you can display the model with an image and a short
description in the same way you display models on the Model Library page.

The Model Library This set of predefined models, which you can access from the
Model Navigator dialog box, is important for several reasons. It offers a quick way to
learn how to use FEMLAB’s capabilities, and it lets you inspect the results of
completed models. You can interact with a model by modifying its geometry and key
parameters, such as the values of the underlying variables. Feel free to use a model as
a starting point and save it under a different name (thus creating a copy).

Model M-files It is possible to export any model created in the graphical interface as
a Model M-file—a MATLAB script version of the model. Representing a model in
this form is convenient for documenting the work you perform in the graphical
interface or for allowing further modeling using script programming.

Script Programming and the FEMLAB Functions Operating FEMLAB as a


programming environment enables you to create and manipulate models within
MATLAB. Here you work directly with the FEMLAB data structure (known as the
FEM structure). Combining MATLAB and FEMLAB functions makes it possible to
run a series of models by varying a parameter. Also, this is a powerful tool for highly
nonstandard modeling.

The Application Program Interface (API) This library of MATLAB functions and
methods allows you to create GUI components and thus customize FEMLAB’s
graphical interface for specific applications. By building a custom interface optimized
for a specific task, you can create complete applets that shield occasional users from
unnecessary complexity yet allow them to quickly obtain results from sophisticated
analyses. You can also use the API for building parameterized models for the GUI.

Open Programming Environment The environment consisting of FEMLAB


together with MATLAB allows for using C, C++, and FORTRAN programs for
defining material properties, loads, and sources through the MATLAB API. For
information on how to call C, C++, and FORTRAN programs from FEMLAB and
MATLAB, see the MATLAB documentation on External Interfaces and API.

The FEMLAB Documentation Set


To help you take advantage of all this functionality, FEMLAB comes with an
extensive set of documentation. There are also minicourses available for

1-10 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
downloading from the web. Assistance starts with on-line help for FEMLAB
functions as well as both on-line and printed versions of all FEMLAB manuals. The
full set of printed documentation includes the following titles:

• The User’s Guide and Introduction now in your hands explains how to get started
with FEMLAB. It does so primarily by guiding you through several detailed
model examples. It also contains brief descriptions of the operation of the
graphical interface and FEMLAB functions.
• The Model Library consists of complete FEMLAB models from different areas of
science and engineering such as heat transfer, chemical engineering,
electromagnetics, structural mechanics, and fluid dynamics, as well as
equation-based models. It serves as a basis for getting a deeper knowledge of
FEMLAB modeling techniques.
• The Reference Manual is an extensive volume that contains several important
sections:
- The Reference Guide provides a detailed presentation of FEMLAB. It focuses
on the data structures and functions available from the MATLAB prompt. The
information is also necessary for advanced use of FEMLAB from the graphical
interface.
- The Graphical User Interface is a section that supplies a comprehensive
description of the GUI including a review of all dialog boxes and their options.
- The Function Reference explains the syntax and use of all FEMLAB functions
for programming. This section is extremely valuable for users running
FEMLAB from the MATLAB prompt as well as those working with Model
M-files or script programming.
• The section titled Installation Guide contains information on how to install
FEMLAB. The document also contains the FEMLAB license agreement.
• The Automatic Control manual contains detailed information about the automatic
control applications in the FEMLAB Model Library. This document is available
only in PDF format.
• The FEMLAB Application Program Interface Guide explains how to write
MATLAB functions and methods that interact with FEMLAB. This document is
available only in PDF and HTML formats.
• The FEMLAB Release Notes covers the latest news on the release. This document
is available only in PDF and HTML formats.

INTRODUCTION | 1-11
All documents are available in two electronic formats, PDF and HTML. The
electronic versions are available on your hard-drive after installation.

Optional Modules for Specific Disciplines


The Chemical Engineering Module, the Electromagnetics Module, and the
Structural Mechanics Module are specialized modules, which provide comfortable
working environments for particular fields of physics. They use standardized
terminology, material libraries, specialized solvers and elements, and appropriate
visualization tools. They all come with their own manuals and model libraries,
unique to their field.

CHEMICAL ENGINEERING MODULE


The Chemical Engineering Module provides a powerful way of modeling equipment
and processes in the field of chemical engineering. It lets you easily model mass, heat,
and momentum transport coupled to chemical reactions in 1D, 2D, or 3D. The
Chemical Engineering Module is designed for the chemical engineer in research,
design, development, and education. It is used in many areas of chemical engineering
and technology, including:

• Reaction engineering and design


• Heterogeneous catalysis
• Separation processes
• Fuel cells and industrial electrolysis
• Process control in conjunction with Simulink

The Chemical Engineering Module provides tailored interfaces and formulations for
problems involving momentum, mass and heat transport coupled with chemical
reactions. You can use these formulations while still having the full flexibility of
modeling with your own equations.

FEMLAB excels in solving systems of coupled nonlinear PDEs. These are especially
widespread in chemical engineering, where they appear in problems involving

• Heat transfer
• Mass transfer through diffusion, convection and migration
• Fluid dynamics

1-12 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
• Chemical reaction kinetics
• Varying material properties.

You can choose to model fluid flow through porous media or to characterize the flow
with the Navier-Stokes equations. Chemical reactions are easily represented by
source or sink terms in the mass and heat balances and can be of any arbitrary order.
All formulations exist for both Cartesian coordinates and axisymmetry and for
stationary and time-dependent cases.

Available application modes are:

• Momentum equations
- Navier-Stokes equations
- Darcy’s law
- The Brinkman equation
- Non-Newtonian flow
- Turbulent flow, k - ε turbulence model
- Compressible Euler flow
• Energy equations
- Heat conduction
- Heat convection and conduction
• Mass balances
- Diffusion
- Convection and diffusion
- Maxwell-Stefan convection and diffusion
- Nernst-Planck transport equations

In the field of chemical engineering, the multiphysics capabilities of FEMLAB enable


you to fully couple and simultaneously model fluid flow, mass and heat transport,
and chemical reactions.

ELECTROMAGNETICS MODULE
The Electromagnetics Module provides a unique environment for the simulation of
wave and field propagation, as well as AC-DC electromagnetics, in 2D and 3D. It
handles static, transient, and frequency-domain simulations, as well as mode analysis,
in a user-friendly graphical user interface. The Electromagnetics Module offers the
perfect foundation for modeling microwave components and photonic devices. For

INTRODUCTION | 1-13
AC-DC modeling it is a powerful tool for detailed analysis of coils, capacitors, and
electromachinery.

The Electromagnetics Module is used for component design in virtually all areas
where electromagnetic field simulations are needed:

• Power system components


• Micro-electromechanical systems (MEMS)
• Antennas
• Waveguides and cavity resonators in microwave engineering
• Optical fibers
• Photonic waveguides
• Photonic crystals
• Active devices in photonics
• Semiconductor devices

Available application modes are:

• Electrostatics
• Magnetostatics
• Low-frequency electromagnetics
• In-plane wave propagation
• Axisymmetric wave propagation
• Full 3D vector wave propagation
• Full vector mode analysis in 2D and 3D

You can use these application modes, while still having the full flexibility of modeling
using your own equations. Any material properties imaginable are supported,
including inhomogeneous and fully anisotropic materials and media with losses or
gains. Complex-valued material properties can be used in all formulations for general
time-harmonic field simulations. The multiphysics capabilities of FEMLAB enable
coupling all simulations with heat transfer, structural mechanics, and fluid flow
formulations, as well as any physical phenomena described by PDEs.

STRUCTURAL MECHANICS MODULE


The Structural Mechanics Module solves problems in the structural mechanics field
of engineering, adding special structural mechanics elements: beams, plates, and

1-14 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
shells, for different engineering simplifications. Like all discipline-specific modules,
it provides a set of prewritten library models.

Available application modes are:

• Plane stress
• Plane strain
• Axisymmetry, stress-strain
• Axisymmetry, heat transfer
• 2D beams, Euler theory
• Thick plates, Mindlin theory
• 3D beams, Euler theory
• 3D solids
• Shells

The analysis capabilities are static, eigenfrequency, transient, and frequency response.
Both linear and nonlinear material models are supported.

The application modes are fully multiphysics enabled making it possible to couple
with any other physics application mode in FEMLAB or the other modules.
Coupling with temperature is one example of multiphysics easily implemented with
the Structural Mechanics Module.

The underlying equations for structural mechanics are available in several of the
application modes—a feature unique to FEMLAB. This makes non-standard
modeling close at hand. You can change material models from isotropic to
orthotropic. The Structural Mechanics Module also features an extended material
library as well as a beam cross section library.

In addition, you can include accurate finite element models as blocks in a dynamic
simulation set-up with Simulink. This combination reduces the need for
approximations and ad hoc models in Simulink simulations. FEMLAB’s tight
integration into the MATLAB environment makes the Structural Mechanics Module
very versatile. For instance, you can use any valid MATLAB expression to describe
loads and constraints. The possibility to save the model as a Model M-file makes it
very easy to perform complex parameter studies.

INTRODUCTION | 1-15
Installing FEMLAB
For information on how to install FEMLAB, see the separate booklet titled
Installation Guide. In that manual you can also find information on system
requirements and the license agreement. The release notes for FEMLAB 2.3 are
available on the CD and on your hard drive after installation.

New Features in FEMLAB 2.2


The major new capabilities in FEMLAB 2.2 are:

HIGHER-ORDER ELEMENTS
The unique equation-based modeling in FEMLAB has taken another step:
Higher-order elements give extreme flexibility in the process of modeling physics
phenomena. You can easily combine elements of different type and order.
User-defined elements can be added to the element library.

EXTENDED MULTIPHYSICS
FEMLAB now supports extended multiphysics modeling for simultaneous
simulation of several physics models. You can now model the interaction between
geometrical domains of different dimensions: 0D, 1D, 2D, 3D plus time, for
example, by integrating a solution on one domain and using it as a material property
in another. This enables true engineering solutions to complex problems, previously
beyond reach for simulation. Automatic Jacobian computation for non-local
couplings is supported. You can access dependent variables non-locally, and you can
define scalar coupling variables by coordinate values or integration and coupling field
variables by projection or extrusion.

3D CAD FILE IMPORT


CAD import for 3D models is now available, with geometry repair on industrial
quality solid models. FEMLAB 2.2 supports the most common format, IGES, for
CAD import.

IMAGE AND MRI IMPORT


The new release combines the power of image processing and visualization built into
MATLAB with the multiphysics and FEM capabilities of FEMLAB in that images
and MRI data can now be imported. Images and MRI data are converted to
FEMLAB geometry objects and can then be used for analysis as any other geometry
model.

1-16 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
CROSS-SECTION VISUALIZATION
Visualize postprocessing expressions of the solution and its gradient on cross sections
by defining slicing planes in the graphical user interface. You can also visualize the
dynamic behavior of a model by plotting the time evolution of the solution on a
cross-section or at any location inside the model.

THE WEAK FORM


As the first simulation environment in the history of numerical computing,
FEMLAB 2.2 introduces a high-level modeling language that makes it possible to
model all types of finite element analysis problems by introducing “the weak form”.
The weak form is at the heart of the finite element method, and it gives you complete
control of the finite element model.

This functionality makes it possible to compute fluxes and other flux-related


quantities with maximum accuracy. Some examples of flux-related quantities are
reaction forces in structural mechanics and surface charges and surface currents in
electromagnetics.

AUTOMATIC TUNING OF SOLVER PARAMETERS FOR LARGE MODELS


A new solver for large 3D models makes manual tuning of solver parameters
unnecessary. The algebraic multigrid preconditioner (AMG) implements
state-of-the-art numerics for higher performance and less memory usage.

MISCELLANEOUS
• Point and edge constraints and sources in 3D
• Point constraints and sources in 2D
• Define variables as symbolic expressions; variables can be differently defined on
different domains
• Use space derivatives in boundary conditions
• Use time derivatives in Neumann boundary conditions
• Define a system of ODEs on a boundary, and couple this system to the PDE
boundary conditions
• Fifth order Argyris element in 2D

New Features in FEMLAB 2.3


The major new capabilities in FEMLAB 2.3 are:

INTRODUCTION | 1-17
PARAMETRIC SOLVER
For examining the influence of different parameters that describe a model or
simulation. the new parametric solver offers an ideal way to study a parameterized
series of models. The varied parameter typically represents a material property,
frequency or reaction rate. The information obtained for one set of variables is then
used for the following sets for fast and efficient parameter sweeping.

For highly nonlinear models, parameter sweeping may also be used for smooth
convergence. The idea is to solve a series of increasingly difficult nonlinear problems.
The solution of a slightly nonlinear problem, which is easy to solve, is used as the
input to a more difficult nonlinear problem by increasing a parameter that represents
the degree of nonlinearity. In this way, very difficult nonlinear problems can be solved
without manual interaction.

GEOMETRIC MULTIGRID (GMG) PRECONDITIONER


The new geometric multigrid (GMG) preconditioner is applicable to a range of
problem types commonly known as elliptic PDE problems. This problem class
contains structural mechanics problems, different kinds of diffusion problems, and
problems including PDEs similar to Poisson’s equation. The GMG preconditioner
significantly improves FEMLAB's ability to handle large models in structural
mechanics. Moreover, in chemical engineering, this solver may be used to solve large
diffusion-convection-reaction problems.

ITERATIVE EIGENVALUE SOLVER


A new iterative eigenvalue solver is available that is based on the standard FEMLAB
preconditioners and iterative solvers. It allows you to solve large eigenfrequency
problems in structural mechanics. It also extends FEMLAB's capabilities of handling
analysis of cavities and other resonance structures in microwave engineering and
photonics.

A U T O M AT IC S C A L I N G O F VA R I A L BL E S
If the dependent variables in your model has widely different magnitudes, a solver
might have problem with the resulting ill-conditioning. For instance, in a structural
mechanics problem, the displacements can be of the order of 0.0001 m, while the
stresses are 1000000 Pa. To remedy this, FEMLAB 2.3 provides automatic internal
rescaling of the variables so that a well-scaled system results. You can access the
scaling properties from the graphical user interface and provide the automatic scaling
mechanism with additional information on scaling known from the physical
properties of the problem at hand.

1-18 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
MISCELLANEOUS
FEMLAB 2.3 additionally includes the following features:

Associative Geometry in 1D
FEMLAB features heuristic rules for keeping PDE and boundary conditions as
changes are made to the geometry. This feature is called associative geometry and is
supported in 2D and 3D since earlier versions of FEMLAB. In FEMLAB 2.3, the
associative geometry feature is made available in all dimensions by the addition of
associative geometry rules for 1D problems.

Line Plots in 3D
Line plots are now supported i 3D. This feature has been available in 2D since earlier
versions.

Explicit Streamline Diffusion in the Navier-Stokes Application Modes


The Navier-Stokes application modes now features explicit streamline diffusion.
Earlier versions of FEMLAB supported automatic streamline diffusion. This feature
is still available and is now complemented by an explicit version. The explicit
streamline diffusion feature makes the additional weak terms corresponding to the
modified test functions available in the GUI. Thus, you can now manually inspect
and modify the streamline diffusion contributions.

New Elements
Hermite elements are now available. The Hermite and Argyris element types are now
available in the graphical user interface.

New Features in Chemical Engineering Module 2.1

NEW APPLICATION MODES


There is one new application mode: mass balance for multicomponent simulations.

NEW MODELS
• MEMS heat exchanger
• Packed bed reactor

MISCELLANEOUS
• The number of customized postprocessingprocessing variables has been increased
significantly.

INTRODUCTION | 1-19
New Features in Chemical Engineering Module 2.3

NEW APPLICATION MODES


The new application modes are:

• Non-Newtonian fluids: Fluid flow studies can now be easily performed using the
new application mode for non-Newtonian fluids, suitable for treating different
types of shear-thickening and shear-thinning problems. This new application
mode can be applied in the modeling of flow in polymer and fiber suspensions,
pastes, etc.
• Compressible flow: Euler models are now available for the simulation of gas flow
at high flow rates.
• Incompressible turbulent flow: A new k - ε turbulence model is now available as a
ready-to-use application mode.
• Maxwell-Stefan diffusion: In studies regarding transport of diluted species in a
carrier gas, Fickean diffusion accounts for the interaction between the dissolved
species and the dominating solvent gas. When all species are present in a
comparable amount, the interactions between all the involved species must be
accounted for. This is addressed in the Chemical Engineering Module by the new
Maxwell-Stefan application mode, which also include the combination of arbitrary
reaction kinetics, momentum and heat transport. This feature allows for the
modeling of gas phase reactors, separators, and filtration units.
• Nernst-Planck application modes: In applications regarding the mass transport of
charged species, migration in an electrical field gives a considerable contribution
to the flux. Hence, two new application modes in the Chemical Engineering
Module ensure that the proper description of electro-kinetic fluid transport and
transport in electrochemical cells are available in ready-to-use formulations. This
considerably simplifies the task of modeling transport in MEMS devices, fuel cells,
and batteries.

NEW MODELS
The Chemical Engineering Model Library features several new models:

• A model of the non-Newtonian flow of a polymer solution in a valve. The model


shows on large variations in viscosity as a function of position and shear rate in the
flow.
• A study of the flow in an open channel with porous walls, where the flow in the
channels and in the porous media are fully coupled. The problem is typical for

1-20 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
monolithic reactors, filters, and other devices where the convective flow in the
porous media cannot be neglected.
• New k-ε models including jets, a static mixer, and the classical backwards-facing
step. Logarithmic wall functions are used as boundary conditions for the solid
walls.
• Compressible flow at supersonic speed and in the presence of shock waves is
modeled using the compressible Euler equations. The model treats the supersonic
flow in a channel with a solid obstacle in the middle of the channel.

• The use of the new parametric solver is exemplified in a model of heat transport
around a heated tube at different flow rates of the streaming fluid. The model
shows the influence of detachment of the viscous layer on the temperature profile
in the fluid.
• A new model of a fuel cell cathode presents the application of the multicomponent
diffusion. The application mode is based on the Maxwell-Stefan diffusion and
shows on the dependence of the binary diffusion coefficient on composition.
• The transport by diffusion and migration of ionic species in electrochemical cells
is studied. The model treats the electrolysis of tumors where tumor destruction is
achieved through acidification and chlorine production.
• A new model of electrokinetic flow in a DNA chip is presented. The
electroosmotic flow is driven by the electric field and the deviations from
electroneutrality at the walls of the channel. The model couples fluid flow and
ionic current conduction in the chip.
• The exothermic reactions in a fixed-bed tubular reactor is investigated through the
definition of coupled heat and mass balances. The production of phthalic
anhydride is highly dependent on the temperature distribution in the reactor.

New Features in Electromagnetics Module 2.0

NEW APPLICATION MODES


There are four new application modes:

• 3D Electrostatics application mode for conductors, capacitors, and other types of


voltage driven static problems
• 3D Magnetostatics application mode for permanent magnets, inductors, and
other types of static magnetic problems

INTRODUCTION | 1-21
• 3D Quasi-Statics application mode for low frequency phenomena in
electromagnetics, such as transformers and electromachinery
• 3D Electromagnetic Waves application mode for high frequency phenomena in
electromagnetics, such as waveguides and optical fibers

ELEMENTS
• Element library with Lagrange elements of arbitrary order enabling higher
accuracy
• Vector elements for 3D electromagnetic wave modeling: The vector elements
ensure that the correct interface conditions are fulfilled at borders between
different media.

NEW MODELS
• 3D MEMS capacitor
• 3D MEMS inductor
• Quasi-static 3D model of a crucible
• 3D waveguide including an S-parameter analysis
• Waveguide in a photonic crystal
• Step-index fiber
• Photonic micro prism model using absorbing layers
• T-junction waveguide model enhanced with an S parameter analysis

MISCELLANEOUS
• Multiphysics with non-local couplings for multiple geometry modeling
• Domain dependent variables
• Material library for user-defined materials
• Cross-section plots

New Features in Electromagnetics Module 2.3

NEW APPLICATION MODES


The new features related to application modes are:

• A new 2D application mode for mode computations of hybrid-mode waves is now


available. The application mode has general support for anisotropic media and is
applied to problems in photonics, optics, and microwave waveguides.

1-22 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
• Impedance boundary conditions have been added to the 3D quasi-statics
application mode. This lets you model induced currents as surface currents along
the boundaries, which makes it possible to work with higher frequencies.

NEW MODELS
The following models have been added to the Model Library:

• A model of a monoconical RF antenna with a study of the antenna impedance and


the radiation pattern. Conical antennas are useful for many applications due to
their broadband characteristics and relative simplicity. The rotational symmetry
allows for using one of the axisymmetric electromagnetic wave propagation
application modes. When modeling in 2D, a denser mesh can be used which gives
excellent accuracy for a wide range of frequencies.
• A magnetostatic model using Maxwell’s stress tensor to calculate the force on two
parallel wires. This model illustrates the use of boundary integrals to compute the
resultant force on current conductors. A comparison with the volume integral of
the force density is made.
• A 3D model using showing how a scalar magnetic potential can be used to
efficiently solve magnetostatic problems for permanent magnets. This model also
uses Maxwell’s stress tensor for force calculations.
• Two models calculating stress-induced birefringence in a photonic waveguide. The
simulation is set up as a multiphysics problem coupling a plane strain equation
with a optical mode analysis. One of the models uses a generalized form of the
plane strain equation, which takes the strain if all three directions into account.
• The S-parameter analysis in the elliptical to rectangular waveguide transition
model, as well as in the T-junction waveguide model is remade using the new
parametric solver.

MISCELLANEOUS
• A “matched boundary” condition has been added to the wave application modes,
which are exactly non-reflecting for eigenmodes of the boundary.
• A new chapter on force calculations has been added to the manual.

INTRODUCTION | 1-23
New Features in Structural Mechanics Module 2.3

NEW APPLICATION MODES


There are three new application modes.

• 3D solids
• 3D Euler beams
• Shells

ELEMENTS
• Element library with Lagrange elements of arbitrary order enabling higher
accuracy
• Beam, bar, and shell elements in 3D

NEW MODELS
• 3D tower, Euler beam model
• Static analysis of a socket to a guyed mat
• 2D beam benchmark problem
• Axisymmetry piston model, transient coupling with temperature
• Steel aluminum component, coupling with temperature
• Pressure vessel modeled using shell elements
• Eigenfrequency analysis of a rotor in an electric motor
• Parameter analysis of a tube connection with prestressed bolts
• Vibration of a disk backed by an air-filled cylinder

MISCELLANEOUS
• Fully multiphysics enabled applications in 2D and 3D
• Domain dependent variables
• Cross-section plots
• Easy thermal coupling with arbitrary temperature field
• New design of the material library; simplifies and extends its use
• Possibility to use integrals in the problem definition
• General parametric solver

1-24 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
• Possibility to reuse inputs when specifying your problem
• Improved contact problem handling using non local coupling and nonlinear
boundary conditions

INTRODUCTION | 1-25
The FEMLAB Q ui ck Start Gui de
The goal of this section is to familiarize you with the FEMLAB environment,
focusing primarily on how to use its graphical user interface. To facilitate a quick
introduction, the following model will examine steps necessary to setup and evaluate
a simple project, and review the major tasks of the modeling process.

Forced and Free Convection Heat Transfer

MODEL BACKGROUND
This example describes a fluid flow problem with heat transfer in the fluid. An array
of heating tubes is submerged in a vessel with fluid flow entering at the bottom. The
figure below depicts the setup.

Fluid flow
direction

Heating tubes

A first consideration when modeling should always be the true dimension of the
problem. Many problems do not show variations in three dimensions and can be
extrapolated from the solution of a related 2D case. Assuming any end effects from
the walls of the vessel can be neglected, the solution can be assumed constant in the

1-26 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
direction of the heating tubes, and the model is therefore reduced to a 2D domain
(below).

The next consideration is finding symmetries. In this case, inclusion of symmetry


planes allows you to model only the thin domain indicated in the figure.

GOVERNING EQUATIONS
This is a multiphysics model, meaning that it involves more than one kind of physics.
In this case, you have Incompressible Navier-Stokes equations from fluid dynamics
together with a heat transfer equation, that is, essentially a convection-diffusion
equation. There are four unknown field variables: the velocity field components u
and v; the pressure, p, and the temperature, T. They are all interrelated through
bidirectional multiphysics couplings.

The pure Incompressible Navier-Stokes equations consist of a momentum balance (a


vector equation) and a mass conservation and incompressibility condition. The
equations are

 ∂u 2
 ρ + ρ ( u ⋅ ∇ )u = – ∇ p + η ∇ u + F
 ∂ t
 ∇⋅u = 0

THE FEMLAB QUICK START GUIDE | 1-27


where F is a volume force, ρ the fluid density and η the dynamic viscosity. We denote
the vector differential operator by ∇ (pronounced “del”). See further “Overview of
PDE Models” on page 1-336.

The heat equation is an energy conservation equation, that says only that the change
in energy is equal to the heat source minus the divergence of the diffusive heat flux.
∂T
ρc p + ∇ ⋅ ( – k∇T + ρc p Tu ) = Q
∂t

where cp is the heat capacity of the fluid, and ρ is fluid density as before. The
expression within the brackets is the heat flux vector, and Q represents a source term.
The heat flux vector contains a diffusive and a convective term, where the latter is
proportional to the velocity field u.

In this model, the above equations are coupled through the F and Q terms. First, add
free convection to the momentum balance with the Boussinesq approximation. In
this approximation, variations in density with temperature are ignored, except
insofar as they give rise to a buoyancy force lifting the fluid. This force will be put in
the F-term in the Navier-Stokes equations. See further “Marangoni Convection” on
page 2-321 in the Model Library.

At the same time, the velocity field must be accounted for in the Heat equation.
Instead of applying the heat equation as it stands, you can put the divergence of the
convective heat flux into the Q coefficient, using the fact that the velocity field is
divergence free. This puts the equation on a form that can be used in FEMLAB’s
Heat transfer application mode.

SETTING UP THE MODEL IN FEMLAB


Let’s begin the modeling process.

• To do so on any platform, type the following entry into the MATLAB command
window:
femlab

1-28 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
This command starts FEMLAB and opens the Model Navigator. On a Windows PC
you can also begin a FEMLAB session from the Start menu.

The Model Navigator is a multi-purpose dialog box in which you control the general
settings of a FEMLAB session. You can find detailed information about the options
in the section “The Model Navigator” on page 1-63 in this book. For now, let us
focus on one of its five tabbed pages: the Multiphysics page lets you select application
modes, dimension and other settings for your multiphysics model. The Model Library
page loads complete models supplied with FEMLAB.

Note A complete version of this model can be found on the Model Library page
under FEMLAB/Multiphysics/free_convection.

• Go to the Multiphysics page, and check that the 2D radio button is selected. The
space dimension must always be selected first, as the Physics modes available differ.
• Select the Incompressible Navier-Stokes application mode in the list on the left. As
you can see, the default Application mode name is ns, and the default names of the
Dependent variables are, u, v and p. These names can be changed, for example, if
they conflict with variables in other application modes. The default finite elements

THE FEMLAB QUICK START GUIDE | 1-29


for the Incompressible Navier-Stokes application mode are mixed second and first
order triangular Lagrange elements, so called Lagrange - p2-p1 elements.
• Press the right arrow symbol (>>) in the center of the page. This accepts the
settings in the Application mode name, Dependent variables and Element fields, and
transfers the Incompressible Navier-Stokes mode to the list of active modes on the
right.
• Then select the Heat transfer application mode from the list of available modes.
Accept the default variable name, T, and elements—second order Lagrange
elements—by again pressing the right arrow button.

• Press OK to confirm your choices and close the Model Navigator.

1-30 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
At this point, the graphical interface opens up in the Heat transfer application mode.
You can always find out in which application mode the package is presently running
because its name appears on the bar at the very top of the FEMLAB window.

Note Because FEMLAB runs within the MATLAB environment, you always have
access to the MATLAB Command Window except when certain modal dialog boxes
are open. When referring to the prompt in MATLAB’s Command Window, this
documentation set uses the term “MATLAB prompt”.

Options and Settings


Later in this model you’ll need the physical properties of the fluid (water), the
temperatures at the inlet and on the surface of the heating tubes, and the inlet
velocity. This data can be entered as constants in the Add/Edit Constants dialog box.
The values used in this model are all given in SI units.

• Select the Options menu at the top of the FEMLAB window and choose Add/Edit
Constants.
• First add the density of the fluid: Enter rho0 in the Name of constant field. Press
page to move the cursor to the Expression field and enter 1e3. The value is saved
when you press enter, push the Set button, or otherwise leave the Expression field.
• Go on adding the dynamic viscosity, mu=1e-3; the heat capacity, cp=4.2e3; the
thermal conductivity, kc=0.6; and the volume expansion coefficient,

THE FEMLAB QUICK START GUIDE | 1-31


alpha0=0.18e-3. Then enter the acceleration of gravity, g0=9.8, and the inlet
velocity, v0=5e-3.

• Finally add the temperature at the inlet and on the heaters, T0=293 and T1=303,
respectively, and press OK.

The model size is in the order of a few centimeters, while the area visible in the
graphical interface is in the order of meters (remember you’re modeling in SI units).
Before you start drawing the geometry, you therefore have to change the size of the
visible drawing area and the grid spacing.

• On the menu bar at the top of the screen select the Options menu, and from the
drop-down choices choose Axes/Grid Settings...

• A dialog box opens up, and on the Axis page enter -0.01, 0.01, -0.01, and 0.05
as X min, X max, Y min, and Y max, respectively.

1-32 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
• Click the page for the Grid page and deselect the Auto check box. Enter 0.005 as
both X spacing and Y spacing.

• Press OK to close the dialog box and to apply the settings.

Draw Mode
Your next task is to draw the model’s geometry. This is easy, involving only the
rectangle and circle primitives, and subtracting one from the other.

• First draw a rectangle of width 0.005 and height 0.04, with the lower left corner
at the origin: Press the Draw Rectangle draw toolbar button. It is the first button
on the draw toolbar, which is located on the left side of the drawing area. Then
click at (0,0), using the left mouse button, and drag the mouse—keeping the
button down—to (0.005,0.04). Release the button.

• Next, draw a circle with radius 0.005 centered at (0,0.015): Press the fourth
button on the draw toolbar, Draw Centered Ellipse. Then, using the right mouse
button, click at (0,0.015) and drag the mouse in any direction, keeping the button
down, until the circle has a radius of 0.005. Using the right mouse button ensures
that a circle, and not an ellipse, is drawn.

THE FEMLAB QUICK START GUIDE | 1-33


• The desired radius of the circle is, however, not 0.005, but 0.0025. To fix this,
double click the circle to open the Object Properties dialog box. Enter 0.0025 as
Radius and press OK.

• Select both the circle and the rectangle. Either you can draw a rubber band box
around both them, or you simply press Ctrl-a to quickly select all objects.

1-34 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
• Press the Difference button on the draw toolbar and then the Zoom Extents button
on the main toolbar. The last button modifies the axes settings so that everything
fits nicely into the drawing area.

Boundary Mode
Now that the geometry is ready, you can start defining your physics. The boundary
conditions and equation coefficients are set independently for the two application
modes. First, set the boundary condition for the Heat transfer mode, and then for the
Incompressible Navier-Stokes mode.

• Choose Boundary Settings... from the Boundary menu. This opens the Boundary
Setting dialog box, and transfers FEMLAB to boundary mode. The dialog box has
different options in different application modes.
• Start by insulating all boundaries. Select all boundaries in the Domain selection list
by selecting number 1 in the list on the left side of the Boundary Settings dialog
box and then number 7 holding the Shift key pressed. Now, insulate all boundaries
by clicking the Insulation/symmetry radio button. For more information on how to
select more than one object in the user interface, see “Object Selection Methods in
2D” on page 1-80 in this book.
• Select the inflow boundary by clicking at the corresponding edge in the geometry,
or by selecting boundary number 2 in the list. Click the Temperature radio button
and change the Temperature field to read T0.

THE FEMLAB QUICK START GUIDE | 1-35


• Select boundaries 6 and 7, that is, the heater, and set the Temperature field to T1.

• Press Apply, to confirm the settings for the Heat transfer application mode. Then
switch to Incompressible Navier-Stokes, by selecting this mode from the bottom
of the Multiphysics menu. The appearance of the dialog box changes to reflect the
new mode.
• Again, start by selecting all boundaries and click the Slip/symmetry condition.
• For the inflow boundary, select boundary 2, click the first radio button and set
Inflow, y velocity to v0. Let the x velocity be 0.

• Continue by selecting the outflow boundary, boundary number 4, and click the
Outflow/pressure radio button. Leave the pressure, p, at 0.
• Finally, select boundaries 6 and 7 and click the No-slip condition. Press OK to
confirm your choises and close the dialog box.

1-36 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
Subdomain Mode
The coefficients in the governing equations can be interpreted, depending on the
application mode, as, for example, material properties, forces and sources. You
specify all of them in subdomain mode. This time, start with the Incompressible
Navier-Stokes application mode, and continue on to the Heat transfer mode.

• Choose Subdomain Settings from the Subdomain menu to open the Subdomain
Settings dialog box, and put the user interface in subdomain mode.
• Select the single subdomain, number 1, and use the already defined constants to
set the density and the viscosity. Enter rho0 and mu in the Density and Dynamic
viscosity fields, respectively.

• The effect of temperature on the density of the fluid is entered only as a buoyancy
force in the y direction. Set the Volume force, y-dir. field to
alpha0*g0*rho0*(T-T0). Remember that T is the dependent variable from the
Heat transfer application mode.

Initial values are also set in the Subdomain Settings dialog box. The Navier-Stokes
equations are nonlinear, and therefore benefit from an educated guess as initial
solution to the nonlinear solver. Sometimes, a good initial value is even necessary for

THE FEMLAB QUICK START GUIDE | 1-37


convergence. The initial values are also used as initial condition for the
time-dependent solver.

• Click the Init page in the Subdomain Settings dialog box to switch to the Init page.
Set the initial value V(t0) to v0.

• Press Apply to confirm the settings and use the Multiphysics menu to switch to the
Heat transfer application mode. The open dialog box returns automatically to the
Coefficients page, but now for Heat transfer mode.

1-38 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
• Set the Density, Heat capacity and Thermal conductivity to rho0, cp and kc,
respectively.
• There is no distributed heat source in this model, but the convective transport of
heat acts as one. To account for the divergence of the convective heat flux, the term
-cp*rho0*(Tx*u+Ty*v) should be entered into the Heat source field.

Tx and Ty in the above expression are the partial space derivatives of the temperature,
T. As you can see, not only the dependent variables, but also their derivatives, are
available when entering, for example, nonlinear material properties and source terms.
In fact, you can use any valid MATLAB expression containing, for example, the
dependent variables, any user defined constants and expressions, the space
coordinates, x, y and z, and time, t.

• The temperature also needs an initial value: Go to the Init page and enter T0 in the
T(t0) field. Then press OK to confirm all settings and close the dialog box.

Mesh Mode
Because FEMLAB is based on the finite element method (FEM), it needs a
subdivision of the geometry known as a mesh. A standard mesh is created
automatically, as soon as you enter mesh mode. If you need a different mesh
resolution, or require the mesh to be denser in some parts of the geometry than in
others, you can work with the Mesh Parameters dialog box, accessible from the Mesh
menu.

If you, on the other hand, trust the default settings, you can proceed directly to
solving the model. A mesh is then created automatically when you press the Solve

THE FEMLAB QUICK START GUIDE | 1-39


Problem button. It is, however, often preferable to inspect the mesh before solving,
as that can give you a hint as to how long time it will take to solve.

• Initialize the default mesh by pressing either the Initialize Mesh button or the Mesh
Mode button, both on the main toolbar. Both in this case have the same effect.

As you can see, a rather coarse mesh has been created. This means that you can obtain
a first solution quickly, to check that your model has been entered correctly into the
program. Later, you can return to mesh mode to refine the mesh. If solving again
using a finer mesh gives the same result, you can be assured that the mesh resolution
is sufficient, otherwise you’ll have to refine the mesh again.

1-40 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
Solving
The required nonlinear solver is default, so all you have to do is press the Solve
Problem button on the main toolbar.

• Press the Solve Problem button. Solving this problem takes 19 seconds on a
1.5-GHz Pentium 4 machine running Windows 2000.

As soon as the solution is ready, a default plot is displayed. In this case you’ll get a
surface plot of the temperature. If you do not get a similar plot, go back and check
the boundary conditions and subdomain settings.

Post Mode
In post mode, you can, for example, add additional plot types, and set parameters for
the different plots. The postprocessing utilities can visualize any valid MATLAB
expression, containing, for example, the solution variables, their derivatives and the
space coordinates. Many frequently used expressions are predefined as postprocessing
variables, directly available from drop-down lists in the Plot Parameters dialog box.

THE FEMLAB QUICK START GUIDE | 1-41


• Press the Plot Parameters button on the main toolbar. This opens the Plot
Parameters dialog box on the general page.

On the General page, you can, for example, choose Plot type and Element refinement
level. The latter property decides how many times the FEM mesh is refined for
visualization purposes. A higher level of refinement gives a smoother plot when using
higher-order elements, but you pay in increasing memory usage. In 2D, you can
normally increase the refinement level, compared to the Auto setting, to get a better
looking plot. In 3D, on the other hand, you might need to decrease the refinement
in order not to run out of memory.

• Select plot types Surface and Arrow by clicking the corresponding check boxes.

1-42 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
• Click the Arrow page and select x velocity (u) and y velocity (v) in the X
expression and Y expression drop-down lists, respectively.

• Finally, set X spacing and Y spacing to 10 and 15 respectively, and choose a suitable
arrow color, preferably grey. Press OK.

Without heating, one would expect an exit y-velocity that is slightly lower towards
the left side, behind the heating tube (wake-effect). However, in this case you see that

THE FEMLAB QUICK START GUIDE | 1-43


the y-velocity is higher on the left. This is because of the buoyancy effect of the free
convection.

Advanced Postprocessing
In FEMLAB, it’s very simple to obtain separate plots of the solution on various
geometry cross sections. The easiest way is to use the Draw Line for Cross-Section Line
Plot button, the second to last button at the bottom of the draw toolbar.

• To show the temperature profile just downstream of the heater, first press the Draw
Line for Cross-Section Line Plot button.
• Point the mouse at (0,0.02); press the left mouse button; drag the mouse to
(0.005,0.02) and release the button. The desired plot appears automatically in a
separate MATLAB window.
Leave the window open, as you’ll need it further on. Separate figure windows opened
by FEMLAB can be handled just like any other MATLAB figures. You can, for
example, use the tools on the figure’s toolbar to add text, and then print or save the
result in any format supported by MATLAB’s print command. Type help print
at the prompt, or see the MATLAB documentation, for more information on
printing.

Checking for Convergence


It is important to check that the solution obtained is indeed close to the best solution
obtainable from the given mathematical model and discretization scheme, and

1-44 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
thereby hopefully close to the “true” solution. This you can do by simply refining the
mesh, solving again, and comparing the solutions.

• Press the Refine Mesh button in the main toolbar. This gives you a uniform
refinement of the mesh, meaning that every triangle is split into four.
• To obtain the new solution, press the Restart button, also on the main toolbar.
When you press the Restart button instead of the Solve Problem button, the last
solution is used as initial data for the nonlinear solver. As the solution isn’t
expected to change much, convergence is fast.

Visually, the solution hardly changes at all. To verify that this is indeed the case, you
can plot the same cross section as above in the same window. But, first you have to
tell MATLAB to draw on top of the existing plot, instead of deleting it.

• Go to the MATLAB prompt and write


figure(1)
hold on

The first line activates the figure containing the cross section, and the second tells
MATLAB to overprint, rather than delete, any existing graphics. Note that if you
have other figure windows opened the number of the figure window, here
assumed to be 1, might need to be changed.

THE FEMLAB QUICK START GUIDE | 1-45


This time, you can use the Cross-Section Plot Parameters dialog box to change the line
color of the cross-section plot. Using this dialog box also ensures that exactly the
same cross section is plotted.

• Open the Cross-Section Plot Parameters dialog box by choosing Cross-Section Plot
Parameters... from the Post menu.

• Click the Line tab to reach the Line page, and then press the Line Settings... button.

1-46 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
• Change the Line color to red, selecting from the drop-down list in the Line Settings
dialog box.

• Press OK twice to close both dialog boxes and display the new temperature profile
as a red line.

As you can see, the temperature profile from the solution on the refined mesh lies
almost on top of the profile for the coarser mesh. Therefore, you can conclude that
even the coarser mesh probably gives sufficient accuracy.

Integrating to Find the Mean Temperature


Since both the velocity and the temperature vary along the outlet at the top, advanced
postprocessing must be employed to get the mean exit temperature. The bulk
temperature, or the “cup mixing temperature” is the temperature that the fluid has if
it is collected in a cup at the outflow and properly mixed. For this 2D example, the

THE FEMLAB QUICK START GUIDE | 1-47


cup mixing temperature is given by the following expression on boundary 4 (the
outlet):


Tv dx
〈 T〉 = -----------------

v dx

• To obtain the numerator, select Boundary integration from the Post menu, select
boundary 4, and type T*v in the Expression field.

• Click the Export result to workspace check box and press Apply. The numerator is
now present in the MATLAB workspace as a variable called ans. The ans variable
always contains the result of the last calculation.

• Save the numerator for later use by typing


Itv = ans

at the MATLAB prompt.

• To obtain the denominator, type v in the Expression field in the Boundary


Integration dialog box and press OK.

• Finally, save also the denominator under a different name, and calculate the cup
mixing temperature. Write
Iv = ans
Tmean = Itv/Iv

at the prompt. The result is displayed immediately.

You should get a mean temperature of 293.8 K, that is, a temperature rise of
approximately 0.8 K between inlet and outlet.

1-48 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
Saving
• To save the model to a file, go to the File menu on the menu bar at the top, then
select Save As and Model MAT-file. This selection saves the model in a binary format
with the extension .mat, a format you can load directly into the graphical
interface.

It is also possible to save the model as a MATLAB script file for parameterized
models and optimal design by selecting Save As and Model M-file…. A complete
description of the Model M-file concept appears in this book in the section “Model
M-files” on page 1-51. Use the Model MAT-file format to save entire FEMLAB
sessions if you intend to resume the modeling later on.

Boundary and PDE Coefficient Views


As you might have noticed, this model doesn’t require you to handle a PDE directly.
When modeling in a physics application mode, such as the Heat transfer mode or the
Incompressible Navier-Stokes mode in this example, you can reach the underlying
PDE formulation by selecting View as Boundary Coefficients and View as PDE
Coefficients from the Boundary and Subdomain menus, respectively. Say, for instance,
you’d like to view the PDE coefficients corresponding to the material settings:

• Go to the Subdomain menu and choose View as PDE Coefficients. Then return to the
same dropdown menu and open the Subdomain Settings dialog box.

The underlying equation appears in the upper left corner, and the edit fields to the
right now correspond to equation coefficients rather than material properties. The
interpretation of the coefficients depend on whether FEMLAB currently uses the
coefficient form or the general form to describe a generic PDE. See “Overview of PDE

THE FEMLAB QUICK START GUIDE | 1-49


Models” on page 1-336 in this manual. Multiphysics problems should normally be
based on the general form, and it’s this formulation that you can see at the top of the
dialog box.

For a multiphysics model, the coefficient view shows the complete system of
equations. It is important to understand that FEMLAB solves multiphysics problems
directly as one PDE system. In general form, the stiffness matrix or Jacobian of the
complete system is obtained automatically through symbolic differentiation. The
result of this automatic manipulation can be seen on the c, a, al and be tabs.

Let us have a closer look at, for example, the β coefficient. In this case β is obtained
through automatic differentiation of the F coefficient. β is usually identified as a
convection coefficient and then contains a transport field.

• Click the be tab to show the convection coefficient. Each field contains a
MATLAB vector of length two, making β in this case a four-by-four-by-two tensor.

Look at the coefficient in the lower right edit field, cp*rho0*u cp*rho0*v. This is
the transport field for heat transport in the fourth equation, the heat equation. As you
can see, the transport field is the fluid velocity field multiplied by the specific heat per
unit volume.

In Coefficient View, you’ve also now got an extra tab, named Weak, where you can
specify additional terms to your equations on weak form. Weak coefficients can be
added on all levels—subdomain, boundary, edge and point—where they can be used
to implement, for example, explicit streamline diffusion, weak constraints, line
sources and point sources, respectively.

1-50 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
Model M-files
In FEMLAB you can save an entire session performed in the graphical interface as a
MATLAB script. This script is called a Model M-file. You can modify a sequence of
FEMLAB commands for whatever reason and reload them into the graphical
interface or execute them from the MATLAB prompt.

The following code listing shows a Model M-file of the model you just developed;
this code represents the model if saved directly after solving it the first time. The
annotations give an overview of the main parts of a typical Model M-file. Note that
information not necessary to grasp the Model M-file concept has been removed from
the listing below. This means that the actual listing obtained when saving the model
as a Model M-file will be slightly longer.
% FEMLAB Model M-file
% Generated 01-Mar-2002 13:14:31 by FEMLAB 2.3.

flclear fem
% FEMLAB Version
clear vrsn;
vrsn.name=’FEMLAB 2.3’;
vrsn.major=0;
vrsn.build=154;
fem.version=vrsn;

% Recorded command sequence

% New geometry 1
fem.sdim={’x’,’y’};

% Geometry
clear s c p
R1=rect2(0,0.005,0,0.04);
C1=circ2(0,0.015,0.0025);
CO1=R1-C1;

objs={CO1};
names={’CO1’};
s.objs=objs;
s.name=names;

c.objs={};
c.name={};

p.objs={};
p.name={};

drawstruct=struct(’s’,s,’c’,c,’p’,p);
fem.draw=drawstruct;
fem.geom=geomcsg(fem);

THE FEMLAB QUICK START GUIDE | 1-51


clear appl

% Application mode 1
appl{1}.mode=flpdens2d(’dim’,{’u’,’v’,’p’});
appl{1}.name=’ns’;
appl{1}.dim={’u’,’v’,’p’};
appl{1}.border=’off’;
appl{1}.form=’general’;
appl{1}.elemdefault=’Lagp2p1’;
appl{1}.assign={’rho’,’rho_ns’};
appl{1}.var={};
appl{1}.shape={’shlag(2,’’u’’)’,’shlag(2,’’v’’)’,’shlag(1,’’p’’)’};

% Application mode 2
appl{2}.mode=flpdeht2d(’dim’,{’T’});
appl{2}.name=’ht’;
appl{2}.dim={’T’};
appl{2}.border=’off’;
appl{2}.form=’coefficient’;
appl{2}.elemdefault=’Lag2’;
appl{2}.assign={’rho’,’rho_ht’};
appl{2}.var={};
appl{2}.shape={’shlag(2,’’T’’)’};
fem.appl=appl;

% Initialize mesh
fem.mesh=meshinit(fem);

% Boundary conditions
clear bnd
bnd.v={’0’,’v0’,’0’,’0’};
bnd.type={’slip’,’uv’,’out’,’noslip’};
bnd.ind=[1 2 1 3 1 4 4];
fem.appl{1}.bnd=bnd;

% Boundary conditions
clear bnd
bnd.T={’0’,’T0’,’T1’};
bnd.type={’q0’,’T’,’T’};
bnd.ind=[1 2 1 1 1 3 3];
fem.appl{2}.bnd=bnd;

% PDE coefficients
clear equ
equ.rho={’rho0’};
equ.eta={’mu’};
equ.Fy={’alpha0*g0*rho0*(T-T0)’};
equ.init={{{’0’};{’v0’};{’0’}}};
equ.usage={1};
equ.ind=1;
fem.appl{1}.equ=equ;

% PDE coefficients
clear equ
equ.rho={’rho0’};

1-52 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
equ.C={’cp’};
equ.k={{{’kc’}}};
equ.Q={’-cp*rho0*(Tx*u+Ty*v)’};
equ.init={{{’T0’}}};
equ.usage={1};
equ.ind=1;
fem.appl{2}.equ=equ;

% Define constants
fem.const={...
’rho0’, 1000,...
’mu’, 0.001,...
’cp’, 4200,...
’kc’, 0.6,...
’alpha0’, 0.18e-3,...
’g0’, 9.8,...
’v0’, 0.005,...
’T0’, 293,...
’T1’, 303};

% Multiphysics
fem=multiphysics(fem);

% Extend the mesh


fem.xmesh=meshextend(fem);

% Evaluate initial condition


init=asseminit(fem,...
’init’, fem.xmesh.eleminit);

% Solve nonlinear problem


fem.sol=femnlin(fem,...
’init’, init,...
’report’, ’on’);

% Plot solution
postplot(fem,...
’geom’, ’on’,...
’tridata’,{’T’,’cont’,’internal’},...
’tribar’,’on’,...
’title’, ’Surface: temperature (T)’)

If you intend to load a modified Model M-file into FEMLAB’s graphical interface,
it’s important that you follow the syntactic rules outlined in the section “Model
M-file” on page 3-171 in the Reference Manual. If you intend to use the modified
Model M-file only from the MATLAB prompt, format requirements are less strict.

A Model M-file is useful for many purposes:

• It documents the work you perform within the graphical interface in a


human-readable manner.

THE FEMLAB QUICK START GUIDE | 1-53


• Studying the file FEMLAB generates can serve as a tool for learning how to work
with FEMLAB functions.
• You can save a Model M-file and modify it for optimal design or for creating
parameterized models.
• You can insert any MATLAB command anywhere in the Model M-file as long as
they do not affect the FEM structure in any way inconsistent with the syntactic
rules, and reload the model into the GUI.
• When working on a complicated model that requires you to write custom
functions, you can start modeling in the graphical interface and then save the
Model M-file to expand it. Note again, though, that if you work outside the
syntactic rules, you can run the resulting model only from the MATLAB prompt.

For more detailed information on this topic see the section “Model M-file” on page
3-171 in the Reference Manual.

Time-dependent Simulation
This example is an extension of the stationary free convection model above. In the
first step of modeling the heat transfer by forced and free convection a steady state
was found. See “Forced and Free Convection Heat Transfer” on page 1-26 on how
to create and save the first part of the model.

Now, suppose that you first let the fluid flow through without any heating until a
stable state is reached. Then you suddenly switch on the heaters: What happens?
How long time does it take to reach a new stable state? These questions can be
answered by a time-dependent simulation.

It is assumed that you have the final state of this model loaded in the graphical user
interface

Loading a Previously Saved Model


If you’ve previously saved the results from the first part of the model as a Model
MAT-file (.mat) or Model M-file (.m), you can now load it into the user interface.

• To load the previously saved model, choose Open from the File menu, and then
Model MAT-file or Model M-file, as appropriate, in the submenu. You can also press
the Open button on the main toolbar to load a Model MAT-file or Model M-file.
• Locate your model file and press OK.

1-54 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
Solving
First you have to generate the initial state, without heating. This you can reach by
simply solving only the Incompressible Navier-Stokes problem.

• Choose Solve for Variables... from the Multiphysics menu. This opens the Solver
Parameters dialog box on the Multiphysics page.

• In the Solve for variables list, only select Geom1: Incompressible


Navier-Stokes (ns). Press the Solve button in the dialog box to solve only for
the velocity components u and v, and pressure p.

THE FEMLAB QUICK START GUIDE | 1-55


The shown solution also verifies the assumption above, that there should be a wake
effect visible behind the heating tube. Next, switch to the time-dependent solver:

• Select both application modes. To do so, open the Solver Parameters dialog box
from the Solve menu. On the Multiphysics page, select both application modes, by
selecting in the Solve for variables list. Click on the first application mode and drag
down the list, or use Ctrl-click for multiple selection. The temperature used is the
initial value of T set earlier in the T(t0) field on the Init page of the Subdomain
Settings dialog box.
• Click the General tab in the Solver Parameters dialog box. Under Solver type in the
top left corner, select Time dependent.

• Then switch to the Timestepping page. The output times are given as a MATLAB
vector, specifying for which times the solution should be obtained. Enter 0:1:30
in the Output times field, which means that the solution will be sampled every
second during 30 seconds.

1-56 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
Note If you are running FEMLAB on MATLAB version 5.2, you also have to
change the Timestepping algorithm to fldaspk. The MATLAB ODE suite solvers
can handle differential-algebraic equations—such as the Navier-Stokes equations—
only in MATLAB 5.3 and later.

• Press OK to confirm the choices. Then press the Restart button in the main toolbar
to start the simulation. The solution is ready after 168 seconds on a 1.5-GHz
Pentium 4 machine.

Post Mode
The solution for the last time step is plotted, using the same plot settings as before.
On the General page of the Solver Parameters dialog box, you can select which time
step to display.

THE FEMLAB QUICK START GUIDE | 1-57


• Open the Plot Parameters dialog box, by pressing the Plot Parameters button. Go
to the Geneal page and select the timestep you want to see from the Solution at time
drop-down list. Press Apply to visualize the solution at that time

Animating the Solution


The most appealing way to view the results from a time-dependent simulation is
often as an animation. When watching an animation, you can easily see features of
the solution, that you wouldn’t find by examining the solutions for the separate time
steps one by one.

• Press the Animation button on the plot toolbar. A new MATLAB figure window is
opened, where the animation is first recorded and then played five times. If you
want to see the animaiton again, just press the same Animation button. The second
time, you do not have to wait for the recording phase.

Plotting the Time Evolution


A different way to examine the time-dependent solution is to plot the same aspect of
the solution evaluated at multiple times in the same figure. You can, for example, plot
the time evolution of the temperature profile on the cross section drawn above.

• If you still have the previous cross-section window on screen, close it.

1-58 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
• Open the Cross-Section Plot Parameters dialog box by choosing Cross-Section Plot
Parameters... from the Post menu.

• Select all even time steps from 0 to 14 seconds in the Solution at time list.
• Switch to the Line page and press the Line Settings button. This opens up the Line
Settings dialog box, in which the appearance of the line plot is defined. Set the Line
color to black, the Line style to cycle, and the Line marker to cycle. Also check the
Legend check box before pressing OK to close the dialog box.

• Type 20 in the Line resolution edit box as a final step in setting up the plot
parameters. Visualize the plot by pressing Apply.

THE FEMLAB QUICK START GUIDE | 1-59


The figure shows line plots for each selected time step. For each curve the
corresponding time can be seen in the legend box.

In the above plot, it is clear that the temperature does not change much between the
last three time steps visualized. To get a clearer picture of when a stationary state is
reached you can plot the time evolution of an expression at a geometry vertex, or at
any location inside the geometry.

• Select all time steps in the Solution time list at the General page in the Cross-Section
Plot Parameters dialog box.

1-60 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
• Click the Point radio button under Plot type, and go to the Point page of the dialog
box. Choose temperature (T) from the Point expression drop-down list.

• Press the Line Settings button and clear the Legend check box. Also set the Line
marker to none. Press OK to use the new settings.
• The x and y coordinates of the points, for which you want to plot the time
evolution, are entered as MATLAB vectors. To plot the solutions at 10 equally
spaced points along the cross section used above, enter linspace(0,0.005,10)
in the X field, and 0.02*ones(1,10) in the Y field.
• Alternatively, press the Draw Point for Cross-Section Point Plot button at the
bottom of the plot toolbar. Then you can place the points manually along the

THE FEMLAB QUICK START GUIDE | 1-61


cross-section line, using the left mouse button. Press OK in the Cross-Section Plot
Parameters dialog box.

From this last plot, you can directly answer the second question: “How long time
does it take to reach a new stable state?”. After approximately 10 seconds, the solution
has stabilized completely on the chosen cross section.

1-62 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
The Model Navigator and the Model Library
This section describes the Model Navigator dialog box. The Model Navigator is a
multi-purpose tool used to control the general settings of a FEMLAB session.

The Model Navigator


When you start FEMLAB you invoke the Model Navigator.

The Model Navigator is a tabbed dialog box with five pages:

• New page — for initializing application mode models


• Model Library page — for loading Model Library models
• User Models page — for loading your own models
• Multiphysics page — for initializing a multiphysics model
• Preferences page — for setting the Model Library paths and Preference File

You can see the five tabs at the top of the dialog box. To start creating a new model
you click on the New tab and choose the application mode that you wish to work in.
To load a model from the Model Library, click the Model Library tab and choose a
model from one of the application areas. You can also build your own models and

THE MODEL NAVIGATOR AND THE MODEL LIBRAR Y | 1-63


access them from the User Models page. The Multiphysics page is used for initializing
multiphysics models. The Preferences page can be used to set the default session
parameters for the Model Library, the User Models and the GUI.

New Page
There are four sets of modes available on the New page: Physics modes, PDE modes,
Weak modes, and Classical PDEs. The optional modules are also listed here and in this
case they are the Chemical Engineering Module, the Electromagnetics Module, and
the Structural Mechanics Module. Different modes and modules have in turn a
number of sub-modes where you can specify which type of model you want to run:
linear or nonlinear, stationary, or time-dependent, etc. The application modes consist
of:

• 1D Physics modes: Diffusion and Heat transfer


• 2D Physics modes: AC power electromagnetics, Conductive media DC,
Diffusion, Electrostatics, Magnetostatics, Heat transfer, Incompressible
Navier-Stokes, Structural mechanics Plane strain, Structural mechanics Plane
stress
• 3D Physics modes: Conductive media DC, Diffusion, Electrostatics,
Magnetostatics, Heat transfer, Incompressible Navier-Stokes, Structural
mechanics
• PDE modes for modeling using partial differential equations, see “The FEMLAB
PDE Language” on page 1-336
• Classical PDE modes: Laplace’s equation, Poisson’s equation, Helmholtz’s
equation, Heat equation, Wave equation, Schrödinger’s equation, Convection
diffusion equation
• Weak modes: Subdomain, Boundary, Edge (3D only), Point, Boundary constraint

For the physics modes, the notation for material properties and boundary conditions
are adapted to the application at hand, for example, flux, heat capacity, conductivity,
etc.

For models where there is no application mode in the Model Navigator, you can use
the PDE modes to specify your PDE and boundary conditions. Depending on the
special form of your PDE, there are several modes to choose from. A more detailed
description of the types of PDEs available can be found in “The FEMLAB PDE
Language” on page 1-336. A complete description can be found in the Reference
Guide.

1-64 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
Many Classical PDEs can be given as instances of the coefficient form in FEMLAB.
Some of them are available in the Model Navigator.

There is also an Application available of a wave guide model that was implemented
using the FEMLAB API.

Model Library Page


On the Model Library page, there are a number of completed models from different
areas of engineering and science.

The Model Library is important for several reasons: it offers a quick way to learn the
facilities of FEMLAB and examine the results of completed models. You can also save
time by using models from the Model Library as an initial platform for developing
your own models. You can modify the geometry, the values of variables, boundary
conditions, etc. The Model Library is also indispensable for demonstration purposes.

THE MODEL NAVIGATOR AND THE MODEL LIBRAR Y | 1-65


On the Model Library page you can find approximately 40 completed models. They
are fully described in detail in the Model Library. In FEMLAB version 2.3, you will
find the following models:

• Acoustic Models
- Eigenmodes of a room
- Acoustics of a heat exchanger
- Humming from rotating electrical machinery
- Humming from rotating electrical machinery with an obstacle

• Chemical Reaction Models


- Monolithic reactor
- Tubular reactor
- Cylindrical tubular reactor with cooling

• Classical PDEs
- Heat transfer problem with differing materials
- Poisson’s equation on the unit disk with a point source in the origin
- Poisson’s equation on the unit disk
- Eigenfunctions of the Schrödinger equation for an electron
- A transport problem with discontinuous solution
- The wave equation for transverse vibrations of a membrane

• Electromagnetic Models
- Safety Connector/Disconnector
- Magnetic field in an electric motor
- Electrostatic Precipitation Filter
- A permanent magnet
- Potential between two cylinders
- Skin effect in circular wire
- Protection of a steel tank immersed in seawater
- A rectangular wave guide

1-66 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
• Equation-Based Models
- The Black-Scholes equation in 1D
- The Black-Scholes equation in 2D
- The Burgers equation
- Eigenvalues and eigenmodes of a square
- The KdV equation and solitons
- The Landau-Ginzburg equation
- A minimal surface problem
• Fluid Dynamics Models
- Stationary incompressible flow over backstep
- Flow over backstep using stream function-vorticity formulation
- Flow over backstep with Argyris element
- Flow past a cylinder
- Flow of paper pulp
- The shallow water equations
- Shock tube
• Geophysics Models
- A rock fracture flow model

• Heat transfer Models


- Heat generation in a disk brake
- Heat distribution in a radioactive rod

• Multidisciplinary Models
- Magnet brake
- Thermal controller
- Thermal controller using non-local coupling variables

THE MODEL NAVIGATOR AND THE MODEL LIBRAR Y | 1-67


• Multiphysics Models
- Stresses in cracked heat exchanger tubes
- Thermo-electric heating
- Bus bar
- Free convection
- Marangoni convection
- Micro robot
- Vibrations in a milk containers

• Physics Models
- The Schrödinger equation for the hydrogen atom
• Semiconductor Device Models
- Semiconductor diode model

• Structural mechanics Models


- The deformation of a feeder clamp
- A Mindlin plate problem
• Wave Propagation Models
- Diffraction patterns
- Isospectral drums
- Eigenvalues and eigenfunctions for the L-shaped membrane
To obtain the on-line documentation for a specific model, press the Documentation
button while the model is selected in the Model Library tab. The on-line
documentation can be used in various ways, for example, as a starting point for
working with scripts, by copying from the documents and pasting in the MATLAB
Command Window.

User Models Page


On the User Models page, you can browse your own set of saved models. If you have
saved a model together with a model image and a model description, you can display
the model with an image and a short description, in the same way you display models
on the Model Library page.

1-68 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
Multiphysics Page
On the Multiphysics page you initialize multiphysics models, by selecting from a list
of application modes. In the GUI, you are then able to couple all the selected
application modes. At any time during the modeling process, you can open the Model
Navigator’s Multiphysics page again, to add or remove application modes.

For more information on how to use the multiphysics feature, see the multiphysics
model “Thermo-Electric Heating in a Bus Bar” on page 1-109, and also the
multiphysics models of the Model Library.

Preferences Page
The Preferences page lets you specify the Model Library path, the User Models path
and preference file. The preference file, with the extension .mat, is a FEMLAB

THE MODEL NAVIGATOR AND THE MODEL LIBRAR Y | 1-69


Model MAT-file that can be used for initializing the GUI settings, such as axis limits,
grid spacing, etc. You can also specify the Startup mode for a FEMLAB session.

1-70 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
The FEMLAB G r aphical User Interface
FEMLAB features a graphical user interface (GUI) that handles all aspects of the
modeling process. Indeed, the simplest way to model an object is with the graphical
interface, which is automatically invoked when you specify an application mode in
the Model Navigator. For some models, however, it can be more expeditious to use the
programming language (see “The Programming Language” on page 1-301).

The figure below shows the 2D graphical interface with annotations that highlight
some of its most important elements.

Main toolbar Axis scroll bars

Menu bar

Draw toolbar

Message log

Status bar
Main axes area

The menu bar enables control of all aspects of the modeling process. It conforms to
the common menu standards:

• Items followed by a right arrow lead to a submenu.

THE FEMLAB GRAPHICAL USER INTERFACE | 1-71


• Items followed by an ellipsis lead to a dialog box.
• Stand-alone items initiate a direct action.
• All menu items have corresponding keyboard interfaces (use ALT+the underlined
character for drop-down menus). You can also execute some menu items with
shortcut keys.

In the main axes area you draw the geometry, display the mesh and plot the solution,
etc.

A message log in the lower part of the interface provides progress information from
solvers as well other items of information.

Located just below the message log, the status bar provides details about the status
of settings such as grid lines. Here you can also examine current cursor coordinates.
You can toggle the state of a status bar item by double-clicking on it.

The main toolbar below the main menu contains icon buttons that provide quick
access to some of FEMLAB’s most important functions. For instance, additional
toolbars sometimes appear: in draw mode, a draw toolbar appears; in post mode you
gain access to a plot toolbar.

For a complete description of all menu items, dialog boxes, and other interface
components, see the chapter The Graphical User Interface in the Reference Manual.

The Menus
The graphical interface provides several selections from the menu bar.

• File menu—where you open and save files, as well as import and export data to the
MATLAB main workspace or to a file. You can also print the current graphics and
exit the graphical interface.
• Edit menu—where you cut, clear, copy, and paste geometry objects, boundary
conditions, material properties and initial conditions. You can perform multiple
undo steps of geometry and mesh actions. A Select All and a Deselect All option is
also available.
• Options menu—where the options allow you to modify axis settings, zoom levels,
rendering settings, and labels. You can also define constants and variables for use
in boundary conditions, and when defining material properties, change assigned
variable names, specify differentiation rules, etc.

1-72 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
• Draw menu—where you select and create primitive solid objects such as circles,
spheres, blocks, and rectangles, which you can then modify with the mouse. You
can move, scale, and rotate objects as well as do coercions of geometry objects. It
is possible to also create composite objects.
• Point menu—where you can open a dialog box in which you define point settings.
(Only in 2D and 3D.)
• Edge menu—where you can open a dialog box in which you define edge settings.
(Only in 3D.)
• Boundary menu—where you can, among other things, open a dialog box in which
you define boundary conditions.
• Subdomain menu—where you can, among other things, open a dialog box for
specifying material properties or PDE coefficients.
• Mesh menu—where you create and modify the finite element mesh. You can
initialize, refine, and smooth the mesh as well as display mesh quality.
• Solve menu—where you start and control model computations. From this menu
you can open a dialog box where the solver parameters are set.
• Post menu—where you can post-process the solution. A wide range of plot types
are available as well as integration tools.
• Multiphysics menu—where you add application modes to or delete application
modes from a multiphysics model. It is also possible to switch among application
modes that were added earlier. Also under this menu you can specify which
solution components to solve for.
• Window menu—where you select any currently open MATLAB figure window;
FEMLAB immediately brings the selected window to the front.
• Help menu—where you find help about FEMLAB’s functions, read on-line
documentation and reach additional help resources locally as well as over the
Internet.

THE FEMLAB GRAPHICAL USER INTERFACE | 1-73


The Toolbars
The main toolbar underneath the main menu contains icon buttons that provide easy
access to key functions. They do not, however, offer any additional functionality; all
toolbar button functions are also available as menu items.

The toolbar consists of seven parts. From the left to right, there are: four buttons
addressing file handling; three buttons handling editing; one button for object
selections; seven buttons addressing meshing, solving, and plotting; four buttons
implement zooming; six (in 2D) buttons handle mode navigation; and at the end
comes a Help button.

FILE HANDLING BUTTONS

New Open Save Print

The file handling buttons (from left to right) perform these actions:

• Open the Model Navigator to start a new model.


• Load a Model MAT-file/Model M-file from disk.
• Save the current model to a Model MAT-file.
• Print a hardcopy screen dump of the FEMLAB main axes.

EDIT BUTTONS AND THE SELECT BUTTON

Cut Copy Paste Select

The edit buttons and the select button (from left to right) perform these actions:

• Move the selected geometry objects to the FEMLAB clipboard.


• Copy the selected geometry objects, boundary conditions, PDE coefficients, or
initial conditions to the FEMLAB clipboard.

1-74 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
• Paste FEMLAB clipboard contents into the current model.
• Select items such as menus, buttons, or objects.

The select button (with an arrow icon) offers a way to select objects by clicking on
them.

MESH, SOLVE, AND PLOT BUTTONS

Solver
Refine
Initialize Mesh Refine Parameters Restart
Mesh Selection Solve Plot Parameters
Problem

The mesh, solve, and plot buttons (from left to right) perform these actions:

• Generate and display an initial mesh.


• Refine the entire current mesh.
• Uniformly refine only selected triangles (1D and 2D only).
• Open the Solver Parameters dialog box.
• Compute the solution for the current model and plot the result (you can disable
the automatic solution plot).
• Restart the solution process after you previously halted it with the Stop button.
• Open the Plot Parameters dialog box.

ZOOM BUTTONS

Zoom Out Zoom Extents


Zoom In Zoom Window

The zoom buttons (from left to right) perform these actions:

• Zoom in, centered.


• Zoom out, centered.
• Zoom in a user-defined zoom window.
• Zoom out as far as the extents of the geometry.

THE FEMLAB GRAPHICAL USER INTERFACE | 1-75


GUI MODE NAVIGATION BUTTONS AND THE HELP BUTTON

Point Mode Subdomain Mode Post Mode


Boundary Mode Mesh Mode Help
Draw Mode

The mode navigation buttons provide a convenient mechanism for mode-selection


accompanied with a visual indication of the current mode. The six buttons (from left
to right) activate the following modes:

• Draw mode
• Point mode
• Boundary mode
• Subdomain mode
• Mesh mode
• Post mode

The last button on the right is the help button, which launches the FEMLAB Help
Desk. In 3D, there is an additional edge mode and a corresponding button.

2 D D R A W TO O L B A R B U T T O N S
In its default configuration, the 2D draw mode provides an additional draw toolbar
that contains buttons for creating and editing the geometry. The 2D draw toolbar is
also available in the work planes for a 3D model. See the section “Work Plane Toolbar

1-76 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
Buttons” on page 1-83 for details. The 3D draw toolbar is described in the
section“3D Draw Toolbar Buttons” on page 1-83.

Draw Rectangle Draw Point

Draw Centered Rectangle Draw Line

Draw Ellipse Draw Arc

Draw Centered Ellipse Draw Cubic Bézier Curve

Union

Intersection
Move
Difference
Rotate

Scale Create Composite Object

Coerce to Solid

Coerce to Curve

Split

Delete Internal Borders

THE FEMLAB GRAPHICAL USER INTERFACE | 1-77


2 D P L O T TO O L B A R B U T T O N S
In its default configuration, post mode provides an additional plot toolbar that
contains buttons for visualization and animation.

2D Surface Plot

3D Surface Plot

Contour Plot

Arrow Plot

Flow Plot

Line Plot

Animation

Draw Line for Cross-Section Plot

Draw Point for Cross-Section Plot

The 3D plot toolbar is described in the section “3D Plot Toolbar Buttons” on page
1-85.

The GUI Modes


The FEMLAB solution process typically involves the following steps:

1 Define the geometry.


2 Define boundary conditions.
3 Define material properties (PDE coefficients).
4 Create the mesh.
5 Solve the problem.
6 Plot the solution and other physical properties calculated from the solution
(postprocessing).

The design of FEMLAB’s graphical interface mirrors this scheme. You work in
different modes, each corresponding to a step in the solution process:

1-78 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
1 In draw mode you create the geometry. You create geometry models by using CAD
tools and either solid-modeling or boundary-modeling techniques. For 2D and
3D modeling, this mode provides a set of primitive solid objects (rectangle, circle,
ellipse, block, cone, cylinder, ellipsoid, and sphere) that can be combined into
composite objects. You can also draw lines, arcs, and rational Bézier curves. Other
tools can convert areas enclosed by curves into solids. It is also possible to import
a geometry from an external file.
2 In boundary mode, edge mode (only in 3D) and point mode (in 2D and 3D), you
specify boundary conditions and conditions on edges and points. You can specify
different types of conditions on different domains.
In these modes, you optionally set initial conditions for time-dependent problems
and the nonlinear solver. It is possible to set varying initial values on different
domains.
Note that there is also support for periodic boundary conditions, see the Model
Library for examples.
3 In subdomain mode you specify application-dependent material properties for
problems you base on templates from FEMLAB’s Physics application modes or
supply PDE coefficients in the PDE application modes. You can specify values for
each subdomain independently. For instance, you can easily specify multiple
material properties within one FEMLAB model.
In subdomain mode you also set initial conditions needed for time-dependent
problems and the nonlinear solver. It is possible to set initial values on different
subdomains.
4 In mesh mode you control automated mesh generation and mesh visualization.
5 You solve your problem by selecting Solve Problem on the Solve menu. You can also
invoke the solver, and and set various solver properties, by calling the Solver
Parameters dialog box.
6 Post mode provides a wide range of visualization and other postprocessing
possibilities. You can visualize solutions either inside the FEMLAB graphical
interface or outside it as a separate MATLAB plot. Several solution properties can
be visualized at the same time using colored surfaces, contours, streamlines, and
vector fields. It is also possible to plot expressions, including the solution, in
cross-sections of the geometry and on boundaries and edges, and to make point
plots or “time extrusion” plots. You can also animate any solution. In post mode,
subdomain and boundary integration tools are also available.

THE FEMLAB GRAPHICAL USER INTERFACE | 1-79


Object Selection Methods in 2D
Throughout the 2D graphical interface, similar principles apply for selecting items
such as geometry objects, subdomains, and boundaries.

• To select a single geometry object, click on it using the left mouse button.
• To select several objects or deselect some of them, Shift-click or Ctrl-click on the
desired objects. On a 3-button mouse, clicking the middle or the right mouse
buttons instead of the left button corresponds to Shift- and Ctrl-clicking,
respectively.
• Clicking on the intersection of several objects selects all of them.
• To open an object’s dialog box, double-click on the object.
• Clicking outside of the objects deselects all of them.
• To select all objects, use the Select All option from the Edit menu or the keyboard
shortcut Ctrl-a.
You can also employ a rubber band box to select objects. Click and drag while holding
the mouse button to create a rubber band box. Selection principles remain as above,
and the selection applies only to objects that the rubber band box surrounds
completely. Shift-clicking adds the rubber band box selection to the current selection,
while Ctrl-clicking performs the exclusive-or operation with the current selection (in
other words, presently selected objects becomes deselected when inside the rubber
band box and vice versa).

Display Additional Information


In mesh mode, you can display the element number at the current position by
pressing a mouse button. Clicking a triangle displays the triangle number in the
message log.

In post mode in 2D, you can display the numerical value of the current surface or
contour plot at the position where you click. Press a mouse button to display the
value of the plotted property in the message log. In 1D, clicking in the main axes area,
displays the value of the currently plotted expression.

If you want to get the values of the solution at several points, you can export the
entire model to MATLAB as a so-called FEM structure. You do this by selecting
Export FEM Structure as ‘fem’ from the File menu. Then you can use the function

1-80 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
postinterp at MATLAB’s prompt to compute numerical values for any expression.
See the entry on postinterp in the Function Reference.

Entering MATLAB® Expressions in the GUI


In many of the edit fields that appear in dialog boxes within the graphical interface
you can enter MATLAB expressions, for example, in the Boundary Settings and
Subdomain Settings dialog boxes.

When entering parameter values as an expression—for example as a function of the


space coordinates x, y and z, also known as independent variables—the string must
be a valid MATLAB expression.

Each application mode works with a set of subdomain and boundary variables. You
can enter these variables as part of a MATLAB expression in the corresponding edit
fields. For instance, in the electrostatics application mode you have access to the
electric potential V as a subdomain variable. Consider another example: in the plane
stress application mode you have access to the surface traction variables Fx and Fy as
boundary variables. For more information on valid subdomain and boundary
variables, see the section “The FEMLAB PDE Language” on page 1-336 and
“Application Mode Reference” on page 4-203 in the Reference Manual.

The FEMLAB Data Formats


FEMLAB can save anything you create in the graphical interface and reload it later.
You can save and load models either as binary code (in a Model MAT-file) or as
MATLAB M-code (in a Model M-file). You can also load a Model M-file into a text
editor for modification or extension with additional MATLAB statements. A Model
M-file executes in the MATLAB command window as does any MATLAB M-file.
Find more details about these formats in the sections “Model M-files” on page 1-51
and “The Programming Language” on page 1-301.

During a FEMLAB session you can export a version of the geometry description to
the MATLAB workspace, operate on it from the MATLAB prompt, and import it
back into FEMLAB for further development. It is also possible to export boundary
conditions and PDE coefficients, or export all FEM data bundled into one MATLAB
structure called the FEM structure (see “The FEM Structure” on page 1-301). You
can import and export 2D geometry objects using a DXF file and import 3D
geometry objects from an IGES file. See “DXF Import” on page 1-209 and “IGES

THE FEMLAB GRAPHICAL USER INTERFACE | 1-81


Import” on page 1-213, respectively. After importing a file, FEMLAB automatically
converts its contents to FEMLAB geometry objects.

The 3D Graphical User Interface


This section addresses 3D aspects of modeling within FEMLAB. A significant part
of what has been said about the 2D graphical interface is applicable in 3D. The main
differences between the 3D and 2D graphical interfaces arise in geometry modeling,
in visualization possibilities of a 3D geometry, and in methods for selecting objects.

The figure below shows the 3D graphical interface together with annotations
pointing out its most important parts.

Main toolbar

Menu bar

Draw toolbar

Selection toolbar

Orbit/Pan/Zoom toolbar

Message log

Status bar
Coordinate system
Main axes area

1-82 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
The 3D menu bar resembles the one in the 2D graphical interface, except for the Edge
menu, which is not available in 2D. The contents of the menus also differ slightly. For
example, the Draw menu differs considerably from the 2D case. You’ll also find
variations in the export/import submenus on the File menu as well as additional 3D
visualization tools on the Options menu, the Boundary menu, the Subdomain menu,
and the Mesh menu.

For a complete description of all menu items, dialog boxes, and other items, see the
chapter “The 3D Graphical User Interface” in the Reference Manual.

3 D D R A W TO O L B A R B U T T O N S
The draw toolbar in 3D has a different appearance than the 2D toolbar. However,
many of the buttons work in a similar manner.

Draw Block Union

Draw Cone Intersection

Draw Cylinder Difference

Draw Ellipsoid Create Composite Object


Draw Sphere Coerce to Solid

Coerce to Face
Move
Coerce to Curve
Rotate
Split Object
Scale
Delete Internal Borders

W O R K P L A N E TO O L B A R B U T T O N S
The work plane draw toolbar is visible only for 3D models when you are in a work
plane view. This toolbar is essentially the same as the 2D draw toolbar with a few
additions at the bottom. See “2D Draw Toolbar Buttons” on page 1-76 for details.

THE FEMLAB GRAPHICAL USER INTERFACE | 1-83


The additional buttons are the ones for the projection of the 3D geometry onto the
work plane. You can snap to the projection when drawing.

Projection of All 3D Geometries

Project Work Plane Intersection

No Projection

O R B I T / P A N / Z O O M TO O L B A R B U T T O N S
The orbit/pan/zoom toolbar is available in all modes in 3D. It contains buttons to
change the 3D view and to select lighting tools.

Orbit Orthographic Projection

Pan Perspective Projection

Zoom
Move as Box
Dolly up/down

Dolly in/out View XY-plane

Orbit Scenelight View YZ-plane

View ZX-plane
Scenelight
Reset 3D View
Headlight
Increase Transparency

Decrease Transparency

1-84 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
S E L E C T I O N TO O L B A R B U T T O N S
The mechanism for making selections is by necessity more elaborate in 3D than in
2D. Therefore it is convenient to work with the select toolbar, which contains
buttons for visualization and selection purposes. It is available in all modes.

Select All Adjacent Render Vertices

Cycle Adjacent Render Curves

Normal Selection Render Faces

All Faces with Same Adjacent Subdomains Highlight Vertices

All Faces on Adjacent Subdomain Highlight Curves

Highlight Faces
Confirm Selection

3 D P L O T TO O L B A R B U T T O N S
In the default configuration, post mode provides an additional plot toolbar that
contains buttons for visualization and animation.

Slice Plot

Isosurface Plot

Tetrahedron Plot

Surface Plot

Arrow Plot

Flow Plot

Animation

Draw Plane for Cross-Section Plot

Draw Line for Cross-Section Plot

THE FEMLAB GRAPHICAL USER INTERFACE | 1-85


Visualization in 3D
The visualization of a 3D geometry object is important not only for understanding
what the geometry looks like, but also for selection purposes. The visualization
depends on the object types being rendered and the ones being highlighted. For
example, you can choose to render only a wireframe plot of deselected face objects or
to render highlighted faces when they are selected. You control the visualization’s
quality through the choice of the geometry mesh detail, the graphics renderer, and
lighting options.

To fully understand the following sections it is important to understand how


FEMLAB composes a geometry object. It does so using faces, edges and vertices. For
example, a solid cylinder consists of one subdomain surrounded by six faces. The faces
are bound by twelve edges that connect at eight vertices. Thus, FEMLAB can visualize
a cylinder by displaying one or several of these four types. For instance, you can
generate a wireframe plot by rendering only the cylinder’s edges.

Geometry objects are said to be adjacent if they connect directly to each other.
Hence, all faces, edges, and vertices on the cylinder are adjacent to the subdomain.
An edge on the cylinder is adjacent to two of the faces and two of the vertices.

The Visualization/Selection Settings dialog box on the Options menu contains all the
tools for controlling the visualization. The dialog box has three pages: Rendering/
Selection, Orbit/Pan/Zoom and Performance.

RENDERING AND HIGHLIGHTING


The first page in the Visualization/Selection Settings dialog box is the Rendering/
Selection page. Here you specify what to render and highlight. You also determine
which objects are clickable and how to suppress objects. These settings apply to draw
mode, boundary mode and subdomain mode. Settings on this page also determine
what you actually select when clicking on adjacent objects or when clicking on faces

1-86 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
in boundary mode. More details are available in the section “Object Selection
Methods in 3D” on page 1-95.

Each of the four object types (Faces, Edges, Vertices and Labels) displays its own frame
on this page; further, a check box next to each frame title allows for the quick and
complete disabling of a specific object type.

In each of the top three frames, the Render check box determines how an object
should appear on the screen when it’s not selected. The Highlight check boxes
determine which object types to highlight when you select an object. Note that
highlighting and rendering properties are independent of each other.

In the labels frame you specify which labels the graphical interface should render. The
labels also have an Auto highlight property that ensures the interface highlights the
label of a selected object if you haven’t checked its highlight check box.

Rendering and highlighting properties for faces, edges and vertices have
corresponding toolbar buttons in the select toolbar.

CLICKING
Each object-type frame on the Rendering/Selection page also contains a Clickable check
box that controls whether that object type is clickable or not. This box must be
checked if you want an object to recognize a mouse click. For example, if you have
trouble selecting a small face object due to the presence of nearby edge, you can
deactivate clickable for edges. For vertices, edges, and faces, what can be clicked on is
independent of what is rendered. However, to be able to make labels clickable, you

THE FEMLAB GRAPHICAL USER INTERFACE | 1-87


must also render them. The clickable-property has no relevance in mesh or post mode
where you cannot normally make selections in the main graphical interface axes.

SUPPRESS ADJACENT PROPERTY


Another important aspect of the 3D visualization capabilities concerns the
suppression feature. By suppressing objects, you can reveal hidden objects or clear the
way to access objects that otherwise would be difficult to reach. In FEMLAB you can
suppress geometry objects, subdomains, and faces. The Suppress adjacent property
dictates whether or not to suppress adjacent objects of a suppressed object. For
example, if you check the Suppress adjacent box in the Edges frame, the edges
enclosing a suppressed face object are also suppressed if they’re not adjacent to
another non-suppressed face. Suppression affects all modes, but the suppress
adjacent property applies only to draw mode, boundary mode, and subdomain
mode. This manual devotes a separate section on page 1-106 to the suppression
feature.

QUALITY OF VISUALIZATION
Several tools in FEMLAB can improve the quality of a visualization. You can control
the resolution of geometry objects as well as select the graphics renderer and lighting
method.

Lighting
The application of lighting can significantly improve the quality of visualization for a
geometry object, a mesh plot, or a solution plot. Lighting properties appear on the
Orbit/Pan/Zoom page in the Visualization/Selection Settings dialog box and also on the
orbit/pan/zoom toolbar.

The FEMLAB graphical interface provides two light sources. The Headlight is
positioned at the observer and directed towards the target. The Scenelight, on the
other hand, radiates from a far distance, simulating the lighting of the sun. To set the
scenelight’s position use the Orbit Scenelight function.

You can also vary the lighting model and the reflection type for best result.

• Flat lighting produces uniform color across each triangular face of an object.
Select this method to view faceted objects.
• Gouraud lighting calculates colors at the vertices and interpolates colors across
faces. Select this method to view curved surfaces.
• Phong lighting interpolates the normals of all vertices across each face and
calculates the reflectance at each pixel. Select this choice to view curved surfaces.

1-88 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
Phong lighting generally produces better results than Gouraud lighting but takes
longer to render.

To change the reflection on face objects you can choose among four different
materials in the Reflection drop-down list box: Default, Dull, Metal, and Shiny.

Renderer
On the Performance page you can choose between two graphics renderers: Z-buffer
and OpenGL. OpenGL operates several times faster than Z-buffer, assuming the
graphics card on your platform supports it.

The Z-buffer renderer generally generates higher resolution plots and the Phong
lighting model isn’t available for OpenGL rendering, which means that you can
sometimes obtain higher quality plots using Z-buffer. Note also that using OpenGL
requires more memory on your graphics card.

Geometry Mesh Detail


On the Performance page of the Visualization/Selection Settings dialog box you specify
the geometry mesh detail. Options include Fine, Normal, Coarse, or Extra Coarse. This
setting controls the number of polygons FEMLAB uses to render geometry surfaces.
Note that the geometry mesh is separate from the mesh FEMLAB uses to compute
problem solutions; you lose no solution accuracy by changing to a coarser geometry
mesh.

THE FEMLAB GRAPHICAL USER INTERFACE | 1-89


RENDERING LARGE GEOMETRY OBJECTS
This section describes some memory-saving techniques that can be useful when
working with large models on a computer with limited processor capacity and
memory.

An obvious way to conserve memory is to render as little as possible of the geometry.


Face objects are the most memory demanding objects. Open the Visualization/
Selection Settings dialog box on the Rendering/Selection page. Now remove all face
rendering either by unchecking the Render, Highlight, and Clickable check boxes in the
Faces frame, or by unchecking the check box in the frame title (the fastest way to
completely disable all face rendering). To get a wireframe plot of the geometry, make
sure the Render check box in the Edges frame is checked.

Remember that once FEMLAB has rendered a geometry using faces, it maintains the
larger geometry mesh level needed for faces until it regenerates the geometry, even if
you turn off all face rendering. See the mlevel property in the meshinit entry in the
Reference Manual for more information about the mesh level. To be certain that
you’re working with the smallest possible mesh, turn off face rendering before
creating the geometry or triggering a regeneration of the geometry. An easy way to
do so is by changing Geometry mesh detail on the Performance page. This selection
also affects the amount of memory consumed; a coarse geometry mesh requires less
memory than a fine geometry mesh.

The same page holds a frame named Remove graphics objects when leaving modes.
Here you can select to delete all graphics objects when they’re no longer needed in
order to free memory during the modeling process.

If you run out of memory on your graphics card when using the OpenGL renderer,
you can either shrink the FEMLAB figure window until it’s small enough for the
graphics memory to render, or you can switch to Z-buffer rendering, which occupies
less graphics memory than OpenGL does.

Another way to save computer memory is to reduce the number of undo steps for the
geometry modeling and also the number of undo steps for mesh generation. This is
done in the Customize dialog box found on the Options menu.

MESH VISUALIZATION
So far this chapter has dealt primarily with the visualization of a geometry whereby
this section applies only to mesh mode and the finite element mesh.

Open the Mesh Visualization Parameters dialog box by selecting Visualization


Parameters… from the Mesh menu. Here you find several tools for visualizing the

1-90 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
finite element mesh. The Patch plot frame decides whether or not to plot the faces of
the mesh’s boundary elements and volume elements. You can turn off all patch plots
by unchecking the check box in the frame title. Similarly, toggle the activation of
boundary and volume elements independently of each other using the Show boundary
elements and Show volume elements check boxes.

It is possible to set the faces to take on one of the predefined colors in the drop-down
list boxes. Alternatively, you can have elements assume a different color depending
on their quality. Choose the quality color map in the Quality color map drop-down
list box in the lower part of the frame. To display a color bar select the Color bar check
box to the right. The Edge color drop-down list box determines the color of the edges
of the patches.

The Wireframe plot frame appears on the lower left. Here you can choose to plot a
wireframe of the mesh elements. Next to the frame title you can turn all wireframe
plots on or off with one click. Inside the frame, you plot volume elements, boundary
elements, and curve elements by checking the Show volume elements, Show boundary
elements, and the Show curve elements check boxes. Other options allow you to set
the color of different wireframe plots individually.

To the right, in the Element selection frame, appears a set of tools that determine
which parts of the mesh to visualize. In the Logical expression for inclusion edit field
you can enter a MATLAB expression in terms of the space coordinates, x, y and z
that specifies which parts of the mesh to include in the plot.

This edit field works in conjunction with the Inclusion type drop-down list box where
you can choose between three options. The All nodes option covers any elements in
which all of their nodes satisfy the inclusion expression. The Any node option

THE FEMLAB GRAPHICAL USER INTERFACE | 1-91


includes elements in which at least one of their nodes satisfy the inclusion expression.
The Xor alternative includes elements in which some but not all of their nodes satisfy
the inclusion expression.

In the Fraction to keep edit field you specify a fraction of the total amount of volume
elements to plot. Depending on settings in the Keep type drop-down list box,
FEMLAB either randomly selects the fraction of elements or it works with the worst
fraction in terms of element quality. You can disable these settings by unchecking the
check box in the frame title for element selection. These settings apply on top of the
suppression of boundaries and subdomains (see “Suppressing Boundaries and
Subdomains” on page 1-107).

The following picture illustrates how to use the logical expression for inclusion
feature on the feeder_clamp model from the Model Library. This example plots
only those elements with all their nodes fulfilling the inclusion condition y<40. From
it you can see the quality of the volume elements in the open cuts.

The 3D View
When working with 3D geometry objects, it’s important to be able to easily change
the view so as to take close-up examination of a geometry part or select objects hidden
behind other objects. This section applies to all modeling modes.

When you look at graphics objects displayed in a 3D axes, you’re viewing the scene
from a particular location in space (in FEMLAB known as the camera position) and
with a particular orientation (the camera up-vector). The center of the scene is the

1-92 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
camera target, which appears to be near or far away depending on the view angle,
which you set with the camera zoom lens.

CHANGING THE VIEW


You can completely define a 3D view in terms of camera position, camera up-vector,
target position, viewing angle and projection type. You can select between two
possible projection types on the Orbit/Pan/Zoom page of the Visualization/Selection
Settings dialog box. The orthographic option projects graphics objects so as to
maintain their actual size and the angles between them; object size does not depend
on relative distance to the camera. The perspective option projects objects so as to
make those further from the camera appear smaller. This projection type is useful for
displaying realistic views of real objects.

Mouse Movement Actions


On the same page you can find a frame for Mouse movement action, which defines
what happens when you click-and-drag in the 3D main axes. Selecting Orbit has the
camera orbit around the target position, Pan orbits the target about the camera
position, while Zoom changes the viewing angle. Dolly up/down moves the camera and
target position up and down, while Dolly in/out moves the camera towards or away
from the target position. This powerful tool can, for instance, make it possible to
examine the inside of a geometry object. Selecting the Orbit scenelight radio button
orbits the scenelight around the scene to get another lighting angle.

The frame also contains a None radio button that disables click-and-drag functionality
and enables rubber band box selection. Further, the Move as box check box deactivates
geometry updates during mouse dragging. Instead, the graphical interface represents
the geometry by a bounding box and follows the mouse movement. The screen
redraws the geometry only when a dragging session is finished, that is, when you
release the mouse button. This functionality is useful when working with complex
geometries that are heavy to render. All the controls in the mouse movement action
frame have corresponding buttons in the orbit/pan/zoom toolbar.

The mouse movement action and selection functionality are both active concurrently
in the 3D graphical interface (see the section “Click-and-Drag in 3D” on page 1-102).

Fine Tuning the View


To fine tune the view using the tools described above, you can press the right mouse
button instead of the left (or use Ctrl-clicking). This action improves precision by a
factor of four compared to left-clicking.

THE FEMLAB GRAPHICAL USER INTERFACE | 1-93


Continuous Rotation
For Orbit, Pan, and Orbit Scenelight, a Shift-click (or click on the middle button in a
3-button mouse) starts a continuous rotation you interrupt by clicking anywhere in
the graphical interface.

Explicit View Settings


If it becomes difficult to attain a specific view with the tools on the FEMLAB
graphical interface, you can define a particular view by using the Explicit View Settings
dialog box. Open it from within the Orbit/Pan/Zoom page in the Visualization/Selection
Settings dialog box.

Example
Let us look at how to use explicit view settings and lighting settings to examine the
solution plot of the example “Deformation of a Feeder Clamp” on page 2-372. in the
Model Library, from the inside. Open the Model Library page in the Model Navigator.
Select the feeder_clamp model from the Structural_Mechanics branch in the
FEMLAB directory and press OK.

Go into post mode and open the Plot Parameters dialog box, deselect Color bar on
the Surface page and click OK.

Open the Visualization/Selection Settings dialog box from the Options menu. On the
Orbit/Pan/Zoom page in the Lighting frame, select Scenelight. On the Performance page
select the OpenGL renderer. Select perspective projection from the Perspective
drop-down list box on the Orbit/Pan/Zoom page and press the Apply button. Press the
Explicit View Settings… button to change the 3D view. Enter the coordinates
(25,45,20) in the fields for Camera position and the coordinates(15,30,20) for the
Camera target position. Set Camera up vector to (-1,1,-1). Finally, enter a view

1-94 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
angle of 140 degrees and click OK to get the following fish-eye view from inside the
middle cylindrical part of the clamp.

You can achieve the same effect using the Dolly In/Out and Zoom buttons on the orbit/
pan/zoom toolbar.

Object Selection Methods in 3D


The selection mechanism in FEMLAB relies on clicking 3D objects in the main axes
of the graphical interface. In other words, you do not have to call up any dialog boxes
to make object selections. Throughout the 3D graphical interface, similar principles
apply for selecting a variety of items including geometry objects, subdomains,
boundaries, edges, and points.

SINGLE SELECTION
You perform a single selection using the left mouse button, and the interface
highlights selected objects in red. You select objects by clicking on them or by clicking
on adjacent objects. Sometimes this method can be faster and easier than clicking
directly on the desired object. For example, you might select a face object by clicking
on the face or its label, on its adjacent vertices or edges, or on the labels of its adjacent
subdomains. See “Adjacency Selection Methods” on page 1-102 for details.

To be able to click on an object, you must set its object type to clickable. The
rendering/highlighting settings also entail certain restrictions (see “Clicking” on page
1-87).

THE FEMLAB GRAPHICAL USER INTERFACE | 1-95


OVER LAPPING OBJECTS
When you click on a 3D geometry within the main axes, occasionally several objects
might be overlapping at the cursor. Thus the intention of the click is ambiguous.
How does FEMLAB handle this situation?

An object’s priority depends on its type. Labels have the highest priority, then come
vertices, then edges, and finally face objects. As a result, you can always select a point
or a curve object, even if a face object in the foreground covers it.

Ordering within an object type exists only for faces. Faces are initially sorted based
on their area; the smallest face has highest priority, so the first click on overlapping
faces selects the smallest one. A subsequent click selects the second smallest face under
the cursor, and so on. In other words, multiple clicking on overlapping faces cycles
among them.

Object precedence also means it’s easy to accidentally click on labels, vertices or edges
when you’re aiming for a face object. While you’re releasing the mouse button, look
at the coordinate field on the Status bar to see which object you’re actually selecting;
the selection action doesn’t trigger until you release the mouse button. See
“Click-and-Drag in 3D” on page 1-102 for a description of how to cancel a pending
selection.

Example
This example demonstrates the selection of a single face segment and object
precedence when clicking on overlapping faces.

Open the Model Library page in the Model Navigator. Select the feeder_clamp model
from the Structural_Mechanics branch in the FEMLAB directory and press OK.
Enter boundary mode by pressing the Boundary Mode button in the main toolbar.
Press the Reset 3D View button in the orbit/pan/zoom toolbar to get the default 3D
view and turn off the lighting by deselecting the Headlight button. Select the Select
button in the main toolbar to disable mouse movement action during this example.
Move the mouse cursor to the position indicated by the arrow in the figure below

1-96 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
and click once with the left button. As illustrated below, two faces are overlapping at
the cursor position, and you’ve selected the smaller of the two.

The face and its adjacent edges are highlighted in red. Click again using the left mouse
button, without moving the mouse; doing so selects the larger face behind the
previously selected face. Continuous clicking on the same spot cycles between the
two faces.

MULTIPLE SELECTIONS
By holding down the Shift key during selection, you can add another object to the
current selection. This feature allows for quick multiple selections. An alternate way
to accomplish the same task is by using the middle button on a 3-button mouse
because its assigned function is equivalent to holding the Shift key. You might find,
though, that making multiple selections with Shift-clicking isn’t always satisfactory
when several objects are overlapping. To avoid such difficulties you can confirm
selections as described in the next section below. To select all objects, use Select All
from the Edit menu or use the shortcut Ctrl-a.

Example
Continuing from the previous example, hold down the Shift-key and click two times
with the left mouse button on the same spot as before; both overlapping faces are
now selected simultaneously. You can move the mouse to other faces and Shift-click
on them to add them to the current selection. If you do not hold the Shift key down,

THE FEMLAB GRAPHICAL USER INTERFACE | 1-97


you end up with just a single selection. The following figure shows a selection of four
faces made in this fashion.

You can also employ a rubber band box to select objects. Press the Select button in
the main toolbar to enable rubber band box selection. Click and drag while holding
the mouse button to create a rubber band box. The selection applies only to objects
that the rubber band box surrounds completely. Shift-clicking adds the rubber band
box selection to the current selection, while Ctrl-clicking performs the logical and
operation with the current selection (only presently selected objects inside the rubber
band box will be selected).

CONFIRMING SELECTIONS
The confirmation feature is a way to lock in the current selection so that the interface
keeps it active until you explicitly deselect it. Previously selected objects (highlighted
in red according to the visualization settings) turn blue when confirmed. You
confirm and thereby lock in a selection by clicking anywhere in the main axes, on the
geometry, or outside the geometry either using the right mouse button or by holding
the Ctrl key when clicking; an alternate is to press the Confirm Selection toolbar button
in the Selection toolbar. Locking in a selection prevents it from being removed by
accident, a feature that proves useful when you’re making multiple selections among
many overlapping objects.

You can reselect confirmed selections in order to mark them for removal. Their
appearance in green indicates this action. When you confirm a green selection the
objects become deselected. Hence, red and green selections can exist at the same time

1-98 | U S E R ’S G U I D E A N D I N T R O D U C T I O N
as blue selections. A confirm-click at this point removes green selections, and red
selections turn blue.

A selection’s color—red, green, or blue—doesn’t matter from a physical point of


view. A selected object is always selected, whether it is confirmed or not.

Example
Proceeding from the previous example, click on the same spot as in the
single-selection example until you’ve selected the larger of the two faces. Confirm the
current single selection by clicking with the right mouse button (or Ctrl-clicking)
anywhere in the graphical interface main axes. The selected face now turns blue.

The selection of this face segment is now locked, and it won’t become deselected
when you make additional single or multiple selections. Click on the top face of the

THE FEMLAB GRAPHICAL USER INTERFACE | 1-99


middle cylindrical part of the clamp using the left mouse button and also confirm that
selection by right-clicking. The selection now looks like this:

DESELECTION
Clicking outside the geometry with the left mouse button deselects all unconfirmed
selections whereas confirmed selections remain intact. Deselection of a subset of
confirmed (blue) selections is possible by selecting the desired objects with the left
mouse button (the blue objects turn green) and removing them with a Ctrl-click or
by clicking the right mouse button. To deselect everything, including confirmed
selections, use Deselect All from the Edit menu or the shortcut Ctrl-d.

Example
Continuing from the previous example, left-click on the bottom face segment of the
cylindrical subdomain in the middle of the clamp. You now have two blue faces and
one red face selected. Click outside the geometry using the left mouse button and the
red selection disappears. However, the confirmed selections remain. To remove the
confirmed selection on the top of the cylindrical subdomain, click on the blue
circular-shaped face until it turns green. You will probably need to click twice because

1-100 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
the first click might result in selection of an underlying face object. The graphical
interface now has the following appearance:

At this point, clicking in the main axes using the right mouse button (or Ctrl-clicking)
removes the green selection. Now only one selection remains. Shift-click anywhere on
the geometry to add more selections. Press Ctrl-d or select Deselect All from the Edit
menu to deselect all faces.

LIST BOX SELECTIONS


In many dialog boxes, such as in the one for specifying boundary conditions, you can
select objects from within a list box. It is thus important to note that a direct
correspondence exists between selections that are active in a list box and selections in
the graphical interface main axes. Further, any list box selection overrides confirmed
selections in the graphical interface. Shortcuts for Select All and Deselect All also work
in list boxes.

DOUBLE-CLICKING
Double-clicking an object opens its associated dialog box. In 3D you do so with the
right mouse button; recall that a double-click with the left button is reserved for rapid
cycling between overlapping objects and adjacent objects when the target of selection
is ambiguous. You can use double-click in draw mode to open the object properties
dialog box, but only if a single geometry object is selected. In point, edge, boundary
and subdomain mode, double-clicking opens the point settings, edge settings,
boundary settings, and subdomain settings dialog boxes, respectively.

THE FEMLAB GRAPHICAL USER INTERFACE | 1-101


CLICK-AND-DRAG IN 3D
In FEMLAB you can make selections and rotate a geometry without pressing any
graphical interface buttons to change between the two operations. It is very
convenient to be able to work with both at the same time, such as using both rotation
and selection. In fact, any mouse-movement action available in the orbit/pan/zoom
toolbar can be active at the same time as selection. Selection is always available, but
you can deactivate mouse movement actions by pressing the Select button in the main
toolbar or by pressing the selected mouse movement action button once again. This
enables rubber band box selection.

In addition, the combination of the two makes it possible to cancel a pending


selection. When you click on an object in the graphical interface main axes while
holding the left mouse button, the object’s label appears in the coordinate field on the
Status bar. The interface doesn’t actually select the object until you release the mouse
button. If you move the mouse before releasing the mouse button, the interface never
selects the object and it instead executes the chosen mouse movement action. You can
verify this new condition by looking at the Status bar, where the name of the mouse
movement action now replaces the object label, or by looking at the mouse pointer,
which now takes on the shape of the current mouse movement action icon.

ADJACENCY SELECTION METHODS


In FEMLAB you can select 3D objects by clicking on them or on their adjacent
objects. However, an adjacent object is often next to more than one object. In such a
case you can either choose to select all adjacent objects or to cycle among them
(multiple clicking selects adjacent objects one at a time). These two methods of
selection are called adjacency selection methods, and controls for them appear on the
Rendering/Selection page in the Visualization/Selection Settings dialog box and at the
top of the select toolbar.

Example
Continuing from the previous example, go to boundary mode and turn on vertex
rendering by selecting the Render Vertices button in the select toolbar. At the top of
the select toolbar, make sure that the Cycle Adjacent button is selected in the first
group of buttons. Select Show Vertex Labels from the Labels submenu on the Options

1-102 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
menu. With the left mouse button click once on vertex 5 (to the lower left of the
middle cylindrical object) and you should see the following.

One of the face segments adjacent to the selected vertex is now selected. Click on
vertex 5 again. This action selects another of the adjacent faces. A third click on the
same vertex selects the last of the three adjacent faces, and repeated clicking continues
the cycle from the first selected face. Deselect the current selection by clicking outside
the geometry. Select the All Adjacent toolbar button at the absolute top of the select
toolbar. Click on vertex 5 again and all the adjacent faces are selected.

THE FEMLAB GRAPHICAL USER INTERFACE | 1-103


BOUNDARY SELECTION METHODS
When you click a face object in boundary mode, such as when selecting boundaries,
the clicked object is normally selected and highlighted according to your visualization
settings. However, a few shortcuts can help get a desired multiple selection. The
definitions of these shortcuts appear in the Boundary selection methods found on the
Rendering/Selection page in the Visualization Selection Settings dialog box. The
selection methods have corresponding toolbar buttons in the select toolbar.

• Normal face selection selects only the face segment being clicked. Multiple clicks
cycle among overlapping faces.
• All faces with same adjacent subdomains selects all face segments in the geometry
that have the exact same adjacent subdomains as the clicked face. Multiple clicks
cycle among overlapping faces.
• All faces adjacent to subdomain selects all faces on the subdomain that are adjacent
to the clicked face. If the face is adjacent to two subdomains, repeated clicking on
it cycles between the subdomains. In addition, multiple clicking on overlapping
faces cycles among the faces.

Example
Continuing from the previous example, open the Visualization/Selection Settings
dialog box from the Options menu. On the Rendering/Selection page, uncheck vertex
labels in the Labels frame and check the Face Labels check box. Make sure that the
Normal selection radio button is selected in the Boundary selection method frame
before clicking OK.

Select Enable Borders from the Boundary menu. Click on face 6 using the left mouse
button (you can also click on the label if desired). Doing so results in the single
selection of face 6 or any underlying face object. Now select the Cycle All Adjacent to
Subdomain button in the select toolbar. Click outside the geometry to remove the
current selection. Click on the label for face 6 (just to make sure you won’t select an
underlying object by mistake) and all the faces on the cylindrical subdomain get

1-104 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
selected. Click on the Headlight button in the orbit/pan/zoom toolbar to get a better
3D effect.

Change the boundary selection method by clicking the All with Same Adjacent
Subdomains button. Click outside the geometry to remove the current selection and
click on the label for face 6 again. This time you should see a hole in the lateral area
of the selection:

The difference between this selection and the previous one arises from the fact that
the differing faces are adjacent not only to the cylindrical subdomain but also to
another adjoining subdomain. Note that the differing faces are so-called internal

THE FEMLAB GRAPHICAL USER INTERFACE | 1-105


borders, in other words, they lie between two subdomains. You can select such faces
only when you’ve selected Enable Borders in the Boundary menu.

Suppression of Objects in 3D
If you want to select objects buried deep inside a complex geometry it might be useful
to suppress parts of the geometry. Another way to do so is with the tools on the orbit/
pan/zoom toolbar. They allow you to change the 3D view and thereby make it easier
to reach the desired objects. The suppression feature makes selected objects invisible
according to the visualization settings.

SUPPRESS ADJACENT OBJECTS


On the Rendering/Selection page of the Visualization/Selection Settings dialog box you
can specify which parts of suppressed objects to display. Each of the Vertices, Edges,
and Faces frames have a Suppress Adjacent check box. If you activate this selection for
an object type, adjacent objects of that type disappear from any object you suppress—
provided it’s not adjacent to another object that isn’t suppressed, as well.

The label of a suppressed object is always invisible. You can highlight a suppressed
object if you haven’t suppressed all of the highlighted object types. If a suppressed
object is highlighted in any way, you can then select it by clicking on an adjacent
object; otherwise you cannot select it by clicking. The only way to select a completely
suppressed object is from a list box, apart from the Select All menu item which selects
all objects including suppressed ones.

SUPPRESSING GEOMETRY OBJECTS


In 3D draw mode you can suppress geometry objects. Do so from the Geometry
Object Suppression dialog box that opens when you choose Suppress Object(s)… from
the Draw menu. The geometry object suppression affects only draw mode.

1-106 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
On the left side of the dialog box you select those objects you wish to suppress. You
can also select objects by clicking in the graphical interface main axes. Pressing Apply
or OK suppresses the selected objects. Now those objects are more or less invisible
depending on the visualization settings. The Select Current Suppression button is a
useful tool to quickly select all suppressed objects. The Cycle Suppression button
cycles the current suppression by extending the selection in the list box downwards
one step and removing a selection from the top. The Invert Suppression button
suppresses objects not currently suppressed and vice versa. To remove all
suppressions, press the Suppress None button or deselect all objects in the list box by
Ctrl-clicking and pressing the Apply button.

SUPPRESSING BOUNDARIES AND SUBDOMAINS


By selecting Suppress Boundaries… from the Boundary menu you can open the
Boundary Suppression dialog box. This dialog box looks like the geometry
suppression dialog box, but its list box contains boundary labels instead of geometry
object labels. The dialog box works in the same way as the geometry suppression
dialog box. Boundary suppression is available in boundary mode, mesh mode and
post mode. Similarly, on the Subdomain menu you can select Suppress Subdomains…
to open the Subdomain Suppression dialog box. Subdomain suppression is available in
subdomain mode, mesh mode, and post mode.

In mesh mode and post mode you cannot get visual feedback on the current selection
in the graphical interface main axes. Nevertheless, you can still open the boundary
and subdomain suppression dialog boxes to select and change the suppression of
boundaries and subdomains. In mesh mode, element selections in the mesh
visualization settings are added to the current suppression.

THE FEMLAB GRAPHICAL USER INTERFACE | 1-107


Modeling with FEMLAB
The objective of this section is to give an introduction to the FEMLAB modeling
process by working through a number of models using the GUI. All models are set
up from the start. You work your way through all the stages of modeling, from
geometry creation to the postprocessing of solution data. Communication with
MATLAB and Simulink is also described.

Style Conventions for the Model Descriptions


The basic flow of actions is indicated by the way the toolbar buttons and the menus
are ordered from left to right. You work your way from left to right in the process of
modeling, defining, solving, and postprocessing your problem using the FEMLAB
GUI. Considering this, a certain style convention, or format, is used throughout the
documentation for describing the models in the User’s Guide and Introduction, as
well as in the Model Library. The format includes a number of headlines
corresponding to each major step in the modeling process. The headlines also
roughly correspond to the different GUI modes.

MO DE L N AVIGATOR
The Model Navigator starts on the New page when initializing a model, if you have not
altered the preferences. Here you specify the space dimension (1D, 2D, or 3D),
application mode, and number of dependent variables. On the Multiphysics page, you
can also set up a combination of application modes. See the section “The Model
Navigator” on page 4-4 for details on the Model Navigator dialog box.

OPTIONS AND SETTINGS


This section covers the basic settings, for example, the axis or grid spacing settings.
These settings can usually be made with the Options menu or by double-clicking on
the status bar. See the sections “Options Menu” on page 4-34 and “The Status Bar”
on page 4-201 for details. You may also need to use the Add/Edit Constants dialog box
to enter model parameters.

DRAW MODE
Here you set up the geometry of the model. You need to know how to use the draw
menu and the draw toolbar. The details on this can be found in the sections “1D
Draw Menu” on page 4-71 for 1D geometry modeling, “2D Draw Menu” on page

1-108 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
4-54 for 2D geometry modeling, and “3D Draw Menu” on page 4-59 for 3D
modeling. It is advisable to get acquainted with 2D modeling before looking at the
3D modeling section. You can also refer to “The 2D Draw Toolbar” on page 4-187
and “The 3D Draw Toolbar” on page 4-189. For general information on the CAD
modeling features and how to use them, see “Geometry Modeling” on page 1-170.

BOUNDAR Y MODE, EDGE MODE, POINT MODE


In these modes, a standard table format is used to describe the settings in the
corresponding Specify Boundary/Edge/Point Settings dialog. For details on the
corresponding menu items, see the sections “Boundary Menu” on page 4-75, “Edge
Menu” on page 4-73, and “Point Menu” on page 4-72. The physics mode parameters
in the dialog boxes are discussed in “Application Mode Reference” on page 4-203.

SUBDOMAIN MODE
In subdomain mode, a standard table format is used to describe the settings in the
Subdomain Settings dialog. Details on the subdomain menu items can be found in the
section “Subdomain Menu” on page 4-81. The physics mode parameters in the
dialog box are discussed in “The Application Modes” on page 1-239 and
“Application Mode Reference” on page 4-203.

MESH MODE
Here you mesh the geometry of the problem. Normally you just need to click the
mesh buttons on the main toolbar. In some cases, you need to use the Mesh menu
described in the section “Mesh Menu” on page 4-90.

SOLVING
Often you only have to press the = button on the main toolbar. Sometimes you need
to open the Solver Parameters dialog box. See the section “Solve Menu” on page
4-102 for details.

POST MODE
The visualization settings are made here. You need to be familiar with the Plot
Parameters dialog box. See the sections “2D Post Menu” on page 4-127 and “3D Post
Menu” on page 4-156 for details.

Thermo-Electric Heating in a Bus Bar


This model examines the relationship between current throughput and temperature
inside a solid copper bar. Such bus bars are used as conductors in industrial

MODELING WITH FEMLAB | 1-109


environments requiring very high currents, for example, aluminum smelters and
certain chemical plants.

The thermo-electric coupling is two-way: volume currents inside the bus bar, which
are proportional to the conductivity, act as a distributed heat source, while at the
same time the temperature affects the metal’s conductivity. These kinds of
dependencies makes it necessary to create a multiphysics model.

As a first step, the stationary current distribution at constant temperature will be


modeled. It is highly recommended that you follow along with the description of the
modeling process in this example even if you’re not an electromagnetics expert. The
discussion focuses on how to use FEMLAB’s graphical interface rather than on the
underlying physics.

The second part of the example adds a heat transfer equation, bidirectionally coupled
to the stationary current model. This part is primarily about multiphysics modeling,
showing how to connect phenomena from different fields of physics. It also shows
how you define coupled variables, which can be, for example, an integral of the
solution, evaluated on some part of the model geometry.

1-110 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
GEOMETRY AND BOUNDARY CONDITIONS
The bus bar is mounted as an intermediate step between two high voltage cables and
a load. Because of the symmetry, it’s only necessary to model one half of the true
geometry.

The copper bus bar is electrically insulated everywhere, except for two contact plates
around the mounting holes. The temperature is constant on the contact plates, and
on the parts in contact with the load or mounting screw. All free faces have heat
transfer coefficients corresponding to free air convection, but the symmetry face is
isolated in all respects.

Symmetry face, no current


and no heat conduction

Constant temperature

Contact plates

MODELING WITH FEMLAB | 1-111


SETTING UP THE MODEL IN FEMLAB
Start FEMLAB either by typing femlab at the MATLAB prompt or by choosing
FEMLAB from the start menu, if you have a Windows PC. Either option first
invokes FEMLAB’s Model Navigator.

• Go to the New page, and select the 3D radio button. The space dimension should
always be selected first, as the Physics modes available differ.
• Select Physics modes, and expose its submenu by double-clicking on the tree view
control (the plus sign).
• Expand to the next submenu by double-clicking on Conductive media DC and select
Linear stationary.
• The default finite elements are second order Lagrange elements, Lagrange -
Quadratic. If you have limited memory and/or a very slow computer, you might
want to change to linear elements. Do this by selecting Lagrange - Linear from the
Element drop-down list.
• Press OK to confirm your choices and hide the Model Navigator.

Note This model can be found on the Model Library page under FEMLAB/
Multiphysics/bus_bar.

1-112 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
At this point, the graphical interface opens up in the Conductive media DC
application mode. You can always find out in which application mode the package is
presently running because its name appears on the bar at the very top of the
FEMLAB window.

Options and Settings


Entering the same numerical material data at different locations in the equations is
tedious, and makes it difficult to change the model. Therefore, FEMLAB lets you
introduce short-hand names for numerical constants and symbolic expressions. These
are defined using dialog boxes accessed from the Options menu in the main menu bar
at the top of the FEMLAB window.

Constants are global, that is, the same for all geometries and subdomains, and are
always evaluated once—when you press the Apply or OK button in the Add/Edit
Constants dialog box. They may depend on other user-defined constants, and contain
any scalar MATLAB expression.

Symbolic expressions are added and modified using the Expression Variable Settings
dialog box, also in the Options menu. Expression variables can have different
meanings on different parts of the model geometry, and may contain any variables
and expressions computable at the time the FEM problem is solved, for example the
solution itself, other expression variables, the space variables, and time. As the
expression definitions are linked to the geometry, they cannot be created until the
geometry has been drawn.

The most powerful option is the Coupling variables. These are a generalization of
expressions, which can define non-local couplings, including mesh transformations,
integrals over subdomains, and projections. The coupling variables are also the
foundation of FEMLAB’s Extended Multiphysics capabilities.

This model, in the end, uses all three kinds of variables. Now, before the geometry is
drawn, you can enter some constants that will be needed later on.

• Select the Options menu at the top of the FEMLAB window and choose Add/Edit
Constants.
• First add the resistivity of copper at room temperature: Enter rho0 in the Name of
constant field. Press Tab to move the cursor to the Expression field and enter
1.754e-8. The value is saved when you press Enter, press the Set button, or
otherwise leave the Expression field.

MODELING WITH FEMLAB | 1-113


• Go on adding the reference temperature, T0=293; the temperature coefficient,
alpha=3.9e-3; and the input voltage, V0= 50e-3.

• Finally, add a constant T with value 293, that will represent the real temperature
during the first part of the model. Later it will be replaced by the solution of the
coupled heat equation. Press OK.

Draw Mode
With the constants set, your first task in running a simulation is to define the model’s
geometry. For this task you need to work in draw mode. Conveniently, the graphical
interface automatically enters this mode when you exit the Model Navigator by
pressing the OK button.

When drawing objects, it’s often useful to take advantage of FEMLAB’s snap-to-grid
option, which is active by default (see page 4-35 of the Reference Manual for details
on making sure it is set or how to change its setting). Snapping makes it easier to align
the cursor to the grid and reach exact coordinate values.

The first part of this model is drawn in a 2D environment known as a work plane. See
“Boundary Modeling” on page 1-180 on how to create and edit work planes. The
default work plane is the x-y plane at z=0.

• Select Draw on the main menu bar of the FEMLAB window. Choose Work plane 1
at the very bottom to enter the default work plane. The toolbar on the left changes,
and the user interface is transfered to a 2D mode, almost identical to the draw
mode when creating a 2D model.

1-114 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
It is often necessary to adjust the settings of the graphical interface. For example, you
might wish to modify the axis limits if the geometry you wish to draw doesn’t fit the
default settings or, as in this example, is too small.

• On the menu bar at the top of the screen select the Options menu, and from the
drop-down choices choose Axes/Grid Settings...

• A dialog box opens up, and on the Axis page enter -0.16, 0.16, -0.08, and 0.08
as X min, X max, Y min, and Y max, respectively.
• Click the tab for the Grid page and deselect the Auto check box. Enter 0.02 as both
X spacing and Y spacing.

• Press OK to close the dialog box and to apply the settings.

Your next task is to draw one half of the S-shaped bus bar profile. This is most
conveniently accomplished using Boolean operations on primitives. When drawing
in a work plane or in a 2D model, you have access to rectangles and ellipses, as well
as polygonal lines, and second and third order Bézier curves. Using these, together
with Boolean operations, scaling, translation and rotation, almost anything can be
drawn.

MODELING WITH FEMLAB | 1-115


• First draw a circle with radius 0.06, centered at the origin. Press the Draw Centered
Ellipse draw toolbar button. It is the fourth button on the draw toolbar, which is
located on the left side of the graphical interface. Then, using the right mouse
button, click at the origin and drag the mouse, keeping the button down, until the
circle has the desired radius. Using the right mouse button ensures that a circle,
and not an ellipse, is drawn.
• Draw a second circle, also centered at the origin, but with radius 0.04.
• Select both circles. Either you can draw a rubber band box around both them, or
you can use Select All from the Edit menu, or simply press Ctrl-a to quickly select
all objects.
• Press the Difference button on the draw toolbar.

The next step is to cut one-eighth out of the ring created so far. This is done most
easily covering the desired part with a polygon and taking the intersection.

• On the draw toolbar, press the Draw Line button.

1-116 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
• Draw a triangle using the left mouse button: click in turn at (0,0), (0.06,0.06),
and(0,0.06). Press the right mouse button to close and solidify the curve.

• Select both the circle and the triangle, using one of the methods above or by
clicking them in turn, keeping the Ctrl key down.
• Press the Intersection button on the draw toolbar.

After this, a rectangle is added and joined to the left side of the ring section. When
unioning, intersecting and subtracting geometrical objects, the resulting composite
object still contains all original boundaries. These, so called, internal borders define
a number of subdomains, which can have different physics. In this case, you want the
S-shaped part to contain only two subdomains—the part you’re drawing, and its
mirror reflection. Therefore, you have to remove the inner border between the
rectangle and the ring section before continuing.

• Draw a rectangle with corners at (-0.1, 0.04) and (0, 0.06). Select the best drawing
tool for the job by pressing the Draw Rectangle button. Point the mouse at
(-0.1,0.04), press the left mouse button, drag the mouse to (0,0.06) and release
the button.

MODELING WITH FEMLAB | 1-117


• Once again, select all objects using one of the suggested techniques. Press the
Union button on the draw toolbar.
• The composite object still contains a border between the rectangle and the ring
section. Make sure the object is selected, and remove the border by pressing the
Delete Internal Borders toolbar button.

One half of the S-shaped profile is done. The next step is to move it to its final
position and make a copy, which is mirrored to produce the desired shape.

• Select the single composite object still remaining and press the Move toolbar
button. A small dialog box opens up.
• Enter -0.05/sqrt(2) both in the X-displacement and Y-displacement fields. Press
OK to move the symmetry line of the final shape to the origin.
• Copy the composite solid object by pressing the Copy button in the main toolbar,
choosing Copy from the Edit menu, or pressing Ctrl-c.
• Press the Paste button, or use the short-cut Ctrl-v, to open the Paste dialog box.
Enter 0 in the fields for both the X-axis displacement and the Y-axis displacement
and press OK.

1-118 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
• With the copy still selected, press the Scale button on the draw toolbar. Enter -1
as both X scale factor and Y scale factor. Press OK. This mirrors the copy in the line
y=x.

• Select both parts of the profile and press the Union toolbar button.

The 2D profile should now be extruded to produce a 3D solid object. FEMLAB can
create 3D objects from 2D profiles by extruding them along a line or revolving them

MODELING WITH FEMLAB | 1-119


around an axis. As will be seen later on, it’s also possible to embed 0D, 1D and 2D
objects directly into the 3D space.

• Choose Extrude... on the Draw menu. Make sure the single object CO1 is selected
in the list at the left of the dialog box that opens up.

• Enter 0.05 in the Distance field and press OK. The user interface switches to the 3D
view.
• Press the Zoom Extents button located on the main toolbar just below the menu
bar at the top of the screen. When you press it, FEMLAB automatically adjusts the
axes’ scales so the graphical interface displays the model geometry for optimal
viewing and manipulation.

The two holes for the fastening screws can be drilled using the cylinder primitive and
3D Boolean operations. It is easier, though, to position the holes and the
surrounding contact areas using work planes parallel to the surfaces in which the
contact areas should be embedded.

1-120 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
New work planes are created using the Add/Edit/Delete Work Plane dialog box, which
can be accessed from the Draw menu. This dialog box presents a number of alternative
ways for positioning new work planes, or moving the existing ones around. See
further “Boundary Modeling” on page 1-180. The only one you’ll need right now is
the utility that positions a work plane parallel to a face in the selected geometry
object.

• Select the S-shaped object and then choose Add/Edit/Delete Work Plane from the
Draw menu.
• Press the Add button to create a new work plane called Work plane 2, and then
go to the Face Parallel page.
• Click the Face positioning radio button to enable the face positioning mode. Select
face EXT1:2 from the list on the left side of the page. You can see the face
highlighted in the 3D view.

• To check how the local coordinate system of the new work plane is embedded in
3D space, press the Disp Coord button. A small triple of axes appear in the 3D view.
The blue x- and y-axes represent the local system of the created work plane, while
the green z-axis shows the direction of positive extrusion from the plane.

MODELING WITH FEMLAB | 1-121


Apparently, you’ll have to extrude a circle in the negative direction, to drill a hole
in the solid object.

• Press OK to close the dialog box and enter straight into the new work plane.

While modeling in the work plane, you can choose how much you want to see of the
full 3D geometry. The options are to project all 3D geometries, meaning that all 3D
edges are projected as blue lines onto the work plane; just show the edges actually
lying in the work plane; or show nothing at all. The second option is default.

• Check that the Project Work Plane Intersection draw toolbar button is selected.
This means that you can see only the contours of the face, parallel to which the
work plane is positioned. If you press the Zoom Extents button now, the view
adapts to the blue projected lines, and not to the objects you have drawn in the

1-122 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
work plane. Note also that the origin of the local system of coordinates is the lower
left corner of the projected face.

• Again, use Axes/Grid Settings, accessible from the Options menu, to change the
density of the grid. On the Grid page of the dialog box, deselect Auto, enter 0.01
as X spacing and 0.005 as Y spacing, and press OK.
• Draw a circle, centered at (0.04,0.025) and with radius 0.005.
• Create a solid 3D cylinder by selecting the circle, choosing Extrude... from the Draw
menu, entering a Distance of -0.02 and pressing OK.
• You’re now in 3D view and can see the new cylinder inside the S-shaped bar.
Choose Work plane 2 from the Draw menu to return to the work plane, from which
you also can embed the necessary contact area.

MODELING WITH FEMLAB | 1-123


• Everything you draw remains in the work plane until you delete it. Therefore you
can re-use the circle employed in creating the cylinder. Draw a second circle using
the same center point, but with radius 0.01.

1-124 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
• Select both circles and press the Difference draw toolbar button.
• Choose Embed... from the Draw menu, make sure the composite object CO1 is
selected in the list, and press OK.

The annular contact area is now embedded in the 3D view.

Now, you have to repeat the same steps for the second hole and contact area.

• Create a new work plane as before, but this time parallel to face EXT1:5. Check the
orientation of the local system of coordinates using the Disp Coord button.
• Adjust the grid settings and then draw a circle with radius 0.005, centered at
(0.06,0.025).
• Extrude the circle 0.02 units in the negative direction to create a cylinder.

MODELING WITH FEMLAB | 1-125


• Return to Work plane 3 and add a second circle with radius 0.01. Select both
circles and press the Difference button.
• Embed the annular contact area into the 3D view using Embed... from the Draw
menu.

The final step in the geometry modeling is to actually drill the holes and glue the
contact areas to the bar.

• Select all objects and press the Difference button on the draw toolbar. Note that
Boolean operations on solid objects do not affect embedded faces.
• Again select all objects, but now press the Coerce to Solid draw toolbar button. This
incorporates the contact faces into the bus bar.

Boundary Mode
Now that you’ve created the model’s physical geometry, it’s time to set its boundary
conditions. Everything that has to do with boundary conditions is handled in
boundary mode, using the options under Boundary in the main menu bar. To enter
boundary mode, press the Boundary Mode button in the main toolbar, or choose
Boundary Mode from the Boundary menu.

Boundary conditions are set in the Boundary Settings dialog box, which can be
opened from the Boundary menu, or by double-clicking anywhere in the model
window outside the model geometry. The Boundary Settings dialog box is customized
to fit the active application mode, because different modes support various types of
boundary conditions. The short-hand name of the active mode—in this case dc—can

1-126 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
be seen after the slash (/) in the title bar of the dialog box. This is important when
using different modes simultaneously in a multiphysics model.

When setting boundary conditions, you can select boundaries either by clicking or
drawing a rubber band box in the geometry; or by selecting from the Boundary
selection list in the Boundary Settings dialog box. To find out more about the flexible
selection tools in FEMLAB, see “Object Selection Methods in 3D” on page 1-95.

The bus bar is electrically insulated everywhere, except on the contact plates, of which
one is grounded, and the other held at a constant potential of 50 mV.

• Choose Boundary Settings from the Boundary menu to open the Boundary Settings
dialog box.
• First set an insulation condition everywhere: select all boundaries and click the
Insulation/symmetry radio button. The conditions on the contact plates will be
changed in the following steps.
• Select the first contact plate—boundary number 6—and click the Antisymmetry/
ground radio button. In the edit fields you can enter real or complex numbers or
even MATLAB expressions.
• Select the second contact plate, which is boundary number 20, click the Electric
potential radio button and enter V0 in the edit field.

• Close the Boundary Settings dialog box, pressing the OK button.

Subdomain Mode
Subdomains, in FEMLAB, are the different cells that the geometry is divided into. In
the subdomain mode, you set material properties (PDE coefficients). It is often
necessary to set different parameters for different subdomains.

MODELING WITH FEMLAB | 1-127


In the parameters, you can use MATLAB expressions that contain application mode
dependent variables, such as the electric potential V and its derivatives, making a
model nonlinear. In a multiphysics model, the dependent variables from all included
application modes are available to create couplings between the modes. Further, you
can always use the space and time variables, for example, x, y, z, and t.

You enter subdomain mode either by pressing the Subdomain Mode button in the
main toolbar, or by choosing Subdomain Mode from the Subdomain menu. Also,
opening the Subdomain Settings dialog box, by choosing Subdomain Settings... from
the Subdomain menu, automatically transfers the user interface to subdomain mode.

The only necessary parameters for the Conductive media DC application mode are
the conductivity, σ, and the distributed current source, Q. In order to prepare for the
multiphysics coupling introduced below, the conductivity is written as a nonlinear
expression of temperature, T, reference temperature, T0, resistivity at the reference
temperature, ρ0, and temperature coefficient, α, all of which have been entered as
constants into the model:

1
σ = -----------------------------------------------
ρ0 ( 1 + α ( T – T0 ) )

As the expression for σ will be needed more than once in the future, this is the right
time to introduce an expression variable.

• Choose Add/Edit Expressions from the Options menu. This opens the Expression
Variable Settings dialog box. As you can see, there are no expression variables
defined yet.

1-128 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
• Enter the name sigmaT in the Variable name field and press Add. This creates a new,
as yet undefined, expression variable named sigmaT.

• Go to the Definition page. Here you can give the expression variable different
meanings on different parts of the geometry or, as is more apropriate in this case,
the same meaning everywhere. Just enter 1/(rho0*(1+alpha*(T-T0))) in the
Expression field, and press OK.

Using the expression for σ, setting the actual material parameters is simple.

• Open the Subdomain Settings dialog box, by choosing Subdomain Settings... from
the Subdomain menu, or by double-clicking anywhere in the axes outside the
geometry.
• Select both subdomains. You can select subdomains both in the list on the left side
of the Subdomain Settings dialog box, and directly in the user interface, using
almost the same selection techniques as for boundaries.

MODELING WITH FEMLAB | 1-129


• Enter sigmaT in the Conductivity field, and set the Current source to 0.

• Press OK to apply the subdomain settings and close the dialog box.

In subdomain mode you can also enter initial values. The initial values are used as an
initial guess by the nonlinear and iterative solvers, and as initial conditions when
solving a time-dependent problem. As this particular model is linear and stationary,
the initial data has no effect and can be left at the default value, which is 0.

Mesh Mode
Because FEMLAB is based on the finite element method (FEM), it needs a
subdivision of the geometry known as a mesh. To create this representation you work
in mesh mode. For simple models, chiefly in 2D, you typically just click one of the
mesh buttons on the main toolbar; alternatively, you can ignore mesh mode and
solve the model directly.

For more complex models, more often than not in 3D, you’re better off trying to
create the most appropriate mesh for your specific needs. The default mesh is
sometimes, as in this case, too dense for a first solution. To change the mesh
parameters, you use the Mesh Parameters dialog box.

• Go to mesh mode by pressing the Mesh Mode button in the main toolbar, pressing
the Initialize Mesh button, or choosing Mesh Mode from the Mesh menu. This
creates a default mesh with roughly three thousand node points and twelve
thousand elements, as you can see in the message log at the bottom of the
FEMLAB window. Note that the automatic settings have created a mesh that is
rather dense close to curved surfaces, but quite coarse far from the smaller details
in the geometry.

1-130 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
• If you’re using second order elements (default) you should create a coarser mesh
to save memory and time. Open the Mesh Parameters dialog box by choosing
Parameters... from the Mesh menu.
• Make sure the Use default mesh settings check box is checked and select Coarser
from the drop-down list. This will create a much coarser mesh, but still one where
the element size varies greatly. To make the mesh smoother, also add a global limit
on the mesh element size: enter 0.011 in the Max edge size, general field.

• Press Remesh and then OK. The new mesh consists of slightly more than one
thousand nodes and almost five thousand elements.

MODELING WITH FEMLAB | 1-131


Note that the number of nodes in the mesh is the same as the number of degrees of
freedom only when using linear elements. If higher-order elements are used, extra
degrees of freedom are introduced.

Solving
Before solving, you can fine tune your solver parameters in the Solver Parameters
dialog box, a step not strictly necessary for this model. You can adjust solver
parameters to achieve higher accuracy or to gain greater control over nonlinear or
time-dependent models. For linear 3D models, the iterative solver with Incomplete
LU preconditioner is default, and does a fair job on this problem. Equations of
Poisson type are, however, solved much more efficiently using the Algebraic
Multigrid preconditioner.

• Open the Solver Parameters dialog box, by choosing Parameters... from the Solve
menu, or pressing the corresponding toolbar button.
• Go to the Iterative page and select AMG from the drop-down list under
Preconditioner. Press OK.

• To solve the model, press the Solve Problem button on the main toolbar. Solving
can require anything from 13 seconds up to a couple of minutes depending on
your computer.

Post Mode
When the solution is ready, FEMLAB automatically transfers to post mode and the
solution is plotted. The default 3D plot is displayed on five evenly spaced cross

1-132 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
sections of the geometry parallel to the y-z plane. Which quantity is plotted depends
on the application mode. In the Conductive media DC application mode, it is the
potential, V.

It is extremely useful to examine solution results in a graphical form. Therefore


FEMLAB’s post mode provides plenty of visualization tools, which you access
through the Plot Parameters dialog box. You can switch quickly between the standard
plot types by simply pressing corresponding buttons on the plot toolbar, the default
toolbar in this mode. Other powerful options include plotting expressions evaluated
on faces, edges, cross sections and lines in separate windows and integrating
expressions over subdomains or boundaries.

• Try out the buttons on the plot toolbar.

The Slice plot, Isosurface plot and Tetrahedron plot all by default plot the same scalar
variable, in this case the potential V. The Arrow and Flow plots are used to visualize
vector fields. The default vector field for the Conductive media DC application mode
is the current density vector, J. The Surface plot, finally, plots the normal component
of the default vector field. If you try it out, you can see that the current enters at one
of the contact plates and exits at the other, the rest is insulated, just as expected.

The easiest way to get a good visualization of the solution is often to start from the
default plot given by one of the buttons on the plot toolbar. Then you open the Plot
Parameters dialog box, and change the parameters until you’re satisfied.

MODELING WITH FEMLAB | 1-133


• For example, first press the Isosurface toolbar button. Open the Plot Parameters
dialog box by pressing the Plot Parameters button in the main toolbar, or by
choosing Plot Parameters from the Post menu.
• Increase the number of isosurfaces: Go to the Isosurface page and enter 20 in the
Isosurface levels field. You can also specify manually, as a MATLAB vector, at what
values the isosurfaces are drawn. Try, for example, linspace(0,0.01,10).
Always press Apply to see the changes.

• Then add, for example, a flow plot. Go to the Flow page and check the Flow plot
check box on the top left. Then decrease the number of streamlines by entering 7

1-134 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
in the top field in the Streamline parameters frame, and make them red, selecting
from the Streamline color drop-down list.

• Press OK to close the dialog box and see the final result. Add some light by pressing
the Scenelight or the Headlight button on the draw toolbar.

Integration on Boundaries
One interesting property of a bus bar is its lumped resistance, that is, the total
resistance of the bus bar when incorporated in an electric network. The lumped
resistance is defined as the applied voltage divided by the associated total current. The

MODELING WITH FEMLAB | 1-135


total current is found by integrating the normal component of the current density
over the internal border between subdomains 1 and 2. Integration on boundaries is
controlled from the Boundary Integration dialog box, which can be opened from the
Post menu.

• Choose Boundary Integration... from the Post Menu. Select boundary 13 in the list
on the left. This is the internal border between the two subdomains in the model.

• Enter dncu in the Expression field, check the Export result to workspace box and
press OK. The reason that you cannot use the predefined current density variable
nJ is that it represents a jump in the current density rather than the current density
itself. To read more about the dncu variable, see “Boundary Coupled Equation
Variables” on page 3-70 in the Reference Guide.

The total current is now present in the MATLAB workspace, as a variable called ans.
The ans variable always contains the result of the last calculation. Therefore, it will
be overwritten by the next operation in the workspace. So, you should make a copy
under a different name. Then calculate the resistance.

• At the MATLAB prompt, write


Itot = ans

• Now find the lumped resistance by writing

R = 0.05/Itot

also at the prompt. The result is displayed immediately.

Annotations in Separate Figure Window


If you choose to plot the solution not in the user interface, but in a separate
MATLAB figure window, you gain access to MATLAB’s tools for setting figure

1-136 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
properties. Further, you can use the versatile printing routines available in MATLAB
to produce prints and image files on various formats.

• To plot results in a separate MATLAB figure window, again call up the Plot
Parameters dialog box. Go to the General page and deselect the Plot in main GUI
axes check box. Press OK to create the plot.

• To remove the axes from the figure, you can enter


axis off

at the MATLAB prompt. If you use MATLAB 5.3 or later, you can write
cameramenu

to get access to a number of tools letting you move the camera around, change the
lighting and other rendering options.

MODELING WITH FEMLAB | 1-137


• You also have access to all of MATLAB’s annotation tools. For instance, to add
some descriptive text inside the figure window, press the Add text toolbar button,
click in the window and start writing.
• You can also add objects such as lines and arrows. MATLAB’s documentation
provides details on how to create annotations in figure windows.

Pure copper

Contact plate, 50 mV
Contact plate, grounded

Saving
• To save the model, including all settings in the graphical user interface, go to the
File menu on the menu bar at the top, then select Save As and Model MAT-file….

It is also possible to save the model as a MATLAB script file for parameterized
models and optimal design by selecting Save As and Model M-file…. A description of
the Model M-file concept appears in this book in the section “Model M-files” on page
1-51.

Thermo-Electric Heating in a Bus Bar with Multiphysics


In the first step of modeling the thermo-electric heating in a bus bar, the stationary
DC current distribution at constant temperature was found. See “Thermo-Electric
Heating in a Bus Bar” on page 1-109 above for instructions on how to create and save
the first part of the model. Here you’ll add an application mode for heat transfer and

1-138 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
couple the equations. You also need an extra point in the geometry, where you can
define the total current, using a coupling variable. Then a time-dependent simulation
will be run, and the total current and the lumped resistance of the bus bar as functions
of time can be plotted.

Loading Previously Saved Model


If you’ve previously saved the results from the first part of the model as a Model
MAT-file (.mat) or Model M-file (.m), you should now load it into the user interface.
When you, as in this case, want to continue modeling in the user interface, you
should save your model as a binary Model MAT-file. These can be loaded complete
with solution and all, while the text-based Model M-files have to recreate the final
state by repeating all steps in the solution. The Model M-files, however, have other
advantages; see “Model M-files” on page 1-51.

• To load the previously saved model, choose Open from the File menu, and then
Model MAT-file or Model M-file, as appropriate, in the submenu. You can also press
the Open button on the main toolbar to load a Model MAT-file.
• Locate your model file and press OK.

Options and Settings


The first thing you have to do is remove the constant T, otherwise it will conflict with
the solution T in the heat transfer equation.

• Choose Add/Edit Constants... from the Options menu. Select the constant T and
press the Delete button. Press OK to close the dialog box.

Multiphysics
Now add the Heat transfer application mode. Additional modes are added using the
Model Navigator, which for this purpose can be accessed from the Multiphysics menu.
You also should change the solution form from Coefficient form to General form.
This is necessary because in Coefficient form, the nonlinear couplings between the
electric potential V and the temperature T aren’t considered when assembling the
Jacobian (essentially the same as the stiffness matrix for a linear stationary problem).
The correct Jacobian is essential in order to obtain good convergence from the
nonlinear and time-dependent solvers. See “The Nonlinear Solver” on page 3-108
and “The Time-Dependent Solver” on page 3-112, both in the Reference Guide.

• Choose Add/Edit Modes... form the Multiphysics menu. The Model Navigator—the
same dialog box that is used for creating new models—opens up on the
Multiphysics page. The other pages are inactive; they are only accessible when
creating a new model, or loading an old one.

MODELING WITH FEMLAB | 1-139


• Select Heat transfer in the application mode list on the left. Note that the default
name of the dependent variable is T and the Element type is Lagrange - Quadratic.
Accept this and add the Heat transfer mode to the model by pressing the right
arrow (>>) in the middle of the dialog box.
• Change Solver type to Time dependent and Solution form to General, by
selecting from the corresponding drop-down lists.

• Press OK to accept the choices and close the Model Navigator. The user interface is
now in Heat Transfer mode, as can be seen in the title bar of the FEMLAB window.

Draw Mode
A coupling variable representing the total current flux from subdomain 2 to
subdomain 1 will be introduced below. Coupling variables must have a source—in
this case boundary number 13—and a destination. As the total current is a scalar
value, it makes sense to have it defined on a point, and also to embed a new point for
this purpose.

1-140 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
• Enter Work plane 1 by choosing from the Draw menu. Press the Draw Point button
on the draw toolbar and draw a single point at (-0.14,-0.04).
• Choose Embed... from the Draw menu. Make sure only the point PT1 is selected in
the list, and press OK.
• The new embeded point is invisible in the 3D view until you press the Render
Vertices button on the select toolbar next to the draw toolbar.

Boundary Mode
The boundary conditions for the Heat transfer mode are somewhat more
complicated than for the Conductive media DC mode: One face, the inside of one of
the fastening holes, and the contact plates are kept at a constant temperature equal to
the temperature of the surrounding air. The free faces have a heat transfer coefficient
of 10, while on the inside of the other hole it’s only 5. Finally, one of the end surfaces
has an Insulation/symmetry condition, representing the fact that the modeled bus bar
is mounted end-to-end with another, of similar shape.

MODELING WITH FEMLAB | 1-141


The following table contains an overview of the boundary conditions. You’ll meet
more tables like this one in the rest of the examples in this book, and also throughout
the Model Library.

BOUNDARY 1-4, 11-19 5-10, 20 21-24 25

Type Flux Temperature Flux Insulation/symmetry


q 0 - 0 -
h 10 - 5 -
Tinf T0 - T0 -
Const 0 - 0 -
Tamb 0 - 0 -
T - T0 - -

• Choose Boundary Settings from the Boundary menu. Note that the title bar of the
dialog box now reads Boundary Settings/ht, to show that you’re working with the
Heat transfer mode.
• Select boundaries 1-4, 11-19 and 21-24, and press the top radio button for a flux
condition. Enter 10 in the h field and T0 in the Tinf field.

• Deselect all boundaries except 21-24 and change h to 5.


• Select boundaries 5-10 and 20, select the Temperature radio button and enter T0
in the edit field.
• Finally, select boundary 25 and select Insulation/Symmetry. Press OK.

1-142 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Subdomain Mode
The application mode specific material parameters for the Heat transfer mode are
density, ρ, heat capacity, C, thermal conductivity, k, and volume heat source Q. The
heat source in this case is the electrical heating, which depends on the solution from
the Conductive media DC problem. The heating power per unit volume from the
current density J is:
2
J 2 2
P = ------ = J ⋅ E = σE = σ ∇V
σ

where E is the electric field and V the potential—the dependent variable in the
Conductive media DC application mode. The conductivity, σ, is temperature
dependent, as before. The heat source is best entered using an expression variable.

• Choose Add/Edit Expressions... from the Options menu. Enter the new expression
name Qj and press the Add button.
• On the Definition page, set the variable to mean sigmaT*(Vx^2+Vy^2+Vz^2) on
the geometry level. Press OK. Note that the new expression variable includes the
old sigmaT in its definition.

MODELING WITH FEMLAB | 1-143


Now enter the material parameters (PDE coefficients) according to the following
table, and set the initial conditions:

SUBDOMAIN 1,2

ρ 8960
C 340
k 384
Q Qj

• Choose Subdomain Settings from the Subdomain menu. Select both subdomains
and enter the values for ρ, C, and k, and write Qj in the Q field.

• Click the Init tab to show the Init page. Still with both subdomains selected, enter
T0 in the T(t0) field. This begins the simulation from room temperature.

It is important that your initial conditions are consistent. Now that you have set an
initial temperature, you should set an initial condition for the electric potential
corresponding to the stationary solution of the Conductive media DC problem at the

1-144 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
same temperature. This you can accomplish by setting a previously stored solution as
initial condition for the following calculations.

• Choose the Conductive media DC application mode from the bottom of the
Multiphysics menu. This transfers the user interface and all open dialog boxes to the
Conductive media DC mode.

• Enter V in the V(t0) field and press OK to confirm and close the Subdomain
Settings dialog box.
Now add a coupling variable which puts the value of the integral of the current flux
over the border between subdomains 1 and 2 into point number 1, the single point
embedded above.

• Choose Add/Edit Coupling Variables... from the Options menu. This opens the
Coupling Variable Settings dialog box. Enter the variable name I of type Scalar and
press Add.

MODELING WITH FEMLAB | 1-145


• Go on to the Source page. Choose Level boundary from the drop down list, and
then select boundary 13.
• Enter the Integrand unga1 and Integration order 4.

The variable nga1 is a so called coupled boundary variable that in general form
defines the normal flux on the boundary. On an outer boundary you would use just
nga1, or even simpler, the postprocessing variable nJ—the normal component of the
current density vector. But, for internal borders these are averages of the currents as
evaluated on the up and down side of the border, which is generally zero; that is nga1
is the jump in the flux. unga1, on the other hand, is the flux out of the upper
subdomain, and therefore into the subdomain on the down side. Se further “The
FEMLAB PDE Language” on page 1-336 in this book.

• Proceed to the Destination page, where you choose Level point and select point 1.
Check the box Active in this domain and press OK. You now have a variable I

1-146 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
defined on point number 1, whose value is always the total current through the
bus bar.

Mesh Mode
As you have changed the geometry, the mesh will be re-initialized when you enter
mesh mode. The settings in the Mesh Parameters dialog box are also lost, so you have
to reenter them to create practically the same mesh as before.

• First select Use default mesh settings and Coarser. Then enter a Max edge size,
general of 0.011 and press OK.
• Press the Initialize mesh button on the main toolbar.

Solving
This time you’re going to use the time-dependent solver. You always have to specify
the time interval for the solution. Normally, it’s best to specify exactly at what times
the solution should be stored, as the timestepping algorithms calculate the solution
at more points in time, than you probably want to keep. That is, the timestepping
algorithms use automatic time step control, but you can specify certain times for
which the solution will be interpolated and stored.

If the output times are given as a MATLAB vector of more than two elements, they
are considered to be times for storing the solution. If, on the other hand, the output
times are given as a vector of only two numbers, these are taken as start and end
points of an interval where all time steps, as decided by the timestepping algorithm,
should be saved.

• Open the Solver Parameters dialog box by pressing the Solver Parameters button
on the main toolbar. Among the Advanced options on the General page, you find
Direct linear solver. If you are running MATLAB 6.0 or later, select SuperLU; this
solver works better than the built-in MATLAB solver for large problems, which
may require virtual memory.
• Click the Timestepping tab.
• In the Output times field, enter 0:5:180, which means that the solution will be
saved every five seconds during three minutes.

MODELING WITH FEMLAB | 1-147


• Select the fldae Timestepping algorithm. The ODE system at hand is a
differential-algebraic equation (DAE), because it contains no time derivatives of
the potential V. In other words, the mass matrix is singular.

• As the system is a DAE, the accuracy in the potential V will be within tolerance,
given enough accuracy in the temperature T. Therefore set the Absolute tolerance
to T 0.0001 V inf. This means that there is no explicit limit on the accuracy in
V. Also, change the Relative tolerance to 0.001.
• Go to the Multiphysics page and press the Store Solution button. This stores the
previous solution for the electric potential V, so that it can be used as initial value

1-148 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
for the multiphysics problem. Press OK to confirm and close the Solver Parameters
dialog box.

Note This problem requires approximately 500 MB of memory. When using the
SuperLU linear solver, solving in virtual memory (“swap”) is reasonably efficient. It
is also possible to reduce the memory requirements by selecting Solution form
coefficient on the General page of the Solver Parameters dialog box (300 MB) or
switching to linear elements (150 MB). The former option gives an accurate result,
as the tolerances are always met, but forces the timestepping algorithm to take more
and shorter steps. The latter alternative gives a much faster, but less accurate,
solution.

• Press the Solve Problem button in the main toolbar to solve the problem. The time
required to solve the problem on a 1.5 GHz Pentium 4 is approximately 529
seconds.

Post Mode
The current plot settings in the Plot Parameters dialog box are used when the new
solution is plotted. Only the last time step is plotted automatically. This time, you’ll
rather want to have a look at the temperature distribution in the bar.

• Open the Plot Parameters dialog box. Deselect Flow lines under Plot type on the
General page.

MODELING WITH FEMLAB | 1-149


• Continue to the Isosurface page and select temperature (T) from the Isosurface
expression drop-down list. Press Apply.
• Return to the General page and have a look at the solution at some earlier
timesteps. You choose which time to display by selecting from the Solution at time
drop-down list. Do not forget to press Apply.

Animating the Solution


The time evolution of a model can be visualized by displaying the saved solutions as
an animation. Surface plots often look particularly good as animations.

• Open the Plot Parameters dialog box, deselect the Isosurface plot, select Surface
instead and change the Surface Expression on the Surface page to temperature
(T). Press OK.
• Press the Animation button on the plot toolbar. A MATLAB figure window opens,
where the animation is first recorded frame by frame and then played five times. If
you press the animation button again, the movie is played directly without the
recording step.

Plotting the Resistance


To plot the time evolution of the lumped resistance, you can use the cross-section plot
facilities for nodes. As the total current already has been extracted out to the free-lying

1-150 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
point, all that is needed is to plot the specified voltage 50 mV divided by this value
for all time steps.

• Open the Cross-Section Plot Parameters dialog box, by choosing Cross-Section Plot
Parameters... from the Post menu. Click Point under Plot type and select all time
steps in the Solution at time list.

• On the Point page, choose to plot data for vertices rather than for specified
coordinates by clicking the Vertices radio button under Select point via. Then select
vertex number 1 from the list. Enter V0/I in the Point Expression field.

MODELING WITH FEMLAB | 1-151


Return to the General page and set a title for the plot: Activate the Title edit field by
clicking the radio button just to the left of it. Enter, for example, Lumped
resistance as function of time. Then change the Y-axis label to read
Resistance, and press OK.

Exporting Data to Text File


The plotted data in the cross sectional plot above can also be exported to a text file.
The data in the text file can then be loaded into other programs, such as Microsoft
Excel. A text file with the plot data is generated by first extracting the values used to
generate the plot above, using the corresponding command line function
postcrossplot at the MATLAB command prompt, followed by issuing the
MATLAB command save -ascii to save the plot data to a text file.

• Start by exporting the FEM structure to the command line by selecting Export FEM
structure as ‘fem’ in the File menu or by pressing the ctrl-f key.
• Extract the plotted data in the cross sectional plot by issuing the following
command at the MATLAB command prompt (for a description of
postcrossplot type help postcrossplot at the MATLAB command prompt).
[h,data] = postcrossplot(fem,0,1,’Pointdata’,’V0/I’,...
’Solnum’,1:37);

• Create a matrix with the x-data and y-data values from the structure data.

1-152 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
resistance = [data.XData(:) data.YData(:)];

• Save the data values in the matrix resistance to a text file called
Resistance.txt.

save Resistance.txt resistance -ascii

The data in the text file Resistance.txt can now be loaded into Microsoft Excel
and be used in creating a diagram.

Controlling Temperature, Exporting to Simulink®


This model simulates a heated metal block with a thermal controller, and
demonstrates how to set up communication between FEMLAB and Simulink.

It is also possible to simulate this system without Simulink by using a FEMLAB


model with two geometries and non-local coupling variables to implement the
interaction between the equations in the two geometries. The model
thermal_controller_ode follows on page 2-288 in the Model Library, showing
how to set up this alternative formulation.

Note The second part of this model requires Simulink on your system.

MODELING WITH FEMLAB | 1-153


The study of this thermal controller involves two distinct modeling situations:

• Taken as a whole, this dynamic system assumes only a small number of states,
making it a good candidate for modeling and simulation with a package such as
Simulink.
• One of the model’s elements, the controller, contains a subsystem that involves
heat distribution. You can model that phenomenon with a PDE, the well-known
heat equation. It is easy to break this portion of the problem down and describe it
in FEMLAB.

The dynamic system consists of a metal block that exchanges heat with the
environment. A heater and a thermostat switch are situated inside the glass-enclosed
system, which works in a simple manner: The thermostat turns the heater on or off
when the temperature becomes too low or high.

Metal Block
Thermostat Heater Temperature

Exterior
Temperature

The finite-element model of the metal block requires two inputs:

• The state of the heater, which can be On (1) or Off (0).


• The exterior temperature, Tout.

As its output, the model supplies the temperature at the thermostat’s location.

The PDE describes the overall system’s temperature distribution given the
temperature of the heater and the exterior environment. If the heat transfer is so rapid
such that for all practical purposes the heat distribution is constant (in space, not in
time), a single state is sufficient. One way to simplify the solution is to replace the
PDE with a gain function, thereby reducing the modeling process to computing the
effective heat conductance. Otherwise, you must merge FEMLAB into the Simulink
environment, a task this model illustrates.

1-154 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The heat equation is:

∂T
ρC ------- – ∇ ⋅ ( k∇T ) = Q.
∂t

The boundary conditions come from the level of insulation around the system. On
well-insulated sides the temperature flux is zero, which gives the Neumann boundary
condition n ⋅ ( k ∇T ) = 0 . The poorly insulated sides involve the Neumann
condition n ⋅ ( k ∇T ) = k g ⁄ lg ⋅ ( T out – T ) , where kg and lg are the thermal
conductivity and the thickness of the glass sheet that separates the metal block and the
exterior.

Heat source
Glass
layer
Thermostat

Insulation

For the purposes of this discussion, assign system objects with some specific
characteristics as noted below. Since we are only interested in the temperature
distribution in the xy-plane, the model is carried out in 2D. For the units to make
sense, you have to think of the domain as having a depth (z-direction) of 1 m.

FEMLAB doesn’t specify any units, which allows you to choose any self-consistent
system. This model, as the rest of the Model library, is based on the SI system. But,
to more appropriately represent the time scale of the problem, the time is counted in
minutes. This means that all involved quantities whose units contain the basic unit of
time must be scaled by a factor 60 compared to their standard SI values. This
conversion is carried out below for the thermal conductivity k and the heat source Q,
before the values are entered into FEMLAB.

Metal block:

• Dimensions 30 × 20 x 100 cm = 0.3 × 0.2 x 1 m


• Density ρ = 7.82⋅103 kg/m3

MODELING WITH FEMLAB | 1-155


• Heat capacity C = 449 J/kg⋅K
• Thermal conductivity k = 82 W/m⋅K = 4.92⋅103 J/m⋅min⋅K

Glass sheet:

• Thermal conductivity kg = 0.9 W/m⋅K = 54 J/m⋅min⋅K


• Thickness lg = 1 mm = 10-3 m

Heater:

• Dimensions 4 × 4 × 100 cm = 0.04 × 0.04 × 1 m


• Heat source Q = 2 kW / Vheater = 2e3 / (1⋅0.042) W/m3 = 7.5⋅107 J/m3⋅min

M O D E L I N G T H E T I ME - D E P E N D E N T TE M P E R AT U RE D I S T R IB U T I O N
Before exporting the model description to Simulink, you should run a
time-dependent simulation in FEMLAB.

Model Library FEMLAB/Multidisciplinary/thermal_controller

Model Navigator
• On the New page, double-click on Physics modes, then double-click on the Heat
transfer tree control to expand it. Select the Time-dependent tree control and press
OK to close the Model Navigator. Second order Lagrange elements are used by
default.

Draw Mode
• First modify the scales of the user-interface coordinate axes to fit the size of the
metal block (0.3 × 0.2 m). Choose Axes/Grid Settings from the Options menu. On
the Axis page, enter –0.1, 0.4, –0.05, and 0.25 as X min, X max, Y min, and Y max,
respectively.
• On the Grid page, deselect the Auto check box and insert 0.08 and 0.12 as extra
ticks for the x- and y-axis. Enter 0.05 for both x-spacing and y-spacing. Press OK to
close the dialog box.
• Press the Draw Rectangle button to create the object that represents the metal plate.
• Position the pointer at (0,0), press the left mouse button, move the pointer to
(0.3,0.2) and release the button. A rectangle denoted R1 appears. (By
double-clicking on the rectangle you can check its coordinates.)

1-156 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Next model the heater as a small rectangle within Rectangle R1:

• Press the Draw Rectangle button.


• Draw a rectangle with corners at (0.08,0.08) and (0.12,0.12). An object
designated R2 appears.

You now need two points in the geometry model to measure temperature in the
metal plate.

• Press the Draw Point button.


• Click at (0.05,0.1) to draw the first point.
• Press the Draw Point button again and draw another point at (0.2,0.1).

Options and Settings


Before specifying the PDE and boundary parameters, define the constants
HeatState and Tout as below.

NAME EXPRESSION

HeatState 1
Tout 20

• Open the Add/Edit Constants dialog box on the Options menu. Enter the name
HeatState and the value 1, then press the Set button. Do the same for the
constant Tout using the value 20. Press the OK button. Note that at this time

MODELING WITH FEMLAB | 1-157


you’re specifying arbitrary values for the constants; they assume new values when
you run the model in Simulink.

Boundary Mode
Enter the following boundary conditions:

BOUNDARY 1 2,3,8

Type Convection Insulation/


symmetry
q 54/1e-3*Tout
h 54/1e-3

• Open the Boundary Settings dialog box by selecting Boundary Settings… from the
Boundary menu.

1-158 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
• For the insulated sides (boundaries 2, 3 and 8) use the Insulation/symmetry
boundary condition.
• For the poorly insulated side (boundary 1) specify an Inward heat flux of 54/
1e-3*Tout and a Heat transfer coefficient of 54/1e-3.

• Press OK to close the dialog box.

Subdomain Mode
Enter PDE coefficients according to the table:

SUBDOMAIN 1 2

ρ 7.82e3 7.82e3
C 449 449
k 4.92e3 4.92e3
Q 0 7.5e7*HeatState

• Open the Subdomain Settings dialog box by selecting Subdomain Settings… from
the Subdomain menu.
• Assume the metal plate is iron. For both subdomains enter the values ρ = 7.82e3,
C = 449, and k = 4.92e3, corresponding to the Density, Heat capacity and Coeff.
of heat conduction, respectively.

MODELING WITH FEMLAB | 1-159


• The Heat source Q equals 0 for the metal block (Subdomain 1) and
7.5e7*HeatState for the heater (Subdomain 2).

• Click the Init tab and enter the initial value 20 for T(t0) for both subdomains. Press
OK to close the dialog box.

1-160 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Mesh Mode
• Open the Mesh Parameters dialog box by selecting Parameters… from the Mesh
menu.
• Set the Max. edge size, general to 0.05 and press OK.

• Press the Initialize Mesh button. The mesh parameter settings generate a mesh
coarser than the default.

MODELING WITH FEMLAB | 1-161


Solving
• Select Show Vertex Labels on the Options menu. In the GUI it’s clear that the two
points where you expect to detect the temperature have the numbers 3 and 8.
• Open the Solver Parameters dialog box by selecting Parameters… on the Solve
menu.
• To run a simulation from 0 to 20 minutes, go to the Timestepping page and set
0:1:20 for the Output times.

• Press the Solve Problem button to start the simulation. (Time to solve: 8 s)

1-162 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
A plot of the surface temperature at Time = 20 appears as in this figure:

You can also run an animation by pressing the Animation button.

S IM U L I N K E X P O R T A N D TE M P E R ATU RE C O N TRO L
As mentioned before, it’s possible to model the temperature control system without
using Simulink and an implementation of this follows from “Controlling
Temperature using Non-local Coupling Variables” on page 2-288, along with a short
discussion of some of the advantages and disadvantages of each approach. In this case
it’s preferable to use Simulink because of the nature of the control mechanism, but
the alternative is included as an illustration.

The result of exporting a model from FEMLAB to Simulink is a structure in the


MATLAB main workspace. To use the model in Simulink, simply drag the FEMLAB
Subsystem block to your Simulink model as described below.

The following variables affect the temperature of the metal block:

• the exterior temperature, Tout


• the state of the heater, HeatState, which can assume the values 1 or 0,
corresponding to On or Off, respectively.

The output from the FEMLAB model is the temperature in the block where the
thermostat is located:

• thermostat temperature, Temp

MODELING WITH FEMLAB | 1-163


You’ll need this variable to control the heater.

• Open the Export Simulink Model dialog box from the File menu.
• Specify the Structure name blocksct. This structure contains the FEMLAB data.
• Check the Use state-space model check box to linearize the model. Because the
FEMLAB model is linear, the linearization doesn’t change the solution’s accuracy.
Using the state-space version of the FEMLAB model prevents MATLAB from
calling the FEMLAB kernel from within Simulink, saving computation time.
• To verify that you’re working with the correct input variables, check that the
variable names HeatState and Tout appear below the Add/Edit Constants button.
• Press the Add button, then set the output to be the first component of the solution
at node 3 by entering 3 in the edit field for Node no.
• Set the Output variable name to Temp.
• Press OK to export the model.

• Start Simulink by typing simulink in the MATLAB Command Window.


Immediately draw a model as shown below. You can find the FEMLAB Subsystem
block under FEMLAB in the Simulink library. Refer to the Simulink manual for
more information about creating models. Alternatively, you can load a prewritten

1-164 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
model from the FEMLAB Model Library into Simulink: .../models/FEMLAB/
Multidisciplinary/thermal_controller_mdl.mdl.

• To set up the input and output ports of the FEMLAB Subsystem block, double-click
on that block and set the structure name to blocksct. Press OK to close the dialog
box.

• Specify the values of the constant blocks for Thermostat Setting and Average
Exterior Temperature as in the previous figure.
• In the Relay block, enter the value 1 as the Switch on point and -1 as the Switch off

MODELING WITH FEMLAB | 1-165


point.

• In the Sine Wave block, set the Amplitude to 10 and the Frequency to 2*pi/120,
which corresponds to a period of 120 minutes.

• Open the Simulation Parameters dialog box by making a selection from the
Simulation menu. Set the Stop time to 240 minutes and the Solver to ode15s. The
stability of discrete heat equations is known to put severe constraints on the time

1-166 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
step of explicit methods. Thus you should select the ode15s solver (implicit) rather
than the explicit integrators.

• Now solve the system by selecting Start from the Simulation menu.

MODELING WITH FEMLAB | 1-167


• To view the temperature at node 3, double-click on the Scope block. The result
from the simulation appears in the figure below.

• Finally switch node 3 for node 8 in the Export Simulink Model dialog box, and press
OK once more. Then restart the simulation in Simulink.

Note a few interesting details in the solutions. For instance, the distance between the
thermostat and the exterior has an effect on the delay between the peaks of the two
curves. Node 8 is further away from the exterior compared to node 3, and the delay
is obviously larger in the second plot than in the first.

Note also the qualitative differences between the two simulations. This extra
information comes as a bonus for solving a detailed heat-flow problem that takes into

1-168 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
account geometry and heat-diffusion properties. Of course, you pay a price in terms
of computing speed compared to other modeling approaches such as the one used in
the demonstration model thermo in Simulink.

MODELING WITH FEMLAB | 1-169


Geometry Modeling
This section describes geometry modeling within FEMLAB and explains the
concepts of solid modeling and boundary modeling. The examples demonstrate how
to use the graphical interface and the FEMLAB functions in programming.

In FEMLAB you can use solid modeling or boundary modeling to create geometry
objects.

During solid modeling, you form a geometry as a combination of solid objects using
Boolean operations. These geometry-modeling operations including union,
intersection and differencehave been popular since the early days of computer
aided design (CAD) because they resemble traditional manufacturing methods such
as welding, milling, drilling, and cutting. The use of Boolean operations together
with the boundary-modeling method presented here continue to represent the most
widespread modeling paradigms in CAD. In FEMLAB, objects you form as a
combination of solid objects using Boolean operations are known as composite solid
objects.

Boundary modeling is the process of defining a solid in terms of its boundaries.

It is also possible to overlay additional non-solid objects on top of solid objects to


control the distribution of the mesh and to improve postprocessing capabilities. For
example, a curve3 object can be added to a geometry to be able to control the mesh
element size along a 3D curve.

Additionally, you can import geometry objects from, or export to, the MATLAB
main workspace. A 2D geometry can also be imported from or exported to a DXF
file, and a 3D geometry can be imported from an IGES file. See “Importing CAD
Models” on page 1-209 for a description of how to use these CAD file formats.

If your geometry data is available in image format or as magnetic resonance imaging


(MRI) data, you can convert this into FEMLAB geometry objects, using the
programming modeling tools described in the section “Image and MRI Import” on
page 1-220.

You can create 2D and 3D spline curves and surface interpolation of measured data
from the MATLAB prompt and insert the resulting geometry objects into the GUI.
For a description of this, see “Spline Interpolation for Creating Geometry Objects”
on page 1-225 and “Surface Interpolation” on page 1-228.

1-170 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
FEMLAB provides the tools for creating 1D, 2D, or 3D geometry objects. This
chapter starts with a discussion of 2D modeling because it forms the basis of 3D
geometry modeling. For details on the other geometry dimensions, please refer to the
sections “Creating a 3D Geometry Model” on page 1-186 or “Creating a 1D
Geometry Model” on page 1-207.

Creating a 2D Geometry Model


Using the draw toolbar, you can easily create many different types of geometry
objects.

The graphical interface automatically assigns each geometry object a unique name. It
supplies defaults in a predefined sequence: for circles, C1, C2, C3, and so on; for
rectangles, R1, R2, and R3; for ellipses, E1, E2, and E3. Although squares are just a
special type of rectangle, the interface gives them a dedicated name of the type SQ1,
SQ2, or SQ3. Composite objects take on designations such as CO1, CO2, and CO3,
and Bézier curves become B1, B2, and B3.

The names appear on the objects. In draw mode, the act of double-clicking on an
object opens a dialog box in which you can edit the name and other geometry
properties. You can change the default name to any unique name as long as it contains
no spaces.

GEOMETRY MODELING | 1-171


SOLID OBJECTS
A solid object consists of a boundary part and an interior part. Sometimes a solid
object has internal borders that separate internal subdomains. A solid object always
consists of one or more subdomains that can serve, for instance, to specify material
properties in different regions of a solid. Additional points and borders can control
the distribution of the mesh inside a solid object, which can be useful for
postprocessing purposes.

A solid’s boundary, including borders, consists of a number of edge segments. A solid


is completely defined in terms of its boundary (and optionally its internal borders)
and is thus said to have a boundary representation. For example, a primitive solid
rectangle or solid square has a boundary that consists of four line segments and one
subdomain. A primitive solid circle or solid ellipse has a boundary that consists of
four circular or elliptical arcs and a single subdomain.

SOLID MODELING USING THE GUI


This section demonstrates the use of Boolean operations ( union, intersection and
difference) on solid objects. These operations are suited for rapid generation of
complex geometries. The examples show how to create composite solids starting
from primitive solids.

Start by selecting Geometry only from the Model Navigator tree.

Creating Holes
Let us first learn how to drill a hole through a solid rectangle. Start by creating the
solid rectangle. If not already selected, select snap by double-clicking on SNAP on the
Status bar. Go to the top of the draw toolbar and press the button that corresponds
to a corner-aligned rectangle, or select Rectangle/Square from the Draw menu. Using
the left mouse button, click and drag from (-1,-1) to (1,1) to describe the rectangle’s
corners. Depending on settings in the graphical interface, you might need to adjust
axis and grid settings to reach these coordinates.

To create the circular hole, press the draw toolbar button for centered ellipse. Click
and drag, this time using the right mouse button (the left button lets you create
ellipses instead of just circles). Start the center at (0,0) and release the button at a
position that results in a solid circle with a radius of 0.5. Depending on the settings
you might find it helpful to add an extra grid line, in this case at x = 0.5. You can
undo the last drawn solid by pressing the Delete or Backspace keys or by selecting
Undo from the Edit menu.

1-172 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The act of drilling a hole through the solid rectangle actually involves the creation of
a composite solid object. First select both objects presently in the graphical interface
(go to Select All on the Edit menu, or use the shortcut Ctrl-a). Now simply press the
Difference draw toolbar button and the hole appears. This button subtracts objects
with smaller areas from the object with the largest area.

You can also try an alternative approach. Before drilling the hole, select Create
Composite Object… from the Draw menu (or press the corresponding button on the
draw toolbar) and this dialog box opens up:

To select both objects, choose Select all. Edit the Set formula by changing the + sign
to a - sign. Doing so results in the set formula R1-C1, here meaning that the interface

GEOMETRY MODELING | 1-173


subtracts the solid circle from the solid rectangle. Press OK to apply the set formula
and close the dialog box. You can see the result of this operation in the figure below.

Trimming Solids
Suppose it is necessary to remove the corners on the solid you just created. To do so,
create a second solid rectangle with the same size as the previously created rectangle,
rotate it 45 degrees, and then form the intersection of the two objects.

In more detail, create a new solid rectangle with corners at (-1,1) and (1,1). Press the
Rotate button on the draw toolbar to open the Rotate dialog box. Enter 45 degrees
of rotation, press OK to apply that value and close the dialog box. To cut the corners
off, first select all objects with, for example, Ctrl-a. Press the Intersection button on

1-174 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
the draw toolbar to form the intersection of the first and the second solid objects. The
figure below shows the result of these operations.

Adding Domains
What if you want to add a domain to a solid? Use the union operation. Continuing
with the solid with the trimmed corners, let us assume you want to attach an elliptical
domain on its right side.

First open the Axes/Grid Settings dialog box from the Options menu. On the Grid page,
deselect automatic grid spacing by unchecking the Auto check box. Then add extra
ticks in the y-direction by entering -0.25 0.25 in the Extra Y ticks edit field. In
addition, add a grid spacing of 0.5 in the x-direction and 0.2 in the y-direction. Press
OK to apply these values and close the dialog box.

GEOMETRY MODELING | 1-175


Now draw an ellipse centered at (1,0) with semi-axes of length 0.5 and 0.25 in the x-
and y-directions, respectively. Use the draw toolbar button for a centered ellipse.
Finally select all the objects and press the draw toolbar icon for union.

USING THE PROGRAMMING LANGUAGE


Now let us learn how to run these same Boolean operations on solid objects from
MATLAB.

The following examples illustrate how to create composite solids starting with
primitive solids, repeating what you just did with the graphical interface. Some
readers might want to skip over this section during a first reading of this manual
because you generally perform geometry modeling with the graphical interface.
However, the programming language can prove useful for creating geometry objects
such as when sequences of commands compute exact coordinates for objects. You can
import the resulting geometry objects into the graphical interface for further
manipulations.

Creating Holes
To learn how to drill a hole, first create a solid rectangle with corners at (-1,-1) and
(1,1):

s1 = rect2(-1,1,-1,1);
geomplot(s1)
axis equal

1-176 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
In the first line, the function rect2 creates a solid rectangular object s1. The function
geomplot plots the rectangle, which in this case is a square. The command axis
equal is necessary for proper visualization of the rectangle as a square.

Now create a circular hole with a radius of 0.5 and center it at (0,0).

s2 = circ2(0,0,0.5);

The function circ2 creates a circular object s2. Use it to effectively drill a hole in the
first object (the square) by forming the difference

s3 = s1-s2;

or by entering

s3 = geomcomp({s1,s2},’ns’,{’s1’,’s2’},’sf’,’s1-s2’);

Finally, visualize the result

geomplot(s3)
axis equal

When entering s3 = s1-s2 you take advantage of MATLAB’s object-orientated


capabilities by means of object arithmetic. In this case, both s1 and s2 are solid
objects, and the operation you run is equivalent to calling the function geomcomp
with the parameters shown. The intersection operator “*” and the union operator
“+” work in a similar fashion. The function geomcomp analyzes the specified
geometric objects and returns the analyzed geometric object. The analyzed object is
of the same class as the input objects.

Trimming Solids
To remove the corners from the solid rectangle, create a second solid rectangle of the
same size, rotate it 45 degrees, and then take the intersection of the two. Notice that
this sequence effectively cuts material from the outside of the rotated solid rectangle.

First rotate s1 about (0,0)

s2 = rotate(s1,45*(pi/180),0,0);

then form the intersection

s = s3*s2;

and visualize the result

geomplot(s)
axis equal

GEOMETRY MODELING | 1-177


The reason for (pi/180)in the argument for rotate is that the function expects
you to express the angle of rotation in radians rather than degrees.

Adding Domains
To add a domain to a solid, use the union operator (+). Take the object you’re
creating, still named solid s, and attach an elliptical domain on its right side.

First create a solid ellipse centered at (0,0) and with semi-axes (0.5, 0.25):

e = ellip2(0,0,0.5,0.25,45*pi/180);

The final argument, 45*pi/180, expresses the angle of rotation in radians with
respect to the semi-axes and the coordinate axes. Now rotate the solid ellipse by -45
degrees to get an ellipse with semi-axes parallel to the coordinate axes. We include
this step merely to illustrate how to rotate objects using FEMLAB functions:

e = rotate(e,-45*pi/180);

Move the center of the ellipse from (0,0) to (1,0):

e = move(e,1,0);

The second and third parameters in the function call correspond to the x- and
y-displacements. Finally, use the union operation to add the solid ellipse to the solid s

s = s+e;

and visualize the result

geomplot(s)

EDITING SOLIDS IN THE GUI


You can move objects by clicking and dragging them using the left mouse button. To
edit the intrinsic geometrical properties of a geometry object, choose Object

1-178 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Properties from the Draw menu or double-click on the object using the left mouse
button.

The contents of the Object Properties dialog box vary depending on which type of
object you have selected for editing. For primitive solid objects, you can modify
object-specific information such as center and semi-axes for ellipse primitives and
corner positions for rectangle primitives. For composite solids, the entries allow
editing of boundary curves and the removal of borders. For details see “Object
Properties…” on page 4-55. You can also edit the name of both primitive solids and
composite solids.

An alternative way for modifying control vertices is a drag-and-drop technique. Click


on one of the control vertices of a solid’s boundary using the left mouse button, hold
the button down and drag the vertex to a new position, then release the button. Any
change that alters a solid’s topology, such as one that creates new intersections or
wraps a solid’s domain, results in a warning message.

SUBDOMAINS AND THE SPLIT OPERATION


When you work with the union operator, the internal borders will partition the
resulting solid into subdomains. These subdomains can, for example, specify
different material properties. If you do not want FEMLAB to create these borders,
deselect the check box Keep internal borders in the Create Composite Object dialog
box.

It is possible to split a solid consisting of multiple subdomains into a collection of


minimal solids that each consists of only one domain. To do so in the graphical
interface, press the Split button on the draw toolbar. Using programming for the
same task, the line of code

GEOMETRY MODELING | 1-179


ss = split(s);

divides the solid s into multiple solid objects, all of which are now contained in the
cell array ss.

CURVE OBJECTS
When drawing a line, arc, or any other curve, you are creating a curve object. Primitive
curve objects in FEMLAB include lines, arcs (or 2nd degree Bézier curves), and 3rd
degree Bézier curves. A composite curve object consists of a collection of primitive
curve objects, and to form one, select Create Composite Object… from the Draw menu.
Before doing so, hold down the Ctrl key to select the constituent objects and click on
the curves using the left mouse button; alternatively, enclose them with a rubber
band box.

BOUNDARY MODELING
When using boundary modeling, you explicitly define a composite solid object’s
boundary by drawing each curve segment of it. The example below shows how to
create a composite solid by means of boundary modeling. The solid consists of two
line segments and four arc segments.

USING THE GRAPHICAL USER INTERFACE


If you haven’t already done so, select grid snapping by double-clicking SNAP on the
Status bar. Open the Axes/Grid Settings dialog box from the Options menu. On the Grid
page, deselect the Auto check box and enter a grid spacing of 0.5 for both the x- and
y-directions. Press OK to apply these selections and close the dialog box.

Choose Arc from the Draw menu or press the Draw Arc button on the draw toolbar.
Create the boundary by clicking at (-0.5,-0.5), (-1,-0.5), (-1,0), (-1,0.5) and
(-0.5,0.5) using the left mouse button. This action generates two arcs. Now choose
Line from the Draw menu or press the Draw Line button on the draw toolbar. Click at
(0.5,0.5) to create a horizontal line segment. Choose Arc again and click at (1,0.5),

1-180 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
(1,0), (1,-0.5) and (0.5,-0.5). Finally, clicking on the right mouse button creates a
solid object.

You can force the transformation of a solid object into a curve object by choosing
Coerce Object(s) To > Curve from the Draw menu or by pressing the Coerce to Curve
button on the draw toolbar. This action coerces the boundary into one composite
curve object. To split a composite curve object into its constituent primitive objects,
select Split Object from the Draw menu or press the Split button on the draw toolbar.
You can also coerce a curve object to a solid object by using the Coerce Object(s) To >
Solid functionality, either by using the corresponding Draw menu item or draw
toolbar button.

USING THE PROGRAMMING LANGUAGE


Let us now create the solid from the previous example using boundary modeling
from the MATLAB prompt. First create the six boundary curve objects:

w = 1/sqrt(2);
c1 = curve2([-0.5 -1 -1],[-0.5 -0.5 0],[1 w 1]);
c2 = curve2([-1 -1 -0.5],[0 0.5 0.5],[1 w 1]);
c3 = curve2([-0.5 0.5],[0.5 0.5]);
c4 = curve2([0.5 1 1],[0.5 0.5 0],[1 w 1]);
c5 = curve2([1 1 0.5],[0 -0.5 -0.5],[1 w 1]);
c6 = curve2([0.5 -0.5],[-0.5 -0.5]);

The objects c1,c2,c3,c4,c5, and c6 are all curve2 objects. The vector [1 w 1]
specifies the weights for a rational Bézier curve that is equivalent to a quarter-circle

GEOMETRY MODELING | 1-181


arc. The graphical interface automatically adjusts weights so that it always creates
elliptical or circular arcs. For more information on available geometry objects see the
Reference Manual.

Create a solid object s of the object type solid2

s = geomcoerce(’solid’,{c1,c2,c3,c4,c5,c6});

and visualize the result

geomplot(s)

You can create a single-curve object by converting a solid2 object to a curve2 object

c = curve2(s);

You can accomplish the same thing with a call to geomcomp

c = geomcomp({c1,c2,c3,c4,c5,c6});

ARCS
The solid you created in the previous example has rounded corners consisting of
circular arcs. When drawing arcs, whether you create circular or elliptical curve
segments depends on the control polygon. FEMLAB draws a circular arc only if the
control polygon is isosceles. In other words, to ensure an arc is circular, keep the
distance between the first and second control vertices equal to the distance between
the second and third control vertices.

The underlying representation of arcs is a 2nd degree Bézier curve with weights that
depend on the shape of the control polygon. When using the graphical interface,
FEMLAB automatically adapts the weights to the shape of the control polygon in
order to create elliptical or circular curve segments. For more information on the
underlying representation of curves, see the Reference Manual.

RATIONAL BÉZIER CURVES


This section gives an elementary introduction to some of the more important
properties of rational Bézier curves. It also describes how to use the graphical
interface or the programming language to generate them.

Why Rational Bézier Curves?


When you work in draw mode and create a geometry object with a curved boundary,
FEMLAB represents that object in terms of rational Bézier curves. This
representational scheme has become a standard in the CAD community because of

1-182 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
its intuitive behavior and representational power. Rational Bézier curves of degree 2
can represent all different types of conic sections including circles, ellipses, parabolas,
and hyperbolas. FEMLAB includes 3rd degree rational Bézier curves to assist in the
creation of additional free-form shapes such as curves with inflection points
(S-shaped curves) and advanced fillets.

Control Vertices and Weights


A rational Bézier curve of degree n is completely defined in terms of a control
polygon consisting of n+1 control vertices and n+1 associated control weights. The
curve always interpolates the two end points of the control polygon. A change in the
control polygon’s shape, such as by moving a control vertex, produces a
corresponding change in the curve’s appearance. Its shape, in a sense, always mimics
that of the control polygon. The higher curve degree, n, the more complicated are
the shapes you can create due to the increased number of control vertices. If you
increase the weight associated with one of the control polygon points, that action
pulls the curve toward the corresponding control vertex.

This simple and intuitive interaction between the control polygon, with its weights,
and the curve makes the rational Bézier curve representation so useful. Below you can
examine some simple examples of how alterations in control vertices and weights
affect curve shape.

Using the Graphical User Interface


Start by examining an S-shaped 3rd degree rational Bézier curve. To produce this
shape, position the control vertices at b0 = (-1,0), b1 = (-0.5,1), b2 = (0.5,-1), and b3

GEOMETRY MODELING | 1-183


= (1,0) in a zigzag pattern. FEMLAB starts with the control weights w0, w1, w2, and
w3 all set to 1.

To create the curve shown above, first open the graphical interface. If you haven’t
already done so, select grid snapping by double-clicking on SNAP on the Status bar.
Deselect the solidifying mode by double-clicking on SOLID on the Status bar. Press
the Draw Cubic Bézier Curve button on the draw toolbar, or select 3rd Degree Bézier
Curve from the Draw menu. Using the left mouse button, click in order at (-1,0),
(-0.5,1), (0.5,-1) and (1,0). You can also click and hold down the left mouse button
at the starting point, move to the next point and release the button, repeating this
process for each point. This drag-and-drop technique gives you visual feedback and
shows the control polygon’s edges while creating the curve.

Deselect the 3rd degree curve mode by clicking on the right mouse button or by
pressing the toolbar for cubic Bézier curves a second time. Doing so coerces the curve
into an editable curve object. Next move b1 to (-0.5,0.4) by clicking on the second

1-184 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
control vertex at (-0.5,1), holding down the left mouse button and releasing it at the
new location. The curve adapts to the altered shape of the control polygon:

Increasing weight w2 (the third weight) from 1 to another value, for example 7, pulls
the curve towards the corresponding control vertex b2:

You can perform this action in the graphical interface by opening the Object
Properties dialog box from the Draw menu or by double-clicking on the curve object.

GEOMETRY MODELING | 1-185


Choose the Weights page, select Curve 1 and alter Weight 3 from 1 to 7. Finish by
pressing the OK button. Be especially aware that weights mathematically denoted w0,
w1, w2, and w3 correspond to Weights 1, 2, 3, and 4 in the graphical interface.

Using the Programming Language


To achieve the same result as above, use this code:

c = curve2([-1 -0.5 0.5 1],[0 1 -1 0],[1 1 1 1]);


geomplot(c,’ctrlmode’,’on’)

In the first line the constructor creates a curve2 object named c, which corresponds
to the S-shaped curve. In the next line the method geomplot plots this object. You
can find a detailed discussion of various geometry methods and the geometry class
structure in the Reference Manual.

When you move the control vertex b1 to (-0.5,0.4), the curve adapts to the altered
shape of the control polygon.

Change the position of the second control vertex by entering

c = change(c,2,-0.5,0.4);

or equivalently

c = curve2([-1 -0.5 0.5 1],[0 0.4 -1 0]);

and plot the changed curve

geomplot(c,’ctrlmode’,’on’)

Note that you can omit the weights when calling curve2; FEMLAB sets all weights
to 1 in this case.

If you now increase weight w2 from 1 to 7, that change pulls the curve towards the
corresponding control vertex b2.

Enter the following code to change the weights:

c = change(c,1,[1 1 7 1]);
geomplot(c,’ctrlmode’,’on’)

Creating a 3D Geometry Model


The computer’s two-dimensional screen limits the possibilities of defining a 3D
geometry object by means of clicking and dragging the mouse. The standard way of
creating 3D geometries is to model a cross section in 2D and then use operations
such as extrude or revolve to extend it into a 3D geometry object. You can implement

1-186 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
even more complex geometries by using Boolean operations as described below. In
FEMLAB, you model 2D cross sections in local 2D coordinate systems called work
planes that you position anywhere in space.

Clearly 2D modeling is an essential part of the 3D modeling process. If you are not
familiar with 2D modeling, you may want to review the previous section, “Creating
a 2D Geometry Model” on page 1-171 before proceeding with this chapter.

FEMLAB also supplies a set of 3D primitives you can create easily without first
activating a work plane. These include blocks, cones, cylinders, ellipsoids, and spheres
and appear at the top of the draw toolbar.

When you create a geometry object, the graphical interface automatically assigns it a
unique name. Default names for cylinders start with CYL1, moving on to CYL2,
CYL3, and so on; it uses BLK1, BLK2, BLK3, and so on for blocks; while CON1,
CON2, and CON3 are used for cones. A geometry object you create from a work
plane with an extrusion operation takes on names such as EXT1, EXT2, or EXT3.
Similarly, a revolve operation results in names such as REV1, REV2, or REV3.

C RE A T I N G WO R K P L A N E S
A work plane is a 2D plane positioned anywhere in 3D space. To completely define
such a plane you need three points and a normal direction. In FEMLAB you can
specify a work plane’s orientation by specifying these properties either explicitly, by

GEOMETRY MODELING | 1-187


specifying its coordinates, or by using existing 3D geometry objects as reference
points.

To create a work plane, open the Add/Edit/Delete Work Plane… dialog box from the
draw menu. Note that if you have any objects selected at this time, all others
temporarily disappear. In the dialog box you can choose among five ways to specify
a work plane. You can add new work planes, edit or delete existing work planes, and
rename them.

On the General page you select a method: Quick positioning, Face positioning, Edge
positioning, Vertex positioning or Specify position. Use quick positioning to obtain a
work plane equal to the xy-, yz-, or zx-plane. When creating a work plane using face
positioning, edge positioning, or vertex positioning, you select existing 3D objects
as reference points. Another possibility to define a work plane is to specify three
points in 3D space. In this case, the normal direction depends on the order of the
specified points. For more information on the different methods to create a work
plane, see the section “3D Draw Menu” on page 4-59 in the Reference Manual.

Pressing the Disp Coord toggle button displays a small axis in the 3D view that
indicates a work space’s origin and its normal vector direction. Pressing OK for this
dialog allows you to then enter the currently selected work plane and start working
in that local 2D coordinate system.

When you enter a work plane, a 2D draw toolbar replaces the 3D draw toolbar. It
contains the same buttons as the standard 2D toolbar but adds three more at the
bottom that define which portion of the 3D geometry to project onto the plane. This

1-188 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
method helps you capture the orientation of a work plane in 3D space. Here you can
choose to see a projection of the entire 3D geometry, see parts of the geometry that
intersect the current plane, or see nothing of the 3D geometry. FEMLAB considers
this geometry projection as a background plot to which you can snap the cursor when
drawing 2D objects.

Drawing in a work plane is essentially the same as 2D geometry modeling. Here you
create a cross-section geometry using standard 2D solid modeling or boundary
modeling techniques. It is possible to embed, extrude, or rotate objects to form a 3D
geometry object.

EXTRUDE, REVOLVE, AND EMBED OPERATIONS


The Extrude item in the Draw menu opens a dialog box in which you select objects to
extrude. You also specify the length of the extruded object in the direction
perpendicular to the plane and other optional parameters. See “Extrude…” on page

GEOMETRY MODELING | 1-189


4-69 for a detailed description of this dialog box. The figure below shows the result
of an extrusion.

The Revolve menu item rotates the selected 2D geometry objects between two angles
and about an axis that you specify in the Revolve dialog box. See “Revolve…” on page
4-70 for a details. Below, a result of a revolution is shown.

You can also embed 2D geometry objects in 3D space, yet still in their existing form,
by choosing the Embed menu item.

SOLID OBJECTS
As is the case with 2D solid objects, a 3D solid object consists of a boundary part and
an interior part. The boundary, including any borders, consists of a number of face
segments. You can completely define a solid in terms of its boundary and optionally
its internal borders, and thus we say it has a boundary representation. For example, a
primitive solid block object or solid cube object has a boundary that consists of six
rectangular face segments and one subdomain. A primitive solid cylinder has a

1-190 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
boundary that consists of two circular faces (top and bottom), four bent rectangular
faces building the lateral area, and a single subdomain.

SOLID MODELING AND BOOLEAN OPERATIONS


This section demonstrates the use of work planes and the Boolean operations (union,
intersection and difference) on solid objects in the graphical interface. The Boolean
operations are suited for rapid generation of complex geometries.

The following examples show how to use the graphical interface to create composite
solids from those you previously created using work planes.

Start by selecting the 3D radio button in the Dimension frame. Then select Geometry
only from the Model Navigator tree.

Using the Graphical User Interface


The first operation shows how to drill holes through a block primitive. Start by
pressing the Block toolbar button, or select Block from the 3D Primitives submenu in
the upper part of the Draw menu. This action opens a dialog box in which you specify
the primitive’s dimensions and position.

In the Style frame you can choose to create a face object or a solid object. The Base
frame defines where to put the origin of the block’s internal coordinate system.
Pressing the More button reveals additional parameters that specify the block’s
position in 3D space. For this exercise, enter the length of the block’s sides as 1, 2,
and 0.2 according to the figure above and press OK.

GEOMETRY MODELING | 1-191


Open the Add/Edit/Delete Work Plane dialog box from the Draw menu. On the Quick
page select the Quick positioning radio button. Select the x-y radio button to create a
work plane in the xy-plane. To view its position and normal direction, simply press
the Disp Coord button. You can change the work plane’s name by clicking on its title
at the bottom of the dialog box. Press OK and you automatically enter the work plane.

Now that you have entered that local 2D coordinate environment, press the Project
Work Plane Intersection toolbar button at the bottom of the draw toolbar if it’s not
already selected. Doing so shows a blue wireframe plot of the 3D geometry. The three
bottom toolbar buttons together with the Geometry Object Suppression dialog box on
the Draw menu control how much of the 3D geometry is displayed in the work plane.
See “Suppressing Geometry Objects” on page 1-106 for more information on how
to suppress geometry objects.

Using the background image for orientation, you can easily find the middle of the
block. Open the Axes/Grid Settings dialog from the Options menu. On the Grid tab,
uncheck the Auto check box and enter 0.25 in the X-spacing, and Y-spacing edit fields.
Press OK

To create the circular hole, press the toolbar button for centered ellipse. Click the
right mouse button and drag the cursor starting at the circle’s center at (0.5,1) and
releasing the mouse button when you’ve created a solid circle with a radius of 0.25.

1-192 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Now open the Extrude dialog box from the Draw menu to turn the circle into a 3D
cylinder.

Select C1 in the object list box and enter the distance 0.2 in the Distance edit field.
Press OK. You can extrude an object in numerous ways. This includes scaling the
geometry in the x- or y-direction to create conic geometries and skew the geometry
by setting an x- or y-displacement. You can also make piece-wise linear and cubic
extrusions by entering matrices in these edit fields. See the reference entry on
extrude on page 5-93 in the Function Reference for details.

To create a chamfer, that is, a flattened corner, select the block by clicking it, and open
the Add/Edit/Delete Work Plane dialog box. Press the Add button to create a new work
plane, which FEMLAB names Work plane 2. On the Face Parallel page, check the Face
positioning radio button and select face 3. Enter an offset of 1 in the Offset from face
edit field. Choose Upward normal in the Work plane z-axis direction frame. Press the
Disp Coord button to view the work plane’s position and normal direction. Press OK,
which puts you automatically into the new work plane.

Select the Project All 3D Geometries button in the draw toolbar, and click the Zoom
Extents button in the main toolbar to view the entire projection of the 3D geometry.
Open the Axis and Grid Settings dialog box from the Options menu. On the Grid tab,
clear the Auto check box and enter 0.05 in both the X-spacing and Y-spacing edit fields.
Press OK.

Make sure that SNAP and SOLID are selected in the Status bar. Create a solid triangle by
selecting the Draw Line button and clicking at (0.15,0.75), (0.2,0.75), and (0.2, 0.8)
using the left mouse button. Right-click anywhere in the axes to create the solid
triangular object.

GEOMETRY MODELING | 1-193


Now rotate this triangular object by selecting Revolve… from the Draw menu. In the
resulting Revolve dialog box, choose the axis about which you want to rotate the
object, and enter the angles between which it should rotate.

Select the composite triangle object CO1. Specify a point on the axis of rotation by
entering 0 and 0.5 in the X0 and Y0 fields, respectively. Specify the axis direction by
selecting the Second point radio button and entering 1 and 0.5 in the X1 and Y1 fields,
respectively. Use the default angles to revolve between 0 and 360 degrees, and press
the OK button. The resulting revolved 3D object is selected in the 3D view.

1-194 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Now let us drill the hole through the solid block by creating a composite solid object.
First choose Select All from the Edit menu or use the shortcut Ctrl-a. Press the draw
toolbar button for difference, which creates the hole. The difference toolbar button
subtracts objects with small volumes from the one with the largest volume.

To get a better view of the 3D geometry use the Headlight button and the Orbit button
on the orbit/pan/zoom toolbar. Turn the axis on or off by double-clicking on AXIS in
the Status bar.

To round off the edges, re-enter the first work plane by selecting Work plane 1 from
the Draw menu. Next, select the old circle object, C1, and press the Delete key or
choose Clear from the Edit menu. Draw a rectangle from (0,0) to (1,2), covering the
entire projection of the 3D geometry. Double-click MULTI on the Status bar to be able
to draw multiple objects without the need to reselect the draw tool. Choose Draw
Ellipse from the drawing toolbar, and then draw four circles with radii of 0.125, using
the right mouse button, aligned to the corners of the rectangular geometry as shown

GEOMETRY MODELING | 1-195


below. Then select all objects by pressing Ctrl-a, and press the Difference toolbar
button in the draw toolbar.

Use the Split Object toolbar button to split the composite solid object into five
objects. To remove the largest middle object, click on it with the mouse and press
delete, or choose Clear from the Edit menu. Now extrude the remaining objects a
distance of 0.2.

1-196 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
In the 3D view, select all objects once again and press the Difference toolbar button
to get the final geometry object.

Using the Programming Language


This section demonstrates the use of Boolean operations (union, intersection, and
difference) on solid objects in the programming language.

The following examples show how to use the FEMLAB functions to create
composite solids starting from primitive solids, repeating the work you just
completed within the graphical interface. Some users might opt to postpone a
reading of this section because you generally perform geometry modeling from the
graphical interface. However, using the programming language for creating
geometry objects can be useful, for instance, when you need a sequence of commands
to compute exact coordinates of geometry objects or, as in this case, to access
advanced functionality not yet implemented in the graphical interface. It is then easy
to import geometry objects you create on the MATLAB prompt into the graphical
interface for further manipulation.

To create a geometry similar to the one in the previous example, first create a solid
rectangle with corners at (0,0) and (1,2).

r = rect2(0,1,0,2);

Then use the fillet utility to take off its edges.

rf = fillet(r,’radii’,0.125);

GEOMETRY MODELING | 1-197


Create a circle object with radius 0.25, and form a triangle using three curve objects.

c1 = circ2(0.5,1,0.25);
t1 = curve2([0.15 0.2],[0.75 0.75]);
t2 = curve2([0.2 0.2],[0.75 0.8]);
t3 = curve2([0.2 0.15],[0.8 0.75]);

Create a solid triangle by a call to geomcoerce.

t = geomcoerce(’solid’,{t1,t2,t3});

The function geomcoerce analyzes the specified geometric objects and coerces the
resulting geometric object into the specified class.

Extrude the rectangle along the z-axis from 0 to 0.2, and extrude circle c1 from 0 to
0.2.

blk = extrude(rf,0.2);
hole = extrude(c1,0.2);

Create the chamfer by revolving the triangle object, t, 360 degrees about the center
of the hole. To do so, first define a work plane going through the center of the hole,
then define an axis of rotation.

wrkpln = [[0;1;0],[0;1;1],[1;1;0]];
ax = [[0;0.5],[1;0]];
chamf = revolve(t,’angles’,[0,2*pi],...
’revaxis’,ax,’wrkpln’,wrkpln);
chamf = solid3(chamf);

Use the resulting 3D objects to create the composite solid object by subtracting the
chamfer and hole from the filleted block using the Boolean operations “+” and “-”.

plate = blk-(chamf+hole);

Plot the final geometry using the geomplot method. The last line adds light to the
plot.

geomplot(plate)
axis equal
camlight

EDITING SOLIDS IN THE GUI


It is not possible to move 3D objects by clicking and dragging them using the mouse
as when working with 2D objects. Instead, you edit a geometry object’s intrinsic
properties by choosing Object Properties from the Draw menu or by double-clicking
on it using the right mouse button. Note that you must use the right button when
double-clicking due to the ambiguity of selection in 3D, but this choice implies that
the selected object is locked. See “Object Selection Methods in 3D” on page 1-95 for

1-198 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
information about selection in 3D. The only objects that FEMLAB allows you to edit
are primitive objects; you cannot edit any object created using a Boolean operation
or a work plane in this way.

Choosing Object Properties opens a primitive’s dialog box, which is the same as the
one that appears when you first created it. Further, you can open it only when exactly
one primitive is selected. The contents of the dialog box differ depending on which
type of primitive you’re working on. You can edit object-specific information such as
its name, dimensions and orientation in 3D space. To rename a non-primitive object,
use the Create Composite Object dialog box.

You can move, scale, or rotate a 3D object with the Move, Scale, and Rotate toolbar
buttons or by selecting Linear Transformation on the Draw menu. In the Rotate dialog
box, you specify an angle of rotation plus the axis of rotation. You define the axis of
rotation with a point on the axis plus a direction vector specified in either Cartesian
or spherical coordinates.

SUBDOMAINS AND THE SPLIT OPERATION


The union operator partitions the resulting solid into subdomains defined by the
internal borders. These subdomains can, for example, specify different material
properties. If you do not want to create borders, deselect the check box Keep internal
borders in the Create Composite Object dialog box.

It is possible to split a solid with multiple subdomains into a collection of minimal


solids that each consists of only one domain. To do so in the graphical interface, press
the Split button on the draw toolbar. The same process from the MATLAB prompt is

ss = split(s);

GEOMETRY MODELING | 1-199


which splits a solid object s into a number of solid objects contained in the cell array
ss.

FACE OBJECTS
When embedding a 2D solid, or extruding or revolving a curve object, you create a
3D face object. A composite face object consists of a collection of face objects. You can
create it by selecting Create Composite Object… from the Draw menu or by coercing a
3D solid into a face object by pressing the Coerce to Face toolbar button.

BOUNDARY MODELING
When using boundary modeling, you explicitly define a composite solid object’s
boundary by drawing each of its face segments. When modeling 3D geometries there
are actually two possible levels of boundary modeling because you can create 3D
boundaries using 2D solid modeling or 2D boundary modeling.

The following example shows how to create a composite solid tetrahedron with
boundary modeling.

Using the Graphical User Interface


Open the Model Navigator, select the 3D radio button, choose Geometry Only and
press OK. Enter the default work plane, Work plane 1, from the lower part of the Draw
menu. By default this work plane is the xy-plane.

Using boundary modeling, create a solid triangle with equal sides. For this task, open
the Axis and Grid Settings dialog box from the Options menu, uncheck Auto on the Grid
page, set the x- and y-spacing to 0.5, and add an extra y-grid line at sqrt(3)/2.
Check that SOLID and SNAP are enabled on the Status bar.

1-200 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Select Draw Line from the toolbar, then click with the left mouse button at (0,0), (1,0)
and (0.5, ( 3 ) ⁄ 2 ). Click anywhere in the axes using the right mouse button to
complete the triangle and solidify it.

Open the Embed dialog box from the Draw menu and select the triangle before
pressing OK.

To create the next face, open the Add/Edit/Delete Work Plane dialog box and select the
Edge Angle page. Check the Edge positioning radio button and select the first edge in
the list box. Select the face in the list box to the right, then enter the expression
asin(sqrt(2)*2/3)*180/pi in the edit field for the angle between the face and the
work plane. Change the z-axis direction to Downward normal and press the Disp Coord

GEOMETRY MODELING | 1-201


button to see the new definition of Work plane 1 before pressing OK and entering the
plane.

Once you are in that local coordinate system, embed the triangle once again without
making any changes.

1-202 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Select both faces by pressing Ctrl-a or clicking the faces while holding the Shift key
down. Turn on vertex highlighting by pressing the corresponding toolbar button in
the select toolbar (if not already selected), and open the Add/Edit/Delete Work Plane
dialog again. Now use Vertex positioning, and in the list box to the left select vertices
1 and 3 from triangle EMB1 and vertex 2 from triangle EMB2. Press the Add button
to move the selected vertices to the right list box. Choose upward normal direction
and confirm the orientation of the work plane using the Disp Coord button.

GEOMETRY MODELING | 1-203


Press OK and embed the triangle again from the work plane. At this point you’ve
created three of the four faces. To create the last one, make sure to select all existing
faces before opening the Add/Edit/Delete Work Plane dialog box one more time.
Remove the vertices from the right list box on the Vertices page by selecting them and
pressing the Remove button. Select vertex 3 from triangle EMB1, vertex 1 from triangle
EMB2, and vertex 2 from triangle EMB3, and then add them to the list box on the
right-hand side. Press the Disp Coord button to verify that the work plane is correctly
oriented before pressing OK. By embedding the triangle a last time, you create the
final face object.

To create a 3D solid object from these face objects, select all the faces by pressing
Ctrl-a or by choosing Select All from the Edit menu. Press the Coerce to Solid button
in the draw toolbar. FEMLAB automatically names the final solid object CO1.

Using the Programming Language


This section demonstrates how to create the solid from the previous example using
boundary modeling and FEMLAB functions. First create the three boundary curve
objects, forming the triangle using the method curve2.

c1 = curve2([0 0.5],[0 sqrt(3)/2]);


c2 = curve2([0.5 1],[sqrt(3)/2 0]);
c3 = curve2([1 0],[0 0]);

For more information on the various geometry objects available, see the Reference
Manual.

1-204 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Create a solid triangle object s of the object type solid2.

s = geomcoerce(’solid’,{c1,c2,c3});

In FEMLAB, you can perform extrude, revolve or embed operations, using the
low-level methods extrude, revolve, and embed directly on 2D objects. Let us look
at this in detail.

Begin by defining three constants; they contain the height for the base triangle in the
xy-plane, the top of the tetrahedron, and the center of the base triangle, respectively:

height= [0.5;sqrt(3)/2;0];
top = [0.5;sqrt(1/12);sqrt(2/3)];
center = top.*[1;1;0];

Create the 3D face objects by embedding the solid triangle, s, using the embed
function. The second argument to this utility is a 3-by-3 matrix containing three
points that define a work plane. The first point is the origin of the work plane. The
second and the third point define the work plane x- and y-axis, respectively.

f1 = embed(s,[[0;0;0],[1;0;0],[0;1;0]]);
f2 = embed(s,[[0;0;0],[1;0;0],top]);
f3 = embed(s,[height,[0;0;0],top]);
f4 = embed(s,[[1;0;0],height,top]);

Finally, create the solid 3D object of type solid3 from the face3 objects by

t = geomcoerce(’solid’,{f1,f2,f3,f4});
geomplot(t)

The last line plots the tetrahedron in a figure window.

RATIONAL BÉZIER PATCHES


This section gives an overview of rational Bézier patches, as used in 3D geometry
modeling in FEMLAB.

Why Rational Bézier Surfaces?


The reason for using rational Bézier surfaces in 3D is the same as that for using
rational Bézier curves in 2D—it is the current industry standard. When you work in
the 3D draw mode and create a geometry object with a curved boundary, FEMLAB
represents that object in terms of rational Bézier surfaces. Two types of Bézier surfaces
are supported: rectangular and triangular surfaces. A rectangular Bézier surface is
assigned a mixed degree (m, n), which represents the degree of the surface in terms
of two parameters, often named s and t. A triangular Bézier surface is assigned a single
degree, m, just as a Bézier curve.

GEOMETRY MODELING | 1-205


FEMLAB supports rectangular surfaces of mixed degree at most (3,3) and triangular
surfaces of degree 1 to represent planar surfaces. Rectangular rational Bézier surfaces,
of mixed degree up to (2,2) can represent all the common CAD-surfaces including
bilinear patches, cylinders, cones, spheres, ellipsoids, and tori. FEMLAB also
includes (3,3)-degree rational Bézier curves to assist in the creation of additional
free-form surfaces. Rational Bézier surfaces are closely connected to so called
NURBS-surfaces (non-uniform rational basis spline surfaces) in that a
NURBS-surface can always be decomposed into a net of rational Bézier surfaces. You
can envision this as considering rational Bézier surfaces as the atomic constituents of
a NURBS-surface.

Control Vertices and Weights


A rectangular rational Bézier surface of degree (m,n) is completely defined in terms
of a control net consisting of (m+1)×(n+1) control vertices, each assigned an
associated positive control weight. The surface always interpolates the four corner
points of the control net. A change in the control net’s shape, such as by moving a
control vertex, produces a corresponding change in the surface’s appearance. Its
shape, in a sense, always mimics that of the control net. The higher the surface degree
the more complicated are the shapes you can create due to the increased number of
control vertices. If you increase the weight associated with one of the control vertex
points, that action pulls the curve toward the corresponding control vertex.

This simple and intuitive interaction between the control net, with its weights, and
the surface makes the rational Bézier surface representation so useful. By using the
face3 command, you can examine how alterations in control vertices and weights
affect surface shape. You can import free-form face objects into the GUI and
incorporate them with your solid models.

3D Geometry Objects
The 3D geometry objects in FEMLAB are formed by a set of trimmed and
untrimmed rational Bézier surfaces. A cylinder, for instance, consists of four
untrimmed rectangular degree (2,1) patches and two trimmed triangular planar
patches. The planar patches are trimmed, so only a circular portion of each planar
patch is actually used. When using geometry modeling operations, the Bézier patches
are trimmed by the intersection curves between surfaces. By trimming surfaces, patch
boundaries can take virtually any shape. The connected trimmed and untrimmed
patches of a 3D geometry object are called faces. It is possible for a patch to be divided
into any number of facescurved areas bounded by trimming (intersection) curves.

1-206 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
For more information on rational Bézier patches, see “Rational Bézier Patches” on
page 3-13 in the Reference Manual.

Creating a 1D Geometry Model

USING THE GRAPHICAL USER INTERFACE


You can also perform geometry modeling in 1D. From the graphical interface, start
by pressing the 1D radio button in the Model Navigator.

GEOMETRY MODELING | 1-207


In draw mode you open the Specify Geometry dialog box from the Draw menu. Here
you enter names and coordinates for 1D solid objects and points. The dialog box is
similar to the Add/Edit Constants dialog box.

For detailed examples of 1D geometry modeling in the graphical interface, go to the


Model Library and examine “The KdV Equation and Solitons” on page 2-172 and
“The Burgers Equation” on page 2-165.

USING THE PROGRAMMING LANGUAGE


From the MATLAB prompt, you create 1D geometry model using the constructors
solid1, point1, and the function geomcsg.

The command

s=solid1([0 1 2])

creates a 1D solid object with two subdomains.

Entering

p=point1(0.5)

creates a 1D point object, and

g=geomcsg({s},{p})

merges the two geometry objects to a 1D analyzed geometry.

See the model “Tubular Reactor” on page 1-378 of this book for an example of 1D
geometry modeling using the programming language.

1-208 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Importing CAD Models
You can import both 2D and 3D CAD models into FEMLAB. In 2D, the DXF file
format is used, and in 3D the IGES format is used.

DXF IMPORT
FEMLAB allows you to import 2D CAD drawings via the DXF file format, which is
an industry standard format for CAD drawings. To be able to utilize the automatic
mesh generation, FEMLAB requires a high degree of accuracy within the CAD
drawing. If these requirements are not met, the geometry needs to be updated to
meet FEMLAB’s requirements. This can be done by applying different “geometry
repair” algorithms on the drawing when importing the DXF file into FEMLAB.

Often there is a need for closing small gaps and eliminate short edges in the imported
geometry. If small gaps or exceedingly short edges are present, FEMLAB might fail
in creating either a valid 2D solid or a mesh of acceptable quality. To remove these
short edges and to close small gaps between the end points of curves, the import
property DXF tolerance often need to be adjusted. This tolerance specifies the largest
distance between the end points of curves allowed in the imported geometry. For the
FEMLAB function, dxfread, this property is called tol. In the GUI you define this
property in the DXF file tolerance field found in the Insert DXF file dialog box. In order
to close gaps between end point of curves and curves within the specified tolerance,
the dxfread property curvesnap has to be activated. The corresponding GUI
setting can be made in the Advanced DXF File Properties dialog box. See “Insert from
File” on page 4-21 in the Reference Manual for details.

An Example Using the Graphical User Interface


To import the DXF file demo1.dxf into the GUI, open the Insert DXF file dialog from
the Insert from File submenu found in the File menu. Start by importing the geometry
in demo1.dxf from the femlab directory as a composed curve object using the
default settings.

GEOMETRY MODELING | 1-209


You can use the Browse… button to find the file. Pressing OK results in the following
plot.

The actual geometry in demo1.dxf is found in the DXF layer 0. To import this layer
only (excluding the frame lying in the DXF layer named Layer1) select layer 0 in the
Advanced DXF File Properties dialog. First remove the current geometry by choosing
Undo Import DXF File from the Edit menu. Now, open the Insert DXF File dialog box
again and press the Advanced… button to open the Advanced DXF File Properties

1-210 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
dialog box. Here, select layer 0 and press OK in both dialog boxes. This results in a
geometry without the bounding box.

Alternatively this can be done by importing both layers but only the curves belonging
to layer 0. In demo1.dxf the first 22 curves belong to layer 0. This curve selection is
done by checking Selected in the Include curves frame in the Advanced DXF File

GEOMETRY MODELING | 1-211


Properties dialog and specifying curves 1:22 in the field Select curves to include
(integers):.

By solidifying the imported geometry it can be seen that parts of the geometry
disappear. This depends on small gaps in the geometry.

These gaps can be closed when importing the DXF file by setting the DXF file
tolerance in the Insert DXF file dialog to 0.001 and checking Snap curves in the
Advanced DXF File Properties dialog. If you clear the previously imported geometry
(for example by choosing Undo Import DXF File) and import the file once again with
these new settings, you can press the Coerce to Solid button in the draw toolbar to get
a solidified geometry. By pressing the Split Object button, you can split the object
into its subdomains. Now, pressing the Difference button in the draw toolbar

1-212 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
removes the smaller geometries from the largest one. The result is the following
geometry:

IGES IMPORT
3D CAD geometric models can be imported to FEMLAB via the IGES format
(Initial Graphics Exchange Specification). The IGES format is a neutral standard
format for exchanging geometric models between different CAD systems. Geometric
models saved in the IGES format do not always pass flawlessly between different
CAD systems. This is unavoidable since the IGES format uses the lowest common
denominator approach to describe a geometric model which means that information
is lost. Furthermore, the IGES format allows a certain geometric model to have
different representations, and some representations are less compatible with the
receiving system than others.

In FEMLAB you get a printed report of the encountered problems during the
translation. This error summary is printed to the message log when you run the GUI
and to the MATLAB prompt when you run the FEMLAB function igesread. Often
there is a need for adjusting the geometry tolerance parameter used when translating
the geometric entities in the IGES file. This tolerance specifies the smallest distance
between coordinates that is considered as discernible. For the FEMLAB function,
this property is called agtol. In the GUI this property is defined in the IGES file
tolerance field found in the Insert IGES file dialog box.

GEOMETRY MODELING | 1-213


The surfaces that define the boundary of a solid in an IGES file are represented by
untrimmed surfaces and their corresponding trimming curves. If FEMLAB
encounters problems trying to trim some surface, the message ‘Unable to trim
surface.’ is printed. Then you are advised to try to import the IGES file without
applying the surface trimming or to adjust the geometry tolerance parameter. The
property that determines if the surfaces in an IGES file are trimmed is called
surftrim for the FEMLAB function, and in the Insert IGES file dialog box it is
defined in the Surface trimming check box.

If you just want to have a quick view of the geometry in the IGES file you should
import the surfaces in the IGES file without composing and coercing them into a
solid. Working from the GUI this is done by unchecking the check box Insert
geometry as a composed object in the Insert IGES file dialog box, and from the
MATLAB prompt by setting the property coercion to off. You can also compose
your imported surfaces into one face object without coercing it into a solid by
checking the Insert geometry as a composed object check box and then choosing face
in the popup menu. On the MATLAB prompt this is done by setting the coercion
property to face.

For more information on the Insert IGES file dialog box, see “Insert from File” on
page 4-21 in the Reference Manual for details.

Using the Graphical User Interface


We will now study two examples of IGES file import working from the GUI. To
import the IGES file demo1.igs into the GUI, open the Insert IGES file dialog box
from the Insert from File submenu found in the File menu. Start by importing the
geometric model in demo1.igs from the femlab directory using the default settings.

1-214 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
You can use the Browse… button to find the file. Click OK to get the following plot.

By studying the error summary in the message log, it can be seen that FEMLAB
encountered some problems while importing this IGES file. These problems can be
avoided by adjusting the IGES file tolerance in the Insert IGES file dialog box. First,
remove the current geometry by selecting Undo Import IGES File from the Edit menu.
Now, open the Insert IGES file dialog box again and set the IGES file tolerance field to
0.0001. By checking the Print IGES file information check box you get information on
the geometry tolerance and the entities defining the geometric model in the IGES file
printed to the message log.

GEOMETRY MODELING | 1-215


By clicking OK, the file is imported smoothly using the new settings.

As mentioned earlier, a single geometric model can have many IGES format
representations. Several different combinations of IGES entities can be used to
represent a geometric model in the IGES format, and each combination is more or
less compatible with the receiving system. You can try to import another IGES file
storing the same geometric model, by using another combination of IGES entities to
represent the geometry. Remove the previously imported geometry and import the
IGES file demo2.igs, found in the femlab directory as well, with the Print IGES file
information check box checked.

1-216 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
By studying the entity summary in the message log, you can see that the file
demo2.igs does not use the same set of IGES entities.

In the error summary, it can be seen that the translator encountered problems when
trying to trim some surfaces in the file demo2.igs. The surface trimming can be
turned off, when importing an IGES file, by unchecking the Surface trimming check
box. Remove the previously imported geometry, and try to import demo2.igs with
the surface trimming turned off.

GEOMETRY MODELING | 1-217


By not trimming the surfaces in the IGES file, the translator succeeded in creating a
valid solid. There is a need for removing some subdomains, however, to obtain the
desired solid object.

Split the solid object into its constituents by pressing the Split Object toolbar button.
Press the Create Composite Object button on the draw toolbar to open the Create

1-218 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Composite Object dialog box where the solids to be deleted can be selected. Select the
solids O4, O6, O7, O8, O9, and O11.

Click Cancel to close the dialog box and select Clear from the Edit menu (or press the
Ctrl-r key) to remove the selected solids. Select all objects by selecting Select All from

GEOMETRY MODELING | 1-219


the Edit menu (or by pressing the Ctrl-a key) and press the Union toolbar button to
create the final solid object.

Image and MRI Import


Magnetic resonance imaging (MRI) is an imaging technique used primarily in
medical settings to produce high quality images of the inside of the human body. The
more general name for the analytical technique is NMR (Nuclear Magnetic
Resonance spectroscopy). MRI data is typically represented as a sequence of 2D
images.

MRI import consists of two steps. First the images need to be imported, and the
corresponding geometry objects in FEMLAB generated. After that, 3D geometry
objects can be created using a lofting technique.

IMPORT OF IMAGES
Images of the formats JPEG, TIFF, GIF, BMP, PNG, HDF, PCX, XWD, ICO, and
CUR can be converted into 2D or 3D geometry objects, working from the MATLAB
prompt. To read graphic file format images use the MATLAB function imread. This
function converts images on graphic file format to a matrix format in the MATLAB
work space. Other useful functions are imwrite, for saving images, image, and
imagesc, for displaying images on matrix format, and imfinfo, for obtaining
information about graphics file format images. See the MATLAB documentation for

1-220 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
more information on the MATLAB functions available for image analysis. Note that
the Image Processing Toolbox contains additional functionality for advanced image
processing.

In FEMLAB, a 2D curve object can be created from an image using the function
flim2curve, and a 3D solid object from a sequence of images using the functions
flim2curve and loft. For more information, see below in this section and the
Function Reference entries flim2curve and loft.

A 2D curve describing the contour curves of an image is created by calling


flim2curve with appropriate property values. The function flim2curve utilizes
the MATLAB function imcontour for detecting contours in images. The following
example shows an image on matrix format, generated from MATLAB’s sample
function peaks, that is converted to a 2D curve object.

p = (peaks+7)*5;
figure
image(p)
v = axis;
c = flim2curve(p,{[],[5:5:75]});
g = geomcsg({rect2(5,45,0,50)},{c})
s = solid2(g);

Visualize the geometry object with the following commands.

figure
geomplot(s,’pointmode’,’off’,’sublabels’,’on’);
axis(v)
axis ij

GEOMETRY MODELING | 1-221


You can continue working on this model either from the MATLAB prompt or from
the GUI. To insert this geometry model into the GUI, select Insert from Workspace
and then Geometry Object(s)... from the File menu in the FEMLAB GUI. Once you
have done this, you can use the Split and Union buttons for creating the geometry to
be used in the simulation.

If the original image is noisy, the resulting geometry object may contain too many
edge segments to be practical to work with. The function flim2curve provides basic
functionality for filtering data by supporting the same input argument properties as
flmesh2spline (see the Function Reference entries for these functions). Also,
MATLAB provides functionality for filtering images before converting them to
FEMLAB geometry objects. See the MATLAB documentation on the functions
filter2 and conv2 for more information on how to do this.

For more information on reducing noise in point data, see “Spline Interpolation for
Creating Geometry Objects” on page 1-225.

If the processed image is large, the computation time for the MRI import functions
can be long. To reduce the computation time one can often subsample the image
before processing it. That is, reduce the number of pixels in the image. The most
simple subsampling method is to include every second pixel in the x and y direction,
respectively. More advanced subsampling methods preprocess the image by low-pass
filtering (also referred to as softening or blurring) before reducing the number of
pixels. This often gives a higher quality of the subsampled image due to the fact that
low-pass filtering reduces the amount of high frequency components in the
subsampled image (due to rasterization effects).

MRI IMPORT
When creating a 3D geometry object from a sequence of images, for example, MRI
data, the work flows as follows.

• Load MRI data to MATLAB. The 3D MRI data is typically represented as a


sequence of 2D images.
• Create a set of 2D geometry sections from the images using the flim2curve
command.
• Use the loft command to create an interpolating 3D surface between the 2D
geometry sections.
• Define your FEM problem on the resulting geometry.

The example below shows how to create a FEMLAB 3D solid object from MRI-data.

1-222 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Start by loading MRI-data from MATLAB.

load mri

This loads a sequence of images stored in multi-dimensional array called mri. It also
loads a color map named map, for illustrating the images.

Create an index vector indicating which sections to include.

i = [1 6 12 17 22 27];

Visualize the sections.

figure
for k = 1:6
subplot(2,3,k)
image(D(:,:,1,i(k)))
title(sprintf(’Image %d’,k))
axis equal,axis off
end
colormap(map)

Before creating curve objects from the images, the threshold and keepfrac data
need to be defined. The threshold value is used for creating a binary image, where all
parts of the image with a lower value than the threshold value is turned white. This
binary image is used for creating contour curve as in the function imcontour. When

GEOMETRY MODELING | 1-223


the threshold value is set to 1, the contour curves are created on the boundaries of the
regions of the images that are completely black. The keepfrac property in
flim2curve is used for determining how many points in the contours created from
the images should be used for creating a curve object. This value need to be tuned for
all images so that every created curve object consists of the same number of segments.
This is crucial for creating a 3D geometry model of the cross-section images.

th = [1 1 1 1 1 1];
kf = [0.11 0.10 0.112 0.115 0.129 0.165];

Loop over sections and save curve-data in the cell-array c.

for k = 1:6
[c{k},r] = ...
flim2curve(D(:,:,1,i(k)),{th(k),[]},’KeepFrac’,kf(k));
end

Convert 2D curve objects to 2D solid objects.

for k = 1:6
c{k} = solid2(c{k});
end

Now, each of these solid objects could be used for creating a 2D mesh, and for
solving 2D problems. Alternatively, the objects could be given specific names and
then imported into FEMLAB. For example, create

s1=c{1}

and import the solid object s1 into the GUI using Insert from Workspace, Geometry
Objects from the File menu. You can then continue modeling from the GUI, creating
a mesh, specifying the boundary conditions and material parameters, solving, and
visualizing the results.

Instead, in this example, the 2D solids are seen as 2D cross-sections of a 3D


geometry, as follows.

Create a mapping table that maps edges between sections. (See loft help text or
Function Reference entry.)

el = {18 18 18 19 19 18};

This means that edge 18 of section 1 is mapped on edge 18 of section 2. The rest of
the edge mappings between sections 1 and 2 are then automatically derived from this.
The mappings between sections 2,3; 3,4; 4,5; and 5,6, then are: 18-18, 18-19, 19-19
and 19-18, respectively.

Create 3D positioning data for the sections.

1-224 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
dvr = {repmat(12.5,1,5),repmat(0,2,6),repmat(0,1,6)};

Loft between the sections using cubic lofting (the default lofting method), with the
lofting weights explicitly given.

lg = loft(c,’loftedge’,el,’loftsecpos’,dvr,...
’loftweights’,repmat(0.1,2,5));

This geometry object can now be imported to the GUI.

• In the Model Navigator, select the 3D, Geometry Only application mode.
• Select Insert from Workspace from the File menu. To import a geometry object,
select Geometry object(s)... and then type the name lg.
• Click the Headlight and Perspective Projection toolbar buttons.
• Click the Render Edges and Highlight Edges toolbar buttons, to avoid visualizing the
edges in the geometry.

You can now continue and use this geometry as part of a simulation: create a mesh,
solve, and post process the solution. Note that to be able to mesh this on a computer
with limited memory resources, you need to select a coarse mesh setting.

Spline Interpolation for Creating Geometry Objects


To create a curve object from a set of data points, the function geomspline can be
used. It creates C1 or C2 continuous splines for the interpolation between the points.

The use of geomspline is illustrated below by creating a geometry object with


splines created from irregularly distributed points on a circle.

GEOMETRY MODELING | 1-225


First create the circle data, sorted by the angle, and remove some of the points.

phi = 0:0.2:2*pi;
phi([1 3 6 7 10 20 21 25 28 32]) = [];
p = [cos(phi);sin(phi)];

Add some noise to the data points.

randn(’state’,17)
p = p+0.01*randn(size(p));

Different global parametrization techniques can be used in geomspline. The global


parametrization is a parameter that varies from 0 in the first interpolated point to 1
in the last interpolated point. For a closed curve these two points coincide. For details
on the different parametrization techniques, see the reference entry on geomspline
in the Function Reference.

First use a uniform parametrization technique. This is the most straightforward


technique, but it does not always work well on irregularly distributed data.

plot(p(1,:),p(2,:),’ro’)
c = geomspline(p,’splinemethod’,’uniform’,’closed’,’on’)
hold on
geomplot(c,’pointmode’,’off’)

Then interpolate using centripetal parametrization and note the difference.

c = geomspline(p,’splinemethod’,’centripetal’,’closed’,’on’)
hold on
geomplot(c,’pointmode’,’off’,’edgecolor’,’b’)
axis equal

0.8

0.6

0.4

0.2

−0.2

−0.4

−0.6

−0.8

−1
−1 −0.5 0 0.5 1

1-226 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
For creating a solid geometry from this, on which you can set up a FEM problem,
simply enter

s = solid2(c);

To use this geometry for modeling in the GUI select Insert from Workspace, and
Geometry Object(s)... from the File menu in the FEMLAB GUI. This is done when the
Draw Mode is active, either when setting up a 2D problem or when a work plane has
been defined when setting up a 3D problem. Once this is done you can use the
ordinary geometry operations to continue working on the model.

Occasionally, point data can be too dense or contain too much noise to be practical
to work with. The functions flcontour2curve and flmesh2spline contain basic
functionality to reduce the number of edge segments in a point set. To understand
the MATLAB contour data format, see the MATLAB functions imcontour,
contour, and contourc.

Note that you can also use geomspline for creating 3D curve objects. Using the data
created in the previous example, define the z coordinates to create the following 3D
curve object.

p = [p;linspace(0,3,22)];
c = geomspline(p,’splinemethod’,’centripetal’,’closed’,’off’)

GEOMETRY MODELING | 1-227


Surface Interpolation
A 3D face object or a 2D solid object can be created from a 3D point set or a 2D point
set respectively using the function geomsurf; see the Function Reference entry
geomsurf for more information.

2D SOLID OBJECTS
A solid object with rectangular subdomains can be created from a rectangular point
set using geomsurf. In the following example a solid object with non-uniformly
distributed subdomains is generated from a non-uniform grid.

[x,y] = meshgrid(0:0.1:1,0:0.2:1);
rand(’state’,1);
x = x+repmat((0.1*rand(1,size(x,2))),size(x,1),1);
rand(’state’,1);
y= y+repmat((0.2*rand(size(y,1),1)),1,size(y,2));
s = geomsurf(x,y);
figure
geomplot(s,’pointmode’,’off’)
axis equal

This can be used for defining a domain with a non-uniform distribution of some
material parameter.

1-228 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
You can import this geometry object into the GUI.

• From the File menu, select Insert from Work Space, Geometry Object(s).
• Type the name of the object, s, in the edit field of the dialog box opened, and press
OK.

3D FACE OBJECTS
By using the function geomsurf, a surface can be created from height data defined
on a grid by bilinear interpolation. The surface created is identical in shape to the
surface created with the MATLAB command surf. The following example illustrates
how to generate a surface from simulated or measured data and how to insert the
generated surface as the top surface of a solid block.

The height data is defined as deviations, with a maximum deviation of 0.03, from a
reference plane situated at z equal to 0.7.

dev_max = 0.03;
ref_level = 0.7;
[x,y] = meshgrid(0:0.1:1,0:0.1:1);
randn(’state’,1);
z = ref_level+dev_max*randn(size(x));

Create a surface from the height data.

f = geomsurf(x,y,z);

Create a solid block whose top surface lies above the generated surface.

b = block3(1,1,ref_level+3*dev_max);

The geometry objects f and b can now be inserted in the GUI.

• Start the FEMLAB GUI. In the Model Navigator, select the 3D, Geometry Only
application mode.

GEOMETRY MODELING | 1-229


• On the File menu, select Insert from Work Space, Geometry Object(s).
• In the dialog box edit field, type a space-separated list of object names: b f, and
press OK.
• In the GUI, select both objects and click the Coerce to Solid toolbar button. This
will merge the objects, one face object and one solid object, into a single solid
object.
• Now, split the object by pressing the Split Object toolbar button.
• Delete the object on the top.

This is the resulting geometry object.

1-230 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
• You can now create a mesh by pressing the Initialize Mesh button, and add any
application mode to solve a problem on this geometry.

From the prompt, the same operations can be made as follows.

Intersect the solid block with the generated surface and split the resulting solid
object.

s = geomcoerce(’solid’,{b,f});
ss = split(s);

Mesh the solid object with the interpolated surface as top surface.

m = meshinit(ss{1});
figure
meshplot(m)
axis equal
cameramenu

This will visualize the mesh in a MATLAB figure window.

If the original data set is noisy, the resulting geometry object may contain too many
faces to be practical to work with. MATLAB provides functionality for filtering data
sets before converting them to FEMLAB geometry objects. See the MATLAB
documentation on the functions filter2 and conv2 for more information on how
to do this.

GEOMETRY MODELING | 1-231


Insertion of Points in Geometry Models
In some modeling situations it is desirable to insert a series of points into a geometry
model created in FEMLAB. This is typically the case in any of the following two
situations:

• You want to set point constraints or point sources, see “Example: Poisson’s
Equation with a Point Source” on page 3-85.
• You want to retrieve values of the solution for certain coordinates. Inserting
explicit points at the coordinate values is not necessary but is sometimes
convenient. This will ensure that the mesh have node points in the explicitly added
points.

Points are most easily inserted into a FEMLAB geometry model using the
Programming Language. You can also load the coordinate values from a file, see
“Importing Data from Text File” on page 1-294.

The following model illustrates how points can be inserted into a geometry.

• Select 3D, Electrostatics application mode from the Model Navigator.


• Draw a sphere with radius 5 centered at the origin, and a block with side lengths
of (10,10,5) centered at the point (0,0,-2.5).

1-232 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
• Open the Create Composite Object dialog box, select both objects, type the formula
SPH1-BLK1 in the Set formula field and press OK. This results in the hemisphere
object CO1.

• Export the geometry object by selecting Export to Workspace, Geometry as


Objects... from the File menu. Then press OK to use the same name for the object in
the MATLAB workspace as in the FEMLAB GUI.
• Run the following script to create the vertices equally distributed on constant
radius in a spherical coordinate system.
% Radius as parameter
r = 5;
% Create a grid of points using spherical coordinates
% on the surface
m = 11; n = 11;
[theta,phi] = meshgrid(...
linspace(0,pi*(1-1/m),m),...
linspace(0,2*pi*(1-1/n),n));

% Evaluate coordinate values from parameters


x = r*sin(theta).*cos(phi);
y = r*sin(theta).*sin(phi);
z = r*cos(theta);

% Create cell array of POINT3 objects.


v = {};
for k = 1:prod(size(x))
v{k} = point3(x(k),y(k),z(k));
end

GEOMETRY MODELING | 1-233


% Insert the point object into original object and coerce to solid
CO1 = geomcoerce(’solid’,{CO1 v{:}});

• The new object can now be inserted into the FEMLAB GUI. First remove the
original object named CO1. Then select Insert from Workspace from the File menu.
Choose Geometry as Object(s)... and give the name CO1. Press OK.
You can also insert the points directly into the GUI and draw the rest of the
geometry using the graphical CAD tools. To do this you create a composite point
object instead of a solid object by entering the MATLAB command
CO1 = geomcoerce(’point’,v);

• To solve a simple problem, select Ground as boundary condition for boundary 1.


Then press the Solve Problem button.

• To study the values of the solution in the vertices you created above, select Export
FEM structure as ‘fem’ from the File menu. Then give the following command at
the MATLAB prompt.
V1 = posteval(fem,’V’,’edim’,0,’dl’,[3 5 7 13 21 35]);

The variable V1 is a cell array of length 1. The values of the vertices can be visually
inspected by selecting Surface plot in the GUI and giving V as the Surface expression
in the Plot Parameters dialog box. Also select Show Vertex Labels from the Options,
Labels menu.

1-234 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Parameterization of Curves and Faces
The curves and surfaces of a geometry object may have several different mathematical
representations. In FEMLAB, rational parameterizations are used in the
representation of curves and surfaces. For a detailed description of these
representations, see “Geometry Modeling” on page 3-10 in the Reference Manual.
This means that there is a parameter s1 for curves and two parameters, s1 and s2, for
faces that can be used when setting up a model or in the postprocessing functions
available in FEMLAB. More precisely, this means that for each value of the curve
parameter s1 there is a unique point lying on the curve. For faces, each pair of values
(s1,s2) corresponds to a unique point that lies on the face.

The faces and edges used in the FEMLAB geometry representation are trimmed
surfaces and curves respectively. This means that there is a well-defined boundary in
the parameter domain that determines the valid values of s1 and s2. In 2D, the
possible values of s1 will in almost all cases be the interval [0,1], but in 3D the
parameter domain is more complicated. For surfaces as well as for curves.

The best way of determining the parameterization is to plot the parameter values.
You can do this for a block as described below.

• Start any 3D application mode in the FEMLAB GUI.


• Draw a Block object with the side lengths 2, 4, and 1 respectively.
• To see how the faces and curves are parameterized before setting up the problem,
select Get Initial Value from the Post menu. This enables you to use the plotting
tools without solving the problem first.
• Deselect Slice plot and select Line plot instead. At the Line page, set the Line
expression to s1. The different geometric variables that are available for plotting

GEOMETRY MODELING | 1-235


are listed in the tables in“Geometric Variables” on page 1-352 and “Geometric
Variables” on page 3-56 in the Reference Manual.

• To visualize the surface parameters on the faces, select Surface plot and give either
s1 or s2 as Surface expression. Make sure to deselect Smooth before plotting, to
avoid an incorrect smoothing over the edges.

Sometimes you may need to modify the parameterization of one or several surfaces
or curves. This is often the case when using periodic boundary conditions in 3D.
Periodic boundary conditions means that two boundaries should be regarded as the
same when assembling the problem. This means that they must have identical
parameter representations.

1-236 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The best way of accomplishing equal parameterizations is to use the extrude and
revolve functionality when creating the geometry models. These functions are
naturally used together with periodic boundary conditions, since they are both two
forms of connecting several faces that are identical with respect to the
parametrization. In some cases, the geometry cannot be created this way. However,
there are alternative ways for obtaining matching parameterizations.

If you study the parameterization of the upper and lower face, with respect to the
z-axis, in the block object above, you can see that the s2 parameter is increasing along
the y-axis for one of the faces and decreasing for the other. This means that these two
faces cannot be used for setting up periodic boundary conditions. There may also be
other reasons than using periodic boundary conditions for wanting to change the
parameterization. Matching parameterizations can be accomplished as described
below.

• Push the Draw mode button and select the object BLK1. Press the Coerce to Face
button followed by the Split Object button.
• Delete face object F4.
• Copy face F3 and set the z-displacement to 1, and the other two displacements to
0 when pasting the new object.
• Select all objects and press the Coerce to Solid button. A new solid object with the
desired parameterization has now been created. To see the new parameterization,
select Get Initial Value from the Post menu. Set the surface expression to s1 or s2
to see that the parametrization is the same for the two faces.

GEOMETRY MODELING | 1-237


Associative Geometry
Associative geometry is a notion for automatic updating of applied physical
properties, such as boundary conditions and PDE coefficients, under geometric
transformations. This means that if you have defined the physical properties of your
FEM model and return to draw mode to modify the geometric model, the physical
properties are updated according to the geometrical modifications as you leave draw
mode.

The associative geometry functionality is essentially built upon geometrical mapping


information between the domain groups, that is, vertices, edges, boundaries, and
subdomains in 3D, in the analyzed geometric object, and the corresponding domain
groups in the geometric model available in draw mode.

Note however that this geometrical mapping is not without ambiguities. This means
that some decisions have to be made by the associative geometry functionality when
mapping the physical properties between the analyzed geometric object, that is, the
object on which the physical properties are imposed, and the geometric model
available in draw mode. This implies that in some cases, the resulting updated
physical properties might not be as desired.

1-238 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The Application Modes
FEMLAB can be applied to a large number of problems in engineering and science.
To help you in setting up material properties and boundary conditions for some
important and common applications, several different physics application modes are
available in addition to the PDE modes for PDEs on coefficient, general, and weak
form.

Note Additional application modes are available in the specialized add-on modules
for chemical engineering, electromagnetics, and structural mechanics.

The available application modes are listed below. The application modes are divided
into four groups: Physics modes, PDE modes, Weak modes, and Classical PDEs.

APPLICATION MODE 1D 2D 3D

PHYSICS MODES

AC power electromagnetics ♦
Conductive media DC ♦ ♦
Diffusion ♦ ♦ ♦
Electrostatics ♦ ♦
Magnetostatics ♦ ♦
Heat transfer ♦ ♦ ♦
Incompressible Navier-Stokes ♦ ♦
Structural mechanics - Plane strain ♦
Structural mechanics - Plane stress ♦
Structural mechanics ♦
PDE MODES

Coefficient form ♦ ♦ ♦
General form ♦ ♦ ♦
WEAK MODES

Subdomain ♦ ♦ ♦
Boundary ♦ ♦ ♦
Edge ♦

THE APPLICATION MODES | 1-239


APPLICATION MODE 1D 2D 3D

Point ♦ ♦
Boundary Constraint ♦ ♦ ♦
CLASSICAL PDES

Laplace’s equation ♦ ♦ ♦
Poisson’s equation ♦ ♦ ♦
Helmholtz’s equation ♦ ♦ ♦
Heat equation ♦ ♦ ♦
Wave equation ♦ ♦ ♦
Schrödinger equation ♦ ♦ ♦
Convection-diffusion equation ♦ ♦ ♦

The PDE modes, the Weak modes and the Classical PDEs are used for modeling
directly with PDEs. Refer to “The FEMLAB PDE Language” on page 1-336 and
“The Partial Differential Equations” on page 3-25, in the Reference Guide, for details
on how to model in these application modes. In this section, the Physics modes will
be explained in more detail.

The Physics Modes


When using an application mode, the generic PDE coefficients are automatically
computed from application-specific parameters such as Young’s modulus for a
structural mechanics model, or the heat capacity for a heat transfer model.

You select an application mode from the Model Navigator before you start working
on a new model. You can also add application modes to an existing model to create
a multiphysics model. The names of the dependent variables will then be extended as
described in the section “Variable Name Suffixes For Multiphysics” on page 1-374.

The application-specific subdomain parameters are entered by selecting Subdomain


Settings from the Subdomain menu. You can also access the subdomain parameters by
double-clicking on a subdomain, if you are in the subdomain mode. In 3D you
double-click using the right mouse button, since left-clicking toggles the selection of
overlapping domains. For a complete description of the material properties available
for an application mode, see the section “Application Mode Reference” on page
4-203 in the Reference Manual.

1-240 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The Boundary Settings dialog box also adapts to the current application and lets you
select from a set of application-specific boundary conditions. The boundary
conditions can be divided into two fundamental types: Dirichlet boundary
conditions and Neumann boundary conditions.

In 2D, Dirichlet and Neumann conditions are indicated by solid (-) and dashed (--)
boundaries, respectively. If there is more than one boundary condition of a particular
type, they are differentiated by using different colors - black (k), blue (b), magenta
(m), and cyan (c). For a complete description of the boundary conditions available for
an application mode, see the section “Application Mode Reference” on page 4-203
in the Reference Manual.

In post mode, the Plot Parameters dialog box and the Cross-Section Plot Parameters
dialog box allow you to visualize any variable, or expression of variables, defined by
the application mode. The Subdomain Integration dialog box and the Boundary
Integration dialog box allow you to compute integrated values for the same set of
variables. For a complete list of the accessible variables, see the section “Application
Mode Reference” on page 4-203 in the Reference Manual. A special set of variables,
called the application mode variables, can also be seen in the Assigned Variable
Names... dialog box opened from the Options menu. These variables are application
specific expressions in the other variables.

Notice that for all application modes, you have access to the shape function variables
and equation variables, for the corresponding PDE solution form, coefficient or
general, as described in the section “The FEMLAB PDE Language” on page 1-336.

The following table lists the available Physics modes. The dependent variables
column contains the variables the PDEs are formulated for. The different analysis

THE APPLICATION MODES | 1-241


capabilities are given. Multiphysics means that the application mode can be coupled
to an arbitrary FEMLAB application mode.
TABLE 1-1:

APPLICATION MODE DEP. VAR. ANALYSIS CAPABILITIES

HEAT TRANSFER

Heat transfer T √ √ √
DIFFUSION

Diffusion c √ √ √
ELECTROMAGNETICS

AC power electromagnetics, 2D Ez √ √
Conductive media DC V √ √
Electrostatics V √ √
Magnetostatics Az √ √
STRUCTURAL MECHANICS

Structural mechanics, 3D u,v,w √ √ √ √


Plane stress, 2D u,v √ √ √ √
Plane strain, 2D u,v √ √ √ √
INCOMPRESSIBLE NAVIER STOKES

Incompressible Navier-Stokes, 2D u,v,p √ √ √


Incompressible Navier-Stokes, 3D u,v,w,p √ √ √

In the remaining part of this section, you will find an introductory description of the
application modes. For a more extended description of the details of the application
modes, see the corresponding entries in “Application Mode Reference” on page
4-203 in the Reference Manual.

1-242 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Heat Transfer
Heat transfer is the common denominator of most multiphysics problems. This is
because most physical processes generate heat due to thermal losses, as a consequence
of the laws of thermodynamics.

Note The Chemical Engineering Module includes an application mode for


axisymmetric heat transfer.

H E AT TR A N S F E R, 1 D, 2 D, A N D 3 D

PDE Formulation
Heat transfer is governed by the heat equation

∂T
ρC ------- – ∇ ⋅ ( k∇T ) = Q
∂t

where ρ is the density, C is the heat capacity and k is the thermal conductivity. For a
stationary problem, the first term containing ρ and C is ignored. The thermal
conductivity can be anisotropic, in which case k is a matrix.

The Heat transfer application mode models the heat equation.

Subdomain Parameters
The subdomain parameters are:

Density This material property, denoted by ρ, specifies the density of the material.

Heat Capacity The heat capacity, or specific heat, is denoted by C, and describes the
amount of heat energy required to produce a unit temperature change in unit mass,
that is, the capacity of a material to store thermal energy.

Thermal Conductivity The thermal conductivity, is denoted by k, and describes the


relation between the heat flux vector q, and the temperature gradient: q=−k∇T.
This relation is also known as Fourier’s law of heat conduction.

THE APPLICATION MODES | 1-243


Heat Source The heat source describes the external heat sources. In 3D, the heat
source is given by a single quantity Q. In 1D and 2D, there can also be transversal heat
sources, which leads to a heat source of the form
4 4
Q + h trans ( T ext – T ) + Ctrans ( T ambtrans – T )

For a description of heat sources, see below.

Boundary Conditions
The boundary conditions are:

Heat Flux Sources


4 4
n ⋅ ( k∇T ) = q + h ( T inf – T ) + C const ( T amb – T )

This boundary condition specifies the inward boundary heat flux −n ⋅ q . The more
advanced boundary heat source terms can be defined in 1D or 2D, see below. A
description of heat sources is also provided below.

Insulation or Symmetry

n ⋅ ( k∇T ) = 0

This boundary condition specifies a zero inward boundary heat flux, equivalent to a
symmetry boundary condition.

Temperature
T = T0

This boundary condition is used to specify a temperature on the boundary, and is


often used to describe, approximately, a boundary with a very high heat transfer
coefficient (see below).

Zero Temperature or Antisymmetry


T = 0

This boundary condition specifies a zero boundary temperature and is equivalent to


an antisymmetry boundary condition.

1-244 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Boundary Heat Flux
The boundary conditions can be of Dirichlet type, where the temperature on the
boundary is specified, or of Neumann type where the inward heat flux, n ⋅ (k∇T) is
given as

4 4
n ⋅ ( k∇T ) = q + h ( T inf – T ) + C const ( T amb – T )

The expression h(Tinf – T) is known as Newton’s law of cooling, and specifies the heat
flux from the surroundings, where h is the heat transfer coefficient and Tinf is the
external temperature. The value of h is dependent of the geometry and nature of the
boundary segment.

For modeling of radiative heat transfer from a surrounding material, the expression
Cconst (T4amb– T4) is used. Tamb is the ambient temperature, which is not
necessarily the same as Tinf. Cconst is a constant dependent of the absorption and
emissitivity of the surface.

For direct specification of the inward heat flux, or as an approximation of the


convective or radiative heat flux, the parameter q can be set.

Advanced Heat Sources


In 2D and 1D, it is often of interest to have heat flux sources in the transversal
direction of the modeling, for example, for modeling cooling of thin plates in 2D. To
model these effects, the PDE of the heat transfer problem are modified according to

∂T 4 4
ρC ------- – ∇ ⋅ ( k∇T ) = Q + h trans ( T ext – T ) + Ctrans ( T ambtrans – T )
∂t

where two expressions similar to the ones for the boundary condition equation have
been added on the right hand side. The interpretation of these expressions is the same
as for the boundary condition case, with the exception that they define the transversal
heat flux.

The term htrans (Text – T) is a model of convective transversal heat transfer from the
surroundings, and it can be useful for modeling heat transfer in thin cooling plates,
etc. The parameter htrans is the convective transversal heat transfer coefficient, and Text
is the external temperature.

Similarly, the term Ctrans (T4ambtrans– T4), models radiative heat transfer from the
surroundings, where Ctrans is a constant and Tambtrans is the transversal ambient
temperature.

THE APPLICATION MODES | 1-245


When you are considering a stationary problem with radiation sources, that is, Ctrans
or Cconst are non-zero, you must use the nonlinear solver. Therefore, the Heat
transfer application mode uses the nonlinear solver by default, even if there is no
nonlinear term in the model. In that case, it will converge immediately, but you can
also use the direct, linear solver instead, by changing Solver type in the Solver
Parameters dialog box. If you have a strongly nonlinear radiation source, you must
change solution form to generalto get the correct Jacobian for faster convergence.

Postprocessing and Anisotropic Materials


As postprocessing variables, you find the temperature, T, the temperature gradient,
∇T, the heat flux, −k∇T, and the normal heat flux n ⋅ (-k∇T). Also available are the
material properties ρ and C, as well as the source Q. The thermal conductivity is not
available, see the note below.

For a complete list of postprocessing variables, see the section on “Application Mode
Reference” on page 4-203 in the Reference Manual.

You can model an anisotropic thermal conductivity by entering space-separated


entries according to the PDE coefficient syntax. See the section “Anisotropic
Materials” on page 1-359 for details. This means that k is not available as a variable
for postprocessing.

For a detailed description of the fundamentals of heat transfer, see [1].

References
[1] Incropera, Frank P., and DeWitt, David P., Fundamentals of Heat and Mass
Transfer, 4th edition, John Wiley & Sons, New York, 1996.

Diffusion
Diffusion processes are ubiquitous in chemical engineering and are governed by the
same equation as heat transfer [1]. Potential flow problems are also described by the
diffusion equation, for example, Darcy’s law problems, but the physical
interpretation is different.

Note The Chemical Engineering Module contains more elaborate application


modes for diffusion processes, as well as for potential flow problems.

1-246 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
PDE Formulation
Since heat transfer is a diffusion process, the generic diffusion equation has the same
structure as the heat equation [2]:
∂c
----- – ∇ ⋅ ( D∇c ) = Q
∂t

where c is the concentration, D is the diffusion coefficient and Q is a volume source.


The diffusion process can be anisotropic, in which case D is a matrix. The diffusion
equation is modeled in the Diffusion application mode.

For potential flow problems, the concentration is reinterpreted as the pressure.

Subdomain Parameters
The subdomain parameters are:

Diffusion Coefficient This material property, denoted by D, describes the diffusive


conductivity of a material, that is, the relation between the concentration gradient
and the mass flux.

Volume Source The volume source, Q, describes the volume density of mass
creation.

Boundary Conditions
The boundary conditions are:

Inward Flux and Membrane Coefficient

n ⋅ ( D ∇c ) + qc = g

The boundary condition is of a generalized Neumann type where the inward flux,
n ⋅ (D∇c), is specified, and where q is a transfer coefficient.

Impervious or Symmetry

n ⋅ ( D ∇c ) = 0

The second boundary condition specifies an impervious boundary or a symmetry


boundary condition.

Concentration
c = c0

The third condition sets a value of the concentration on the boundary.

THE APPLICATION MODES | 1-247


Zero Concentration
c = 0

The fourth boundary condition sets the boundary concentration to zero, equivalent
of an antisymmetry boundary condition.

Postprocessing and Anisotropic Materials


Available as postprocessing variables are the concentration c, the concentration
gradient, ∇c, the diffusive flux, −k∇c, and the normal component of the diffusive
flux, n ⋅ (-k∇c). Also available is the source Q. The diffusion coefficient D is not
available, see below.

For a complete list of postprocessing variables, see the section on “Application Mode
Reference” on page 4-203 in the Reference Manual.

You can model an anisotropic diffusion coefficient by entering space-separated


entries according to the PDE coefficient syntax. See the section on “Anisotropic
Materials” on page 1-359 for details. This means that D is not available as a variable
for postprocessing.

References
[1] R. B. Bird, W. E. Stewart and E. N. Lightfoot, Transport Phenomena, John Wiley
& Sons, 1960.

[2] Gresho, P.M, and Sani, R.L., Incompressible Flow and the Finite Element
Method, Volume 1 & 2, John Wiley & Sons, New York, 2000.

Electromagnetics
For simulating electromagnetic phenomena, there are four application modes
available in FEMLAB. Three of these modes, Electrostatics, Conductive media DC,
and Magnetostatics, are used for static simulations. Under static conditions, either
the electric properties are modeled, as is the case for the former two modes, or the
magnetic properties, as is the case for Magnetostatics. In the case of time varying
fields, the electric and magnetic quantities are coupled, and obtained in one
simulation, as is the case for the AC power electromagnetics application mode.

Following a brief introduction to electromagnetics, and definition of the


electromagnetic quantities, the four application modes are presented in subsequent
sections.

1-248 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Note The Electromagnetics Module contains specialized and extended application
modes and models for electromagnetic simulations, for example, for computations
of inductors and capacitors. The Electromagnetics Module also includes application
modes for wave propagation problems for microwave engineering and photonics.

PRELIMINARIES OF ELECTROMAGNETICS
The problem of electromagnetic analysis on a macroscopic level is the problem of
solving Maxwell’s equations subject to certain boundary conditions. Maxwell’s
equations, written in differential or integral form, state the relationships between the
fundamental electromagnetic quantities. These quantities are the electric field intensity
E, the electric displacement or electric flux density D, the magnetic field intensity H, the
magnetic flux density B, the current density J and the electric space charge density ρ.

Maxwell’s Equations
The equations can be formulated in differential or integral form. The differential
form will be presented here, since it leads to differential equations that can be handled
by the finite element method. For general time-varying fields, Maxwell’s equations
can be written as [1,3]

∇×H = J + ∂D
∂t

∇×E = – ∂B
∂t
∇⋅D =ρ
∇⋅B =0

The first two equations are also referred to as Maxwell-Ampère’s law and Faraday’s law.
Equation three and four are two forms of Gauss law, the electric and magnetic form
respectively.

Another fundamental equation is the equation of continuity, which can be written as


∂ρ
∇⋅J = –
∂t

THE APPLICATION MODES | 1-249


Out of the five equations mentioned only three are independent. The first two
combined with either the electric form of Gauss’ law or the equation of continuity
form such an independent system.

Constitutive Relations
To obtain a closed system, the constitutive relations, describing the macroscopic
properties of the medium, are included. They are given as
D = ε0E + P
B = µ0 ( H + M )
J = σE

Here ε0 is the permittivity of vacuum, µ0 is the permeability of vacuum, and σ the


conductivity. In the SI system the permeability of vacuum, or free space, is chosen to
be 4π10-7 H/m. The velocity of an electromagnetic wave in free space is given as c0
and the permittivity of free space is derived from the equivalence

1 – 12 1 –9
ε 0 = ----------
- = 8.854 ⋅ 10 F/m ≈ ---------- ⋅ 10 F/m .
2
c0 µ0 36π

The electric polarization vector P describes how the material is polarized when an
electric field E is present. It can be interpreted as the volume density of electric dipole
moments. P is generally a function of E and some materials can have a non-zero P
also when there is no electric field present.

The magnetization vector M similarly describes how the material is magnetized when
a magnetic field H is present. It can be interpreted as the volume density of magnetic
dipole moments. M is generally a function of H and permanent magnets for instance
have a non-zero M also when there is no magnetic field present.

For linear materials the polarization is directly proportional to the electric field,
P = ε 0 χ e E , where χe is the electric susceptibility. Similarly in linear materials the
magnetization is directly proportional to the magnetic field, M = χ m H , where χm
is the magnetic susceptibility. For such materials the constitutive relations can be
written
D = ε0 ( 1 + χ e )E = ε 0 εr E = εE
B = µ 0 ( 1 + χ m )H = µ 0 µ r H = µH

The parameter εr is the relative permittivity and µr is the relative permeability of the
material. Usually they are scalar properties but can in the general case be 3-by-3

1-250 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
tensors when the material is anisotropic. The properties ε and µ without subscripts
are the permittivity and permeability of the material.

Generalized Constitutive Relations


In the application modes, a more generalized form of the constitutive relations is
used. The form used for the electric fields is
D = ε 0 εr E + P

This can be seen as combination of the two versions above, and can if not used
correctly lead to double-counting of the polarization. By either setting εr = 1 or
P = 0 we obtain either of the two forms above. Thus be careful when you specify
these properties. For nonlinear materials with a more complicated constitutive
relation both εr and P may have non-trivial values.

Similarly the constitutive relation for the magnetic fields we will use is
B = µ0 µr ( H + M )

This can also be seen as a combination of the two forms above, and can if not used
correctly lead to a double-counting of the magnetization. By either setting µ r = 1 or
M = 0 we obtain either of the two forms above. For nonlinear materials, with a
more complicated constitutive relation, both µr and M can have non-trivial values.

The third equation can be generalized by the introduction of an externally generated


e
current, J . This relation can accordingly be written
J = σ E + Je

Potentials
Under certain circumstances it can be helpful to formulate the problems in terms of
the electric scalar potential V and magnetic vector potential A. They are given by the
equalities
B = ∇×A

E = – ∇V – ∂ A
∂t

which are direct consequences of the magnetic case of Gauss’ law and Faraday’s law
respectively.

Material Properties
This far the constitutive relations have only been introduced formally. These
seemingly simple relations can be quite complicated at times. There are four main

THE APPLICATION MODES | 1-251


groups of materials where these relations requires some considerations. A material
can fall into any numbers of these groups. The groups are:

• inhomogeneous materials
• anisotropic materials
• nonlinear materials
• dispersive materials

The least complicated of the above groups is the one including inhomogeneous
materials. An inhomogeneous medium is simply one where the constitutive
parameters vary with the space coordinates, so that different field properties prevail
at different parts of the material structure.

For anisotropic materials the field relations at any point are different for different
directions of propagation. This means basically that a 3-by-3 tensor is required to
properly define the constitutive relations. If this tensor is symmetric, the material is
often referred to as reciprocal. In these cases the coordinate system can be rotated in
such a way that a diagonal tensor is obtained. If two or three of the diagonal entries
are equal, the material is uniaxially anisotropic. If two of the elements have the same
value, the material is biaxially anisotropic [2]. Examples where anisotropic
parameters are used are for permittivity in crystals, and conductivity when modeling
solenoids.

Nonlinearity is the effect of variations in permittivity or permeability with the


intensity of the electromagnetic field. This also includes hysteresis effects, where not
only the current field intensities influence the physical properties of the material, but
also the history of the field distribution.

Finally, dispersion describes changes in the velocity of the wave with wavelength. In
the frequency domain, dispersion is expressed by a frequency dependence of the
constitutive laws.

The FEMLAB solvers handle all of the above whenever the PDE can be derived
without any assumptions on the constitutive laws.

1-252 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Boundary and Interface Conditions
To get a full description of an electromagnetic problem we also need to specify
boundary conditions at material interfaces and physical boundaries. At interfaces
between two media the boundary conditions can be expressed as

n2 × ( E1 – E2 ) = 0
n2 ⋅ ( D1 – D2 ) = ρs
n2 × ( H1 – H2 ) = Js
n 2 ⋅ ( B1 – B2 ) = 0

where ρs and J s denote surface charge density and surface current density
respectively, and n2 is the outward normal from medium 2. Of these four conditions
only two are independent; one from the first and the fourth equation, and the other
from the second and third.

A consequence of the above is the interface condition for the current density,
∂ρs
n 2 ⋅ ( J 1 – J 2 ) = – --------
∂t

Interface Between a Dielectric and a Perfect Conductor


A perfect conductor has infinite conductivity, and as such it has no internal electric
field. Otherwise, it would produce an infinite current density according to the third
fundamental constitutive relation. At an interface between a dielectric and a perfect
conductor, the boundary conditions for the E and D fields are simplified. If, say,
subscript 1 corresponds to the perfect conductor, then D1=0 and E1=0 in the
relations above. If, in addition, we have a time-varying case, then B1=0 and H1=0
as well, as a consequence of Maxwell’s equations. The result is the following set of
boundary conditions for the fields in the dielectric medium for the time-varying case

– n2 × E2 = 0
– n2 × H2 = Js
–n2 ⋅ D2 = ρs
–n2 ⋅ B2 = 0

References
[1] Cheng, D. K. Field and Wave Electromagnetics. Addison-Wesley. Reading, 1989.

THE APPLICATION MODES | 1-253


[2] Jin, Jianming. The Finite Element Method in Electromagnetics, John Wiley & Sons,
New York, 1993.

[3] Popovic, Branko D., Introductory Engineering Electromagnetics,


Addison-Wesley, Reading, MA, 1971.

ELECTROSTATICS, 2D AND 3D
Applications involving electrostatics include high voltage apparatus, electronic devices,
and capacitors. The “statics” implies that the time rate of change is slow, and that
wavelengths are very large compared to the size of the domain of interest.

PDE Formulation
In electrostatics, the scalar electrostatic potential V is related to the electric field
density E by E = –∇V and, using one of Maxwell’s equations, ∇ ⋅ D = ρ , and the
relationship D = ε0εrE+P, where P is the polarization vector, we arrive at the
equation

– ∇ ⋅ ( ε 0 εr ∇V – P ) = – ∇ ⋅ ( ε∇V – P ) = ρ

where ε is the permittivity and ρ is the space charge density. The permittivity can be
anisotropic, in which case ε is a tensor.

Using the Electrostatics application mode, you can solve electrostatic problems
modeled by the equation above.

Subdomain Parameters
The subdomain parameters are:

Permittivity This material property is denoted by ε=ε0εr , where εr is the relative


permittivity and ε0 is the permittivity of vacuum. The permittivity of vacuum is a
universal constant that, in electrostatics, describes the relation between the electric
charge and the electric field. The relative permittivity is a material property that
describes the relation between the electric field, E, and the electric displacement, D,
in a material.

Space Charge Density This parameter is denoted by ρ and specifies the volume
density of electric charges in a material.

Polarization Vector The polarization vector, P= (Px,Py,Pz), describes the volume


density of bound charges in a material. In 2D, only the x and y components of P are
available.

1-254 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Note ε0 is the permittivity of vacuum (8.854 ⋅ 10-12 Farad/meter), and εr is the
relative permittivity that varies among different dielectric media (1.00059 in air,
2.24 in transformer oil, etc.)

Boundary Conditions
The boundary conditions for electrostatic problems can be of Dirichlet or Neumann
type. For Dirichlet conditions, the electrostatic potential V is specified on the
boundary. For Neumann conditions, the surface charge density −n ⋅ D = ρs is
specified on the boundary. The following options are available.

Surface Charge Density

– n ⋅ D = ρ s = ρ 0s

This boundary condition is used for specifying a surface charge density.

Electric Insulation or Symmetry

–n ⋅ D = 0

This boundary condition is used for defining a zero surface charge, but can also be
used as a symmetry boundary condition. This is the default boundary condition on
internal borders, and as such it specifies a continuous normal component of D.

Electric Potential

V = V0

This boundary condition is used for specifying the electric potential.

Ground or Antisymmetry

V = 0

This boundary condition is used for defining a zero electric potential, but can also be
used as an antisymmetry boundary condition.

THE APPLICATION MODES | 1-255


Postprocessing and Anisotropic Materials
As postprocessing variables you find, among others, the electrostatic potential V, the
electric field intensity E, the electric displacement D, and the surface charge density
ρs. Also available are the material properties, the space charge density ρ and the
polarization vector P. The permittivity is not available, see below.

For a complete list of postprocessing variables, see the section on “Application Mode
Reference” on page 4-203 in the Reference Manual.

You can model an anisotropic permittivity by entering space-separated entries


according to the PDE coefficient syntax. See the section “Anisotropic Materials” on
page 1-359 for details. This means that ε is not available as a variable for
postprocessing.

MAGNETOSTATICS, 2D AND 3D
Magnets, electric motors, and transformers can often be modeled by magnetostatics.
The “statics” implies that the time rate of change is slow.

PDE Formulation
To derive the equation system solved, start with Maxwell’s equations for static cases,

∇×H = J
∇⋅B = 0

and the relationship

B = µ0 µr ( H + M ) = µ ( H + M )

where B is the magnetic flux density, H is the magnetic field intensity, J is the current
density, M is the magnetization vector, and µ is the material’s permeability.

Since the magnetic flux density is divergence free, there exists a magnetic vector
potential A such that B = ∇×A , which gives the potential formulation

∇× --- ∇×A – M = J


1
µ 

When modeling this equation in the FEMLAB framework, the equation system

– ∇ ⋅ ( c ∇A – γ ) = J

is solved, in the 3D Magnetostatics application mode.

1-256 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
In the 2D case, the equation system is reduced to a scalar equation

– ∇ ⋅ ( c ∇A z – γ ) = J z

where Az and Jz are the z components of A and J, respectively.

The coefficients c and γ are presented in the section on “Application Mode Reference”
on page 4-203 in the Reference Manual.

Subdomain Parameters
The subdomain parameters are:

Permeability This material property is denoted by µ=µ0µr , where µr is the relative


permeability and µ0 is the permeability of vacuum. The permeability of vacuum is a
universal constant that, in magnetostatics, relates the electric current and the
magnetic field. The relative permeability is a material property that describes the
relation between the magnetic field, H, and the magnetic flux density, B, in a
material.

Current Density This vector, J =(Jx,Jy,Jz) , describes the electric current density in
a material. In 2D, only the x and y components of J are available.

Magnetization Vector This vector, M =(Mx,My,Mz) , describes the volume density


of magnetic dipole moments in a material. In 2D, only the x and y components of M
are available.

Boundary Conditions
The boundary conditions are:

Surface Current

In 3D

– n × H = J s = J 0s = ( J0sx, J 0sy, J 0sz )

and in 2D

J s = J0s

This boundary condition specifies the components of the surface current Js. Note
that in 2D, the surface current is in the z direction, for example, out of the modeling
plane.

THE APPLICATION MODES | 1-257


Symmetry or Zero Surface Current

In 3D

Js = 0

and in 2D

Js = 0

The boundary condition specifies a zero surface current, equivalent to a symmetry


boundary condition.

Tangential Component of Magnetic Potential

In 3D

n × A = n × A 0 = n × ( A 0x, A 0y, A 0z )

and in 2D

Az = A0z

This boundary condition specifies the tangential component of the magnetic


potential. Note that in 2D, the tangential component is in the z direction, for
example, out of the modeling plane.

Antisymmetry or Zero Tangential Component

In 3D
n×A = 0

and in 2D
Az = 0

This boundary condition specifies a zero tangential magnetic potential, equivalent to


an antisymmetry boundary condition.

1-258 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Notes on the Boundary Conditions
The interface condition across subdomain borders between regions of different
material properties is that n × H should be continuous, in the absence of surface
currents. This is expressed by the equation

n ×  --- ∇×A – M = 0
1
µ 

which is equivalent to the ordinary Neumann condition, and hence is automatically


fulfilled on inner borders. In the presence of surface currents, it is specified as
–n × H = Js

The Dirichlet condition is used to specify the value of n × A at the boundaries.

In ferromagnetic materials, µ is usually dependent on the field strength


B = ∇×A , so you need to use the nonlinear solver.

Postprocessing
As postprocessing variables you find, among others, the magnetic field intensity H,
the magnetic flux density B, the magnetic potential A, and the surface current density
Js. Also available are the material and subdomain parameters, the permeability µ, the
current density J, and the magnetization vector M.

For a complete list of postprocessing variables, see the section on “Application Mode
Reference” on page 4-203 in the Reference Manual.

A C POW E R E L E C T RO M A G N E T I C S , 2 D
AC power electromagnetics problems are found when studying motors, transformers
and conductors carrying alternating currents.

PDE Formulation
Consider a dielectric, with permittivity ε, permeability µ, and conductivity σ, with no
charges at any point. The fields satisfy a special set of the general Maxwell’s
equations:

∂B ∂H
∇ × E = – ------- = – µ --------,
∂t ∂t
∂D ∂E
∇ × H = -------- + J = ε ------- + σE
∂t ∂t

THE APPLICATION MODES | 1-259


Under the assumption that the electric field only has a component in the
perpendicular direction, that is, a z component, the magnetic field will have only
in-plane components. It is thus possible to derive the scalar equation
2
∂E z ∂ Ez
– ∇ ⋅  --- ∇E z + σ ---------- + ε ------------
1
= 0
µ  ∂t 2
∂t

for the non-zero component of the electric field E.

The case of time-harmonic fields is treated by using the complex form. Substituting by
Ezejωt, in the equation above, we get

– ∇ ⋅  --- ∇Ez + ( jωσ – ω ε )E z = 0


1 2
µ 

This is the equation used by FEMLAB in the AC power electromagnetics application


mode. It is a complex-valued Helmholtz’s equation, describing the propagation of
plane electromagnetic waves in dielectrics as well as in good conductors. A complex
permittivity εc can be defined as εc = ε−jσ/ω, where the conductivity σ represents the
losses (ohmic losses, polarization losses, and others).

Subdomain Parameters
The subdomain parameters are:

Permeability This material property is denoted by µ=µ0µr , where µr is the relative


permeability and µ0 is the permeability of vacuum. The relative permeability is a
material property that describes the relation between the magnetic field, H, and the
magnetic flux density, B, in a material.

Conductivity The conductivity, σ , describes the relation between the electric field
and the electric current in a material. The conductivity is often referred to as the
ohmic losses of a material. Additionally, an equivalent conductivity can be included
in σ, for representing the polarization losses of a material.

Permittivity This material property is denoted by ε=ε0εr , where εr is the relative


permittivity and ε0 is the permittivity of vacuum. The relative permittivity is a
material property that describes the relation between the electric field, E, and the
electric displacement, D, in a material.

Boundary Conditions
The boundary conditions are:

1-260 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Surface Current

( – n × H )z = J s = J 0s

This boundary condition specifies the surface current in the z direction, for example,
out of the modeling plane.

Symmetry

Js = 0

This boundary condition specifies a zero surface current, and is equivalent of a


symmetry condition.

Electric Field

E z = E0z

This boundary condition specifies the electric field, in the z direction.

Antisymmetry

Ez = 0

This boundary condition specifies a zero electric field, equivalent to an antisymmetry


boundary condition.

The continuity conditions of the electric and magnetic field at material interfaces are
automatically fulfilled and need no special attention.

Postprocessing
Interesting quantities that can be derived from the solution, Ez, are the current
density and the resistive heating rate, which are given from the expressions

Jz = σE z

and

Q = Jz Ez

respectively.

THE APPLICATION MODES | 1-261


As postprocessing variables you find, among others the z component of the electric
field Ez, the magnetic flux density B, the magnetic field H, the z component Jz of
2
the current density J, the resistive heating rate Q = E z σ , and the surface current,
Js. Also available are the material properties µ, σ, and ε.

For a complete list of postprocessing variables, see the section on “Application Mode
Reference” on page 4-203 in the Reference Manual.

In AC power electromagnetics there is also an application scalar variable, the angular


frequency ω, with the default variable name omega. An application scalar variable is a
scalar application-specific variable, that is a part of the PDE describing the
application mode. It is independent of the geometry and material properties in the
model. You can set the value of omega in the Application Scalar Variables dialog box
that you can find in the Options menu.

CONDUCTIVE MEDIA DC, 2D AND 3D


For electrolysis and computation of resistances of grounding plates, we have a
conductive medium with conductivity σ and a steady current.

PDE Formulation
The current density J is related to the electric field E through J = σE. You can also
have an external current, J0, so that the total field Jtot is given as

J tot = J + J0 = σE + J 0

Combining the continuity equation ∇ ⋅ Jtot = 0, with the definition of the electric
potential E=−∇V, yields the equation

– ∇ ⋅ ( σ∇V ) = Q

where Q is the current source defined by ∇ ⋅ J0, and J=−σ∇V. The conductivity can
be anisotropic, in which case σ is a tensor.

This is the equation modeled in the Conductive media DC application mode.

Subdomain Parameters
The subdomain parameters are:

Conductivity The conductivity, σ, describes the relation between the electric field
and the electric current in a material.

Current Source The current source, Q, describes the external current, see above.

1-262 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Boundary Conditions
The boundary conditions are:

Inward Current

– n ⋅ J + qV = g

The boundary condition specifies the inward normal component of the current
density n ⋅ (σ ∇V)=−n ⋅ J=Jn, through the parameter g. The parameter q can be
interpreted as a film conductance for thin plates.

Insulation or Symmetry

–n ⋅ J = 0

This boundary condition specifies a zero current flux, equivalent to an insulating


boundary, or a symmetry boundary condition.

Electric Potential

V = V0

The boundary condition assigns values of the electric potential V to the boundaries,
usually metallic conductors.

Ground or Antisymmetry

V = 0

This boundary condition specifies a zero potential, equivalent to a grounded


boundary, or an antisymmetry boundary condition.

Postprocessing and Anisotropic Materials


As postprocessing variables you find the electric potential V, the electric field E, the
current density J, and the normal current density flux Jn. Also available is the
subdomain parameter Q. The conductivity σ is not available, see below.

For a complete list of postprocessing variables, see the section on “Application Mode
Reference” on page 4-203 in the Reference Manual.

You can model an anisotropic conductivity by entering space-separated entries


according to the PDE coefficient syntax. See the section “Anisotropic Materials” on

THE APPLICATION MODES | 1-263


page 1-359 for details. This means that σ is not available as a variable for
postprocessing.

Structural Mechanics
For structural mechanics simulations, there are three application modes available in
FEMLAB. Two of these modes are for 2D structural mechanics: Plane stress and
Plane strain. The third application mode is for general 3D structural mechanics.

Following a brief introduction to structural mechanics, and definition of the


structural mechanics quantities, the three application modes are presented in
subsequent sections.

Note The Structural Mechanics Module contains specialized and extended


application modes and models for structural mechanics simulations.

PRELIMINARIES OF STRUCTURAL MECHANICS


Structural mechanical modeling is solving the equilibrium equations for
displacements, stresses, and strains in a material [1, 2].

For a total description of the stress conditions at a point, the symmetric stress matrix,

σ x τxy τ zx
σ = τ xy σ y τ yz
τ zx τ yz σ z

1-264 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
can be used, where σi are the stress components, and τi are the shear stresses. The
relation between these different components are governed by the static equilibrium
conditions (balance of force equations),

∂σ x ∂τxy ∂τ zx
– – – = Kx
∂x ∂y ∂z
∂τxy ∂σ y ∂τ yz
– – – = Ky
∂x ∂y ∂z
∂τ zx ∂τ yz ∂σ z
– – – = Kz
∂z ∂y ∂z

where K denotes the volume forces (body forces).

Using compact notation, this can be written

∇⋅σ = K

The strain conditions at a point can be completely described from the deformation
components and their derivatives. The strain components and the shear strain
components are given from the equations

∂u γxy 1  ∂u ∂v
εx = εxy = ------- = --- +
∂x 2 2  ∂ y ∂ x
∂v γyz 1  ∂v ∂w
εy= ε yz = ------- = --- +
∂y 2 2  ∂z ∂y 
∂w γzx 1  ∂w ∂u
εz = εzx = ------- = --- +
∂z 2 2  ∂x ∂z 

where u, v, and w are the deformation components. For elastic materials, there exist
an unambiguous relation between the stress and the strain in the material. This

THE APPLICATION MODES | 1-265


relation, known as Hooke’s law, is under the assumptions of isotropic and isothermal
conditions, described by the equations


 σ = ------------
E  ν
 x 1 + ν  ε x + --------------- - ( ε + εy + ε z ) τ xy = G γxy
1 – 2ν x 

 E ν
 σ y = ------------  ε y + ---------------- ( ε x + εy + ε z ) τ yz = G γyz
 1 + ν 1 – 2ν 

 σ = ------------
E  ν
 z 1 + ν  ε z + --------------- - ( ε + εy + ε z ) τ zx = G γzx
1 – 2ν x 

where ν is Poisson’s ratio, E is the elasticity modulus or Young’s modulus, and G is the
shear modulus defined by
E
G = ---------------------
2(1 + ν)

Using Hooke’s law, all stress and strain components can be derived once the
derivatives of the deformations have been obtained. To do this, the balance of force
can be formulated in terms of the deformation components, formulating a system of
three equations known as Navier’s equations,

∂  ∂u i ∂u j ∂  ∂u j
– ∑ G + + µ 
∂ x j  ∂ x j ∂ x i ∂ x i  ∂ x j 
= Ki
j

where i and j denotes the space coordinate indices, and x1, x2, and x3 denotes x,y, and
z, and u1, u2, and u3, are used as the deformation components. The variable µ is
defined as


µ = ---------------------------------------
( 1 + ν ) ( 1 – 2ν )

For the plane stress deformation state, µ is replaced by µps, see the section “Plane
Stress, 2D” on page 4-242 in the Application Mode Reference in the Reference
Manual.

1-266 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
In the case of small deformations, the equilibrium conditions are

2
∂ u ∂σ x ∂τ xy ∂τ zx
ρ – – – = Kx
∂t
2 ∂x ∂y ∂z
2
∂ v ∂τ xy ∂σ y ∂τ yz
ρ – – – = Ky
∂t
2 ∂x ∂y ∂z
2
∂ w ∂τ zx ∂τ yz ∂σ z
ρ – – – = Kz
∂t
2 ∂z ∂y ∂z

where ρ is the density in the material. The corresponding formulation of Navier’s


equations is

2
∂ ui ∂  ∂u i ∂uj ∂  ∂u j
ρ
∂t
2
– ∑ G + + µ 
∂ x j  ∂ x j ∂ x i ∂ x i  ∂ x j
= Ki
j

Using compact notation, Navier’s equation reads


2
∂ u
ρ 2
– ∇ ⋅ c ∇u = K
∂t

where c is a tensor, where each entry is a linear function of G and µ.

From the stress and strain components, you can derive the principal stress and the
principal strain. These are the eigenvalues to the stress matrix and the strain matrix,
respectively. You can also obtain the von Mises effective stress.

The full Navier’s equations are solved in the Structural mechanics application mode
in 3D.

Two special cases for enabling 2D modeling of Navier’s equations are available, the
Plane stress and the Plane strain application modes.

References
[1] Zienkiewicz, O.C., and Taylor, R.L., The Finite Element Method, 4th edition,
McGraw-Hill, Lodon, England, 1994.

[2] Cook, Robert D., David S. Malkus, and Michael E. Plesha, Concepts and
Applications of Finite Element Analysis, 3rd edition, John Wiley & Sons, New York,
1989.

THE APPLICATION MODES | 1-267


STRUCTURAL MECHANICS, 3D

PDE Formulation
When using the Structural mechanics application mode in 3D, you are solving the
Navier’s equations for the components u=(u,v,w), of the displacement vector.
2
∂ u
ρ 2
– ∇ ⋅ c ∇u = K
∂t

The tensor c is listed in the “Application Mode Reference” on page 4-203 in the
Reference Manual.

Alternatively, for solving eigenvalue problems, the formulation

– ∇ ⋅ c ∇u = λρ u

is used, where λ is the eigenvalue. The eigenfrequency f can be derived from λ as


2
ω = λ
ω
f = ------

where ω is the angular frequency.

Subdomain Parameters
The subdomain parameters are:

Young’s Modulus or Elasticity Modulus This material property, denoted by E,


specifies Young’s modulus, or elasticity modulus, and defines the elastic properties of
the material. Young’s modulus is a proportional constant in the relations between the
stresses and strains of a material. The default value corresponds to a generic steel
material.

Poisson Ratio This material property, denoted by ν, specifies Poisson’s ratio, which
intuitively describes the relative contraction of a material, in a direction orthogonal
to the strain. The default value corresponds to a generic steel material.

Body Force This property, denoted by K, defines a body force, distributed in a


subdomain, for example, the gravity force.

Density This material property, denoted by ρ, specifies the density of the material.
The default value corresponds to a generic steel material.

1-268 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Boundary Conditions
The boundary conditions are:

Force per Area

( n ⋅ σ ) x = Fx
( n ⋅ σ ) y = Fy
( n ⋅ σ ) z = Fz

These boundary conditions are used for specifying loads, where Fx, Fy, and Fz are
given as force per area.

Constraints

u = Rx
v = Ry
w = Rz

These boundary conditions are used for specifying x-, y-, and z-displacement,
respectively. You can also specify combinations of loads and constraints.

Postprocessing
As postprocessing variables you find, among others, the displacements, the von
Mises stress, the different stress components, and the principal stresses and strains.

Also available as postprocessing variables are the material properties Young’s


modulus, Poisson’s ratio, and the density.

For a complete list of postprocessing variables, see the section on “Application Mode
Reference” on page 4-203 in the Reference Manual.

PLANE STRESS, 2D
The Plane stress application mode utilizes the fact that, for many problems in
structural mechanics, the stress in one coordinate direction is very small, and can be
neglected. Under this assumption, a 2D domain can be used for specifying the
problem, and the performance can be greatly improved. Plane stress is a condition
that prevails in a flat plate in the x-y plane, loaded only in its own plane and without
z-direction restraint.

THE APPLICATION MODES | 1-269


PDE Formulation
Under the assumption that

σ z = τ yz = τzx = 0

Navier’s equations for the two deformation components u=(u,v) are solved, in
contrast to the 3D case.
2
∂ u
ρ 2
– ∇ ⋅ c ∇u = K
∂t

The tensor c is listed in the “Application Mode Reference” on page 4-203 in the
Reference Manual.

As in the 3D case, you can also solve eigenvalue problems.

Subdomain Parameters, Boundary Conditions and Postprocessing


The subdomain property, boundary conditions, and postprocessing variables are the
same as in 3D, except that only the x- and y-components of the stresses and strains
are available.

PLANE STRAIN, 2D
A deformation state where there are no displacements in the z-direction, and the
displacements in the x- and y-directions are functions of x and y but not z is called
plane strain. This is the deformation state modeled by the Plane strain application
mode, and is another type of problem that is efficiently handled in 2D. An example
of a plane strain problem is a slice of an underground tunnel that lies along the z-axis.
It deforms in essentially plane strain conditions.

PDE Formulation
For plain strain problems, the assumption
ε z = γ yz = γ zx = 0

is true, and Navier’s equations for the two deformation components u=(u,v) are
solved, in contrast to the 3D case.
2
∂ u
ρ 2
– ∇ ⋅ c ∇u = K
∂t

1-270 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The tensor c is listed in the “Application Mode Reference” on page 4-203 in the
Reference Manual, and has slightly different components than that of the plane strain
case.

You can also solve eigenvalue problems.

Subdomain Parameters, Boundary Conditions and Postprocessing


The material properties, boundary conditions, and postprocessing variables are the
same as in 3D, except that only the x- and y-components of the strains are available.

Fluid Mechanics
This area of physical engineering deals with the studies of gases or liquids either in
motion, fluid dynamics, or at rest, fluid statics. When studying liquid flows, it is
often safe to assume that the density of the material is almost constant. This is referred
to as incompressible fluid flow. The incompressible Navier-Stokes application mode,
provided in FEMLAB, is used for modeling these kinds of physical problems.

Note The Chemical Engineering Module contains more elaborate application


modes for incompressible Navier-Stokes problem, for example, an application mode
for axisymmetric Navier-Stokes.

IN COMPRES SIBL E N AVIE R-STOKES, 2D AND 3D


Incompressible flow in fluids is modeled within the Incompressible Navier-Stokes
application mode [1,2]. The underlying equations are the Navier-Stokes equations,
hence the name of this mode.

PDE Formulation
In the time-dependent case, the equations can be written

 ∂u T
 ρ ------- – ∇ ⋅ η ( ∇u + ( ∇u ) ) + ρ ( u ⋅ ∇ )u + ∇p = F
 ∂t

 ∇⋅u = 0

The first equation is the momentum balance, and the second is the equation of
continuity for incompressible fluids. Here, η is the dynamic viscosity, ρ is the density,
u the velocity field, p the pressure, and F a volume force field such as gravity. It
should be noted that this formulation allows for varying viscosity. For a Newtonian

THE APPLICATION MODES | 1-271


fluid, of which the viscosity is constant, the viscous term will reduce to −η∇2u. For
the steady-state case, you can use the stationary version:
 T
 – ∇ ⋅ η ( ∇u + ( ∇u ) ) + ρ ( u ⋅ ∇ )u + ∇p = F

 ∇⋅u = 0

The Navier-Stokes equations are often rewritten on a dimensionless form. Introduce


the variables u* = u/U, an appropriate length scale L, a properly scaled
dimensionless pressure p*, and properly scaled forces F*. Dropping the asterisks, the
equations then become


 – ∇ ⋅  ------
1 T 
 Re ( ∇u + ( ∇u ) ) + ( u ⋅ ∇ )u + ∇p = F
-


 ∇⋅u = 0

where the magnitude of the viscous effects are measured by the dimensionless
Reynolds number

ULρ
Re = ------------
η

The relation between the dimensionless and physical pressure and volume forces,
respectively, are

 p
 p∗ = ----------
-
 ρU
2

 ∗ L
 F = F ⋅ ----------2-
 ρU

The value of the Reynolds number has a large influence on the flow. Generally, the
turbulent behavior increases as Re increases, and the fine-scale vortices in the flow
become smaller.

Subdomain Parameters
The subdomain parameters are:

Density This material property, denoted by ρ, specifies the density of the fluid.

1-272 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Dynamic Viscosity The dynamic viscosity, η, describes the relation between the shear
stresses in a fluid to the shear-rate. Intuitively, water and air have a low viscosity, and
substances often describes as “thick”, such as oil, have a higher viscosity.
Non-Newtonian fluids can be described, for example, by defining a shear-rate
dependent viscosity. Examples of non-Newtonian fluids are yoghurt, paper pulp, and
polymer suspension.

Volume Force The volume force vector, F=(Fx, Fy, Fz), describes a distributed force
field, such as gravity.

Boundary Conditions
The viscous force per unit area is defined as
T
K = n ⋅ η ( ∇u + ( ∇u ) )

and is the force that the boundary exerts on the fluid. This is used in some of the
boundary conditions, which are as follows.

Inflow

At an inflow boundary, the velocity field of the fluid is specified:

u = ( u, v, w ) = ( u 0, v 0, w 0 )

in 3D. The last component is dropped in 2D.

Outflow or Pressure

At an outflow boundary, the pressure and the viscous force are zero,

p=0
K=0

Slip or Symmetry

A slip condition means that the normal component of the velocity is zero,
n⋅u = 0

and that the tangential tangential component of the viscous force vanishes,
t⋅K = 0

THE APPLICATION MODES | 1-273


in 2D, and
t1 ⋅ K = 0
t2 ⋅ K = 0

in 3D. This is also equivalent of a symmetry boundary condition.

No-slip

A no-slip condition means that the velocity of the fluid equals the velocity of the
boundary, usually zero. This is normally used for walls,
u = 0

Straight-out

At a straight-out outflow boundary, the pressure and the tangential components of


the velocity are zero. Also, the normal component of the viscous force is zero. In 2D,
this reads
t⋅u = 0
p=0
n⋅K= 0

and in 3D
t1 ⋅ u = 0
t2 ⋅ u = 0
p=0
n⋅K= 0

Neutral

A neutral boundary is treated as if there was no boundary, which means that the
viscous force vanishes,
K = 0

Postprocessing
For postprocessing of incompressible Navier-Stokes problems you can use the
pressure p, the velocity field u, the vorticity V, the volume force F, and the viscous
force per unit area K. The viscous forces are available on the boundaries of the
modeling domains, and the volume forces are available in the interior. Also available
as postprocessing parameters are the subdomain parameters ρ and η.

1-274 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
For a complete list of postprocessing variables, see the section on “Application Mode
Reference” on page 4-203 in the Reference Manual.

References
[1] Gresho, P.M, and Sani, R.L., Incompressible Flow and the Finite Element
Method, Volume 1 & 2, John Wiley & Sons, New York, 2000.

[2] Pironneau,O., Finite Element Methods for Fluids, John Wiley & Sons, 1989.

THE APPLICATION MODES | 1-275


Extended Multiphysics
Coupling Variables
Variables in FEMLAB are generally evaluated locally—their value at each evaluation
point is computed using information only from that evaluation point. In contrast,
the value of a coupling variable is the result of a computation carried out elsewhere
in the geometry or even in another geometry altogether. When used in the PDE and
boundary conditions, the result is the introduction of non-local dependencies—
extended multiphysics—as opposed to ordinary multiphysics, which refers to
dependencies between variables in the same geometric location.

The coupling variables are extremely powerful in their ability to make the value and
the exact Jacobian of an expression available non-locally. The coupling variables are
not only useful for modeling coupled problems—they can also be used solely for
postprocessing and visualization purposes.

All coupling variables are defined in two steps. First define the source, that is, which
expression to evaluate, and where to evaluate it; secondly define the destination, that
is the domains within which it is possible to use the resulting variable.

There are three kinds of coupling variables available: scalar, extrusion, and projection
variables.

1-276 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Specifying Non-Local Couplings
In the graphical user interface you can define coupling variables by using the Coupling
Variable Settings dialog box from the Options menu as shown below.

The Source and Destination pages allow you to set the source and destination details
and the Variable type gives the choice of defining a scalar, extrusion, or projection
variable.

The dialog box is described in further detail on page 4-39 of the Reference manual.
The example “Magnetic Brake” on page 2-254 of the Model Library also includes
step by step instructions on how to define variables. In addition, the following
examples give advice on how to use the coupling variables.

At the MATLAB prompt, coupling variables are defined by creating element syntax
structures as described in “Non-Local Couplings” on page 3-147.

Scalar Couplings
Use scalar coupling variables to make scalar values available elsewhere in your model.
The source of the scalar value can be an expression at a vertex. In addition, the source
of the scalar value can be the integral of an expression over one or several subdomains,
boundaries, or edges. The destination of the scalar variable can be the full geometry,
one or several subdomains, boundaries, edges, or vertices.

EXTENDED MULTIPHYSICS | 1-277


SCALAR COUPLING EXAMPLE
As a simple example, consider the case of Poisson’s
equation on a single rectangular domain. The integral
y
of the square of the solution is used as in-flux in a
x Neumann boundary condition on the right boundary.
There is a Dirichlet boundary condition on the left
boundary, and the top and bottom boundaries have
zero in-flux. The problem is nonlinear so you have to use the nonlinear solver. The
right boundary condition contains the scalar coupling variable in a coefficient, so the
weak solution form must be used.

– ∆u = 1 on Ω
u=x on ∂Ω 1
∂u
=0 on ∂Ω 2, 3
∂n
∂u
∂n

2
= – u dΩ on ∂Ω 4

Model Navigator
Start FEMLAB and select the 2D, Coefficient, Nonlinear, PDE mode in the Model
navigator. Use the Lagrange - Quadratic element type. Press the More button, and select
solution form Weak.

Draw Mode
• Draw a single rectangle of any size.

Boundary Mode
• Change the following boundary coefficients:

BOUNDARY 1 2-3 4

Type Dirichlet Neumann Neumann


r x
g 0 int2

Subdomain Mode
• Use the default PDE coefficients (Poisson’s equation).
• Open the Add/Edit Coupling Variables dialog box.
• Enter the variable name int2, and choose the default type Scalar. Press Add.

1-278 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
• Go to the Source page and select subdomain 1. Enter -u^2 in the Expression field,
and enter 4 in the Integration order field.
As a simple rule, the integration order can be the maximum of the quadrature
order for the integration of the shape functions of the variables in the expression.
See the section “Numerical Quadrature” on page 3-50 for details.
• On the Destination page, select boundary 4 and check Active in this domain.
• Return to the Variables page to check the definition. Finally, press OK.

Solving
• Press the Solve Problem button to start the simulation.

Post Mode
• Open the Subdomain Integration item on the Post menu. Type -u^2 in the
expression field. Select subdomain 1 and press Apply. The integral of the solution
is displayed in the message log.
• Open the Plot Parameters dialog box. Check Contour and uncheck Surface. Press
the Contour tab. Change the Contour expression to ux. Click in the GUI on the
right boundary, and verify that the in-flux is equal to the integral.

BRIEF EXAMPLES OF SCALAR COUPLINGS


One example of a scalar coupling is when a scalar value
from a vertex is used everywhere on a boundary to
which the vertex belongs. In structural mechanics, you
y
can use this type of coupling to formulate displacement
x constraints along a boundary in terms of the
displacements of the end point. In electromagnetics,
the same technique can be employed to implement
floating contacts.

Another example is to use the integral over a


y subdomain in a 2D geometry along a subdomain in
another 1D geometry. This is useful for process
x
industry models, where two different processes
interact.
r

EXTENDED MULTIPHYSICS | 1-279


Finally, scalar coupling variables can be used to
implement integral constraints. Define a coupling
variable at some vertex in such a way that it represents
the value of the integral to be constrained. Then use a
point constraint to set the coupling variable, and
y thereby the integral, to the desired value.
x

Extrusion Couplings
An extrusion coupling variable takes values from the source domain by interpolation
of an expression at points that are dependent in some way on the position of the
evaluation points in the destination domain.

When the destination domain has more space dimensions than the source domain,
the variable performs extrusion of values. The extrusion coupling variable can also be
used for mapping values from the source to the destination. This is applicable when
the source and destination domains have the same number of space dimensions.

Destination
Source (3D subdomain)
(2D boundary)

Destination
transformation

Source
transformation

Intermediate mesh
(2D, planar)

The definition of any extrusion coupling variable involves two different mesh
transformations, which are important to understand. The, so called, source

1-280 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
transformation is a one-to-one mapping that maps the mesh of the physical source
domain to an intermediate mesh embedded in a space of the same dimension as the
source. The destination transformation is a mapping from the destination domain,
where the value of the variable is defined, to the same space that contains the
intermediate mesh.

When you request the value of the coupling variable somewhere in the destination
domain, the destination points are transformed using the destination transformation.
The resulting coordinates are compared to the elements in the intermediate mesh in
order to find corresponding locations in the physical source domain. This means that
the source transformation has to be inverted, but not the destination transformation.
The latter can in fact be non-invertible, which is for example the case for a linear
extrusion.

To avoid having to solve a nonlinear system of equations for every destination point,
the source transformation is assumed to be linear on each element of the intermediate
mesh. In practice, it is often trivial and leaves the coordinates unchanged, but it can
also be used to rescale, stretch, bend, or reflect the mesh.

EXTRUSION COUPLING EXAMPLE


Consider the case of a single rectangular domain, where the source term in Poisson’s
equation comes from the inward flux over the right boundary for the corresponding
y coordinate.


– ∆u = u ( x 2, y ) on Ω
∂n
u = xy on ∂Ω

The figure to the left illustrates the extrusion process.


The values of the in-flux on the boundary become
y
available throughout the domain by extrusion along
x2 x the y-axis. The source transformation is y, and the
destination transformation is y.

The problem is linear so you can use the linear solver. We use the weak term to specify
the source term in the Poisson’s equation, so we do not have to use the weak solution
form.

Model Navigator
Start FEMLAB and select the 2D, Coefficient, Linear, PDE mode in the Model navigator.
Use the Lagrange - Quadratic element type.

EXTENDED MULTIPHYSICS | 1-281


Draw Mode
Draw a single rectangle of any size.

Boundary Mode
• In boundary mode, select all boundaries. Set the r coefficient to x*y.

Subdomain Mode
• On the Weak tab, set the subdomain 1 weak term to u_test*flux. (Poisson’s
equation with source flux).
• Open the Add/Edit Coupling Variables dialog box.
• Enter the variable name flux and choose the default type Extrusion and press Add.
• Go to the Source page and select boundary 4. Enter ncu in the Expression field, and
set local mesh transformation to y.
• On the Destination page, select subdomain 1, and set local mesh transformation to
y.

• Return to the Variables page to check the definition. Finally, press OK.

Solving
• Press the Solve Problem button.

Post Mode
• On the Surface tab, change Surface expression to flux.
• On the Line tab, check Line plot, and select ncu as Line expression.
• Press OK.

The plot shows both the value of the flux variable on the destination domain and
the source ncu on the boundary.

BRIEF EXAMPLES OF EXTRUSION COUPLINGS


One application of extrusion couplings is to mirror the
solution in the x-axis. This can be very useful for
y postprocessing, for example, see “Safety Connector/
x Disconnector” on page 2-106 in the Model Library.
The source transformation is x, y, and the destination
transformation is x, -y.

1-282 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Another example is to extrude the solution in the 1D
x geometry to a 2D domain along the s axis. The source
transformation is x, and the destination transformation
is r. For applications, see the model
s “Elliptical-to-Rectangular Transition in Waveguide”
r on page 2-121 in FEMLAB Electromagnetics.

Yet another example is to map values on the lower


y boundary of a rectangle that extends from x=-1 to
x=1, and from y=0 to y=1, to the right boundary on
x the same rectangle. The source transformation is
(x+1)/2 and the destination transformation is y.

Finally, to map the solution from a 2D axially


symmetric model onto the original 3D domain, use the
source transformation r, z and destination
transformation sqrt(x^2+y^2), z.This mapping is
particularly useful for postprocessing purposes.

z z y
r x

Projection Couplings
A projection coupling variable takes values from the source domain by evaluating a
series of line integrals within the source domain, where the line positions are
dependent on the positions of the evaluation points in the destination domain. In
this way you can evaluate the average of a variable over one space variable at a range
of different points along the other space axis, giving a result which varies over the
latter space variable.

The method employed is that first a one-to-one transformation is applied to the mesh
of the source domain. The last space dimension in the transformed mesh is the one
integrated over, so the lines used to integrate are vertical in the transformed source
mesh. The placement of the vertical lines in the transformed source mesh is given by

EXTENDED MULTIPHYSICS | 1-283


the positions of the transformed destination evaluation points. The integrals are then
carried out in the source domain over curves which correspond to the vertical lines in
the transformed source mesh.

Then a second transformation is applied to the evaluation points in the destination


domain, and the resulting points are used for the interpolation of an expression at
points in the transformed source mesh.

BRIEF EXAMPLES OF PROJECTION COUPLINGS


For each point r return

v( r) = ∫ u ( x, y ) dx

y = r⁄2
y ( x, y ) ∈ S 2
x r
The source transformation mapping is y,
x, and the destination transformation
mapping is r/2.

For each point (0,s) return

v ( 0, s ) = ∫ u ( x, y ) dx

y=s
y s ( x, y ) ∈ S 2

x r
The source transformation mapping is y, x,
and the destination transformation
mapping is s.

For each point (r,0) return

v ( r, 0 ) = ∫ u ( x, y ) dx

y y = r⁄2
s ( x, y ) ∈ S 2
x r

The source transformation mapping is y,


x, and the destination transformation
mapping is r/2.

1-284 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Also non-rectangular domains can be swept by the integration. Only the source
domains will be included in the integrals. Other domains and the external area will
be excluded from the integrals.

The Weak Solution Form and the Solvers


FEMLAB computes an exact Jacobian contribution from the coupling variables
when the coupling variables occur in weak terms. When using solution form
Coefficient or General, only the entries in the weak, dweak, and constr fields on the
Weak tabs in FEMLAB’s dialog boxes are evaluated correctly. Solution form Weak
converts the complete set of equations into weak terms.

If you use a coupling variable in a coefficient, without using solution form Weak, the
Jacobian is likely to be incorrect. The stationary linear solvers need a correct and
constant Jacobian, while the nonlinear solvers may produce a correct answer—
through fix-point iteration—even for an incomplete Jacobian. This last fact can be
exploited if you need to avoid the weak solution form.

It can sometimes be difficult to know if a problem involving coupling variables is


linear or not. In such cases, the nonlinear solver can always be used. If you are sure
about the linearity of the problem, and coupling variables only occur in weak terms,
one of the linear solvers is the preferred choice.

Sparsity of Jacobian
The Jacobian for problems formulated using the finite element method is usually
large, but rather sparse, that is, with relatively few nonzero elements. This is because
the solution at each node in the mesh can be dependent at most on the degrees of
freedom from the neighboring mesh elements. If however coupling variables are
introduced, non-local dependencies are introduced, filling up the rows and columns
of the affected source and destination nodes. This extra filling may make the Jacobian
matrix slightly less sparse (in which case the solution speed is only slightly affected)
or it may make it a great deal less sparse (in which case the memory use and CPU time
involved in solving the problem may be increased a great deal). For this reason care
should be taken when introducing non-local couplings.

EXTENDED MULTIPHYSICS | 1-285


Non-Local Dirichlet Boundary conditions
When using coupling variables in Dirichlet boundary conditions, ideal constraints
are used, that is, the constraint force is applied both in the destination and source
domains. This corresponds approximately to how periodic boundary constraints are
handled in FEMLAB, and this may be appropriate in the context of the problem
being modeled. Often, however, it is more appropriate to leave the source unaffected
and apply the constraint force only in the destination domain. If this is the case, the
constraint should be specified using the weak constraint method which is outlined in
“Weak Constraints, Their Uses and Limitations” on page 1-398.

1-286 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Interpolation of Measured Data
One strong feature of FEMLAB is the possibility to use MATLAB expressions and
functions when setting up a problem both from the GUI and in the programming
language. This can be used for PDE coefficients or material parameters, as well as for
initial values. In reality, many material parameters are not given by any analytical
expression, but can only be obtained by measurements. These measurements can
then be used for approximating the material parameter via interpolation when
performing a simulation. Measured data can also be used for describing a geometry.
Geometric measured data can originate, for example, from MRI-scans or laser
scanning of mechanical components. Import of measured data describing a geometry
is explained in the sections beginning with “Image and MRI Import” on page 1-220.
Import of measured data for material parameters is discussed in this section

Interpolation of Measured Material Properties


In many cases the material parameters vary in space, or are highly dependent on a
physical quantity such as temperature. It is often not plausible to use an expression
for the parameter. The only data available might be some measured data for given
space coordinates or for a given value of the temperature or other physical quantity.
To obtain reasonable values in the simulation in these cases, it is important to use
interpolation techniques.

INTERPOLATION WITH RESPECT TO SPATIAL COORDINATES,


INHOMOGENEOUS MATERIALS
When setting up a material with an inhomogeneous material, an interpolation
function of the same dimension as the geometry can be used. For a 2D problem, a
material parameter can be specified using the MATLAB function, interp2. Since
interpolation of measured data often involves large data sets, it is in many cases more
convenient to create a function which loads this data into the MATLAB workspace.
This technique is demonstrated below. After that, an alternative approach is
demonstrated, where the interpolation function is called directly from FEMLAB.

• Select the 2D, Geometry Only application mode.


• Draw a rectangle with corners at (0,0) and (90,90).
• Press the Zoom Extents toolbar button to adjust the coordinate system with respect
to the size of the rectangle.

INTERPOLATION OF MEASURED DATA | 1-287


• Press Initialize Mesh.
• Press Refine Mesh once. This is needed to resolve the interpolated data.

There are two different parameters that control the resolution of material properties,
as used in subdomain settings:

• For visualization, the resolution is controlled by the Element refinement level set in
the corresponding field on the General page in the Plot Parameters dialog box. The
value entered there controls the number of refinement of element edges (line edges
for triangle elements and triangle faces for tetrahedral elements) used for
evaluating variables and expressions for visualization.
• For solving, the resolution is controlled by the finite element mesh. To get higher
resolution, you need to refine the mesh, for example, by using the Refine Mesh
button. For highly irregular data, this is very important.

The MATLAB function used for the interpolation in this model is called flafun,
described in detail later in this section. It takes the x and y coordinates as input for
the interpolation. An expression calling this function is defined in the Expression
Variable Settings dialog box.

• Click the Subdomain Mode button.


• Select Add/Edit Expressions... from the Options menu.
• Type a_data in the edit field for the Variable name.
• Set the Variable type to Subdomain. This means that the expression is valid for use
on the selected subdomains.
• Click the Add button.
• On the Definition page, enter the expression flafun(x,y)and click OK.

1-288 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
This expression can now be visualized without solving the problem.

• Open the Plot Parameters dialog box.


• On the Surface page, set the surface expression to a_data^1.25. Press OK.
• Select Get Initial Value from the Post menu. This makes it possible to plot the
expression without solving the problem first. The solution will be equal to the
expressions defined in the Initial value field on the Init page in the Subdomain
Settings dialog box.
• To get higher visualization resolution, you can change the Element refinement
value on the General page in the Plot Parameters dialog box.

For an example of how this data is used in a complete model, see “A Rock Fracture
Flow Model” on page 2-238 in the Model Library.

Using FEMLAB functions, the FEM problem for this is set up with the following
commands.

clear fem
fem.geom = rect2(0,90,0,90);
fem.mesh = meshinit(fem);
fem.mesh = meshrefine(fem);

The expression a_data is defined the same way as from the GUI.

fem.equ.expr = {’a_data’ ’flafun(x,y)’};

To visualize this data, the mesh structure is extended and the expression plotted.

fem.xmesh = meshextend(fem);
postplot(fem,’tridata’,’a_data^1.25’,’tribar’,’on’)

INTERPOLATION OF MEASURED DATA | 1-289


This illustrates that the function flafun can be used for defining an expression in
FEMLAB, which can be used for postprocessing. More importantly, it can also be
used in PDE coefficients or for material parameters when setting up a FEM problem.
To understand how the interpolation is carried out it is necessary to study flafun in
more detail. Enter type flafun at the MATLAB command prompt to see the steps
carried out for computing the data.
%FLAFUN Interpolate aperture from sampled data.
% A = FLAFUN(X,Y) interpolates rock fracture aperture from sampled data.
% X and Y are coordinates for node points in an unstructured grid.
% A is the interpolated aperture in the the node points.
%
% FLAFUN is a function used as diffusion coefficient in the geophysics
% ROCK_FRACTURE model in the Model Library.
%
% Use FLAFUN as flafun(x,y)^3 in the diffusion coefficient in GUI.
% This implements the cubic law for fracture conductivity in a
% potential flow model.
%
% The sampled data is stored in the file FLAPERTURE.MAT.
%
% See also FLDOPING.

% Load the aperture data matrix.


load flaperture
% Create sample coordinates.
[m,n] = size(aperture);
dx=1;
dy=1;
[x1,y1] = meshgrid(0:dx:(m-1)*dx,0:dy:(n-1)*dy);
% Interpolate from rectangular grid to unstructured grid.
a = interp2(x1,y1,aperture,x,y);

This is all of the code in flafun. The measured data is stored in the file flaperture.
By loading this file the matrix aperture is available in the function workspace. Two
matrices with the coordinate points for which the data is measured is created as x1
and y1. Then the interp2 function can be used for interpolating aperture values to
the coordinates x and y, which are the input to flafun.

An alternative for using flafun is to call the interp2 function directly. To do this
the variables x1, y1 and aperture need to be available in the FEMLAB functions.
This is done by first creating the measured data matrices at the MATLAB prompt as
in flafun.

load flaperture
[m,n]=size(aperture);
dx=1;
dy=1;
[x1,y1]=meshgrid(0:dx:(m-1)*dx,0:dy:(n-1)*dy);

1-290 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
These variables can then be used in the FEM problem by making sure that evaluation
is carried out in the main workspace. This means that all variables in the main
workspace are available for use in expressions.

fem.equ.expr = {’a_data’ ’interp2(x1,y1,aperture,x,y)’};


fem.xmesh = meshextend(fem);
postplot(fem,’tridata’,’a_data^1.25’,’tribar’,’on’,...
’context’,’main’)

It is the property context that enables the use of the variables in the main workspace.
For solving a problem involving the expression a_data, the same property must be
used when calling the solvers.

The second alternative is to define corresponding variables in the FEM structure, so


that these are available for evaluation without changing the evaluation context in the
FEMLAB functions.

fem.equ.expr = {’x1’ x1 ’y1’ y1 ’aperture’ aperture ...


’a_data’ ’interp2(x1,y1,aperture,x,y)’};
fem.xmesh = meshextend(fem);
postplot(fem,’tridata’,’a_data^1.25’,’tribar’,’on’)

The latter of the two alternatives cannot be employed in the GUI. You can however
set the evaluation context to main as in the first example. This is done in the Solver
Parameters dialog box.

• Select Main as Context in the Solver Parameters dialog box.


• Open the Expression Variable Settings dialog box. On the Definition page, change
the expression for a_data to interp2(x1,y1,aperture,x,y).
• Select Get Initial Value from the Post menu.
This will display the interpolated result in the GUI.

INTERPOLATION WITH RESPECT TO SOLUTION - NONLINEAR


MATERIALS
Measured data that is dependent of the solution variable can also be handled. One
typical example of this is when approximating hysteresis curves for magnetic
materials or temperature dependent properties such as heat conductivity.
Interpolation is usually made in one dimension, that is, the material parameter is
considered as a function of one variable. This can be handled in a manner very similar
to that suggested for inhomogeneous materials above, but the problems often
become much more complicated in this case.

INTERPOLATION OF MEASURED DATA | 1-291


To illustrate the use of interpolation for nonlinear materials, a model with a thermal
conductivity that is measured for different temperatures is studied.

Start FEMLAB and select 2D, Heat transfer, Nonlinear stationary physics mode, with
Lagrange - Quadratic elements, press the More button and set the Solution form to
Coefficient.

• Draw a rectangle with corners at (0,0) and (1,1).


• Press the Zoom Extents toolbar button to adjust the coordinate system with respect
to the size of the rectangle.
• Press Initialize Mesh to use the default mesh.

The first step in setting up the interpolation routine is to define the values for the
measured data as constant in FEMLAB. The measured data are given in the following
table.
TABLE 1-2: THERMAL CONDUCTIVITY

TEMPERATURE THERMAL
CONDUCTIVITY

20 1.4
22 3.6
24 6.3
26 4.7
28 4.3
30 3.7
32 3.6
34 4.8
36 5.2
38 5.1
40 4.8

• Select Add/Edit Constants... from the Options menu. Enter the constant names and
expressions according to the following table.

NAME EXPRESSION

Tref linspace(20,40,11)
kref [1.4 3.6 6.3 4.7 4.3 3.7 3.6 4.8 5.2 5.1 4.8]

• Open the Boundary Settings dialog box. Select the Temperature boundary
condition and set T to 20 at all boundaries.

1-292 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
• Open the Subdomain Settings dialog box. Enter the following coefficients:

SUBDOMAIN 1

k interp1(Tref,kref,T)
Q 750

• Set the Initial value to 20 on the Init page.

• Solve the problem.

INTERPOLATION OF MEASURED DATA | 1-293


Importing Data from Text File
Instead of defining the measured data as constants in the Add/Edit Constants dialog
box, the measured data can be loaded into the local workspace from a text file
generated from for example Microsoft Excel. This can be achieved by defining an
interpolation function similar to the MATLAB function flafun, described in the
section “Interpolation with Respect to Spatial Coordinates, inhomogeneous
Materials” on page 1-287, into which the data in the text file is loaded.

Assume that the measured data given in the table “Thermal conductivity” on page
1-292 is stored in a text file called therm_cond.txt. Then the MATLAB
interpolation function fltherm_cond, defined below, can be used in the expression
for the thermal conductivity. Enter type fltherm_cond at the MATLAB command
prompt to see how the data in the text file is used to interpolate values of thermal
conductivities for given temperature values.
%FLTHERM_COND Interpolate thermal conductivity from sampled data.
% K = FLTHERM_COND(T) interpolates thermal conductivity from sampled
% data.
%
% T is the temperature values.
%
% K is the interpolated values of thermal conductivity for the given
% temperature values.
%
% K = FLTHERM_COND(T,DER) returns the derivative of order DER.
%
% The sampled data is stored in the ASCII file therm_cond.txt.
%
% See also FLAFUN.

if nargin==1
der = 0;
end
% Load the sampled data matrix.
load therm_cond.txt -ascii
% Temperature data
Tdata = therm_cond(:,1);
% Thermal conductivity data
kdata = therm_cond(:,2);
% Interpolate values of thermal conductivity for the given temperature
values.
k = flinterp1(Tdata,kdata,T,1,der);

By loading the text file therm_cond.txt using the MATLAB command load
-ascii, the matrix therm_cond with the measured data is available in the local
workspace. The data in this matrix is then used in the interpolation of the thermal
conductivity.

1-294 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Now, load the measured data into the FEM model directly from the text file by
specifying fltherm_cond(T) in the expression for the thermal conductivity.

• Open the Subdomain Settings dialog box and set the Thermal conductivity to
fltherm_cond(T).

• Solve the problem.

The text file will with this approach be loaded several times since the function
fltherm_cond is evaluated several times during the solution process. If the text file
is large the total loading time of the text file might be too time consuming. An
alternative way of making use of the data in the text file when defining the thermal
conductivity coefficient, is to load the measured data to the command line and use
the interp1 command in the expression for the thermal conductivity.

The data in the text file is loaded to the command line and transferred into to the two
arrays Tdata and kdata by issuing the following commands at the MATLAB
command prompt.

% Load the sampled data matrix.


load therm_cond.txt -ascii
% Temperature data
Tdata = therm_cond(:,1);
% Thermal conductivity data
kdata = therm_cond(:,2);

Use the interp1 command in the expression for the thermal conductivity to
interpolate the measured data.

• Open the Subdomain Settings dialog box and set the Thermal conductivity to
interp1(Tdata,kdata,T).

For the solver to have access to the variables Tdata and kdata you need to set the
evaluation context to main. This is done in the Solver Parameters dialog box.

• Select Main workspace as Context in the Solver Parameters dialog box.


• Solve the problem again. Note how the nonlinear solver converges in the Message
log at the bottom of the FEMLAB main window.

Using General Solution Form


This worked well, but from the progress report printed in the command window, it
is clear that the number of iterations that is needed for obtaining convergence is high
and the convergence rate is linear. For larger problems, and with stronger
nonlinearities, this is often a problem. The reason for the slow convergence in this
case is that the coefficient form was used. For nonlinear problems the general form is

INTERPOLATION OF MEASURED DATA | 1-295


preferred since the different expressions used for the problem definition are then
differentiated with respect to the dependent variables and its gradient. See
“Stationary Problems in General Form” on page 3-29 for details. To be able to use
interpolation together with the general solution form, it is necessary to define the
gradient of the interpolation function.

The derivatives of a function or an expression can be defined by setting up the


relation in the FEM structure field rules. From the GUI you do this from the
Differentiation Rules dialog box.

The example below shows how to define the derivatives of the Bessel function of the
first kind, usually denoted by Jp(z).

• Select Differentiation Rules... from the Options menu.


• Type besselj(nu,z) in the edit field Name. The parameters nu and z are chosen
arbitrarily. They are only symbolic names that can be used in the expression for the
gradient of the function. In this case, they coincide with the names in the help text
of besselj.
• The function Jp(z) is a function one variable, z, but in MATLAB it has two input
arguments. In FEMLAB there is a need to specify the derivative of both
arguments. Define the derivative with respect to nu as 0. The derivative with
respect to z can be found in the literature as
Jp – 1 ( z ) – Jp + 1 ( z )
J’p ( z ) = -------------------------------------------------
2

The gradient is given as a string with the respective partial derivatives separated by
commas. In the Derivative edit field, type

0, (bessel(nu-1,z)-bessel(nu+1,z))/2

corresponding to the derivative with respect to nu and z, respectively.

1-296 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
For elementary functions such as the sin function, these relations are automatically
accounted for when solving FEMLAB problems.

An example of a separate MATLAB function that is implemented in such a way that


reasonable derivatives can be obtained is flinterp1. This is a 1D interpolation
function with slightly less generality than interp1, but which can easily be used in
FEMLAB even when the general form is used. The derivatives of the interpolation
function are obtained by using the argument der to flinterp1.

The help text of the function follows.


FLINTERP1 1D interpolation for use in FEMLAB.
YI = FLINTERP1(X,Y,XI) interpolates to find YI, the values of
the underlying function Y at the points in the vector XI.
The vector X specifies the points at which the data Y is
given. If Y is a matrix, then the interpolation is performed
for each column of Y and YI will be length(XI)-by-size(Y,2).

YI = FLINTERP1(X,Y,XI,METHOD) specifies alternate methods.


The default is linear interpolation. Available methods are:

1) ’linear’ - linear interpolation


2) ’nearest’ - nearest neighbor interpolation
3) ’spline’ - piecewise cubic spline interpolation
4) ’pchip’ - piecewise cubic Hermite interpolation

METHOD is either a string or a scalar value.

YI = INTERP1(X,Y,XI,METHOD,DER) differentiates the piecewise


polynomial DER times.

Ex. Plot a sampled distribution and its derivative.

x= linspace(20,40,10);
y = [1.4 2.6 6.3 4.7 4.3 3.7 3.6 4.8 5.2 5.1];
xi = linspace(20,40,100);
plot(xi,flinterp1(x,y,xi,’spline’),’r.’,...
xi,flinterp1(x,y,xi,’spline’,1),’bo’)

See also FLAFUN.

INTERPOLATION OF MEASURED DATA | 1-297


Continuing with the heat transfer example above, the differentiation rules are defined
as follows.

• Open the Differentiation Rules dialog box.


• Enter the function name and derivative according to the following table.

FUNCTION NAME DERIVATIVE

flinterp1(a,b,c) 0, 0, flinterp1(a,b,c,1,1)

The interpolation function will not be differentiated with respect to its first two
input arguments, and the derivatives can thus be chosen arbitrarily. The dependent
variable will on the other hand be used as third input argument when the functions
is called, and this derivative must be defined. The fourth input argument to
flinterp1 specifies the interpolation method. By default this is the linear
method, which also is given by the argument 1. The same method should be used
for the derivative, where it cannot be defaulted. The last argument to flinterp1
specifies the order of the derivative, in this case 1.
• Open the Subdomain Settings dialog box and change the value of k to
flinterp1(Tref,kref,T).

• Open the Solver Parameters dialog box and change the Solution form to General.
• Solve the problem.

The function fltherm_cond can be used in the expression for the thermal
conductivity also in this case where the general solution form is used. Just make sure
to define the derivative of the function fltherm_cond with respect to the
temperature.

• Open the Subdomain Settings dialog box and change the value of k to
fltherm_cond(T).

• Enter the function name and derivative according to the following table.

FUNCTION NAME DERIVATIVE

fltherm_cond(T) fltherm_cond(T,1)

The second argument in the definition of the derivative specifies the order of the
derivative, in this case 1.
• Solve the problem again.
From the progress report it is clear that the nonlinear algorithm converges much
faster. Note also from the error estimates that the convergence rate is quadratic.

1-298 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Working with the Programming Language
You can also solve this problem from the MATLAB prompt. Initialize a FEM
structure by creating the geometry and the mesh.

clear fem
fem.geom = rect2(0,1,0,1);
fem.mesh = meshinit(fem);

Specify two vectors that represent the measured data according to the table above,
and store them in the FEM structure.

fem.const = {’Tref’ linspace(20,40,11) ...


’kref’ [1.4 3.6 6.3 4.7 4.3 3.7 3.6 4.8 5.2 5.1 4.8]}

Now create a Heat transfer application mode. Define the thermal conductivity using
interpolation, and set the temperature to 20 on all the boundaries.

fem.appl.mode = flpdeht2d;
fem.appl.equ.k = ’interp1(Tref,kref,T)’;
fem.appl.equ.Q = 750;
fem.appl.bnd.T = ’20’;
fem.appl.bnd.type = ’T’;

Solve the problem using the nonlinear solver, after using multiphysics and extending
the mesh.

fem = multiphysics(fem);
fem.xmesh = meshextend(fem);
fem.sol = femnlin(fem,’init’,20,’report’,’on’);
postplot(fem,’tridata’,’T’,’tribar’,’on’)

The differentiation rules are set up in the field rules in the FEM structure as follows.

INTERPOLATION OF MEASURED DATA | 1-299


fem.rules = {’flinterp1(a,b,c)’ ’0, 0, flinterp1(a,b,c,1,1)’};

Now modify the thermal conductivity so that flinterp1 is used instead of interp1,
and regenerate the FEM structure. To use the general form for the solution, make
sure that this is stated in the multiphysics call.

fem.appl.equ.k = ’flinterp1(Tref,kref,T)’;
fem = multiphysics(fem,’outform’,’general’);
fem.xmesh = meshextend(fem);

The problem can now be solved as before, but since the FEM structure is set up for
the general solution form, the derivatives of the interpolation function will be taken
into account.

fem.sol = femnlin(fem,’init’,20,’report’,’on’);

1-300 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The Programmi ng Language
As mentioned in the introduction, the GUI is designed for solving 1D, 2D, and 3D
problems. The GUI provides a convenient modeling environment, but there are
situations where a programming tool is more useful than graphical interaction.
FEMLAB provides such a tool in the programming language.

Situations when the programming language is useful include:

• using the FEMLAB functions as a function library for creating your own programs
or functions
• non-standard boundary conditions
• complicated PDE or boundary condition coefficients
• special solution data processing and presentation
Furthermore, when modifying a Model M-file it is important to have some
knowledge of the FEMLAB functions, see “Model M-files” on page 1-51.

A summary of the FEMLAB data structure and the FEMLAB functions is found
below. This summary is followed by examples of how to set up and solve Poisson’s
equation and a thermo-electric multiphysics model using the programming
language. You will learn how to set up the FEM structure, and how to use some of
the FEMLAB functions. The relation to classical PDEs is also described. Other
examples of how to use the FEMLAB functions can be found in the section “Tubular
Reactor” on page 1-378, as well as in the Model Library.

The FEM Structure


When setting up your problem in the programming language, all data necessary for
the simulation is stored in a single MATLAB structure—the FEM structure. A
MATLAB structure is a container for a set of fields; these are accessed by a dot
notation. The data structures in the fields of the FEM structure define different
aspects of the PDE problem, and the various processing stages produce new data

THE PROGRAMMING LANGUAGE | 1-301


structures out of old ones. Here, we denote the FEM structure by fem. The table
below contains the most important fields of the FEM structure.
TABLE 1-3: FEM STRUCTURE FIELDS

FIELD INTERPRETATION

fem.sdim Names of space coordinates (independent variables)


fem.draw The solid objects, face objects (3D only), curve objects (2D
and 3D only), and point objects that form the geometry
fem.geom Analyzed geometry. Can be either a Geometry object or a
Geometry M-file or a mesh
fem.equiv Equivalent boundaries
fem.mesh Mesh structure. Contains finite element mesh
fem.appl Application modes.
fem.sshape Geometry approximation order
fem.dim Names or number of dependent variables
fem.shape Shape functions (finite elements)
fem.const Definition of constants
fem.expr Definition of variables as expressions
fem.var Application mode specific variables
fem.equ Variables, equations, constraints, and initial values on
subdomains
fem.bnd Variables, equations, constraints, and initial values on
boundaries (not present in 0D)
fem.edg Variables, equations, constraints, and initial values on edges
(Only in 3D)
fem.pnt Variables, equations, constraints, and initial values on
vertices (only in 2D and 3D)
fem.form Form of equations. Can be ’coefficient’ (default),
’general’, or ’weak’
fem.border Assembly on borders
fem.mat Matrix M-files
fem.elem Element structures, a low-level way of specifying a problem
fem.eleminit Element initial value structures, a low-level way of specifying
initial values
fem.xmesh Extended mesh structure

1-302 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
TABLE 1-3: FEM STRUCTURE FIELDS

FIELD INTERPRETATION

fem.init Initial value


fem.sol Solution structure
Subfields: u, lambda, tlist
Not all of the fields listed above are needed when modeling with FEMLAB
functions. Many of the fields can also be automatically generated. There are some
crucial fields, though, that form the base of the model.

The geom field contains the geometry model. A geometry can be created from
primitive object constructors such as rect2 or by solid operations to form more
complicated geometry models. External formats and meshes can also represent a
geometry model.

In order to solve the problem a mesh is needed. Once a geometry has been created
the mesh is easily generated by meshinit and stored in the mesh field.

For setting up the problem, one or several application structures can be stored in the
appl field. These structures store the material properties, sources, or PDE
coefficients needed for the problem.

If the application structure has been created, the equ, bnd, edg, and pnt fields are all
generated, when necessary, with the multiphysics function. You can also choose to
set up your model by specifying these fields explicitly.

An important field that forms the basis of the numerical method is the xmesh field.
Although much of the most crucial information is stored here, you do not need to
know the details of it. This structure is automatically generated with the meshextend
command.

Finally, once the solution has been found, it is stored in the sol field. When it is
stored here, it can used for postprocessing and visualization.

The FEMLAB Functions


When working with a FEM problem in the programming language, there are several
functions available. These functions span the modeling process from functions for
creating the geometry model and mesh, via a family of solvers, to advanced
postprocessing functions. Although the ways to set up a model in the programming
language are almost unlimited, there are a few functions that are crucial.

THE PROGRAMMING LANGUAGE | 1-303


In the table below the most important functions for setting up a problem and solving
it are listed. For full details on these functions, and associated ones not listed here, see
the respective entries in the Function Reference. You can also study “Specifying a
Model” on page 3-54 in the Reference Guide for a more in-depth description on how
to use these functions.
TABLE 1-4: MAJOR FEMLAB FUNCTIONS

FUNCTION DESCRIPTION

geomcomp Analyze geometry model


meshinit Build an initial mesh
meshrefine Refine mesh
multiphysics Combines application modes into composite FEM
structure
femdiff Differentiate a FEM structure
meshextend Extend a finite element grid to the desired element
types
assemble Assemble equation and constraints matrices of a PDE
problem
asseminit Compute initial value
femlin, femnlin, Solve linear/nonlinear static PDE problem
femiter, adaption,
multigrid
femtime Solve linear/nonlinear time-dependent PDE problem
femeig Solve eigenvalue PDE problem
posteval, postinterp Evaluate expression from FEM solution
postint Integrate expression from FEM solution
postplot, postmovie, Plot expression
postcrossplot

At all stages in the solution process in the GUI, the current FEM structure can be
exported to the MATLAB prompt by using the Export FEM Structure as ’fem’ or
Export FEM Structure... options from the File menu.

1-304 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Example: Solving Poisson’s Equation
In this example, Poisson’s equation is solved first on a unit disk and then on a
cylinder, using the FEMLAB functions. The boundary condition is of the clamped
type, also called a Dirichlet condition. The PDE formulation is
 – ∇ ⋅ ∇u = k in Ω
 1
 u=k on ∂Ω
 2

where Ω represents the disk or cylinder. We will only solve for the case of constant k1
and k2.

Poisson’s equation is the PDE model of, for example, the Electrostatics application
mode, and the stationary Heat transfer application mode.

As mentioned earlier, a FEMLAB model is defined by a data structure called the FEM
structure. The FEM structure for this example is created step-by-step by a sequence
of calls to several FEMLAB functions.

• Start in the MATLAB command window by clearing the FEM structure, in case
there are old results in the main workspace.
clear fem

• First give the dependent variable and form of the model.


fem.dim = {’u’};
fem.form = ’coefficient’;

This creates a PDE model with one solution component u using the coefficient
form.
• Optionally, parameters for the model can now be specified using the field
fem.const. Here, we introduce the constants k1 and k2 set to 1 and 0,
respectively.

fem.const = {’k1’ 1 ’k2’ 0};

This means that we are actually going to solve

 – ∇ ⋅ ∇u = 1 in Ω

 u=0 on ∂Ω

The field fem.const is a cell vector with an alternating sequence of names of


constants and their associated numerical values.

THE PROGRAMMING LANGUAGE | 1-305


PO IS S O N ’S E Q U AT IO N O N A U N I T D I S K
FEMLAB functions for creating primitive geometry objects are analogous to the
primitive geometry object buttons on the draw toolbar of the GUI.

• A solid circle with center at (0,0) and radius 1 is defined as

c = circ2(0,0,1)

• The geometry data is stored in the geometry field of the FEM structure.

fem.geom = c;

See the section “Geometry Modeling” on page 1-170 for more information on how
to create geometry objects.

• You can plot the geometry by entering

geomplot(fem)
axis equal

• The boundary conditions are of the Dirichlet type.

fem.bnd.h = 1;
fem.bnd.r = ’k2’;

The field fem.bnd has four sub fields: q, g, h, and r. The meaning of these fields is
explained in “Equations and Constraints” on page 3-73, and the notation is also used
in the dialog box for boundary conditions, see “The FEMLAB PDE Language” on
page 1-336. Each of these fields has a default value of zero.

• Use quadratic Lagrange elements:

fem.shape = 2;

The field fem.shape field defines the shape functions. They are explained in “Shape
Functions” on page 3-60 in the Reference Manual.

• The PDE coefficients are defined by

fem.equ.f = ’k1’;
fem.equ.c = 1;

The field fem.equ can define seven PDE coefficients: da, c, al, ga, be, a, and f.
They are explained in“The FEMLAB PDE Language” on page 1-336 and
“Equations and Constraints” on page 3-73.

• The mesh is initialized by the command

fem.mesh = meshinit(fem);

• The function meshrefine refines an already existing mesh.

1-306 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
fem.mesh = meshrefine(fem);

The initial mesh is generated by the function meshinit, based on the geometry in
fem.geom. The field fem.mesh is added in the FEM structure.

• To plot the current mesh, enter

meshplot(fem);

• Everything is now set to extend the mesh and solve the PDE using the linear
solver:

fem.xmesh = meshextend(fem);
fem.sol = femlin(fem);

The function femlin creates the sub-field fem.sol.u in the field fem.sol which
contains the actual solution vector.

There are some different FEMLAB functions to choose from when solving a
problem. The solvers are explained in section “The Solvers” on page 1-406. Details
of the usage of solvers in programming are available in section “Solver Algorithms”
on page 3-103 in the Reference Guide.

For stationary problems, you can choose between the linear solver, femlin, the
nonlinear solver femnlin, and the iterative solver femiter that handles both linear
and nonlinear problems. See the section “The Solvers” on page 1-406 for how to
choose between these solvers.

For time-dependent problems, the main algorithm is femtime. It supports a number


of time-stepping algorithm: the ODE Suite algorithms of MATLAB, and the
FEMLAB specific time-stepping algorithms fldae, fldaek, and fldaspk. The
algorithms fldaek and fldaspk are capable of using iterative methods to solve the
linear systems. The function femtime returns the fields fem.sol.u and
fem.sol.tlist, the output times for which the solution, u, is computed.

An eigenvalue problem is solved with femeig, which returns fem.sol.u and


fem.sol.lambda, the eigenvalues for which the solution, u, is computed.

In addition, adaptive and multigrid solvers are available. For more information on
different solvers, see the Reference Guide.

• To plot the solution (the solution variable is ’u’), enter

postplot(fem,'tridata','u','triz','u')

• You can now use any function in MATLAB or FEMLAB to continue


postprocessing the solution. You can for example add a grid by typing:

THE PROGRAMMING LANGUAGE | 1-307


grid on

and obtain a plot as below

There are a number of plot commands for different types of plotting, for example,
postplot and postsurf.

PO IS S O N ’S E Q U AT IO N O N A C Y L IN DE R
Now, let us solve the same problem on a cylinder. Continue from the previous
example and replace the 2D geometry with a 3D primitive cylinder object.

• Start by copying the structure fem into a new variable.


fem3 = fem;

• A solid cylinder with base center at (0,0,0) and radius 1 and height 1 is defined as
c = cylinder3(1,1,[0,0,0])

• Replace the 2D geometry in the FEM structure by the cylinder.


fem3.geom = c;

• Generate a new mesh by the command


fem3.mesh = meshinit(fem3);

1-308 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
You can plot the geometry and the mesh using the geomplot and the meshplot
commands in the same way as in the unit disk example.

• You are now ready to extend the mesh and solve the PDE using the iterative solver
femiter with the AMG preconditioner. The iterative solver uses less memory
than the direct solver femlin.

fem3.xmesh = meshextend(fem3);
fem3.sol = femiter(fem3,’prefun’,’amg’);

For more information on different solvers, see the section “The Solvers” on page
1-406.

• To plot the solution, enter

postplot(fem3,’slicedata’,’u’,’geom’,’on’)

This plots the solution on five slices through the cylinder as illustrated below.

POSTPROCESSING EXAMPLES
To integrate functions and expressions of the solution over boundaries and
subdomains, you can use the FEMLAB function postint. There is also a function
for evaluation on domains of any space dimension: posteval. Note that the help
texts of the postprocessing functions contain simple examples. Just enter, for
example, help posteval at the MATLAB prompt for obtaining the help text of
posteval.

THE PROGRAMMING LANGUAGE | 1-309


For a complete list of variables that are accessible from the postprocessing functions,
for example, posteval, postint, postinterp, postplot, and postmovie, see the
tables for application mode variables in the section “Application Mode Reference” on
page 4-203 in the Reference Manual. For postprocessing when using the PDE
forms, see the section “The FEMLAB PDE Language” on page 1-336.

Below you will find examples of using Poisson’s equation model for integration and
interpolation. See also the Model Library and the Function Reference for more
information on postprocessing.

Subdomain Integrals
You integrate over subdomains by using the function postint. The simple case is
when the subdomain is part of the original geometry. Then you just use postint on
the original geometry with a solution computed on that geometry.

If the subdomain is not part of the original geometry, the best way to handle the
situation is to use coupling variables. You create the auxiliary geometry on which you
want to integrate over a subdomain. You then create a coupling variable that maps
the solution from the original geometry to the auxiliary geometry. Finally, you
integrate the coupling variable over the auxiliary geometry.

For previous FEMLAB versions, we recommended interpolation between the


original geometry and the auxiliary geometry, but with the new extended mesh data
structure, this method is too complicated and no longer recommended.

Suppose you want to integrate the square of the solution of Poisson’s equation on the
unit disk, using an elliptical integration domain centered at (0.25,0) with a minor
and major axis of 0.1 and 0.25, respectively. The elliptical domain is represented in
FEMLAB by the mesh of a solid ellipse. In the same way, any mesh can be used as
integration domain using the technique presented below.

• Create a mesh of the ellipse, and set the fields of the auxiliary FEM structure femE.

e = ellip2(0.25,0,0.1,0.25);
clear femE
femE.geom = e;
femE.mesh = meshinit(femE);
femE.mesh = meshrefine(femE);

• The auxiliary FEM structure will only be used for postprocessing so the list of
dependent variables is empty. The geometry approximation order should be set to
match the element order in the original FEM structure, fem.

femE.dim={};

1-310 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
femE.sshape=2;

• Plot the solution of Poisson’s equation assuming that the FEM structure created
in the example of Poisson’s equation above is still present in the MATLAB
workspace.

postplot(fem,’tridata’,’u’)
view(2)
axis equal

• Plot the ellipse on top of the solution plot.

hold on
meshplot(femE,’elmode’,’on’,’edgemode’,’off’,...
’elcolor’,[0.5 0.5 0.5],’eledgecolor’,[0.5 0.5 0.5])

• Create a coupling variable u from the circular geometry to the elliptical. This
coupling variable maps the solution from geometry 1 to geometry 2 without
doing any coordinate transformation. More information about the coupling
variables are available in the Reference Manual in “Non-Local Couplings” on page
3-147 and the reference entry on elcplextr.

clear cpl
cpl.elem=elcplextr;
cpl.src.g=1;
cpl.src.meshp={’x’ ’y’};
cpl.src.equ.var={’u’ ’u’};
cpl.dst.g=2;
cpl.dst.ep={’x’ ’y’};

• Create an extended FEM structure as container for the full problem, including
both the fem and femE structures. The list of constants must be contained in the

THE PROGRAMMING LANGUAGE | 1-311


extended FEM structure. The asseminit function is used to map the previous
solution to the new extended mesh.

clear xfem
xfem.const=fem.const;
xfem.fem{1}=fem;
xfem.fem{2}=femE;
xfem.elem{1}=cpl;
xfem.xmesh=meshextend(xfem);
xfem.sol = asseminit(xfem,’init’,fem) ;

• Integrate the square of the solution over the elliptical domain; use the long
MATLAB output format to display more than five digits.

format long e
I = postint(xfem,’u.^2’,’geomnum’,2)

The value of the integral, as computed here by postint, is approximately 0.00415.


The second argument of postint is a string with a MATLAB expression containing
valid variables. See the section “Application Mode Reference” on page 4-203 for
more information on application mode specific variables.

The task to integrate an expression over a 3D subdomain is equivalent to the 2D


subdomain integration. The example integrates over a subdomain in the original
problem geometry.

• Using the FEM structure from the example of Poisson’s equation in 3D above,
integrate the square of the solution over the entire cylinder.
I = postint(fem3,’u.^2’)

Boundary Integrals
It is also possible to compute line integrals along 2D curve objects and surface
integrals over 3D face objects using the function postint. We specify the property
Edim to postint to control which domain type to integrate on.

In the following example, the integral is assumed to be taken over a line ranging from
2
(-1/√2, -1/√2) to (1/√2, 1/√2), again with the integrand u .

Using the refined Poisson solution:

• Create the line object and the corresponding mesh, and fill out the auxiliary FEM
structure femL.

clear femL
l = curve2([-1/sqrt(2) 1/sqrt(2)],[-1/sqrt(2) 1/sqrt(2)]);
femL.geom = l;

1-312 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
femL.mesh = meshinit(femL);

• The auxiliary FEM structure will only be used for postprocessing so the list of
dependent variables can be empty. The geometry approximation order should be
set to match the element order in the original FEM structure, fem.

femL.dim={};
femL.sshape=2;

Of course, you can use any curve object for integration. See the section “Geometry
Modeling” on page 1-170 for more information on how to create curve objects.

• Create a coupling variable u from the cylinder to the curve. This coupling variable
just maps the solution from geometry 1 to geometry 2 without doing any
coordinate transformation. The element structure cpl from the previous example
can be used.
• Create an extended FEM structure as container for the full problem, including
both the fem and femE structures. The list of constants must be contained in the
extended FEM structure.
clear xfem2
xfem2.const=fem.const;
xfem2.fem{1}=fem;
xfem2.fem{2}=femL;
xfem2.elem{1}=cpl;
xfem2.xmesh=meshextend(xfem2);
xfem2.sol = asseminit(xfem2,’init’,fem);

• Compute the integral

I = postint(xfem2,’u.^2’,’geomnum’,2,’edim’,1)

The value of the integral I is approximately 0.067.

To integrate along edges of the original solid circle of the Poisson’s equation example,
postint is used with the property dl specifying which boundaries to integrate on.

• The integral of the source term in Poisson’s equation on the unit disk should equal
the negative of the integral of the in-flux over the boundary. To verify this, enter

I1 = postint(fem,’f’)
I2 = postint(fem,’ncu’,’edim’,1,’dl’,[1 2 3 4])
res = I1+I2

The flux can be more accurately computed using weak constraints, see “Weak
Constraints, Their Uses and Limitations” on page 1-398. By refining the mesh,
solving again, and performing the above integrations, the value of the variable res

THE PROGRAMMING LANGUAGE | 1-313


approaches 0. The dl specification of boundaries can be omitted, using the default
boundary list which is the collection of all geometry boundaries.

The task of integrating an expression over a 3D boundary is equivalent to the 2D


boundary integration.

• Using the FEM structure from the example of Poisson’s equation in 3D above,
integrate the z-derivative of the solution over the top face of the cylinder. This is
face number 6 which can be verified by plotting the geometry and its face labels.

geomplot(fem3,’facemode’,’off’,’facelabels’,’on’)
I = postint(fem3,’uz’,’edim’,2,’dl’,6)

For more information on how to use the functions postint, postplot and
postinterp, see the corresponding reference entries in the Function Reference
section in the Reference Manual.

The Application Structure


When working with equation-based modeling it is often most convenient to directly
specify the equ and bnd fields of the FEM structure. If you want to work with
physical quantities and material properties, the physics modes can be used. When
employing these for script modeling in the programming language, the application
structure is used.

The application structure stores the necessary information in several fields. Many of
these correspond to the fields in the FEM structure. The most important fields are
given in the following table.
TABLE 1-5: APPL STRUCTURE FIELDS

FIELD INTERPRETATION

appl.bnd Boundary coefficients/application data


appl.border Cell vector with strings on/off or a corresponding logical
vector, one for each solution component
appl.dim Cell vector with names of the solution components or an
integer specifying the number of solution components
appl.edg Edge coefficients/application data
appl.elemdefault A string indicating the element used for default settings
appl.equ Subdomain coefficients/application data
appl.form Problem form: coefficient, general, or weak

1-314 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
TABLE 1-5: APPL STRUCTURE FIELDS

FIELD INTERPRETATION

appl.mode Application mode


appl.var Application mode specific variables
Most of these fields have default values, and need not be specified when solving a
problem in the programming language. The functions appl2fem and multiphysics
are used for transforming the application structure data to the FEM structure for
generating the complete set of equations. See the corresponding entries in the
FEMLAB Function Reference for details.

There are other fields that can be used for modeling. For a complete list of the fields,
see the reference entry on appl2fem in the Function Reference, or “The Application
Structure” on page 3-95 in the Reference Guide.

APPL.MODE - APPLICATION OBJECTS


The application modes are specified via a corresponding MATLAB class. To create an
application mode object, a function with the same name as the class is called, for
example,

obj3 = flpdeht3d

which creates a Heat transfer application mode in 3D, or

obj2 = flpdeps

which is the Structural mechanics Plane stress application mode. Theses objects can
then be stored in the mode field by entering

appl2.mode = obj2;
appl3.mode = obj3;

Alternatively, the mode field in the application structure can contain a string with the
name of the application mode. To create a Diffusion problem in 1D you can enter

appl1.mode = ’flpdedf1d’

APPL.DIM - DEPENDENT VARIABLES


The dim field in the application states the names of the dependent variables and hence
gives the dimension of the corresponding PDE system. If the dimension is missing,
a default name, using the corresponding standard name of the field quantity solved
for, will be used.

The default name of the dependent variable in the Magnetostatics mode is obtained
by entering

THE PROGRAMMING LANGUAGE | 1-315


default_dim(flpdems3d)

which gives

ans =

’Ax’ ’Ay’ ’Az’

You can set a new name of the dependent variable by entering

appl.dim = {'u1','u2','u3’};

A P PL . VAR - A PP L I C ATI O N S C A L A R VA R I A BL E S
For variables that are always used in the generation of PDEs and boundary
conditions, such as the angular frequency, the values can be specified in the appl.var
field. The value can be either a constant value or an expression containing constants
available in fem.variables. Note that only predefined variable names can be used
in this field.

For the AC power electromagnetics mode, the variable can be set as

appl.var.omega = 2*pi*100;

The appl.var field can also be specified as a cell array, that is,

appl.var = {'omega' '2*pi*freq'};

The default value is obtained by entering

default_var(flpdeac)

which gives the result

ans =

'omega' '2*pi*50'

APPL.ELEMDEFAULT - ELEMENTS
The element type used as default when generating the xmesh field in the FEM
structure is specified in the appl.elemdefault field. You can write

appl.elemdefault = 'Lag1';

to obtain linear Lagrange elements.

To see which available elements there are in the Incompressible Navier-Stokes mode,
enter

eleminfo(flpdens2d,'elemshortdescr')

1-316 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The result is

’Lag1’ ’Lagp2p1’ ’Lagp3p2’ ’Lagp4p3’

To see the current default, that is, the element you obtain if you do not define your
own, enter

eleminfo(flpdens2d,’default’)

which results in

ans =

Lagp2p1

For more descriptive names of the elements enter

eleminfo(flpdens2d,’elemdescr’)

The result is

ans =

’Linear Lagrange’
’Lagrange - p2-p1’
’Lagrange - p3-p2’
’Lagrange - p4-p3’

These strings are used in the popup menu in the GUI, and cannot be used at the
MATLAB prompt.

APPL.EQU - SUBDOMAIN SETTINGS


The application structure field equ is used for specifying properties which will be
transformed into PDE coefficients. To see which quantities that are available for a
certain mode and their default values, enter

default_equ(flpdesm3d)

For the Structural mechanics application mode, the result is

ans =

E: {’2.06E11’}
nu: {’0.3’}
Kx: {’0’}
Ky: {’0’}
Kz: {’0’}
rho: {’7800’}

Now consider an example with two materials. To use other values than the default for
the physical properties, enter them as follows.

THE PROGRAMMING LANGUAGE | 1-317


appl.equ.E = {’1.84e11’ ’2.12e11’};

APPL.BND - BOUNDARY CONDITIONS


The boundary conditions for the simulation are given in the bnd field. First you have
to select which type of boundary condition you want at each boundary. This in done
using the field bnd.type. Then some boundary conditions require certain boundary
variables to be set, unless the default value is sufficient. Note that not all types of
boundary conditions require a boundary variable.

The default conditions can be obtained by entering

default_bnd(flpdedc3d)

which gives

ans =

g: {’0’}
q: {’0’}
V: {’0’}
type: {’V0’}

for an object of the flpdedc3d class.

To change boundary conditions, simply enter,

appl.bnd.type = {’V’ ’V0’};


appl.bnd.V = {’1+x’ ’0’};

which sets the electric potential V to 0 on one boundary and to the expression 1+x on
another.

THE INDEX VECTOR


Often you have a model with several subdomains having the same physical properties
and many boundaries where you want to apply the same boundary condition. To
simplify the notation the index vectors in the fields equ.ind and bnd.ind are used.
Consider this example:

appl.equ.sigma = {’0’ ’5.9e7’};


appl.equ.ind = [2 1 2 2 2];

Here you have five subdomains. Subdomain 2 is non-conducting, whereas the


7
conductivity in the other four subdomains are 5.9 ⋅ 10 S/m.

Here is another example where three different boundary conditions are applied to six
boundaries:

appl.bnd.type = {’V’ ’V0’ ’nD’};

1-318 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
appl.bnd.nD = {’’ ’’ ’-12’};
appl.bnd.V = {’100’ ’’ ’’};
appl.bnd.ind = [2 3 3 2 1 2];

For the Electrostatics application mode, this sets the electric potential to 100 at
boundary 5 and to 0 (ground) at boundaries 1,4, and 6. At boundary 2 and 3, a
surface charge of -12 are set.

Example: Thermo-Electric Heating


To demonstrate the power of the FEMLAB functions and how to use them when
writing a MATLAB program, this section describes a multiphysics problem with
similar physics as the model of the section “Thermo-Electric Heating in a Bus Bar
with Multiphysics” on page 1-138. Giving a detailed description of the FEMLAB
commands used for setting up a problem in the programming language, a 2D model
of resistive heating in a copper plates is described. After that, the full program code
for running the bus bar modeled in the GUI earlier is presented.

RESISTIVE HEATING IN A COPPER PLATE


Imagine a copper plate measuring 1 x 1 m that also contains a small hole. The plate’s
arbitrary thickness, t, has no effect on the model. Suppose you subject the plate to an
electric potential difference across two opposite sides (all other sides are insulated).
The potential difference induces a current that heats the plate.

A multiphysics model of this is set up using the Conductive media DC application


mode and a Heat transfer application mode. An air stream at 300 K (27° C) cools
the plate except on its thermally insulated upper and lower edges. A voltage

THE PROGRAMMING LANGUAGE | 1-319


difference is applied between the left and right edge. The upper and lower edges are
kept electrically insulated.

Thermal and Electric Insulation

300 K
300 K
0V
0.1 V

Copper Plate

300 K

Current

Thermal and Electric Insulation


1m

To set up the multiphysics model you need to know how electric current affects the
temperature. Recall that the electric potential, V, is the solution variable in the
Conductive media DC application mode. The generated heat, Q, is proportional to
the square of the magnitude of the electric current, J , in the material. The current,
in turn, is proportional to the electric field, which equals the negative of the gradient
of the potential V.
2
Q∝ J

The coefficient of proportionality is the electrical resistivity ρ= 1/σ, which is also the
reciprocal of the temperature-dependent electric conductivity σ = σ(T). Combining
these facts gives the fully coupled relation

1 2 1 2 2
Q = --- J = --- σE = σ ∇V
σ σ

using the vector differential operator symbol ∇ for the gradient. For more
information on the vector differential operator, see the section “The FEMLAB PDE
Language” on page 1-336.

1-320 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Notice that quantities other than σ vary with temperature. For example, the thermal
conductivity is temperature dependent, as well, and a refined model would take this
into account.

To form the FEM structure for the multiphysics model, we first create two separate
application structures, a1 and a2. The first is the Conductive media DC application
mode; the second is Heat transfer. The two structures are then combined to form the
composite FEM structure. For more information on different application modes, see
the section “Application Mode Reference” on page 4-203 in the chapter The
Graphical User Interface in the Reference Manual.

• First clear the FEM and application mode structures, and define the geometry and
constants.

clear fem a1 a2
fem.geom = geomcsg({square2(0,0,1)});
fem.const = {’r0’,1.754e-8,’T0’,293,’alpha’,0.0039};

The command geomcsg is used to create an analyzed geometry. Calling geomcsg is


convenient when filling out the geom field to create a canonized enumeration of
subdomains and edges, that is, an enumeration that is the same regardless of the
order in which the geometry operations are performed.

• Specify the expression for the resistivity as a function of the temperature.

fem.expr = {’r’,’r0*(1+alpha*(T-T0))’};

• Initialize the mesh, and refine it once.

fem.mesh = meshinit(fem);

• Specify the Conductive media DC application mode by filling out the mode field
with the appropriate method name.

a1.mode = flpdedc2d;

• Specify the boundary conditions. The right boundary is grounded, the top and
bottom are insulated, and the left has the potential V=0.1V.

a1.bnd.V = {0.1 {} {}};


a1.bnd.type = {’V’ ’qg0’ ’V0’};
a1.bnd.ind = [1 2 2 3];

The field bnd.ind is used to distribute boundary conditions without needing to


repeat values that are equal for groups of boundaries. The entry bnd.ind(k)
contains the number of the boundary condition for boundary number k. PDE
coefficients and initial conditions can also be grouped by using the equ.ind. See the

THE PROGRAMMING LANGUAGE | 1-321


section “Domain Groups” on page 3-55 for more information on subdomain and
boundary groups.

• Specify the conductivity, source current, and initial potential.

a1.equ.sigma = ’1/r’;
a1.equ.Q = 0;
a1.equ.init = ’0.1*(1-x)’;

• Now specify the Heat transfer application mode.

a2.mode = flpdeht2d;

• The left and right boundaries have a temperature of 300K, and the top and bottom
boundaries are insulated.

a2.bnd.T = {300 {}};


a2.bnd.type = {’T’ ’q0’};
a2.bnd.ind = [1 2 2 1];

• Specify the density, heat capacity, heat conduction coefficient, heat source, and
initial temperature.

a2.equ.rho = 8930;
a2.equ.C = 340;
a2.equ.k = 384;
a2.equ.Q = ’1/r*(Vx^2+Vy^2)’;
a2.equ.init = 300;

• Specify the desired element types. The easiest way to do this is to use the
elemdefault field. Here, we use quadratic Lagrange elements.

a1.elemdefault = ’Lag2’;
a2.elemdefault = ’Lag2’;

This field is used by multiphysics to generate the correct shape functions,


integration order, constraint order, and geometry shape order. See the Function
Reference entry on elemdefault for details about the elemdefault field.

• Combine the two modes, and create the FEM structure.

fem.appl = {a1 a2};


fem = multiphysics(fem);

The multiphysics command is used to merge the application modes contained in


the cell array of the application mode field appl. The function appl2fem is called by
multiphysics to expand the application mode data in fem.appl to FEM structure
format and to re-insert it in the FEM structure. If a field is missing in an application

1-322 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
structure, its default value will be used. For more information, see the reference
entries on appl2fem and multiphysics.

• Create the extended mesh. This creates an xmesh field containing information
about the mesh, degrees of freedom, shape functions, equations, additional
variables, etc.

fem.xmesh = meshextend(fem);

• Solve the problem using the time-dependent solver.

fem.sol = femtime(fem,’tlist’,linspace(0,3000,41), ...


’report’,’on’);

• The transition to a steady state is shown by creating a movie, using the electric
potential as surface data and the temperature as surface height data.

postmovie(fem,’movie’,’off’,’tridata’,’V’,’triz’,’T’, ...
’tribar’,’on’);

• Create the geometry with a hole in the middle and mesh it.

fem.geom = square2(0,0,1)-circ2(0.5,0.5,0.1);
fem.mesh = meshinit(fem);

• Change the boundary conditions. The new geometry has four more boundary
segments, numbered 5 through 8. The boundary conditions for the hole are
electric insulation for a1 and temperature, T=300, for a2. Only the ind field has
to be updated.

a1.bnd.ind = [1 2 2 3 2 2 2 2];

THE PROGRAMMING LANGUAGE | 1-323


a2.bnd.ind = [1 2 2 1 1 1 1 1];

• The solution is now obtained and animated as before.

fem.appl = {a1 a2};


fem = multiphysics(fem);
fem.xmesh = meshextend(fem);
fem.sol = femtime(fem,’tlist’,linspace(0,3000,41), ...
’report’,’on’);
postmovie(fem,’movie’,’off’,’tridata’,’V’,’triz’,’T’, ...
’tribar’,’on’);

If your system is equipped with an OpenGL graphics acceleration card, adding the
Camera menu to the figure window can be useful for being able to, for example, rotate
3D graphs in real-time. To add the Camera menu, enter cameramenu, then click and
drag in the graph for rotating it.

RESISTIVE HEATING IN A BUS BAR


The model described above is in many repasts very similar to the the model presented
in “Thermo-Electric Heating in a Bus Bar with Multiphysics” on page 1-138, so the
working flow for creating a script program of the Bus Bar model is almost the same.

To give a complete picture of what a program using the FEMLAB functions looks
like, the whole script is listed below. Since this 3D model is quite complicated to
construct, the geometry modeling section is a large part of the script. For details on
the FEMLAB functions used in this script, type help followed by the function name
at the MATLAB prompt.
%BUS_BAR_CMD Script running Bus Bar model.
%

1-324 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
clear fem

% Creating the Geometry

% Work plane 1
wrkpln1 = geomgetwrkpln(’quick’,{’xy’,0});

% Draw first part of the geometry


c1 = circ2(0,0,0.06);
c2 = circ2(0,0,0.04);
co1 = c1-c2;
l1 = line2([0 0.06 0],[0 0.06 0.06]);
co1 = co1*l1;
r1 = rect2(-0.1,0,0.04,0.06);

% Create composite object and remove internal borders


co1 = geomdel(co1+r1);

% Create a mirror object using scale and move


co1 = move(co1,-0.05/sqrt(2),-0.05/sqrt(2));
co2 = scale(co1,-1,-1);

% Create composite object


co1 = co1+co2;

% Create extruded 3D geometry object


ex1 = extrude(co1,’distance’,0.05,’wrkpln’,wrkpln1);

% Work plane 2
wrkpln2 = geomgetwrkpln(’faceparallel’,{ex1,2,1,0});

% Create cylinder for first hole


c1 = circ2(0.04,0.025,0.005);
ex2 = extrude(c1,’distance’,-0.02,’wrkpln’,wrkpln2);

% Create circular face object


c2 = circ2(0.04,0.025,0.01);
co2 = c2-c1;
em1 = embed(co2,’wrkpln’,wrkpln2);

% Work plane 3
wrkpln3 = geomgetwrkpln(’faceparallel’,{ex1,5,1,0});

% Create cylinder for second hole


c3 = circ2(0.06,0.025,0.005);
ex3 = extrude(c3,’distance’,-0.02,’wrkpln’,wrkpln3);

% Create circular face object


c4 = circ2(0.06,0.025,0.01);
co3 = c4-c3;
em2 = embed(co3,’wrkpln’,wrkpln3);

% Drill holes in bar


% Use GEOMCOMP for faster analysis. If the set formula is
% given directly at the MATLAB prompt, only one operation

THE PROGRAMMING LANGUAGE | 1-325


% at the time can be made.
co4 = geomcomp({ex1, ex2, ex3},’ns’,{’EX1’ ’EX2’ ’EX3’},...
’sf’,’EX1-(EX2+EX3)’);

% Coerce all objects to a solid


co4 = geomcoerce(’solid’,{co4 em1 em2});

% Add point for use with coupling variables


p1 = embed(point2(-0.14,-0.04),’wrkpln’,wrkpln1);

% Create analyzed geometry


fem.geom = geomcsg({co4},{},{},{p1});

% Defining Constants and Expressions

% Add Constants
fem.const = {...
’rho0’,1.754e-8, ...
’T0’,293, ...
’alpha’,0.0039,...
’V0’,50e-3};

% Add expressions
fem.expr = {...
’sigmaT’ ’1/(rho0*(1+alpha*(T-T0)))’ ...
’Qj’ ’sigmaT*(Vx^2+Vy^2+Vz^2)’ ...
’T’ ’T0’};

% Application Mode 1

clear appl1
appl1.mode = flpdedc3d;

% Boundary Settings
appl1.bnd.type = {’qg0’ ’V0’ ’V’};
appl1.bnd.V = {’’ ’’ ’V0’};
appl1.bnd.ind = ones(1,25);
appl1.bnd.ind(1,6) = 2;
appl1.bnd.ind(1,20) = 3;

% Subdomain Settings
appl1.equ.sigma = ’sigmaT’;
appl1.equ.Q = ’0’;
appl1.equ.ind = [1 1];

fem.appl{1} = appl1;

% Initialize Mesh
fem.mesh = meshinit(fem,’hcurve’,0.6,’hmaxfact’,1.9,...
’hgrad’,1.6,’hcutoff’,0.03,’hmax’,0.011);

% Generate FEM structure fields and extended the mesh data


fem = multiphysics(fem);
fem.xmesh = meshextend(fem);

1-326 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
% Use the iterative solver for solving this problem. This solver
% is less memory consuming. The choice of preconditioner in this
% case is Algebraic MultiGrid.
fem.sol = femiter(fem,’prefun’,’amg’);

% Postprocessing
postplot(fem,...
’isodata’,’V’,...
’isolevels’,20,...
’flowdata’,{’Ex’ ’Ey’ ’Ez’},...
’flowlines’,7,...
’flowcolor’,’red’)

% Save FEM structure for use as initial value later on


fem0 = fem;

% Remove expression with name T


fem.expr = fem.expr(1:4);

% Create Application Mode 2


clear appl2
appl2.mode = flpdeht3d;

% Set boundary conditions


appl2.bnd.type = {’q’ ’T’ ’q’ ’q0’};
appl2.bnd.h = {’10’ ’’ ’5’ ’’};
appl2.bnd.Tinf = {’T0’ ’’ ’T0’ ’’};
appl2.bnd.T = {’’ ’T0’ ’’ ’’};
appl2.bnd.ind = ones(1,25);
appl2.bnd.ind(1,[5:10 20]) = 2;
appl2.bnd.ind(1,[21:24]) = 3;
appl2.bnd.ind(1,[25]) = 4;

% Define Subdomain parameters


appl2.equ.rho = ’8960’;
appl2.equ.C = ’340’;
appl2.equ.k = ’384’;
appl2.equ.Q = ’Qj’;
appl2.equ.ind = [1 1];

fem.appl{2} = appl2;

% Create coupling element. The value of the integrated current


% on boundary 13 is stored as a value in point 1. This is the
% point lying outside the solid geometry model.
clear elem
elem{1}.elem = elcplscalar;
elem{1}.src.g = 1;
elem{1}.src.bnd.gporder = 4;
elem{1}.src.bnd.var = {’I’ {’unga1’}};
elem{1}.src.bnd.ind = {13};
elem{1}.dst.g = 1;
elem{1}.dst.pnt.ind = {1};

fem.elem = elem;

THE PROGRAMMING LANGUAGE | 1-327


% To avoid variable name conflicts the application mode
% variable of the Conductive media DC application mode
% is renamed from ’Q’ to ’Qv’.
fem.appl{1}.assign={’Q’ ’Qv’};

% Generate FEM structure fields and extended mesh data. In


% the call to multiphysics the output form is set to general.
% This means that an equation in general form is derived and
% stored in the FEM structure. This ensures better convergence
% for nonlinear problems.
fem = multiphysics(fem,’outform’,’general’);
fem.xmesh = meshextend(fem);

% Solve a time-dependent problem


% The initial value is taken from the stationary
% solution of the electric potential. The initial value
% for T is obtained by evaluating T in the fem0 structure.
% Since T was defined as T0, this will be the initial value
% for T.
fem.sol = femtime(fem,...
’tlist’,0:5:180,...
’rtol’,0.001,...
’atol’,{’T’ 0.0001 ’V’ ’Inf’},...
’ode’,’fldae’,...
’report’,’on’,...
’init’,fem0)

% Alternatively you can solve a nonlinear problem.


% This is either done using the nonlinear solver
% FEMNLIN, or as in this case the iterative solver with the
% property ’nonlin’ set to ’on’.
fem.sol_2 = femiter(fem,...
’prefun’,’amg’,...
’init’,fem0,...
’nonlin’,’on’,...
’report’,’on’,...
’solcomp’,{’T’});

% Postprocessing
postplot(fem,...
’solnum’,1,...
’isodata’,’T’,...
’isolevels’,20,...
’flowdata’,{’Ex’ ’Ey’ ’Ez’},...
’flowlines’,7,...
’flowcolor’,’red’,...
’u’,fem.sol_2.u)

% Plot lumped resistance as function of time


postcrossplot(fem,0,1,...
’solnum’,1:37,...
’pointtype’,’vertex’,...
’pointdata’,’V0/I’,...
’title’,’Lumped resistance as function of time’,...

1-328 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
’axislabel’,{’time’ ’Resistance’})

Advanced Visualization and High-Resolution Images


To effectively utilize the visualization capabilities within the FEMLAB environment,
you might need to combine the functions of FEMLAB and MATLAB. This is, for
example, the case for producing high-quality print-outs of postprocessing
visualizations. This section shows different techniques for smoothly handling
different kinds of visualizations and saving the result as an image file.

CREATING HIGH-RESOLUTION IMAGES AND PRINTING


Let us use a model from the Model Library to see how to create high-resolution
images of FEMLAB visualizations. Run the programming language version of the
model “Corrosion Protection of a Steel Tank Immersed in Seawater” on page 2-147.
Doing this, you end up with the following visualization

To create a high-resolution TIFF-image of this visualization, you need to enter a few


lines of code for getting the proper settings.

THE PROGRAMMING LANGUAGE | 1-329


Firstly, the number of colors in the plot is not high enough for high-quality printing.
At a closer inspection, you will notice that there are artificial boundaries in the surface
plot, due to only 64 colors being used in the color map.

To increase the color map resolution from 64 colors to 1024, use the trimap
property in the postplot command

figure
postplot(fem,’tridata’,’V’,...
’ellogic’,’abs(x)<1.49 & abs(y)<1.49 & abs(z)<1.49’,...
’ellogictype’,’any’,’camlight’,’on’,...
’tribar’,’on’,’trimaxmin’,’on’,’trimap’,jet(1024));
set(gcf,’renderer’,’zbuffer’)
axis equal

Notice that the artificial boundaries are no longer visible.

For more information on the different properties of postplot, see the entry on
postplot in the Function Reference.

Now, say you would like to create a TIFF-image of size 3000-by-2250 pixels. First
create constants representing the width and height of the image.

aspect_ratio = 4/3
width = 3000
height = aspect_ratio*width

The variable aspect_ratio represents the aspect ratio of the image.

Define a variable scale that determines the font sizes, tick marks, etc. In most cases
the value 1 is appropriate for this variable.

scale = 1

Define the variable imformat that represents the image format used, in this case
TIFF.

imformat = ’tiff’

Define the name of the TIFF file to be create.

fname = ’tank_vis1.tif’

And now create the TIFF-file by entering

res = min(width,height)*0.2*scale;
set(gcf,’PaperUnits’,’inches’);
set(gcf,’PaperPosition’,[0 0 width/res height/res]);
print([’-r’ int2str(res)],[’-d’ imformat],...
[’-f’ num2str(gcf)],fname);

1-330 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
For more information on using the PaperUnits and PaperPosition properties, as
well as the print command, see the MATLAB documentation. For most purposes,
the technique outlined above is sufficient.

If you would like to change the viewing angle of the visualization. Turn on the
cameramenu by entering

cameramenu
axis equal
set(gcf,’renderer’,’zbuffer’)

The axis equal command ensures that the aspect ratio is right, and the set
command is used to set the Z-buffer renderer. The Z-buffer renderer needs to be set
since the print command does not support the OpenGL renderer.

You can now rotate the model freely. You can also rotate a 3D model using the box
rotation function. To do this, press the Rotate 3D button in the figure window. If you
want to use a more exact positioning you can use the campos and camtarget
properties in the postplot function. Create a new plot using the postplot
command again.

figure
postplot(fem,’tridata’,’V’,...
’ellogic’,’abs(x)<1.49 & abs(y)<1.49 & abs(z)<1.49’,...
’ellogictype’,’any’,’camlight’,’on’,...
’campos’,[2 2 2],’camtarget’,[-1 -1 -1],...
’tribar’,’on’,’trimaxmin’,’on’,’trimap’,jet(1024));
set(gcf,’renderer’,’zbuffer’)
axis equal

PLOTTING WITH AN OVERLAID MESH


To view a solution and a mesh simultaneously, use the triedgestyle property. Try
this by overlaying the mesh on a cube.

clear fem
fem.geom = geomcsg({block3});
fem.mesh = meshinit(fem);
fem.equ.c = 1;
fem.equ.f = ’x^2-y^2’;
fem.sol = femlin(fem); % solve Poisson’s equation
figure
postplot(fem,’tridata’,’u’,...
’tribar’,’on’,’trimaxmin’,’on’,’trimap’,jet(1024),...
’triedgestyle’,’bg’);
set(gcf,’renderer’,’zbuffer’)
axis equal

THE PROGRAMMING LANGUAGE | 1-331


INCREASING THE GEOMETR Y VISUALIZATION DETAIL
To create an arbitrarily high-quality visualization of your geometry model you can
use the function meshinit in conjunction with geomplot. You can do this by
explicitly providing geomplot with a mesh. Create a simple geometry by drilling a
hole through a torus.

t = torus3
c = cylinder3(0.2,3,[0.7 0.7 -1.5])
s = t-c % create a solid object named s
geomplot(s)
axis equal
view(30,30)
lighting gouraud
light

The resolution of the geometry surface is dependent of the geometry visualization


mesh. This mesh is automatically created by geomplot as default, and you can obtain
some control over the mesh resolution by using the property detail in geomplot.
For more information, see the help text or Function Reference entry of geomplot.

1-332 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
By providing the mesh yourself, you can fully control the geometry resolution detail.
To create a surface mesh of the solid object, enter

gmesh = meshinit(s,’mlevel’,’face’,’hmax’,0.05)
figure
geomplot(s,’mesh’,gmesh)
axis equal
view(30,30)
lighting gouraud
light

This gives a very dense surface mesh. You can view the mesh by entering

shading faceted

and return to the interpolated visualization by

shading interp

To eliminate the geometry edges, enter

figure
geomplot(s,’mesh’,gmesh,’edgemode’,’off’)
axis equal
view(30,30)
lighting gouraud
light

You can choose between two projection types: perspective projection and
orthographic projection. The orthographic projection type is default. To enable
perspective projection, enter

set(gca,’projection’,’perspective’)

THE PROGRAMMING LANGUAGE | 1-333


This can improve the 3D depth impression of the visualization significantly.

Hints and Suggestions for Using the Programming Language


Use the export facilities of the GUI as much as you can. They provide data structures
with the correct syntax and are good starting points that you can modify to suit your
needs.

You can easily switch between working with geometry objects in the GUI and in the
MATLAB environment using the export/import facilities. For special geometry
requirements, you can write a Geometry M-file. See the Function Reference entry
geomfile for more information.

Working directly with the system matrices and vectors produced by assemble can
sometimes be valuable. See the Function Reference entry assemble for detailed
information. When solving the same equation for different loads or boundary
conditions, it is a good idea to assemble the stiffness matrix only once.

The routines for adaptive mesh generation and solution are powerful but can lead to
dense meshes and thus long computation times. See the Function Reference entry
adaption for detailed information. Setting the Ngen parameter to 1 limits you to a

1-334 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
single refinement step. This step can then be repeated to show the progress of the
refinement. The Maxt parameter helps you stop before the adaptive solver generates
too many elements. Note that adaption requires an analyzed geometry as input.

THE PROGRAMMING LANGUAGE | 1-335


The FEMLAB PD E Language
Systems of partial differential equations (PDEs) constitute the mathematical
foundation of FEMLAB. The possibility of using a system of equations is crucial for
accurately setting up a multiphysics models. The way a PDE system is defined and
translated into data structures and variables can be referred to as the FEMLAB PDE
Language. It is crucial to master this language to be able to utilize the full capabilities
of FEMLAB. This section gives an overview of PDE models as they appear in
FEMLAB. The different PDE formulations available are presented. The way in
which these formulations translate into FEMLAB variables is also explained, as is the
use of variables in general.

Overview of PDE Models


The PDEs in FEMLAB can be given in three different forms: the coefficient form,
the general form, and the weak form. Which form to be used in a particular
application depends on the general properties of the PDE that is modeled. The
coefficient form is most suited for linear or almost linear PDEs, and the general form
is most suited for nonlinear PDEs. The weak form is, despite of its name, the most
powerful formulation. This section gives an overview of PDE models in FEMLAB.
Later sections explain, in further detail, how these models are used in FEMLAB and
which FEMLAB variables correspond to which terms in the different equations.

THE COEFFICIENT FORM

The Scalar Coefficient Form Equation


Assume you have a single dependent variable u. This is an unknown function on the
domain that is to be determined from the PDE problem. A PDE problem in
coefficient form reads:
 ∂u
 d a ∂ t + ∇ ⋅ ( – c ∇u – αu + γ ) + β ⋅ ∇u + au = f in Ω

 T
 n ⋅ ( c ∇u + αu – γ ) + qu = g – h µ on ∂Ω

 hu = r on ∂Ω

The domain of interest is usually called Ω, consisting of bounded subdomains and


boundaries. The symbol Ω represents the union of all subdomains, and ∂Ω denotes
the domain boundary. The outward unit normal vector on ∂Ω is denoted by n. The

1-336 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
first equation is the PDE, and it is to be satisfied inside Ω. The second and third
equations are the boundary conditions, and they will be satisfied on the boundary of
Ω . The second equation is referred to as a generalized Neumann boundary
condition, and the third equation is referred to as a Dirichlet boundary condition.

The generalized Neumann boundary condition is also referred to as a mixed


boundary condition, or a Robin boundary condition.

The symbol ∇ is the vector differential operator, defined as

∂ ∂ 
∇=  , …,
 ∂ x1 ∂ x n

where the space coordinates are denoted x1, ..., xn, where n represents the number
of space dimensions.

When the coefficients depend only on the space coordinates (or are constants), the
PDE is linear. If the coefficients depend on u, or the components of ∇u, the PDE is
nonlinear. As mentioned earlier, the coefficient form is used to describe linear or
almost linear problems. For nonlinear problems, all coefficients can depend on u and
the derivatives of u. However, extra care need to be taken when the coefficients are
nonlinear: Always use the general or weak solution form when having nonlinear
coefficients. This ensures that the nonlinear solver gets all information on the
nonlinear properties of the PDEs, that is needed for convergence.

All the coefficients in the above equation are scalars except α, β, and γ, which are
vectors with n components. The coefficient c can alternatively be an n-by-n matrix,
to model anisotropic materials. This is explained later, in the section “Variables for
PDEs in Coefficient Form” on page 1-356. The variable da is a matrix for
time-dependent systems, called the mass matrix (or mass coefficient for scalar
equations). See “Time-Dependent Equations” on page 1-343 for more information
on time-dependent problems.

The factor hT in the Neumann boundary condition is the transpose of h. Since h is


scalar here, hT=h. The function µ in the boundary condition is an additional
dependent variable called the Lagrange multiplier. Often, the boundary conditions
can be reformulated without Lagrange multipliers, as is done in most of the
application modes. For a full understanding of Lagrange multipliers in PDEs, see the
explanation in the section “The Partial Differential Equations” on page 3-25 in the
Reference Guide. In structural mechanics problems, the Lagrange multiplier equals
the reaction forces on the boundary. Similar explanations can be given in other areas
of physics.

THE FEMLAB PDE LANGUAGE | 1-337


The rest of this section handles stationary problems where ∂u/∂t=0. That is,
problems where the transient effects have vanished.

In the GUI, the following dialog box is opened in subdomain mode for a coefficient
form, scalar, and stationary 2D problem.

The default values in the fields correspond to a Poisson problem, but you can easily
fill out the coefficients you want. They can be different for different subdomains. By
selecting one or several subdomains at a time in the Subdomain selection list box, you
can impose different equation coefficients on different subdomains.

The boundary conditions are specified in the following dialog box that is opened in
boundary mode.

1-338 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The default values correspond to homogeneous Dirichlet boundary conditions, but
you can easily change this. By selecting one or several boundaries at a time in the
Boundary selection list box, you can impose different boundary conditions on
different segments of the boundary.

Note that c, α, and γ are given in the Subdomain Settings dialog box.

The Coefficient Form Equation System


Assume you have two independent variables u1 and u2. Then, the stationary PDE
problem in coefficient form is the following system of equations:


 – ∇ ⋅ ( c 11 ∇u1 + c 12 ∇u2 + α 11 u 1 + α 12 u 2 – γ 1 )

 + β 11 ∇u1 + β 12 ∇u 2 + a 11 u 1 + a 12 u2 = f 1 in Ω

 – ∇ ⋅ ( c 21 ∇u1 + c 22 ∇u2 + α 21 u 1 + α 22 u 2 – γ 2 )

 + β 21 ∇u1 + β 22 ∇u 2 + a 21 u 1 + a 22 u2 = f 2 in Ω

The Dirichlet boundary condition is:



 h 11 u1 + h12 u 2 = r 1 on ∂Ω

 h 21 u1 + h22 u 2 = r 2 on ∂Ω

and the generalized Neumann boundary condition is:


 n ⋅ ( c 11 ∇u 1 + c 12 ∇u 2 + α 11 u 1 + α 12 u 2 – γ 1 )

 + q 11 u 1 + q 12 u 2 = g 1 – h11 µ 1 – h21 µ 2 on ∂Ω

 n ⋅ ( c 21 ∇u 1 + c 22 ∇u 2 + α 21 u 1 + α 22 u 2 – γ 2 )

 + q 21 u 1 + q 22 u 2 = g 2 – h12 µ 1 – h22 µ 2 on ∂Ω

THE FEMLAB PDE LANGUAGE | 1-339


In the GUI, the following dialog box is opened in subdomain mode for a coefficient
form, two variables, and stationary 2D problem.

For the boundary conditions, the following dialog box is opened in boundary mode.

THE GENERAL FORM

The Scalar General Form Equation


The general form is suited for nonlinear PDEs. Assume you have a single independent
variable u. Then a stationary problem in general form reads

 ∇⋅Γ= F in Ω
 T
 – n ⋅ Γ = G +  ∂R µ on ∂ Ω
  ∂u

 0=R on ∂Ω

1-340 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The first equation is the PDE. The second and third equations are the Neumann and
Dirichlet boundary conditions, respectively. For information on the time-dependent
general form equation, see “Time-Dependent Equations” on page 1-343.

The terms Γ, F, G, and R are usually called coefficients. They can be functions of the
space coordinates and the solution u. The coefficients Γ and F can also depend on the
first space derivatives of u. Note that the coefficients F, G, and R are scalar, while Γ
is a vector usually called the flux vector. The T in the Neumann boundary condition
denotes the transpose, which in this single variable case is unnecessary. The variable
µ is the Lagrange multiplier.

In the GUI, the following dialog box is opened in subdomain mode for a general
form, scalar, and stationary 2D problem.

For the boundary conditions, the following dialog box is opened in boundary mode.

THE FEMLAB PDE LANGUAGE | 1-341


The General Form Equation System
Assume you have two independent variables u1 and u2. Then, the stationary PDE
problem in general form is the following system of equations:


 ∇ ⋅ Γ 1 = F1 in Ω

 ∇ ⋅ Γ 2 = F2 in Ω

with the generalized Neumann boundary conditions



 ∂R 1 ∂R 2
 –n ⋅ Γ1 = G1 + µ1 + µ on ∂Ω
 ∂ u1 ∂ u1 2

 ∂R 1 ∂R 2
 –n ⋅ Γ2 = G2 + µ1 + µ on ∂Ω
 ∂ u 2 ∂ u2 2

and the Dirichlet boundary conditions



 0 = R1 on ∂Ω

 0 = R2 on ∂Ω

In the GUI, the following dialog box is opened in subdomain mode for a general
form, two variables, and stationary 2D problem.

1-342 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
For the boundary conditions, the following dialog box is opened in boundary mode.

TIME-DEPENDENT EQUATIONS
The equation for a time-dependent problem is derived from the stationary equation
by adding a term containing first time derivatives to the left-hand side. The time
derivatives have to appear linearly. Also, the Dirichlet conditions have to be linear.
Thus, a time-dependent problem in coefficient form reads
 ∂u
 d a ∂ t + ∇ ⋅ ( – c ∇u – αu + γ ) + β ⋅ ∇u + au = f in Ω

 T
 n ⋅ ( c ∇u + αu – γ ) + qu = g – h µ on ∂Ω

 hu = r on ∂Ω

If u is a vector of dependent variables, then the mass coefficient da can be a matrix


(mass matrix). Of course, the coefficients can depend on time. The name mass matrix
or mass coefficient stems from the fact that in many physics problems the mass
density is contained in da.

If you have made a stationary model, any expressions entered in the edit field for the
da coefficient will be ignored. The da coefficient can be activated, however, and the
model converted into a time-dependent model, by changing the solver type to Time
dependent, in the Solver Parameters dialog box. You can also change the solver type
on the Multiphysics page of the Model Navigator. You reach this page by selecting Add/
Edit Modes from the Multiphysics menu.

THE FEMLAB PDE LANGUAGE | 1-343


The time-dependent problem in general form is

 ∂u
 da + ∇ ⋅ Γ = F in Ω
 ∂t
 T
 – n ⋅ Γ = G +  ∂R µ on ∂ Ω
  ∂u

 0=R on ∂Ω

Time-Dependent Systems
For time-dependent systems, the da coefficient is a matrix. Say you have the
following system of equations

∂u 1 ∂u 2
d 11 + d12 + ∇ ⋅ ( – c 11 ∇u1 – c 12 ∇u2 ) + a11 u1 + a 12 u 2 = f 1
∂t ∂t
∂u 1 ∂u 2
d 21 + d22 + ∇ ⋅ ( – c 21 ∇u1 – c 22 ∇u2 ) + a21 u1 + a 22 u 2 = f 2
∂t ∂t

This system corresponds to the coefficient matrices

d 11 d 12
da =
d 21 d 22

c 11 c 12
c =
c 21 c 22

a 11 a 12
a =
a 21 a 22

Many interesting problems have a singular da matrix, that is det(da)=0. Such


problems are called differential-algebraic equation (DAE) systems. These are difficult
to solve using conventional ODE solvers. However, FEMLAB provides a number of
different solvers for DAE systems: fldaspk, fldae, and the MATLAB solver
ode15s.

The models “Forced and Free Convection Heat Transfer” on page 1-26 and
“Thermo-Electric Heating in a Bus Bar” on page 1-109 are both DAE systems. For
more information on coefficient matrices see “PDEs on coefficient form in 2
variables” on page 1-360.

1-344 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
WAVE E QUATIO NS
A time-dependent scalar equation on the coefficient or general form has a first-order
time derivative term. It is common, however, to have second-order time derivative
terms, for instance
2
∂ u
da 2
+ ∇ ⋅ ( – c ∇u – αu + γ ) + β ⋅ ∇u + au = f
∂t

This equation, describing a wave phenomenon, can be reduced to the case with
first-order time derivatives by introducing a new variable v = ∂u ⁄ ∂t . We get the
system

 ∂u = v
 ∂t

 ∂v
 d a + ∇ ⋅ ( – c ∇u – αu + γ ) + β ⋅ ∇u + au = f
 ∂t

This system is created automatically when using a Wave extension application


submode. When selecting a coefficient form or general form application mode, you
can choose between a Time dependent submode or a Time dep., wave extension
submode. You can also change the current submode by selecting from the submode
list on the Multiphysics page in the Model Navigator, opened from the Multiphysics
menu by selecting Add/Edit Modes.

EIGENVALUE EQUATIONS
FEMLAB handles eigenvalue problems on coefficient form
– ∇ ⋅ ( c ∇u + αu ) + β∇u + au = λd a u

where λ is an unknown eigenvalue.

The general form is handled by linearizing around an equilibrium point. For more
information on eigenvalue formulations, see the section“Eigenvalue Problems” on
page 3-41 in the Reference Guide.

THE WEAK FORM


The term weak form comes from a certain equation involving integrals that can be
derived from a PDE. The solution to a partial differential equation could be called a
strong solution, but is usually simply referred to as a solution. In FEMLAB, a
solution computed using the coefficient, general, or weak form, is always a weak

THE FEMLAB PDE LANGUAGE | 1-345


solution. In coefficient and general form, you enter PDE coefficients. FEMLAB then
derives the corresponding weak equation, called the weak form of the PDE. This
weak equation is then discretized by the finite element method, and solved.

The weak solution form gives you direct access to the terms of this weak equation.
This gives you maximum freedom in defining finite element problems.

A PDE problem on coefficient form is transferred into the corresponding weak form,
as follows.

The PDE problem is

 ∇ ⋅ ( – c ∇u – αu + γ ) + β ⋅ ∇u + au = f in Ω
 T
 n ⋅ ( c ∇u + αu – γ ) + qu = g – h µ on ∂Ω

 hu = r on ∂Ω

Now, let v be an arbitrary function on Ω, called the test function. (The function v
should belong to a suitably chosen well-behaved class of functions.) Multiplying the
PDE with this function, rearranging terms, and integrating, we get

∫ v∇ ⋅ ( – c ∇u – αu + γ ) dA = ∫ v ( f – β ⋅ ∇u – au ) dA
Ω Ω

where dA is the area element, in 2D (length element in 1D and volume element in


3D). Now we use integration by parts (in other words, Gauss’ law or the divergence
theorem) to get

∫ v ( – c∇u – αu + γ ) ⋅ n ds – ∫ ∇v ⋅ ( – c∇u – αu + γ ) dA = ∫ v ( f – β ⋅ ∇u – au ) dA
∂Ω Ω Ω

where ds is the length element. Now, use the Neumann boundary condition
T
n ⋅ ( c ∇u + αu – γ ) + qu = g – h µ

This gives the following equation:

∫ ( ∇v ⋅ ( – c ∇u – αu + γ ) + v ( f – β ⋅ ∇u – au ) ) dA + ∫ v ( –qu + g – h
T
0 = µ ) ds
Ω ∂Ω

Together with the Dirichlet condition, this is the weak form of the coefficient form
PDE problem.

1-346 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Recall the condition that this weak equation should be valid for any test function v
in the given class of functions. This is such a strong condition that the valid solutions
of the weak form equation are more or less the same as that of the original PDE. One
difference is that the weak form equation allows for the coefficients (describing
material properties) to be discontinuous, a fact that is very important in many
applications of the finite element method.

The derivation from coefficient form made earlier illustrates the relation between a
PDE and its weak form. The weak form in FEMLAB, however, is not restricted to
weak equations corresponding to PDEs on coefficient form. That would give no new
functionality.

By using the weak form, say in 2D, you are able to enter weak terms on the form

( 2t ) ( 1t ) ( 0t ) (2) (1) (0)


∫W dA + ∫W ds + ∑W = ∫W dA + ∫W ds + ∑W +…
Ω ∂Ω P Ω ∂Ω P

where Ω, ∂Ω, and P symbolize the geometric domain, the boundary, and points,
respectively. Sometimes the symbol ∂2Ω is used for points, instead of P. The
integrands denoted by W have superscripts where t indicates that the expression
includes time derivatives. The integrands W(0), W(1), and W(2) can be expressions in
u,∇u, v, and ∇v. The time derivative integrands W(0t), W(1t), and W(2t) can
additionally include ∂u/∂t and ∇∂u/∂t.

In the GUI, weak terms are added on the Weak page in the Point Settings, Edge
Settings, Boundary Settings, and Subdomain Settings dialog boxes. For the coefficient
form application mode, the following dialog box is available for subdomains.

THE FEMLAB PDE LANGUAGE | 1-347


You can read more on the weak form, for example a derivation of the weak form from
the general form, in the section “Stationary Problems in Weak Form” on page 3-33
in the Reference Guide. The variable names available in weak form, as well as how to
use the weak form to include additional time derivative PDE terms, are described
in“Weak Form Meta Variables” on page 1-372.

Interpreting PDE Coefficients


The FEMLAB PDE formulations are capable of modeling a variety of problems,
though in the documentation coefficient names in the spirit of continuum mechanics
and mass transfer are used. For the coefficient form:

• da is the mass coefficient


• c is the diffusion coefficient
• α is the conservative flux convection coefficient
• β is the convection coefficient
• a is the absorption coefficient
• γ is the conservative flux source term
• f is the source term.
Convection

Convection
Source
Mass Diffusion Source

∂u
da – ∇ ⋅ ( c ∇u + αu – γ ) + β ⋅ ∇u + au = f
∂t

Conservative Flux Absorption

It is important to realize that there are many interesting PDE problems that cannot
easily be given this interpretation. For instance, a time-harmonic PDE such as
Helmholtz’s equation represents a time-dependent phenomenon that has been
transformed into the frequency domain.

For the Neumann boundary condition of the coefficient form

T
n ⋅ ( c ∇u + αu – γ ) + qu = g – h µ

1-348 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
• q is the boundary absorption coefficient
• g is the boundary source term

Classical PDEs
Many classical PDEs can be given as instances of the coefficient form in FEMLAB.
All the classical PDEs below have their own application modes. You find them under
the Classical PDEs branch in the Model Navigator. The table below shows how the
classical PDEs can be written using both the compact notation of vector analysis, that
is, the one used in this documentation, and an expanded mathematical notation.

The following conventions are used here:

• ∆ stands for the Laplace operator


2 2
∂ ∂
2
+…+ 2
∂x1 ∂ xn

• by ∇ ⋅ ( c∇u ) we mean:
∂  ∂u  ∂  ∂u 
c +…+ c
∂ x 1  ∂ x 1 ∂ x n  ∂ x n

• by β ⋅ ∇u we mean :

∂u ∂u
β1 + … + βn
∂x1 ∂ xn

where the β n :s are the components of β .


TABLE 1-1: CLASSICAL PDES IN COMPACT AND STANDARD NOTATION

EQUATION COMPACT NOTATION STANDARD NOTATION (2D)

Laplace’s
equation ∂ ∂u ∂ ∂u
– ∇ ⋅ ( ∇u ) = 0 – – = 0
∂ x∂ x ∂ y∂y

Poisson’s
equation
– ∇ ⋅ ( c ∇u ) = f ∂  ∂u ∂  ∂u
– c – c = f
∂ x  ∂ x ∂ y  ∂ y

Helmholtz’s
equation ∂  ∂u ∂  ∂u
– ∇ ⋅ ( c ∇u ) + au = f – c – c + au = f
∂ x  ∂ x ∂ y  ∂ y

THE FEMLAB PDE LANGUAGE | 1-349


TABLE 1-1: CLASSICAL PDES IN COMPACT AND STANDARD NOTATION

EQUATION COMPACT NOTATION STANDARD NOTATION (2D)

Heat
equation
∂u ∂u ∂  ∂u ∂  ∂u
da – ∇ ⋅ ( c ∇u ) = f da – c – c = f
∂t ∂ t ∂ x  ∂ x ∂ y  ∂ y 

Wave
equation 2 2
∂ u ∂ u ∂  ∂u ∂  ∂u
da 2 – ∇ ⋅ ( c ∇u ) = f da – c – c = f
∂t ∂t
2 ∂ x  ∂ x ∂ y  ∂ y

Schrödinger
equation
– ∇ ⋅ ( c ∇u ) + au = λu ∂  ∂u ∂  ∂u
– c – c + au = λu
∂ x  ∂ x ∂ y  ∂ y

Convection-
reaction ∂u
equation da – ∇ ⋅ ( c ∇u ) + β ⋅ ∇u = f ∂u ∂  ∂u ∂  ∂u
∂t da – c – c +
∂ t ∂ x  ∂ x ∂ y  ∂ y
∂u ∂u
βx + βy = f
∂x ∂y

Expressions in Dialog Boxes


In most of the edit fields that appear in dialog boxes within the graphical user
interface, you can enter MATLAB expressions, for example, in the Boundary Settings
and Subdomain Settings dialog boxes.

When entering parameter values as an expressionfor example as a function of the


space coordinates x, y, and z, also known as independent variablesthe string can be
any valid MATLAB expression. This means you have not only access to elementary
functions such as sin and cos, but also more advanced functions such as besseli,
gamma, and erf can be used. You can also write your own MATLAB functions and
use these as part of expressions in edit fields. As an example, see the function
flafun(x,y), used in the Model Library model “A Rock Fracture Flow Model” on
page 2-238.

You can also use dependent variables as part of an expression. In the model
“Thermo-Electric Heating in a Bus Bar with Multiphysics” on page 1-138, there is
an expression variable for the electric conductivity

1-350 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
1/(r0*(1+alpha*(T-T0)))

appearing in the equation for conductive media DC. In this case, the dependent
variable for temperature, T, which stems from another equation (the heat equation),
is used in the equation for conductive media DC, making this a nonlinear model.

Variable Classification and Geometric Scope


FEMLAB provides a considerable set of variables that can be utilized in expressions
when specifying a PDE model, as well as for visualizing and postprocessing the
solution. The variables available on subdomains are different from those available on
boundaries. A number of variables are common to all application modes in
FEMLAB. The space coordinate variables x, y, and z are examples of such variables.
In addition, each application mode has its own set of variables, representing relevant
quantities for the physics modeled. This section describes the available variables, their
naming and meaning. More information on variables can also be found in the section
“Variables” on page 3-66 in the Reference Guide.

The variables that can be used in expressions are divided into the following categories

• Constants
• Geometric variables
• Field variables
• Special variables

The constants and the geometric variables are always available. This is not the case for
the field variables and the special variables. They appear differently depending on the
solution form used: coefficient, general, or weak. An application mode can only have
one solution form at a time. When selecting an application mode from the Model
Navigator, a suitable solution form is defaulted. The current solution form can be
changed on the General page in the Solver Parameters dialog box, as well as on the
Multiphysics page in the Model Navigator.

The choice of application mode and the dimension of the domain studied also affects
the set of field variables and special variables available. The term domain is used to
denote subdomains, boundaries, edges, or points (vertices). Later in this section, the
different variables available in 1 and 2 variable coefficient form and general form is
described.

Because equations can be active in different domains, this also affects the set of
variables available. Equation variables corresponding to certain equation terms are

THE FEMLAB PDE LANGUAGE | 1-351


available only in those domains where the equation is active. Equations can be
activated or deactivated in subdomains by selecting or clearing the Active in this
domain check box in the Subdomain Settings dialog box. Equation variables defined
on domains of lower dimension than the subdomain will inherit the property of
being active if the adjacent subdomain is active.

Expression variables are available only on a domain or group of domains that they are
defined on.

Constants
Constants are defined in the Add/Edit Constants dialog box found on the Options
menu. Constants are often needed to specify modeling properties that have global
influence on a model; angular frequency or material density (if it can be considered
constant) are typical examples of such parameters. Using constants is the most direct
way of introducing parameters for parametric studies in your modeling: after solving
a FEM problem you can easily edit the values of the constants, in the Add/Edit
Constants dialog box, and solve again.

If you unintentionally define a constant with a name that conflicts with some other
variable name, you will get a warning message and be asked for if you wish to
continue using the conflicting name or not.

Geometric Variables
A number of variables are available regardless of the application mode used. Among
these are the variables that are related to the geometric properties. The table below
summarizes the most important of these variables. For a complete listing of all
available geometric variables, see “Geometric Variables” on page 3-56 in the
Reference Guide.

DOMAIN \ SPACE DIM 1D 2D 3D ND

POINT

EDGE s1,t1x,t1y,
t1z

1-352 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
DOMAIN \ SPACE DIM 1D 2D 3D ND

BOUNDARY dnx,nx, dnx,dny,nx, dnx,dny,dnz,


unx ny,s,tx,ty, nx,ny,nz,s1,
unx,uny s2,t1x,t1y,
t1z,t2x,t2y,
t2z,unx,uny,
unz
SUBDOMAIN h
ALL x x,y x,y,z dom

In the table, the space dimension refers to the number of independent variables. As
seen from the table, most geometric variables of interest are defined on boundaries.

The explanations following below mainly use terminology for three space
dimensions, but are analogous for lower dimensions, with a slight change of
terminology.

SPACE COORDINATE VARIABLES


The space coordinate variables x, y, and z are available for all domain types and
represent the Cartesian coordinates with the same names. You can change these
names in the Model Navigator in the beginning of a modeling session. By pressing the
More>> button, you get access to edit fields for changing the variable names.

PA R AM E TE R IZ AT I O N VA R I A BL E S
The surface boundary parameterization variables s1 and s2 are available in all
boundary edit fields. They can be used to define distributed loads and constraints but
might be hard to use since in many cases the relation between x, y, and z and s1 and
s2 is nonlinear. It can be straightforward to use s1 and s2 in cases where a face is
equivalent to an untrimmed patch, that is a face that has no parts that are cut away,
see “Geometry Modeling” on page 3-10. More often it is convenient to use
expressions with x, y, and z for specifying distributed boundary conditions.

The curve parameterization variable s1 (also s in 2D) is available in edit fields for
edges or boundaries in 2D. The curve parameter s1 is in 2D equivalent to the Bézier
curve parameter, as described in “Geometry Modeling” on page 3-10. In 3D, the
curve parameter is approximately equivalent to arc-length (this is not the case in 2D).

THE FEMLAB PDE LANGUAGE | 1-353


TAN G E N T A N D N O R M A L VA R I A BL E S
In 3D, the tangent variables t1x, t1y, t1z, t2x, t2y, and t2z are defined on surfaces
according to
∂x ( s 1, s 2 ) ∂y ( s 1, s 2 ) ∂z ( s 1, s 2 )
( t ix, t iy, t iz ) = k i  -------------------------, -------------------------, ------------------------ , i = 1, 2
 ∂s i ∂s i ∂s i 

These most often define two orthogonal vectors on a surface, but the orthogonality
can be ruined by scaling geometry objects. These are normalized vectors; ki is a
normalizing parameter in the expression above.

For edges, the tangent variables t1x, t1y, t1z, (t1x, t1y or tx, ty in 2D) simply
define the curve tangent vector. This vector is normalized.

The boundary normal component variables are named nx, ny, and nz, (just nx and
ny in 2D), and define a normal vector that is pointing outwards relative subdomains.
This vector is normalized.

To get control of the direction of normal component on inner boundaries, the


variables, dnx, dny, dnz, unx, uny, and unz are available. The prefixes u and d mean
up and down with respect to the geometric parameterization of the boundary in the
variables s1 and s2. The geometric normal direction is defined as

n geom = ( t 1x, t 1y, t 1z ) × ( t 2x, t 2y, t 2z )

The down-normal defined by dnx, dny, and dnz, is equivalent to the geometric
normal direction. The geometric normal is pointing into the up-side of the geometry.
The up-normal defined by unx, uny, and unz, is pointing out from the up-side of the
geometry, for example, dnx=-unx, dny=-uny, and dnz=-dnz.

In 2D, the up-side is defined as the left side with respect to the parameterization of
the curve in the variable s1, as described above. The direction of the parameterization
is visualized, in the GUI, by arrows in boundary mode.

Note that you can visualize any vector variables. You can do this by using arrow plots
available from the Arrow page in the Plot Parameters dialog box.

MISCELLANEOUS VARIABLES
The variable h, available in subdomains only, represents the maximum edge size for
elements, that is the maximum edge size for triangles in 2D and the maximum edge
size for tetrahedrons in 3D.

1-354 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The variable dom is the domain number. That is, the subdomain number, the
boundary number, the edge number, or the point (vertex) number. This variable only
takes integer values. For subdomains, the variable sd has the same meaning.

Field Variables
The field variables are the dependent variables together with variables that are derived
from these.

S U BD I VI S I O N O F F I E L D VA R I A BL E S
The field variables are divided into the following sub-categories

• Shape function variables


• Boundary coupled shape variables
• Equation variables
• Boundary coupled equation variables
• Application mode variables
• Expression variables
• Coupling variables.

The shape function variables and the boundary coupled shape variables are related to
the shape functions of the finite elements. A shape function is the polynomial
function used in a finite element for approximating the solution. The shape function
variables are related to the degrees of freedom defined by a finite element. Typically,
the shape function variables are a base name, along with its first and second
derivatives. For more information on shape functions and shape function variables,
see “Variables” on page 3-66 in the Reference Guide.

The equation variables and the boundary coupled equation variables are accessible in
coefficient and general form but not in weak form. These variables are shorthands for
certain terms in the PDE and boundary conditions for the coefficient form or general
form. Normally they should only be used in postprocessing. For more information
on equation variables, see “Variables” on page 3-66 in the Reference Guide, as well as
later in this section.

The application mode variables are application mode specific and consist of physically
meaningful combinations of material constants and other variables. The application
mode variables are pre-defined for each application mode.

THE FEMLAB PDE LANGUAGE | 1-355


An expression variable is a user-defined shorthand for an expression involving other
variables. An expression variable can be defined differently on different domains
(subdomains, boundaries, edges, and points). Expression variables can be used for
defining, for example, nonlinear material properties.

The coupling variables are user-defined variables for non-local couplings. For more
information on coupling variables, see “Extended Multiphysics” on page 1-276.

Variables for PDEs in Coefficient Form


To understand the naming of the variables in coefficient form, consider the
application mode named 1 variable coefficient form PDE. This application mode you
get by selecting: PDE modes, Coefficient, Time dependent, in the Model Navigator.

The single dependent variable is called u, and the equation solved is

∂u
da – ∇ ⋅ ( c ∇u + αu – γ ) + β ⋅ ∇u + au = f
∂t

In multiple component application modes, the solution components will be named


u1, u2, u3, etc.

There are two available boundary conditions: the Dirichlet condition and generalized
Neumann condition. If you choose Dirichlet, you get the boundary condition

hu = r, n ⋅ ( c ∇u + αu – γ ) + qu = g – hµ

If you choose Neumann, you get the boundary condition

n ⋅ ( c ∇u + αu – γ ) + qu = g

Apart from the conventional boundary conditions, additional constraints can also be
used at points (2D and 3D), along edges (3D), and also on subdomains.

The table below summarizes the most important variables that are available as default
for the 1 variable coefficient form PDE application mode.

DOMAIN \ SPACE DIM 1D 2D 3D

POINT u u
EDGE u

1-356 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
DOMAIN \ SPACE DIM 1D 2D 3D

BOUNDARY alux,au,beu, alux,aluy,au, alux,aluy,aluz,


cux,f,g,gax, beu,cux,cuy, au,beu,cux,cuy,
nalu,ncu, f,g,gax,gay, cuz,f,g,gax,gay,
nga,qu,u,ux nalu,ncu,nga, gaz,nalu,ncu,
qu,u,ux,uy nga,qu,u,ux,uy,
uz
SUBDOMAIN abscu1x,absux, abscu1x,absux, abscu1x,absux,
alux,au,beu, alux,aluy,au, alux,aluy,aluz,
cux,dau,f, beu,cux,cuy, au,beu,cux,cuy,
gax,u,ux,uxx dau,f,gax,gay, cuz,dau,f,gax,
u,ux,uy,uxx, gay,gaz,u,ux,uy,
uxy,uyx,uyy uz,uxx,uxy,uxz,
uyx,uyy,uyz,
uzx,uzy,uzz

The explanations that follow mainly use terminology for three space coordinates, but
are analogous for lower dimensions, with a slight change of terminology.

The table below shows the division into categories, and also displays the
corresponding variables as they appear in equations. In the table, the categories shape
function variables and boundary coupled shape variables are collected under the same
title: shape function variables. In the same way, equation variables and boundary
coupled equation variables are presented as equation variables.

EQUATION STYLE VARIABLE NAME EQUATION SHAPE APPLICATION


VARIABLE FUNCTION MODE
VARIABLE VARIABLE

c ∇u abscu1x ♦
∇u absux ♦

αu = ( α x u, α y u, α z u ) alux,aluy,
aluz

au au ♦


∂u ∂u ∂u
β ⋅ ∇u = β 1 ------ + β 2 ------ + β 3 ------ beu
∂x ∂y ∂z

THE FEMLAB PDE LANGUAGE | 1-357


EQUATION STYLE VARIABLE NAME EQUATION SHAPE APPLICATION
VARIABLE FUNCTION MODE
VARIABLE VARIABLE


∂u ∂u ∂u
c∇u =  c ------, c ------, c ------ cux,cuy,cuz
∂x ∂y ∂z

dau dau ♦
f f ♦
g g ♦
γ = ( γ x , γ y, γ z ) gax,gay,gaz ♦
n ⋅ αu nalu ♦
n ⋅ c∇u ncu ♦
n⋅γ nga ♦
qu qu ♦
u u ♦

∂u ∂u ∂u
∇u =  ------, ------, ------ ux,uy,uz
 ∂x ∂y ∂z 


2 2
∂ u ∂ u uxx,uxy,uxz,
--------2-, ------------, …
∂x ∂x∂y
uyx,uyy,uyz,
uzx,uzy,uzz

Variables for the Physics Application Modes


In the table, the shape function variable names contain u (the letter u in italics). For
the physics application modes, these variables are accessible, but with the application
mode’s dependent variable instead of u. One example is for heat transfer, where the
dependent variable is T, for temperature.

S H A PE F U N C T I O N VA R I A BL E S
The variable u is the main solution variable, the quantity solved for. All other variables
are derived from this variable in combination with the PDE and boundary
coefficients.

The variables ux and uy are components of the gradient ∇u , that is, the first order
derivative components.

1-358 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The variables uxx,uxy, and uyy are the second order derivative components. These
are only meaningful if the degree of the polynomial shape function used in an
element is high enough. For elements with second degree polynomial shape
functions (also called second order elements), the polynomial degree of the second
order derivatives are zero, that is, the second derivatives are constant in each element.
For element orders lower than two, the second derivatives will evaluate to zero,
regardless of the values of the second order derivatives of the true solution.

E Q U AT IO N VA R I ABL E S
Using terminology in the spirit of continuum mechanics and mass transfer, the
variables alux, aluy, and aluz are the components of the conservative convective
flux, au is the absorption term, beu is the convection term, cux, cuy, and cuz are the
components of the diffusive flux, dau is the mass coefficient multiplied with the
solution, f is the source term, g is the boundary source term, gax, gay, and gaz are
the components of the conservative flux source, nalu is the normal component,
available on boundaries, of the conservative convective flux, ncu is the normal
component, available on boundaries, of the diffusive flux, nga is the normal
component of the conservative flux source, and qu is the boundary absorption term.

Anisotropic Materials
In the table above, it is assumed that the diffusion coefficient c is a scalar, defining
isotropic diffusion. It is also possible to define anisotropic diffusion by letting the
diffusion coefficient be a matrix. In the general case, in 3D, the diffusion coefficient
is a 3-by-3 matrix

c 11 c 12 c 13
c = c 21 c 22 c 23
c 31 c 32 c 33

The term c∇u is then computed as

∂u ∂u ∂u ∂u
------ c 11 ------ + c 12 ------ + c 13 ------
c 11 c 12 c 13 ∂x ∂x ∂y ∂z
c∇u = c 21 c 22 c 23 ∂-----
u =
-
∂u ∂u ∂u
c 21 ------ + c 22 ------ + c 23 ------
∂y ∂x ∂y ∂z
c 31 c 32 c 33 ∂u ∂u ∂u ∂u
------ c 31 ------ + c 32 ------ + c 33 ------
∂z ∂x ∂y ∂z

THE FEMLAB PDE LANGUAGE | 1-359


and the three components are still called cux, cuy, and cuz. Note that the case of a
scalar diffusion coefficient c is equivalent to that of a diagonal matrix with
c11=c22=c33=c, and all other entries set to zero.

In the GUI, you can create a diffusion matrix in the edit field for the c coefficient by
typing the components of the matrix as a space separated vector, in column order:
c11 c21 c31 c12 c22 c32 c13 c23 c33, for the case of 3 independent variables.
As a short cut, diagonal matrices can be entered by just typing the diagonal terms:
c11 c22 c33. This corresponds to an anisotropic material with the principal axes
aligned with the coordinate axes. As another short cut, the upper triangular part of a
symmetric matrix can be entered by typing c11 c12 c22 c13 c23 c33; note the
ordering of the matrix elements.

APPLICATION MODE VARIABLES


The variable abscu1x is the norm, or the magnitude, of the diffusive flux.

The variable absux is the norm, or the magnitude, of the solution gradient.

PDES ON COEFFICIENT FORM IN 2 VARIABLES


To understand the naming of variables for multiple component problems, consider
the application mode named 2 variable coefficient form PDE. You can view this
application mode by selecting: PDE modes, Coefficient, Time dependent, in the Model
Navigator, entering 2 in the edit field No. of dependent variables.

The explanations made below are for two space coordinates, that is,
∂ ∂
∇ =  -----, -----
∂x ∂y

This is for making the expressions smaller and clearer. The generalization to three
space coordinates is straightforward.

S H A PE F U N C T I O N VA R I A BL E S
The variables u1 and u2 are the main solution variables, the quantities solved for. All
other variables are derived from these variables in combination with the PDE and
boundary coefficients.

The variables u1x and u1y are the components of the gradient ∇u 1, and the variables
u2x and u2y are components of the gradient ∇u 2

The variables u1xx, u1xy, u1yx, u1yy, u2xx, u2xy, u2yx, and u2yy are the second
order derivative components.

1-360 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
E Q U AT IO N VA R I ABL E S

The PDE Terms


The dependent variables are called u1 and u2, and the equation system solved is

∂u
da – ∇ ⋅ ( c ∇u + αu – γ ) + β ⋅ ∇u + au = f
∂t

where u=(u1,u2). The coefficients and equation terms are now generalizations
(vectors and matrices) of the corresponding scalars for the 1 variable coefficient form
PDE described earlier.

The mass term is defined as

∂u 1 ∂u 1 ∂u 2
d a11 + da12
∂u d a11 da12 ∂ t ∂ t ∂t
da = =
∂t d a21 da22 ∂u
2 ∂u 1 ∂u 2
d a21 + da22
∂t ∂t ∂t

The components of this term are not available as variables.

The diffusive flux is defined as

∂u 1 ∂u 2
c 11 ∂x + c ∂x
12
∂u 1 ∂u 2
c 11 c 12 u1 c 11 c 12 ∇u 1 c 11 ∇u 1 + c 12 ∇u 2 ∂y ∂y
c ∇u = ∇ = = = =
c 21 c 22 u2 c 21 c 22 ∇u 2 c 21 ∇u 1 + c 22 ∇u 2
∂u 1 ∂u 2
c 21 ∂x + c ∂x
22
∂u 1 ∂u 2
∂y ∂y

THE FEMLAB PDE LANGUAGE | 1-361


∂u 1 ∂u 2
c 11 + c 12
∂x ∂x
∂u 1 ∂u 2 cu1x
c 11 + c 12
∂y ∂y cu1y
= =
∂u 1 ∂u 2 cu2x
c 21 + c 22
∂x ∂x cu2y

∂u 1 ∂u 2
c 21 + c 22
∂y ∂y

where ∇u 1 and ∇u 2 are considered to be column vectors. The variable names for
the diffusive flux components are cu1x, cu1y, cu2x, and cu2y. Note that the flux
matrix or flux tensor is presented here as a column vector. It can also be presented on
matrix form, as

c ∇u = cu1x cu1y
cu2x cu2y

For anisotropic materials, each of the components c11, c12, c21, and c22 can be
matrices, as described above for the 1 variable coefficient form PDE. In this case, the
diffusive flux reads

c 1111 c 1112 c 1211 c 1212 c 1111 c 1112 c 1211 c 1212


∇u 1 + ∇u 2
c 11 c 12 ∇u 1 c 1121 c 1122 c 1221 c 1222 ∇u 1 c 1121 c 1122 c 1221 c 1222
c ∇u = = =
c 21 c 22 ∇u 2 ∇u 2
c 2111 c 2112 c 2211 c 2212 c 2111 c 2112 c 2211 c 2212
∇u 1 + ∇u 2
c 2121 c 2122 c 2221 c 2222 c 2121 c 2122 c 2221 c 2222

The variable names are the same as for the isotropic diffusive flux.

The conservative convective flux is defined as

α 111 α 121 α 111 α 121


u1 + u2
u1 α 11 α 12 u 1 α 112 α 122 u1 α 112 α 122
αu = α = = =
u2 α 21 α 22 u 2 u2
α 211 α 221 α 211 α 221
u1 + u2
α 212 α 222 α 212 α 222

1-362 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The variable names for these components are alu1x, alu1y, alu2x, and alu2y.
Here, the third index, k, of αijk corresponds to the space coordinate suffixes x and y.

The conservative flux source is defined as

γ 11
γ 12
γ =
γ 21
γ 22

The variables names for these components are ga1x, ga1y, ga2x, and ga2y. Here, the
second index, j, of γij denotes the space coordinate suffixes for x and y.

Note that in the PDE, the divergence operator is operating on each row separately,
for the flux terms. To illustrate this, consider the divergence of the conservative flux
source

γ11 γ11
∇⋅
γ12 γ12
∇⋅γ = ∇⋅ =
γ21 γ21
∇⋅
γ22 γ22

The convection term is defined as

β 111 β 121 β 111 β 121


⋅ ∇u1 + ⋅ ∇u 2
β 11 β 12 ∇u 1 β 112 β 122 ∇u1 β 112 β 122
β ⋅ ∇u = ⋅ = ⋅ =
β 21 β 22 ∇u 2 ∇u2
β 211 β 221 β 211 β 221
⋅ ∇u1 + ⋅ ∇u 2
β 212 β 222 β 212 β 222

The variable names for these components are beu1 and beu2.

The absorption term is defined as

a 11 a 12 u1 a 11 u1 + a12 u2
au = =
a 21 a 22 u2 a 21 u1 + a22 u2

THE FEMLAB PDE LANGUAGE | 1-363


The variable names for these components are au1 and au2.

The source term is defined as

f1
f =
f2

The variable names for these components are f1 and f2.

The Boundary Condition Terms


The Dirichlet condition, on expanded form, reads
h 11 h 12 u 1 r1
=
h 21 h 22 u 2 r2

The components of this equation are not available as variables.

If you choose the Dirichlet condition, you automatically get also the generalized
Neumann condition, which reads
T
n ⋅ ( c ∇u + αu – γ ) + qu = g – h µ

The normal vector n=(nx,ny) operates on the flux vector in the same way as the
divergence operator, as explained above. If you choose the Neumann condition, you
get only the boundary condition

n ⋅ ( c ∇u + αu – γ ) + qu = g

The normal component of the diffusive flux is defined as

c 11 c 12 ∇u1 n ⋅ ( c 11 ∇u 1 + c 12 ∇u2 )
n ⋅ c ∇u = n ⋅ =
c 21 c 22 ∇u2 n ⋅ ( c 21 ∇u 1 + c 22 ∇u2 )

The variable names for these components are ncu1 and ncu2.

1-364 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The normal component of the conservative convective flux is defined as

 α α 
α 111 α 121 ( n x, n y ) ⋅  111 u 1 + 121 u 2
u1 + u2
α 112 α 122  α 112 α 122 
n ⋅ αu = n ⋅ =
α 211 α 221  α α 
u1 + u2 ( n x, n y ) ⋅  211 u 1 + 221 u 2
α 212 α 222  α α 222 
 212

The variable names for these components are nalu1 and nalu2.

The normal component of the conservative flux source is defined as

γ11 γ11
( n x, n y ) ⋅
γ12 γ12
n ⋅ γ = ( n x, n y ) ⋅ =
γ21 γ21
( n x, n y ) ⋅
γ22 γ22

The variable names for these components are ngau1 and ngau2.

The boundary absorption term is defined as

q 11 q 12 u 1 q 11 u1 + q 12 u 2
qu = =
q 21 q 22 u 2 q 21 u1 + q 22 u 2

The variable names for these components are qu1 and qu2.

The boundary source term is defined as

g1
g =
g2

The variable names for these components are g1 and g2.

APPLICATION MODE VARIABLES


For the 1 variable coefficient form PDE application mode, the application mode
variables available are the magnitudes of the diffusive flux components and the
magnitude of gradients.

THE FEMLAB PDE LANGUAGE | 1-365


The magnitudes of the diffusive flux components are
c 11 ∇u 1 + c 12 ∇u 2
c 21 ∇u 1 + c 22 ∇u 2

and these are named abscu1x and abscu2x.

The magnitudes of the gradients are


∇u 1
∇u 2

and these are named absu1x and absu2x.

Variables for the Physics Application Modes


In the listing earlier of shape function variables, variable names containing u are
substituted with other variables in the physics application modes. For the physics
application modes, these variables are accessible but with the application mode’s
dependent variables instead of u. One example is for plane stress, where the
dependent variables are u and v for the displacements in the x- and y-directions. This
holds for the generalization to three variables as well.

Variable Naming Convention


The naming of shape function variables and equation variables follows a certain
convention. The index number after the letter u denotes the equation number that
the expression corresponds to. For variables not including any contribution from a
dependent variable, the equation index number stands immediately after the variable
name, for example, ga1x and g1. The letter x, y, or z occurring at the end of a variable
name denotes the space coordinate component, if any. For each application mode,
the names of independent and dependent variables can easily be changed from the
Model Navigator in the beginning of a modeling session. By pressing the More>>
button, you access edit fields for changing the variable names.

Variables for PDEs in General Form


To understand the naming of the variables in general form, consider the application
mode named 1 variable general form PDE. This application mode you get by selecting:
PDE modes, General, Time dependent in the Model Navigator.

1-366 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The single dependent variable is called u, and the equation solved is
∂u
da +∇⋅Γ = F
∂t

The available boundary conditions are the Dirichlet condition and the generalized
Neumann condition. If you choose Dirichlet, you get the boundary condition
∂R
0 = R, –n ⋅ Γ = G + µ
∂u

If you choose Neumann, you get the generalized Neumann condition

–n ⋅ Γ = G

The general form PDE equals the coefficient form PDE with all terms removed
except for the mass term, da ∂u ⁄ ∂t , the conservative flux source, γ, and the source
term, f. The terms γ and f are capitalized in the general form and become Γ and F.
Also, the boundary source term g is capitalized and becomes G in the general form.

The table below summarizes the most important variables that are available as default
for the 1 variable general form PDE application mode.

DOMAIN \ SPACE DIM 1D 2D 3D

POINT u u
EDGE u
BOUNDARY f,g,gax, f,g,gax,gay,nga, f,g,gax,gay,gaz,
nga,u,ux u,ux,uy nga,u,ux,uy,uz
SUBDOMAIN absga1x, absga1x,absux, absga1x,absux,
absux, dau,f,gax,gay, dau,f,gax,gay,
dau,f, u,ux,uy,uxx, gaz,u,ux,uy,uz,
gax,u, uxy,uyx,uyy uxx,uxy,uxz,
ux,uxx uyx,uyy,uyz,
uzx,uzy,uzz

The table below shows the division into categories and also displays the
corresponding variables as they appear in equations.

EQUATION STYLE VARIABLE NAME EQUATION SHAPE APPLICATION


VARIABLE FUNCTION MODE
VARIABLE VARIABLE

Γ absga1x ♦
∇u absux ♦
dau dau ♦
F f ♦

THE FEMLAB PDE LANGUAGE | 1-367


EQUATION STYLE VARIABLE NAME EQUATION SHAPE APPLICATION
VARIABLE FUNCTION MODE
VARIABLE VARIABLE

G g ♦
Γ = ( Γ x , Γ y, Γ z ) gax,gay,gaz ♦

n⋅Γ nga ♦
u u ♦


∂u ∂u ∂u
∇u =  ------, ------, ------ ux,uy,uz
 ∂x ∂y ∂z 


2 2
∂ u ∂ u uxx,uxy,uxz,
--------2-, ------------, …
∂x ∂x∂y
uyx,uyy,uyz,
uzx,uzy,uzz

The only variable in general form that does not have any correspondence in the
coefficient form is the application mode variable absga1x which represents the
magnitude of the Γ vector.

Notice that if you model using the general form, and then choose View as PDE
Coefficients from the Subdomain menu, the coefficient form variables are displayed in
the Subdomain Settings dialog box. These coefficient form coefficients represent a
linearization of the general form. This is described in “Linearization” on page 3-39
in the Reference Guide.

If you model using the coefficient form, and then choose to change the solution form
to general, a conversion is made. See the Reference entry on flform for a description
of this conversion.

Variables for the Physics Application Modes


In the table, the shape function variable names contain u (the letter u in italics). For
the physics application modes, these variables are accessible but with the application
mode’s dependent variable instead of u. One example is for heat transfer, where the
dependent variable is T, for temperature.

1-368 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
P DE S O N G E N E R AL FO R M I N 2 VA R I A BL E S
To understand the naming of variables for multiple component problems, consider
the application mode named 2 variable general form PDE. You can view this
application mode by selecting: PDE modes, General, Time dependent in the Model
Navigator, entering 2 in the edit field No. of dependent variables.

The explanations made below are for two space coordinates. This is for making the
expressions smaller and clearer. The generalization to three space coordinates is
straightforward. See also the description of the 1 variable coefficient form PDE
application mode above.

S H A PE F U N C T I O N VA R I A BL E S
For a description of the shape function variables, see the corresponding section for
the 2 variable coefficient form PDE application mode above.

E Q U AT IO N VA R I ABL E S

The PDE Terms


The dependent variables are called u1 and u2, and the equation system solved is
∂u
da +∇⋅Γ = F
∂t

where u=(u1,u2), Γ = ( Γ 1, Γ 2 ) , and F = ( F 1, F 2 ) .

The mass term is the same as in the case of the 2 variable coefficient form PDE
application mode above.

The flux vector is defined as

Γ 11
Γ 12
Γ =
Γ 21
Γ 22

where the notation with a column vector of column vectors is used below for being
able to define the operation of the normal vector and the gradient operator.

THE FEMLAB PDE LANGUAGE | 1-369


The flux vector can also be viewed as a 2-by-2 matrix

Γ 11 Γ 12
Γ =
Γ 21 Γ 22

The variables names for these components are ga1x, ga1y, ga2x, and ga2y. Here, the
second index, j, of γij denotes the space coordinate suffixes x and y. The divergence
operator operates on Γ in the same way as described above for the 1 variable
coefficient form PDE application mode.

The source term is defined as

F1
F =
F2

The variable names for these components are f1 and f2.

The Boundary Terms


The Dirichlet condition, on expanded form, reads

0 = R1
0 R2

The components of this equation are not available as variables.

If you choose the Dirichlet condition, then you automatically also get the generalized
Neumann condition, which reads
∂R T
–n ⋅ Γ = G +   µ
 ∂ u

The normal vector n=(nx,ny) operates on the flux vector in the same way as the
divergence operator, as explained above. If you choose the Neumann condition, you
get only the boundary condition

–n ⋅ Γ = G

1-370 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The normal component of the flux vector is defined as

Γ 11 Γ 11
( n x, n y ) ⋅
Γ 12 Γ 12
n ⋅ Γ = ( n x, n y ) ⋅ =
Γ 21 Γ 21
( n x, n y ) ⋅
Γ 22 Γ 22

The variable names for these components are ngau1 and ngau2.

The normal flux term is defined as

G1
G =
G2

The variable names for these components are g1 and g2.

APPLICATION MODE VARIABLES


The application mode variables available are the magnitudes of the flux vector and the
gradients.

The magnitudes of the flux vector components are


Γ1
Γ2

and they are named absga1x and absga2x.

The magnitudes of the gradients are


∇u 1
∇u 2

and they are named absu1x and absu2x.

Variables for the Physics Application Modes


In the listing earlier of shape function variables, variable names containing u are
substituted with other variables in the physics application modes. For the physics
application modes, these variables are accessible but with the application mode’s
dependent variables instead of u. One example is for plane stress, where the
dependent variables are u and v, for displacements in the x- and y-direction. This
holds for the generalization to three dependent variables as well.

THE FEMLAB PDE LANGUAGE | 1-371


Weak Form Meta Variables
When using the weak solution form, the shape function variables (and the boundary
coupled shape variables) are the only automatically generated field variables that are
available as default. The shape function variables are available in a way as described
earlier for the coefficient and general solution forms. User-defined expression
variables and coupling variables are also available.

In addition to shape function variables, meta variables for test functions, test function
derivatives, and time derivatives are available in the weak and dweak edit fields on the
Weak page in the Subdomain Settings, Boundary settings, Edge settings, and Point
settings dialog boxes. The test function meta variables follow a naming convention
similar to that used for variables, see “Variable Naming Convention” on page 1-366.

In the weak edit fields, you type a series of weak terms. The test functions always
occur linearly in the weak terms. These weak terms are either used alone to define the
problem, as is the case when using the Weak application modes, or used in addition
to the coefficients in coefficient and general form.

The table below shows the available test function meta variables and shape function
time derivatives for the application mode 2 variable weak form PDE.

1D 2D 3D

WEAK u1_test,u2_test, u1_test,u2_test, u1_test,u2_test,


FORM
META
u1x_test,u2x_test, u1x_test,u1y_test, u1x_test,u1y_test,
VARIABLE u1_time,u2_time, u2x_test,u2y_test, u1z_test,u2x_test,
u1x_time,u2x_time u1_time,u2_time, u2y_test,u2z_test,
u1x_time,u1y_time, u1_time,u2_time,
u2x_time,u2y_time u1x_time,u1y_time,
u1z_time,u2x_time,
u2y_time,u2z_time

Also the corresponding second-order space derivatives are available. Notice that the
time derivative meta variables are only available in the dweak edit fields.

For the scalar coefficient form PDE, the weak form was derived earlier, in the section
“The Weak Form” on page 1-345. The weak form of the coefficient form PDE is

∫ ( ∇v ⋅ ( – c ∇u – αu + γ ) + v ( f – β ⋅ ∇u – au ) ) dA + ∫ v ( –qu + g – h
T
0 = µ ) ds
Ω ∂Ω

1-372 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Suppose c is a scalar. Using the weak form meta variables for a 2D problem, this
translates to:

For the weak edit field of Ω in the GUI

ux_test*(-c*ux-alx*u+gax)+uy_test*(-c*uy-aly*u+gay)+...
u_test*(f-bex*ux-bey*uy-a*u)

For the weak field of ∂Ω in the GUI

u_test*(-q*u+g)

The variables alx, aly, bex, bey, gax, and gay are the components of α, β, and γ,
respectively. The coefficients in this weak form expression, for example c, alx and q
need to be replaced with appropriate expressions.

The Lagrange multiplier µ is automatically added by FEMLAB, and the constraint


matrix h is specified, indirectly, by the constraints. See the section “Conversion to
Weak Form” on page 3-36 in the Reference Guide for more information on Lagrange
multipliers and constraints.

For modeling using programming, the above expressions for the weak edit fields can
be entered in the equ.weak and bnd.weak fields, respectively.

ADDITIONAL TIME DERIVATIVE COEFFICIENTS


Some additional coefficients and terms can be introduced by using the weak fields.
You might have wondered why the da coefficient uses the subscript a. This is because
it is similar to the a coefficient in the absorption term, but it stands in front of ∂u ⁄ ∂t
instead of u. To understand how the weak form can be used to introduce new
coefficients, consider the coefficients dc, dα, and dβ for ∂u ⁄ ∂t , analogous to the
coefficients c, α, and β for u, in the extended PDE formulation

∂u ∂u ∂u ∂u
– ∇ ⋅  d c ∇ + d α  + d β ⋅ ∇ + d a – ∇ ⋅ ( c ∇u + … ) + …
 ∂t ∂t  ∂t ∂t

These coefficients are not yet available in general or coefficient form, but can still be
introduced by adding weak terms in the dweak field in the Subdomain Settings dialog
box.

For 1D, type

ux_test*(d_c*ux_time+d_al*u_time)+u_test*d_be*ux_time

For 2D, type

THE FEMLAB PDE LANGUAGE | 1-373


ux_test*(d_c*ux_time+d_al1*u_time)+
uy_test*(d_c*uy_time+d_al2*u_time)+
u_test*(d_be1*ux_time+d_be2*uy_time)

The variables d_c, d_al, d_be, d_al1, d_al2, d_be1, and d_be2 must be replaced
with appropriate expressions.

The generalization to 3D is straightforward.

The coefficients dc, dα, and dβ will be available in coefficient and general form in a
future release of FEMLAB.

For script modeling, the above expressions for the dweak edit fields can be entered in
the equ.dweak field in the FEM structure.

INTRODUCING TIME DERIVATIVES IN BOUNDARY CONDITIONS


Consider introducing a time derivative in the Neumann boundary condition by
∂u T
n ⋅ ( c ∇u + … ) + d q + qu = g – h µ
∂t

You can get the dq coefficient by adding the following term in the dweak edit field
for boundaries

u_test*d_q*u_time

The dq coefficient will be available in coefficient and general form in a future release
of FEMLAB.

For script modeling, the above expression for the dweak edit field can be entered in
the bnd.dweak field in the FEM structure.

Variable Name Suffixes For Multiphysics


When using more than one application mode simultaneously, each application mode
variable gets an application mode suffix. This is necessary to avoid variable name
conflicts. The variables derived from the application mode 1 variable coefficient form
PDE will get the suffix _c1, if this was the first application mode of the type 1 variable
coefficient form PDE that was added to the list of application modes used. The next
application mode of this type will generate suffixes _c2, the next _c3, and so on. In
the same way, the variables derived from application modes of the type 1 variable
general form PDE will get the suffix _g1, _g2, and so on. A list of physics application
mode suffixes can be found in the variable tables in the section “Application Mode
Reference” on page 4-203 in the Reference Manual.

1-374 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Special Variables
The special variables are variables that have no natural place under the categories
constants, geometric variables, and field variables. These are the time variable, the
eigenvalue variable, and the phase variable.

THE TIME VARIABLE


For time-dependent problems, the time variable t is available. The variable t can be
part of any expression in boundary and subdomain settings, as well as in
postprocessing: it is always a scalar, even for time-dependent problems where more
than one output time is computed. In the GUI, to choose between different output
times, you select from the Solution at time list box, available in each of the dialog
boxes opened from the Post menu. The value of t will correspond to the selection
made in the Solution at time list.

Using t in the Programming Language


When working from the MATLAB prompt, the selection of solution time is
controlled by the property Solnum. (See the reference entries on the postprocessing
functions, for example posteval, for more information on how to use Solnum.)
Also, in the postprocessing functions, the property T is available for setting the time
for evaluation of the variable t. Notice that using the property T will only affect the
value of the variable t appearing explicitly in expressions and will not affect the time
for evaluation of the solution, for example, u in the 1 variable coefficient form PDE
application mode. The time for evaluation of the solution is always controlled by the
property Solnum. This means that the solution is always evaluated at one of the user
specified output times; no interpolation of the solution is ever made between these
values.

T H E E IG E NVA L U E VA R I A BL E
Eigenvalue problems are specified like time-dependent problems. FEMLAB replaces
the time derivative ∂u ⁄ ∂t with – λu, where λ is the eigenvalue. Also, the source
terms are omitted. Thus, an eigenvalue problem in coefficient form reads

∇ ⋅ ( – c ∇u – αu ) + β ⋅ ∇u + au = λd a u

For more information on the eigenvalue equation, see “Eigenvalue Problems” on


page 3-41 in the Reference Guide.

For a 1 variable coefficient form eigenvalue PDE, the eigenvalue term is defined as
λd a u

THE FEMLAB PDE LANGUAGE | 1-375


where da is a scalar and the eigenvalue λ is available as the variable lambda. The
eigenvalue term factor da u is available as the variable dau.

For a 2 variable coefficient form eigenvalue PDE, the eigenvalue term is defined as.

d a11 d a12 u 1 da11 u 1 + d a12 u2


λd a u = λ = λ
d a21 d a22 u 2 da21 u 1 + d a22 u2

The components of the last vector are available as dau1 and dau2.

The eigenvalue variable lambda is a scalar, available only in post mode. To choose
between different eigenvalues, in the GUI, you select from the Eigenvalue list box,
available in each of the dialog boxes opened from the Post menu. The value of lambda
will correspond to the selection made in the Eigenvalue list box. When working from
the MATLAB prompt, the selection of eigenvalues is controlled by the property
Solnum. See the reference entries on the postprocessing functions, for example
posteval, for more information on how to use Solnum.

T H E P H A S E VA R I ABL E
In all physics application modes where time-harmonic problems are solved, the
solution is obtained for a phasor variable, ũ , defined by
jωt
u ( r, t ) = Re ( ũ ( r )e )

The phasor ũ contains the amplitude and phase information of u but is itself
independent of t. Note that the real part of ũ is the value of u at time t = 0.

To obtain the value at any given time, a phase angle, φ, can be specified in all
postprocessing dialog boxes. This phase angle can be interpreted as φ = ωt0 for some
given time t0. When using programming, the phase angle is specified using the Phase
property of the function.

In the physics application modes, the solution variable, as well as all other
time-harmonic application mode variables, are automatically multiplied by the phase
factor ejφ. When using the PDE application modes to define a problem using
phasors, only the solution variable is automatically multiplied by ejφ. For other
harmonic fields, the phase factor has to be given explicitly. This is done using the
variable phase. Say you have a quantity F = F ˜ e jωt denoting an explicit load,
specified by setting the coefficient form source term f equal to F˜ . To obtain the
proper harmonic behavior of F, multiply F ˜ by exp(j*phase), when postprocessing.

1-376 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Animations
When making animations, the interpretation of the Phase property of the
postprocessing functions and the interpretation of the variable phase have to be
slightly modified. The reason is that in this case we are not interested in the value only
at a single time but in the whole time evolution.

The Phase property of the postprocessing functions, which is the same as you can
specify in the postprocessing dialog boxes, is the phase at time t = 0. Thus the time
evolution will be given by a factor ej(ωt+φ), where φ is the taken from the Phase
property.

When specifying a phase factor exp(j*phase) using the variable phase, this factor
is interpreted as the factor ej(ωt+φ). Thus exp(j*phase) is the factor ejφ given by the
Phase property multiplied by the time evolution factor ejωt.

Phasor Products
Special care has to be taken when evaluating products of phasors. Say you want to
evaluate the product uv of two time-harmonic variables u and v. The time evolution
of uv is
jωt jωt
u ( t )v ( t ) = Re ( ũe )Re ( ṽe )

When evaluating uv at a given time or when animating the time evolution, uv has to
be given as real(u)*real(v).

Using the relation


1 *
Re ( a )Re ( b ) = --- Re ( ab + ab )
2

where b* is the complex conjugate of b, we can also express the time average of uv.
We find that

jωt jωt 1 * 2jωt


Re ( ũe )Re ( ṽe ) = --- Re ( ũṽ + ũṽe )
2
Since the time average of the second term vanishes, we can obtain the average by
evaluating 0.5*real(u*conj(v)).

THE FEMLAB PDE LANGUAGE | 1-377


Equation-Based Modeling
The models developed in this section are somewhat more advanced than the previous
ones in this document. Therefore, the reader may prefer to skip the model
development part in an overview reading. These models serve collectively as an
introduction to equation-based modeling using PDE systems in FEMLAB. The
modeling is done using both the GUI and the FEMLAB functions for script
programming.

The first model demonstrates 1D modeling using script programming, and the
second model shows 2D multiphysics modeling using PDE systems in the GUI.

Tubular Reactor
In a tubular gas reactor, chemical reactions take place during the time a stream of gas
carries reactants from the inlet to the outlet. Mass and energy transport occur
through a convection-diffusion process.

This example examines a simplified model of a tubular reactor. It assumes that radial
variations in compositions and temperature are small due to plug flow and
heat-insulated walls.

(c,T)
v

The gas in the reactor flows with velocity v, and it has a density ρ and specific heat C.

Several factors influence the reactant’s concentration c, which you can model with the
equation shown below on the left. Its terms account for convection, diffusion (where
D denotes the diffusion coefficient), and the reaction rate (using the reaction term
Q).

E
– ---------
∂c ∂c ∂  ∂c  RT
+v = D – Q, Q = kce .
∂t ∂x ∂ x  ∂ x

1-378 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Further assume that you can model the reaction with a first-order rate law where the
Arrhenius equation (above, right) gives the temperature dependence. Here E
denotes the activation energy, and k is the pre-exponential factor. This assumption of
first-order kinetics is plausible because you’re dealing with the combustion of low
concentrations of fuel in an oxygen-rich environment.

This example involves heat transfer by convection and conduction. We denote the
thermal conductivity with λ. Heat production occur by reaction enthalpy ∆H.

∂T ∂T ∂  ∂T
ρc p  + v  = λ + Q ∆H.
∂t ∂x  ∂ x ∂ x 

The influx gas has temperature T0 and concentration c0. Making the assumption that
the main transport of reactants into the reactor takes place by convection results in
the following boundary condition for the flux at the inlet:

∂c
vc ( 0, t ) – D = vc 0 .
∂x

Similarly, for the heat flux, you have:

∂T
ρCT ( 0, t ) – λ = ρCvT 0 .
∂x

Also assume the gradients at the exit are small, so that:

∂c ∂T
= 0, = 0.
∂x ∂x

To make the discretized finite element model well-conditioned, set up dimensionless


scales for the variables. To do this, express length in terms of L, express time in terms
of D/L2, measure temperature relative to T0, and scale concentration to c0.

By examining values for the coefficients in the scaled, dimensionless problem it


becomes easier to assess the importance of various processes in the model:

Thermal conduction/diffusion λ
r 0 = -------------
ρCD

“Thermal” Peclet number, convection/conductive heat vLρC r2


r 1 = --------------- = -----
transfer λ r0

EQUATION-BASED MODELING | 1-379


Peclet number, convection rate/diffusion rate vL
r 2 = -------
D
2
Reaction heat production/diffusion ∆Hc 0 L k
B 1 = -------------------------
DρCT 0
2
Reaction production rate/diffusion rate kL
B 2 = ----------
D
Model-characteristic temperature constant E
q = -----------
RT 0

Now you can express the tubular reactor with a system of PDEs in terms of the
dimensionless, scaled variables

2 q
– ----
∂T ∂T ∂ T T
+ r2 = r 0 2 + B 1 ce
∂t ∂x ∂x
2 q
– ----
∂c ∂c ∂ c T
+ r 2 = 2 – B 2 ce
∂t ∂x ∂x

with these boundary conditions:

∂T ∂T
– r0 ( x , t ) = r 2 ( T 0 – T ( x 0, t ) ); ( x , t) = 0
∂x 0 ∂x 1
∂c ∂c
– ( x , t ) = r 2 ( c 0 – c ( x 0, t ) ); ( x , t ) = 0,
∂x 0 ∂x 1

where T = T(x,t), c = c(x,t), x0 = 0, x1 = 1, and T0 = 1.

It is possible to reduce this model to a pure diffusion problem by introducing


coordinates that move with the fluid, specifically:

ξ = x – r2 t, τ = t.

For a pure initial-value problem with

T ( x, 0 ) = T 0 > 0 and c ( ξ, 0 ) > 0 given for – ∞ < ξ < ∞,

1-380 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
you can conclude that two possible scenarios exist:

• The process consumes the reactant completely and the final state becomes:

B1
c ( ξ, ∞ ) = 0, T ( ξ, ∞ ) = T 0 + ------- c 0 .
B2

• The process doesn’t run to completion in finite time.

The model described thus far takes on relevance to the real world when you consider
what happens in a tubular reactor of finite length that operates for a specific period
of time. Suppose a plant engineer, striving to maximize return on investment, wants
a system to generate a large flow of reaction product. That person must evaluate
several design trade-offs. If T0 is low, if gas velocity v is large or if the reactor is short,
the time during which the gas resides in the reactor isn’t sufficient for a high degree
of conversion. On the other hand, low gas velocity means a small flow of reaction
products, while increasing length L implies an excessively large and expensive system.

In addition, it’s sometimes possible that multiple steady-state concentration and


temperature profiles can arise from the same set of values for L, T0, v, and c0. In that
case, the effects of stability and sensitivity to perturbations during operation become
important.

Using these factors as starting points, you can develop guidelines for the design and
operation of a tubular reactor by simulating its dynamic operation. Let us investigate
an example based on the following parameters:

7
r0 = 1 B 1 = 7.8 ⋅ 10
8
r 1 = 30 B 2 = 1.2 ⋅ 10
r 2 = 30 q = 17.6

A PDE SYSTEM ON GENERAL FORM


Instead of using application modes with ready-made equations, we will model the
tubular reactor by entering the PDEs explicitly. See the section “The FEMLAB PDE
Language” on page 1-336 for a description of PDEs in FEMLAB. We will use the

EQUATION-BASED MODELING | 1-381


general form of equations, and solve for two variables: the temperature and the
concentration. The PDEs in general form are

∂u1 ∂u 2
d11 + d 12 + ∇ ⋅ Γ1 = F 1
∂t ∂t
∂u1 ∂u 2
d21 + d 22 + ∇ ⋅ Γ2 = F 2
∂t ∂t

where u1 and u2 denote temperature and concentration, respectively. The functions


Γ1, Γ2, F1, and F2 depend on the solution to these equations, thereby making the
problem nonlinear.

You can identify the coefficients in the scaled equations from the previous section
with Γi and F2; replace u1 with T and u2 with c; also replace ∇·Γi with ∂Γi/∂x. Now
the equations for this 1D model become:
q
– ----
∂T ∂c ∂ ∂T ∂T
+ 0 +  – r 0  = – r 2 + B1 ce
T
1
∂t ∂t ∂x ∂x ∂x
q
– ----
∂T ∂c ∂ ∂c ∂c
+ 1 +  –  = – r2 – B 2ce
T
0 .
∂t ∂ t ∂ x  ∂ x ∂x

Boundary conditions for the general form fall into one of two categories:

• Dirichlet, where you set R = 0 on the boundary ∂Ω.


• Generalized Neumann, where -n·Γ=G on ∂Ω.

As you just did with the PDE, identify the coefficients in the scaled boundary
conditions from the previous section with the generalized Neumann boundary
conditions in general form. The boundary consists of the two points x0 = 0 and x1 =
1, and for this system

∂T
– n ( x 0 )Γ 1 ( x 0, t ) = G 1 ( x 0, t ) –r0 ( x , t ) = r 2 ( T 0 – T ( x 0, t ) )
∂x 0
∂T
– n ( x 1 )Γ 1 ( x 1, t ) = G 1 ( x 1, t ) r0 (x , t) = 0
∂x 1
∂c
– n ( x 0 )Γ 2 ( x 0, t ) = G 2 ( x 0, t ) – ( x , t ) = r 2 ( c 0 – c ( x 0, t ) )
∂x 0
∂c
– n ( x 1 )Γ 2 ( x 1, t ) = G 2 ( x 1, t ) ( x , t) = 0
∂x 1

1-382 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
where the left column contains the general expressions and the right column contains
the equations as they pertain to this example.

To see what impact initial conditions have on this 1D model, you might want to run
it twice with different values. The first set consist of T(x,0) = c(x,0) = 1; for the
second set use:

T ( x, 0 ) = 1 + 0,15x
c ( x, 0 ) = 1.

Model Library FEMLAB/Chemical_Engineering/tubular_reactor

USING THE PROGRAMMING LANGUAGE


We will model the tubular reactor using script programming, instead of using the
GUI. See the section “The Programming Language” on page 1-301 for a description
of the use of FEMLAB functions at MATLAB’s prompt or in scripts (M-files). Start
by clearing the FEM structure to eliminate any previously created variables:

clear fem

Specify the problem dimension (number of dependent variables) and the form in
which you plan to enter the equations:

fem.dim=2;
fem.form=’general’;

The interval on the real axis over which you plan to study this model is [0,1], so
specify the geometry as:

fem.geom=solid1([0 1]);

The function solid1 creates a 1D solid object on the real axis.

The following command creates an initial 1D mesh:

fem.mesh=meshinit(fem,’hmax’,0.01);

Next specify the problem’s constants:

fem.const={’r0’ 1 ’r1’ 30 ’r2’ 30 ...


’B1’ 7.8e7 ’B2’ 1.2e8 ’q’ 17.6};

With these preliminaries out of the way, you can now specify the PDE system (and
recall that r1 = r2/r0):

EQUATION-BASED MODELING | 1-383


fem.dim={’T’,’c’};
fem.equ.ga={{{’-r0*Tx’} {’-cx’}}};
fem.equ.f={{’-r2*Tx+B1*c*exp(-q/T)’ ...
’-r2*cx-B2*c*exp(-q/T)’}};
fem.equ.da={{1 1}};
fem.bnd.g={{’r1*(1-T)’ ’r2*(1-c)’} 0};

In order to solve the nonlinear PDEs, you must instruct FEMLAB to form the
Jacobian by symbolic differentiation using the function femdiff:

fem=femdiff(fem);

As noted earlier, you’ll be working with two sets of initial conditions, which you
place in the field fem.init. The first one corresponds to the start-up of a cold
reactor:

fem.equ.init={{1 1}};

Use quadratic Lagrange elements.

fem.shape=[2 2];

For this time-dependent problem you should select the solver function femtime. In
the function call’s arguments you can request a progress report as well as specify the
time interval for the simulation:

fem.xmesh=meshextend(fem);
fem.sol=femtime(fem,’report’,’on’,’tlist’,0:0.01:0.1);

At this point FEMLAB displays a progress report.

Plot the concentration in the pipe for each output time.

postcrossplot(fem,1,1,’lindata’,’c’,’linlegend’,’on’,...
’lincolor’,’cycle’)

The legend can be moved with the mouse. You can also plot the temperature by
replacing ‘c’ by ‘T’ in the command above.

To animate T and c, use the command:

postmovie(fem,'lindata','T','liny','c');

Using a few more output times, 0:0.002:0.1, in the call to femtime helps making
the animation smoother.

Recall that you’re working with two sets of initial conditions. Thus try an initial value
slightly above the stationary value of the previous run:

fem.init={{’1+0.15*x’ 1}};
fem.sol=femtime(fem,’report’,’on’,’tlist’,0:0.002:0.1);

1-384 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Animate T and c again:

postmovie(fem,’lindata’,’T’,’liny’,’c’);

You should see small regions of instability that must pass through the reactor before
the system settles.

REFERENCE
Ramirez, W. Fred, Computational Methods for Process Simulation, 1989, Butterworths
(Boston, MA), ISBN 0-498-90184-9.

Cylindrical Tubular Reactor with Cooling1


This example refines the previous model by incorporating the cooling effect of the
walls in a cylindrical reactor.

outside

y (c,T)

v
symmetry
axis
x

You can still assume plug flow along the reactor, whereas heat conduction and
molecular diffusion take place in radial and axial directions. Considering these effects,
the scaled equations become

2 q
– ----
∂T ∂T ∂ T L R ∂ ∂T
= r 0 2 + r 0 -------  y  + B 1 ce
T
+ r2
∂t ∂x ∂x y ∂ y ∂ y 
2 q
– ----
∂c ∂c ∂ c LR ∂ ∂c
+ r 2 = 2 + -------  y  – B 2 e
T
∂t ∂x ∂x y ∂y ∂y

1. Model courtesy of Bernt Nilsson, Chemical Engineering Dept., Lund University.

EQUATION-BASED MODELING | 1-385


with the boundary conditions

∂T ∂T
– r0 (0, y, t) = r 2 ( T 0 – T ( 0, y, t ) ) ( 1, y , t ) = 0
∂x ∂x
∂c ∂c
– ( 0, y , t ) = r 2 ( c 0 – c ( 0, y , t ) ) ( 1, y , t ) = 0
∂x ∂x
∂T ∂T
( x, 0, t ) = 0 ( x, 1, t ) = κ ( T R – T ( x, 1, t ) )
∂y ∂y
∂c ∂c
( x, 0, t ) = 0 ( x, 1, t ) = 0
∂y ∂y

where T = T(x,y,t), c = c(x,y,t), LR = 10, κ = 100 and TR = C0 = T0 = 1.

TR gives the scaled temperature of the cooling medium, LR is the scaled radius, and
κ is a scaled heat-transfer coefficient.

You must also establish some initial conditions:

T(x,y,0) = 1 and c(x,y,0) = 1.

Model Library FEMLAB/Chemical_Engineering/tubular_reactor_cooling

USING THE GRAPHICAL USER INTERFACE

Model Navigator
• In the Model Navigator, select General Time-dependent from the PDE modes.
• To specify the number of dependent variables, in this case two, enter that value in
the edit field for No. of dependent variables at the bottom of the New page.
• Select the Lagrange - Quadratic element type.

1-386 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
• To change the default names of the dependent variables, press the More button.

• Enter T c instead of u1 u2 in the Dependent variables edit field.


• Change the Application mode name to something meaningful, such as
convection_diffusion.

• Press OK.

Options and Settings


• Open the Axis and Grid Settings dialog box from the Options menu. Set the axis
limits to [-0.25 1.25] for the x-axis range and [-0.25 1.25] for the y-axis range.
• Open the Add/Edit Constants dialog box from the Options menu. Enter the
following variable names and expressions:

NAME EXPRESSION

r0 1
r1 30
r2 30
B1 7.8e7
B2 1.2e8
q 17.6
LR 10

EQUATION-BASED MODELING | 1-387


NAME EXPRESSION

kappa 20
TR 1
kappa = 20 introduces some cooling on the outside of the cylinder.

Draw Mode
• Press the Draw Rectangle button on the draw toolbar and create a square from the
origin to (1,1).

1-388 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Boundary Mode
• Choose Boundary Settings from the Boundary menu. In the dialog box that opens
enter the boundary coefficients as in the following table.

BOUNDARY 1 2,4 3

G(1) r1*(1-T) 0 kappa*(TR-T)


G(2) r2*(1-c) 0 0
R(1) 0 0 0
R(2) 0 0 0

EQUATION-BASED MODELING | 1-389


Subdomain Mode
• Choose Subdomain Settings from the Subdomain menu. Enter the coefficients from
the following table.

SUBDOMAIN 1

Γ(1) -r0*Tx -r0*LR*Ty


Γ(2) -cx -LR*cy
F(1) -r2*Tx+r0*LR/y*Ty+
B1*c*exp(-q/T)
F(2) -r2*cx+LR/y*cy-
B2*c*exp(-q/T)
da(1,1) 1
da(1,2) 0
da(2,1) 0
da(2,2) 1

Note that each text field for the Γ coefficient contains two space-separated items,
each item corresponding to the space-coordinate level of the PDE syntax from
section “Level 3 Coefficients” on page 3-76.

• Press the Init tab in the Subdomain Settings dialog box. Set the following initial
conditions:

SUBDOMAIN 1

T 1+0.15*x
c 1

1-390 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Mesh Mode
• Select Initialize Mesh from the Mesh menu. This action instructs FEMLAB to
generate and plot an initial mesh.

EQUATION-BASED MODELING | 1-391


Solving
• From the Solve menu Choose Parameters, which opens the Solver Parameters
dialog box. Select the Timestepping page and set the time steps to 0:0.005:0.1
in the edit box.

• Instruct FEMLAB to find the solution by going to the Solve menu and selecting
Solve Problem or by pressing the corresponding toolbar button. (Time to solve:
63 s)

1-392 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Post Mode
• On the Surface page in the Plot Parameters dialog box, select T for Surface data and
c for Height data (3D). Press OK to see a 3D representation of the variables plotted
against each other.
• Press the Animation toolbar button to see how the 3D plot changes over time.
• On the General page, you can examine the solution surface at specific points in time
with the Solution at time menu.

Rotate the 3D graph by clicking and dragging with either mouse button.

You can also try setting kappa to zero, which makes the problem equivalent to the
previous 1D script model. Edit the kappa value in the Add/Edit Constants dialog box,
then press the Solve toolbar button to run the model for kappa = 0.

EQUATION-BASED MODELING | 1-393


Modeling Approaches
This section describes a number of different features that can enhance the modeling
and solution process. The first two subsections present ways to treat multiphysics
problems. Then scaling of the geometry, variables, and equations are described. The
latter subsections discuss weak equations and weak constraints, which can be used, for
example, to do very accurate flux computations.

Multiphysics Modeling Approaches


The thermo-electric heating model, “Thermo-Electric Heating in a Bus Bar” on page
1-109, illustrates one of the ways in which you can set up a multiphysics model in
FEMLAB: Select one of the application modes. Draw the geometry and set the
boundary conditions and the material data (PDE coefficients). Solve and visualize the
results. Then, add another application mode by selecting Add/Edit Modes… from the
Multiphysics menu. Continue by adding and modifying couplings in boundary mode
and subdomain mode.

Another way of doing multiphysics modeling is to begin with multiple application


modes by using the Multiphysics page of the Model Navigator directly when starting a
session.

The different techniques of multiphysics modeling described above are actually just
a matter of approach since you end up with selecting application modes on the
Multiphysics page of the Model Navigator, in both cases.

It is also possible to solve a multiphysics problem in a “weakly coupled” manner by


using the Solve for variables feature on the Multiphysics page in the Solver Parameters
dialog box. You specify which degree of freedom names to solve for by selecting the
corresponding application modes in a list box. The deselected variables are kept at a
value given by the initial conditions. This feature could have been used in the
previous model, thermo-electric heating, in the following way: When adding the
Heat transfer application mode, the Conductive media DC application mode is
disabled and a pure Heat transfer model is solved. After doing this, the full
multiphysics model can be solved by selecting both application modes.

Occasionally, it is necessary to deactivate application modes per subdomain. This


could be, for example, when different subdomains have different associated physics
phenomena and an application mode is not meaningful in a subdomain. The feature

1-394 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
of deactivating application modes per subdomain is accessible from the Subdomain
Settings dialog box through the check box labeled Active in this subdomain. For an
example of how to use this feature, see the model “Vibrations in Milk Containers” on
page 2-336 in the Model Library.

Iteration Techniques for Solving Multicomponent Systems


For large 3D problems, it is often difficult to solve the full coupled systems of
equations, in particular because of memory constraints. You can often solve the
system on a fine mesh by solving for one component at the time. It is often best to
get an initial solution to the full coupled system by first solving on a coarse grid.
Thus, set up and solve the problem on a coarse grid; you can use a direct solver to
avoid problems with iterative solvers, and preconditioning. Then refine the mesh to
the desired mesh size. Select a subset of the variables in the Solve for Variables list box
on the Multiphysics page in the Solver Parameters dialog box. Press the Restart button
to solve for the selected variables. Then use the Solve for Variables list box to select
some complementary variables, and press Restart to solve for these. Perform
iterations like this can result in convergence for the full system. Using the nonlinear
solver to solve the partial system helps also for a linear system. This is because the
nonlinear solver utilizes an error estimator. If all initial error estimates reported are
lower than a certain value, this value is likely to be a good error estimator for the full
system.

Scaling of the Geometry


Sometimes the geometry of a problem can be very thin in one direction. Since
FEMLAB’s mesh generator creates mesh elements that are isotropic in size, a large
number of elements will be created in the thin layer. Large differences in scale may
also cause the mesh generator to fail in creating the mesh. In such cases one can use
a scaled geometry in which the thin direction has been expanded to the same size as
the other directions. An alternative (equivalent) approach is to scale back the
geometry and mesh to the original size, thus producing an anisotropic mesh. The
second approach requires some command-line programming, but it eliminates the
need to rescale the equations. We only describe the first approach.

For example, suppose that the original geometry is a rectangle 0<X<A, 0<Y<B,
where A is much bigger than B. Then one can introduce new coordinates x=X/A,
y=Y/B. In these coordinates, the geometry is the square 0<x<1, 0<y<1. Now, the

MODELING APPROACHES | 1-395


PDE and boundary condition must be translated to the new geometry. Assume that
we have a PDE on coefficient form for a variable u:

∂u
da – ∇ ⋅ ( c ∇u + αu – γ ) + β ⋅ ∇u + au = f
∂t

with boundary conditions


T
n ⋅ ( c ∇u + αu – γ ) + qu = g – h µ , hu = r

where
∂ ∂
∇ =  ,
∂ X ∂ Y

Expressed in terms of the new coordinates x and y, this becomes


–1 ∂ –1 ∂ 
∇ = A , B
 ∂x ∂ y

Thus, the PDE expressed in the new coordinates becomes

∂u ˜ ˜ u + α̃u – γ̃ ) + β̃ ⋅ ∇
˜ u + au = f
da – ∇ ⋅ ( c̃∇
∂t

where
˜ = ∂ , ∂

 ∂ x ∂ y

and

–1
c̃ = ScS , α̃ = Sα , β̃ = Sβ , γ̃ = Sγ , S = A 0
–1
0 B

Note that the diffusive coefficient c̃ now is a matrix, even if the original c was a scalar.
Note also that the expressions for the coefficients and terms in the equation have to
be rewritten according to the substitutions X=Ax and Y=By. Let

ñ = ( n x , n y )

be the normal vector in the new geometry. Then the boundary conditions become
˜ u + α̃u – γ̃ ) + q̃u = g̃ – h T µ̃ ,
ñ ⋅ ( c̃∇ hu = r

1-396 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
where
nx 2 ny 2 nx 2 ny 2
q̃ = q  ------ +  ------ , g̃ = g  ------ +  ------
A B A B

Note that in our example, the boundaries are parallel to the coordinate axes, which
means that the square root is 1/A or 1/B.

One can also scale different parts of the geometry with different scale factors, but then
one has to think about the interfaces to get the scalings right.

Scaling of the Variables and Equations


If the dependent variables in your model has widely different magnitudes, a solver
might have problem with the resulting ill-conditioning. For instance, in a structural
mechanics problem, the displacements can be of the order of 0.0001 m, while the
stresses are 1000000 Pa. To remedy this, FEMLAB internally rescales the variables so
that a well-scaled system results. You can control the scaling by using the Scaling of
Variables dialog box, which is accessible from the General page of the Solver
Parameters dialog box. The default scaling is the Automatic scaling, which should
work well for most models. If you know in advance the order of magnitudes of your
variables, you can use the Manual scaling. For instance, suppose that you have two
degrees of freedom u and sigma. Assume the values of u are of the order 10-4, and
the values of sigma are around 106. Then you can enter u 1e-4 sigma 1e6 in the
Manual scaling edit field. This means that the solvers will internally use the rescaled
degrees of freedom U=u/1e-4 and Sigma=sigma/1e6, which both are of the order
1. If you have given an initial value or linearization point which gives a good estimate
of the scales of your variables, then you can use the Initial value based scaling. Finally,
the scaling of variables can be turned off by choosing the None radio button.

Even though the variables are well scaled, the equations can have very different scales.
To overcome this problem, the equations can be equilibrated by choosing Row
equilibration On. The scaling of the equations can be turned off by choosing Row
equilibration Off. The default setting for Row equilibration is Automatic, which means
that On or Off is chosen depending on whether variable scaling is used or not.

When using MATLAB’s command line, the scaling is controlled by the properties
Uscale and Rowscale, see “Some Solver Options” on page 3-136 of the Reference
Manual.

MODELING APPROACHES | 1-397


Point and Edge Constraints and Loads
Point and Edge constraints can be defined by using the Point Settings and Edge
Settings dialog boxes, respectively. In the physics modes application modes, you will
have to check View as Point Coefficients or View as Edge Coefficients, respectively.

Use the Constr field to set a constraint. The expression written in the field is
constrained to zero. For an example on how to define point constraints using the
Constr field, see “Stresses in Cracked Heat Exchanger Tubes” on page 2-296 in the
Model Library.

Similarly, add a load by typing u_test*load in the Weak field, where u is the variable
associated with the load. For an example of how to use point load, see “Implementing
a Point Source” on page 2-84 in the Model Library.

Weak Constraints, Their Uses and Limitations


The weak constraints feature implements constraints by using finite elements on the
constraint domain for the Lagrange multipliers and solving for the Lagrange
multipliers along with the original problem. The weak constraints have a number of
distinct advantages:

• Very accurate flux computations: the Lagrange multipliers along the constraints
will optimally balance the finite element projection of the applied loads.
• Handle nonlinear constraints. The nonlinear solver in FEMLAB handles linear or
nearly linear standard constraints. Weak constraints can include non-linearities
because they contribute to the stiffness matrix and residual instead of the
constraint matrices.
• Implement constraints including derivatives. In FEMLAB 2.2 and later, the
gradient of the dependent variables are available also on the boundary. Constraints
on only the tangential component of the derivative work when using standard
constraints, whereas you need to use weak constraint to be able to handle
non-tangential constraints.

SPECIFYING WEAK CONSTRAINTS


In the graphical user interface you can add weak constraints by adding the Weak,
boundary constraint application mode in addition to the original application mode.
You can do this in Multiphysics page of the Model Navigator. The variable names in the
weak constraint application modes correspond to the Lagrange multipliers. The weak

1-398 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
application mode will “take over” the constraints in the original application mode
and implement them weakly. The weak constraints are not active by default.

You have to activate them by using the Boundary Settings dialog box on the Boundary
menu. In this dialog box you also specify the variables (and the corresponding
equations) of the constraints. The dialog box also lets you specify if the constraints
are to be “taken over” from the h and r fields (default) or from the constr field. In
all physics modes, constraints are implemented using the h and r fields so you can
normally keep default setting. In addition, you have the ability to choose between a
non-ideal constraint (default) or ideal constraints.

IDEAL VS. NON-IDEAL CONSTRAINTS


Briefly, ideal constraints should give about the same results as using the standard
(pointwise) constraints. When derivatives occur in the constraint, this gives a bad
discretization of the reaction forces, since there will be reaction forces in interior
points. The non-ideal dim constraints will limit the reaction forces to the boundary.

The ideal weak boundary constraint is implemented by adding the weak term

(1) T (1)
∫ν ∫
⋅ R ds – v ⋅ h µ ds
B B

where µ(1) are the Lagrange multipliers and ν(1) the corresponding test functions. R
is the constraint and -h its derivative with respect to the dependent variables. If R
involves also the derivatives of the dependent variables, then there are additional
terms in the second integral to account for this dependence.

MODELING APPROACHES | 1-399


The non-ideal dim constraint is similarly implemented by

(1) (1)
∫ν ∫
⋅ R ds – v ⋅ µ ds
B B

but now there are no additional terms when derivatives occur. This produces a better
discretization when derivatives occur in the constraints.

There are many possible variants of non-ideal weak constraints. The example
“Marangoni Convection” on page 2-321 shows how to use the Weak, boundary mode
to explicitly add a non-ideal weak constraint.

WEAK CONSTRAINTS LIMITATIONS


Weak constraints are more difficult to use than the conventional strong constraints.
Consider the following tips when using weak constraints:

• Strong and weak constraints on the same set of variables on adjacent boundaries
(boundaries that share common node points in the mesh) will not work. This
means that if you need to constrain all boundaries on a solid and want to use a
weak constraint on one boundary segment (one face), you need to use the weak
constraint on the entire boundary of the solid (that is, if the boundary is
connected).
• You must always have a non-zero constraint on the boundaries when you enable
the weak constraint.
• There are sometimes problems with the scaling of the linear systems in
conjunction with weak constraints. Attempt to scale your problem so that all the
dependent variables are of the same magnitude. Also the expected weak constraints
should be of the same order of magnitude.
• Discontinuous constraints will result in (theoretically) infinite Lagrange
multipliers. In practice, you get large oscillations.

• Always use the same shape function type for the weak constraint as for the variables
that you constrain, possibly with lower order elements for the weak constraint. If
you only constrain derivatives, you need to use lower order elements. This is
because the solution derivatives have intrinsically lower order accuracy than the
solution components.
• Iterative solvers have problems with weak constraints since the structure of the
stiffness matrix is very non-diagonal. Use incomplete LU factorization with low

1-400 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
drop tolerance. You most likely need to go for a drop tolerance below the default
1e-2.

WEAK CONSTRAINTS EXAMPLE


This example shows how a constraint in the normal direction on a boundary can be
defined by using a non-ideal weak constraint. The PDE is the Laplace’s equation on
a rectangle.

∆u = 0 on Ω
u=0 on ∂Ω 1
∂u
=0 on ∂Ω 2, 3
∂n
∂u
0 = y– on ∂Ω 4
∂x

Model Navigator
Start FEMLAB and press the Multiphysics tab in the Model Navigator. Select the 2D,
PDE, coefficient form application mode. Use the Lagrange - Quadratic element type.
Press the >> button. Select the Weak, boundary constraint application mode. Use the
Lagrange - Linear element type. Press the >> button. Press OK.

The choice of linear elements for the weak constraint is crucial in this example, since
the solution derivatives have intrinsically lower order accuracy than the solution
components.

Draw Mode
• Draw a single rectangle of any size.

Boundary Mode
• Open the Boundary Settings dialog box.
• Select boundary 4, and check Active. Set the Constraint variable to u. Check Use
constraint specified in constr. Check Non-ideal dim constraints. Press Apply.
• On the Multiphysics menu, select the PDE, coefficient application mode.
• Set the Boundary condition type according to the table. Press the Weak tab. Set the
constr field according to the table. Press OK.

BOUNDARY 1 2-3 4

Type Dirichlet Neumann Neumann


constr 0 0 y-ux

MODELING APPROACHES | 1-401


Strong and weak constraints are mixed in the example but not used on adjacent
boundaries. Also the weak constraints are only activated where constraints are
available. Violating any of these conditions would lead to problems.

Subdomain Mode
• Set the f coefficient to 0. (Laplace’s equation).

Solving
• Press the Solve Problem button.

Post Mode
• Open the Plot Parameters dialog box.
• On the General tab, clear Surface, and check Contour.
• Press the Contour tab. Enter the Contour expression ux. Enter contour levels
-1:0.1:1. (Assuming your rectangle was drawn in the default axis.)

• Press OK.

The contour plot shows that the normal constraint is fulfilled.

For others examples of how to use weak constraints, see “Flow Past a Cylinder” on
page 2-208 and “Marangoni Convection” on page 2-321 in the Model Library.

Accurate Flux Computation


Clearly fluxes can be accurately computed in FEMLAB using higher-order elements
and standard strong constraints. To achieve optimal accuracy, weak constraints can be
used. The Lagrange multipliers are the dependent variables in the weak constraint
application mode. The Lagrange multipliers correspond to the following
postprocessing variables:
TABLE 1-2: PHYSIC MODES INTERPRETATION OF LAGRANGE MULTIPLIERS

PHYSICS MODE NAME QUANTITY CORRESPONDING VARIABLE

AC power electromagnetics Surface current i*omega*Js


Electrostatics Surface charge -nD
density
Magnetostatics Surface current -Js, -Jsx, -Jsy, -Jsz
Conductive media DC Current flux nJ
Heat transfer Heat flux n_flux
Diffusion Flux n_flux

1-402 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
TABLE 1-2: PHYSIC MODES INTERPRETATION OF LAGRANGE MULTIPLIERS

PHYSICS MODE NAME QUANTITY CORRESPONDING VARIABLE

Structural mechanics Force -Fx, -Fy, -Fz


Navier-Stokes Viscous force -Kx, -Ky, -Kz

Only the part of the boundary flux captured by the Lagrange multiplier is computed.
You might have additional flux coming from boundary sources or non-identity
constraint matrices. This should not happen in the Physics application modes
though. For an example of how to use weak constraints for accurate flux
computations, see “Flow Past a Cylinder” on page 2-208 in the Model Library.

FLUX COMPUTATION EXAMPLE


Compute the flux over the constrained boundary of a rectangle. The PDE of the
rectangle is the Poisson’s equation, ∆u=1, with u=0 on the boundary.

Model Navigator
Start FEMLAB and select the 2D, Coefficient, Linear, PDE mode in the Model
navigator. Use the Lagrange - Quadratic element type.

Draw Mode
• Draw a single rectangle of any size.

Solving
• Press the Solve Problem button.

Post Mode
• Open the Subdomain Integration dialog box on the Post menu. Type 1 in the
expression field. Select subdomain 1 and press OK. The area of the rectangle is
shown.
• Open the Boundary Integration dialog box on the Post menu. Select ncu1 in the
expression pop-up menu. Select all boundaries and press Apply. The in-flux over
the boundary is computed by using the boundary coupled equation variable.

The in-flux is approximately equal to the integral of the negative source term in the
Poisson’s equation.

Multiphysics Menu
• Open the Add/Edit Modes dialog box on the Multiphysics menu.
• Select the Weak, boundary constraint application mode. Use the Lagrange -
Quadratic element type. Press the >> button. Press OK.

MODELING APPROACHES | 1-403


Boundary Mode
• Open the Boundary Settings dialog box.
• Select all boundaries, and check Active. Set Constraint variable to u.

Solving
• Press the Solve Problem button.

Post Mode
• Open the Boundary Integration item on the Post menu. Type lm in the expression
field. Select boundary 1 and press Apply. The flux over the boundary is computed
by using the weak constraint variable.

The integral of the flux exactly equals the integral of the finite element projection of
the source term in the Poisson’s equation.

Using Weak Coefficients or the Weak Modes

USE OF WEAK SOLUTION FORM


By using the weak solution form, you can model using one of the strong forms of the
PDE using, for example, the PDE application modes and still take advantage of some
of the abilities of the weak form. All your equations will be automatically converted
to weak fields before FEMLAB solves your problem.

WEAK FORM VS. STRONG FORMS


There are some features in FEMLAB that are only available in either strong or weak
form. When a feature is available in weak form but not in a strong form, you can
always convert to weak form by using the weak solution form, but when a feature is
only available in a strong form, you really must model using this form.

Strong form features


• Adaption considers only the strong form coefficients when computing the error
estimators.
• Streamline diffusion only considers the strong coefficients when contributions are
computed.
• The coupled boundary equation variables are only available for the strong forms.
• The automatic logic for reassembly during time stepping only works for strong
coefficients — any weak contributions makes it necessary to set the reassembly
parameters manually, to speed up the computations.

1-404 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Weak form features
• The weak form automatically computes the Jacobian contributions for all
variables, including coupling variables, contributions from Coefficient M-files,
and also standard variables. The strong forms only consider Jacobian
contributions from coefficients—no Jacobian contributions are computed by
asking field variables for the Jacobian.
Thus, to get the accurate Jacobian when dealing with coupling variables, you might
have to use the weak solution form, but when using the weak form, you lose features
such as adaptivity and automatic streamline diffusion.

For examples of how to use the weak form, see “Implementing a Point Source” on
page 2-84, and “Explicit streamline diffusion” on page 2-99, in the Model Library.

MODELING APPROACHES | 1-405


The Solv ers
This section describes which FEMLAB solver to choose and how to tune its
parameters. The section mostly considers working in the graphical user interface. An
in-depth reference to the solvers and their abilities can be found in Chapter 3 in the
Reference Manual.

Solver Types
Normally you need not worry about which solver to use, since an appropriate default
solver is chosen by the application mode. If you need to select a solver, then the first
question you should ask is whether the problem is stationary or time-dependent.
Most real-world phenomena develops in time, but you might know that the solution
approaches a stationary value. In the time-dependent coefficient form problem,

∂u
da + ∇ ⋅ ( – c ∇u – αu + γ ) + β ⋅ ∇u + au = f
∂t

the stationary solver searches for a solution where ∂u/∂t=0, that is, all time-variation
has ceased. For a stationary problem you have to select either a linear or nonlinear
stationary solver. The time-dependent solver handles both linear and nonlinear
problems.

In some cases, you might want to study natural harmonic oscillations of a


time-dependent problem, so called eigensolutions (with an associated eigenvalue), to
a PDE problem
∇ ⋅ ( – c ∇u – αu + γ ) + β ⋅ ∇u + au = λd a u

This is particularly interesting in electromagnetics, structural mechanics and wave


propagation. To study the eigensolutions, you have to choose the eigenvalue solver.

You can make the solver type choice when selecting application mode in the Model
Navigator. You can also change solver type later on by opening the Solver Parameters
dialog box and selecting the Solver type on the General page. When you select a solver
option in the Model Navigator a particular submode might be associated with that
application mode.

1-406 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
Selecting Solution Form
The choice of Solution form on the General page in the Solver Parameters dialog box
is also related to the linearity of the problem. The solution form can also be set when
selecting application modes in the Model Navigator. The solution form determines the
form that the PDE is converted to before solving. You can use Solution form
Coefficient for linear and almost linear problems. For nonlinear stationary problems,
Solution Form General or Weak are highly recommended. This will ensure that all
information available on the nonlinear behavior of the model is used. Selecting
Coefficient as Solution form for a stationary nonlinear model might cause the iterations
not to converge.

You should also select Solution form General or Weak for nonlinear time-dependent
problems. This is not as critical as for stationary problems, but using Solution form
Coefficient can lead to unnecessary small time steps or failure of the time-stepping
algorithm. When using weak solution form or weak coefficients for time-dependent
problems, you might have to take Manual control of reassembly on the Timestepping
page in the Solver Parameters dialog box.

If you are working with the Numeric option for the Jacobian setting on the General tab,
any solution form can be used.

Using Submodes
The submode mechanism allows for changing the underlying equation in an
application mode. In standard FEMLAB it is used only for wave-extension, that is,
introducing a second order time derivative, by adding an additional equation. The
Coefficient, General and Weak, and Structural mechanics application modes support
this type of submode. You can change submode on the Multiphysics page in the Model
Navigator.

Which Models are Nonlinear?


How do you determine if the problem is linear or nonlinear? This might sound fairly
easy, but it is not always easy to tell; in particular if you are using a physics mode,
where the equations are hidden.

As a basic rule, a physics mode (except Heat transfer and Navier-Stokes) and a PDE
coefficient mode is linear if no coefficient or material property contains a field
variable. In addition, for the heat transfer application mode, the coefficients Ctrans

THE SOLVERS | 1-407


or C must both be zero for the problem to be linear. The Navier-Stokes application
mode is always nonlinear, unless ρ=0, resulting in the special case of the linear Stokes
equations.

When you have set Solution Form to General, you can tell if the problem is linear by
checking the c, α, β, a, g, and h coefficients in Coefficient View. If any of these
coefficients depend on a field variable, the problem is nonlinear, otherwise it is linear.
This criterion can be applied, for example, to the PDE General application mode.
This is a precise criterion for linearity.

Direct Solvers vs. Iterative Solvers


For both the stationary, eigenvalue, and time-dependent solvers, you can choose
between direct and iterative linear solvers. The solvers in FEMLAB always break
down each problem to one or several solutions of linear systems. Thus for any
FEMLAB solver, the choice between direct and iterative solver for the linear systems
affects the solution time and memory requirements.

The direct solvers solve the linear system by Gaussian elimination. This is a stable and
reliable process, and is well-suited for ill-conditioned systems. They require less
tuning and are often faster than the iterative solvers in 1D and 2D. The direct solvers
are default in 1D and 2D. The elimination process sometimes requires large memory
and computing times resources. This is noticeable in particular in 3D. The SuperLU
direct solver, available for MATLAB 6 users, performs somewhat better than the
MATLAB direct solver, in particular for non-definite systems. The present version of
FEMLAB includes the SuperLU algorithm for real systems. Also try SuperLU if you
want to use a direct solver, when you have limited physical memory resources.
SuperLU is able to take advantage of virtual memory efficiently. Do not use the
computer for other purposes when using SuperLU in this way.

The default in 3D is to use iterative solvers. The iterative solvers generally use
substantially less memory than direct solvers, and they are often also faster in 3D. The
iterative solvers need a careful selection of preconditioner for optimal performance.

Selecting Iterative Solver


FEMLAB has three iterative solvers. The Good Broyden iterative solver works well
for most elliptic problems such as the Poisson, Helmholtz, and Navier equations.

1-408 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
The GMRES iterative solver is recommended for the Navier-Stokes equations and
other non-elliptic PDEs. The third solver is transpose-free QMR.

In general, there is no best iterative method. The three methods all have their own
characteristics, and behave differently on each unique problem. It is always possible,
but not easy, to find the best method for a specific problem. This is the reason why
FEMLAB provides a group of solvers to choose from. Expect the solvers to have
similar performance on elliptic problems and a more diverse behavior on difficult,
nonlinear multiphysics problems. Generally, GMRES is considered to be the most
robust solver in the group.

Tuning the Parameters to the Iterative Solvers


The default preconditioner is incomplete LU factorization. This is the most general
preconditioner, and it works well also for difficult problems, but it requires a careful
choice of drop tolerance. The incomplete LU factorization is the preferred
preconditioner for the incompressible Navier-Stokes 3D application mode.

The default drop tolerance is 1e-2. For more difficult problems, this is often too
high. For the default parameter value, the risk of running out of memory is low, so
this value is a good starting point. If you do not get convergence, or you get an error
message, select a lower drop tolerance, for example, 1e-3. As you decrease the drop
tolerance, the memory requirements will increase, but the number of solver iterations
required will be reduced. As the drop tolerance approaches 0, the incomplete LU
factorization will become more and more similar to that of using a complete LU
factorization, which is equivalent to using the direct solver.

The geometric multigrid (GMG) preconditioner is an implementation of the classical


multigrid method. Here it is assumed that a hierarchy of at least two different
discretizations may be created. One level, the fine level, is taken as the given mesh and
elements as chosen for the model by the user. A second level, the coarse level, is then
constructed by either lowering the element order or by coarsening the mesh. The
standard coarse-grid correction can then be applied. Of course, any number of levels
may be used but the quality of the discretization normally prevents a number that is
too large.

GMG is designed for elliptic equations and therefore performs best within this
context. In contrast to the AMG preconditioner, the hierarchy of levels in GMG is
not based on the stiffness matrix and so its performance is less dependent on
couplings between solution components. What is most important is instead the

THE SOLVERS | 1-409


possibility to create the hierarchy of multigrid levels which in practise puts demands
on the geometry. Try first to create only two multigrid levels, preferably by lowering
the element order. If the time used by the setup phase is long or if it uses lots of
memory, this probably comes from the fact that the LU factorization on the coarsest
level is too demanding. Adding one level will normally decrease these demands and
the overall performance is improved. Ideally you will find an optimum number of
levels, yielding fast convergence, low memory demands and a reasonably fast setup
phase.

There is also the possibility of assembling the stiffness matrices on the coarse levels.
Normally, the stiffness matrices at the coarse levels are defined via interpolation of the
stiffnes matrix at the fine level. This procedure is convenient and invariant of scaling,
however it also uses lots of memory due to increased fill-in. A partial solution is to
assemble in some of, or in all, coarse levels. Note that it can be dangerous to use
scaling when coarse assembly is used since the assembly procedure does not account
for this.

GMG is the preferred preconditioner for the structural mechanics 3D application


mode. The GMG preconditioner is not applicable to complex-valued problems or
time-dependent problems.

The algebraic multigrid (AMG) preconditioner is easier to use, since the default
parameters often work well. AMG works best for scalar elliptic PDEs such as the
Laplace and Poisson’s equations, and the total solution time is often faster than what
you can achieve by using the incomplete LU factorization preconditioner. AMG is
the preferred preconditioner for Electrostatics, Conductive media DC, Heat transfer,
and Diffusion 3D application modes. The AMG preconditioner is not applicable to
complex-valued problems or time-dependent problems.

The SSOR and diagonal scaling preconditioners also work well for the Laplace and
Poisson’s equations. They normally result in longer computing times than the AMG
preconditioner, but the solution process will require less memory.

The preconditioner and its parameters will influence the total number of iterations
required. For diagonal scaling, SSOR, and incomplete LU with a high drop
tolerance, several hundred iterations may be needed. Increasing the Restart value for
the iterative solver often leads to faster convergence in such cases, but more memory
will be used. The default value is 10, but you can expect to find an optimal value
somewhere between 10 and 50.

The mesh quality is important for the iterative solvers. If you increase the mesh
quality, the iterative solver will use fewer iterations. You can also use a higher drop

1-410 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
tolerance, and thus use less memory. If the mesh quality is below 0.3, for 3D models,
or 0.6, for 2D models, try to improve it by manipulating different parameters in the
Mesh Parameters dialog box. Often selecting a finer mesh and selecting lower mesh
growth rate will increase quality.

Choosing a better initial value will also reduce the number of iterations. The ideal
initial value is one that resembles the final solution as much as possible. This might
of course be difficult to achieve, but a good initial value can sometimes be generated
by solving a simplified version of the original problem.

Adaptive Meshing
When modeling, you often want to study a particular quantity and to select a mesh
that minimizes the error in this quantity. FEMLAB has several ways of setting the
mesh size manually. It is not easy to specify mesh size manually to minimize the error
in the desired quantity. Adaption helps you do this. The choice of error estimate
determines the quantity for which you minimize the error.

• The linear functional error estimator computes an error estimate based on the
linear functional
∂ul
Ψ( u) = ∫ fl ul dA + ∫ γlj ∂ xj dA + ∫ gl ul ds
Ω Ω ∂Ω

Thus by specifying a non-zero f or Γ, you can make the error estimate in terms of
the solution or its gradient, respectively. By specifying different values for f or Γ
(including zero) on different subdomains, you can put different weights on
different parts of the geometry. The linear function error estimator is expensive to
compute since an additional linear system will be solved.
• Use the energy norm if you want to compute a quantity related to energy, in
problems that have a corresponding energy minimization problem. In such cases,
the FEM solution will correspond to the solution of this minimization problem.
For example, in structural mechanics the energy norm is related to the stresses, and
the FEM solution corresponds to a configuration of stresses that minimizes the
energy of the system. The energy must be semi-definite for this error estimator to
work.
• Use the L2 norm error estimator to get a general, fast to compute error estimator,
that adapts on the solution components and not a quantity related to its gradient.

THE SOLVERS | 1-411


1-412 | U S E R ’S G U I D E AN D I N T RO D UC T I O N
I N D E X
1 variable coefficient form PDE applica- selecting all 1-103
tion mode 1-356 algebraic multigrid preconditioner 1-132,
1 variable general form PDE application 1-410
mode 1-366 ambient temperature 1-245
1D geometry object 1-171, 1-208 AMG preconditioner 1-132, 1-410
2 variable coefficient form PDE applica- Ampère’s law 1-249
tion mode 1-360 analysis capabilities 1-241
2 variable general form PDE application analyzed geometry 1-321
mode 1-369 angular frequency 1-262, 1-268
2D draw toolbar 1-76 animation 1-58, 1-78, 1-150, 1-163, 1-384,
2D geometry object 1-170 1-393
2D graphical interface 1-71 anisotropic
2D plot toolbar 1-78 diffusion 1-359
3D draw toolbar 1-83 material 1-246, 1-248, 1-252, 1-256,
3D geometry object 1-206 1-263, 1-362
visualization 1-86 annotations 1-138
3D graphical interface 1-82 ans variable 1-48, 1-136
3D plot toolbar 1-85 antennas 1-14
3D primitives 1-187 antisymmetry boundary condition 1-244,
3D view 1-92 1-248, 1-258, 1-261, 1-263
changing 1-92 API 1-10, 1-65
explicit setting 1-94 appl2fem 1-315, 1-322

A absorption coefficient 1-348 Application 1-65

absorption term 1-363 application mode 1-241

AC power electromagnetics application 1 variable coefficient form PDE 1-356,


1-366
mode 1-259
Active in this domain check box 1-352 1 variable general form PDE 1-366

active subdomain 1-352 2 variable coefficient form PDE 1-360

adaption 1-411 2 variable general form PDE 1-369

adaptive meshing 1-411 AC power electromagnetics 1-259

adaptive solver 1-411 adding 1-139

Add/Edit Constants dialog box 1-31 classes 1-315

Add/Edit/Delete Work Plane dialog box Coefficient form 1-239, 1-278, 1-281,
1-360, 1-366, 1-367, 1-401, 1-403
1-188, 1-201
adjacency selection methods 1-102 Conductive media DC 1-262, 1-319

adjacent objects Diffusion 1-247

, 1 ' ( ; | 

Electrostatics 1-254 beam cross section library 1-15
field 1-322 beam element 1-14
General form 1-366, 1-369, 1-386 beams 1-24
Geometry only 1-172, 1-191, 1-200, Bézier curve 1-180, 1-182
1-225, 1-229, 1-287 bilinear interpolation 1-229
Heat transfer 1-27, 1-138, 1-154, 1-156, birefringence 1-23
1-243, 1-305, 1-321 BMP 1-220
Incompressible Navier-Stokes 1-27, body forces 1-265
1-271 Boolean operations 1-115, 1-170
Magnetostatics 1-256 borders 1-199
multiple component 1-356, 1-360, internal 1-172, 1-179, 1-199
1-369 bound charges 1-254
name 1-29 boundary absorption coefficient 1-349
object 1-315 boundary absorption term 1-365
Plane strain 1-270 boundary arrows 1-354
Plane stress 1-269 boundary coefficients 1-49, 1-318
Structural mechanics, 3D 1-268 boundary condition 1-126, 1-306, 1-318,
structure 1-303, 1-314 1-337
variable 1-81, 1-355, 1-360, 1-365, 1-371 antisymmetry 1-244, 1-248, 1-258,
Application Program Interface 1-10, 1-65 1-261, 1-263
application scalar variable 1-262, 1-316 Dirichlet 1-241, 1-305, 1-337
application structure 1-303, 1-314 generalized Neumann 1-337
arc 1-180 grouping 1-321
circular 1-182 mixed 1-337
area 1-403 Neumann 1-241, 1-337
Argyris element 1-19 periodic 1-79, 1-236
Arrhenius law 1-379 Robin 1-337
arrow plot 1-42, 1-133 setting 1-35
arrows, adding 1-138 symmetry 1-244, 1-247, 1-258, 1-263,
ASCII 1-152, 1-153, 1-294, 1-295 1-274
associative geometry 1-19, 1-238 boundary coupled equation variable
Auto highlight property 1-87 1-355, 1-403
automatic scaling 1-18 boundary coupled shape variable 1-355
axis settings 1-32, 1-115 boundary elements 1-91
Axisymmetry 1-283 boundary integration 1-47, 1-136, 1-312
Boundary menu 1-73
B B/H-curve 1-291
boundary mode 1-35, 1-79, 1-109, 1-126
balance of force equations 1-265
boundary modeling 1-170, 1-180, 1-200
bars 1-24

 | , 1 ' ( ;
boundary parameterization variable composite solid object 1-170
1-353 compressible Euler equations 1-21
boundary representation 1-172, 1-190 compressible Euler flow 1-13
boundary selection methods 1-104 compressible flow 1-20
Boundary Settings dialog box 1-35, 1-127 computational fluid dynamics 1-271
boundary source term 1-349, 1-365 computer aided design 1-9, 1-170
Boussinesq approximation 1-28 concentration 1-247, 1-378
Brinkman equation 1-13 concentration gradient 1-248
buoyancy force 1-28, 1-44 conduction 1-379
bus bar 1-109, 1-138 Conductive media DC application mode
1-109, 1-262, 1-319, 1-321
C CAD 1-9, 1-170
conductivity 1-250, 1-262
Camera menu 1-324
electric 1-128
cavity resonators 1-14
thermal 1-243
CFD 1-271
confirming selections 1-98
chamfer 1-193
conic sections 1-183
Chemical Engineering Module 1-8, 1-12,
conservative convective flux 1-362
1-64, 1-243, 1-246, 1-271
normal component 1-365
chemical reaction kinetics 1-13
conservative flux 1-348
circle 1-183
conservative flux convection coefficient
circular arc 1-182
1-348
Classical PDEs 1-239
conservative flux source 1-363
classical PDEs 1-64, 1-349
normal component 1-365
Coefficient form
conservative flux source term 1-348
application mode 1-239, 1-278, 1-281,
constant 1-113, 1-352
1-356, 1-360, 1-366, 1-367, 1-401,
Add/Edit Constants 1-113
1-403
defining 1-31
PDE mode 1-278, 1-281, 1-401, 1-403
constitutive relations 1-250
coefficient form 1-6, 1-305, 1-336, 1-343,
constraint
1-346, 1-347, 1-348, 1-368, 1-406
edge 1-398
coefficient view 1-49
point 1-232, 1-398
Coerce to Curve 1-181
continuous rotation 1-94
Coerce to Solid 1-126, 1-181, 1-204
contour 1-227
combustion 1-379
contour curves in images 1-221
Command Window 1-31
contour plot 1-80
command-line functions 1-378
contourc 1-227
complex numbers 1-127
control polygon 1-182, 1-183
complex permittivity 1-260
Control System Toolbox 1-9
composite geometry object 1-180, 1-200

, 1 ' ( ; | 

control vertices 1-179, 1-182, 1-183 current density 1-249, 1-256, 1-262
conv2 1-222, 1-231 normal component 1-263
convection 1-12, 1-379 curve
convection and diffusion 1-13 parameterization 1-235
convection coefficient 1-50, 1-348 curve elements 1-91
convection term 1-363 curve object 1-180
convection-diffusion process 1-378 curve parameterization varaible 1-353
convection-reaction equation 1-350 curve segment 1-182
convective heat transfer coefficient 1-245 curve3 1-170
convergence analysis 1-44 cycle adjacent objects 1-103
conversion between solution forms
D da coefficient 1-337, 1-344
1-368
DAE 1-57, 1-148, 1-344
coordinate system, work planes 1-188
Darcy’s law 1-13, 1-246
copy button 1-74
degree, of rational Bézier curve 1-183,
coupling
1-206
local 1-320
degrees of freedom 1-132, 1-355
non-local 1-153
density 1-243, 1-267, 1-271
coupling variable 1-113, 1-140, 1-276,
space charge 1-254
1-310, 1-311, 1-313, 1-355, 1-405
surface charge 1-255
creating 1-145
dependent variable 1-241, 1-350, 1-355
destination 1-276
default name 1-315
Dirichlet boundary condition 1-286
naming 1-29
extrusion 1-280
derivative
Jacobian 1-285
of interpolation function 1-297
projection 1-283
test function 1-372
scalar 1-277
time 1-372
source 1-276
deselect all 1-100
Create Composite Object 1-218
deselecting objects 1-100
cross-section plot 1-44, 1-132, 1-151,
destination transformation 1-281
1-384
desuppressing objects 1-107
Cross-Section Plot Parameters dialog
diagonal scaling preconditioner 1-410
box 1-46, 1-59
dielectric
cubic Bézier curve 1-184
conductor 1-253
cup mixing temperature 1-47
losses 1-260
CUR 1-220
media 1-255
current
difference 1-35, 1-76, 1-83, 1-116, 1-117,
source 1-262
1-125, 1-126, 1-170, 1-172, 1-173,
steady 1-262
1-177, 1-191, 1-195, 1-196, 1-197,

 | , 1 ' ( ;
1-199, 1-212 dweak edit field 1-372
differential-algebraic equation 1-57, DXF file 1-81, 1-170, 1-209
1-148, 1-344 advanced import 1-210
differentiation rules 1-296, 1-298 advanced properties 1-211
diffusion 1-12, 1-13, 1-380 importing 1-209, 1-214
anisotropic 1-359 layers 1-211
coefficient 1-247, 1-348, 1-359 dynamic viscosity 1-28, 1-271, 1-273
isotropic 1-359 dynamical system 1-154
Diffusion application mode 1-247
E Edge Angle page 1-201
diffusive flux 1-248, 1-360, 1-361
edge constraint 1-398
anisotropic material 1-362
edge load 1-398
component magnitude 1-366
Edge menu 1-73
normal component 1-364
edge mode 1-109
dimensionless variables 1-379
edge segment 1-172
dipole
edges, rendering and highlighting 1-87
magnetic moment 1-257
edit buttons 1-74
direct solvers 1-408
Edit menu 1-72
Dirichlet boundary condition 1-241,
editing geometry object 1-178, 1-198
1-305, 1-337, 1-364, 1-370
eigenfrequency 1-268
dispersive materials 1-252
eigenvalue problem 1-268, 1-345
divergence 1-28
elasticity modulus 1-266
operator 1-363
elcplextr 1-280, 1-283
theorem 1-346
electric
documentation 1-10
conductivity 1-320
Documentation button 1-68
current 1-320
dolly 1-93
displacement 1-249, 1-256
domain number variable 1-355
field intensity 1-249, 1-254, 1-262
domain properties 1-317
flux density 1-249
domains 1-351
polarization 1-250
double-clicking, 3D 1-101
resistance 1-320
Draw menu 1-73
space charge density 1-249
draw mode 1-33, 1-79, 1-108, 1-114, 1-182
electrical heating 1-143
draw toolbar 1-76, 1-116
electrochemical cell 1-21
2D 1-76
electrokinetic flow 1-21
3D 1-83
electrolysis 1-12, 1-21
work plane 1-83
Electromagnetics Module 1-8, 1-13, 1-64,
drilling holes 1-191
1-249
drop tolerance 1-409
electroneutrality 1-21

, 1 ' ( ; | 

electroosmotic flow 1-21 in points 1-234
electrostatic exact Jacobian 1-285
potential 1-251, 1-254 Excel 1-152, 1-294
Electrostatics application mode 1-254, exothermic reaction 1-21
1-305 explicit streamline diffusion 1-19
element Explicit View Settings dialog box 1-94
beam 1-14 export to workspace
default settings 1-316 FEM structure 1-234
displaying number 1-80 geometry object 1-233
higher order 1-42, 1-112, 1-132, 1-402 exporting data 1-81
Lagrange - p2-p1 1-30 to text file 1-152, 1-153
maximum edge size variable 1-354 expression
mesh selection 1-91 MATLAB 1-81, 1-350
plate 1-14 variable 1-113, 1-128, 1-352, 1-355
quadratic 1-292, 1-306, 1-386 extended FEM structure 1-311, 1-313
quality 1-91 extended multiphysics 1-276
selecting 1-30 external temperature 1-245
shell 1-15 extrude 1-198
Element refinement level 1-42, 1-288 Extrude dialog box 1-120, 1-193
ellipse 1-183
F face
elliptic PDE problem 1-18
parameterization 1-235
embed 1-125
face object 1-200
point in 3D 1-141
face segment 1-190
embed 1-205
face3 1-206
enable borders 1-104
faces, rendering and highlighting 1-87
energy equations 1-13
Faraday’s law 1-249
energy norm 1-411
FEM 1-6, 1-39, 1-130
energy transport 1-378
FEM resolution 1-288
enumeration of subdomains and edges
FEM structure 1-301, 1-305, 1-322
1-321
export to workspace 1-234
equation of continuity 1-249
femeig 1-307
equation variable 1-355, 1-359, 1-361
femlab 1-28
equation-based modeling 1-378
FEMLAB API 1-65
error estimator 1-411
FEMLAB functions 1-10, 1-11, 1-303
Euler beam 1-15, 1-24
FEMLAB Help Desk 1-76
Euler equations 1-21
FEMLAB PDE Language 1-336
Euler flow 1-13
FEMLAB session, saving 1-49
evaluation
FEMLAB Subsystem 1-163

 | , 1 ' ( ;
FEMLAB window 1-31 Fourier’s law of heat conduciton 1-243
femtime 1-307 free convection heat transfer 1-26
ferromagnetic materials 1-259 frequency
field variable 1-355 angular 1-262
figure window, plot in separate 1-137 frequency response 1-15
file handling buttons 1-74 fuel cell cathode 1-21
File menu 1-72 fuel cells 1-12
fillet 1-197
G Gauss’ law 1-249, 1-346
film conductance 1-263
General form
filter2 1-222, 1-231
application mode 1-366, 1-369, 1-386
fine-tuning view 1-93
general form 1-6, 1-49, 1-336, 1-340,
finite element method 1-6, 1-39, 1-130
1-344, 1-382
first order derivative components 1-358
generalized Neumann boundary condi-
first-order time derivative 1-345
tion 1-337, 1-364, 1-370
fixed-bed tubular reactor 1-21
geom field 1-303
flattened corner 1-193
geomcoerce 1-182, 1-198
flcontour2curve 1-227
geomcomp 1-177
fldae 1-307, 1-344
geomcsg 1-321
fldaek 1-307
geometric multigrid preconditioner 1-18
fldaspk 1-307, 1-344
geometric variable 1-352
flim2curve 1-221, 1-222
plotting 1-235
flinterp1 1-297, 1-298
geometry model 1-303
flmesh2spline 1-222, 1-227
geometry modeling
floating contact 1-279
1D 1-207
flow in an open channel with porous
2D 1-171
walls 1-20
3D 1-186
flow plot 1-133, 1-134
geometry object 1-170
fluid dynamics 1-12, 1-26, 1-271
1D 1-171, 1-208
fluid mechanics 1-271
2D 1-170
fluid statics 1-271
3D 1-206
flux 1-247, 1-348
composite 1-180, 1-200
conservative 1-348
default names 1-171, 1-187
diffusive 1-248, 1-360, 1-361
editing 1-178, 1-198
normal 1-371
exporting to workspace 1-233
vector 1-341, 1-369, 1-371
insert from workspace 1-234
force
properties 1-178, 1-198
viscous 1-274
scaling 1-119
force calculations 1-23
split 1-179, 1-196, 1-199

, 1 ' ( ; | 

suppressing 1-106 coefficient 1-141, 1-245
visualization 1-86 equation-based model 1-379
Geometry only application mode 1-172, free convection 1-26
1-191, 1-200, 1-225, 1-229, 1-287 Heat transfer application mode 1-27,
geometry plot 1-306 1-138, 1-154, 1-156, 1-243, 1-305,
geometry visualization mesh detail 1-89, 1-319, 1-321
1-332 Helmholtz’s equation 1-260, 1-348, 1-349
geomplot 1-306 help button 1-76
geomspline 1-225 Help menu 1-73
geomsurf 1-228 Hermite element 1-19
GIF 1-220 heterogeneous catalysis 1-12
GMG preconditioner 1-18, 1-409 higher-order elements 1-42, 1-112, 1-132,
gradient 1-320 1-402
components 1-358 highlighting 1-86
magnitude 1-366, 1-371 hold on 1-45
temperature 1-243 Hooke’s law 1-266
graphical user interface 1-5, 1-9, 1-71 hybrid-mode waves 1-22
graphics objects hyperbola 1-183
regenerate 1-90 hysteresis 1-291
remove from memory 1-90
I ICO 1-220
Grid 1-33, 1-115
IGES file 1-81, 1-170, 1-213
grid settings 1-32, 1-115
format 1-213
GUI 1-5, 1-9, 1-71
import 1-213
modes 1-78
image
preferences 1-70
filtering 1-222
settings 1-70, 1-115
reducing noise 1-222
H HDF 1-220 image 1-220
headlight 1-88 image contour curves 1-221
Headlight button 1-135 image import 1-220
heat capacity 1-143, 1-156, 1-243 image processing 1-221
heat conduction 1-13 Image Processing Toolbox 1-221
heat convection and conduction 1-13 imagesc 1-220
heat equation 1-243, 1-350 imcontour 1-221, 1-227
heat flux 1-243, 1-245 imfinfo 1-220
heat flux vector 1-28 impedance boundary condition 1-23
heat production 1-379 impervious boundary 1-247
heat source 1-156, 1-320 importing data 1-81
heat transfer 1-12, 1-26 from text file 1-294, 1-295

 | , 1 ' ( ;
image 1-220 interpolation 1-310
MRI 1-222 curve objects 1-225
imread 1-220 material parameters 1-287
imwrite 1-220 of surfaces 1-228
incomplete LU factorization 1-132, 1-409 PDE coefficients 1-287
incomplete LU preconditioner 1-132, intersection 1-76, 1-83, 1-116, 1-117,
1-409 1-170, 1-172, 1-174, 1-177, 1-191,
incompressible flow 1-271 1-197, 1-199
Incompressible Navier-Stokes applica- isosceles control polygon 1-182
tion mode 1-27, 1-271 isosurface plot 1-133, 1-134
incompressible turbulent flow 1-20 isotropic diffusion 1-359
ind field 1-321 iterative eigenvalue solver 1-18
independent variable 1-81, 1-350 iterative solvers 1-408
index vector 1-318
J Jacobian 1-139, 1-285, 1-405
inflection point 1-183
exact 1-285
inhomogeneous materials 1-252, 1-287
numerical 1-407
initial condition 1-130
JPEG 1-220
grouping 1-321
K keep internal borders 1-179, 1-199
initial mesh 1-307
k-epsilon turbulence model 1-13
initial values
kinetics 1-13
setting 1-37
Kirchhoff plate 1-15
insert from workspace
geometry object 1-234 L L2 norm 1-411
installation, of FEMLAB 1-16 labels, rendering and highlighting 1-87
insulating boundary 1-263 Lagrange element 1-306, 1-316
insulation/symmetry quadratic 1-292, 1-386
Cunductive media DC 1-127 Lagrange multiplier 1-337, 1-399
Heat transfer 1-142 Laplace operator 1-349
integral constraint 1-280 Laplace’s equation 1-349, 1-410
integrating 1-310 large models 1-18
on boundary 1-47, 1-135, 1-136, 1-312 lighting 1-88
on subdomain 1-310 flat 1-88
on surface 1-310 Gouraud 1-88
integration by parts 1-346 model 1-88
internal border 1-117, 1-172, 1-179 Phong 1-88
deleting 1-118 line 1-180
interp1 1-299 line integrals 1-312
interp2 1-287 line plot 1-19

, 1 ' ( ; | 

linear material properties 1-127
functional 1-411 different 1-179, 1-199
problem 1-337 inhomogeneous 1-287
stationary solver 1-406 nonlinear 1-291
lines, adding 1-138 setting 1-37
list box selections 1-101 MATLAB 1-8
load direct solver 1-408
edge 1-398 expression 1-81, 1-128, 1-350
point 1-398 main workspace 1-72
load -ascii 1-294 output format 1-312
loading model 1-54, 1-139 MATLAB Command Window 1-31,
lock in selections 1-98 1-137
loft 1-221 MATLAB figure window 1-137
losses MATLAB M-file 1-49, 1-138
dielectric 1-260 MATLAB prompt 1-31
ohmic 1-260 maximum edge size for elements variable
polarization 1-260 1-354
LU Maxwell’s equations 1-254, 1-259
incomplete factorization 1-132, 1-409 Maxwell’s stress tensor 1-23
luinc 1-132, 1-409 Maxwell-Ampère’s law 1-249
lumped resistance 1-135 Maxwell-Stefan convection and diffusion
1-13
M magnetic
Maxwell-Stefan diffusion 1-20
dipole moments 1-257
memory-saving techniques 1-90
field intensity 1-249, 1-256
MEMS 1-14
flux density 1-249, 1-256, 1-262
menu bar 1-71
vector potential 1-251, 1-256
mesh 1-39, 1-306, 1-308, 1-310
magnetic potential 1-23
buttons 1-75
magnetization vector 1-250, 1-256
mode 1-39, 1-79, 1-80, 1-109, 1-130
magnetostatic model 1-23
quality 1-91
magnetostatic problems 1-23
Mesh menu 1-73
Magnetostatics application mode 1-256
Mesh Parameters dialog box 1-39, 1-130
main axes area 1-72
Mesh Visualization Parameters dialog
main workspace 1-72
box 1-90
mass coefficient 1-337, 1-343, 1-348
meshextend 1-307
mass matrix 1-148, 1-337, 1-343
meshinit 1-307
mass term 1-361
meshplot 1-307
mass transfer 1-12
meshrefine 1-306
material library 1-15

 | , 1 ' ( ;
Message Log 1-72, 1-80 import of 1-222
meta variable multidisciplinary 1-8, 1-156
shape function time derivative 1-372 model 1-154
test function 1-372 multiphysics 1-7, 1-27, 1-110, 1-138, 1-242,
metallic conductors 1-263 1-322
micro electro-mechanical systems 1-14 extended 1-276
microwave engineering 1-14, 1-249 model 1-321, 1-394
microwave waveguides 1-22 Model Navigator tab 1-29
migration 1-12 multiphysics 1-315
Mindlin plate 1-15 Multiphysics page 1-69
mirror geometry object 1-119 multiple component
miscellaneous variable 1-354 application mode 1-356, 1-360, 1-369
mixed boundary condition 1-337 multiple selections 1-97
mixer 1-21
N naming convention
mode analysis 1-14, 1-23
variable 1-366
mode navigation buttons 1-76
Navier’s equations 1-266
model description 1-10, 1-68
Navier-Stokes equations 1-13, 1-271
model image 1-9, 1-68
Nernst-Planck transport equations 1-13,
Model Library 1-7, 1-10, 1-63, 1-65
1-20
models 1-66
Neumann boundary condition 1-241,
page 1-65
1-337, 1-364, 1-370
path 1-69
New page 1-64, 1-112
Model MAT-file 1-49, 1-81, 1-138
Newton’s law of cooling 1-245
Model M-file 1-10, 1-49, 1-51, 1-81, 1-138
noise
Model Navigator 1-29, 1-63, 1-108, 1-112
reducing, in point data 1-227
model simplification
non-ideal dim constraint 1-400
3D to 1D 1-378
nonlinear
3D to 2D 1-26
expression 1-128
symmetry planes 1-27
material 1-252, 1-291
models 1-66
model 1-109
modes 1-78
problem 1-337
modules 1-8, 1-12, 1-64
problem, difficult 1-18
momentum balance 1-27
solver 1-246, 1-259, 1-406
momentum equations 1-13
stationary solver 1-406
monoconical RF antenna 1-23
non-Newtonian flow 1-13
mouse movement actions 1-93
non-Newtonian fluid 1-20, 1-273
move as box 1-93
normal component
MRI data 1-220
conservative convection term 1-365

, 1 ' ( ; | 

conservative source term 1-365 output format 1-312
current density 1-263 output times 1-56, 1-147
diffusion term 1-364 overlapping objects 1-96
variable 1-354
P pan 1-93
normal flux term 1-371
continuous 1-94
normal vector 1-354, 1-364, 1-370
parabola 1-183
no-slip boundary condition 1-274
parameter sweep 1-18
number of element
parameterization 1-235
displaying 1-80
parameterized models 1-10, 1-49, 1-54,
numerical Jacobian 1-407
1-138
numerical value
parametric solver 1-18, 1-23
displaying 1-80
partial differential equation 1-6
NURBS 1-206
paste button 1-75
O ODE solvers 1-344 patch plot 1-91
ode15s 1-344 PCX 1-220
ohmic losses 1-260 PDE 1-6, 1-249, 1-340
ohmic resitance 1-261 classical 1-64, 1-349
on-line coefficient names 1-348
documentation 1-68 coefficients 1-306
FEMLAB manuals 1-11 modes 1-9, 1-239
help 1-11 stationary 1-406
OpenGL 1-324 system 1-378
renderer 1-89 time-dependent 1-406
optical fibers 1-14 PDE coefficients 1-49, 1-127
optical mode analysis 1-23 coefficient view 1-49
optics 1-22 grouping 1-321
optimal design 1-49, 1-54, 1-138 PDE mode
options and settings 1-31, 1-108, 1-113 Coefficient form 1-239, 1-278, 1-281,
Options menu 1-31, 1-72 1-356, 1-360, 1-366, 1-367, 1-401,
orbit 1-93 1-403
continuous 1-94 General form 1-366, 1-369, 1-386
scenelight 1-93 PDE modes 1-64
scenelight, continuous 1-94 PDE term
Orbit/Pan/Zoom page 1-88, 1-93 absorption 1-363
orbit/pan/zoom toolbar 1-84 conservative convection 1-362
orthographic projection 1-93 conservative source 1-363
outflow/pressure boundary condition convection 1-363
1-36 diffusion 1-361

 | , 1 ' ( ;
mass 1-361 flow 1-133, 1-134
source 1-364, 1-370 geometry 1-306
Peclet number 1-379 in separate figure window 1-136
perfect conductor 1-253 isosurface 1-133, 1-134
Performance page 1-89 keeping the previous 1-45
periodic boundary condition 1-79, 1-236 slice 1-133
permanent magnet 1-23 solution 1-41, 1-307, 1-309
permeability 1-256, 1-259 surface 1-42, 1-133
of vacuum 1-250, 1-257, 1-260 tetrahedron 1-133
relative 1-250, 1-257, 1-260 time evolution 1-58
permittivity 1-254, 1-259 toolbar 1-78, 1-133
of vacuum 1-250, 1-254, 1-260 toolbar, 2D 1-78
relative 1-250, 1-254, 1-260 toolbar, 3D 1-85
perspective projection 1-93, 1-333 without solving 1-235
phase 1-376 Plot menu 1-73
phasor variable 1-376 Plot Parameters dialog box 1-42, 1-133
photonic waveguide 1-23 PNG 1-220
photonics 1-14, 1-22, 1-249 point 1-157
physics mode 1-9, 1-64, 1-239 point constraint 1-232, 1-398
AC power electromagnetics 1-259 point data
Conductive media DC 1-262, 1-319 for creating geometry models 1-227
Diffusion 1-247 point evaluation 1-234
Electrostatics 1-254 point insertion 1-232
Heat transfer 1-156, 1-243 point load 1-398
Incompressible Navier-Stokes 1-271 Point menu 1-73
Magnetostatics 1-256 point mode 1-109
Plane strain 1-270 point sources 1-232
Plane stress 1-269 Poisson’s equation 1-132, 1-305, 1-310,
Structural mechanics, 3D 1-268 1-349, 1-410
plane strain 1-23 on a cylinder 1-308
Plane strain application mode 1-270 on unit disk 1-306
Plane stress application mode 1-269 Poisson’s ratio 1-266
plate element 1-14 polarization
plot losses 1-260
animation 1-58, 1-150 vector 1-254
arrow 1-42, 1-133 polymer solution 1-20
buttons 1-75 polynomial function 1-355
cross section 1-44 porous media 1-13

, 1 ' ( ; | 

Post menu 1-73 patch 1-205
post mode 1-41, 1-57, 1-79, 1-80, 1-109, surface 1-205
1-132 reaction engineering 1-12
posteval 1-234, 1-309, 1-310 reaction enthalpy 1-379
postint 1-309, 1-310 rectangle 1-117
postinterp 1-310 Refine Mesh 1-45
postmovie 1-310 reflection type 1-88
postplot 1-308, 1-310 relative permeability 1-257, 1-260
postprocessing 1-276, 1-307, 1-309 relative permittivity 1-254, 1-260
advanced 1-44 rendering 1-86, 1-89
postsurf 1-308 Rendering/Selection page 1-86
potential resistance
electrostatic 1-254 lumped 1-135
magnetic 1-256 resistive heating rate 1-261, 1-262
potential flow 1-246 resolution
preconditioner 1-132, 1-409 FEM 1-288
algebraic multigrid 1-410 revolve 1-194, 1-198
AMG 1-132 Revolve dialog box 1-194
diagonal scaling 1-410 Reynolds number 1-272
GMG 1-409 RF 1-23
incomplete LU 1-132, 1-409 Robin boundary condition 1-337
SSOR 1-410 rotation
preference file 1-69 continuous 1-94
Preferences page 1-64, 1-69 rounded corners 1-182
pressure 1-271 rubberband box 1-80, 1-98
printing 1-329
S s1 1-235
programming language 1-10, 1-71, 1-197,
s2 1-235
1-301, 1-303
save -ascii 1-152
Project Work Plane Intersection 1-122
saving model 1-49
projection
scalar magnetic potential 1-23
3D view 1-93
scaling 1-18
of 3D geometry 1-84
dimensionless 1-379
work plane 1-189
geometry object 1-119
Q quadratic element 1-292, 1-306, 1-386 scenelight 1-88, 1-135
quick start 1-26 orbit 1-88, 1-93
Schrödinger equation 1-350
R radiative heat transfer 1-245
script
rational Bézier
programming 1-10
curve 1-182

 | , 1 ' ( ;
second order derivative components simplified model
1-359 3D to 1D 1-378
second-order time derivative 1-345 3D to 2D 1-26
Select All 1-97 symmetry planes 1-27
select button 1-74 Simulink 1-9, 1-153
select toolbar 1-85 Simulink export 1-163
selecting single selection, 3D 1-95
2D objects 1-80 slice plot 1-133
3D objects 1-95, 1-96 slip boundary condition 1-273
adjacent objects 1-102 snap curves 1-212
all adjacent objects 1-103 snap to grid 1-114
confirming objects 1-98 solid
current suppression 1-107 3D object 1-190
cycle adjacent objects 1-102 circle 1-172, 1-192
deselecting objects 1-100 coerce to 1-181, 1-204
double-clicking objects 1-101 ellipse 1-178
multiple objects 1-80, 1-97 modeling 1-170
objects by clicking 1-87 object 1-172, 1-310
objects in a list box 1-101 rectangle 1-172
objects, cycle overlapping 1-96 trimming 1-174
overlapping objects 1-96, 1-101 solution component 1-55
shortcuts for objects 1-104 number 1-356
status bar indication for objects 1-96 solution form 1-407
separate figure window 1-136 coefficient 1-351, 1-368, 1-407
separation processes 1-12 conversion between 1-368
session, saving 1-49 general 1-351, 1-368, 1-407
setting boundary conditions 1-35 weak 1-278, 1-285, 1-351, 1-372, 1-407
setting material properties 1-37 solution gradient 1-360
shape function solution plot 1-307, 1-309
time derivative meta variable 1-372 solution value, display 1-80
variable 1-355, 1-358, 1-360, 1-369 solve buttons 1-75
shear modulus 1-266 Solve for Variables 1-55
shear strain 1-265 Solve menu 1-73
shear stress 1-265 solve mode 1-41, 1-55, 1-79, 1-109
shear-rate dependent viscosity 1-273 solver
Shell 1-24 adaptive 1-411
shell element 1-15 iterative 1-132
shock waves 1-21 linear 1-132

, 1 ' ( ; | 

parameters 1-132 Plane stress application mode 1-269
preconditioner 1-132 Structural Mechanics Module 1-8, 1-14,
time-dependent 1-147 1-64, 1-264
Solver Parameters dialog box 1-56, 1-246 subdomain 1-179, 1-199
Solver type 1-56 integral 1-310
solving a model 1-41 settings 1-317
source 1-282 Subdomain menu 1-73
point 1-232 subdomain mode 1-37, 1-79, 1-109, 1-127
source term 1-348, 1-364, 1-370 Subdomain Settings dialog box 1-37,
Source transformation 1-280 1-128
space charge density 1-254 SuperLU direct solver 1-408
space coordinate variables 1-353 supersonic speed 1-21
space dimension 1-353 suppressing 1-106
S-parameter analysis 1-23 adjacent objects 1-88, 1-106
specific heat 1-243 boundaries 1-107
Specify Geometry dialog box 1-208 geometry objects 1-106
spline interpolation 1-225 invert objects 1-107
split geometry object 1-179, 1-196, 1-199 objects 1-88, 1-106
SSOR preconditioner 1-410 objects, cycle 1-107
starting FEMLAB 1-28 objects, none 1-107
state-space model 1-164 subdomains 1-107
stationary PDE 1-406 surface charge density 1-253, 1-255
stationary solver 1-406 surface current 1-253
stationary value 1-406 surface integral 1-310
status bar 1-72 surface interpolation 1-228
steady current 1-262 surface plot 1-42, 1-80, 1-133
Stokes equations 1-408 symmetry boundary condition 1-244,
streamline diffusion, explicit 1-19 1-247, 1-258, 1-263, 1-274
stress equilibrium conditions 1-265, symmetry planes 1-27
1-267
T tangent variable 1-354
stress matrix 1-264
temperature 1-379
stress-induced birefringence 1-23
temperature coefficient 1-128
strong solution 1-345
temperature dependent quantity 1-321
strongly coupled model 1-394
temperature gradient 1-243, 1-246
Structural mechanics
test function 1-346, 1-372
3D application mode 1-242, 1-264,
derivative 1-372
1-268
meta variable 1-372
Plane strain application mode 1-270
tetrahetron plot 1-133

 | , 1 ' ( ;
text file Turbulent flow, k - e turbulence model
exporting data to 1-152, 1-153 1-13
importing data from 1-294, 1-295
U undo steps 1-90
text, adding to figure 1-138
union 1-76, 1-83, 1-117, 1-170, 1-172,
thermal conductivity 1-143, 1-155, 1-243
1-175, 1-177, 1-178, 1-179, 1-191,
temperature dependent 1-321
1-197, 1-199
thermal controller 1-153, 1-154
untrimmed patch 1-353
thermo-electric effect 1-109, 1-138
up and down direction 1-354
thermostat 1-154
user models 1-64
TIFF 1-220
path 1-69
time derivative 1-372
User Models page 1-9, 1-68
time-dependent coefficient form equa-
V variable 1-351
tion 1-343
1 variable coefficient form PDE 1-356,
time-dependent general form equation
1-367
1-341
ans 1-48, 1-136
time-dependent PDE 1-406
application mode 1-355, 1-360, 1-365,
time-dependent problem 1-156, 1-337,
1-371
1-343, 1-345, 1-384, 1-386
application scalar 1-316
time-dependent simulation 1-54
boundary coupled equation 1-355
time-dependent solver 1-147
boundary coupled shape 1-355
time-dependent system 1-337, 1-344
boundary parameterization 1-353
time-dependent wave equation 1-345
changing name 1-353, 1-366
time-extrusion plot 1-79
coupling 1-355
time-harmonic field simulations 1-14
curve parameterization 1-353
time-harmonic model 1-260, 1-348
dependent 1-350, 1-355
timestepping
domain number 1-355
output times 1-56
equation 1-355, 1-359, 1-361, 1-369
timestepping algorithm 1-147, 1-407
expression 1-355
Timoshenko beam 1-15
field 1-355
toolbar 1-72, 1-74
geometry 1-352
transport 1-13
independent 1-350
transport field 1-50
miscellaneous 1-354
transversal ambient temperature 1-245
naming convention 1-366
transversal heat flux 1-245
normal component 1-354
trimmed curve 1-235
shape function 1-355, 1-358, 1-360,
trimmed surface 1-235
1-369
trimming solids 1-174, 1-177
space coordinate 1-353
tubular reactor 1-378
tangent 1-354

, 1 ' ( ; | 

vector differential operator 1-320, 1-337 control polygon 1-181, 1-183, 1-186,
velocity 1-271 1-206
vertices, rendering and highlighting 1-87 Window menu 1-73
View as Boundary Coefficients 1-49 wireframe plot 1-90, 1-91, 1-192
View as PDE Coefficients 1-49, 1-368 work plane 1-114
virtual memory 1-408 creating 1-121, 1-187
viscous draw toolbar 1-83
force 1-274 face positioning 1-121
layer 1-21
X XWD 1-220
visualization 1-78, 1-133, 1-307, 1-324,
Y Young’s modulus 1-266
1-329
geometry 1-86, 1-332 Z Z-buffer renderer 1-89
mesh 1-90 zoom 1-93
mesh quality 1-91 buttons 1-75
quality of 1-88 window 1-75
Visualization/Selection Settings dialog Zoom Extents 1-35, 1-75, 1-120
box 1-86
volume
element 1-91
force 1-265, 1-271
source 1-247
von Mises effective stress 1-267
vorticity 1-274

W wake effect 1-56


wave equation 1-345, 1-350
wave propagation 1-14
waveguide transition 1-23
waveguides 1-14
weak
constraints 1-286, 1-398
edit field 1-372
form 1-6, 1-336, 1-372
formulation 1-278
solution form 1-285, 1-372, 1-407
term 1-372
weak modes 1-64, 1-239
weakly coupled model 1-394
weights

 | , 1 ' ( ;

You might also like