-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
221 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: CI | ||
|
||
on: [push, pull_request, workflow_dispatch] | ||
|
||
# 64-bit Julia only | ||
jobs: | ||
test: | ||
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} | ||
runs-on: ${{ matrix.os }} | ||
if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, 'CompatHelper')" | ||
strategy: | ||
matrix: | ||
version: | ||
- '1.9.4' | ||
os: | ||
- ubuntu-latest | ||
- macOS-latest | ||
- windows-latest | ||
arch: | ||
- x64 | ||
steps: | ||
- run: echo ACTIONS_RUNNER_DEBUG true | ||
- uses: actions/[email protected] | ||
- name: "Set up Julia" | ||
uses: julia-actions/setup-julia@latest | ||
with: | ||
version: ${{ matrix.version }} | ||
arch: ${{ matrix.arch }} | ||
#- uses: julia-actions/julia-buildpkg@latest | ||
- uses: julia-actions/julia-runtest@latest | ||
#env: | ||
# ACTIONS_RUNNER_DEBUG: true | ||
- uses: julia-actions/julia-uploadcodecov@latest | ||
env: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: TagBot | ||
on: | ||
issue_comment: | ||
types: | ||
- created | ||
workflow_dispatch: | ||
jobs: | ||
TagBot: | ||
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: JuliaRegistries/TagBot@v1 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
ssh: ${{ secrets.DOCUMENTER_KEY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,138 @@ | ||
# PhysicalFDM.jl | ||
|
||
Finite Differencing Method | ||
|
||
WARNING: *This package is under development!!!* | ||
|
||
## Installation | ||
|
||
```julia | ||
]add PhysicalFDM | ||
``` | ||
|
||
or | ||
|
||
```julia | ||
using Pkg; Pkg.add("PhysicalFDM") | ||
``` | ||
|
||
or | ||
|
||
```julia | ||
using Pkg; Pkg.add("https://github.com/JuliaAstroSim/PhysicalFDM.jl") | ||
``` | ||
|
||
To test the Package: | ||
```julia | ||
]test PhysicalFDM | ||
``` | ||
|
||
## User Guide | ||
|
||
This package is extracted from [AstroNbodySim.jl](https://github.com/JuliaAstroSim/AstroNbodySim.jl). You may find more advanced examples there. | ||
|
||
### Differencing | ||
|
||
Central differencing scheme is defined as | ||
$$ | ||
\left(\frac{\partial u}{\partial x}\right)_{i, j}=\frac{1}{2 \Delta x}\left(u_{i+1, j}-u_{i-1, j}\right)+O(\Delta x) | ||
$$ | ||
Suppose we have an 1D data, and $\delta x = 5$: | ||
```julia | ||
julia> d1 = [1,2,1] | ||
3-element Vector{Int64}: | ||
1 | ||
2 | ||
1 | ||
|
||
julia> grad_central(5, d1) | ||
3-element Vector{Float64}: | ||
0.2 | ||
0.0 | ||
-0.2 | ||
``` | ||
|
||
2D example, where $(\nabla_x(d2), \nabla_y(d2))$ is returned as `Tuple`: | ||
```julia | ||
julia> d2 = [1 1 1; 1 2 1; 1 1 1] | ||
3×3 Matrix{Int64}: | ||
1 1 1 | ||
1 2 1 | ||
1 1 1 | ||
|
||
julia> grad_central(5, 5, d2) | ||
([0.1 0.2 0.1; 0.0 0.0 0.0; -0.1 -0.2 -0.1], [0.1 0.0 -0.1; 0.2 0.0 -0.2; 0.1 0.0 -0.1]) | ||
``` | ||
|
||
3D example | ||
```julia | ||
julia> d3 = ones(3,3,3); | ||
d3[2,2,2] = 2; | ||
|
||
julia> grad_central(1, 1, 1, d3) | ||
([0.5 0.5 0.5; 0.0 0.0 0.0; -0.5 -0.5 -0.5;;; 0.5 1.0 0.5; 0.0 0.0 0.0; -0.5 -1.0 -0.5;;; 0.5 0.5 0.5; 0.0 0.0 0.0; -0.5 -0.5 -0.5], [0.5 0.0 -0.5; 0.5 0.0 -0.5; 0.5 0.0 -0.5;;; 0.5 0.0 -0.5; 1.0 0.0 -1.0; 0.5 0.0 -0.5;;; 0.5 0.0 -0.5; 0.5 0.0 -0.5; 0.5 0.0 -0.5], [0.5 0.5 0.5; 0.5 1.0 0.5; 0.5 0.5 0.5;;; 0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0;;; -0.5 -0.5 -0.5; -0.5 -1.0 -0.5; -0.5 -0.5 -0.5]) | ||
``` | ||
|
||
### FDM solver | ||
|
||
#### Poisson equation | ||
$$ | ||
\delta u = f | ||
$$ | ||
can be discretized to | ||
$$ | ||
\frac{u_{i+1}-2 u_{i}+u_{i-1}}{\Delta x^{2}}=f_{i}, i = 1, 2, \cdots, N | ||
$$ | ||
In Dirichlet boundary conditions, | ||
$$ | ||
\frac{1}{\Delta x^2} \begin{pmatrix} | ||
-2 & 1 & 0 & \cdots & \cdots & 0 \\ | ||
1 & -2 & 1 & 0 & \cdots & \vdots \\ | ||
0 & 1 & -2 & 1 & \cdots & \vdots \\ | ||
\vdots & \ddots & \ddots & \ddots & \ddots & \vdots \\ | ||
\vdots & \ddots & 1 & -2 & 1 & 0 \\ | ||
\vdots & \ddots & 0 & 1 & -2 & 1 \\ | ||
0 & \cdots & \cdots & 0 & 1 & -2 | ||
\end{pmatrix} | ||
\cdot \begin{pmatrix} | ||
u_1 \\ u_2 \\ \vdots \\ \vdots \\ \vdots \\ u_{N-1} \\ u_N | ||
\end{pmatrix} | ||
= \begin{pmatrix} | ||
f_1 \\ f_2 \\ \vdots \\ \vdots \\ \vdots \\ f_{N-1} \\ f_N | ||
\end{pmatrix} | ||
$$ | ||
|
||
The Poisson problem is converted to solving a matrix equation | ||
$$ | ||
\mathbf{A} \cdot \mathbf{u} = \mathbf{f} | ||
$$ | ||
|
||
`PhysicalFDM.jl` is here to provide user-friendly tools to generate `\mathbf{A}` matrix. | ||
|
||
For example, suppose we have a 1D mesh with 3 points, and for the Poisson problem we have a 2nd-order differencing operator: | ||
```julia | ||
julia> A = diff_mat(3,2) | ||
3×3 Matrix{Float64}: | ||
-2.0 1.0 0.0 | ||
1.0 -2.0 1.0 | ||
0.0 1.0 -2.0 | ||
``` | ||
|
||
Here's a MWE: | ||
```julia | ||
using PhysicalFDM | ||
f = [0, 1, 0] | ||
A = diff_mat(3,2) | ||
u = f \ A | ||
``` | ||
|
||
## Package ecosystem | ||
|
||
- Basic data structure: [PhysicalParticles.jl](https://github.com/JuliaAstroSim/PhysicalParticles.jl) | ||
- File I/O: [AstroIO.jl](https://github.com/JuliaAstroSim/AstroIO.jl) | ||
- Initial Condition: [AstroIC.jl](https://github.com/JuliaAstroSim/AstroIC.jl) | ||
- Parallelism: [ParallelOperations.jl](https://github.com/JuliaAstroSim/ParallelOperations.jl) | ||
- Trees: [PhysicalTrees.jl](https://github.com/JuliaAstroSim/PhysicalTrees.jl) | ||
- Meshes: [PhysicalMeshes.jl](https://github.com/JuliaAstroSim/PhysicalMeshes.jl) | ||
- Plotting: [AstroPlot.jl](https://github.com/JuliaAstroSim/AstroPlot.jl) | ||
- Simulation: [ISLENT](https://github.com/JuliaAstroSim/ISLENT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters