Skip to content

Add Julia transport1D example (#503) - #527

Open
Aditi-Naiknaware wants to merge 1 commit into
csrc-sdsu:mainfrom
Aditi-Naiknaware:issue-503-transport1d-julia
Open

Aditi-Naiknaware wants to merge 1 commit into
csrc-sdsu:mainfrom
Aditi-Naiknaware:issue-503-transport1d-julia

Conversation

@Aditi-Naiknaware

Copy link
Copy Markdown

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Example
  • Documentation

Description

This PR adds a Julia implementation of the existing C++ transport1D.cpp example 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, and
  • Operators.interpol(m, 0.5) for center-to-face interpolation of the concentration field.

The numerical parameters were kept consistent with the existing C++ example:

  • Operator order: k = 2
  • Domain: [0, 130]
  • Number of cells: m = 26
  • Simulation time: t = 4
  • Number of iterations: iter = 208
  • Dispersivity: 5 m
  • Pore-water velocity: 15 m/year
  • Retardation: R = 2.5
  • Initial concentration: C0 = 1 mmol/kgw

As 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 = 0 through i = iter, inclusive, so the Julia example uses the equivalent 0:iter iteration 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 output directory, 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 transport1D example proposed in #503.

QA Instructions, Screenshots, Recordings

Running the example

From the julia/MOLE.jl directory, run:

julia --project=. examples/parabolic/transport1D.jl

The example should:

  1. Construct the one-dimensional MOLE gradient, divergence, and center-to-face interpolation operators.
  2. Run the advection-reaction-dispersion simulation using the same numerical parameters as the existing C++ transport1D.cpp example.
  3. Print the final concentration vector.
  4. Generate examples/parabolic/output/transport1D.png containing the final concentration profile.

Cross-language validation

I ran the existing C++ examples/cpp/transport1D.cpp implementation 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 + 2 scalar-field values for m = 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:

Position in vector C++ result Julia result
1 1.0000e+00 1.0000000000
2 9.9012e-01 0.9901161678
3 9.5237e-01 0.9523694224
4 8.8441e-01 0.8844054487
5 7.8370e-01 0.7837043464
10 1.6534e-01 0.1653402611
15 6.2998e-03 0.0062998176
20 5.2687e-05 0.0000526873
25 1.2324e-07 1.2323886847e-07
26 3.2192e-08 3.2191918473e-08
27 9.8869e-09 9.8869009150e-09
28 9.8869e-09 9.8869009150e-09

The 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++ transport1D example.

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:

Testing MOLE operators       | 214 / 214 passed
Testing Boundary Conditions  |  14 / 14 passed
Testing Grids                | 113 / 113 passed

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:

  • Concentration vector C: m + 2 entries
  • Gradient output: m + 1 face values
  • Interpolated concentration I * C: m + 1 face values
  • Velocity vector V: m + 1 entries
  • Divergence output: m + 2 entries

This ensures that the Julia expression

D * (dis .* (G * C)) - D * (V .* (I * C))

uses the same staggered-grid structure as the corresponding C++ calculation.

Keep-open request

  • I am requesting maintainer review for 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.

  • Yes
  • No, and this is why: This PR adds a new example rather than modifying the MOLE.jl operator implementation. No new automated unit test was added. The example was validated directly against the existing C++ transport1D.cpp implementation, and the complete existing MOLE.jl test suite was run after the change. All 341 existing tests passed.
  • I need help with writing tests

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?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MOLE.jl: Add a 1D transport equation example

1 participant