Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
209 commits
Select commit Hold shift + click to select a range
3e585c5
TST: Refactored Ad GridOperator tests.
keileg Sep 9, 2026
2d1f816
FEAT: Domain check of Ad Operators
keileg Mar 4, 2026
90605bb
MAINT: Ad scalars have empty domains
keileg Mar 17, 2026
6838819
Stage 1: Convert GridEntity from type alias to str enum
keileg Apr 8, 2026
59e3211
Stage 2: Add DomainType, OperatorSpace, and operator domain/range pro…
keileg Apr 8, 2026
3eb0cda
Fix Stage 2 regressions in model tests
keileg Apr 8, 2026
6677c43
Stage 3: assign domain/range to grid operators
keileg Apr 8, 2026
63a4f34
Stage 4c: add optional dof_info to TimeDependentDenseArray
keileg Apr 8, 2026
cf506f8
Stage 4e: MergedOperator inherits operator_domain/range from discreti…
keileg Apr 8, 2026
6b60ec2
Stage 5: validate operands and infer domain/range for arithmetic oper…
keileg Apr 8, 2026
ff91837
Stage 6: compound operator space tests and neg fixes
keileg Apr 9, 2026
0b74032
Stage 7: concrete get_row/col_dof_info on standard discretizations
keileg Apr 9, 2026
cd8a0fd
Stage 7: implement get_row/col_dof_info for Tpsa
keileg Apr 9, 2026
f3286ed
tests: add high-priority coverage gaps for ad operator domains
keileg Apr 9, 2026
185bc86
tests: add Variable-on-mortar and Divergence dim>1 coverage gaps
keileg Apr 9, 2026
57a5cab
tests: add Tpsa MergedOperator integration and sum_operator_list spac…
keileg Apr 9, 2026
95e1cd0
refactor: drop str inheritance from GridEntity, removing backwards co…
keileg Apr 9, 2026
a859d95
Stage B: Convert _domain_type from string literals to DomainType enum
keileg Apr 9, 2026
cbb0cbe
Fix string GridEntity key usages in tests after Stage A/B API changes
keileg Apr 9, 2026
7fa7f68
refactor(test_operator_space): module-level imports, helper functions…
keileg Apr 9, 2026
610e9b8
refactor(test_operator_space): parametrize arithmetic propagation tests
keileg Apr 9, 2026
8164b40
refactor(test_operator_space): parametrize discretization dof_info tests
keileg Apr 9, 2026
fa9a8f6
Move infer_domain_range to Operations enum; drop legacy domains propa…
keileg Apr 9, 2026
409b451
Rename range_ → range parameter throughout AD operators
keileg Apr 10, 2026
4068a22
Remove _domains/_domain_type; make domain/range mandatory keyword arg…
keileg Apr 10, 2026
1cc47c0
Remove Operator.subdomains and Operator.interfaces properties
keileg Apr 10, 2026
2454024
Add tests for Scalar domain support
keileg Apr 10, 2026
2477553
MAINT: Ad scalar operators have domains
keileg Apr 10, 2026
bec9396
REFACT: Move OperatorSpace and DomainType to separate module
keileg May 4, 2026
e0b7841
REFACT: Ad operations avoids use of private operator attributes
keileg May 4, 2026
7e08324
DOC: Comments in Ad operations class
keileg May 4, 2026
19ecdea
MAINT: Discretization row/col dof info raise for unknown matrix keys
keileg May 4, 2026
5bb8d26
REFACT: Rename Discretization -> DiscretizationAd in ad hierarchy
keileg May 4, 2026
9466653
FEAT: InterfaceDiscretizations have row/col info getters
keileg May 4, 2026
7e4b341
MAINT: Implement row/col dof info getters for UpwindCoupling
keileg May 4, 2026
2e71e7b
FEAT: Ad MergedOperators create row/col dof info for all discretizations
keileg May 4, 2026
263903a
Require explicit Operator spaces
keileg May 5, 2026
1fe7f40
Refresh AD operator-space tests
keileg May 5, 2026
b32adba
FEAT: AdFunctions must specify domain and range
keileg May 5, 2026
853f592
FEAT: MixedDim Ad variables have domains and ranges
keileg May 5, 2026
f7afb35
TUT: Domain and range in tutorial pp.ad.Function
keileg May 5, 2026
8698612
BUG: Ad Operators only need compatible ranges, not domains
keileg May 5, 2026
51bbf7d
FEAT: Ad OperatorSpaces can be unclear
keileg May 8, 2026
1a697b7
MAINT: Parameter check on OperatorSpaces
keileg May 8, 2026
2f1d0e4
MAINT: Reworked OperatorSpace logic in Ad Operator construction
keileg May 8, 2026
2fa685d
MAINT: Update constitutive laws to new OperatorSpace logic
keileg May 8, 2026
8343dd0
MAINT: TimeDependentDenseArrays know their spacial dimension
keileg May 8, 2026
b67cf39
MAINT: Model boundary condition creation accounts for spatial dimension
keileg May 8, 2026
215ea15
MAINT: Simplifications after OperatorSpace update
keileg May 8, 2026
2faa0ef
MAINT: Ad MergedOperator keep track of its domains
keileg May 8, 2026
c971ef2
MAINT: Update tests after OperatorSpace change
keileg May 8, 2026
c11055a
BUG: FractureStress operator space mismatch of characteristic size
keileg May 8, 2026
e4ef219
MAINT: Remove domain and domains property from MdVariable
keileg May 11, 2026
6bcf99f
MAINT: Remove _grid attribute from Variable class
keileg May 11, 2026
cb760bf
MAINT: Variables no longer has attributes _cells, _faces, _nodes
keileg May 11, 2026
993ef5d
MAINT: Purge Ad Operator property domain_type
keileg May 11, 2026
5e310fa
MAINT: Purge property domain from Variable class
keileg May 11, 2026
351058b
MAINT: Make MdVariable helper method private
keileg May 11, 2026
3f4968c
Rename AD operator spaces to source/target
keileg May 11, 2026
20ade30
Refresh operator-space planning docs
keileg May 11, 2026
1482c99
MAINT: Fixes after rebasing on develop
keileg Jun 18, 2026
e44d70b
MAINT: Updates after rebasing operator_domains on reference-states
keileg Jul 2, 2026
947ab39
MAINT: Simplified syntax of operator space definitions
keileg Jul 2, 2026
cf4b504
STY: Simplification and docs of get row/col info for discretizations
keileg Jul 3, 2026
612c21f
TST: Purge test of discretization row/col dof getters
keileg Jul 3, 2026
1fbdc29
TST: Simplifications in test of operator spaces
keileg Jul 3, 2026
db2acd6
TST: Simplified OperatorSpace tests for ad grid operators
keileg Jul 3, 2026
7c961cd
FEAT: Ad Wrapped dense arrays have domains and range
keileg Jul 3, 2026
b27cb71
MAINT: Ad discretizations take spatial dimension as arguments
keileg Jul 6, 2026
da23cbd
MAINT: OperatorSpaces domain type can be specified also for empty dom…
keileg Jul 6, 2026
bb41bec
MAINT: Updates to Operator parsing of OperatorSpace information
keileg Jul 6, 2026
531b8d0
MAINT: Ad wrapping of arrays can specify which grid entity the targe…
keileg Jul 6, 2026
48e0ef9
MAINT: Minor fix in OperatorSpace
keileg Jul 6, 2026
ae0a782
MAINT: Fix operator space in line search
keileg Jul 6, 2026
c018ecf
MAINT: Fix OperatorSpace for diff-tpfa
keileg Jul 6, 2026
ca9f7b5
MAINT: Remove assertion in Ad operator init
keileg Jul 6, 2026
87bb929
MAINT: Ad wrapping of grid entities account for face and node arrays
keileg Jul 9, 2026
8ccc49f
FEAT: OperatorSpaces have num_dof method
keileg Jul 9, 2026
b56f0c0
FEAT: Ad operator size check for sparse and dense arrays
keileg Jul 9, 2026
d04dea3
TST: Tests for Ad sparse and dense array shape checks
keileg Jul 9, 2026
36c3b18
MAINT: Fix OperatorSpaces for Dense and Sparse AdArrays
keileg Jul 9, 2026
05d3b12
MAINT: Fix operatorSpaces for md variables
keileg Jul 9, 2026
b9af022
MAINT: Fix OperatorSpaces for grid operators
keileg Jul 9, 2026
7c68df2
MAINT: Updates to Ad operator space parsing
keileg Jul 9, 2026
1ddb035
MAINT: Operator Spaces for summation of list of slicers
keileg Jul 9, 2026
65c28ca
MAINT: OperatorSpaces for Projection Operators
keileg Jul 9, 2026
03b44c1
FEAT: Model geometry basis methods use OperatorSpace
keileg Jul 9, 2026
11fd7ad
TST: Bugfix in test of tpfa
keileg Jul 9, 2026
cf40e79
MAINT: Treatment of OperatorSpaces for Ad Interpolated and Diagonal O…
keileg Jul 9, 2026
b0a33fe
FEAT: OperatorSpace for SparseAdArray transpose
keileg Jul 9, 2026
7595465
MAINT: OperatorSpace added in parsing step
keileg Jul 9, 2026
1fb73b8
MAINT: Fixup of OperatorSpace for Ad functions
keileg Jul 9, 2026
3ddee29
MAINT: OperatorSpace for DenseArray Ad operators
keileg Jul 9, 2026
49da428
MAINT: Fix Operatorspace in line search
keileg Jul 10, 2026
aa98e50
MAINT: Add OperatorSpace in sneddon setup
keileg Jul 10, 2026
1d86a92
TST: Update OperatorSpaces in tests
keileg Jul 10, 2026
687c3c8
FEAT: Introduce waived OperatorSpaces to disable size compatibility c…
keileg Jul 10, 2026
d38b762
TST: Purge OperatorSpace tests that probes None spaces
keileg Jul 10, 2026
38771f3
MAINT: Let diff-tpfa half-transmissibility matrices use waived Operat…
keileg Jul 10, 2026
3c34218
TST: Reworked test for copying Ad operator trees
keileg Jul 10, 2026
5b7ee7f
TST: Updates to test of AdOperator parsing
keileg Jul 10, 2026
214300e
TST: Remove tests that targets Operators with source/target set to None
keileg Jul 10, 2026
b55c2bd
TST: TestOperators fixes related to OperatorSpaces
keileg Jul 10, 2026
7933214
MAINT: TimeDependentDenseArrays must be able to infer their domain types
keileg Jul 10, 2026
f8705f1
FEAT: AdOperator construction requires source and target spaces
keileg Jul 10, 2026
bbc38e5
STY: Added type hints in tpsa
keileg Jul 10, 2026
70372e1
STY: Ad Operators are typed as non-optional
keileg Jul 10, 2026
2c663e9
MAINT: Deleted unused void GridEntity
keileg Jul 10, 2026
0752a46
MAINT: Minor cleanup in OperatorSpace
keileg Jul 10, 2026
8b7414b
MAINT: Make grid_entity module public
keileg Jul 10, 2026
e083c2b
MAINT: Simplification of OperatorSpace combination logic
keileg Jul 10, 2026
802fc62
TST: Simplified test of grid_entity
keileg Jul 10, 2026
ef8afad
MAINT: Minor documentation and improvements relating to OperatorSpaces
keileg Jul 10, 2026
9f8eb6e
MAINT: Operator mixins source and target are not optional
keileg Jul 10, 2026
31b1dcb
TST: Delete operator space checks for individual discretizations
keileg Jul 10, 2026
8b310f9
TST: Prune test_operator_spaces
keileg Jul 10, 2026
6599a01
TST: Simplify OperatorSpcae test of compound spaces
keileg Jul 10, 2026
d8138c5
TST: Simplified test of OperatorSpcae domain/range propagation
keileg Jul 10, 2026
193574d
MAINT: Parameter parsing in Ad MergedOperator
keileg Jul 10, 2026
116cbf0
MAINT: Move Ad Operations class to separate module
keileg Aug 4, 2026
cc39797
TST: Operator wrapping on scalars in tests
keileg Aug 4, 2026
1069e72
TST: Simplified tests of operator spaces
keileg Aug 4, 2026
ca71ffe
TST: Move tests for Ad operations to separate module
keileg Aug 4, 2026
b1c02b2
REFACT: Move helper method in Ad Operations source/target identification
keileg Aug 4, 2026
7380439
BUG: Ad operation source-target identifacation of rmatmul
keileg Aug 4, 2026
e2b95c2
REFACT: Extract helper function in Ad operations source-target inferral
keileg Aug 4, 2026
efa91ed
MAINT: Documentation and simplification of Ad Operations class
keileg Aug 4, 2026
fca87b6
MAINT: Documentation and cleanup of operator space module
keileg Aug 4, 2026
6ef8bf3
MAINT: Deleted unused code in Ad Operator parsing
keileg Aug 4, 2026
6b576d5
MAINT: Improvements and documentation in Ad operator module
keileg Aug 4, 2026
71378f7
TST: Cleanup and simplifications in test of operator spaces
keileg Aug 5, 2026
767f3b2
TST: Remove duplicated tests for OperatorSpaces
keileg Aug 5, 2026
45db982
TST: Fix test of operator space
keileg Aug 7, 2026
20935c1
BUG: Variable domains are arrays in equationSystem
keileg Aug 7, 2026
72df0f2
BUG: Ad Operator domains should be inferred from target, not source
keileg Aug 7, 2026
5a45d33
DEL: Remove Ad Variable property dof_info
keileg Aug 7, 2026
f0996c0
DEL: Remove mistakenly added copilot files
keileg Aug 7, 2026
04de1f5
TST: Delete test of models on scalar domains
keileg Aug 7, 2026
9867494
TST: Purge unnecessary test of operator spaces
keileg Aug 7, 2026
834c948
MAINT: EquationSystem set_equation() no longer gets domain
keileg Aug 7, 2026
8535a19
BUG: Missing Ad operator source/target in equtaion metric
keileg Aug 14, 2026
b777f16
BUG: Correct calculation of dofs in EquationSystem indexer construction
keileg Aug 14, 2026
6ec753d
MAINT: Ad Variable has property domain
keileg Aug 14, 2026
dd5d4ac
STY: Ruff, isort
keileg Aug 14, 2026
c94ac44
TST: Wrap scalars as Ad operators in diff-tpfa test
keileg Aug 14, 2026
426bd30
TST: Wrong dof declaration in matrix inversion test
keileg Aug 14, 2026
12774e8
STY: Mypy issues in _operations.py
keileg Aug 14, 2026
9b2eaab
MAINT: Updates based on comments from code review
keileg Aug 18, 2026
94028db
MAINT: Remove unneeded domain_type argument in surrogate operators
keileg Aug 19, 2026
d1426d2
MAINT: Operator domains return a tuple, not a list
keileg Aug 19, 2026
d4d3209
MAINT: Minor change to ad variable domain type
keileg Aug 19, 2026
ad92f70
MAINT: Simplified access to domain of atomic Ad Variable operator
keileg Aug 19, 2026
f1d06e1
TST: Minor additions to OperatorSpcae tests
keileg Aug 20, 2026
1e53456
MAINT: Purge property equation_image_size_info from EquationSystem
keileg Aug 20, 2026
986ae4f
MAINT: Ad Variable num_dofs is picked from operator space
keileg Aug 20, 2026
352f3ab
MAINT: Surrogate factory num_dofs_on_grid uses Operator space informa…
keileg Aug 20, 2026
c56d3d6
MAINT: Ad Operator target defaults to source
keileg Aug 20, 2026
6f4a0ee
DOC: Ad operator sparse and dense array docstrings
keileg Aug 20, 2026
abe90dc
BUG: FrictionDamage equtaion dof info
keileg Aug 20, 2026
850f9cf
MAINT: EquationSystem set_equation dof_info is optional
keileg Aug 20, 2026
9b912b4
MAINT: Models do not exlpcitly set equation dof information
keileg Aug 20, 2026
1404d54
FEAT: Introduce GridEntities data class
keileg Aug 20, 2026
c510d30
MAINT: Updates to GridEntities dataclass
keileg Aug 20, 2026
ac36fec
MAINT: Take GridEntities dataclass into use
keileg Aug 20, 2026
51a15f3
MAINT: Simpler access to dof information from OperatorSpaces
keileg Aug 20, 2026
a3e4c20
FEAT: OperatorSpaces are immutable
keileg Aug 21, 2026
58dac0f
FEAT: OperatorSpace dof-info defaults to cells=1
keileg Aug 21, 2026
a7c5158
MAINT: OperatorSpaces with 1 cell dof need not declare their dofs
keileg Aug 21, 2026
e51af50
MAINT: Remove outdated checks of empty Operator targets
keileg Aug 21, 2026
0b0d972
MAINT: Ad wrapping of arrays has grids as mandatory parameter
keileg Aug 21, 2026
82a298c
MAINT: Ad operator functions have identical source and target by default
keileg Aug 21, 2026
fb4101f
MAINT: EquationSystem update_equation no longer takes grids argument
keileg Aug 21, 2026
50b65fe
TST: Cover OperatorSpaces in the Ad GridOperator tests.
keileg Aug 25, 2026
03556b3
TST: Cleanup test of grid entity structure
keileg Aug 25, 2026
bc03903
TST: Merged test of operator spaces for Dense and sparse arrays
keileg Aug 25, 2026
7531db1
TST: Update docstrings for test of grid operators and Ad operator spaces
keileg Aug 25, 2026
1444de9
STY: Ruff formatting
keileg Aug 25, 2026
664b212
MAINT: Update OperatorSpace definitions
keileg Aug 25, 2026
eccca03
TUT: Update tutorials to operator spaces
keileg Aug 25, 2026
a76d7df
TUT: Update equations tutorial
keileg Aug 26, 2026
c1ca35e
MAINT; Remove outdated definition in EquationSystem
keileg Aug 27, 2026
0911eb3
MAINT: Remove admissible_dof_types from EquationSystem
keileg Aug 27, 2026
c23c78b
MAINT: Simplified EquationSystem indexer construction
keileg Aug 27, 2026
1a4a1f5
MAINT: Helper functions for Ad grid projection operator space constru…
keileg Aug 27, 2026
1605068
MAINT: Variable init dof info given by GridEntities
keileg Aug 27, 2026
f5ec570
MAINT: Surrogate operator init accepts GridEntities dof info
keileg Aug 27, 2026
8deaa2d
MAINT: DiagonalJacobian Ad Operator Funciton needs source and target …
keileg Aug 27, 2026
70f4a2e
DOC: Comments in fracture stress constitutive law
keileg Aug 27, 2026
c60f9f4
TST: Issue in progres bar test
keileg Aug 27, 2026
03e6222
MAINT: GridEntities is now a dataclass
keileg Sep 3, 2026
7e47ee6
MAINT: Discretization classes dof enquiries return GridEntities
keileg Sep 3, 2026
665d81d
MAINT: Cleanup in OperatorSpace dof-info treatment
keileg Sep 3, 2026
25763b2
MAINT: New GridEntities is taken into use
keileg Sep 3, 2026
8330b74
TST: Update tests to use new GridEntities
keileg Sep 3, 2026
f70e266
TST: Update GridEntities tests
keileg Sep 3, 2026
3679063
BLD: Update Changelog
keileg Sep 3, 2026
55e57a5
BUG: Postponed annotation evaluation in discretization modules
keileg Sep 3, 2026
031589d
STY: Ruff format
keileg Sep 3, 2026
60154ec
MAINT: Edits after code review
keileg Sep 9, 2026
963e796
Apply batched suggestions from code review
keileg Sep 9, 2026
cea1e54
MAINT: Rename row/col info methods in discretizations
keileg Sep 9, 2026
bb85ab7
MAINT: GridEntities->present_entities return tuple instead of frozenset
keileg Sep 9, 2026
59949a2
TEST: Deleted unnecessary GridEntities test
keileg Sep 9, 2026
a86ec73
MAINT: OperatorSpace grid and domain_type must agree if both are spec…
keileg Sep 9, 2026
b586c0c
MAINT: Model basis methods cannot mix domain types
keileg Sep 9, 2026
56187fe
MAINT: Stricter checks of ad operator matmul operator spaces
keileg Sep 9, 2026
d68b379
TST: Improve test of operator space
keileg Sep 9, 2026
24789fe
TST: Minor documentation fixes in grid entities test
keileg Sep 9, 2026
9aa1be0
MAINT: Remove unreachable branch in operator space inference
keileg Sep 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ PR 1772: SPEED: Faster construction of grid topologies on 3d simplex grids.
PR 1770: Simplify PR template by deferring to CONTRIBUTING.md for details on code style and conventions.
PR 1767: Bugfix in THM manufactured setup.
PR 1766: Fix bug in generation of Cartesian grids not anchored in the origin.
PR 1747: Ad Operators domain, range and dof info is specified by OperatorSpace objects.
PR 1732: Added support for evaluating restricted variable subsystems without evaluating
the full Jacobian and then slicing columns.




