| 1 |
// Copyright (C) 2010 Kristian B. Oelgaard |
| 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: 2010-07-23 |
| 19 |
// Last changed: 2012-11-12 |
| 20 |
// |
| 21 |
// This demo program solves Poisson's equation |
| 22 |
// |
| 23 |
// - div grad u(x, y) = f(x, y) |
| 24 |
// |
| 25 |
// on the unit square with source f given by |
| 26 |
// |
| 27 |
// f(x, y) = -1.0 if (x - 0.33)^2 + (y - 0.67)^2 < 0.015 |
| 28 |
// 5.0 if 0.015 < (x - 0.33)^2 + (y - 0.67)^2 < 0.025 |
| 29 |
// -1.0 if (x,y) in triangle( (0.55, 0.05), (0.95, 0.45), (0.55, 0.45) ) |
| 30 |
// 0.0 otherwise |
| 31 |
// |
| 32 |
// and homogeneous Dirichlet boundary conditions. |
| 33 |
|
| 34 |
#include <dolfin.h> |
| 35 |
#include "Conditional.h" |
| 36 |
|
| 37 |
using namespace dolfin; |
| 38 |
|
| 39 |
// Sub domain for Dirichlet boundary condition |
| 40 |
class DirichletBoundary : public SubDomain |
| 41 |
{ |
| 42 |
bool inside(const Array<double>& x, bool on_boundary) const |
| 43 |
{ |
| 44 |
return on_boundary; |
| 45 |
} |
| 46 |
}; |
| 47 |
|
| 48 |
int main() |
| 49 |
{ |
| 50 |
// Create mesh and function space |
| 51 |
auto mesh = std::make_shared<UnitSquareMesh>(64, 64); |
| 52 |
auto V = std::make_shared<Conditional::FunctionSpace>(mesh); |
| 53 |
|
| 54 |
// Define boundary condition |
| 55 |
auto u0 = std::make_shared<Constant>(0.0); |
| 56 |
auto boundary = std::make_shared<DirichletBoundary>(); |
| 57 |
DirichletBC bc(V, u0, boundary); |
| 58 |
|
| 59 |
// Define variational problem |
| 60 |
Conditional::BilinearForm a(V, V); |
| 61 |
Conditional::LinearForm L(V); |
| 62 |
|
| 63 |
// Compute solution |
| 64 |
Function u(V); |
| 65 |
solve(a == L, u, bc); |
| 66 |
|
| 67 |
// Save solution in VTK format |
| 68 |
File file("conditional.pvd"); |
| 69 |
file << u; |
| 70 |
|
| 71 |
return 0; |
| 72 |
} |