Repository navigation
Add Julia transport1D example (#503) - #527
Open
Aditi-Naiknaware wants to merge 1 commit into
Open
Aditi-Naiknaware wants to merge 1 commit into
Aditi-Naiknaware wants to merge 1 commit into
Conversation
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What type of PR is this? (check all applicable)
Description
This PR adds a Julia implementation of the existing C++
transport1D.cppexample to MOLE.jl.The example solves the same 1D advection-reaction-dispersion problem as the existing C++ implementation and uses the corresponding MOLE.jl mimetic operators. The purpose of this contribution is to expand the MOLE.jl example coverage while also providing a direct cross-language validation case between the C++ and Julia implementations.
The Julia example uses:
Operators.grad(k, m, dx)for the concentration gradient,Operators.div(k, m, dx)for the divergence of the dispersive and advective fluxes, andOperators.interpol(m, 0.5)for center-to-face interpolation of the concentration field.The numerical parameters were kept consistent with the existing C++ example:
k = 2[0, 130]m = 26t = 4iter = 2085 m15 m/yearR = 2.5C0 = 1 mmol/kgwAs in the C++ implementation, the hydrodynamic dispersion coefficient is calculated by multiplying the dispersivity by the pore-water velocity, and the time step is adjusted by the retardation factor.
The Julia implementation also preserves the time-integration behavior of the existing C++ example. The C++ loop runs from
i = 0throughi = iter, inclusive, so the Julia example uses the equivalent0:iteriteration range.The right boundary reflection condition is translated from the zero-based C++ indexing
C(m + 1) = C(m)to the equivalent one-based Julia indexing
C[m + 2] = C[m + 1].The example also generates a plot of the final concentration profile as a function of position. The plot is saved to the example's
outputdirectory, following the general output pattern used by existing MOLE.jl examples. The generated output directory is already excluded by the repository's.gitignore.Related Issues & Documents
This PR implements the Julia
transport1Dexample proposed in #503.QA Instructions, Screenshots, Recordings
Running the example
From the
julia/MOLE.jldirectory, run:The example should:
transport1D.cppexample.examples/parabolic/output/transport1D.pngcontaining the final concentration profile.Cross-language validation
I ran the existing C++
examples/cpp/transport1D.cppimplementation and used its final concentration vector as the reference result. I then ran the new Julia implementation using the same problem parameters and numerical setup.Both implementations produced 28 concentration values, corresponding to the
m + 2scalar-field values form = 26. I compared the complete output vectors. The Julia results agree with the C++ results to the precision printed by the C++ implementation.Representative values from across the concentration profile are shown below:
1.0000e+001.00000000009.9012e-010.99011616789.5237e-010.95236942248.8441e-010.88440544877.8370e-010.78370434641.6534e-010.16534026116.2998e-030.00629981765.2687e-050.00005268731.2324e-071.2323886847e-073.2192e-083.2191918473e-089.8869e-099.8869009150e-099.8869e-099.8869009150e-09The small apparent differences in the table are due to the C++ example printing fewer significant digits, while Julia prints the concentration values at higher precision.
The final two values are equal in both implementations, which is also consistent with the reflected right boundary condition.
This comparison verifies that the Julia implementation reproduces the numerical behavior of the existing C++
transport1Dexample.MOLE.jl test suite
After adding the example, I ran the complete existing MOLE.jl test suite with:
julia --project=. -e 'using Pkg; Pkg.test()'The results were:
Therefore, all 341 existing MOLE.jl tests passed after adding the new example.
Additional validation
I also verified the dimensions of the operators and fields used by the example:
C:m + 2entriesm + 1face valuesI * C:m + 1face valuesV:m + 1entriesm + 2entriesThis ensures that the Julia expression
uses the same staggered-grid structure as the corresponding C++ calculation.
Keep-open request
keep-open.Reason:
This PR implements the contribution discussed in #503. I would appreciate maintainer review and feedback, particularly regarding the placement and conventions of the new MOLE.jl example. I am available to address requested changes or suggestions.
Added/updated tests?
We encourage you to test all code included with MOLE, including examples.
transport1D.cppimplementation, and the complete existing MOLE.jl test suite was run after the change. All 341 existing tests passed.Read Contributing Guide and Code of Conduct
[optional] Are there any post deployment tasks we need to perform?
None.
[optional] What gif best describes this PR or how it makes you feel?