Problem Set 2

advertisement
Institute for Applied Mathematics
University of Heidelberg
Stefan Frei1 , Matthias Klinger2 ,
Matthias Maier3 , Jevgeni Vihharev4
30.11.2011
Problem Set No. 2 – Gascoigne Workshop
Winter Term 2011/2012
Based on the tutorial5
by Thomas Richter6
Changing the Problem
The template for this problem set is given in:
1
cp −r / s r v / s h a r e / g a s c o i g n e /2011/ ps2 .
First you need to configure the example using cmake ../src in ps2/bin.
After that you have to compile the program with the command make.
In this problem set we learn about changing the problem definition: Boundary condition and Right hand side. The problem ps2 solves the Poisson
equation
−∆u = f
u=g
in Ω
on ∂Ω
with f = 1 and Dirichlet data g = 0 on the whole boundary of the domain.
Problem 2.1: (Changing the right hand side)
Here, we change the right hand side, given as a function f (x, y). In Gascoigne this function is specified by a class of type DomainRightHandSide
as defined in the file domainrighthandside.h. You can use the Online Documentation to get an impression of the fundamental functions, which are
already implemented in the header files (*.h). Therefore you open the following web-page:
http://www.numerik.uni-kiel.de/~mabr/gascoigne
1
stefan.frei@iwr.uni-heidelberg.de
matthias.klinger@iwr.uni-heidelberg.de
3
matthias.maier@iwr.uni-heidelberg.de
4
jevgeni.vihharev@iwr.uni-heidelberg.de
5
Gascoigne: http://numerik.uni-hd.de/~lehre/WS11/gascoigne/pdf-files/gascoignescript.pdf
6
thomas.richter@iwr.uni-heidelberg.de
2
1
and click on the Documentation-Link on the left hand side. With a further
click on the Classes-Link on the top of the right hand side you entering a
menu, which gives you an overview of all available header-files in Gascoigne. Here you have to choose the Link DomainRightHandSide to get further
information about the file domainrighthandside.h.
Chapter ”The right hand side“ in the tutorial describes which functions are
necessary to derive a class from this base class.
Open the file problem.h in your directory ../ps2/src and change the class
MyRhs which is derived from the class DomainRightHandSide defined in the
file domainrighthandside.h, such that the following right hand side is used:
1 if |x − 0.5| + |y − 0.5| ≤ 0.25
f (x, y) =
0 else
Do not expect a large change in the resulting solution. It nearly looks like the
original one. Visualize the solution with Visusimple using Actor->Scalarbar
to get an idea of the absolute values of the solution and compare it to the
solution of the first problem set (f = 1).
Problem 2.2: (Changing the Dirichlet data)
Dirichlet boundary values are given by the class of the type DirichletData,
which you can look up in the Online Documentation as described in the last
problem.
Chapter ”Dirichlet boundary data“ describes how to write this class. Modify
the program, such that the Dirichlet data is given by the function:
u = g, g(x, y) = x2 + y 2 .
∂Ω
Compare the solution to the former solutions!
Problem 2.3: (Mixed boundary data)
If on a piece of the boundary no Dirichlet data is indicated in the parameter file, Gascoigne uses the natural boundary condition. This condition
depends on the type of differential equation. For the Poisson equation the
natural boundary condition is the homogeneous Neumann condition
∂n u = 0
on ∂Ω.
This is seen by the integration by parts:
(∇u, ∇φ)Ω = (−∆u, φ)Ω + h∂n u, φi∂Ω ,
where h·, ·i∂Ω is the L2 -inner product on the boundary of the domain.
2
(1)
Prescribing Dirichlet conditions on a part of the boundary ΓD ⊂ ∂Ω means
that all test functions φ are zero here:
φ=0
on ΓD .
If we do not prescribe Dirichlet data on another part ΓN ⊂ ∂Ω we also do not
restrict the test space. Hence, the boundary term in the weak formulation
in equation (1) changes to:
h∂n u, φi∂Ω = h∂n u, φ iΓD + h∂n u, φiΓN = h∂n u, φiΓN = 0.
|{z}
=0
That means:
∂n u = 0 on ΓN .
Chapter ”Boundary Data“ describes how to choose different boundary conditions properly.
Our computational domain is a square given in the file square.inp in the
directory ../ps2/src. You can visualize the domain with Visusimple by
the command
1
visusimple square . inp &
In the .inp file the code
1
2
3
4
0
1
2
3
4
2
4
2
line
line
line
line
0
1
2
3
1
2
3
0
describes the boundary. Here the values 2 and 4 indicate ”colors“ corresponding to the different parts of the boundary. For detailed information
compare the chapter ”Definition of coarse meshes“.
Change the parameter file, such that Dirichlet data is valid only on the left
and right part of the boundary. These parts are indicated by the color value
2. On the top and bottom part there should be homogeneous Neumann
condition, marked by the color value 4.
What happens if you use Neumann boundary values on all parts of the
boundary? Look closely at the output of Gascoigne. Why is it like this?
For having no Dirichlet values at all, the //Block BoundaryManager has to
look like this:
1
// B l o c k BoundaryManager
2
3
dirichlet 0
3
Problem 2.4: (Homework)
If you use Neumann data on all parts of the boundary the solution is not
unique. If u is a solution of −∆u = f then for every c ∈ R another solution
is given by u + c since −∆c = 0.
To solve problems like this with Gascoigne we have to fix this ambiguity.
This can easily be done by adding the condition
Z
u dx = 0
Ω
for the mean value of the solution.
Therefore we add a parameter to //Block Solver in the parameter file:
1
pfilter 1 0
By this notation we tell Gascoigne that there is one solution component
(number zero), where we want to filter out the constants.
Hint: We will learn about components later, for scalar PDE’s we always
have only one component, for systems of PDE’s the number of equations is
the number of components.
Solve the Problem 2.3 with Neumann conditions on the whole boundary
with the above changes! Compare the results!
4
Download