-
Notifications
You must be signed in to change notification settings - Fork 7
Add Burgers Equation solver example #22
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 all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
1851567
fix(vector_1D_t): mk weighted_premultiply private
rouson 146cc77
feat(burgers-1D): define initial condition, order
rouson bcb9fbe
feat(dyad_1D_t): type, operator(/), operator(*)
rouson 82c1e4d
feat(dyad_1D_t): add operator(.div.)
rouson b36d47a
refac: rename mimetic_* -> differential_operator_*
rouson 6c351be
feat(interpolation): add operators
rouson 44ad054
WIP: start defining divergence of dyad
rouson bb9e304
doc(README): merge upstream changes
rouson d3cb453
doc(README): resolve git-stash conflict
rouson 2d17f84
feat(interpolate): .div.dyad maps centers to faces
rouson 67c748b
feat(interpolation): centers-extended to faces
rouson 0c839bd
feat(interpolation): faces to centers-extended
rouson 5d81101
fix(burgers-1D): work around gfortran issue
rouson 420c46f
fix(interpolator_test): work around gfortran issue
rouson 7bb94ce
fix(dyad_1D_s): work around lfortran issue
rouson 6f1531f
doc(README): fix test command for fpm version<0.13
rouson 03886cc
test(dyad): assert .div. dyad_1D_t has N+1 points
rouson 91e6ef0
feat(scalar): power op, new construct, grid check
rouson dc493f5
feat(scalar_1D_t): type-bound division operator
rouson eae9489
refac(interpolator test): rm intermediate vars
rouson 41f867e
feat(d_dx): spatial partial deriv of 1D scalar
rouson 394b1b2
feat(d2_dx2): scalar_1D spatial 2nd partial deriv
rouson 62fa003
feat(scalar_1D): operator(*) for premult by double
rouson b86d9b4
feat(scalar_1D): operator(-) for scalar_1D lhs/rhs
rouson 3dac064
feat(scalar_1D): operator(+), operator(*)
rouson 4e2f5c7
feat(example): 1st-draft Burgers eq. solver
rouson e64aee1
chore(dyad_1D_t): remove unused type
rouson 61f0da5
fix(scalar_1D): operator(/) for integer denominator
rouson 35a9003
chore(scalar_1): assert preconditions in operators
rouson 6a25084
fix(scalar_1D_t): exponentiate & better test
rouson 158ba0a
fix(burgers-1D): work around gfortran issues
rouson 365a7f8
fix(scalar_1D_test): work around gfortran issues
rouson ae59e8d
chore(burgers): tidy up
rouson 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
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,97 @@ | ||
| ! Copyright (c) 2026, The Regents of the University of California | ||
| ! Terms of use are as specified in LICENSE.txt | ||
|
|
||
| module initial_condition_m | ||
| implicit none | ||
|
|
||
| contains | ||
|
|
||
| pure function initial_condition(x) | ||
| !! Initial solution to Burgers equation | ||
| double precision, intent(in) :: x(:) | ||
| double precision, allocatable :: initial_condition(:) | ||
| initial_condition = 10*sin(x) | ||
| ! To change this function, please edit only the right-hand-side (RHS) expression, | ||
| ! keeping the rest in place for proper display of the function at runtime. | ||
| end function | ||
|
|
||
| end module | ||
|
|
||
| program burgers_1D | ||
| !! This program demonstrates the use of Formal to solve the partial differential equation of | ||
| !! Burgers (1948) in conservative form using the 2nd- or 4th-order mimetic discretizations of | ||
| !! Corbino & Castillo (2020) and Dumett & Castillo (2022). | ||
| !! | ||
| !! * Burgers, J.M. (1948) https://doi.org/10.1016/S0065-2156(08)70100-5 | ||
| !! * Corbino & Castillo (2020) https://doi.org/10.1016/j.cam.2019.06.042. | ||
| !! * Dumett & Castillo (2022) https://doi.org/10.13140/RG.2.2.26630.14400 | ||
| use initial_condition_m, only : initial_condition | ||
| use julienne_m, only : command_line_t | ||
| use formal_m, only : scalar_1D_t, scalar_1D_initializer_i, d_dx, d2_dx2 | ||
| implicit none | ||
|
|
||
| #ifdef __GFORTRAN__ | ||
| procedure(scalar_1D_initializer_i), pointer :: scalar_1D_initializer | ||
| #endif | ||
| character(len=:), allocatable :: order_string | ||
| type(command_line_t) command_line | ||
| integer order | ||
|
|
||
| if (command_line%argument_present([character(len=len("--help")) :: ("--help"), "-h"])) then | ||
| stop new_line('') // new_line('') & | ||
| // 'Usage:' // new_line('') & | ||
| // ' fpm run \' // new_line('') & | ||
| // ' --example burgers-1D \' // new_line('') & | ||
| // ' --compiler flang \' // new_line('') & | ||
| // ' --flag "-O3" \' // new_line('') & | ||
| // ' [--help|-h] | [--order <integer>]' // new_line('') // new_line('') & | ||
| // 'where square brackets indicate optional arguments and angular brackets indicate user input values.' // new_line('') | ||
| end if | ||
|
|
||
| print *, new_line('') | ||
| print *," Initial condition" | ||
| print *," =================" | ||
|
|
||
| call execute_command_line("grep 'initial_condition =' example/burgers-1D.F90 | grep -v execute_command", wait=.true.) | ||
|
|
||
| order_string = command_line%flag_value("--order") | ||
|
|
||
| if (len(order_string)==0) then | ||
| order = 2 | ||
| else | ||
| read(order_string,"(i1)") order | ||
| end if | ||
|
|
||
| print *, "order = ", order | ||
|
|
||
| block | ||
| #ifndef __GFORTRAN__ | ||
| procedure(scalar_1D_initializer_i), pointer :: scalar_1D_initializer | ||
| #endif | ||
| double precision, parameter :: dt = 1D0, pi = acos(-1D0) | ||
| type(scalar_1D_t) u | ||
|
|
||
| scalar_1D_initializer => initial_condition | ||
| u = scalar_1D_t(scalar_1D_initializer, order, x_min=0D0, x_max=2*pi, cells=20) | ||
|
|
||
| runge_kutta_2nd_order: & | ||
| associate(u_half => u + d_dt(u)*dt/2) ! first substep | ||
| u = u + d_dt(u_half)*dt ! second substep | ||
| end associate runge_kutta_2nd_order | ||
|
|
||
| end block | ||
|
|
||
| #ifdef __GFORTRAN__ | ||
| stop | ||
| #endif | ||
|
|
||
| contains | ||
|
|
||
| pure function d_dt(u) result(du_dt) | ||
| type(scalar_1D_t), intent(in) :: u | ||
| type(scalar_1D_t) du_dt | ||
| double precision, parameter :: nu=1D0 | ||
| du_dt = nu*d2_dx2(u) - d_dx((u**2)/2) | ||
| end function | ||
|
|
||
| end program | ||
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
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
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,78 @@ | ||
| ! Copyright (c) 2026, The Regents of the University of California | ||
| ! Terms of use are as specified in LICENSE.txt | ||
|
|
||
| module interpolator_1D_m | ||
| !! Define a sparse matrix storage format tailored to the staggered-grid interpolation matrix | ||
| !! operators detailed by Dumett & Castillo (2022) https://doi.org/10.13140/RG.2.2.26630.14400 | ||
| implicit none | ||
|
|
||
| private | ||
| public :: centers_to_faces_1D_t | ||
| public :: faces_to_centers_1D_t | ||
|
|
||
| type, abstract :: interpolator_1D_t | ||
| !! Encapsulate a staggered-grid interpolation matrix with a corresponding matrix-vector product operator | ||
| private | ||
| integer order_, cells_, dx_ | ||
| double precision first_ | ||
| double precision, allocatable :: upper_(:,:) | ||
| double precision, allocatable :: inner_(:) | ||
| double precision, allocatable :: lower_(:,:) | ||
| double precision final_ | ||
| end type | ||
|
|
||
| type, extends(interpolator_1D_t) :: centers_to_faces_1D_t | ||
| contains | ||
| procedure, non_overridable :: face_values | ||
| end type | ||
|
|
||
| type, extends(interpolator_1D_t) :: faces_to_centers_1D_t | ||
| contains | ||
| procedure, non_overridable :: center_values | ||
| end type | ||
|
|
||
| interface centers_to_faces_1D_t | ||
|
|
||
| pure module function c2f_constructor(order, cells, dx) result(centers_to_faces_1D) | ||
| !! Construct centers-to-faces interpolation operator | ||
| implicit none | ||
| integer, intent(in) :: order, cells | ||
| double precision, intent(in) :: dx | ||
| type(centers_to_faces_1D_t) centers_to_faces_1D | ||
| end function | ||
|
|
||
| end interface | ||
|
|
||
| interface faces_to_centers_1D_t | ||
|
|
||
| pure module function f2c_constructor(order, cells, dx) result(faces_to_centers_1D) | ||
| !! Construct centers-to-faces interpolation operator | ||
| implicit none | ||
| integer, intent(in) :: order, cells | ||
| double precision, intent(in) :: dx | ||
| type(faces_to_centers_1D_t) faces_to_centers_1D | ||
| end function | ||
|
|
||
| end interface | ||
|
|
||
| interface | ||
|
|
||
| pure module function face_values(self, centers_extended) result(faces) | ||
| !! Interpolate cell-centered values to face-centered values | ||
| implicit none | ||
| class(centers_to_faces_1D_t), intent(in) :: self | ||
| double precision, intent(in) :: centers_extended(:) | ||
| double precision, allocatable :: faces(:) | ||
| end function | ||
|
|
||
| pure module function center_values(self, faces) result(centers_extended) | ||
| !! Interpolate face-centered values to cell-centered values | ||
| implicit none | ||
| class(faces_to_centers_1D_t), intent(in) :: self | ||
| double precision, intent(in) :: faces(:) | ||
| double precision, allocatable :: centers_extended(:) | ||
| end function | ||
|
|
||
| end interface | ||
|
|
||
| end module interpolator_1D_m |
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.