Skip to content

Commit

Permalink
Comments, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
patnr committed Sep 26, 2023
1 parent 694676f commit 9f5aee2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion TPFA_ResSim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def _set_Q(self, k):
for xy, q in zip(xys, rates):
# Use += in case of superimposed wells (e.g. by optimzt)
Q[self.xy2ind(*xy)] += sign * q
assert np.isclose(Q.sum(), 0), "Inj - Prod does not sum to 0"
assert np.isclose(Q.sum(), 0), "(Inj - Prod) does not sum to 0"
self._Q = Q

# Pres() -- listing 5
Expand Down
10 changes: 5 additions & 5 deletions TPFA_ResSim/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
The index ordering is "C-style" (numpy default).
This choice means that `x` is the 1st coord., `y` is 2nd,
and is hardcoded in the reservoir simulator model code
in what takes place **between** `np.ravel` and `np.reshape`
(both of which are configured to use row-major index ordering).
(in what takes place **between** `np.ravel` and `np.reshape`,
both of which are configured to use row-major index ordering.
"F-style" (column-major) indexing implementation is perfectly possible,
but would imply an undue amount hassle).
Conveniently, it also means that `x` and `y` tend to occur in alphabetic order.
Thus, in printing a matrix of a field, the `x` coordinate corresponds to the row index.
By contrast, the plotting module depicts `x` from left to right, `y` from bottom to top.
Implementing support for "F-style" (column-major) indexing is possible,
but would imply an undue amount hassle.
"""

from dataclasses import dataclass
Expand Down Expand Up @@ -68,7 +68,7 @@ def size(self):

@property
def domain(self):
"""`(0, 0, Lx, Ly)`"""
"""`((0, 0), (Lx, Ly))`"""
return ((0, 0), (self.Lx, self.Ly))

@property
Expand Down
20 changes: 10 additions & 10 deletions TPFA_ResSim/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,14 @@ def plt_field(self, ax, Z, style="default", wells=True,
`kwargs` falls back to `styles[style]`, which falls back to `styles['defaults']`.
"""
# Set defaults
# Populate kwargs with fallback style
kwargs = {**styles["default"], **styles[style], **kwargs}
# Pop from kwargs. Remainder goes to countourf
ax.set(**axprops(kwargs))
cticks = kwargs.pop("cticks")

# Plotting with extent=(0, Lx, 0, Ly), rather than merely changing ticks
# has the advantage that set_aspect("equal") yields correct axes size,
# and that mouse hovering (with interactive backends) reports correct pos.
# Disadvantage: well_scatter must also account for coord_type.
# Why extent=(0, Lx, 0, Ly), rather than merely changing ticks?
# set_aspect("equal") and mouse hovering (reporting x,y).
if "rel" in coord_type:
Lx, Ly = 1, 1
elif "abs" in coord_type:
Expand All @@ -75,8 +73,8 @@ def plt_field(self, ax, Z, style="default", wells=True,
else:
raise ValueError(f"Unsupported coord_type: {coord_type}")

# Need to transpose coz self assumes shape (Nx, Ny),
# and contour() uses the same orientation as array printing.
# Need to transpose coz orientation is model.shape==(Nx, Ny),
# while contour() displays the same orientation as array printing.
Z = kwargs.pop("transf")(Z)
Z = Z.reshape(self.shape).T

Expand All @@ -85,9 +83,11 @@ def plt_field(self, ax, Z, style="default", wells=True,

# ax.imshow(Z[::-1])
collections = ax.contourf(
Z, **kwargs, extend="both" if has_out_of_range else "neither",
origin="lower", extent=(0, Lx, 0, Ly),
)
Z, **kwargs,
origin="lower",
extent=(0, Lx, 0, Ly),
extend="both" if has_out_of_range else "neither",
)

# Contourf does not plot (at all) the bad regions. "Fake it" by facecolor
if has_out_of_range:
Expand Down

0 comments on commit 9f5aee2

Please sign in to comment.