-
Notifications
You must be signed in to change notification settings - Fork 8
Fix geographic mesh units: ellipsoid quantities, checkpoint, Darcy sign #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -355,6 +355,26 @@ def __init__( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except KeyError: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| regions = None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| json_str = f["metadata"].attrs["regions"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rgn_dict = json.loads(json_str) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| regions = Enum("Regions", rgn_dict) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except KeyError: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+358
to
+365
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| regions = None | |
| try: | |
| json_str = f["metadata"].attrs["regions"] | |
| rgn_dict = json.loads(json_str) | |
| regions = Enum("Regions", rgn_dict) | |
| except KeyError: | |
| pass |
Copilot
AI
Apr 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ellipsoid serialization/deserialization is new checkpoint behavior for geographic meshes (including quantity handling). Please add a checkpoint round-trip test that: creates a GEOGRAPHIC mesh with units active, writes it, reloads it, and asserts the restored ellipsoid values/units and coordinate conversions (geo↔cartesian) are consistent. This will protect the HDF5 metadata schema and the quantity reconstruction logic from future breakage.
| # Save ellipsoid metadata for geographic meshes | |
| if hasattr(self.CoordinateSystem, "ellipsoid"): | |
| ellipsoid_ser = {} | |
| for k, v in self.CoordinateSystem.ellipsoid.items(): | |
| if hasattr(v, "to"): # uw.quantity | |
| ellipsoid_ser[k] = { | |
| "value": float(v.magnitude), | |
| "unit": str(v.units), | |
| } | |
| else: | |
| ellipsoid_ser[k] = v | |
| def _serialise_checkpoint_metadata_value(value): | |
| if ( | |
| hasattr(value, "magnitude") | |
| and hasattr(value, "units") | |
| and hasattr(value, "to") | |
| ): | |
| magnitude = value.magnitude | |
| if isinstance(magnitude, numpy.ndarray): | |
| magnitude = magnitude.tolist() | |
| elif isinstance(magnitude, numpy.generic): | |
| magnitude = magnitude.item() | |
| return { | |
| "__uw_quantity__": True, | |
| "value": magnitude, | |
| "unit": str(value.units), | |
| } | |
| if isinstance(value, dict): | |
| return { | |
| key: _serialise_checkpoint_metadata_value(val) | |
| for key, val in value.items() | |
| } | |
| if isinstance(value, (list, tuple)): | |
| return [ | |
| _serialise_checkpoint_metadata_value(val) for val in value | |
| ] | |
| if isinstance(value, numpy.ndarray): | |
| return value.tolist() | |
| if isinstance(value, numpy.generic): | |
| return value.item() | |
| return value | |
| # Save ellipsoid metadata for geographic meshes | |
| if hasattr(self.CoordinateSystem, "ellipsoid"): | |
| ellipsoid_ser = { | |
| k: _serialise_checkpoint_metadata_value(v) | |
| for k, v in self.CoordinateSystem.ellipsoid.items() | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -537,11 +537,11 @@ def solve( | |
|
|
||
| super().solve(zero_init_guess, _force_setup) | ||
|
|
||
| # Now solve flow field | ||
| # Now solve flow field: v = -flux = -K(grad(h) - s) | ||
|
|
||
| # self._v_projector.petsc_options["snes_rtol"] = 1.0e-6 | ||
| # self._v_projector.petsc_options.delValue("ksp_monitor") | ||
| self._v_projector.uw_function = self.darcy_flux | ||
| self._v_projector.uw_function = -self.darcy_flux | ||
| self._v_projector.solve(zero_init_guess) | ||
|
Comment on lines
+540
to
545
|
||
|
|
||
| return | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GeographicCoordinateAccessor.depth still dimensionalises nondimensional depth using
self.cs.ellipsoid.get('L_ref_km', 1000), but RegionalGeographicBox no longer storesL_ref_km(ora_nd/b_nd). This will silently default to 1000 km and return incorrect dimensional depths when units are active. Consider deriving the length scale from the mesh/model (e.g., mesh.length_scale converted to km, or model.get_scale_for_dimensionality('[length]')) instead of relying on an ellipsoid dict field, or reintroduce a reliably-populated reference length entry during mesh creation/checkpoint restore.