- 
                Notifications
    You must be signed in to change notification settings 
- Fork 133
Hyperbolic-Parabolic elixir using SparseConnectivityTracer #2604
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
          
     Merged
      
      
    
  
     Merged
                    Changes from 57 commits
      Commits
    
    
            Show all changes
          
          
            62 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      32c3b48
              
                Hyperbolic-Parabolic elixir using SCT
              
              
                 50ac70b
              
                Add CI test
              
              
                 ba41d03
              
                PR corrections
              
              
                 aaef843
              
                Adding missed comment
              
              
                 2dca898
              
                Navierstokes hyperbolic parabolic convergence test
              
              
                 a850705
              
                Adding CI test for advection_diffusion elixir
              
              
                 8721016
              
                Revert "Adding CI test for advection_diffusion elixir"
              
              
                 a99f8c7
              
                Apply suggestions from code review
              
              
                DanielDoehring af9ecf3
              
                Apply suggestions from code review
              
              
                DanielDoehring ea03915
              
                Update examples/tree_2d_dgsem/elixir_navierstokes_convergence_implici…
              
              
                DanielDoehring 923ead0
              
                Adding CI test for advection_diffusion elixir
              
              
                 61b19ab
              
                Revert "Adding CI test for advection_diffusion elixir"
              
              
                 7338beb
              
                Convert adv_diffusion to 1D and N-S to P4est
              
              
                 a02890c
              
                Use IMEX methods
              
              
                 c796eff
              
                Add demonstration of adv_velocity=0
              
              
                 31f7d7e
              
                Fix tests
              
              
                 283ec2b
              
                Apply suggestions from code review
              
              
                DanielDoehring 37cd0b5
              
                PR comments
              
              
                 0e4aada
              
                PR comments2
              
              
                 ca2be94
              
                Undo overwrite of Project.toml
              
              
                 c785a7a
              
                Remove the navierstokes elixir and test
              
              
                 d6d4ea0
              
                Update unit test to actually include rhs!
              
              
                 e62ea22
              
                Merge branch 'main' into split_Jac_SCT2
              
              
                DanielDoehring 90b6b55
              
                Update test/test_unit.jl
              
              
                DanielDoehring 9938624
              
                Merge branch 'main' into split_Jac_SCT2
              
              
                DanielDoehring 2ff50c5
              
                Apply suggestions from code review
              
              
                DanielDoehring fc82c9e
              
                Update test/test_parabolic_1d.jl
              
              
                DanielDoehring 9b76287
              
                Update test/test_parabolic_1d.jl
              
              
                DanielDoehring 2a670ea
              
                Formatting changes
              
              
                 a12ddd3
              
                Merge branch 'main' into split_Jac_SCT2
              
              
                DanielDoehring 5f805da
              
                PR comments
              
              
                 6a35c76
              
                Spell check / formatting
              
              
                 308abfc
              
                Formatting x2
              
              
                 4c453cd
              
                formatting x3
              
              
                 00cea01
              
                formatting last time
              
              
                 db3c85e
              
                Merge branch 'main' into split_Jac_SCT2
              
              
                DanielDoehring c465dce
              
                Apply suggestions from code review
              
              
                DanielDoehring a808417
              
                Apply suggestions from code review
              
              
                DanielDoehring 3a4e586
              
                Apply suggestions from code review
              
              
                DanielDoehring 7ff20ee
              
                Fix unit test
              
              
                 98e5ff4
              
                Merge branch 'main' into split_Jac_SCT2
              
              
                DanielDoehring 75af937
              
                Update test/test_unit.jl
              
              
                DanielDoehring 5bdb3c0
              
                Merge branch 'main' into split_Jac_SCT2
              
              
                DanielDoehring 018e7f9
              
                Update test/test_unit.jl
              
              
                DanielDoehring dac9f22
              
                Update test/test_unit.jl
              
              
                DanielDoehring 006cd55
              
                Apply suggestions from code review
              
              
                DanielDoehring 6729ec6
              
                Update test/test_unit.jl
              
              
                DanielDoehring bcc91fe
              
                Apply suggestions from code review
              
              
                DanielDoehring bb1a8be
              
                Update test/test_unit.jl
              
              
                DanielDoehring 49a35e8
              
                Merge branch 'main' into split_Jac_SCT2
              
              
                DanielDoehring 121276b
              
                Update examples/tree_1d_dgsem/elixir_advection_diffusion_implicit_spa…
              
              
                DanielDoehring 7747d55
              
                Update examples/tree_1d_dgsem/elixir_advection_diffusion_implicit_spa…
              
              
                DanielDoehring 49d0662
              
                Apply suggestions from code review
              
              
                DanielDoehring 6afddf1
              
                Apply suggestions from code review
              
              
                DanielDoehring 049e885
              
                Update test/test_unit.jl
              
              
                DanielDoehring 52509d4
              
                Update test/test_unit.jl
              
              
                DanielDoehring f09e3ac
              
                Update test/test_unit.jl
              
              
                DanielDoehring 6f6ef14
              
                Apply suggestions from code review
              
              
                DanielDoehring b3db7ef
              
                db
              
              
                DanielDoehring a8fb6bd
              
                update comments
              
              
                DanielDoehring b03fdb8
              
                typo
              
              
                DanielDoehring a322606
              
                typo
              
              
                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
          Some comments aren't visible on the classic Files Changed page.
        
