forked from trixi-framework/Trixi.jl
-
Couldn't load subscription status.
- Fork 1
Elixir: ImplicitEuler solve with sparse jacobian #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sbairos
wants to merge
132
commits into
DanielDoehring:main
Choose a base branch
from
sbairos:elixir_implicit_sparse
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 80 commits
Commits
Show all changes
132 commits
Select commit
Hold shift + click to select a range
e0f73ed
Elixir for implicit solver using sparse jacobian
9dbe05c
Docstring for new semidiscretize
6adff66
PR comments
097e994
Making the hacks into an extension
2e7cebf
Apply suggestions from code review
DanielDoehring 2be59f8
work
DanielDoehring 254a79f
packages
DanielDoehring 9089e6a
reduce time
DanielDoehring 89a7b92
work
DanielDoehring 524ae9a
use sparse ode
DanielDoehring c984c02
comment
DanielDoehring 0dd324d
be more explicit
DanielDoehring 1f5a40b
try nonlinear
DanielDoehring 46b2d92
comment
DanielDoehring ca5f951
comment
DanielDoehring 7bdfc8d
exchange solver
DanielDoehring 2f9d246
work
DanielDoehring c1ebd50
comment
DanielDoehring 7d141cf
comments
DanielDoehring bb6b7d5
Merge branch 'main' into SteveSparseDiff
DanielDoehring 4e163fe
comment
DanielDoehring dad7fe7
rename
DanielDoehring b5db145
comments
DanielDoehring 3ce1a4c
Moving the ext back into the elixirs
a65537c
Adding CI test
27bc102
Adding CI test for implicit_sparse_jacobian elixir
d956961
Update examples/tree_1d_dgsem/elixir_euler_convergence_implicit_spars…
DanielDoehring 4b1dbdd
Update examples/tree_1d_dgsem/elixir_euler_convergence_implicit_spars…
DanielDoehring cc3fa6a
Apply suggestions from code review
DanielDoehring 6e9a0d0
Update examples/tree_2d_dgsem/elixir_advection_implicit_sparse_jacobi…
DanielDoehring 6344c66
comments on constant jacs
DanielDoehring 63c9214
move dir
DanielDoehring 691cedf
comment
DanielDoehring c5f5fcf
order
DanielDoehring 5586491
restart file
DanielDoehring eb6aa90
Apply suggestions from code review
DanielDoehring e851808
compat
DanielDoehring 82caac1
Merge branch 'elixir_implicit_sparse' of github.com:sbairos/Trixi.jl …
DanielDoehring 9d97bcc
remove redundant comments
DanielDoehring 2ed4e38
Elixir for implicit solver using sparse jacobian
7bd5f32
Docstring for new semidiscretize
238cadb
PR comments
8a4ce20
Making the hacks into an extension
d12dca7
Apply suggestions from code review
DanielDoehring 6b3a900
work
DanielDoehring ef31890
packages
DanielDoehring d65fadb
reduce time
DanielDoehring 8289379
work
DanielDoehring 61e8f13
use sparse ode
DanielDoehring 6e3d6ea
comment
DanielDoehring d02e4d1
be more explicit
DanielDoehring d024182
try nonlinear
DanielDoehring 4041aab
comment
DanielDoehring b5f7e10
comment
DanielDoehring 80b3d53
exchange solver
DanielDoehring 979a66b
work
DanielDoehring 914e1dd
comment
DanielDoehring 9cfdbd0
comments
DanielDoehring 0fa5381
comment
DanielDoehring 987c1ea
rename
DanielDoehring 8c7a425
comments
DanielDoehring b526312
Moving the ext back into the elixirs
51a5b77
Adding CI test
9f713b9
Adding CI test for implicit_sparse_jacobian elixir
4ca244b
CI tests for both
6909159
Merge branch 'workwork' into elixir_implicit_sparse
4467be4
Other 2 CI tests
5bb92d6
Uncomment commented tests and delete 1D convergence_implicit elixir
0cc77c0
Replace the test that I accidentally overwrote
a829d5c
Unit test
c303210
Update test/test_unit.jl
DanielDoehring 84a5be8
Update Project.toml
DanielDoehring 747768e
Update examples/tree_2d_dgsem/elixir_advection_implicit_sparse_jacobi…
DanielDoehring 9a164a8
Update examples/tree_2d_dgsem/elixir_advection_implicit_sparse_jacobi…
DanielDoehring 03ac768
revisit
DanielDoehring b0e9083
unit test
DanielDoehring 5c33791
repeat comment
DanielDoehring 5e7e7b1
linear structure
DanielDoehring 9137af2
fmzt
DanielDoehring 5ae5c72
fix unit test
DanielDoehring 026bc8a
Apply suggestions from code review
DanielDoehring 6e8115c
Spellcheck
2a894fe
Merge branch 'main' into elixir_implicit_sparse
DanielDoehring a147c1c
Update examples/tree_2d_dgsem/elixir_advection_implicit_sparse_jacobi…
DanielDoehring 5719d0e
Merge branch 'main' into elixir_implicit_sparse
DanielDoehring 61e4d47
comment
DanielDoehring 122a46e
add sparse arrays
DanielDoehring 47a7a5b
try module
DanielDoehring ea8cf44
rm
DanielDoehring b9a54d2
try more specific overload
DanielDoehring 476b174
Merge branch 'main' into elixir_implicit_sparse
DanielDoehring 309c730
simplify
DanielDoehring 6d6a497
v
DanielDoehring 36ed9b9
v
DanielDoehring 07589c2
Update examples/structured_2d_dgsem/elixir_euler_convergence_implicit…
DanielDoehring 70b3861
Update examples/structured_2d_dgsem/elixir_euler_convergence_implicit…
DanielDoehring f479c92
Update examples/structured_2d_dgsem/elixir_euler_convergence_implicit…
DanielDoehring 8478589
Merge branch 'main' into elixir_implicit_sparse
DanielDoehring aba1e36
Merge branch 'main' into elixir_implicit_sparse
DanielDoehring 25518ef
Update examples/tree_2d_dgsem/elixir_advection_implicit_sparse_jacobi…
DanielDoehring 6ea38f2
Merge branch 'main' into elixir_implicit_sparse
DanielDoehring 5153dab
Merge branch 'main' into elixir_implicit_sparse
DanielDoehring f2f3780
correct comment
DanielDoehring 613f01a
Merge branch 'elixir_implicit_sparse' of github.com:sbairos/Trixi.jl …
DanielDoehring 1b241ae
simplify
DanielDoehring 25b54b5
kwargs
DanielDoehring c026cf9
adapt
DanielDoehring 0f3f00c
shorten
DanielDoehring 9bc0f6c
Update examples/tree_2d_dgsem/elixir_advection_implicit_sparse_jacobi…
DanielDoehring cde1bff
fmt
DanielDoehring eb29838
simplify
DanielDoehring a72dce2
try different warning
DanielDoehring 2c9eb34
warning
DanielDoehring d9e4b51
Merge branch 'main' into elixir_implicit_sparse
DanielDoehring f99ac51
test
DanielDoehring 5c5722f
Merge branch 'elixir_implicit_sparse' of github.com:sbairos/Trixi.jl …
DanielDoehring 8542b3e
up
DanielDoehring 43900a4
revert
DanielDoehring 9d04c00
move comment
DanielDoehring 03c6b7b
compat
DanielDoehring 7824a97
v
DanielDoehring 5357ec3
v
DanielDoehring a16419a
v
DanielDoehring a4f3af4
try plots
DanielDoehring 6991c6e
v
DanielDoehring 63a415e
Update test/Project.toml
DanielDoehring d21a0e2
module replace
DanielDoehring 151bc57
Merge branch 'elixir_implicit_sparse' of github.com:sbairos/Trixi.jl …
DanielDoehring 72ac79f
typo
DanielDoehring b04e814
Merge branch 'main' into elixir_implicit_sparse
DanielDoehring 76754b5
error tol
DanielDoehring c815383
Merge branch 'elixir_implicit_sparse' of github.com:sbairos/Trixi.jl …
DanielDoehring File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
159 changes: 159 additions & 0 deletions
159
examples/structured_2d_dgsem/elixir_euler_convergence_implicit_sparse_jacobian.jl
This file contains hidden or 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,159 @@ | ||
| using Trixi | ||
| using OrdinaryDiffEqSDIRK | ||
|
|
||
| # Functionality for automatic sparsity detection | ||
| using SparseDiffTools, Symbolics | ||
|
|
||
| import Base: * # For overloading with type `Real` | ||
|
|
||
| ############################################################################################### | ||
| ### Overloads to construct the `LobattoLegendreBasis` with `Real` type (supertype of `Num`) ### | ||
|
|
||
| # Required for setting up the Lobatto-Legendre basis for abstract `Real` type. | ||
| # Constructing the Lobatto-Legendre basis with `Real` instead of `Num` is | ||
| # significantly easier as we do not have to care about e.g. if-clauses. | ||
| # As a consquence, we need to provide some overloads hinting towards the intended behavior. | ||
|
|
||
| const float_type = Float64 # Actual floating point type for the simulation | ||
|
|
||
| # Newton tolerance for finding LGL nodes & weights | ||
| Trixi.eps(::Type{Real}) = Base.eps(float_type) | ||
| # There are some places where `one(RealT)` or `zero(uEltype)` is called where `RealT` or `uEltype` is `Real`. | ||
| # This returns an `Int64`, i.e., `1` or `0`, respectively which gives errors when a floating-point alike type is expected. | ||
| Trixi.one(::Type{Real}) = Base.one(float_type) | ||
| Trixi.zero(::Type{Real}) = Base.zero(float_type) | ||
|
|
||
| # Multiplying two Matrix{Real}s gives a Matrix{Any}. | ||
| # This causes problems when instantiating the Legendre basis, which calls | ||
| # `calc_{forward,reverse}_{upper, lower}` which in turn uses the matrix multiplication | ||
| # which is overloaded here in construction of the interpolation/projection operators | ||
| # required for mortars. | ||
| function *(A::Matrix{Real}, B::Matrix{Real})::Matrix{Real} | ||
| m, n = size(A, 1), size(B, 2) | ||
| kA = size(A, 2) | ||
| kB = size(B, 1) | ||
| @assert kA==kB "Matrix dimensions must match for multiplication" | ||
|
|
||
| C = Matrix{Real}(undef, m, n) | ||
| for i in 1:m, j in 1:n | ||
| #acc::Real = zero(promote_type(typeof(A[i,1]), typeof(B[1,j]))) | ||
| acc = zero(Real) | ||
| for k in 1:kA | ||
| acc += A[i, k] * B[k, j] | ||
| end | ||
| C[i, j] = acc | ||
| end | ||
| return C | ||
| end | ||
|
|
||
| # We need to avoid if-clauses to be able to use `Num` type from Symbolics without additional hazzle. | ||
| # In the Trixi implementation, we overload the sqrt function to first check if the argument | ||
| # is < 0 and then return NaN instead of an error. | ||
| # To turn off this behaviour, we switch back to the Base implementation here which does not contain an if-clause. | ||
| Trixi.sqrt(x::Num) = Base.sqrt(x) | ||
|
|
||
| ############################################################################################### | ||
| ### equations and solver ### | ||
|
|
||
| equations = CompressibleEulerEquations2D(1.4) | ||
|
|
||
| # For sparsity detection we can only use `flux_lax_friedrichs` at the moment since this is | ||
| # `if`-clause free | ||
| surface_flux = flux_lax_friedrichs | ||
|
|
||
| # `RealT = Real` requires fewer overloads than the more explicit `RealT = Num` from Symbolics. | ||
| # `solver_real` is used for computing the Jacobian sparsity pattern | ||
| solver_real = DGSEM(polydeg = 3, surface_flux = surface_flux, RealT = Real) | ||
| # `solver_float` is used for the subsequent simulation | ||
| solver_float = DGSEM(polydeg = 3, surface_flux = surface_flux, RealT = float_type) | ||
|
|
||
| ############################################################################################### | ||
| ### mesh ### | ||
|
|
||
| # Mapping as described in https://arxiv.org/abs/2012.12040, | ||
| # reduced to 2D on [0, 2]^2 instead of [0, 3]^3 | ||
| function mapping(xi_, eta_) | ||
| # Transform input variables between -1 and 1 onto [0,2] | ||
| xi = xi_ + 1 | ||
| eta = eta_ + 1 | ||
|
|
||
| y = eta + 1 / 4 * (cos(pi * (xi - 1)) * | ||
| cos(0.5 * pi * (eta - 1))) | ||
|
|
||
| x = xi + 1 / 4 * (cos(0.5 * pi * (xi - 1)) * | ||
| cos(2 * pi * (y - 1))) | ||
|
|
||
| return SVector(x, y) | ||
| end | ||
| cells_per_dimension = (16, 16) | ||
| mesh = StructuredMesh(cells_per_dimension, mapping) | ||
|
|
||
| ############################################################################################### | ||
| ### semidiscretizations ### | ||
|
|
||
| initial_condition = initial_condition_convergence_test | ||
|
|
||
| # `semi_real` is used for computing the Jacobian sparsity pattern | ||
| semi_real = SemidiscretizationHyperbolic(mesh, equations, | ||
| initial_condition_convergence_test, | ||
| solver_real, | ||
| source_terms = source_terms_convergence_test) | ||
| # `semi_float` is used for the subsequent simulation | ||
| semi_float = SemidiscretizationHyperbolic(mesh, equations, | ||
| initial_condition_convergence_test, | ||
| solver_float, | ||
| source_terms = source_terms_convergence_test) | ||
|
|
||
| t0 = 0.0 # Re-used for the ODE function defined below | ||
| t_end = 5.0 | ||
| t_span = (t0, t_end) | ||
|
|
||
| # Call `semidiscretize` on `semi_float` to create the ODE problem to have access to the initial condition. | ||
| ode_float = semidiscretize(semi_float, t_span) | ||
| u0_ode = ode_float.u0 | ||
| du_ode = similar(u0_ode) | ||
|
|
||
| ############################################################################################### | ||
| ### Compute the Jacobian with SparseDiffTools ### | ||
|
|
||
| # Create a function with two parameters: `du_ode` and `u0_ode` | ||
| # to fulfill the requirments of an in_place function in SparseDiffTools | ||
| # (see example function `f` from https://docs.sciml.ai/SparseDiffTools/dev/#Example) | ||
| rhs = (du_ode, u0_ode) -> Trixi.rhs!(du_ode, u0_ode, semi_real, t0) | ||
|
|
||
| # Taken from example linked above to detect the pattern and choose how to do the differentiation | ||
| sd = SymbolicsSparsityDetection() | ||
| ad_type = AutoForwardDiff() | ||
| sparse_adtype = AutoSparse(ad_type) | ||
|
|
||
| # `sparse_cache` will reduce calculation time when Jacobian is calculated multiple times | ||
| sparse_cache = sparse_jacobian_cache(sparse_adtype, sd, rhs, du_ode, u0_ode) | ||
|
|
||
| ############################################################################################### | ||
| ### Set up sparse-aware ODEProblem ### | ||
|
|
||
| # Revert overrides from above for the actual simulation | ||
| Trixi.eps(x::Type{Real}) = Base.eps(x) | ||
| Trixi.one(x::Type{Real}) = Base.one(x) | ||
| Trixi.zero(x::Type{Real}) = Base.zero(x) | ||
|
|
||
| # Supply Jacobian prototype and coloring vector to the semidiscretization | ||
| ode_float_jac_sparse = semidiscretize(semi_float, t_span, | ||
| sparse_cache.jac_prototype, | ||
| sparse_cache.coloring.colorvec) | ||
|
|
||
| summary_callback = SummaryCallback() | ||
| analysis_callback = AnalysisCallback(semi_float, interval = 50) | ||
| alive_callback = AliveCallback(alive_interval = 3) | ||
|
|
||
| # Note: No `stepsize_callback` due to implicit solver | ||
| callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback) | ||
|
|
||
| ############################################################################################### | ||
| ### solve the ODE problem ### | ||
|
|
||
| sol = solve(ode_float_jac_sparse, # using `ode_float` is essentially infeasible, even single step takes ages! | ||
| # Default `AutoForwardDiff()` is not yet working, | ||
| # probably related to https://docs.sciml.ai/DiffEqDocs/stable/basics/faq/#Autodifferentiation-and-Dual-Numbers | ||
| Kvaerno4(; autodiff = AutoFiniteDiff()); | ||
| dt = 0.05, save_everystep = false, callback = callbacks); |
140 changes: 140 additions & 0 deletions
140
examples/tree_2d_dgsem/elixir_advection_implicit_sparse_jacobian.jl
This file contains hidden or 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,140 @@ | ||
| using Trixi | ||
| using OrdinaryDiffEqSDIRK | ||
|
|
||
| # Functionality for automatic sparsity detection | ||
| using SparseDiffTools, Symbolics | ||
|
|
||
| import Base: eps, zero, one, * # For overloading with type `Real` | ||
|
|
||
| ############################################################################################### | ||
| ### Overloads to construct the `LobattoLegendreBasis` with `Real` type (supertype of `Num`) ### | ||
|
|
||
| # Required for setting up the Lobatto-Legendre basis for abstract `Real` type. | ||
| # Constructing the Lobatto-Legendre basis with `Real` instead of `Num` is | ||
| # significantly easier as we do not have to care about e.g. if-clauses. | ||
| # As a consquence, we need to provide some overloads hinting towards the intended behavior. | ||
|
|
||
| const float_type = Float64 # Actual floating point type for the simulation | ||
|
|
||
| # Newton tolerance for finding LGL nodes & weights | ||
| Trixi.eps(::Type{Real}) = Base.eps(float_type) | ||
| # There are some places where `one(RealT)` or `zero(uEltype)` is called where `RealT` or `uEltype` is `Real`. | ||
| # This returns an `Int64`, i.e., `1` or `0`, respectively which gives errors when a floating-point alike type is expected. | ||
| Trixi.one(::Type{Real}) = Base.one(float_type) | ||
| Trixi.zero(::Type{Real}) = Base.zero(float_type) | ||
|
|
||
| # Multiplying two Matrix{Real}s gives a Matrix{Any}. | ||
| # This causes problems when instantiating the Legendre basis, which calls | ||
| # `calc_{forward,reverse}_{upper, lower}` which in turn uses the matrix multiplication | ||
| # which is overloaded here in construction of the interpolation/projection operators | ||
| # required for mortars. | ||
| function *(A::Matrix{Real}, B::Matrix{Real})::Matrix{Real} | ||
| m, n = size(A, 1), size(B, 2) | ||
| kA = size(A, 2) | ||
| kB = size(B, 1) | ||
| @assert kA==kB "Matrix dimensions must match for multiplication" | ||
|
|
||
| C = Matrix{Real}(undef, m, n) | ||
| for i in 1:m, j in 1:n | ||
| #acc::Real = zero(promote_type(typeof(A[i,1]), typeof(B[1,j]))) | ||
| acc = zero(Real) | ||
| for k in 1:kA | ||
| acc += A[i, k] * B[k, j] | ||
| end | ||
| C[i, j] = acc | ||
| end | ||
| return C | ||
| end | ||
|
|
||
| ############################################################################################### | ||
| ### semidiscretizations of the linear advection equation ### | ||
|
|
||
| advection_velocity = (0.2, -0.7) | ||
| equation = LinearScalarAdvectionEquation2D(advection_velocity) | ||
|
|
||
| # `RealT = Real` requires fewer overloads than the more explicit `RealT = Num` from Symbolics | ||
| # `solver_real` is used for computing the Jacobian sparsity pattern | ||
| solver_real = DGSEM(polydeg = 3, surface_flux = flux_godunov, RealT = Real) | ||
| # `solver_float` is used for the subsequent simulation | ||
| solver_float = DGSEM(polydeg = 3, surface_flux = flux_godunov) | ||
|
|
||
| coordinates_min = (-1.0, -1.0) | ||
| coordinates_max = (1.0, 1.0) | ||
|
|
||
| mesh = TreeMesh(coordinates_min, coordinates_max, | ||
| initial_refinement_level = 4, | ||
| n_cells_max = 30_000) | ||
|
|
||
| # `semi_real` is used for computing the Jacobian sparsity pattern | ||
| semi_real = SemidiscretizationHyperbolic(mesh, equation, | ||
| initial_condition_convergence_test, | ||
| solver_real) | ||
| # `semi_float` is used for the subsequent simulation | ||
| semi_float = SemidiscretizationHyperbolic(mesh, equation, | ||
| initial_condition_convergence_test, | ||
| solver_float) | ||
|
|
||
| t0 = 0.0 # Re-used for the ODE function defined below | ||
| t_end = 1.0 | ||
| t_span = (t0, t_end) | ||
|
|
||
| # Call `semidiscretize` on `semi_float` to create the ODE problem to have access to the initial condition. | ||
| # For the linear example considered here one could also use an arbitrary vector for the initial condition. | ||
| ode_float = semidiscretize(semi_float, t_span) | ||
| u0_ode = ode_float.u0 | ||
| du_ode = similar(u0_ode) | ||
|
|
||
| ############################################################################################### | ||
| ### Compute the Jacobian with SparseDiffTools ### | ||
|
|
||
| # Create a function with two parameters: `du_ode` and `u0_ode` | ||
| # to fulfill the requirments of an in_place function in SparseDiffTools | ||
| # (see example function `f` from https://docs.sciml.ai/SparseDiffTools/dev/#Example) | ||
| rhs = (du_ode, u0_ode) -> Trixi.rhs!(du_ode, u0_ode, semi_real, t0) | ||
|
|
||
| # Taken from example linked above to detect the pattern and choose how to do the AutoDiff automatically | ||
| sd = SymbolicsSparsityDetection() | ||
| ad_type = AutoFiniteDiff() | ||
| sparse_adtype = AutoSparse(ad_type) | ||
|
|
||
| # `sparse_cache` will reduce calculation time when Jacobian is calculated multiple times, | ||
| # which is in principle not required for the linear problem considered here. | ||
| sparse_cache = sparse_jacobian_cache(sparse_adtype, sd, rhs, du_ode, u0_ode) | ||
|
|
||
| ############################################################################################### | ||
| ### Set up sparse-aware ODEProblem ### | ||
|
|
||
| # Revert overrides from above for the actual simulation | ||
| Trixi.eps(x::Type{Real}) = Base.eps(x) | ||
| Trixi.one(x::Type{Real}) = Base.one(x) | ||
| Trixi.zero(x::Type{Real}) = Base.zero(x) | ||
|
|
||
| # Supply Jacobian prototype and coloring vector to the semidiscretization | ||
| ode_float_jac_sparse = semidiscretize(semi_float, t_span, | ||
| sparse_cache.jac_prototype, | ||
| sparse_cache.coloring.colorvec) | ||
|
|
||
| # Note: We experimented for linear problems with providing the constant, sparse Jacobian directly via | ||
| # | ||
| # const jac_sparse = sparse_jacobian(sparse_adtype, sparse_cache, rhs, du_ode, u0_ode) | ||
| # const jac_sparse_func!(J, u, p, t) = jac_sparse | ||
| # SciMLBase.ODEFunction(rhs!, jac_prototype=float.(jac_prototype), colorvec=colorvec, jac = jac_sparse_func!) | ||
| # | ||
| # which turned out to be significantly slower than just using the prototype and the coloring vector. | ||
|
|
||
| summary_callback = SummaryCallback() | ||
| analysis_callback = AnalysisCallback(semi_float, interval = 10) | ||
| save_restart = SaveRestartCallback(interval = 100, | ||
| save_final_restart = true) | ||
|
|
||
| # Note: No `stepsize_callback` due to (implicit) solver with adaptive timestep control | ||
| callbacks = CallbackSet(summary_callback, analysis_callback, save_restart) | ||
|
|
||
| ############################################################################################### | ||
| ### solve the ODE problem ### | ||
|
|
||
| sol = solve(ode_float_jac_sparse, # using `ode_float_jac_sparse` instead of `ode_float` results in speedup of factors 10-15! | ||
| # Default `AutoForwardDiff()` is not yet working, | ||
| # probably related to https://docs.sciml.ai/DiffEqDocs/stable/basics/faq/#Autodifferentiation-and-Dual-Numbers | ||
| TRBDF2(; autodiff = ad_type); | ||
| adaptive = true, dt = 0.1, save_everystep = false, callback = callbacks); |
28 changes: 28 additions & 0 deletions
28
examples/tree_2d_dgsem/elixir_advection_implicit_sparse_jacobian_restart.jl
This file contains hidden or 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,28 @@ | ||
| using Trixi | ||
|
|
||
| ############################################################################### | ||
| # create a restart file | ||
|
|
||
| elixir_file = "elixir_advection_implicit_sparse_jacobian.jl" | ||
| restart_file = "restart_000000006.h5" | ||
|
|
||
| trixi_include(@__MODULE__, joinpath(@__DIR__, elixir_file)) | ||
|
|
||
| ############################################################################### | ||
|
|
||
| restart_filename = joinpath("out", restart_file) | ||
| t_span = (load_time(restart_filename), 2.0) | ||
| dt_restart = load_dt(restart_filename) | ||
|
|
||
| ode_float_jac_sparse = semidiscretize(semi_float, t_span, | ||
| sparse_cache.jac_prototype, | ||
| sparse_cache.coloring.colorvec) | ||
|
|
||
| ############################################################################### | ||
| # run the simulation | ||
|
|
||
| sol = solve(ode_float_jac_sparse, # using `ode_float_jac_sparse` instead of `ode_float` results in speedup of factors 10-15! | ||
| # Default `AutoForwardDiff()` is not yet working, | ||
| # probably related to https://docs.sciml.ai/DiffEqDocs/stable/basics/faq/#Autodifferentiation-and-Dual-Numbers | ||
| TRBDF2(; autodiff = ad_type); | ||
| adaptive = true, dt = dt_restart, save_everystep = false, callback = callbacks); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.