neumann.tex 3.3 KB
 Thomas Witkowski committed Oct 23, 2008 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 \section{Neumann boundary conditions} \label{s:neumann} In this example, we solve the problem defined in Section \ref{s:ellipt}. But now, we set the domain $\Omega$ to $[-0.5;0.5]^2$, so the source $f$ is located in the middle of $\Omega$. Furthermore, we use Neumann boundary conditions on the left and on the right side of $\Omega$. We set $A\nabla u \cdot \nu = 1$ at the Neumann boundary. So, the derivative in direction of the surface normal is set to $1$ at these points. The rest of the boundary keeps unchanged (Dirichlet boundary, set to the true solution). \begin{table} \center \begin{tabular}{|cc|c|c|c|} \hline & & {\bf 1d} & {\bf 2d} & {\bf 3d} \\ \hline {\bf source code} & \tt src/ & \multicolumn{3}{|c|}{\tt neumann.cc} \\ \hline {\bf parameter file} & \tt init/ & \tt neumann.dat.1d & \tt neumann.dat.2d & \tt neumann.dat.3d \\ \hline {\bf macro file} & \tt macro/ & \tt neumann.macro.1d & \tt neumann.macro.2d & \tt neumann.macro.3d \\ \hline {\bf output files} & \tt output/ & \multicolumn{3}{|c|}{\tt neumann.mesh, neumann.dat} \\ \hline \end{tabular} \caption{Files of the {\tt neumann} example.} \end{table} \subsection{Source code} Only a few changes in the source code are necessary to apply Neumann boundary conditions. First, we define the function $N=1$.\\ \begin{lstlisting}{} class N : public AbstractFunction > { public: double operator()(const WorldVector& x) const { return 1.0; } }; \end{lstlisting} In the main program we add the boundary conditions to our problem \verb+neumann+. \begin{lstlisting}{} int main(int argc, char* argv[]) { ...  Thomas Witkowski committed May 26, 2009 44 45  neumann.addNeumannBC(1, new N); neumann.addDirichletBC(2, new G);  Thomas Witkowski committed Oct 23, 2008 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94  ... } \end{lstlisting} Since the Dirichlet condition has a higher ID, it has a higher priority against the Neumann boundary condition. This is important, where different conditions meet each other in some points. In this example, these are the corner points of $\Omega$. If Dirichlet boundary conditions are used together with boundary conditions of other type, the Dirichlet conditions should always have the higher priority. \subsection{Parameter file} In the parameter file, we use the file \verb+./macro/neumann.macro.2d+ as macro mesh file, described in the next section. \subsection{Macro file} The file \verb+neumann.macro.2d+ is listed below: \begin{lstlisting}{} DIM: 2 DIM_OF_WORLD: 2 number of vertices: 5 number of elements: 4 vertex coordinates: -0.5 -0.5 0.5 -0.5 0.5 0.5 -0.5 0.5 0.0 0.0 element vertices: 0 1 4 1 2 4 2 3 4 3 0 4 element boundaries: 0 0 2 0 0 1 0 0 2 0 0 1 \end{lstlisting} In contrast to the standard file \verb+macro.stand.2d+, here the vertex coordinates are shifted to describe the domain $[-0.5;0.5]^2$. Furthermore, the boundary block changed. The elements 0 and 2 have the Dirichlet boundary with ID 2 at edge 2. Elements 1 and 3 have the Neumann boundary condition with ID 1 applied to their local edge 2. \subsection{Output} In Figure \ref{f:neumann solution}, the solution is shown. At the Neumann boundaries, one can see the positive slope. At Dirichlet boundaries, the solution is set to $g(x)$. \begin{figure} \center \includegraphics[width=0.5\textwidth]{fig/neumann_solution.jpg} \caption{Solution of the problem with Neumann boundary conditions at two sides.} \label{f:neumann solution} \end{figure}