Skip to content

Commit 87470da

Browse files
committed
Small modifications
1 parent 42a9c65 commit 87470da

26 files changed

+2132
-1
lines changed

.JuliaFormatter.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Use SciML style: https://github.com/SciML/SciMLStyle
2+
style = "sciml"
3+
4+
# Python style alignment. See https://github.com/domluna/JuliaFormatter.jl/pull/732.
5+
yas_style_nesting = true
6+
7+
# Align struct fields for better readability of large struct definitions
8+
align_struct_field = true

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
2+
version: 2
3+
updates:
4+
- package-ecosystem: "github-actions"
5+
directory: "/" # Location of package manifests
6+
schedule:
7+
interval: "monthly"

.github/workflows/FormatCheck.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: format-check
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
tags: '*'
8+
pull_request:
9+
10+
jobs:
11+
check-format:
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
matrix:
15+
julia-version: [1]
16+
julia-arch: [x86]
17+
os: [ubuntu-latest]
18+
steps:
19+
- uses: julia-actions/setup-julia@latest
20+
with:
21+
version: ${{ matrix.julia-version }}
22+
23+
- uses: actions/checkout@v4
24+
- name: Install JuliaFormatter and format
25+
# This will use the latest version by default but you can set the version like so:
26+
#
27+
# julia -e 'using Pkg; Pkg.add(PackageSpec(name = "JuliaFormatter", version = "0.13.0"))'
28+
#
29+
# TODO: Change the call below to
30+
# format(".")
31+
run: |
32+
julia -e 'using Pkg; Pkg.add(PackageSpec(name = "JuliaFormatter"))'
33+
julia -e 'using JuliaFormatter; format(["examples", "src", "test"])'
34+
- name: Format check
35+
run: |
36+
julia -e '
37+
out = Cmd(`git diff --name-only`) |> read |> String
38+
if out == ""
39+
exit(0)
40+
else
41+
@error "Some files have not been formatted !!!"
42+
write(stdout, out)
43+
exit(1)
44+
end'

.github/workflows/SpellCheck.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Spell Check
2+
3+
on: [pull_request, workflow_dispatch]
4+
5+
jobs:
6+
typos-check:
7+
name: Spell Check with Typos
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout Actions Repository
11+
uses: actions/checkout@v4
12+
- name: Check spelling
13+
uses: crate-ci/[email protected]

.github/workflows/ci.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- 'AUTHORS.md'
9+
- 'LICENSE.md'
10+
- 'README.md'
11+
pull_request:
12+
paths-ignore:
13+
- 'AUTHORS.md'
14+
- 'LICENSE.md'
15+
- 'README.md'
16+
workflow_dispatch:
17+
18+
# Cancel redundant CI tests automatically
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
test:
25+
if: "!contains(github.event.head_commit.message, 'skip ci')"
26+
# We could also include the Julia version as in
27+
# name: ${{ matrix.trixi_test }} - ${{ matrix.os }} - Julia ${{ matrix.version }} - ${{ matrix.arch }} - ${{ github.event_name }}
28+
# to be more specific. However, that requires us updating the required CI tests whenever we update Julia.
29+
name: ${{ matrix.trixi_test }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
30+
runs-on: ${{ matrix.os }}
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
version:
35+
- '1.9'
36+
os:
37+
- ubuntu-latest
38+
arch:
39+
- x64
40+
steps:
41+
- uses: actions/checkout@v4
42+
- uses: julia-actions/setup-julia@v1
43+
with:
44+
version: ${{ matrix.version }}
45+
arch: ${{ matrix.arch }}
46+
- run: julia -e 'using InteractiveUtils; versioninfo(verbose=true)'
47+
- uses: julia-actions/cache@v1
48+
- uses: julia-actions/julia-buildpkg@v1
49+
env:
50+
PYTHON: ""
51+
- name: Run tests with coverage
52+
uses: julia-actions/julia-runtest@v1
53+
with:
54+
coverage: true
55+
- uses: julia-actions/julia-processcoverage@v1
56+
with:
57+
directories: src,examples
58+
- uses: coverallsapp/github-action@master
59+
with:
60+
github-token: ${{ secrets.GITHUB_TOKEN }}
61+
flag-name: run-${{ matrix.trixi_test }}-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }}
62+
parallel: false
63+
path-to-lcov: ./lcov.info