### Breaking changes
PR 1747: DenseAdArray, SparseAdArray must be initialized with OperatorSpace objects.
Other Ad Operators are by default treated as mapping from and to the same grid, with one
degree of freedom per cell. To change this default, explicit OperatorSpaces must be
assigned.

Changes to the front end (user-facing code: multiphysics models, solvers, grids, and
similar) that require users to update their own code when upgrading.
12 changes: 8 additions & 4 deletions src/porepy/applications/discretizations/flux_discretization.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class FluxDiscretization:
fourier_keyword: str
"""Keyword for the Fourier (energy) problem."""

nd: int
"""Ambient dimension of the problem. Normally set by a mixin instance of
:class:`~porepy.models.geometry.ModelGeometry`."""

def darcy_flux_discretization(
self, subdomains: list[pp.Grid]
) -> pp.ad.MpfaAd | pp.ad.TpfaAd:
Expand All @@ -31,9 +35,9 @@ def darcy_flux_discretization(
"""
scheme = self.params.get("darcy_flux_discretization", "mpfa")
if scheme.lower() == "mpfa":
return pp.ad.MpfaAd(self.darcy_keyword, subdomains)
return pp.ad.MpfaAd(self.darcy_keyword, subdomains, nd=self.nd)
elif scheme.lower() == "tpfa":
return pp.ad.TpfaAd(self.darcy_keyword, subdomains)
return pp.ad.TpfaAd(self.darcy_keyword, subdomains, nd=self.nd)
else:
msg = f"{scheme} is not a valid Darcy flux discretization scheme. "
msg += "Use either 'tpfa' or 'mpfa'."
Expand All @@ -53,9 +57,9 @@ def fourier_flux_discretization(
"""
scheme = self.params.get("fourier_flux_discretization", "mpfa")
if scheme.lower() == "mpfa":
return pp.ad.MpfaAd(self.fourier_keyword, subdomains)
return pp.ad.MpfaAd(self.fourier_keyword, subdomains, nd=self.nd)
elif scheme.lower() == "tpfa":
return pp.ad.TpfaAd(self.fourier_keyword, subdomains)
return pp.ad.TpfaAd(self.fourier_keyword, subdomains, nd=self.nd)
else:
msg = f"{scheme} is not a valid Fourier flux discretization scheme. "
msg += "Use either 'tpfa' or 'mpfa'."
Expand Down
5 changes: 4 additions & 1 deletion src/porepy/applications/test_utils/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def effective_tangential_permeability(
].values[0][0]
values.append(val_loc)
return pp.wrap_as_dense_ad_array(
np.hstack(values), size, "effective_tangential_permeability"
np.hstack(values),
size=size,
name="effective_tangential_permeability",
grids=subdomains,
)

def effective_normal_permeability(
Expand Down
4 changes: 3 additions & 1 deletion src/porepy/applications/test_utils/well_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,7 @@ def well_permeability(self, subdomains: list[pp.Grid]) -> pp.ad.Operator:

"""
size = sum(sd.num_cells for sd in subdomains)
permeability = pp.wrap_as_dense_ad_array(1, size, name="well permeability")
permeability = pp.wrap_as_dense_ad_array(
1, size=size, name="well permeability", grids=subdomains
)
return self.isotropic_second_order_tensor(subdomains, permeability)
14 changes: 9 additions & 5 deletions src/porepy/compositional/compositional_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ def overall_fraction(
if self.fluid.num_components == 1:

def fraction(domains: pp.SubdomainsOrBoundaries) -> pp.ad.Operator:
return pp.ad.Scalar(1.0, "single_feed_fraction")
return pp.ad.Scalar(1.0, "single_feed_fraction", domains=domains)

# NOTE: If the reference component fraction is independent, below elif-clause
# will be executed, instead of the next one.
Expand Down Expand Up @@ -737,7 +737,7 @@ def saturation(self, phase: Phase) -> DomainFunctionType:
if self.fluid.num_phases == 1:

def saturation(subdomains: pp.SubdomainsOrBoundaries) -> pp.ad.Operator:
return pp.ad.Scalar(1.0, "single_phase_saturation")
return pp.ad.Scalar(1.0, "single_phase_saturation", domains=subdomains)

# NOTE: If the reference phase is independent, below elif-clause will be
# executed.
Expand Down Expand Up @@ -773,7 +773,7 @@ def phase_fraction(self, phase: Phase) -> DomainFunctionType:
if self.fluid.num_phases == 1:

def fraction(domains: pp.SubdomainsOrBoundaries) -> pp.ad.Operator:
return pp.ad.Scalar(1.0, "single_phase_fraction")
return pp.ad.Scalar(1.0, "single_phase_fraction", domains=domains)

elif get_local_equilibrium_condition(self) is None:

Expand Down Expand Up @@ -845,7 +845,9 @@ def extended_fraction(

def fraction(domains: pp.SubdomainsOrBoundaries) -> pp.ad.Operator:
return pp.ad.Scalar(
1.0, "single_component_single_phase_extended_fraction"
1.0,
"single_component_single_phase_extended_fraction",
domains=domains,
)

# If no unified equilibrium, calling the extended fractions will raise an error.
Expand Down Expand Up @@ -901,7 +903,9 @@ def partial_fraction(

def fraction(domains: pp.SubdomainsOrBoundaries) -> pp.ad.Operator:
return pp.ad.Scalar(
1.0, f"single_partial_fraction_{component.name}_{phase.name}"
1.0,
f"single_partial_fraction_{component.name}_{phase.name}",
domains=domains,
)

# Case only 1 phase in entire mixture, partial fractions are equal to overall
Expand Down
5 changes: 4 additions & 1 deletion src/porepy/examples/flow_benchmark_2d_case_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ def fracture_permeability(self, subdomains: list[pp.Grid]) -> pp.ad.Operator:
"""
size = sum([sd.num_cells for sd in subdomains])
permeability = pp.wrap_as_dense_ad_array(
self.solid.fracture_permeability, size, name="fracture permeability"
self.solid.fracture_permeability,
size=size,
name="fracture permeability",
grids=subdomains,
)
return self.isotropic_second_order_tensor(subdomains, permeability)

Expand Down
10 changes: 6 additions & 4 deletions src/porepy/examples/flow_benchmark_2d_case_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def fracture_permeability(self, subdomains: list[pp.Grid]) -> pp.ad.Operator:

"""
if len(subdomains) == 0:
return pp.wrap_as_dense_ad_array(1, size=0)
return pp.wrap_as_dense_ad_array(1, size=0, grids=[])
permeabilities = []
for sd in subdomains:
permeabilities.append(
Expand All @@ -91,7 +91,9 @@ def fracture_permeability(self, subdomains: list[pp.Grid]) -> pp.ad.Operator:
"m^2",
)
)
permeability = pp.wrap_as_dense_ad_array(np.concatenate(permeabilities))
permeability = pp.wrap_as_dense_ad_array(
np.concatenate(permeabilities), grids=subdomains
)
return self.isotropic_second_order_tensor(subdomains, permeability)

def normal_permeability(self, interfaces: list[pp.MortarGrid]) -> pp.ad.Operator:
Expand All @@ -105,7 +107,7 @@ def normal_permeability(self, interfaces: list[pp.MortarGrid]) -> pp.ad.Operator

"""
if len(interfaces) == 0:
return pp.wrap_as_dense_ad_array(1, size=0)
return pp.wrap_as_dense_ad_array(1, size=0, grids=[])
permeabilities = []
for intf in interfaces:
# Get hold of the fracture subdomain.
Expand Down Expand Up @@ -133,7 +135,7 @@ def normal_permeability(self, interfaces: list[pp.MortarGrid]) -> pp.ad.Operator
self.units.convert_units(val * np.ones(intf.num_cells), "m^2")
)
return pp.wrap_as_dense_ad_array(
np.hstack(permeabilities), name="normal_permeability"
np.hstack(permeabilities), name="normal_permeability", grids=interfaces
)


Expand Down
5 changes: 4 additions & 1 deletion src/porepy/examples/flow_benchmark_2d_case_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ def fracture_permeability(self, subdomains: list[pp.Grid]) -> pp.ad.Operator:
"""
size = sum([sd.num_cells for sd in subdomains])
permeability = pp.wrap_as_dense_ad_array(
self.solid.fracture_permeability, size, name="fracture permeability"
self.solid.fracture_permeability,
size=size,
name="fracture permeability",
grids=subdomains,
)
return self.isotropic_second_order_tensor(subdomains, permeability)

Expand Down
7 changes: 5 additions & 2 deletions src/porepy/examples/flow_benchmark_3d_case_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def matrix_permeability(self, subdomains: list[pp.Grid]) -> pp.ad.Operator:
vals.append(kxx) # This is just a placeholder, it will not be used.

if len(subdomains) > 0:
permeability = pp.wrap_as_dense_ad_array(np.hstack(vals))
permeability = pp.wrap_as_dense_ad_array(np.hstack(vals), grids=subdomains)
else:
# This part is need it only to set up the model, not actually used.
permeability = self.solid.permeability # type:ignore
Expand All @@ -142,7 +142,10 @@ def intersection_permeability(self, subdomains: list[pp.Grid]) -> pp.ad.Operator
# Use `fracture_permeability` as intersection permeability under the assumption
# that they are equal. This is valid in the current benchmark case.
permeability = pp.wrap_as_dense_ad_array(
self.solid.fracture_permeability, size, name="intersection_permeability"
self.solid.fracture_permeability,
size=size,
name="intersection_permeability",
grids=subdomains,
)
return self.isotropic_second_order_tensor(subdomains, permeability)

Expand Down
5 changes: 4 additions & 1 deletion src/porepy/examples/flow_benchmark_3d_case_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ def intersection_permeability(self, subdomains: list[pp.Grid]) -> pp.ad.Operator
# Use `fracture_permeability` as intersection permeability under the assumption
# that they are equal. This is valid in the current benchmark case.
permeability = pp.wrap_as_dense_ad_array(
self.solid.fracture_permeability, size, name="intersection permeability"
self.solid.fracture_permeability,
size=size,
name="intersection permeability",
grids=subdomains,
)
return self.isotropic_second_order_tensor(subdomains, permeability)

Expand Down
20 changes: 9 additions & 11 deletions src/porepy/models/abstract_equations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
from __future__ import annotations

from functools import cached_property
from typing import Callable, Optional, Sequence, Union, cast
from typing import Callable, Mapping, Optional, Sequence, Union, cast

import numpy as np

import porepy as pp
from porepy.numerics.ad.equation_system import GridEntity
from porepy.numerics.ad.equation_system import GridEntities, GridEntity


class EquationMixin(pp.PorePyModel):
Expand Down Expand Up @@ -231,7 +231,9 @@ def eliminate_locally(
dependencies: Sequence[Callable[[pp.GridLikeSequence], pp.ad.Variable]],
func: Callable[..., tuple[np.ndarray, np.ndarray]],
domains: Sequence[pp.Grid | pp.MortarGrid | pp.BoundaryGrid],
equations_per_grid_entity: Optional[dict[GridEntity, int]] = None,
equations_per_grid_entity: Optional[
Union[GridEntities, Mapping[GridEntity, int]]
] = None,
) -> None:
"""Method to add a secondary equation eliminating a variable by some
constitutive law depending on *other* variables.
Expand Down Expand Up @@ -279,12 +281,12 @@ def eliminate_locally(
equations_per_grid_entity: ``default=None``.

Argument for when adding above equation to the equation system and
creating a surrogate factory. If None, the default ``{'cells':1}`` is
assigned.
creating a surrogate factory. If None, the default
``GridEntities(cells=1)`` is assigned.

"""
if equations_per_grid_entity is None:
equations_per_grid_entity = {"cells": 1}
equations_per_grid_entity = GridEntities(cells=1)

# Separate these two because Boundary values for independent quantities are
# stored differently.
Expand All @@ -310,11 +312,7 @@ def eliminate_locally(
equ_name = f"elimination_of_{sec_var.name}_on_grids_{g_ids}"
local_equ = sec_var - sec_expr(non_boundaries)
local_equ.set_name(equ_name)
self.equation_system.set_equation(
Comment thread
Yuriyzabegaev marked this conversation as resolved.
local_equ,
cast(list[pp.Grid] | list[pp.MortarGrid], non_boundaries),
equations_per_grid_entity,
)
self.equation_system.set_equation(local_equ)

self._add_local_elimination(
equ_name, sec_var, sec_expr, func, cast(pp.GridLikeSequence, domains)
Expand Down
24 changes: 19 additions & 5 deletions src/porepy/models/boundary_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def update_boundary_condition(
pp.set_solution_values(name=name, values=vals, data=data, iterate_index=0)

def create_boundary_operator(
self, name: str, domains: Sequence[pp.BoundaryGrid]
self, name: str, domains: Sequence[pp.BoundaryGrid], dim: int = 1
) -> pp.ad.TimeDependentDenseArray:
"""Creates an operator on boundary grids.

Expand All @@ -155,7 +155,12 @@ def create_boundary_operator(
"""
if not all(isinstance(x, pp.BoundaryGrid) for x in domains):
raise ValueError("Domains must consist entirely of the boundary grids.")
return pp.ad.TimeDependentDenseArray(name=name, domains=domains)
return pp.ad.TimeDependentDenseArray(
name=name,
domains=domains,
dof_info={pp.ad.GridEntity.cells: dim},
domain_type=pp.ad.DomainType.boundary_grids,
)

def _combine_boundary_operators(
self,
Expand Down Expand Up @@ -194,10 +199,16 @@ def _combine_boundary_operators(
}
filters = {
"dirichlet": pp.ad.TimeDependentDenseArray(
name=(name + "_filter_dir"), domains=boundary_grids
name=(name + "_filter_dir"),
domains=boundary_grids,
dof_info={pp.ad.GridEntity.cells: dim},
domain_type=pp.ad.DomainType.boundary_grids,
),
"neumann": pp.ad.TimeDependentDenseArray(
name=(name + "_filter_neu"), domains=boundary_grids
name=(name + "_filter_neu"),
domains=boundary_grids,
dof_info={pp.ad.GridEntity.cells: dim},
domain_type=pp.ad.DomainType.boundary_grids,
),
}

Expand All @@ -206,7 +217,10 @@ def _combine_boundary_operators(
if robin_operator is not None:
operators["robin"] = robin_operator(boundary_grids)
filters["robin"] = pp.ad.TimeDependentDenseArray(
name=(name + "_filter_rob"), domains=boundary_grids
name=(name + "_filter_rob"),
domains=boundary_grids,
dof_info={pp.ad.GridEntity.cells: dim},
domain_type=pp.ad.DomainType.boundary_grids,
)

# Adding bc_type function to local storage to evaluate it before every time step
Expand Down
2 changes: 1 addition & 1 deletion src/porepy/models/compositional_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def set_equations(self) -> None:
for component in self.fluid.components:
if self.has_independent_fraction(component):
sd_eq = self.component_mass_balance_equation(component, subdomains)
self.equation_system.set_equation(sd_eq, subdomains, {"cells": 1})
self.equation_system.set_equation(sd_eq)

def component_mass_balance_equation(
self, component: pp.Component, subdomains: list[pp.Grid]
Expand Down
Loading
Loading