Time dependent Dirichlet BC

time_dependent_Dirichlet_BC.edp (3.0 KB)

Hello,

i am new to FreeFem and i am trying to simulate the propagation of an acoustic wave generated by a transducer by solving the wave equation with a time dependent Dirichlet boundary condition. Everething is working well if i use the “problem” approach (see the script attached).

Unfortunately, the code is a little bit slow for my computer and i’ve tried the “varf” approach which is way faster (part commented in the script attached). My problem is that i can not manage to impose the time dependent Dirichlet BC by using “varf”. The matrix is not updated in the time loop. I am definitely missing something.

Any help is much appreciated. Since i am new to FreeFem any suggestion on the code i wrote is welcomed.

Thank you,

Adrian

Hi,

You have a time-dependent BC by changing f, but you compute the M and AA matrix outside the time loop, so they remain constant during the simulation. This was the main issue of your code.

I modified your code to work with varf, so have a look at it to see how it works. I used a single varf statement, but you can decompose it into multiple statements to increase the performance (I mean if you can keep one of A or M constant, otherwise switching problem and varf has nothing to say with the speed of computation). One advantage of having varf formulation is that you can boost the performance by taking advantage of PETSc interface in FF, but I recommend you to first make it fully work in a sequential simulation (like what you have) and then parallelize it to make it much faster.
time_dependent_Dirichlet_BC.edp (3.0 KB)

Hello Mojtaba,

thank you for your reply, i appreciate it. I let the M and AA matrix out of the time loop because first i’ve tried the Neumann time dependent BC (as in the attached file). The code is turning a lot faster because only the Neumann BC vector is re-computed in the time loop. On the other hand, the signal shape is not the expected one (one sinus period) because “f” si derived with respect to space and multiplied by the normals… (Neumann BC behavior). I thought that somehow in FreeFem it is possible to do the same with the Dirichlet BCs (update only the matrix or vector related to the boundary conditions in the time loop).

I think that you posted the original file and not the one modified by you. Can you please post the one you modified?

Thank you for your time,

Adrian
time_dependent_Newmann_BC.edp (3.1 KB)

Hi,

Sorry, my bad. Here is the modified version. You can definitely do that, but you should be careful about updating the necessary matrices.

time_dependent_Dirichlet_BC_modified.edp (3.4 KB)

Hi,

thank you for your fast answer and the script. I am sorry but it is not clear to me how to do the same with the Dirichlet BCs, this is the point were i’m blocked. I can isolate the Neumann BC vector from the other matrices by writing:

varf vNBC(unused, v) = int1d(Th, B04)(f(tc)*v);

but i do not see how to do the same with the Dirichlet BC without tying it to one of the other matrices by using “+ on(…)”.

Kind regards,

Adrian

Hi,

If you take a look at the implementation of the Dirichlet boundary conditions, you will see that for the matrix assemly the actual boundary value does not matter. Therefore it is sufficient to assemble the matrix only once (with +on(…) and an arbitrary value). You can reuse this matrix in the time loop and you only have to reassemble the right hand side vector.

lewe.edp (3.7 KB)

Hello,

the time dependent Dirichlet BC on the wave equation is working well now thanks to the answers received here. Nevertheless, I have a new question on this topic. I try to apply a time dependent BC on the linearized elastic wave equations under the velocity-stress formulation (script attached) but the excitation which i’m creating is getting the solution unstable. The system has 5 equations and i think that this is getting me confused, espeacily within the time loop.

Any help or suggestions from your side is much appreciated.

Kind regards,

Adrian