← Back to team overview

fenics team mailing list archive

Re: [noreply@xxxxxxxxxxxxx: [Branch ~fenics-core/fenics-doc/main] Rev 11: Added Poisson.ufl and main.cpp file and create link for download.]

 



On 27 April 2010 14:18, Anders Logg <logg@xxxxxxxxx> wrote:
Any ideas on how to keep the code in the documentation and the actual
demos in sync? Should we have a script that copies all the source
files? Or should we do the opposite: extract the demos from the
documentation?

Good question, initially I thought copying from DOLFIN to documentation was the way to go, but on second thought the other  way around might be better.
The reason is that if the demos break, then they will be fixed in the documentation which makes is more likely that the accompanying text (and code snippets) will also be corrected.

Kristian

--
Anders


---------- Forwarded message ----------
From: noreply@xxxxxxxxxxxxx
To: Anders Logg <logg@xxxxxxxxx>
Date: Tue, 27 Apr 2010 12:01:19 -0000
Subject: [Branch ~fenics-core/fenics-doc/main] Rev 11: Added Poisson.ufl and main.cpp file and create link for download.
------------------------------------------------------------
revno: 11
committer: Kristian B. Ølgaard <k.b.oelgaard@xxxxxxxxx>
branch nick: fenics-doc
timestamp: Tue 2010-04-27 13:57:42 +0200
message:
 Added Poisson.ufl and main.cpp file and create link for download.
added:
 source/demos/cpp/pde/Poisson.ufl
 source/demos/cpp/pde/poisson_main.cpp
modified:
 source/demos/cpp/pde/cpp_poisson.rst


--
lp:fenics-doc
https://code.launchpad.net/~fenics-core/fenics-doc/main

You are subscribed to branch lp:fenics-doc.
To unsubscribe from this branch go to https://code.launchpad.net/~fenics-core/fenics-doc/main/+edit-subscription

=== added file 'source/demos/cpp/pde/Poisson.ufl'
--- source/demos/cpp/pde/Poisson.ufl    1970-01-01 00:00:00 +0000
+++ source/demos/cpp/pde/Poisson.ufl    2010-04-27 11:57:42 +0000
@@ -0,0 +1,20 @@
+# Copyright (C) 2005-2009 Anders Logg.
+# Licensed under the GNU LGPL Version 2.1.
+#
+# First added:  2005
+# Last changed: 2009-09-08
+#
+# The bilinear form a(v, u) and linear form L(v) for
+# Poisson's equation.
+#
+# Compile this form with FFC: ffc -l dolfin Poisson.ufl.
+
+element = FiniteElement("Lagrange", triangle, 1)
+
+v = TestFunction(element)
+u = TrialFunction(element)
+f = Coefficient(element)
+g = Coefficient(element)
+
+a = inner(grad(v), grad(u))*dx
+L = v*f*dx + v*g*ds

=== modified file 'source/demos/cpp/pde/cpp_poisson.rst'
--- source/demos/cpp/pde/cpp_poisson.rst        2010-04-27 11:12:29 +0000
+++ source/demos/cpp/pde/cpp_poisson.rst        2010-04-27 11:57:42 +0000
@@ -10,7 +10,7 @@

 This text is C++ specific

-Some UFL code in ``Poisson.h``
+Some UFL code in :download:`Poisson.ufl`.

 .. code-block:: python

@@ -71,3 +71,6 @@
    }
  };

+All this should be in the same :download:`main.cpp<poisson_main.cpp>` file.
+
+

=== added file 'source/demos/cpp/pde/poisson_main.cpp'
--- source/demos/cpp/pde/poisson_main.cpp       1970-01-01 00:00:00 +0000
+++ source/demos/cpp/pde/poisson_main.cpp       2010-04-27 11:57:42 +0000
@@ -0,0 +1,87 @@
+// Copyright (C) 2006-2009 Anders Logg.
+// Licensed under the GNU LGPL Version 2.1.
+//
+// First added:  2006-02-07
+// Last changed: 2010-04-05
+//
+// This demo program solves Poisson's equation
+//
+//     - div grad u(x, y) = f(x, y)
+//
+// on the unit square with source f given by
+//
+//     f(x, y) = 10*exp(-((x - 0.5)^2 + (y - 0.5)^2) / 0.02)
+//
+// and boundary conditions given by
+//
+//     u(x, y) = 0        for x = 0 or x = 1
+// du/dn(x, y) = -sin(5*x) for y = 0 or y = 1
+
+#include <dolfin.h>
+#include "Poisson.h"
+
+using namespace dolfin;
+
+// Source term (right-hand side)
+class Source : public Expression
+{
+  void eval(Array<double>& values, const Array<double>& x) const
+  {
+    double dx = x[0] - 0.5;
+    double dy = x[1] - 0.5;
+    values[0] = 10*exp(-(dx*dx + dy*dy) / 0.02);
+  }
+};
+
+// Boundary flux (Neumann boundary condition)
+class Flux : public Expression
+{
+  void eval(Array<double>& values, const Array<double>& x) const
+  {
+    values[0] = -sin(5*x[0]);
+  }
+};
+
+// Sub domain for Dirichlet boundary condition
+class DirichletBoundary : public SubDomain
+{
+  bool inside(const Array<double>& x, bool on_boundary) const
+  {
+    return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS;
+  }
+};
+
+int main()
+{
+  // Create mesh and function space
+  UnitSquare mesh(32, 32);
+  Poisson::FunctionSpace V(mesh);
+
+  // Define boundary condition
+  Constant u0(0.0);
+  DirichletBoundary boundary;
+  DirichletBC bc(V, u0, boundary);
+
+  // Define variational problem
+  Poisson::BilinearForm a(V, V);
+  Poisson::LinearForm L(V);
+  Source f;
+  Flux g;
+  L.f = f;
+  L.g = g;
+
+  // Compute solution
+  VariationalProblem problem(a, L, bc);
+  problem.parameters["linear_solver"] = "iterative";
+  Function u(V);
+  problem.solve(u);
+
+  // Save solution in VTK format
+  File file("poisson.pvd");
+  file << u;
+
+  // Plot solution
+  plot(u);
+
+  return 0;
+}


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkvW1i0ACgkQTuwUCDsYZdGwLgCdFPgbJke73i5QHWPo50NaQXxU
6cEAniYG20A/l8GYI389W10WZng8P7Vb
=ik1b
-----END PGP SIGNATURE-----

_______________________________________________
Mailing list: https://launchpad.net/~fenics
Post to     : fenics@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~fenics
More help   : https://help.launchpad.net/ListHelp



Attachment: signature.asc
Description: OpenPGP digital signature


Follow ups

References