|
1 | | -from typing import List, NamedTuple, cast |
2 | | - |
3 | | -import numpy as np |
| 1 | +from typing import List, cast |
4 | 2 |
|
5 | 3 | from imod.common.interfaces.iagnosticpackage import IAgnosticPackage |
6 | 4 | from imod.common.interfaces.imodel import IModel |
7 | 5 | from imod.common.interfaces.ipackage import IPackage |
8 | 6 | from imod.common.utilities.clip import clip_by_grid |
| 7 | +from imod.common.utilities.partitioninfo import PartitionInfo |
9 | 8 | from imod.mf6.boundary_condition import BoundaryCondition |
10 | 9 | from imod.mf6.ims import Solution |
11 | 10 | from imod.mf6.model_gwf import GroundwaterFlowModel |
12 | 11 | from imod.mf6.model_gwt import GroundwaterTransportModel |
13 | 12 | from imod.mf6.ssm import SourceSinkMixing |
14 | 13 | from imod.mf6.validation_settings import ValidationSettings, trim_time_dimension |
15 | 14 | from imod.typing import GridDataArray |
16 | | -from imod.typing.grid import ( |
17 | | - get_non_spatial_dimension_names, |
18 | | - ones_like, |
19 | | -) |
20 | | - |
21 | | - |
22 | | -class PartitionInfo(NamedTuple): |
23 | | - active_domain: GridDataArray |
24 | | - id: int |
25 | | - |
26 | | - |
27 | | -def create_partition_info(submodel_labels: GridDataArray) -> List[PartitionInfo]: |
28 | | - """ |
29 | | - A PartitionInfo is used to partition a model or package. The partition |
30 | | - info's of a domain are created using a submodel_labels array. The |
31 | | - submodel_labels provided as input should have the same shape as a single |
32 | | - layer of the model grid (all layers are split the same way), and contains an |
33 | | - integer value in each cell. Each cell in the model grid will end up in the |
34 | | - submodel with the index specified by the corresponding label of that cell. |
35 | | - The labels should be numbers between 0 and the number of partitions. |
36 | | - """ |
37 | | - _validate_submodel_label_array(submodel_labels) |
38 | | - |
39 | | - unique_labels = np.unique(submodel_labels.values) |
40 | | - |
41 | | - partition_infos = [] |
42 | | - for label_id in unique_labels: |
43 | | - active_domain = submodel_labels.where(submodel_labels.values == label_id) |
44 | | - active_domain = ones_like(active_domain).where(active_domain.notnull(), 0) |
45 | | - active_domain = active_domain.astype(submodel_labels.dtype) |
46 | | - |
47 | | - submodel_partition_info = PartitionInfo( |
48 | | - id=label_id, active_domain=active_domain |
49 | | - ) |
50 | | - partition_infos.append(submodel_partition_info) |
51 | | - |
52 | | - return partition_infos |
53 | | - |
54 | | - |
55 | | -def _validate_submodel_label_array(submodel_labels: GridDataArray) -> None: |
56 | | - unique_labels = np.unique(submodel_labels.values) |
57 | | - |
58 | | - if not ( |
59 | | - len(unique_labels) == unique_labels.max() + 1 |
60 | | - and unique_labels.min() == 0 |
61 | | - and np.issubdtype(submodel_labels.dtype, np.integer) |
62 | | - ): |
63 | | - raise ValueError( |
64 | | - "The submodel_label array should be integer and contain all the numbers between 0 and the number of " |
65 | | - "partitions minus 1." |
66 | | - ) |
| 15 | +from imod.typing.grid import get_non_spatial_dimension_names |
67 | 16 |
|
68 | 17 |
|
69 | 18 | class ModelSplitter: |
|
0 commit comments