Repository navigation
Keep the physical dimension of mappings in Domain.export / Domain.from_file #201
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
base: master
Are you sure you want to change the base?
Changes from all commits
aed5382
1cf6298
79811e7
aeed096
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,7 +31,6 @@ | |||||||||||
| # TODO fix circular dependency between domain and mapping | ||||||||||||
| if TYPE_CHECKING: | ||||||||||||
| from sympde.topology.mapping import Mapping | ||||||||||||
| # TODO add pdim | ||||||||||||
|
|
||||||||||||
| iterable_types = (tuple, list, Tuple, Union) | ||||||||||||
|
|
||||||||||||
|
|
@@ -336,7 +335,9 @@ def get_interior(self, name): | |||||||||||
|
|
||||||||||||
| def todict(self): | ||||||||||||
| name = str(self.name) | ||||||||||||
| dim = str(self.dim) | ||||||||||||
| ldim = str(self.dim) | ||||||||||||
| mappings = [m for m in self.mappings.values() if m is not None] | ||||||||||||
| pdim = str(mappings[0].pdim) if mappings else ldim | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Suggested change
|
||||||||||||
| interior = self.interior.todict() | ||||||||||||
| boundary = self.boundary.todict() | ||||||||||||
| connectivity = self.connectivity.todict() | ||||||||||||
|
|
@@ -346,7 +347,8 @@ def todict(self): | |||||||||||
| dtype = 'None' | ||||||||||||
|
|
||||||||||||
| d = {'name': name, | ||||||||||||
| 'dim': dim, | ||||||||||||
| 'ldim': ldim, | ||||||||||||
| 'pdim': pdim, | ||||||||||||
| 'dtype': dtype, | ||||||||||||
| 'interior': interior, | ||||||||||||
| 'boundary': boundary, | ||||||||||||
|
|
@@ -404,8 +406,13 @@ def from_file(cls, filename): | |||||||||||
| h5 = h5py.File( filename, mode='r' ) | ||||||||||||
| yml = yaml.load( h5['topology.yml'][()], Loader=yaml.SafeLoader ) | ||||||||||||
|
|
||||||||||||
| if 'dim' in yml: | ||||||||||||
| raise ValueError(f"'{filename}' was written by an older version of SymPDE:" | ||||||||||||
| " replace its 'dim' key with the keys 'ldim' and 'pdim'") | ||||||||||||
|
|
||||||||||||
| domain_name = yml['name'] | ||||||||||||
| dim = int(yml['dim']) | ||||||||||||
| ldim = int(yml['ldim']) | ||||||||||||
| pdim = int(yml['pdim']) | ||||||||||||
| dtype = yml['dtype'] | ||||||||||||
| d_interior = yml['interior'] | ||||||||||||
| d_boundary = yml['boundary'] | ||||||||||||
|
|
@@ -422,7 +429,7 @@ def from_file(cls, filename): | |||||||||||
|
|
||||||||||||
| constructors = [globals()[dt['type']] for dt in dtype] | ||||||||||||
| interiors = [cs(i['name'], **dt['parameters']) for cs,i,dt in zip(constructors, d_interior, dtype)] | ||||||||||||
| mappings = [Mapping(I['mapping'], dim=dim) if I.get('mapping', "None") != "None" else None for I in d_interior] | ||||||||||||
| mappings = [Mapping(I['mapping'], ldim=ldim, pdim=pdim) if I.get('mapping', "None") != "None" else None for I in d_interior] | ||||||||||||
| domains = [mapping(i) if mapping else i for i,mapping in zip(interiors, mappings)] | ||||||||||||
| patch_index = {I.name:ind for ind,I in enumerate(interiors)} | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| import os | ||
|
|
||
| import h5py | ||
| import numpy as np | ||
| import pytest | ||
| import yaml | ||
| from sympy import preorder_traversal | ||
| from sympy.core import Basic | ||
|
|
||
|
|
@@ -113,6 +117,31 @@ def test_topology_1(): | |
|
|
||
| assert D.todict() == Omega.todict() | ||
|
|
||
| #============================================================================== | ||
| def test_export_surface_mapping(tmp_path): | ||
| domain = Mapping('F', ldim=2, pdim=3)(Square('Omega')) | ||
|
|
||
| filename = str(tmp_path / 'surface.h5') | ||
| domain.export(filename) | ||
| D = Domain.from_file(filename) | ||
|
|
||
| assert D.mapping.ldim == 2 | ||
| assert D.mapping.pdim == 3 | ||
| assert D.todict() == domain.todict() | ||
|
|
||
| #============================================================================== | ||
| def test_from_file_with_old_dim_key(tmp_path): | ||
| yml = Mapping('F', dim=2)(Square('Omega')).todict() | ||
| yml['dim'] = yml.pop('ldim') | ||
| del yml['pdim'] | ||
|
|
||
| filename = str(tmp_path / 'old.h5') | ||
| with h5py.File(filename, mode='w') as h5: | ||
| h5['topology.yml'] = np.array(yaml.dump(data=yml, sort_keys=None), dtype='S') | ||
|
|
||
| with pytest.raises(ValueError, match="older version of SymPDE"): | ||
| Domain.from_file(filename) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please see my comment to #==============================================================================
def test_export_mappings_with_different_pdim(tmp_path):
A = Mapping('FA', ldim=2, pdim=3)(Square('A'))
B = Mapping('FB', ldim=2, pdim=2)(Square('B'))
with pytest.raises(ValueError):
domain = Domain.join([A, B], [((0, 0, 1), (1, 0, -1), 1)], name='Omega')
domain.export(str(tmp_path / 'omega.h5'))Both |
||
| #============================================================================== | ||
| def test_domain_1(): | ||
| Omega_1 = InteriorDomain('Omega_1', dim=2) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
I would split this into two separate points. A new one should go under "Changed" (see my other comment to this file) and this one should become much shorter: