Skip to content

Commit 27cd3cb

Browse files
authored
flesh out protocol impl (#306)
refining protocols introduced in #296 for the refactor described in #167 * renamed DimensionRegistry → DimensionResolver * renamed DimensionRegistryMixin → DimensionResolverMixin * renamed get_dimensions() → get_dims() * consolidated resolve_dimension() / get_all_dimensions() → resolve_dims() * resolve_dims() accepts multiple (or no) dim names and returns dict for consistency: * resolve_dims() → all available dimensions * resolve_dims('nlay') → {'nlay': 3} * resolve_dims('nlay', 'nrow') → {'nlay': 3, 'nrow': 10}
1 parent 0571028 commit 27cd3cb

8 files changed

Lines changed: 500 additions & 157 deletions

File tree

docs/dev/protocols-plan.md

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,25 +127,39 @@ For development/testing, provide an optional validation function:
127127
- Caching tests
128128
- All tests passing
129129

130-
### Phase 3: Not Started
131-
132-
**Integrate with _resolve_dimensions** - NOT DONE
133-
- Update _resolve_dimensions() in structure.py:
134-
- Try parent.get_all_dimensions() FIRST (new path)
135-
- Fall back to xattree's parent.data.dims (compatibility)
136-
- Keep computed dimension fallback (temporary)
137-
- All tests pass using both new and fallback paths
138-
- Tests: All existing tests pass (proving coexistence works)
139-
140-
NOTE: structure.py has been created but still uses old xattree path (parent.data.dims)
141-
142-
**Validation** - NOT DONE
143-
- Add conflict detection in get_all_dimensions()
144-
- Add optional validate_dimension_resolution() tool
130+
### Phase 3: Complete ✅
131+
132+
**Integrate with _resolve_dimensions** - DONE ✅
133+
- Updated _resolve_dimensions() in structure.py:
134+
- Uses parent.resolve_dims() (new path)
135+
- Removed xattree fallback - cleaner, simpler code
136+
- Updated resolve_dims() to include parent dimensions (walks up hierarchy)
137+
- Tests: All 207 non-integration tests pass
138+
139+
**Validation** - DONE ✅
140+
- Added conflict detection in resolve_dims()
141+
- Detects conflicts among children at same level
142+
- Allows children to override parent dimensions
143+
- Added validate_dimension_resolution() validation tool in dimensions.py
144+
145+
**Implement Disv DimensionProvider** - DONE ✅
146+
- Added get_dims() to Disv class
147+
- Returns nlay, ncpl, nvert, and computed nodes dimension
148+
- All Disv-related tests now pass
149+
150+
**API Refinements** - DONE ✅
151+
- Renamed: DimensionRegistry → DimensionResolver
152+
- Renamed: DimensionRegistryMixin → DimensionResolverMixin
153+
- Renamed: get_dimensions() → get_dims()
154+
- Unified API: resolve_dimension() + get_all_dimensions() → resolve_dims()
155+
- resolve_dims() always returns dict for consistency:
156+
- `resolve_dims()` → all available dimensions
157+
- `resolve_dims('nlay')``{'nlay': 3}`
158+
- `resolve_dims('nlay', 'nrow')``{'nlay': 3, 'nrow': 10}`
145159

146160
**ParentSettingDict** - NOT DONE
147161
- Not yet implemented
148-
- Planned for Phase 3 (parent management migration)
162+
- Deferred to Phase 4 (parent management migration)
149163

150164
### Phase 4: Future Work
151165

flopy4/mf6/component.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from xattree import xattree
1010

1111
from flopy4.mf6.constants import MF6
12-
from flopy4.mf6.dimensions import DimensionRegistryMixin
12+
from flopy4.mf6.dimensions import DimensionResolverMixin
1313
from flopy4.mf6.spec import field, fields_dict
1414
from flopy4.mf6.utils.grid import update_maxbound
1515
from flopy4.mf6.write_context import WriteContext
@@ -22,7 +22,7 @@
2222
# kw_only=True necessary so we can define optional fields here
2323
# and required fields in subclasses. attrs complains otherwise
2424
@xattree(kw_only=True)
25-
class Component(DimensionRegistryMixin, ABC, MutableMapping):
25+
class Component(DimensionResolverMixin, ABC, MutableMapping):
2626
"""
2727
Base class for MF6 components.
2828

flopy4/mf6/converter/ingress/structure.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from flopy4.adapters import get_nn
1111
from flopy4.mf6.config import SPARSE_THRESHOLD
1212
from flopy4.mf6.constants import FILL_DNODATA
13+
from flopy4.mf6.dimensions import DimensionResolver
1314

1415

1516
def structure_keyword(value, field) -> str | None:
@@ -48,7 +49,10 @@ def _resolve_dimensions(
4849

4950
# Resolve dims from model context
5051
# Priority: 1) explicit dims parameter, 2) self_.__dict__, 3) parent
51-
inherited_dims = dict(self_.parent.data.dims) if self_.parent else {}
52+
inherited_dims = {}
53+
if self_.parent and isinstance(self_.parent, DimensionResolver):
54+
inherited_dims = self_.parent.resolve_dims()
55+
5256
explicit_dims = self_.__dict__.get("dims", {})
5357
dim_dict = inherited_dims | explicit_dims
5458

0 commit comments

Comments
 (0)