Skip to content

Commit 41f2e03

Browse files
committed
added new check if there is a mapping to distinguish right cases
1 parent 4f1e44a commit 41f2e03

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

src/pyclaw/state.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44
Module containing all Pyclaw solution objects
55
"""
66

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+
722
class State(object):
823
r"""
924
A PyClaw State object contains the current state on a particular patch,
@@ -187,16 +202,19 @@ def is_valid(self):
187202
if not self.aux.flags['F_CONTIGUOUS']:
188203
logger.debug('aux array is not Fortran contiguous.')
189204
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.")
200218
return valid
201219

202220
def set_cparam(self,fortran_module):

0 commit comments

Comments
 (0)