Skip to content
14 changes: 14 additions & 0 deletions src/pyclaw/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ def is_valid(self):
- (bool) - True if valid, false otherwise
"""
return all([state.is_valid() for state in self.states])

def is_mapped_solution_valid(self) -> bool:

r""" Checks to see if this mapped solution is valid

The Solution checks to make sure it is valid by checking each of its states.
If the mapping and aux is missing, then False is returned.
If the capacity function index is invalid, an ValueError is raised.
If the mapping is present and the capacity array is not set an ValueError is raised.
:Output:
- (bool) - True if valid, false if nothing is set, ValueError otherwise"""

return all([state.is_mapped_state_valid() for state in self.states])



def __str__(self):
Expand Down
14 changes: 14 additions & 0 deletions src/pyclaw/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@ def is_valid(self):
logger.debug('aux array is not Fortran contiguous.')
valid = False
return valid

def is_mapped_state_valid(self) -> bool:
if self.grid.mapc2p is not None and self.aux is None:
if self.grid.mapc2p is not None and self.aux is not None:
Comment thread
NDM14 marked this conversation as resolved.
Outdated
if self.index_capa < -1 or self.index_capa >= self.num_aux:
raise ValueError("Capacity function index out of range.")
elif self.index_capa == -1:
raise ValueError("Capacity function index is not set.")
raise ValueError("Mapped grid requires capacity array to be set.")
elif self.grid.mapc2p is None and self.aux is not None:
Comment thread
NDM14 marked this conversation as resolved.
Outdated
return False
return True



def set_cparam(self,fortran_module):
"""
Expand Down