.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
*.pdf
2+
*.png
3+
*.h5
4+
*.mp4
5+
*.mem
6+
*.vtu
7+
*.pvd
8+
*.avi
9+
*.ogv
10+
*.mesh
11+
*.bson
12+
*.inp
13+
**/Manifest.toml
14+
out*/
15+
docs/build
16+
docs/src/notebooks
17+
docs/src/authors.md
18+
docs/src/tutorials
19+
public/
20+
coverage/
21+
coverage_report/
22+
**/*.jl.*.cov
23+
**/.ipynb_checkpoints/
24+
**/solution_*.txt
25+
**/restart_*.txt
26+
.vscode/
27+
28+
.DS_Store
29+
30+
run
31+
run/*
32+
33+
LocalPreferences.toml

.typos.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[default.extend-words]
2+
rcall = "rcall"
3+
claus = "claus"
4+
dum = "dum"

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023-present Michael Schlottke-Lakemper, Julia Odenthal
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Project.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name = "TrixiSmartShockFinder"
2+
uuid = "6b42f25e-8cc0-41c2-936f-439385811e39"
3+
authors = ["Michael Schlottke-Lakemper <[email protected]> and contributors"]
4+
version = "0.1.0"
5+
6+
[deps]
7+
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
8+
MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221"
9+
Trixi = "a7f1ee26-1774-49b1-8366-f1abc58fbfcb"
10+
11+
[compat]
12+
Flux = "0.13.15, 0.14"
13+
MuladdMacro = "0.2.4"
14+
# Trixi = "0.6"
15+
julia = "1.9"

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,47 @@
11
# TrixiSmartShockFinder.jl
2-
Spin-off repository of Trixi.jl with neural network-based shock indicators
2+
[![Build Status](https://github.com/trixi-framework/TrixiSmartShockFinder.jl/workflows/CI/badge.svg)](https://github.com/trixi-framework/TrixiSmartShockFinder.jl/actions?query=workflow%3ACI)
3+
[![Coveralls](https://coveralls.io/repos/github/trixi-framework/TrixiSmartShockFinder.jl/badge.svg?branch=main)](https://coveralls.io/github/trixi-framework/TrixiSmartShockFinder.jl?branch=main)
4+
[![License: MIT](https://img.shields.io/badge/License-MIT-success.svg)](https://opensource.org/licenses/MIT)
5+
6+
Spin-off repository of [Trixi.jl](https://github.com/trixi-framework/Trixi.jl)
7+
with neural network-based shock indicators.
8+
9+
**Note: This repository is currently not under development and has been archived. If you are
10+
interested in using any of this, please get in touch with the developers of the
11+
[Trixi.jl](https://github.com/trixi-framework/Trixi.jl) package.
12+
13+
14+
## Usage
15+
To run any of the elixirs with the neurl network-based indicators, you first need to install
16+
all required auxiliary packages by running the following code in the Julia REPL:
17+
```julia
18+
julia> using Pkg
19+
20+
julia> Pkg.add(["BSON", "Flux", "OrdinaryDiffEq", "Trixi"])
21+
```
22+
23+
Then, clone this repository
24+
```shell
25+
git clone [email protected]:trixi-framework/TrixiSmartShockFinder.jl.git
26+
```
27+
enter the directory, and start Julia (tested with Julia v1.9) with the project set to
28+
the clone directory
29+
```
30+
cd TrixiSmartShockFinder.jl
31+
julia --project=.
32+
```
33+
34+
Now run one of the elixirs in the `examples` folder, e.g.,
35+
```julia
36+
using TrixiSmartShockFinder
37+
trixi_include("examples/tree_2d_dgsem/elixir_euler_blast_wave_neuralnetwork_perssonperaire.jl")
38+
```
39+
40+
## Authors
41+
TrixiSmartShockFinder.jl was initiated by
42+
[Michael Schlottke-Lakemper](https://lakemper.eu) (University of Augsburg, Germany) and
43+
Julia Odenthal (University of Cologne, Germany).
44+
45+
46+
## License and contributing
47+
TrixiSmartShockFinder.jl is licensed under the MIT license (see [LICENSE.md](LICENSE.md)).
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
using Downloads: download
2+
using Flux
3+
using BSON: load
4+
network = joinpath(@__DIR__, "modelnnpp-0.97-0.0001.bson")
5+
download("https://github.com/trixi-framework/Trixi_IndicatorNeuralNetwork_networks/raw/main/networks/modelnnpp-0.97-0.0001.bson",
6+
network)
7+
model1d = load(network, @__MODULE__)[:model1d]
8+
9+
using OrdinaryDiffEq
10+
using TrixiSmartShockFinder
11+
using Trixi
12+
13+
# TODO: Remove once Trixi.jl is released without these exports
14+
NeuralNetworkPerssonPeraire = TrixiSmartShockFinder.NeuralNetworkPerssonPeraire
15+
NeuralNetworkRayHesthaven = TrixiSmartShockFinder.NeuralNetworkRayHesthaven
16+
IndicatorNeuralNetwork = TrixiSmartShockFinder.IndicatorNeuralNetwork
17+
18+
# This elixir was one of the setups used in the following master thesis:
19+
# - Julia Odenthal (2021)
20+
# Shock capturing with artificial neural networks
21+
# University of Cologne, advisors: Gregor Gassner, Michael Schlottke-Lakemper
22+
# This motivates the particular choice of fluxes, mesh resolution etc.
23+
24+
###############################################################################
25+
# semidiscretization of the compressible Euler equations
26+
27+
equations = CompressibleEulerEquations1D(1.4)
28+
29+
"""
30+
initial_condition_blast_wave(x, t, equations::CompressibleEulerEquations1D)
31+
32+
A medium blast wave taken from
33+
- Sebastian Hennemann, Gregor J. Gassner (2020)
34+
A provably entropy stable subcell shock capturing approach for high order split form DG
35+
[arXiv: 2008.12044](https://arxiv.org/abs/2008.12044)
36+
"""
37+
function initial_condition_blast_wave(x, t, equations::CompressibleEulerEquations1D)
38+
# Modified From Hennemann & Gassner JCP paper 2020 (Sec. 6.3) -> "medium blast wave"
39+
# Set up polar coordinates
40+
inicenter = SVector(0.0)
41+
x_norm = x[1] - inicenter[1]
42+
r = abs(x_norm)
43+
# The following code is equivalent to
44+
# phi = atan(0.0, x_norm)
45+
# cos_phi = cos(phi)
46+
# in 1D but faster
47+
cos_phi = x_norm > 0 ? one(x_norm) : -one(x_norm)
48+
49+
# Calculate primitive variables
50+
rho = r > 0.5 ? 1.0 : 1.1691
51+
v1 = r > 0.5 ? 0.0 : 0.1882 * cos_phi
52+
p = r > 0.5 ? 1.0E-3 : 1.245
53+
54+
return prim2cons(SVector(rho, v1, p), equations)
55+
end
56+
initial_condition = initial_condition_blast_wave
57+
58+
surface_flux = flux_lax_friedrichs
59+
volume_flux = flux_chandrashekar
60+
basis = LobattoLegendreBasis(3)
61+
indicator_sc = IndicatorNeuralNetwork(equations, basis,
62+
indicator_type = NeuralNetworkPerssonPeraire(),
63+
alpha_max = 0.5,
64+
alpha_min = 0.001,
65+
alpha_smooth = true,
66+
alpha_continuous = false,
67+
alpha_amr = false,
68+
variable = density_pressure,
69+
network = model1d)
70+
volume_integral = VolumeIntegralShockCapturingHG(indicator_sc;
71+
volume_flux_dg = volume_flux,
72+
volume_flux_fv = surface_flux)
73+
solver = DGSEM(basis, surface_flux, volume_integral)
74+
75+
coordinates_min = (-2.0,)
76+
coordinates_max = (2.0,)
77+
mesh = TreeMesh(coordinates_min, coordinates_max,
78+
initial_refinement_level = 6,
79+
n_cells_max = 10_000)
80+
81+
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)
82+
83+
###############################################################################
84+
# ODE solvers, callbacks etc.
85+
86+
tspan = (0.0, 12.5)
87+
ode = semidiscretize(semi, tspan)
88+
89+
summary_callback = SummaryCallback()
90+
91+
analysis_interval = 100
92+
93+
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
94+
95+
alive_callback = AliveCallback(analysis_interval = analysis_interval)
96+
97+
save_solution = SaveSolutionCallback(interval = 100,
98+
save_initial_solution = true,
99+
save_final_solution = true,
100+
solution_variables = cons2prim)
101+
102+
stepsize_callback = StepsizeCallback(cfl = 0.5)
103+
104+
callbacks = CallbackSet(summary_callback,
105+
analysis_callback, alive_callback,
106+
save_solution,
107+
stepsize_callback)
108+
109+
###############################################################################
110+
# run the simulation
111+
112+
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
113+
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
114+
save_everystep = false, callback = callbacks);
115+
summary_callback() # print the timer summary

0 commit comments

Comments
 (0)