Skip to content

Commit

Permalink
SPEED: Avoid double costly evaluation of permeability in constitutive…
Browse files Browse the repository at this point in the history
… law

This gives a surprising speedup in computations
  • Loading branch information
keileg committed Feb 18, 2025
1 parent 628c26c commit b49c619
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/porepy/models/constitutive_laws.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,16 +518,16 @@ def operator_to_SecondOrderTensor(
# fall back on reference value.
permeability = fallback_value * np.ones(sd.num_cells) * volume
return pp.SecondOrderTensor(permeability)
evaluated_value = self.equation_system.evaluate(operator)
if not isinstance(evaluated_value, np.ndarray):

if not isinstance(permeability, np.ndarray):
# Raise error rather than cast for verbosity of function which is not
# directly exposed to the user, but depends on a frequently user-defined
# quantity (the tensor being converted).
raise ValueError(
f"Operator {operator.name} has type {type(evaluated_value)}, "
f"Operator {operator.name} has type {type(permeability)}, "
f"expected numpy array for conversion to SecondOrderTensor."
)
val = evaluated_value.reshape(9, -1, order="F")
val = permeability.reshape(9, -1, order="F")
# SecondOrderTensor's constructor expects up to six entries: kxx, kyy, kzz,
# kxy, kxz, kyz. These correspond to entries 0, 4, 8, 1, 2, 5 in the 9 x
# num_cells array.
Expand Down

0 comments on commit b49c619

Please sign in to comment.