|
4 | 4 | Module containing all Pyclaw solution objects |
5 | 5 | """ |
6 | 6 |
|
| 7 | +# Default mapc2p functions |
| 8 | +def identity_map_1d(x): |
| 9 | + return x, |
| 10 | + |
| 11 | +def identity_map_2d(x,y): |
| 12 | + return x,y |
| 13 | + |
| 14 | +def identity_map_3d(x,y,z): |
| 15 | + return x,y,z |
| 16 | + |
| 17 | +identity_map={'1': identity_map_1d, |
| 18 | + '2': identity_map_2d, |
| 19 | + '3': identity_map_3d} |
| 20 | + |
| 21 | + |
7 | 22 | class State(object): |
8 | 23 | r""" |
9 | 24 | A PyClaw State object contains the current state on a particular patch, |
@@ -187,16 +202,19 @@ def is_valid(self): |
187 | 202 | if not self.aux.flags['F_CONTIGUOUS']: |
188 | 203 | logger.debug('aux array is not Fortran contiguous.') |
189 | 204 | valid = False |
190 | | - if self.grid.mapc2p is not None and self.aux is None: |
191 | | - raise ValueError("Mapped grid requires a capacity function, stored in the aux array, " \ |
192 | | - "but no aux array is present. Please set state.num_aux to a positive value.") |
193 | | - elif self.grid.mapc2p is not None and self.aux is not None: |
194 | | - if self.index_capa == -1: |
195 | | - raise ValueError("Capacity function index is not set. " \ |
196 | | - "Please set state.index_capa to the appropriate index in the aux array.") |
197 | | - elif self.index_capa < 0 or self.index_capa > self.num_aux -1: |
198 | | - raise ValueError("Capacity function index out of range. " \ |
199 | | - "Please set state.index_capa to the appropriate index in the aux array.") |
| 205 | + if self.grid.mapc2p in list(identity_map.values()): |
| 206 | + pass # No mapping |
| 207 | + else: |
| 208 | + if self.aux is None: |
| 209 | + raise ValueError("Mapped grid requires a capacity function, stored in the aux array, " \ |
| 210 | + "but no aux array is present. Please set state.num_aux to a positive value.") |
| 211 | + elif self.aux is not None: |
| 212 | + if self.index_capa == -1: |
| 213 | + raise ValueError("Capacity function index is not set. " \ |
| 214 | + "Please set state.index_capa to the appropriate index in the aux array.") |
| 215 | + elif self.index_capa < 0 or self.index_capa > self.num_aux -1: |
| 216 | + raise ValueError("Capacity function index out of range. " \ |
| 217 | + "Please set state.index_capa to the appropriate index in the aux array.") |
200 | 218 | return valid |
201 | 219 |
|
202 | 220 | def set_cparam(self,fortran_module): |
|
0 commit comments