def validate(self, indent=1, verbose=False, enable_print=True, working_directory=None): """ Method to validate sub hierarchy """ if len(self) == 0: return 0 # overwrite current working directory prev_dir = settings.WORKING_DIRECTORY if working_directory: settings.set_working_directory(working_directory) error_count = 0 indent_str = ' ' * indent for name in self.keys(skip_default=True): obj = self.__dict__[name] if isinstance(obj, PFDBObj): if len(obj): if hasattr(obj, '_value_'): value = obj._value_ add_errors, validation_string = validate_helper( obj, '_value_', value, indent) if enable_print and (add_errors or verbose): print(f'{indent_str}{name}: {validation_string}') error_count += add_errors elif enable_print: if verbose or obj.validate(enable_print=False): print(f'{indent_str}{name}:') error_count += obj.validate(indent + 1, verbose=verbose, enable_print=enable_print) elif hasattr(self, '_details_') and name in self._details_: add_errors, validation_string = validate_helper( self, name, obj, indent) if enable_print and (verbose or add_errors): print(f'{indent_str}{name}: {validation_string}') error_count += add_errors elif obj is not None: if enable_print and verbose: print(f'{indent_str}{name}: {obj}') # revert working directory to original directory settings.set_working_directory(prev_dir) return error_count
#----------------------------------------------------------------------------- from parflow import Run from parflow.tools.fs import cp, mkdir, chdir, get_absolute_path from parflow.tools import settings forsyth2 = Run("forsyth2", __file__) #--------------------------------------------------------- # Copy solid file #--------------------------------------------------------- dir_name = get_absolute_path('test_output/forsyth2') mkdir(dir_name) chdir(dir_name) settings.set_working_directory() cp('$PF_SRC/test/input/fors2_hf.pfsol') #--------------------------------------------------------- forsyth2.FileVersion = 4 forsyth2.Process.Topology.P = 1 forsyth2.Process.Topology.Q = 1 forsyth2.Process.Topology.R = 1 #--------------------------------------------------------- # Computational Grid #---------------------------------------------------------