There are no files selected for viewing
        
          
          
            126 changes: 126 additions & 0 deletions
          
          126 
        
  examples/tree_1d_dgsem/elixir_advection_diffusion_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,126 @@ | ||
| using Trixi | ||
| using SparseConnectivityTracer # For obtaining the Jacobian sparsity pattern | ||
| using SparseMatrixColorings # For obtaining the coloring vector | ||
| using OrdinaryDiffEqBDF, ADTypes | ||
|  | ||
| ############################################################################### | ||
| # semidiscretization of the linear advection-diffusion equation | ||
|  | ||
| advection_velocity = 1.5 | ||
| equations_hyperbolic = LinearScalarAdvectionEquation1D(advection_velocity) | ||
| diffusivity() = 5.0e-2 | ||
| equations_parabolic = LaplaceDiffusion1D(diffusivity(), equations_hyperbolic) | ||
|  | ||
| solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs) | ||
|  | ||
| coordinates_min = -1.0 | ||
| coordinates_max = 1.0 | ||
|  | ||
| mesh = TreeMesh(coordinates_min, coordinates_max, | ||
| initial_refinement_level = 4, | ||
| n_cells_max = 30_000) | ||
|  | ||
| function initial_condition_diffusive_convergence_test(x, t, | ||
| equation::LinearScalarAdvectionEquation1D) | ||
| # Store translated coordinate for easy use of exact solution | ||
| RealT = eltype(x) | ||
| x_trans = x - equation.advection_velocity * t | ||
|  | ||
| nu = diffusivity() | ||
| c = 1 | ||
| A = 0.5f0 | ||
| L = 2 | ||
| f = 1.0f0 / L | ||
| omega = 2 * convert(RealT, pi) * f | ||
| scalar = c + A * sin(omega * sum(x_trans)) * exp(-2 * nu * omega^2 * t) | ||
| return SVector(scalar) | ||
| end | ||
| initial_condition = initial_condition_diffusive_convergence_test | ||
|  | ||
| ############################################################################### | ||
| ### semidiscretization for sparsity detection ### | ||
|  | ||
| jac_detector = TracerSparsityDetector() | ||
| # We need to construct the semidiscretization with the correct | ||
| # sparsity-detection ready datatype, which is retrieved here | ||
| jac_eltype = jacobian_eltype(real(solver), jac_detector) | ||
|  | ||
| semi_jac_type = SemidiscretizationHyperbolicParabolic(mesh, | ||
| (equations_hyperbolic, | ||
| equations_parabolic), | ||
| initial_condition, solver, | ||
| uEltype = jac_eltype) | ||
|  | ||
| tspan = (0.0, 1.5) # Re-used for wrapping `rhs_parabolic!` below | ||
|  | ||
| # Call `semidiscretize` to create the ODE problem to have access to the | ||
| # initial condition based on which the sparsity pattern is computed | ||
| ode_jac_type = semidiscretize(semi_jac_type, tspan) | ||
| u0_ode = ode_jac_type.u0 | ||
| du_ode = similar(u0_ode) | ||
|  | ||
| ############################################################################### | ||
| ### Compute the Jacobian sparsity pattern ### | ||
|  | ||
| # Only the parabolic part of the `SplitODEProblem` is treated implicitly so we only need the parabolic Jacobian, see | ||
| # https://docs.sciml.ai/DiffEqDocs/stable/types/split_ode_types/#SciMLBase.SplitFunction | ||
| # Wrap the `Trixi.rhs_parabolic!` function to match the signature `f!(du, u)`, see | ||
| # https://adrianhill.de/SparseConnectivityTracer.jl/stable/user/api/#ADTypes.jacobian_sparsity | ||
| rhs_parabolic_wrapped! = (du_ode, u0_ode) -> Trixi.rhs_parabolic!(du_ode, u0_ode, | ||
| semi_jac_type, tspan[1]) | ||
|  | ||
| jac_prototype_parabolic = jacobian_sparsity(rhs_parabolic_wrapped!, du_ode, u0_ode, | ||
| jac_detector) | ||
|  | ||
| # For most efficient solving we also want the coloring vector | ||
|  | ||
| # We choose `nonsymmetric` `structure` because we're computing a Jacobian, which | ||
| # is for the upwind-alike discretization of the advection term nonsymmmetric | ||
| # We arbitrarily choose a column-based `partitioning`. This means that we will color | ||
| # structurally orthogonal columns the same. `row` partitioning would be equally valid here | ||
| coloring_prob = ColoringProblem(; structure = :nonsymmetric, partition = :column) | ||
| # The `decompression` arg specifies our evaluation scheme. The `direct` method requires solving | ||
| # a diagonal system, whereas the `substitution` method solves a triangular system of equations | ||
| coloring_alg = GreedyColoringAlgorithm(; decompression = :direct) | ||
| coloring_result = coloring(jac_prototype_parabolic, coloring_prob, coloring_alg) | ||
| coloring_vec_parabolic = column_colors(coloring_result) | ||
|  | ||
| ############################################################################### | ||
| ### sparsity-aware semidiscretization and ODE ### | ||
|  | ||
| # Semidiscretization for actual simulation. `uEltype` is here retrieved from `solver` | ||
| semi= = SemidiscretizationHyperbolicParabolic(mesh, | ||
| (equations_hyperbolic, | ||
| equations_parabolic), | ||
| initial_condition, solver) | ||
|  | ||
| # Supply Jacobian prototype and coloring vector to the semidiscretization | ||
| ode = semidiscretize(semi, tspan, | ||
| jac_prototype_parabolic = jac_prototype_parabolic, | ||
| colorvec_parabolic = coloring_vec_parabolic) | ||
| # using "dense" `ode = semidiscretize(semi, tspan)` is 4-6 times slower! | ||
|  | ||
| ############################################################################### | ||
| ### callbacks ### | ||
|  | ||
| summary_callback = SummaryCallback() | ||
|  | ||
| analysis_interval = 100 | ||
| analysis_callback = AnalysisCallback(semi, interval = analysis_interval) | ||
|  | ||
| alive_callback = AliveCallback(analysis_interval = analysis_interval) | ||
|  | ||
| 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, alive_callback, save_restart) | ||
|  | ||
| ############################################################################### | ||
| ### solve the ODE problem ### | ||
|  | ||
| sol = solve(ode, SBDF2(; autodiff = AutoFiniteDiff()); | ||
| ode_default_options()..., | ||
| dt = 0.01, | ||
| abstol = 1e-9, reltol = 1e-9, | ||
| callback = callbacks) | ||
|         
                  DanielDoehring marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
        
          
          
            30 changes: 30 additions & 0 deletions
          
          30 
        
  examples/tree_1d_dgsem/elixir_advection_diffusion_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,30 @@ | ||
| using Trixi | ||
|  | ||
| ############################################################################### | ||
| # create a restart file | ||
|  | ||
| elixir_file = "elixir_advection_diffusion_implicit_sparse_jacobian.jl" | ||
| restart_file = "restart_000000100.h5" | ||
|  | ||
| trixi_include(@__MODULE__, joinpath(@__DIR__, elixir_file)) | ||
|  | ||
| ############################################################################### | ||
|  | ||
| restart_filename = joinpath("out", restart_file) | ||
| tspan = (load_time(restart_filename), 2.0) | ||
| dt_restart = load_dt(restart_filename) | ||
|  | ||
| ode = semidiscretize(semi, tspan, | ||
| restart_filename, | ||
| jac_prototype_parabolic = jac_prototype_parabolic, | ||
| colorvec_parabolic = coloring_vec_parabolic) | ||
|  | ||
| ############################################################################### | ||
| # run the simulation | ||
|  | ||
| sol = solve(ode_jac_sparse, | ||
| SBDF2(; autodiff = AutoFiniteDiff()); | ||
| ode_default_options()..., | ||
| dt = dt_restart, | ||
| abstol = 1e-9, reltol = 1e-9, | ||
| callback = callbacks); | ||
|         
                  DanielDoehring marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      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.