PDE For Modelica
PDE For Modelica
Levon Saldamli
Acknowledgments
First of all I would like to thank my supervisor Peter Fritzson for the inspiration for doing the work and writing this thesis, and for improving my
writing. I would also like to thank Vadim Engelson, Bernhard Bachmann
and Mikael Adlers for their guidance during this work.
Many thanks go to my colleagues at PELAB (Programming Environments
Laboratory) for contributing to an interesting and stimulating environment
with lively and sometimes too long coee break discussions. In particular,
I would like to thank the members of the pelab-modelica group, and especially Peter Aronsson and Peter Bunus for many meetings and exchange
of ideas. Many thanks also to Andrzej Bednarski and Jon Edvardsson for
om for her help
LATEX support. Special thanks to Bodil Mattsson Kihlstr
with all the administrative issues. Also thanks to Lillemor Wallgren and
Bodil Carlsson at IDA for their support with other administrative tasks,
and to Ivan Rankin at IDA for language review of this thesis.
I would also like to thank the members of the Modelica Association, for
developing the Modelica language, and especially Hans-Ju
rg Wiesmann and
Hubertus Tummescheit for their ideas and comments on this work.
ii
Contents
1. Introduction
1.1. PDE-based Model Example . . .
1.1.1. Connection to ODE/DAE
1.2. Contributions . . . . . . . . . . .
1.3. Overview of the Thesis . . . . . .
. . . . .
models .
. . . . .
. . . . .
2. Background
2.1. Modelica . . . . . . . . . . . . . . . . . . .
2.2. Partial Dierential Equations . . . . . . .
2.2.1. Classication . . . . . . . . . . . .
2.3. Solution of Partial Dierential Equations
2.3.1. Finite Dierence Methods . . . . .
2.3.2. Finite Element Methods . . . . . .
2.3.3. Finite Volume Methods . . . . . .
2.3.4. Method of Lines . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3. Related Work
3.1. Libraries and Programming Language-Based Packages .
3.1.1. Dipack . . . . . . . . . . . . . . . . . . . . . . .
3.1.2. Overture . . . . . . . . . . . . . . . . . . . . . .
3.1.3. Compose . . . . . . . . . . . . . . . . . . . . . .
3.2. High Level Packages and Problem Solving Environments
3.2.1. gPROMS . . . . . . . . . . . . . . . . . . . . . .
3.2.2. PELLPACK . . . . . . . . . . . . . . . . . . . . .
3.2.3. PDESpec . . . . . . . . . . . . . . . . . . . . . .
3.2.4. FEMLAB . . . . . . . . . . . . . . . . . . . . . .
3.3. Discussion . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1
2
3
5
6
.
.
.
.
.
.
.
.
7
7
14
16
17
17
18
19
20
.
.
.
.
.
.
.
.
.
.
21
21
22
22
22
23
23
24
25
26
28
4. PDEModelica
31
4.1. Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . 31
4.2. PDE Problem Specication . . . . . . . . . . . . . . . . . . . 31
4.3. Domain Geometry Denition . . . . . . . . . . . . . . . . . . 32
iii
Contents
4.3.1.
4.3.2.
4.3.3.
4.4. Model
4.4.1.
4.4.2.
Boundary Description . . . . . . . . . . . . . .
Complex Domains . . . . . . . . . . . . . . . .
Domain Classes and Boundary Classes . . . . .
Denition . . . . . . . . . . . . . . . . . . . . .
Operators . . . . . . . . . . . . . . . . . . . . .
Hierarchical Denition of PDEs and Boundary
ditions . . . . . . . . . . . . . . . . . . . . . . .
4.4.3. Complete Model Denition . . . . . . . . . . .
4.5. Summary of Extensions in PDEModelica . . . . . . . .
5. Implementation
5.1. Modelica Parser . . . . . . . . . . . . . . . . .
5.1.1. PDEModelica Extensions . . . . . . .
5.2. Modelica Translator . . . . . . . . . . . . . .
5.2.1. RML . . . . . . . . . . . . . . . . . . .
5.2.2. Modelica Translator Specied in RML
5.2.3. PDEModelica Extensions . . . . . . .
5.2.4. Code Generation . . . . . . . . . . . .
5.3. Numerical Solver . . . . . . . . . . . . . . . .
5.3.1. Domain Discretization . . . . . . . . .
5.3.2. Mesh Generator . . . . . . . . . . . .
5.3.3. Finite Element Solver . . . . . . . . .
5.4. Future Extensions in the Implementation . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. . . .
. . . .
. . . .
. . . .
. . . .
Con. . . .
. . . .
. . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
32
35
36
37
37
39
42
43
45
45
48
49
50
51
52
56
62
62
63
64
68
6. Examples
69
6.1. Electrostatic Fields . . . . . . . . . . . . . . . . . . . . . . . . 69
6.2. Static Currents . . . . . . . . . . . . . . . . . . . . . . . . . . 70
6.3. Heat Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
7. Conclusions and Future Work
7.1. Conclusions . . . . . . . . . . .
7.2. Future Work . . . . . . . . . .
7.2.1. Complex Domains . . .
7.2.2. Generalized Connectors
7.2.3. Expressing PDEs . . . .
7.2.4. Debugging . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
77
77
77
77
78
78
78
References
79
83
87
iv
Contents
C. Problem Formulation Generated for FEMLAB
89
91
Contents
vi
Chapter 1.
Introduction
In mathematical modeling of a physical system, the behaviour of dierent
parts of the system is typically modeled using dierential equations or a
system of dierential and algebraic equations, i.e. algebraic equations containing derivatives.
For large scale models, some properties of the physical system that is
modeled are usually approximated; for example when controlling the temperature of a uid in a container, the temperature can be assumed to be
the same everywhere inside the container. This way, the space dependency
is eliminated, resulting in models containing only ordinary dierential equations (ODEs), or dierential and algebraic equations (DAEs), i.e. equations
where all derivatives are with respect to time. This greatly simplies the
solution of the equations and the simulation.
However, sometimes a more detailed model with explicit space dependency is needed for the whole system or some part of the system. Such
space-dependent models are used to study the behaviour on a smaller scale,
and contain partial derivatives, i.e. derivatives with respect to space variables
like x, y and z in a Cartesian coordinate system. Dierential equations containing partial derivatives are called partial dierential equations (PDEs),
and are used in many elds to model physical behaviour, for example structural mechanics, computational uid dynamics and electrostatics.
There are many tools for modeling and simulation with ordinary dierential equations as well as with partial dierential equations. However, most
of these tools are specialized for certain application domains or special kinds
of models.
An eort to dene a general, application domain and tool-independent
modeling language is made by Modelica Association, with the Modelica language as a result. Modelica [15, 27] is a standard language designed for
component-based modeling, where previously dened models can be reused
as components in new models. Object oriented constructs, equation-based
and declarative modeling support, as well as a connection concept make
Chapter 1. Introduction
this possible. Currently, the Modelica language only supports models with
ordinary dierential equations. Several Modelica implementations and simulation tools exist [2, 5, 16, 18].
Thanks to the progress in computer performance, the use of detailed models containing partial dierential equations is becoming increasingly common. The aim of this work is to dene a language based on Modelica, in
order to handle partial dierential equation based models in addition to differential and algebraic equation based models. This language is called PDEModelica, and this thesis discusses the initial language extensions needed for
the desired support.
of the unknown variable known on the boundary. See also Section 2.2.
of the outward normal derivative of the unknown variable is known on the boundary. The outward normal derivative is the space derivative in the outward normal
direction. See also Section 2.2.
3 The sum of the unknown variable and its outward normal derivative is known on the
boundary. See also Section 2.2.
2 Value
Chapter 1. Introduction
Figure 1.2.: The PDEModelica code to dene the heat conduction problem
in Section 1.1. Predened PDE and boundary condition models
have been left out. The syntax is explained in Chapter 4.
1.2. Contributions
model and the ODE model can be more complex. Chapter 7 discusses future
work on this issue.
Coupled models are not yet fully supported in the implementation, see Section 5.4 for details.
Controller
Heater
T = 30o C
Tout = 20o C
Window
Sensor
Figure 1.3.: A coupled PDE and ODE model. Time dependent heat transfer
model with a controller.
1.2. Contributions
The result of this work is preliminary design and implementation of an
object-oriented modeling language, PDEModelica, with support for
object-oriented modeling with PDEs and boundary conditions,
complex geometry description with lines, polygons, parametric curves
and a combination of these,
component-based geometry denition,
hierarchical modeling and decomposition with a general connection
concept, and
modeling of combined ODE/DAE and PDE problems.
Chapter 1. Introduction
We believe that the combination of these aspects in a single language is
rather new.
A prototype translator and solver environment is set up as well, with a
basic PDE solver interface for adding new solvers and mesh generators.
Some of the work discussed in this thesis has been published previously
in the following publications:
1. L. Saldamli and P. Fritzson. Object-Oriented Modeling with Partial
Dierential Equations. In Proceedings of the Modelica Workshop 2000,
Lund, Sweden, October 2000 [35].
2. L. Saldamli and P. Fritzson. A Modelica-Based Language for ObjectOriented Modeling with Partial Dierential Equations. In Proceedings
of the 4th International EUROSIM Congress, Delft, The Netherlands,
June 2001 [37].
3. L. Saldamli and P. Fritzson. Domains and Partial Dierential Equations in Modelica. In Proceedings of the 42nd SIMS Conference, Porsgrunn, Norway, October 2001 [36].
4. L. Saldamli, P. Fritzson and B. Bachmann. Extending Modelica for
Partial Dierential Equations. In Proceedings of the 2nd International
Modelica Conference, Oberpfaenhofen, Germany, March 2002 [38].
Chapter 2.
Background
The basic concepts of Modelica are presented in the rst part of this chapter. In the second part, the topic of partial dierential equations (PDEs)
and classication of PDEs are briey presented, and nally an overview of
dierent numerical solution methods is given.
2.1. Modelica
Modelica [17, 27] is a modeling language for equation-based, object-oriented
modeling and simulation of physical systems. Using object-oriented concepts, it allows hierarchical, component-based modeling which in turn makes
reuse of existing models possible. The general modeling concepts in Modelica allow it to be used in dierent application domains and in multi-domain
modeling, for example when dening a combined electrical and mechanical
model. There is a free Modelica Standard Library [28] and other free Modelica libraries with packages of existing models from dierent domains that
can be used as components in specic models. Non-causal modeling, i.e.
modeling using equations - not assignment statements, allows single models
to be used in dierent data ow contexts since variables are not explicitly
declared as input or output but this information is rather derived from the
context where the model is used. In his PhD thesis, H. Tummescheit [45]
discusses design and implementation of modeling libraries using Modelica.
Models in Modelica are hierarchically built from submodels that are dened separately, which in turn can be built in the same way. Hence, a model
can contain one or more instances of other models with dierent set of parameter values for each instance, and a set of connections between these
components. Additionally, each model can have variables of built-in types,
and equations that dene the relationship between these variables and also
between variables in submodels.
Chapter 2. Background
Classes
The basic structural unit in Modelica is class. A class can contain other
classes, variable declarations, equations and algorithms. An example of a
class can be seen in Figure 2.1. Other keywords can be used to denote classes,
restricted classes that are special cases of classes with some restrictions.
These are record, type, connector, model, block, package and function.
Dierent restricted classes and restrictions that apply to them can be seen
in Table 2.1.
model MyModel "Short description of this model"
Real x,y;
equation
x + y = 5;
x + 2y = 11;
end MyModel;
Restrictions
No equations are allowed.
May only be used to extend primitive types.
No equations are allowed.
Model instances may not be used in connections.
Fixed causality. Each variable must be declared
as input or output.
May only contain classes and constants. Is allowed
to import from.
Similar to block. No equations, at most one algorithm
section. May be called using positional arguments.
May be recursive.
Variable Declarations
Variable declarations consist of a type and a variable name. The type can
be one of the primitive types or another class name. The primitive types
are Real, Integer, String, Boolean and Enumeration. Each declaration
can also have type modiers, such as the type variability prex constant,
discrete, or parameter, or a causality prex, input or output.
2.1. Modelica
Variables with the constant or parameter prex keep their value constant during a simulation, i.e. they are constants. The dierence between
parameters and constants is that values of parameters can be changed before
each simulation without needing to recompile the Modelica code. Variables
of type Real declared without the constant or parameter modiers are implicitly time-dependent, i.e. functions of time. Time derivatives of variables
can be represented using the der() operator. Using the time derivatives, ordinary dierential equations can be expressed, and full systems of dierential
and algebraic equations (DAEs) can be specied.
Subtyping and Inheritance
Modelica models can be dened using inheritance. The extends clause is
used together with a class name to inherit that class. Multiple inheritance
is allowed using several extends clauses, one for each inherited class. Inheritance is equivalent to inserting the contents of the inherited class at the
place where the extends clause resides.
Type equivalence in Modelica is dened as follows: Two types T and U
are equivalent if
they denote the same primitive type (see previous section), or
T and U are classes containing the same elements (according to their
names) and the elements types are equivalent.
Subtypes in Modelica are dened independently from the inheritance
mechanism. A class C is a subtype of a class S if
S and C are type equivalent, or
both of the following statements hold:
every public element of S also exists in C (according to its name).
the type of each such element in C is a subtype of the type of the
corresponding element in S.
If a class C is a subtype of a class S then S is called the supertype of C.
Subtypes and supertypes do not necessarily need to be in an inheritance
hierarchy, but a class that is inherited from, a base class, is a supertype of a
class that inherits from it, a derived class. An example is shown in Figure 2.2.
The TempResistor class cannot extend the Resistor class because it
has a dierent equation in the equation section, but it is still a subtype of
Chapter 2. Background
10
2.1. Modelica
Resistor because it contains all the elements in Resistor, and additional
elements. Both classes inherit from the OnePort1 class, though.
Modications
Modications in Modelica are used to modify parameter values when declaring instances of classes. Since models are built up hierarchically, modications can be overridden, in which case the topmost (outermost) modication
is applied. A modication can also be hierarchical, in order to modify a lower
level parameter directly. Each modication consists of a component reference and an expression that is evaluated in the context where the declaration
resides. Example of modications can be seen in Figure 2.3. Declarations
preceded by the final keyword are nal elements and cannot be modied
using modications. The final keyword can also precede modications, in
which case it prevents further modications of that variable in outer modications.
model ModelA
parameter Real pa = 0; // default value
end ModelA;
model ModelB
ModelA compa(pa=1);
// modification
parameter Real pb = 0;
end ModelB;
model MyModel
parameter Real mypa=3, mypb=4;
ModelB compb(pb=mypb, compa(pa=mypa)); // hierarchical modification
end MyModel;
11
Chapter 2. Background
Equations and Algorithms
The keywords equation and algorithm denote equation and algorithm sections, respectively. There can be several such sections of each kind in a class.
During compilation, all equation sections are merged into a single equations
section.
Equation sections can contain standard equation clauses, connect equations, conditional equations, for equations and when equations. Standard
equations consist of two expressions and the equality operator denoted by
=. The assignment operator := is not allowed in equation sections, whereas
the equality operator = is not allowed in algorithm sections. Besides the
common operators like arithmetic operators and function calls, Modelica
has if-expressions, which can be used in situations like:
equation
x = if (z > 0) 2*z else (-2*z);
Connect equations consist of the connect() operator with two arguments
that are references to connectors. Connectors are instances of connector
restricted classes and usually contain two kinds of variables, ow (e.g. current) and non-ow (e.g. potential) variables, the former being denoted by
the flow keyword. Connect equations are translated into standard equations during compilation, where for each connection the non-ow variables
of the involved connectors are set equal, and the sum of all the ow variables
is set to be equal to zero. Figure 2.4 illustrates the use of connectors and
connections, and the resulting equations.
Conditional equations are written using the if-elseif-else construct
with equations in the body. for equations are useful for repetitive equation structures involving arrays. when clauses are used for discrete event
simulation.
Algorithm section can contain assignments, conditional statements, forloops, while-loops and when-statements. The dierence from equation sections is that algorithm sections contain assignments instead of equations,
and the contents of the algorithms are executed sequentially. An assignment consists of a variable reference, the assignment operator := and an
expression.
Replaceable Elements
Elements in classes in Modelica can be declared as replaceable, in which
case they can be replaced by another type of element that is type compatible
when the containing class is extended or instantiated. Generic classes with
type parameters is supported in Modelica through the replaceable mechanism.
12
2.1. Modelica
B
p
p
C
(a) Visual view of a connector and connection example.
equation
a.p.i + b.p.i + c.p.i = 0;
a.p.v = b.p.v;
b.p.v = c.p.v;
(c) Resulting equations
Figure 2.4.: Example of connectors and connections and the resulting simple
equations after compilation.
13
Chapter 2. Background
The type restriction of a redeclaration is that the new declared type must
be a subtype of the original declared type, a constraining type.
14
(2.1)
The denition domain, i.e. the geometric region on which the PDE is dened, denoted , is in most cases a closed region in space as dened by the
independent variables, see Figure 2.5.
Figure 2.5.: The denition domain , its boundary and the outward
normal vector n.
Boundary conditions in a PDE problem specify the behaviour of the model
on the boundary of the domain , denoted , and usually contain derivatives of one order less than the PDE. A general boundary condition corresponding to equation (2.1) can be expressed as
g(u, ux, x) = 0
(2.2)
u=g
on
N eumann :
n u
=g
Robin :
n u
+ qu = g
on
on
15
Chapter 2. Background
In cases where the right-hand side is zero, the corresponding condition is
called homogeneous, otherwise non-homogeneous.
2.2.1. Classication
PDEs are classied based on linearity properties. An equation expressed
using the linear operator2 L() in the form
L(u + v) = 0
is linear if
L(u + v) = L(u) + L(v)
If a PDE with the dependent variable u and the independent variables x
and y can be expressed in the following form:
auxx + 2buxy + cuyy = d
(2.3)
where the coecients a, b and c are constants, the PDE is linear. If the
coecients are functions of the independent variables only, x and y in this
example, the PDE is semi-linear, and if the coecients also depend on u or
its rst-order derivatives the PDE is quasi-linear. Equations that cannot be
expressed linearly in the second order derivatives as in equation (2.1) are
nonlinear. In this text, semi-linear PDEs will be regarded as linear, while
quasi-linear PDEs will be classied together with the nonlinear.
If a > 0, Equation (2.3) is classied further into three categories depending
on the value of b2 ac:
Elliptic :
b2 ac < 0
P arabolic :
b2 ac = 0
Hyperbolic :
b2 ac > 0
16
17
Chapter 2. Background
conditions are applied at the grid points neighboring the boundary, depending on the kind of boundary conditions. With Dirichlet boundary conditions,
the values on the boundary are known and can be used directly. With Neumann and Robin conditions, the derivative is approximated in the same way
as in the PDE and equations involving the grid points outside the domain are
generated, that can be used to express the unknown values on the boundary.
When solving time-dependent problems, the time derivatives can be approximated with nite dierences as well. Note however, that when using
nite dierence methods, the discretization steps must be chosen according
to certain conditions in order to maintain stability.
Dierent solution methods use dierent norms of how close the approximation is to the unknown function, when calculating the coecients. Since
there are a nite number of basis functions and nite number of unknown
coecients, it is possible to numerically calculate the coecients, given the
PDE and known values at some points, i.e. the boundary conditions.
The Galerkin method is a basic method for calculating the unknown coecients. For a partial dierential equation of the form
L(u(x)) = 0
where L() is a linear operator containing u and its derivatives, a residual
error R of an approximation u
is dened by
R(
u(x)) = L(
u(x))
The residual error measures how well the approximation satises the partial
dierential equation. If it is identical to zero, i.e. R(
u(x)) 0 for all x in
the domain, then the approximation is the exact solution. A criterion for
measuring how close a function is to being zero is to look at its orthogonality
to a chosen set of functions. Orthogonality of two functions f (x) and g(x)
is dened as
f (x)g(x) dx = 0
18
k = 0..N
Substituting u
with its denition in (2.4) and calculating the integrals gives
an equation system that can be solved to nally obtain the coecients to
the trial functions and the approximation to the solution.
The selection of the trial and test functions lead to dierent solution methods. Using polynomials as basis functions for the trial space requires global
support from the polynomials, because each basis function contributes to
the entire domain. In order to increase the accuracy of the approximation
the degree of the polynomials must be increased.
A more exible method is to divide the domain into m subdomains and
use basis functions with local support, where each function vk is zero outside
of one subdomain and its neighboring domains. This method is called the
nite element method, elements being the subdomains, and can be applied to
the dierent solution methods using dierent test functions. Usually lower
order polynomials can be used because local support simplies the approximation. Instead of polynomials of higher degree, smaller elements can be
used for better approximation, especially for the parts of the domain where
the solution has steep changes. Subdivision of the domain can be performed
in dierent ways, triangulation being a common method. Adaptive triangulation can also be used, to rene the mesh iteratively on parts of the solution
where the error is too large.
19
Chapter 2. Background
20
Chapter 3.
Related Work
This chapter contains an overview of work done on tools for modeling and
simulation of partial dierential equation based models, categorized by the
user interaction level. The rst category of tools requires the user to write the
problem formulation and the solution algorithm in an ordinary programming
language such as Fortran, C or C++, with library support from the tool.
The second category provides a high-level interface, a problem description
language or a graphical user interface, where the problem can be specied.
21
3.1.1. Dipack
Dipack [12] is a C++ library package with data structures and numerical
methods that are used to solve PDE problems. The package is divided into
a kernel and application-specic toolboxes for use in dierent engineering
areas. Dipack includes support for solving sparse linear systems using iterative methods and solving non-linear systems, using nite element and nite
dierence methods with a collection of nite elements and nite dierence
schemes, adaptive meshes, domain decomposition methods and multi-grid
methods. The package also includes support for administrative tasks, such as
report generation, simulation result handling and data entry using a graphical user interface.
3.1.2. Overture
Overture [32] is a framework for writing PDE solvers in C++ using nite difference or nite volume methods. Built-in classes are used to represent domains, discretized domains, dierentiation operators, solution vectors, and
other data needed in a PDE solver system. The framework also includes grid
generators, solvers, and graphical interface classes for plotting the results.
Overture uses overlapping grids to support composition of domain geometries. A grid generator is used to generate overlapping grids which are
used for domains composed of several domain components. In a composite domain, common grid points are generated for the overlapping parts of
the domain components that comprise the nal domain. This method is also
useful for moving overlapping grids where the domain components move over
time, in which case the grid is regenerated each time a domain component
is moved.
3.1.3. Compose
Compose [44] is an object-oriented framework built on top of Overture. The
Compose framework has been developed using object-oriented analysis, design and implementation, with the objective of separating the classes used
for problem formulation from the classes concerned with the numerical solution process. Hence, the equation classes, domain classes, and other classes
that represent the mathematical model are separated from classes that handle discretization and solution of the PDEs. Thus, compared to Overture,
where the formulation of the mathematical model and the numerical solution
method are more tightly coupled, Compose has a higher level of abstraction.
However, there is no automatic solver selection support in Compose compared to many problem solving environments. Equations and equation dis-
22
3.2.1. gPROMS
gPROMS is a general process modeling system for dynamic simulation of
chemical processes, with support for combined lumped and distributed models [30]. gPROMS uses a high-level language for modeling and simulation of
mixed systems of integral, partial, and ordinary dierential, and algebraic
equations (IPDAEs) over rectangular domains.
MODEL TubularReactor
PARAMETER
NbrComp
...
ReactorLength, ReactorRadius
DISTRIBUTION_DOMAIN
Axial
Radial
AS INTEGER
AS REAL
AS ( 0 : ReactorLength )
AS ( 0 : ReactorRadius )
23
Here, Temp is of type Temperature that is dened elsewhere, and its geometric domain is the three-dimensional area dened by the independent
variables Axial and Radial and their limits as dened in Figure 3.1. This
declaration is similar to declaration of arrays in the gPROMS language,
which is done using the array keyword:
F
AS ARRAY ( NbrComp )
OF Flowrate
3.2.2. PELLPACK
PELLPACK [19] is a problem solving environment for specication, solution
and post-processing of PDE problems. A PDE language is used to specify
the PDE, the domain geometry, the boundary conditions, the discretization
method, the solution method, and other method-specic parameters that
are needed to solve the problem. There are also tools providing graphical
user interfaces for specifying dierent parts of the problem, from which the
specication in the same PDE language is generated.
The PDE language used in PELLPACK is an extension of the ELLPACK
language. The ELLPACK language is divided into sections where the PDE
problem is specied and the solution method is selected. The equation
section contains the PDE written in mathematical form. The boundary
section denes the geometry by dening the domain boundary. The boundary conditions are also written in the boundary section together with the
24
UXX + UYY
The boundary conditions can be specied in dierent ways, using lines and
parametric curves. A circular domain is dened as in Figure 3.3, where the
boundary section species the condition that the function is zero on a circle
with radius 1 and center (1, 1). The boundary statement also denes the geometry of the problem. The equation and boundary parts of an ELLPACK
program are declarative, whereas the rest grid, discretization, fortran
etc., are executed in a sequential order.
BOUNDARY.
U = 0.0 ON
X = 1. - COS(PI*THETA), &
Y = 1. - SIN(PI*THETA) &
FOR THETA = 0. TO 2.
3.2.3. PDESpec
S. Weerawarana [46] presents a high-level language PDESpec where the PDE
problem is specied using objects. Dierent types of objects are equation, do-
25
domain (
name = "dome",
type = piecewise_parametric,
boundary = [
orientation = clockwise,
parametric (x=3, y=.7-t, t, 0, .7),
...
]
);
3.2.4. FEMLAB
FEMLAB [13] is a Matlab package for solving PDE problems. Both steadystate and time-dependent problems can be solved, as well as scalar PDEs
and systems of PDEs. An environment with a graphical user interface as
well as the Matlab command line interface is used for problem specication,
solution, and visualization. Figure 3.6 shows an example of the FEMLAB
user interface, where surfaces of the three-dimensional domain can be individually highlighted and assigned dierent boundary conditions.
26
Figure 3.6.: Surface selection in the FEMLAB graphical user interface, useful
for example during boundary condition specication.
27
3.3. Discussion
In the beginning of this chapter we classied available systems for solving
PDEs into two groups:
programming language based packages,
high-level packages.
The rst category of tools is directed towards users with numerical knowledge and some programming language skills. Also, a varying degree of manual work on the solution must be done before the actual implementation.
On the other hand, an ecient solver can be obtained for a specic problem.
The second category contains tools that do not require numerical knowledge to the same extent, and the details of the solution process are hidden.
This is true especially for the problem solving environments, and in particular FEMLAB. In FEMLAB, existing models can be used directly, with
some modication of the parameters and new models can be dened using
the graphical user interface. Although, the language support is poor, model
parameters can be set directly using the Matlab interface and there is a
number of help functions. PELLPACK has a more advanced, but still limited, specication language. The tool with the most advanced language is
gPROMS, which denes a formal modeling language and supports hierarchical modeling, domain description, etc., but only rectangular domains are
supported.
28
3.3. Discussion
PDEModelica belongs to the second category, being a high-level language,
and aims to hide numerical details from the user. The closest tool to PDEModelica is gPROMS which only supports simpler domains. Compared to
the other packages PDEModelica has additional object-orientation support,
like inheritance, as well as support for a general connection concept.
29
30
Chapter 4.
PDEModelica
This chapter denes the problem to be solved in this thesis and presents
a possible solution. The solution is a set of language extensions to the
Modelica language, consisting of constructs for component-based domain
geometry description, operators to express partial dierential equations in
the language, and constructs for dening a complete PDE model containing
the domain, the equations and the boundary conditions.
31
Chapter 4. PDEModelica
the boundary conditions, and
the initial conditions in case the PDE problem is time-dependent.
The computed solution is a function of space for a stationary problem, and
a function of space and time for a time-dependent problem.
32
(xn1 , yn1 )
Figure 4.1.: A set of connected lines that is described by the line() construct line({{x0,y0},{x1,y1},...,{xn,yn}})
The simplest case is a single line dened by its start and end points.
Figure 4.2 shows the PDEModelica code that denes a Line2D class.
domain Line2D "A line segment"
extends Cartesian2D;
parameter Real x0=0, y0=0, x1=1, y1=1;
boundary
line({{x0,y0},{x1,y1}});
end Line2D;
Figure 4.2.: Denition of the Line2D class using the line() operator
33
Chapter 4. PDEModelica
point on the curve is calculated by a weighted sum of all the control points,
where the weights are functions of the position on the curve varying between 0 and 1. One simple way of calculating the points of the curve is
using de Casteljaus algorithm [9, 11], which is implemented in the function
bezierfunc in Figure 4.3.
When declaring an instance of the Bezier2D class in Figure 4.3, two arrays
must be given as parameters, one array containing the x-coordinates of the
control points and one containing the y-coordinates.
function bezierfunc
input Real px[:];
input Real u;
output Real res;
Real qx[size(px,1)];
algorithm
qx := px;
for k in 1:size(px, 1) - 1 loop
for i in 1:size(px,1) - k loop
qx[i] := (1-u)*qx[i] + u*qx[i+1];
end for;
end for;
res := qx[1];
end bezierfunc;
domain Bezier2D "Boundary domain"
extends Cartesian2D;
parameter Real px[:];
parameter Real py[size(px,1)];
parameter Real u;
boundary
curve(bezierfunc(px, u), bezierfunc(py, u));
end Bezier2D;
Figure 4.3.: Denition of the Bezier2D class using the curve() operator.
34
Figure 4.4.: Denition of the Rectangle2D class using the composite() operator.
top
h
w
left
right
(cx, cy)
bottom
Figure 4.5.: The domain dened by the Rectangle2D class in Figure 4.4.
35
Chapter 4. PDEModelica
connector operators, models such as the static current problem in Section 6.2
can be specied.
aluminum
copper
aluminum
Figure 4.6.: Example of a complex domain consisting of three subdomains
with two dierent physical materials.
In our current work, building really complex geometric domains has not
yet been investigated.
36
Figure 4.7.: Two boundaries that dene domains with dierent dimensionality.
4.4.1. Operators
In order to represent the equations of the model, the initial conditions and
the boundary conditions, new operators need to be introduced in PDEModelica. The basic operator is the new partial derivative operator for derivatives
with respect to space variables, analogous to the der() operator in Modelica
that represents time derivative of variables.
An operator for the normal derivative on a domain boundary is also needed
for certain boundary conditions.
Moreover, special derivative operators such as divergence and gradient are
often used in mathematics to more conveniently express certain PDEs.
Partial Derivative
m
37
Chapter 4. PDEModelica
Divergence and Gradient
A short and very common mathematical notation for expressing PDE models
involves the gradient and the divergence operators, and respectively. If
a Cartesian coordinate system in two-dimensional space is used, the gradient
operator is dened as
x u
u =
y u
Hence, the gradient operator increases the dimensionality of its argument.
On the other hand, the divergence reduces the dimensionality of its argument. With the same coordinate system, and using the argument
u1
u=
u2
the divergence operator is dened as
u = x u1 + y u2
Thus, using these operators together, the Laplace equation can be expressed
as
(u) = 0
which given the same coordinate system as above, is equivalent to
xx u + yy u = 0
These operators can be introduced in PDEModelica, divergence() for
the divergence operator and gradient() for the gradient operator. The advantage of also introducing these operators besides the pder() operator is
that the syntax of these special operators is independent of the dimensionality of the problem and the names of the coordinates unlike the pder()
operator.
Directional Derivative
In some boundary conditions, the outward
normal derivative on the domain
m
boundary occurs, usually written nm (expr), most commonly only being the
rst-order derivative, m = 1. The outward normal derivative is the directional space derivative in the outward normal direction, see Figure 4.8. Since
the normal vector depends on the domain geometry, this derivative cannot
be represented by the pder() operator alone. Either the normal vector
must be available or a special operator must be used to represent the normal derivative, for example the operator nder(expr,m), with nder(expr)
corresponding to m = 1.
38
Figure 4.8.: The normal vector on the boundary that is used in the normal
derivative operator. The normal derivative is the directional
space derivative in the normal direction.
u
(cu) + au = f
t
39
Chapter 4. PDEModelica
model PDE2D
space Real x,y;
Real u(x,y);
end PDE2D;
model PDECoeff2D
extends PDE2D;
parameter Real da = 0;
parameter Real c = 0;
parameter Real a = 0;
parameter Real f = 0;
equation
da*der(u) - div(c*grad(u)) + a*u = f;
end PDECoeff2D;
This represents the Poisson equation. A general, time-dependent HeatTransfer model with coecients common for heat transfer problem formulations can be dened as follows:
model HeatTransfer
extends PDECoeff2D(da=rho*C, c=k, a=h, f=Q+h*T_ext);
parameter Real rho=0 "density";
parameter Real C=0 "heat capacity";
parameter Real k=0 "thermal conductivity";
parameter Real h=0 "convection coefficient";
parameter Real T_ext=0 "External temperature";
end HeatTransfer;
u
(ku) = Q + h(Text u)
t
with u being the temperature, i.e. the solution. Hence, time dependency is
chosen by modifying the coecient of the time derivative term.
Boundary Conditions
A Robin boundary condition, used in a heat transfer problem to describe a
boundary that is neither a perfect conductor nor a perfect insulator, can be
40
u + qu = g
n
(ku) = qh + hh(Text u)
n
where qh is the source term, hh is the heat transfer coecient and Text is
the external temperature.
41
Chapter 4. PDEModelica
model HeatRobin "For heat transfer"
extends Robin(c = k,
q = hh,
g = qh + hh*T_ext);
parameter Real k = 1;
parameter Real qh = 0
"Heat flux";
parameter Real hh = 1
"Heat transfer coefficient";
parameter Real T_ext = 25 "External temperature";
end HeatRobin;
Figure 4.12.: Heat transfer specic model derived from the general Robin
model.
42
Figure 4.13.: Complete specication of a PDE problem using previously dened domains, PDE and boundary condition models.
Initial values that are not constant over the domain can be expressed by
dening a function. However, this has not been tested yet in the current
work and needs to be further investigated.
43
Chapter 4. PDEModelica
eq: Predened variable in domain restricted classes for assigning PDEs
to domains.
bc: Predened variable in domain restricted classes for assigning boundary conditions to boundary segments.
44
Chapter 5.
Implementation
The PDEModelica prototype consists of several modules. The input model
specication to the system is a text le containing PDEModelica code.
PDEModeq is the Modelica translator Modeq with PDE extensions which
extracts domain information and PDE parameters from the input source.
From the domain denitions in PDEModelica, a discrete domain description is generated by the domain discretizer for the specic mesh generator
used. The mesh generator and the PDE solver can be external software
modules freely available with source code. Figure 5.1 provides an overview
of the system.
The Modelica translator consists of several parts. The rst step is the
lexer and the parser that reads textual Modelica code and generates an
abstract syntax tree. Next, a generated compiler interprets the code and
translates the models into a at set of dierential and algebraic equations
and possibly a set of functions. A numerical solver is then used to solve
the set of equations and simulate the models. The dierent steps of the
translation process and the tools used can be seen in Figure 5.2.
The PDE extensions are described separately, in sections Section 5.1.1
and Section 5.2.3. This implementation uses the coecient-based approach,
assuming that a certain general equation is used, and only handles the parameters of the PDE model, ignoring the equations sections. Thus, the special operators for dening PDEs are not mentioned. Future work regarding
these issues is discussed in Chapter 7.
45
Chapter 5. Implementation
User input
PDE-Modeq
Parser
PDE-Modelica
Domain
Discretizer
Domain
Translator
Mesh generator
Parameters
Solver
External software
Tool
Abstract syntax
tree in ANTLR
Abstract syntax
tree in RML
Translator
RML
DAE-list
in-RML
Figure 5.2.: The dierent steps of the translation process, the tools used and
the intermediate results.
46
= "class"
= "connect"
= "connector"
;
;
;
Each alternative contains a rule that is checked for a match. Table 5.1 lists
some of the symbols used in ANTLR rules.
Table 5.1.: Some symbols in ANTLR used in rules, consisting of regular
expressions.
Symbol
(. . . )
(. . . )*
(. . . )+
(. . . )?
{. . . }
|
..
.
Description
Subrule
Closure subrule (repeat zero or more times)
Positive closure subrule (repeat one or more times)
Optional
Semantic action
Alternative operator
Range operator
Wildcard
Rules are also used in the parser, but instead of characters a stream of
tokens is the input that is being parsed, and a parse tree is automatically
generated.
ANTLR also supports the implementation of tree walkers using a metalanguage similar to the lexer and parser denition meta-languages. Tree
walkers can be used to traverse a syntax tree built by the parser and perform
some actions or transformations on the tree.
47
Chapter 5. Implementation
Description
Space variables for coordinates
New restricted class domain
New section in classes for domain
geometry denition
Boundary geometry description
operators
Predened variables in domain classes
boundary
: (
| line_clause
| curve_clause
| composite_clause
)
comment!
;
line_clause :
LINE^ LPAR! e:expression RPAR!
;
curve_clause :
CURVE^ LPAR! e:expression_list RPAR!
;
composite_clause :
COMPOSITE^ LPAR! el:component_reference_list RPAR!
;
48
ROOT
DOMAIN
TestDomain
PUBLIC
ELEMENT
ELEMENT
COMPONENTS
space
Real
COMPONENT
x
BOUNDARY
ELEMENT
COMPONENTS
COMPONENT
y
parameter
Real
CURVE
cos(2*PI*u)
sin(2*PI*u)
COMPONENTS
COMPONENT
PI
parameter
Real
COMPONENT
u
MODIFICATION
= 3.141593
Figure 5.5.: The abstract syntax tree for the domain class example in Figure 5.4. The expression subtrees are compressed into single
strings for readability.
49
Chapter 5. Implementation
declared in RML. The tree is subsequently processed further by the Modelica
translator described in the following sections.
5.2.1. RML
RML (Relational Meta Language) [14, 33] is a meta language for formal
specication of language semantics using Natural Semantics [21]. A translator for the language described in RML is automatically generated using the
rml2c compiler, which generates ecient C code that is compiled into an
executable.
Specications in Natural Semantics are expressed using inference rules
similar to natural deduction used in logics. Inference rules with the same
input and output formal parameters can be grouped into signatures. Each
rule is dened by a set of propositions called premises and a proposition
called conclusion. A proposition is proved by applying a rule with a conclusion that can be instantiated to that proposition, and the premises of that
rule are proven similarly. An inference rule with the premises p1 ..pn and the
conclusion p is written
p1 p2 pn
p
In RML, signatures are dened using relations. Each relation consist of
a set of rules. Rules contain propositions consisting of relation invocation
with arguments and results separated by the => symbol. The premises and
the conclusion are separated by a line with two or more consecutive dashes,
see Figure 5.6. The syntax is otherwise similar to that of Standard ML [26].
An example relation can be seen in Figure 5.6.
The rst part of an RML specication le contains the data type declarations and relation declarations that are visible to other modules. The
module exprmod in Figure 5.6 contains one data type, Exp, that can be either an integer constant or an addition operation with two subexpressions.
Integer numbers are represented by the primitive type int. The only relation in this module is called eval, which evaluates the value of an expression
with the integer value as the result.
Rules without premises are called axioms, as in the rst rule of the eval
relation, which returns the value of an integer constant. The second rule
handles the addition operations by rst evaluating the subexpressions and
adding their values using the built-in RML operator int_add. The result of
the rule is then the result of that addition.
50
...
end
51
Chapter 5. Implementation
of equations that is semantically equivalent and makes further processing
simpler.
From the SCode representation, the appropriate Modelica class is instantiated by the Inst module. The result of the instantiation is the DAE representation dened in the DAE module, which contains the resulting functions
and a at set of equations resulting from the translation. Instantiating a
Modelica class means:
retrieving the class denition of the extended classes if there are any
extends clauses and inserting their contents into the current model,
retrieving the class denition of the declared class of each component
in the model,
instantiating their contents with the current component name prex
to avoid name clashes,
applying the modications and inserting their contents into the current
model,
building connections sets and generating equations from these, and
merging the equations from the instantiated subcomponents updated
with the new component names.
During the instantiation, some type checking and constant expression evaluation are also performed. Type checking also includes checking whether
the subtype relationship holds between Modelica classes. Figure 5.7 shows
the RML relation that checks subtyping and type equivalence as dened
in Section 2.1.
52
subtype
subtype
subtype
subtype
(T_INTEGER,T_INTEGER)
(T_REAL,T_REAL)
(T_STRING,T_STRING)
(T_BOOL,T_BOOL)
=>
=>
=>
=>
true
true
true
true
...
rule subtype_varlist(el1, el2) => true
----------------------------------subtype(T_COMPLEX(st1, el1), T_COMPLEX(st2, el2)) => true
axiom subtype(t1,t2) => false
end
Figure 5.7.: The RML relations that check subtyping and type equivalence
between to Modelica classes. Subtyping rules regarding arrays
and tuples are not shown. The relation subtype_varlist calls
the subtype relation for the declared types of each pair of variables in the given variable lists.
53
Chapter 5. Implementation
boundary node with a list of boundary elements, where each element can be
one of the three boundary types, see Figure 5.8. In the current prototype,
the representation is kept simple, using the Exp data type for the LINES node,
which corresponds to the list of points written as a single expression using
the array syntax. Similarly, the CURVE node contains a list of expressions,
one for each of the coordinates.
datatype ClassPart =
|
|
|
|
Figure 5.8.: Data type extensions for domain representation in the Absyn
module.
The representation of boundaries in the SCode module are the same as
in the Absyn module, but the ClassDef data type has been modied to
represent domain information as well (see Figure 5.9).
datatype ClassDef = PARTS of Element list
* Equation list
* Algorithm list
| DERIVED of Path
* Absyn.ArrayDim option
* Mod
| DOMAINPARTS of Element list
* Boundary list
Figure 5.9.: Data type extensions for domain representation in the SCode
module.
The DAE representation is also extended with nodes needed to represent
the extra information related to PDEs, see Figure 5.10. Data types for
expressions stored in the DAE representation are dened in the Exp module,
and contain the statically analyzed expressions, as opposed to the Absyn.Exp
data type which contains the expressions before the analysis. The DAElist
stored in the CURVE node is needed during code generation to determine
which component references in the curve expressions that are parameters, in
order to prex them with the correct prex. See Section 5.2.4 for description
of the code generation phase.
54
Figure 5.10.: Additions in the DAE module for storing domain information.
The only addition in the Element data type is the DOMAIN node.
Translation
The SCode module contains the relations that convert the Absyn representation to the SCode representation, beginning with the elaborate relation.
Some relations in this module are modied to handle the domain extensions. The elab_class relation redirects the translation to elab_domaindef
instead of elab_classdef if the current class has the restriction type R_DOMAIN, i.e. if the class being translated is a domain class. Conversion of the
declaration part in elab_domaindef is identical to the conversion of other
classes, but the conversion of equation and algorithm sections are replaced
with a relation that converts the boundary section. The result of the boundary section conversion is the SCode.DOMAINPARTS structure. The rst part
of this structure are the elements from the declaration part, and the second
part is the boundary description consisting of SCode.Boundary elements
generated by the relation elab_boundary_parts, see Figure 5.11.
The translation is done in the Inst module in dierent ways depending on the type of the SCode.ClassDef node, one of PARTS, DERIVED or
DOMAINPARTS. In the latter case, the rule for translating the domains is activated. The declaration part is handled as for other classes. The boundary
part is instantiated using the relation inst_boundary, see Figure 5.12. In
this relation the three dierent kinds of boundary descriptions POINTS, CURVE
and COMPOSITE are recognized and corresponding DAE nodes are generated.
The common steps for each kind is:
static analysis: constant expression evaluation, type analysis and type
annotation of expressions, variable references, etc. In the COMPOSITE
55
Chapter 5. Implementation
relation elabbndparts: Absyn.Boundary list => Boundary list =
axiom elabbndparts ([]) => []
rule
rule
rule
end
Figure 5.11.: The relation elab_boundary_parts (abbreviated to elabbndparts) in the SCode module that handles the boundary description parts from the Absyn module.
case, only variable references are checked, because that is the only kind
of expression allowed in the composite() operator.
prexing expressions: adding the correct prex to variable references
in the current instantiation environment. A reference to a variable v
in a variable comp in the class being instantiated is prexed by comp.
to build comp.v.
state transition in class inference: modifying the state in the class
inference module ClassInf which keeps track of the class state in
order to check if the class contents is consistent with the restricted
class type. In this case the transition to FOUND_BOUNDARY has been
added.
56
Figure 5.12.: The inst_boundary relation that instantiates the three dierent kinds of boundary elements, POINTS, CURVE and COMPOSITE
and builds the corresponding DAE structures.
57
Chapter 5. Implementation
declaration and initialization of parameters, function denitions, creating
functions for parameterized boundary description and associating boundary
conditions and boundary sections. The generated code is incomplete, and is
combined with prewritten C++ code.
Model Parameters
The model parameters declared in functions are collected and generated as
elds in separate C++ structs, one for each function instance. The model
parameters of the instantiated, complete model are generated as elds in a
struct that contains all the parameters of all subcomponents as a at list
of C++ variables. Initialization of all model parameters of all functions is
performed in an initialization routine, and another routine initializes the
values of the model parameters. The pointer to the model parameter struct
is passed to functions so that model parameters can be accessed from within
instantiated functions.
Functions
The rst step of function code generation is to generate a unique C++ struct
for each function, containing the Modelica parameters of that function. A
global struct variable is declared at the same time, with a name corresponding to the full name of the function with dots replaced by underscores. Later,
initialization code is generated for assigning the parameter values for all
function parameters.
Next, the function head is generated. The input variables are generated as
arguments of the function with their type and value and output variables are
generated as the return value. For simple variable types simple C++ variables
are generated, like int, real, etc. For complex types a C++ struct is generated and the name of the struct is used as the type. If there is only one
output variable, the type of that variable is used as the return type of the
function. If there are more output variables, a return type struct is created
and used as the return value containing all the output variables. The return
variable is declared at the beginning of the function body and if a struct is
used, the output variables are prexed with the structs name appropriately.
The function body is generated from the algorithm section of the corresponding Modelica function which has a close correspondence to C++ code.
Finally, the return statement is constructed.
Function Instances
Code instances of parameterized functions are implemented using the replaceable function feature of Modelica. PDE and boundary condition mod-
58
Object2D
+getPoints(): point_vector
+getCurves(): curvep_vector
+isComposite(): bool
Curve2D
+func(u:Real): Point2D
DiscreteCurve2D
-points: point_vector
+add(point:Point2D)
Composite2D
-curves: curvep_vector
+add(in curve:Object2D)
Figure 5.13.: The class hierarchy for the C++ classes written to generate
domain descriptions. Line2D objects are represented by the
DiscreteCurve2D class.
The curve approach to boundary description uses a parametric expression that denes the boundary curve. The description is symbolic, but is
discretized before the triangulation can be made. This is handled by generating a function which calculates the coordinates of a point on the curve for
a given parameter value. For example, the boundary description:
curve(cos(2*PI*u), sin(2*PI*u), u);
59
Chapter 5. Implementation
is translated into a C++ function with the structure shown in Figure 5.14.
Point2D func(Real u) {
Point2D res;
res.x = cos(2*PI*u);
res.y = sin(2*PI*u);
return res;
}
described
as
The class Curve2D is used to represent parametric curve based descriptions. A new, specialized class is generated for each such domain description, which inherits Curve2D and overloads the func() method to calculate
the correct curve. The Curve2D class can be seen in Figure 5.15. The
getPoints() method automatically calls the func() method to generate
the required number of discrete points on the curve.
class Curve2D : public Object2D {
public:
Curve2D(string name=string("Curve2DObject"))
: Object2D(name) {
}
virtual Point2D func(Real u)=0;
virtual point_vector* getPoints(int n);
};
Figure 5.15.: The Curve2D class that represents parametric curves. Each
specic boundary description inherits this class and overloads
the func() method.
When the lines method is used for boundary description, the class DiscreteCurve2D is instantiated and the set of points from the lines description is added to that instance. See Figure 5.16 for the contents of the DiscreteCurve2D class. The list of points added to an instance is directly returned from the getPoints() method, ignoring the desired maximum number of points, for simplicity. Hence, it is assumed that the number of points
given in the lines operator is always less than the required number of discretization points on the boundary. If this does not hold, the result will be
a ner discretization than what is desired.
The composite method is slightly more complex to handle. Figure 5.17
shows the declaration of the Composite2D class that represents composite
boundaries. A composite curve is discretized by retrieving its constituent
60
curve segments and discretizing them, compensating for the overlaps at the
joints. The getCurves() method is used to access the curve segments. It traverses the composition hierarchy and collects all non-composite curves into
a single list. Hence, if a curve segment itself is composite, the getCurves()
method is called recursively on that curve object and the resulting list of
curves is inserted into the top level list. Thus, the list of curves returned
only contains Curve2D or DiscreteCurve2D objects.
class Composite2D : public Object2D {
curvep_vector curves;
public:
Composite2D(string name=string("Composite2D"))
: Object2D(name) {
}
virtual point_vector* getPoints(int n);
curvep_vector* getCurves();
void add(Object2D* c);
void add(Object2D** c, int n);
virtual bool isComposite() {
return true;
}
};
Figure 5.17.: The Composite2D class that represents a boundary that is composed of one or more other boundary objects, composite or
plain (curve or discrete curve). The getCurves() method recursively goes through any constituent composite curves, returning only a at list of non-composite curve segments.
61
Chapter 5. Implementation
Boundary Conditions
Boundary conditions are represented by the BoundaryCondition C++ class,
see Figure 5.18. The same class can be used for the three dierent kinds
of boundary conditions: Dirichlet, Robin, and Neumann conditions. The
names of the boundary condition objects are mapped from their names in
the Modelica domain description. The mesh generator and the PDE solver
supports named boundary segments. The code generation consists of instantiating the boundary condition objects and putting them in a list to be
passed to the solver.
class BoundaryCondition {
public:
space_function* g;
Float q;
bool is_dirichlet;
string name;
public:
typedef Float space_function (const point& p);
BoundaryCondition();
};
62
DiscreteDomain2D
+generate(domain:Object2D)
BamgMeshGenerator
GeoMeshGenerator
+discretize(curve:Object2D)
+optimize()
+getPoints()
+getSegments()
+getSubnames()
EasymeshMeshGenerator
Solver
+solve(domain,bclist,reglist)
RheolefSolver
MathFEMSolver
FEMLABSolver
Figure 5.19.: The class diagram for the mesh generator and the solver classes.
number of points on the boundary and creating a polygon with these points
as the corners of the polygon, in practice approximating the curve with
linear segments. The discretization is performed by calling the getPoints()
method of the Object2D interface. The discretizer also keeps track of the
boundary section names in order to pass the information to the PDE solver
for the boundary conditions to be applied appropriately.
This discretization is done because most mesh generators support the
boundary representation based on corner points and linear segments. In the
future, splines and other higher-order representations may be supported.
63
Chapter 5. Implementation
64
65
Chapter 5. Implementation
User input
PDE-Modeq
Parser
PDE-Modelica
Discretizer
domain
Translator
Mesh generator
mesh
Solver
External software
Figure 5.20.: Solution method using an external PDE solver or a pregenerated solver. This method is used with Rheolef and FEMLAB.
66
User input
PDE-Modeq
Parser
PDE-Modelica
domain
Discretizer
Translator
equations
boundary conditions
parameters
Mesh generator
External software
mesh
Solver generator
Mathematica
Solver
Parameter values
Figure 5.21.: Solution method with dynamic solver generation. This method
is used with the MathFEM solver.
67
Chapter 5. Implementation
68
Chapter 6.
Examples
This chapter contains three examples solved using the prototype implementation. The static current example in Section 6.2 was only partially dened
in PDEModelica, because of lack of subdomain support. The heat transfer example in Section 6.3 was solved using both Rheolef and FEMLAB for
comparison. Time-dependent problems can be solved using FEMLAB, and
an experimental time-dependent solver is implemented for Rheolef, but no
time-dependent examples are mentioned here.
(6.1)
69
Chapter 6. Examples
V=500kV
E
D
Transformer
V=0
Consider a high voltage substation in the vicinity of an electrically grounded transformer [20], illustrated in Figure 6.1. The line labeled A represents
the high voltage part with the potential V = 500kV , and line B denes the
transformer and the ground with V = 0. The lines C and D are chosen
to be far away from the transformer, where the electrical eld becomes approximately vertical and thus tangential to the lines C and D. No change
in electric eld intensity occurs across lines C and D because of the Neumann boundary conditions. The lines A and B have constant potential,
corresponding to Dirichlet boundary conditions.
The PDEModelica code for this example is shown in Figure 6.2. The
model is translated, compiled, and executed. The resulting plot can be seen
in Figure 6.3.
70
(6.2)
domain VoltageLine
extends Domain2D;
boundary
line({{4.5, 2.}, {2., 2.}, {2., 1.0}, {-0.5, 1.0}, {-1.5, 2.},
{-4.5, 2.}});
end VoltageLine;
domain Transformer
extends Domain2D;
boundary
line({{-4.5, -2.}, {-1., -2.}, {-1., -1.5}, {-1.5, -1.}, {-1.5, 0.},
{1.5, 0.}, {1.5, -1.}, {1., -1.5}, {1., -2.}, {4.5, -2.}});
end Transformer;
domain TransformerDomain
extends Domain2D;
VoltageLine voltageline;
Transformer transformer;
Line2D left (x0=-4.5, y0= 2, x1=-4.5, y1=-2);
Line2D right(x0= 4.5, y0=-2, x1= 4.5, y1= 2);
boundary
composite(voltageline, left, transformer, right);
end TransformerDomain;
model ElectricField
parameter Real rho=0, epsilon=1;
extends PDECoeff2D(c=epsilon, f=rho);
end ElectricField;
model PDEModel
Dirichlet voltageline(g=500), ground(g=0);
Neumann verticalfield;
ElectricField ef;
equation
dom.eq=ef;
dom.left.bc=verticalfield;
dom.right.bc=verticalfield;
dom.voltageline.bc=voltageline;
dom.transformer.bc=ground;
end PDEModel;
Figure 6.2.: PDEModelica code for the electric eld calculation example
in Section 6.1 with a high voltage substation and a grounded
transformer.
71
Chapter 6. Examples
2
480
450
420
390
360
330
300
270
240
210
180
150
120
90
60
30
0
2
4
4.5
72
Va
C
B
E
copper
E
aluminium
Vb
Figure 6.4.: A static current problem. The current on the boundaries C and
D is given, and the current distribution inside the domain is
calculated.
0.84
0.28
0.24
0.88
0.8
0.64
0.6
0.52
0.72
0.44
0.32
0.04
0.96
0.76
0.56
0.68
0.48
0.4
0.2
0.16
0.12
0.08
0.92
0.36
0.84
0.28
0.24
0.88 .8
0
44
0.
2
0.3
0.2
0.6
4
0.5 0.6
2
0.72
0.0
8
0.88
0.8
0.56
0.48
0.4
0.28
0.16
0.76
0.68
0.72
0.64
0.6
0.52
0.44
0.36
0.32
0.12
0.96
0.92
0.84
68 0.7
0.04
0.3
0.96
0.
0.5
0.16
0.2
0.12
0.08
0.4
0.4
0.28
0.2
0.24
0.2
0.16
0.12
0.04
0.08
0.04
1
1
Figure 6.5.: Solution of the static current problem dened in Section 6.2.
73
Chapter 6. Examples
2
59
57.6
56.2
54.7
53.3
51.8
50.4
49
47.5
46.1
44.6
43.2
41.8
40.3
38.9
37.4
36
2
5
Figure 6.6.: Solution of the stationary heat conduction example in Section 6.3 using Rheolef.
Figure 6.7.: Solution of the stationary heat conduction example in Section 6.3 using FEMLAB.
74
domain Circle2D
extends Cartesian2D;
parameter Real PI=3.14159265358979;
parameter Real x0=0, y0=0, ra=1, rb=ra, a=2*PI, b=0;
parameter Real u;
boundary
curve(x0 + ra*cos(a*u + b), y0 + rb*sin(a*u + b));
end Circle2D;
domain TestDomain
extends Domain2D;
parameter Real PI=3.14159265358979;
Bezier2D right(px=[ 1.0, 1.3, -4.0, -4.0, 1.3, 1.0],
py=[-2.0, 0.0, -3.0, 3.0, 0.0, 2.0]);
Line2D top(x0=1, y0=2, x1=-1, y1=2);
Circle2D left(x0=-1, y0=-2, ra=4, a=PI/2, b=PI/2);
Line2D bottom1(x0=-5, y0=-2, x1=-3, y1=-2);
Line2D bottom2(x0=-3, y0=-2, x1=-1, y1=-2);
Line2D bottom3(x0=-1, y0=-2, x1=1, y1=-2);
boundary
composite(right, top, left, bottom1, bottom2, bottom3);
end TestDomain;
Figure 6.8.: The domain geometry for the example in Section 6.3. See Figure 4.3 and Figure 4.2 for the denitions of Bezier2D and
Line2D, respectively.
75
Chapter 6. Examples
76
Chapter 7.
Conclusions and Future Work
This chapter presents some conclusions drawn from the results of this research, and outlines future work that is needed to achieve a more complete
solution to the problem.
7.1. Conclusions
The language extensions described in this thesis and implemented in the
prototype suce to solve PDE problems based on a general PDE with coecients that can be modied. The three most common types of boundary conditions are supported, which allows formulation and solution of a
wide range of problems that are based on the predened PDE. Complex
domain boundaries are supported thanks to the curve() operator which
allows a parametric description of the boundary, and the composite() operator which can combine boundary segments of curves and lines.
77
7.2.4. Debugging
There is ongoing work on debugging of declarative equation based languages,
specically debugging of Modelica models [6,7]. It is useful to also investigate
debugging of PDE based models, for example checking of sucient denition
of initial and boundary conditions.
78
References
[1] BAMG home page. http://www-rocq.inria.fr/gamma/cdrom/www/
bamg/eng.htm.
[2] Dynasim AB. http://www.dymola.com/.
[3] EasyMesh home page.
http://www-dinma.univ.trieste.it/
~nirftc/research/easymesh/easymesh.html.
[4] ANTLR home page. http://www.antlr.org/.
[5] P. Aronsson, P. Fritzson, L. Saldamli, and P. Bunus. Incremental Declaration Handling in Open Source Modelica. In Martin Otter, editor,
Proc. of the SIMS - 43rd Conference on Simulation and Modeling, Oulu,
Finland, September 2002.
[6] P. Bunus and P. Fritzson. A Debugging Scheme for Declarative Equation Based Languages. In Proceedings of the 4th International Symposium on Practical Aspects of Declarative Languages, volume 2257 of
LNCS. Springer-Verlag, 2002.
[7] Peter Bunus. Debugging and Structural Analysis of Declarative
Equation-Based Languages. Licentiate Thesis, PELAB, Dept. of Computer and Information Science, Link
opings universitet, 2002.
[8] Pierre E. Bezier. The First Years of CAD/CAM and the UNISURF
CAD System. In Les Piegl, editor, Fundamental Developments of
Computer-Aided Geometric Modeling, pages 1326. Academic Press,
1993.
[9] C.-K.Shene. Introduction to Computing with Geometry. http://www.
cs.mtu.edu/~shene/COURSES/cs3621/NOTES/notes.html.
[10] A. F. Cardenas and W. J. Karplus. PDEL a Language for Partial
Dierential Equations. Communications of the ACM, 13(3):184191,
March 1970.
79
References
[11] Paul de Casteljau. Polar Forms for Curve and Surface Modeling as
Used at Citroen. In Les Piegl, editor, Fundamental Developments
of Computer-Aided Geometric Modeling, pages 112. Academic Press,
1993.
[12] Dipack home page. http://www.diffpack.com/.
[13] FEMLAB home page. http://www.femlab.com/.
[14] P. Fritzson. Ecient Language Implementation by Natural Semantics.
Personal communication. Book draft 1996.
[15] P. Fritzson. Principles of Object-Oriented Modeling and Simulation.
Personal communication. Book draft 2002. Chapter 1 on http://www.
ida.liu.se/~pelab/modelica/.
[16] P. Fritzson, P. Aronsson, P. Bunus, V. Engelson, L. Saldamli, H. Johansson, and A. Karstr
om. The Open Source Modelica Project. In Martin Otter, editor, Proc. of the 2nd International Modelica Conference,
Oberpfaenhofen, Germany, March 2002. http://www.modelica.
org/.
[17] P. Fritzson and P. Bunus. Modelica, a General Object-Oriented Language for Continuous and Discrete-Event System Modeling and Simulation. In Proceedings of the 35th Annual Simulation Symposium, San
Diego, California, April 2002.
[18] P. Fritzson, J. Gunnarsson, and M. Jirstrand. MathModelica - An Extensible Modeling and Simulation Environment with Integrated Graphics and Literate Programming. In Proc. of the 2nd International Modelica Conference, Munich, March 2002. http://www.modelica.org/.
[19] E. N. Houstis, J. R. Rice, S. Weerawarana, A. C. Catlin, P. Papachiou, K.-Y. Wang, and M. Gaitatzes. PELLPACK: A ProblemSolving Environment for PDE-Based Applications on Multicomputer
Platforms. ACM Transactions on Mathematical Software, 24(1):3073,
March 1998.
[20] Nathan Ida and Jo
ao P.A. Bastos. Electromagnetics and Calculation of
Fields, chapter 9.10, pages 391392. Springer, 2nd edition, 1997.
[21] G. Kahn. Natural semantics. In Proceedings of the Symposium on
Theoretical Aspects of Computer Science, STACS87, volume 247 of
LNCS, pages 2239. Springer-Verlag, 1987.
80
References
[22] D. K
agedal. A Natural Semantics Specication for the Equation-based
Modeling Language Modelica. Masters thesis, PELAB, Dept. of Computer and Information Science, Link
opings universitet, October 1998.
LiTH-IDA-Ex-98/48.
[23] D. K
agedal and P. Fritzson. Generating a Modelica Compiler from
Natural Semantics Specications. In Proceedings of the 1998 Summer
Computer Simulation Conference (SCSC98), Reno, Nevada, July 1998.
[24] Macsyma home page. http://www.scientek.com/macsyma/main.htm.
[25] MathCore. http://www.mathcore.com.
[26] R. Milner, M. Tofte, R. Harper, and D. MacQueen. The Denition of
Standard ML (Revised). MIT Press, 1997.
[27] Modelica Association. Modelica A Unied Object-Oriented Language
for Physical Systems Modeling - Language Specication Version 2.0,
Jan 2002. http://www.modelica.org/.
[28] Modelica Association. Modelica Standard Library, 2002. http://www.
modelica.org/libraries.shtml.
[29] NETLIB home page. http://www.netlib.org/.
[30] M. Oh. Modelling and Simulation of Combined Lumped and Distributed
Processes. PhD thesis, University of London, 1995.
[31] Open Source Modelica home page. http://www.ida.liu.se/~pelab/
modelica.
[32] Overture home page. http://www.llnl.gov/CASC/Overture/.
[33] M. Pettersson. Compiling Natural Semantics. volume 1549 of LNCS.
Springer-Verlag, 1999.
[34] J. R. Rice. An Agent-based Architecture for Solving Partial Dierential
Equations. SIAM News, 31(6), 1998.
[35] L. Saldamli and P. Fritzson. Object-Oriented Modeling with Partial
Dierential Equations. In Proc. of Modelica Workshop 2000, Lund,
Sweden, October 2000. http://www.modelica.org/.
[36] L. Saldamli and P. Fritzson. Domains and Partial Dierential Equations
in Modelica. In Tor Anders Hauge, Bernt Lie, Rolf Ergon, Marta Due
nas Des, Glenn-Ole Kaasa, Anita Dale, Bjorn Glemmestad, and Are
Mjaavatten, editors, Proc. of the 42nd SIMS Conference, Porsgrunn,
Norway, October 2001.
81
References
[37] L. Saldamli and P. Fritzson. A Modelica-based Language for ObjectOriented Modeling with Partial Dierential Equations. In A. Heemink,
L. Dekker, H. de Swaan Arons, I. Smith, and T. van Stijn, editors, Proc.
of the 4th International EUROSIM Congress, Delft, The Netherlands,
June 2001.
[38] L. Saldamli, P. Fritzson, and B. Bachmann. Extending Modelica for
Partial Dierential Equations. In Martin Otter, editor, Proc. of the 2nd
International Modelica Conference, Oberpfaenhofen, Germany, March
2002.
[39] Pierre Saramito and Nicolas Roquet. Rheolef home page. http://
www-lmc.imag.fr/lmc-edp/Pierre.Saramito/rheolef/, 2002.
[40] Pierre Saramito and Nicolas Roquet. Rheolef users manual. Technical report, LMC-IMAG, 2002. http://www-lmc.imag.fr/lmc-edp/
Pierre.Saramito/rheolef/usrman.ps.gz.
[41] K. Sheshadri and P. Fritzson. A Mathematica-based PDE-solver generator. In Proc. of the Scandinavian Simulation Society (SIMS) Conference, Linko
ping University, Linko
ping, Sweden, September 1999.
[42] K. Sheshadri and P. Fritzson. A General Symbolic PDE-Solver Generator: Explicit Schemes. Accepted for publication in Scientic Programming, 2001.
[43] G. D. Smith. Numerical Solution of Partial Dierential Equations:
Finite Dierence Methods, chapter one, pages 69. Oxford University
Press, third edition, 1985.
[44] K.
Ahlander. An Object-Oriented Framework for PDE Solvers. PhD
thesis, Uppsala University, 1999.
[45] Hubertus Tummescheit. Design and Implementation of Object-Oriented
Model Libraries using Modelica. PhD thesis, Lund Institute of Technology, 2002.
[46] S. Weerawarana. Problem Solving Environments for Partial Dierential
Equation based Applications. PhD thesis, Department of Computer
Sciences, Purdue University, August 1994.
82
Appendix A.
PDE Solver Using Rheolef
Rheolef specic parts from RheolefSolver.cc:
/
Common r o u t i n e to c r e a t e th e Xh s p a c e based on th e
boundary c o n d i t i o n s .
/
omega ,
string & eltype ,
v e c t o r<BoundaryCondition > & b c l i s t ,
& Xh ) {
domain t o b l o c k ;
i n t n d i r =0;
f o r ( unsigned i n t i = 0 ; i<b c l i s t . s i z e ( ) ; i ++) {
domain d = omega [ b c l i s t [ i ] . getName ( ) ] ;
if ( bclist [ i ]. is dirichlet ) {
n d i r ++;
t o b l o c k += d ;
}
}
i f ( ndir > 0)
Xh . b l o c k ( t o b l o c k ) ;
}
/
Steadys t a t e s o l v e r . e l t y p e i s one o f th e e l e m e n t t y p e s
used i n R h e o l e f , e . g . P1 . Each DomainRegion c o n t a i n s
th e c and f c o e f f i c i e n t s o f th e PDE . Only d i f f e r e n t
c c o e f f i c i e n t s a r e s u p p o r te d ( same f f o r th e e n t i r e
domain ) .
/
83
i n t nneumann = 0 , n r o b i n =0;
s p a c e Xh( omega , e l t y p e ) ;
makeXh ( omega , e l t y p e , b c l i s t , Xh ) ;
s p a c e Qh ( omega , P0 , v e c t o r ) ;
f i e l d e t a ( Qh , 1 ) ;
i f ( r e g l i s t . s i z e () == 1) {
e t a = r e g l i s t [ 0 ] . pde>c ;
}
else {
f o r ( unsigned i n t i = 0 ; i< r e g l i s t . s i z e ( ) ; i ++) {
e t a [ r e g l i s t [ i ] . name ] = r e g l i s t [ i ] . pde>c ;
c o u t << r e g l i s t [ i ] . name << = << r e g l i s t [ i ] . pde>c ;
c o u t << e n d l ;
}
}
form diag d ( eta ) ;
form grad ( Xh , Qh , grad ) ;
form m ( Xh , Xh , mass ) ;
form inv m ( Qh , Qh , i n v m a s s ) ;
f i e l d f h = i n t e r p o l a t e ( Xh , f ) ;
f i e l d uh ( Xh ) ;
v e c<F l o a t > s o l v e c = m. uu f h . u + m. ub f h . b ;
form a = t r a n s ( grad ) ( inv m d ) grad ;
f o r ( unsigned i n t i = 0 ; i< b c l i s t . s i z e ( ) ; i ++) {
domain d = omega [ b c l i s t [ i ] . getName ( ) ] ;
s p a c e Wh ( omega , d , e l t y p e ) ;
f i e l d gh = i n t e r p o l a t e (Wh, b c l i s t [ i ] . g ) ;
if ( bclist [ i ]. is dirichlet ) {
uh [ d ] = gh ;
} else {
form mb (Wh, Xh , mass bdr ) ;
s o l v e c += mb . uu gh . u + mb . ub gh . b ;
i f ( b c l i s t [ i ] . q == 0)
nneumann++;
else {
n r o b i n++;
form ab ( Xh , Xh , mass bdr , d ) ;
a = a + b c l i s t [ i ] . q ab ;
}
}
}
84
s o l v e c = a . ub uh . b ;
s s k<F l o a t > f a c t = l d l t ( a . uu ) ;
uh . u = f a c t . s o l v e ( s o l v e c ) ;
c o u t << uh ;
}
/
85
86
Appendix B.
FEMLAB Domain Generation
Interface Routine
The Matlab routine femlabdomainfix for reordering of the boundary conditions after FEMLABs vertex sorting. The input variables are the array
of points with coordinates and boundary condition indices v, the array of
edges with vertex indices and boundary condition indices and e. The output variables are the generated FEMLAB polygon object poly and the array
neweb of boundary condition indices with the correct order according to the
created polygon.
femlabdomainfix.m:
vx = v ( : , 1 ) ;
vy = v ( : , 2 ) ;
vb = v ( : , 3 ) ;
es = e ( : , 1 ) ;
ee = e ( : , 2 ) ;
eb = e ( : , 3 ) ;
p o l y=l i n e 2 ( vx , vy ) ;
n e w v e r t i c e s=flgeomvtx ( p o l y ) ;
newedges=flgeomse ( p o l y ) ;
newvx=n e w v e r t i c e s ( : , 1 ) ;
newvy=n e w v e r t i c e s ( : , 2 ) ;
newes=newedges ( : , 1 ) ;
newee=newedges ( : , 2 ) ;
n=length ( newes ) ;
neweb=ones ( n , 1 ) ;
87
myeps = ep s 1 0 0 ;
f o r i =1: n
news = newes ( i ) ;
newe = newee ( i ) ;
newsx = newvx ( news ) ;
newsy = newvy ( news ) ;
newex = newvx ( newe ) ;
newey = newvy ( newe ) ;
f o r j =1:n
s2 = es ( j ) ;
e2 = ee ( j ) ;
s x = vx ( s 2 ) ;
s y = vy ( s 2 ) ;
ex = vx ( e2 ) ;
ey = vy ( e2 ) ;
i f ( ( abs ( newsxs x ) <
( abs ( newexex ) <
( ( abs ( newsxex ) <
( abs ( newexs x ) <
neweb ( i ) = eb ( j ) ;
end
end
end
88
myeps )
myeps )
myeps )
myeps )
&
&
&
&
( abs ( newsys y )
( abs ( neweyey )
( abs ( newsyey )
( abs ( neweys y )
<
<
<
<
myeps ) & . . .
myeps ) ) | . . .
myeps ) & . . .
myeps ) )
Appendix C.
Problem Formulation Generated
for FEMLAB
The generated problem formulation code for the heat transfer example in
Section 6.3 for solving with FEMLAB. The arrays v and e are passed to
femlabdomainfix.m, shown in Appendix B, which creates the FEMLAB
polygon in poly and puts the boundary conditions in neweb.
femlabproblem.m:
c l e a r fem ;
fem . dim = { u } ;
fem . form = c o e f f i c i e n t ;
fem . equ . f = 0 ;
fem . equ . c = 1 ;
bnd . g = { { { 1 . 0 8 e + 0 6 } } , { { 0 } } , { { 0 } } ,
{{0}}, {{0}}, {{0}}};
bnd . q = { { { 3 0 0 0 0 } } , { { 0 } } , { { 0 } } ,
{{0}}, {{0}}, {{0}}};
bnd . h = { { { 0 } } , { { 0 } } , { { 0 } } ,
{{0}}, {{1}}, {{0}}};
bnd . r = { { { 0 } } , { { 0 } } , { { 0 } } ,
{{0}}, {{60}}, {{0}}};
v = [1 2 1;0.989529 1.70911 1;0.87162 1.50575 1;0.670313
1.36317 1;0.407803 1.25928 1;0.104429 1.17629 1;0.221312
1.10036 1;0.552779 1.02119 1;0.875175 0.93169
1;1.17556 0.827545 1;1.44283 0.706894 1;1.66774
0.569928 1;1.8429 0.418526 1;1.96275 0.255877 1;2.0236
0.0861045 1;2.0236 0.0861045 1;1.96275 0.255877 1;1.8429
0.418526 1;1.66774 0.569928 1;1.44283 0.706894 1;1.17556
0.827545 1;0.875175 0.93169 1;0.552779 1.02119 1;0.221312
1.10036 1;0.104429 1.17629 1;0.407803 1.25928 1;0.670313
1.36317 1;0.87162 1.50575 1;0.989529 1.70911 1;1 2 1;1 2
89
90
Appendix D.
PDE Formulation Generated for
Mathematica Based Solver
The generated problem formulation code for the heat transfer example in
Section 6.3 for the Mathematica based FEM solver. Two les are generated, the rst one for the solver generation and then code generation using
MathCode, and the second one for the execution of the solver.
91
92
Datum
Date
Avdelning, Institution
Division, department
Institutionen fr datavetenskap
LINKPINGS UNIVERSITET
Sprk
Language
Svenska/Swedish
Engelska/English
2002-12-18
Rapporttyp
Report: category
ISBN
ISRN
Licentiatavhandling
Examensarbete
C-uppsats
D-uppsats
vrig rapport
91- 7373-560-4
LiU-Tek-Lic- 2002:63
ISSN
0280-7971
Titel
Title
PDEModelica - Towards a High-Level Language for Modeling with Partial Differential Equations
Frfattare
Author
Levon Saldamli
Sammandrag
Abstract
This thesis describes initial language extensions to the Modelica language to define a more general
language called PDEModelica, with built-in support for modeling with partial differential equations
(PDEs). Modelica is a standardized modeling language for object-oriented, equation-based modeling. It also supports component-based modeling where existing components with modified parameters can be combined into new models. The aim of the language presented in this thesis is to maintain
the advantages of Modelica and also add partial differential equation support.
Partial differential equations can be defined using a coefficient-based approach, where a predefined
PDE is modified by changing its coefficient values. Language operators to directly express PDEs in
the language are also discussed. Furthermore, domain geometry description is handled and language
extensions to describe geometries are presented. Boundary conditions, required for a complete PDE
problem definition, are also handled.
A prototype implementation is described as well. The prototype includes a translator written in the
relational meta-language, RML, and interfaces to external software such as mesh generators and PDE
solvers, which are needed to solve PDE problems. Finally, a few examples modeled with PDEModelica and solved using the prototype are presented.
Nyckelord
Keywords
Vojin Plavsic: Interleaved Processing of Non-Numerical Data Stored on a Cyclic Memory. (Available at:
FOA, Box 1165, S-581 11 Linkping, Sweden. FOA Report B30062E)
Arne Jnsson, Mikael Patel: An Interactive Flowcharting Technique for Communicating and Realizing Algorithms, 1984.
Johnny Eckerland: Retargeting of an Incremental Code Generator, 1984.
Henrik Nordin: On the Use of Typical Cases for Knowledge-Based Consultation and Teaching, 1985.
Zebo Peng: Steps Towards the Formalization of Designing VLSI Systems, 1985.
Johan Fagerstrm: Simulation and Evaluation of Architecture based on Asynchronous Processes, 1985.
Jalal Maleki: ICONStraint, A Dependency Directed Constraint Maintenance System, 1987.
Tony Larsson: On the Specification and Verification of VLSI Systems, 1986.
Ola Strmfors: A Structure Editor for Documents and Programs, 1986.
Christos Levcopoulos: New Results about the Approximation Behavior of the Greedy Triangulation, 1986.
Shamsul I. Chowdhury: Statistical Expert Systems - a Special Application Area for Knowledge-Based Computer Methodology, 1987.
Rober Bilos: Incremental Scanning and Token-Based Editing, 1987.
Hans Block: SPORT-SORT Sorting Algorithms and Sport Tournaments, 1987.
Ralph Rnnquist: Network and Lattice Based Approaches to the Representation of Knowledge, 1987.
Mariam Kamkar, Nahid Shahmehri: Affect-Chaining in Program Flow Analysis Applied to Queries of Programs, 1987.
Dan Strmberg: Transfer and Distribution of Application Programs, 1987.
Kristian Sandahl: Case Studies in Knowledge Acquisition, Migration and User Acceptance of Expert Systems, 1987.
Christer Bckstrm: Reasoning about Interdependent Actions, 1988.
Mats Wirn: On Control Strategies and Incrementality in Unification-Based Chart Parsing, 1988.
Johan Hultman: A Software System for Defining and Controlling Actions in a Mechanical System, 1988.
Tim Hansen: Diagnosing Faults using Knowledge about Malfunctioning Behavior, 1988.
Jonas Lwgren: Supporting Design and Management of Expert System User Interfaces, 1989.
Ola Petersson: On Adaptive Sorting in Sequential and Parallel Models, 1989.
Yngve Larsson: Dynamic Configuration in a Distributed Environment, 1989.
Peter berg: Design of a Multiple View Presentation and Interaction Manager, 1989.
Henrik Eriksson: A Study in Domain-Oriented Tool Support for Knowledge Acquisition, 1989.
Ivan Rankin: The Deep Generation of Text in Expert Critiquing Systems, 1989.
Simin Nadjm-Tehrani: Contributions to the Declarative Approach to Debugging Prolog Programs, 1989.
Magnus Merkel: Temporal Information in Natural Language, 1989.
Ulf Nilsson: A Systematic Approach to Abstract Interpretation of Logic Programs, 1989.
Staffan Bonnier: Horn Clause Logic with External Procedures: Towards a Theoretical Framework, 1989.
Christer Hansson: A Prototype System for Logical Reasoning about Time and Action, 1990.
Bjrn Fjellborg: An Approach to Extraction of Pipeline Structures for VLSI High-Level Synthesis, 1990.
Patrick Doherty: A Three-Valued Approach to Non-Monotonic Reasoning, 1990.
Tomas Sokolnicki: Coaching Partial Plans: An Approach to Knowledge-Based Tutoring, 1990.
Lars Strmberg: Postmortem Debugging of Distributed Systems, 1990.
Torbjrn Nslund: SLDFA-Resolution - Computing Answers for Negative Queries, 1990.
Peter D. Holmes: Using Connectivity Graphs to Support Map-Related Reasoning, 1991.
Olof Johansson: Improving Implementation of Graphical User Interfaces for Object-Oriented KnowledgeBases, 1991.
Rolf G Larsson: Aktivitetsbaserad kalkylering i ett nytt ekonomisystem, 1991.
Lena Srmbck: Studies in Extended Unification-Based Formalism for Linguistic Description: An Algorithm for Feature Structures with Disjunction and a Proposal for Flexible Systems, 1992.
Mikael Pettersson: DML-A Language and System for the Generation of Efficient Compilers from Denotational Specification, 1992.
Andreas Kgedal: Logic Programming with External Procedures: an Implementation, 1992.
Patrick Lambrix: Aspects of Version Management of Composite Objects, 1992.
Xinli Gu: Testability Analysis and Improvement in High-Level Synthesis Systems, 1992.
Torbjrn Nslund: On the Role of Evaluations in Iterative Development of Managerial Support Sytems,
1992.
Ulf Cederling: Industrial Software Development - a Case Study, 1992.
Magnus Morin: Predictable Cyclic Computations in Autonomous Systems: A Computational Model and Implementation, 1992.
Mehran Noghabai: Evaluation of Strategic Investments in Information Technology, 1993.
Mats Larsson: A Transformational Approach to Formal Digital System Design, 1993.
Johan Ringstrm: Compiler Generation for Parallel Languages from Denotational Specifications, 1993.
Michael Jansson: Propagation of Change in an Intelligent Information System, 1993.
Jonni Harrius: An Architecture and a Knowledge Representation Model for Expert Critiquing Systems, 1993.
Per sterling: Symbolic Modelling of the Dynamic Environments of Autonomous Agents, 1993.
Johan Boye: Dependency-based Groudness Analysis of Functional Logic Programs, 1993.
No 402
No 406
No 414
No 417
No 436
No 437
No 440
FHS 3/94
FHS 4/94
No 441
No 446
No 450
No 451
No 452
No 455
FHS 5/94
No 462
No 463
No 464
No 469
No 473
No 475
No 476
No 478
FHS 7/95
No 482
No 488
No 489
No 497
No 498
No 503
FHS 8/95
FHS 9/95
No 513
No 517
No 518
No 522
No 538
No 545
No 546
FiF-a 1/96
No 549
No 550
No 557
No 558
No 561
No 563
No 567
No 575
No 576
No 587
No 589
No 591
No 595
No 597
No 598
No 599
No 607
No 609
FiF-a 4
FiF-a 6
No 615
No 623
No 626
No 627
No 629
No 631
No 639
No 640
No 643
No 653
FiF-a 13
No 674
No 676
No 668
No 675
FiF-a 14
No 695
No 700
FiF-a 16
No 712
No 719
No 723
No 725
No 730
No 731
No 733
No 734
FiF-a 21
FiF-a 22
No 737
No 738
FiF-a 25
No 742
No 748
No 751
No 752
No 753
No 754
No 766
No 769
No 775
FiF-a 30
No 787
No 788
No 790
No 791
No 800
No 807
No 809
FiF-a 32
No 808
No 820
No 823
No 832
FiF-a 34
No 842
No 844
FiF-a 37
FiF-a 40
FiF-a 41
No. 854
No 863
No 881
No 882
No 890
Fif-a 47
No 894
No 906
No 917
No 916
Fif-a-49
Fif-a-51
No 919
No 915
No 931
No 933
No 938
No 942
No 956
FiF-a 58
No 964
No 973
No 958
Fif-a 61
No 985
No 982
No 989
No 990