1
// Copyright (C) 2012 Anders Logg
3
// This file is part of DOLFIN.
5
// DOLFIN is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU Lesser General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
10
// DOLFIN is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU Lesser General Public License for more details.
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
18
// First added: 2012-08-16
19
// Last changed: 2012-08-30
21
// This demo program solves the heat equation
23
// du/dt - div kappa(x, y) grad u(x, y, t) = f(x, y, t)
25
// on the unit square with source f given by
27
// f(x, y, t) = sin(5*t)*10*exp(-((x - 0.5)^2 + (y - 0.5)^2) / 0.02)
29
// heat conductivity kappa given by
31
// kappa(x, y) = 1 for x < 0.5
32
// kappa(x, y) = 0.1 for x >= 0.5
34
// boundary conditions given by
36
// u(x, y, t) = 0 for x = 0 or x = 1
37
// du/dn(x, y, t) = sin(5*x) for y = 0 or y = 1
39
// and initial condition given by u(x, y, 0) = 0.
43
// FIXME: Include standard file for now
46
using namespace dolfin;
48
// Source term (right-hand side)
49
class Source : public Expression
51
void eval(Array<double>& values, const Array<double>& x, double t) const
53
double dx = x[0] - 0.5;
54
double dy = x[1] - 0.5;
55
values[0] = sin(5*t)*10*exp(-(dx*dx + dy*dy) / 0.02);
59
// Normal derivative (Neumann boundary condition)
60
class dUdN : public Expression
62
void eval(Array<double>& values, const Array<double>& x, double t) const
64
values[0] = sin(5*x[0]);
68
// Sub domain for Dirichlet boundary condition
69
class DirichletBoundary : public SubDomain
71
bool inside(const Array<double>& x, bool on_boundary) const
73
return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS;
79
// Temporary until this works
80
cout << "This demo is not yet working" << endl;
83
// Create mesh and function space
84
UnitSquare mesh(32, 32);
85
Heat_2D::Form_0::TrialSpace V(mesh);
87
// Define boundary condition
89
DirichletBoundary boundary;
90
DirichletBC bc(V, u0, boundary);