Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/eduardgomezescandell/finite_elements_1d_julia


https://github.com/eduardgomezescandell/finite_elements_1d_julia

Last synced: 13 days ago
JSON representation

Awesome Lists containing this project

README

        

# Finite element implementation in Julia
This is a toy project as a first contact with the Julia programming language.

It solves partial derivative equations in a 1D domain using the Finite Element Method.
Currently, the following equations are implemented:
- Poisson (pure diffusion)
- Convection-diffusion
- Burger's equation
The program is easily extendable to other partial derivative equations.

You can choose between diferent polynomial interpolations and diferent quadrature orders.
You can also choose between Neumann and Dirichlet boundary conditions.

### Dependencies
You need to install the `Gaston` package and `GNUplot`:

```bash
julia -e 'using Pkg; Pkg.add("Gaston")'
sudo apt install gnuplot
```

## How to run
Open the `demos/demo_steady.jl` file and edit the settings to your liking. Then use:
```bash
julia -i demos/demo_steady.jl
```
The following figure should pop up:

![demos/demo_steady.jl](https://user-images.githubusercontent.com/47142856/164203009-7d13d0b8-6a17-40e2-b03d-a21111d446b0.png)

If no figure pops up, you may be missing `gnuplot` (a warning will show in the console) or you might have run the
program without the `-i` flag. A Julia interactive session will stay open, and you can subsequently call
```julia
julia> include("demos/demo_steady.jl")
```
after changing any of the settings to avoid recompiling Gaston, the plotting library.

The same process works for the other demos. For instance, here is the result for `demos/demo_unsteady_implicit.jl`:

![demos/demo_unsteady_implicit.jl](https://user-images.githubusercontent.com/47142856/164744229-e9387896-5b54-42c4-b86e-17ea35298d0c.gif)

Convection-diffusion equation:

![demos/demo_convection_diffusion](https://user-images.githubusercontent.com/47142856/164912633-2ea4d31d-0f8f-41ad-88c8-e4762aee521d.gif)

Here is the Burger's equation:

![demos/demo_burgers.jl](https://user-images.githubusercontent.com/47142856/164912512-a136e5d5-93a7-4115-a5e8-9fd1c39f85b6.gif)

## General Structure
### Time integrator
The time integrator is in charge of time-stepping. If you don't want to step in time, `TimeIntegratorSteady` is a dummy integrator that
merely solves the steady-state equation. In order to solve each step (or the steady state), the time integrator assembles a system such as:
```
∂u/∂t + L(u)u = s
```
by discretizing the previous equation in space, with help of shape functions `w`, we obtain:
```
(w, ∂u/∂t) - (w, L(u)u) = (w, s)
```
This generates two matrices and a vector, one for each term: `M`, `L`, and `F`. Depending on the time integrator, these matrices are evaluated
at one ore more points in time. For instance, with a Forward-Euler time scheme we get:
```
M(t_old)*U(t) = Δt*F(t_old) + (M(t_old) - Δt*K(t_old))*U(t_old)
```

Hence:
```
LHS = M
RHS = Δt*F(t_old) + (M - Δt*K(t_old)) U(t_old)
U = LHS \ RHS
```
The time scheme is in charge of evaluating this expression. To obtain matrices `M`, `L` and vector `F`, the space integrator is called.

### Space integrator

This class is in charge of assembling the contributions from each element and boundary condition by calling `calculate_M`, `calculate_L` and `calculate_F`.
The global matrices are partitioned:
```
[ LHS_ff | LHS_fl ] [ Uf ] [ RHS_f ]
[----------+----------] [----] = [-------]
[ LHS_ff | LHS_fl ] [ Ul ] [ RHS_l ]
```
where `f` indicates the free degrees of freedom, and `l` indicates the locked ones (Dirichlet boundary condition). The space integrator is also in charge
of sending each local contribution to the right partition.

It is also in charge of generating a solution vector `U` by interlacing `Uf` and `Ul`.

### SystemOfEquations
To solve the partitioned system of equations, the following expression is followed:
```
LHS_ff * Uf = RHS_f - LHS_fl*Ul
```
Class SystemOfEquations is in charge of solving for Uf.

### Elements
They are in charge of computing local matrices `M`, `L` and vector `F`. They use Gauss quadrature to integrate them.

# Known issues
Explicit time integrators do not work with non-linear elements.