Using 2d tools tools for 1d problems
To solve the basic Laplace problem with homogeneous boundary conditions on \( (0,1)\) use 2d tools to construct the 1d problem.
Set a 2d mesh Th using a line of triangles sitting on \((0,1)\).
This gives our first uniform partition on \((0,1)\) labelled by 1
All we need will be generated and stored in 2d structures and extracted from them.
- Given Th, we can extract the dofs on label 1 constructing one pointer to them zoi, see the example 2 in Quick and dirty tips
- two variable functions u(x,y) on label 1 are the one variable functions u(x,0) that we need
- Using varf mat(u,v)= int1d(Th,1)(dx(u)*dx(v))+on(2,3,4,u=0); we construct the terms for the 1d matrix
- Using A=mat(Vh,Vh,tgv=1e30); store these terms on a sparse matrix
- Using varf rhs(u,v)= int1d(Th,1)(f*v)+on(2,3,4,u=0); we construct the terms for the right hand side
- Using d=rhs(0,Vh,tgv=1e30); store these terms on a array larger than needed
- Using M=A(zoi,zoi); we extract the correct entries for the stiff matrix to the 1d problem and with b=d(zoi); we extract the values of right hand side. Then, our problem is Mx=b
Take a look at the following examples:
1d FreeFem++ examples
- Steady convection-diffusion equation with remeshing example1
- Steady reaction-diffusion equation with remeshing example2
- Non steady heat equation equation example3
- Non steady Black-Scholes equation example4
- Wave equation with Crank-Nicolson example5
return to 1d examples