In this tutorial the implementation of inhomogeneous Neumann boundary conditions using trace spaces is shown.
Now we derive the corresponding variational formulation of the introduced problem: find such that
are included. With the following using directive
The mesh is read from three files containing the coordinates, the elements and the boundary attributes of the mesh.
In our example the edges are given the following attributes: 1 (bottom), 2 (right), 3 (top) and 4 (left).
Now the mesh is plotted using a scaling factor of 100, a greyscale of 1.0 and one point per edge.
The homogeneous Dirichlet boundary conditions are set.
and a set of unsigned intergers identifying the edges with Neumann boundary conditions is created.
Note that in our example Neumann boundary conditions are only prescribed at the bottom boundary with attribute 1.
Using the mesh and the homogeneous Dirichlet boundary conditions, the space can be built. We refine the space two times and set the polynomial degree to three. Then the elements of the space are built and the space is plotted.
The right hand side is computed. In our case, the vector rhs
only contains the integrals of the Neumann trace as the source term is zero.
We solve the equation using the conjugate gradient method with a tolerance of 1e-6 and a maximum number of iterations of 200.
Finally, exceptions are caught and a sane return value is given back.
Mesh: Import2dMesh(ncell = 1)
RHS Vector:
Vector(132, [ 1.678744e-01, 0.000000e+00, 1.570060e-02, 5.980456e-03, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 2.374103e-01, 0.000000e+00, 3.790460e-02, 2.477186e-03, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 1.678744e-01, 0.000000e+00, 3.790460e-02, -2.477186e-03, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 1.570060e-02, -5.980456e-03, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00])
System Matrix:
SparseMatrix(132x132, HashedSparseMatrix: 1794 (1.029614e+01%) entries bound.)
Solver:
CG(solves SparseMatrix(132x132, HashedSparseMatrix: 1794 (1.029614e+01%) entries bound.), eps = 7.757995e-13, it = 36, relres = 0)
Solution:
Vector(132, [ 2.138848e-01, 9.326628e-02, 3.516844e-02, 5.584007e-03, -4.883629e-02, 3.356455e-03, 1.532876e-02, 2.433166e-03, -8.064913e-03, 5.630397e-04, -1.288910e-03, 9.407855e-05, 3.024788e-01, 1.318984e-01, 8.490413e-02, 2.312972e-03, -6.906494e-02, 4.746742e-03, 3.700689e-02, -1.007849e-03, -1.947042e-02, 1.359298e-03, -5.338839e-04, 3.896852e-05, 5.610815e-02, 3.967446e-02, -2.990543e-02, 2.106316e-03, 1.573143e-02, 4.281191e-04, -2.114634e-02, -1.489391e-03, -8.355282e-03, 6.177991e-04, -2.262989e-04, 1.911231e-05, 6.516172e-03, 1.033572e-03, -3.460871e-03, 2.559008e-04, -5.463338e-04, 4.614120e-05, 2.138848e-01, 9.326629e-02, 8.490413e-02, -2.312971e-03, -4.883628e-02, 3.356452e-03, 3.700689e-02, -1.007851e-03, -1.947042e-02, 1.359298e-03, 5.338840e-04, -3.896865e-05, 3.516844e-02, -5.584008e-03, 1.532875e-02, 2.433164e-03, -8.064912e-03, 5.630394e-04, 1.288910e-03, -9.407842e-05, 3.967446e-02, 6.516172e-03, 1.033571e-03, -2.114633e-02, -1.489390e-03, -3.460871e-03, 2.559007e-04, 5.463338e-04, -4.614119e-05, 1.573143e-02, 4.281196e-04, -8.355282e-03, 6.177991e-04, 2.262988e-04, -1.911231e-05, 1.459316e-02, 2.063785e-02, -8.635381e-03, 6.999117e-04, 5.786236e-03, -1.585277e-04, -1.221227e-02, -9.898247e-04, -3.384507e-03, 2.667914e-04, 9.347732e-05, -9.106996e-06, 2.396737e-03, 3.827195e-04, -1.401909e-03, 1.105086e-04, 2.256743e-04, -2.198624e-05, -2.321856e-03, -4.072598e-04, -3.763560e-04, 6.414338e-05, 7.463472e-05, -1.439713e-05, -3.283600e-03, -5.759523e-04, -9.086037e-04, 1.548558e-04, 3.091471e-05, -5.963484e-06, 1.459316e-02, -8.635382e-03, 6.999119e-04, 2.396737e-03, 3.827196e-04, -1.401909e-03, 1.105086e-04, -2.256742e-04, 2.198624e-05, 5.786236e-03, -1.585275e-04, -3.384507e-03, 2.667914e-04, -9.347736e-05, 9.107000e-06, -2.321856e-03, -4.072598e-04, -9.086037e-04, 1.548558e-04, -3.091471e-05, 5.963487e-06, -3.763560e-04, 6.414338e-05, -7.463471e-05, 1.439713e-05])