Skip to content
Public template

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Assignment 12 — Mixed Time Integration

Assignment tests

Goal

Extend the supplied one-dimensional reservoir solver with a mixed time-integration method. The transmissibility, accumulation, boundary conditions, and explicit and implicit solvers are already implemented. Your task is confined to solve_one_step() in assignment12.py; do not redo Assignment 11.

Four-block reservoir

inputs.yml supplies the four-block reservoir. The model uses pressure in psi, time in days, geometry in ft, permeability in mD and viscosity in cP. The supplied conversion factor is already applied once in T and Q. Keep that convention. T and B are sparse (N, N) matrices; p and Q are (N,) arrays. The balance is

$$ \mathbf{B}\frac{dp}{dt}+\mathbf{T}p=Q. $$

B stores block accumulation; T stores converted face conductances. Prescribed pressures act at boundary faces, half a block from the neighboring cell center; zero prescribed flux means no flow. The provided code handles both ends separately. Boundary conditions and sources are constant in time for this assignment.

Implement the mixed method

Support this solver input, either in a YAML file or an equivalent dictionary:

numerical:
  solver:
    mixed method:
      theta: 0.5

This is only the solver portion: retain the grid, time-step and other existing input fields. The existing strings explicit and implicit must still work. For this course's convention, theta weights the old-time transmissibility term:

$$ \left(\frac{\mathbf{B}}{\Delta t}+(1-\theta)\mathbf{T}\right)p^{n+1} = \left(\frac{\mathbf{B}}{\Delta t}-\theta \mathbf{T}\right)p^n+Q. $$

  • theta = 0: fully implicit.
  • theta = 1: fully explicit.
  • theta = 0.5: Crank–Nicolson.
  • Other finite real values between 0 and 1 are valid.

Some references use the opposite theta convention; use the equation above. Reject missing theta, nonnumeric values, booleans, NaN, infinity and values outside [0, 1] with ValueError. The mixed solver configuration must contain exactly mixed method, whose settings contain exactly theta. Unknown solver names or malformed configurations raise ValueError.

Use sparse matrix arithmetic and scipy.sparse.linalg.cg with atol=1e-8 and rtol=0.0 for the mixed linear system. Check the returned status: on failure, raise RuntimeError and leave the old pressure unchanged. Do not replace the supplied explicit or implicit branches or change other methods.

Work with your agent

Ask the agent to explain the balance equation and theta convention and propose a short implementation and verification plan. Review that plan before approving edits. Have it implement only the mixed-method extension, run the public tests and show the diff. Independently rerun the tests and inspect the change before accepting its work. Passing a few endpoint examples does not establish that an intermediate theta is implemented correctly.

Run and submit

Open in Codespaces, or install environment.yml with conda/micromamba. Codespaces requests Python and Jupyter extensions and registers the Python 3 (Assignment 12) kernel. Rebuild an existing Codespace to apply the configuration if necessary.

python -m unittest -v test.py test_submission.py

The starter passes the supplied-foundation and submission checks, but mixed-method checks fail until you implement the extension. Do not modify tests or inputs. Tests cover endpoint equivalence, Crank–Nicolson, intermediate theta, repeated steps, invalid settings, solver failure, and the existing model behavior.

Only assignment12.py is submitted and numerically graded. When ready, tell the agent submit assignment 12, review its submission plan and approve execution. Verify your pushed commit and GitHub Actions result.

Optional plots

Run verification.ipynb after implementation to view pressure plots for different theta values and time steps.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages