kinnala / scikit-fem

Simple finite element assemblers
https://scikit-fem.readthedocs.io
BSD 3-Clause "New" or "Revised" License
500 stars 79 forks source link

Poisson equation with time stepping #1026

Closed martinbaun closed 1 year ago

martinbaun commented 1 year ago

Hi,

I can solve the static poisson equation $\Delta A \frac{1}{\mu} = J$ with

@skfem.BilinearForm()
def poisson(u, v, _):
    return dot(grad(u), grad(v)/perm)

and the harmonic poisson equation $\Delta A \frac{1}{\mu} + 1j \cdot \omega \sigma A= J$ with

@skfem.BilinearForm(dtype = np.complex64)
def poisson_harmonic(u, v, _):
    return dot(grad(u), grad(v)/perm) + 1j*omega*sigma*u

So far so good. But I want to implement the time stepping method, know.

$\Delta A \frac{1}{\mu} + \sigma \frac{\partial A}{ \partial t}= J$

I think I have to replace $\frac{\partial A}{ \partial t}$ with $\frac{A_{t-1}-A_t}{\Delta t}$

but I don't know how to use the solution of A from the previous simulation step. Following code doesn't work because "u" and "A_0" have different shapes.

...
A_0 = solve(...) # solution of the first calculation (static)

@skfem.BilinearForm
def poisson_transient(u, v, _):
    return dot(grad(u), grad(v)/perm) + sigma * ( A_0 - u) / dt

Any hints for me?

kinnala commented 1 year ago

Here is info on something related: https://scikit-fem.readthedocs.io/en/latest/howto.html#discrete-functions-in-forms

kinnala commented 1 year ago

Another comment is that usually you move those functions, such as $A_0$ that you already know, to right-hand side load vector.

martinbaun commented 1 year ago

The combination of your comments solved my problem. Thanks!