~corrado-maurini/dolfin/tao

« back to all changes in this revision

Viewing changes to demo/undocumented/heatequation/cpp/main.cpp

  • Committer: corrado maurini
  • Date: 2012-12-18 12:16:08 UTC
  • mfrom: (6685.78.207 trunk)
  • Revision ID: corrado.maurini@upmc.fr-20121218121608-nk82ly9jgsld9u84
updating with trunk, fix uint in TAO solver and hacking the check for tao FindTAO.cmake

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (C) 2012 Anders Logg
2
 
//
3
 
// This file is part of DOLFIN.
4
 
//
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.
9
 
//
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.
14
 
//
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/>.
17
 
//
18
 
// First added:  2012-08-16
19
 
// Last changed: 2012-08-30
20
 
//
21
 
// This demo program solves the heat equation
22
 
//
23
 
//     du/dt - div kappa(x, y) grad u(x, y, t) = f(x, y, t)
24
 
//
25
 
// on the unit square with source f given by
26
 
//
27
 
//     f(x, y, t) = sin(5*t)*10*exp(-((x - 0.5)^2 + (y - 0.5)^2) / 0.02)
28
 
//
29
 
// heat conductivity kappa given by
30
 
//
31
 
//     kappa(x, y) = 1   for x <  0.5
32
 
//     kappa(x, y) = 0.1 for x >= 0.5
33
 
//
34
 
// boundary conditions given by
35
 
//
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
38
 
//
39
 
// and initial condition given by u(x, y, 0) = 0.
40
 
 
41
 
#include <dolfin.h>
42
 
 
43
 
// FIXME: Include standard file for now
44
 
#include "Heat_2D.h"
45
 
 
46
 
using namespace dolfin;
47
 
 
48
 
// Source term (right-hand side)
49
 
class Source : public Expression
50
 
{
51
 
  void eval(Array<double>& values, const Array<double>& x, double t) const
52
 
  {
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);
56
 
  }
57
 
};
58
 
 
59
 
// Normal derivative (Neumann boundary condition)
60
 
class dUdN : public Expression
61
 
{
62
 
  void eval(Array<double>& values, const Array<double>& x, double t) const
63
 
  {
64
 
    values[0] = sin(5*x[0]);
65
 
  }
66
 
};
67
 
 
68
 
// Sub domain for Dirichlet boundary condition
69
 
class DirichletBoundary : public SubDomain
70
 
{
71
 
  bool inside(const Array<double>& x, bool on_boundary) const
72
 
  {
73
 
    return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS;
74
 
  }
75
 
};
76
 
 
77
 
int main()
78
 
{
79
 
  // Temporary until this works
80
 
  cout << "This demo is not yet working" << endl;
81
 
  return 0;
82
 
 
83
 
  // Create mesh and function space
84
 
  UnitSquare mesh(32, 32);
85
 
  Heat_2D::Form_0::TrialSpace V(mesh);
86
 
 
87
 
  // Define boundary condition
88
 
  Constant u0(0.0);
89
 
  DirichletBoundary boundary;
90
 
  DirichletBC bc(V, u0, boundary);
91
 
 
92
 
  return 0;
93
 
}