Hi there,
I’m rather new with FreeFEM and I’m trying to solve a simple 1D-ODE (2nd-order) with boundary conditions on the same (leftmost) boundary.
Since it is not possible in the weak formulation to impose Dirichlet- and von Neumann-conditions at the same point, I set up a coupled system of 2 ODEs where I can prescribe Dirichlet-data separately for both unknowns. More specifically, let’s consider
u’’ = u - 2sin(x)
u(0) = 0, u’(0) =1,
the obvious solution being u(x) = sin(x).
The code I came up with, is shown here:
// grid definition: we want n points in the interval [0,L]
int n = 1000;
real L = 15*pi;
// specify label indicators for left- and rightmost grid point
int [int] labs = [3, 4];
// create 1D meshL-object
meshL Th = segment(n, [x*L], label = labs);
// create FE-space, test- and trial-functions
fespace Vh(Th, P1);
Vh u1, u2, v1, v2;
// function definition for righthand-side
func f = -2.0*sin(x);
//---------------------------------------------------------------------------
// we want to solve y'' = y - 2*sin(x) = y + f with BCs y(0) = 0; y'(0) = 1
// Dirichlet- and von-Neumann-BC at the same point is not possible in weak
// formulation, therefore recast into first-order system via
// y1' = y2
// y2' = y1 - 2*sin(x)
// with pure Dirichlet-BCs y1(0) = 0; y2(0) = 1
//---------------------------------------------------------------------------
// set up and solve weak form
solve simple([u1, u2], [v1, v2], solver = UMFPACK)
= int1d(Th)(
dx(u1) * v1
- u2 * v1
+ dx(u2) * v2
- u1 * v2
)
- int1d(Th)(
f*v2
)
+ on(3, u1=0.0, u2 = 1.0);
However, when plotting the solution while the left part looks fine and all boundary conditions are fulfilled, the solution gets progressively worse on the right side of the interval and I have no idea why and what I can do to prevent it..
Any help is greatly appreciated, thanks!
Ps: I tried to dig into various example codes and forum posts but wasn’t able to find something that could help me, but I might have overlooked something..