-
Notifications
You must be signed in to change notification settings - Fork 1
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
26 changed files
with
2,132 additions
and
1 deletion.
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,8 @@ | ||
# Use SciML style: https://github.com/SciML/SciMLStyle | ||
style = "sciml" | ||
|
||
# Python style alignment. See https://github.com/domluna/JuliaFormatter.jl/pull/732. | ||
yas_style_nesting = true | ||
|
||
# Align struct fields for better readability of large struct definitions | ||
align_struct_field = true |
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,7 @@ | ||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" # Location of package manifests | ||
schedule: | ||
interval: "monthly" |
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,44 @@ | ||
name: format-check | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
tags: '*' | ||
pull_request: | ||
|
||
jobs: | ||
check-format: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
julia-version: [1] | ||
julia-arch: [x86] | ||
os: [ubuntu-latest] | ||
steps: | ||
- uses: julia-actions/setup-julia@latest | ||
with: | ||
version: ${{ matrix.julia-version }} | ||
|
||
- uses: actions/checkout@v4 | ||
- name: Install JuliaFormatter and format | ||
# This will use the latest version by default but you can set the version like so: | ||
# | ||
# julia -e 'using Pkg; Pkg.add(PackageSpec(name = "JuliaFormatter", version = "0.13.0"))' | ||
# | ||
# TODO: Change the call below to | ||
# format(".") | ||
run: | | ||
julia -e 'using Pkg; Pkg.add(PackageSpec(name = "JuliaFormatter"))' | ||
julia -e 'using JuliaFormatter; format(["examples", "src", "test"])' | ||
- name: Format check | ||
run: | | ||
julia -e ' | ||
out = Cmd(`git diff --name-only`) |> read |> String | ||
if out == "" | ||
exit(0) | ||
else | ||
@error "Some files have not been formatted !!!" | ||
write(stdout, out) | ||
exit(1) | ||
end' |
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,13 @@ | ||
name: Spell Check | ||
|
||
on: [pull_request, workflow_dispatch] | ||
|
||
jobs: | ||
typos-check: | ||
name: Spell Check with Typos | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Actions Repository | ||
uses: actions/checkout@v4 | ||
- name: Check spelling | ||
uses: crate-ci/[email protected] |
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,63 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths-ignore: | ||
- 'AUTHORS.md' | ||
- 'LICENSE.md' | ||
- 'README.md' | ||
pull_request: | ||
paths-ignore: | ||
- 'AUTHORS.md' | ||
- 'LICENSE.md' | ||
- 'README.md' | ||
workflow_dispatch: | ||
|
||
# Cancel redundant CI tests automatically | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test: | ||
if: "!contains(github.event.head_commit.message, 'skip ci')" | ||
# We could also include the Julia version as in | ||
# name: ${{ matrix.trixi_test }} - ${{ matrix.os }} - Julia ${{ matrix.version }} - ${{ matrix.arch }} - ${{ github.event_name }} | ||
# to be more specific. However, that requires us updating the required CI tests whenever we update Julia. | ||
name: ${{ matrix.trixi_test }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
version: | ||
- '1.9' | ||
os: | ||
- ubuntu-latest | ||
arch: | ||
- x64 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: julia-actions/setup-julia@v1 | ||
with: | ||
version: ${{ matrix.version }} | ||
arch: ${{ matrix.arch }} | ||
- run: julia -e 'using InteractiveUtils; versioninfo(verbose=true)' | ||
- uses: julia-actions/cache@v1 | ||
- uses: julia-actions/julia-buildpkg@v1 | ||
env: | ||
PYTHON: "" | ||
- name: Run tests with coverage | ||
uses: julia-actions/julia-runtest@v1 | ||
with: | ||
coverage: true | ||
- uses: julia-actions/julia-processcoverage@v1 | ||
with: | ||
directories: src,examples | ||
- uses: coverallsapp/github-action@master | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
flag-name: run-${{ matrix.trixi_test }}-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }} | ||
parallel: false | ||
path-to-lcov: ./lcov.info |
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,33 @@ | ||
*.png | ||
*.h5 | ||
*.mp4 | ||
*.mem | ||
*.vtu | ||
*.pvd | ||
*.avi | ||
*.ogv | ||
*.mesh | ||
*.bson | ||
*.inp | ||
**/Manifest.toml | ||
out*/ | ||
docs/build | ||
docs/src/notebooks | ||
docs/src/authors.md | ||
docs/src/tutorials | ||
public/ | ||
coverage/ | ||
coverage_report/ | ||
**/*.jl.*.cov | ||
**/.ipynb_checkpoints/ | ||
**/solution_*.txt | ||
**/restart_*.txt | ||
.vscode/ | ||
|
||
.DS_Store | ||
|
||
run | ||
run/* | ||
|
||
LocalPreferences.toml |
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,4 @@ | ||
[default.extend-words] | ||
rcall = "rcall" | ||
claus = "claus" | ||
dum = "dum" |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023-present Michael Schlottke-Lakemper, Julia Odenthal | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 = "TrixiSmartShockFinder" | ||
uuid = "6b42f25e-8cc0-41c2-936f-439385811e39" | ||
authors = ["Michael Schlottke-Lakemper <[email protected]> and contributors"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" | ||
MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" | ||
Trixi = "a7f1ee26-1774-49b1-8366-f1abc58fbfcb" | ||
|
||
[compat] | ||
Flux = "0.13.15, 0.14" | ||
MuladdMacro = "0.2.4" | ||
# Trixi = "0.6" | ||
julia = "1.9" |
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,2 +1,47 @@ | ||
# TrixiSmartShockFinder.jl | ||
Spin-off repository of Trixi.jl with neural network-based shock indicators | ||
[![Build Status](https://github.com/trixi-framework/TrixiSmartShockFinder.jl/workflows/CI/badge.svg)](https://github.com/trixi-framework/TrixiSmartShockFinder.jl/actions?query=workflow%3ACI) | ||
[![Coveralls](https://coveralls.io/repos/github/trixi-framework/TrixiSmartShockFinder.jl/badge.svg?branch=main)](https://coveralls.io/github/trixi-framework/TrixiSmartShockFinder.jl?branch=main) | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-success.svg)](https://opensource.org/licenses/MIT) | ||
|
||
Spin-off repository of [Trixi.jl](https://github.com/trixi-framework/Trixi.jl) | ||
with neural network-based shock indicators. | ||
|
||
**Note: This repository is currently not under development and has been archived. If you are | ||
interested in using any of this, please get in touch with the developers of the | ||
[Trixi.jl](https://github.com/trixi-framework/Trixi.jl) package. | ||
|
||
|
||
## Usage | ||
To run any of the elixirs with the neurl network-based indicators, you first need to install | ||
all required auxiliary packages by running the following code in the Julia REPL: | ||
```julia | ||
julia> using Pkg | ||
|
||
julia> Pkg.add(["BSON", "Flux", "OrdinaryDiffEq", "Trixi"]) | ||
``` | ||
|
||
Then, clone this repository | ||
```shell | ||
git clone [email protected]:trixi-framework/TrixiSmartShockFinder.jl.git | ||
``` | ||
enter the directory, and start Julia (tested with Julia v1.9) with the project set to | ||
the clone directory | ||
``` | ||
cd TrixiSmartShockFinder.jl | ||
julia --project=. | ||
``` | ||
|
||
Now run one of the elixirs in the `examples` folder, e.g., | ||
```julia | ||
using TrixiSmartShockFinder | ||
trixi_include("examples/tree_2d_dgsem/elixir_euler_blast_wave_neuralnetwork_perssonperaire.jl") | ||
``` | ||
|
||
## Authors | ||
TrixiSmartShockFinder.jl was initiated by | ||
[Michael Schlottke-Lakemper](https://lakemper.eu) (University of Augsburg, Germany) and | ||
Julia Odenthal (University of Cologne, Germany). | ||
|
||
|
||
## License and contributing | ||
TrixiSmartShockFinder.jl is licensed under the MIT license (see [LICENSE.md](LICENSE.md)). |
115 changes: 115 additions & 0 deletions
115
examples/tree_1d_dgsem/elixir_euler_blast_wave_neuralnetwork_perssonperaire.jl
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,115 @@ | ||
using Downloads: download | ||
using Flux | ||
using BSON: load | ||
network = joinpath(@__DIR__, "modelnnpp-0.97-0.0001.bson") | ||
download("https://github.com/trixi-framework/Trixi_IndicatorNeuralNetwork_networks/raw/main/networks/modelnnpp-0.97-0.0001.bson", | ||
network) | ||
model1d = load(network, @__MODULE__)[:model1d] | ||
|
||
using OrdinaryDiffEq | ||
using TrixiSmartShockFinder | ||
using Trixi | ||
|
||
# TODO: Remove once Trixi.jl is released without these exports | ||
NeuralNetworkPerssonPeraire = TrixiSmartShockFinder.NeuralNetworkPerssonPeraire | ||
NeuralNetworkRayHesthaven = TrixiSmartShockFinder.NeuralNetworkRayHesthaven | ||
IndicatorNeuralNetwork = TrixiSmartShockFinder.IndicatorNeuralNetwork | ||
|
||
# This elixir was one of the setups used in the following master thesis: | ||
# - Julia Odenthal (2021) | ||
# Shock capturing with artificial neural networks | ||
# University of Cologne, advisors: Gregor Gassner, Michael Schlottke-Lakemper | ||
# This motivates the particular choice of fluxes, mesh resolution etc. | ||
|
||
############################################################################### | ||
# semidiscretization of the compressible Euler equations | ||
|
||
equations = CompressibleEulerEquations1D(1.4) | ||
|
||
""" | ||
initial_condition_blast_wave(x, t, equations::CompressibleEulerEquations1D) | ||
A medium blast wave taken from | ||
- Sebastian Hennemann, Gregor J. Gassner (2020) | ||
A provably entropy stable subcell shock capturing approach for high order split form DG | ||
[arXiv: 2008.12044](https://arxiv.org/abs/2008.12044) | ||
""" | ||
function initial_condition_blast_wave(x, t, equations::CompressibleEulerEquations1D) | ||
# Modified From Hennemann & Gassner JCP paper 2020 (Sec. 6.3) -> "medium blast wave" | ||
# Set up polar coordinates | ||
inicenter = SVector(0.0) | ||
x_norm = x[1] - inicenter[1] | ||
r = abs(x_norm) | ||
# The following code is equivalent to | ||
# phi = atan(0.0, x_norm) | ||
# cos_phi = cos(phi) | ||
# in 1D but faster | ||
cos_phi = x_norm > 0 ? one(x_norm) : -one(x_norm) | ||
|
||
# Calculate primitive variables | ||
rho = r > 0.5 ? 1.0 : 1.1691 | ||
v1 = r > 0.5 ? 0.0 : 0.1882 * cos_phi | ||
p = r > 0.5 ? 1.0E-3 : 1.245 | ||
|
||
return prim2cons(SVector(rho, v1, p), equations) | ||
end | ||
initial_condition = initial_condition_blast_wave | ||
|
||
surface_flux = flux_lax_friedrichs | ||
volume_flux = flux_chandrashekar | ||
basis = LobattoLegendreBasis(3) | ||
indicator_sc = IndicatorNeuralNetwork(equations, basis, | ||
indicator_type = NeuralNetworkPerssonPeraire(), | ||
alpha_max = 0.5, | ||
alpha_min = 0.001, | ||
alpha_smooth = true, | ||
alpha_continuous = false, | ||
alpha_amr = false, | ||
variable = density_pressure, | ||
network = model1d) | ||
volume_integral = VolumeIntegralShockCapturingHG(indicator_sc; | ||
volume_flux_dg = volume_flux, | ||
volume_flux_fv = surface_flux) | ||
solver = DGSEM(basis, surface_flux, volume_integral) | ||
|
||
coordinates_min = (-2.0,) | ||
coordinates_max = (2.0,) | ||
mesh = TreeMesh(coordinates_min, coordinates_max, | ||
initial_refinement_level = 6, | ||
n_cells_max = 10_000) | ||
|
||
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver) | ||
|
||
############################################################################### | ||
# ODE solvers, callbacks etc. | ||
|
||
tspan = (0.0, 12.5) | ||
ode = semidiscretize(semi, tspan) | ||
|
||
summary_callback = SummaryCallback() | ||
|
||
analysis_interval = 100 | ||
|
||
analysis_callback = AnalysisCallback(semi, interval = analysis_interval) | ||
|
||
alive_callback = AliveCallback(analysis_interval = analysis_interval) | ||
|
||
save_solution = SaveSolutionCallback(interval = 100, | ||
save_initial_solution = true, | ||
save_final_solution = true, | ||
solution_variables = cons2prim) | ||
|
||
stepsize_callback = StepsizeCallback(cfl = 0.5) | ||
|
||
callbacks = CallbackSet(summary_callback, | ||
analysis_callback, alive_callback, | ||
save_solution, | ||
stepsize_callback) | ||
|
||
############################################################################### | ||
# run the simulation | ||
|
||
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false), | ||
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback | ||
save_everystep = false, callback = callbacks); | ||
summary_callback() # print the timer summary |
Oops, something went wrong.