12.07.2015 Views

DOLFIN User Manual - FEniCS Project

DOLFIN User Manual - FEniCS Project

DOLFIN User Manual - FEniCS Project

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>DOLFIN</strong> <strong>User</strong> <strong>Manual</strong>Hoffman, Jansson, Logg, Wells2.2.2 Writing the solverHaving compiled the variational problem (2.4) with FFC, it is now easy toimplement a solver for Poisson’s equation. We first discuss the implementationline by line and then present the complete program. The source codefor this example is available in the directory src/demo/pde/poisson/ of the<strong>DOLFIN</strong> source tree.At the beginning of our C++ program, which we write in a text file namedmain.cpp, we must first include the header file dolfin.h, which gives ourprogram access to the <strong>DOLFIN</strong> class library. In addition, we include theheader file Poisson.h generated by the form compiler. Since all classes inthe <strong>DOLFIN</strong> class library are defined within the namespace dolfin, we alsospecify that we want to work within this namespace:#include #include ‘‘Poisson.h’’using namespace dolfin;Since we are writing a C++ program, we need to create a main function.You are free to organize your program any way you like, but in this simpleexample we just write our program inside the main function:int main(){// Write your program herereturn 0;}We now proceed to specify the right-hand side f of (2.1). This is done bydefining a new subclass of Function and overloading the eval() function toreturn the value f(x, y) = x sin(y):18

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!