Пример #1
0
 def set_up_population(self, detail_level):
     grid_length = self.side_length * detail_level
     cells_file = self.get_detail_level_results(detail_level)
     # If cells_file.events is empty then the detail level directory has
     # probably only just been created, and this file does not yet exist.
     if cells_file.events == []:
         cells_file.set_space_parameters(wrapping=self.wrapping,
                             is_3d=self.is_3d, side_length=self.side_length)
         bio_array_path = os.path.join(self.detail_level_dir, 'bio_array')
         self.bio_array = numpy.ones((grid_length,)*2, dtype=numpy.int)
         last_path = os.path.join(self.root_dir, 'lastIter',
                                                  'event_location_last.xml')
         last_file = SimulationResultsFile(path=last_path, read_only=True)
         cells_file.copy_event_list(last_file)
         cells_file.set_up_population(detail_level, grid_length,
                                             self.wrapping, self.bio_array)
         toolbox_basic.save_array(self.bio_array, bio_array_path)
         self.make_mesh_files(self.bio_array, detail_level)
         # Finally, update and save the 'cell_locations.xml' file.
         head = 'mark,x,i_min,i_max,y,j_min,j_max'
         if self.is_3d: head += ',z,k_min,k_max'
         cells_file.set_event_list_header(head)
         cells_file.write()
     else:
         cells_file.setup_ranges(grid_length, self.wrapping)
     return cells_file
Пример #2
0
 def get_concn_array(self, detail_level, sif_name):
     self.get_run_dir(detail_level, sif_name)
     grid_length = detail_level * self.side_length
     array_path = os.path.join(self.run_dir, 'concn_array')
     if os.path.isfile(array_path):
         concn_array = toolbox_basic.load_array(array_path)
     else:
         result_file_path = os.path.join(self.run_dir, 'case.result')
         result_file_path = toolbox_basic.check_path(result_file_path)
         # This isn't quite correct! Without wrapping, Elmer skips some nodes
         num_nodes = (grid_length + 1)**2
         array_shape = (grid_length + 1,)*2
         with open(result_file_path, 'Ur') as f:
             last_lines = f.readlines()[-num_nodes:]
         concn_array = numpy.array([float(line) for line in last_lines])
         concn_array = numpy.reshape(concn_array, array_shape)
         toolbox_basic.save_array(concn_array, array_path)
     return concn_array
Пример #3
0
 def get_run_results(self, detail_level, sif_name, read_only=False):
     self.get_run_dir(detail_level, sif_name)
     rates_path = os.path.join(self.run_dir, 'cell_rates.xml')
     rates_file = SimulationResultsFile(path=rates_path, read_only=read_only)
     if rates_file.events == []:
         grid_length = self.side_length * detail_level
         rates_file = self.get_detail_level_results(detail_level)
         rates_file.path = rates_path
         rates_file.setup_ranges(grid_length, self.wrapping)
         rate_array = numpy.zeros((grid_length,)*2, dtype=numpy.float)
         concn_array = self.get_concn_array(detail_level, sif_name)
         consume_rate, produce_rate = \
                 self.get_consume_produce_functions(detail_level, sif_name)
         rates_file.calc_rates_from_concn_array(concn_array, consume_rate,
                                         produce_rate, rate_array=rate_array)
         array_path = os.path.join(self.run_dir, 'rate_array')
         toolbox_basic.save_array(rate_array, array_path)
         head = 'mark,x,y'
         if self.is_3d: head += ',z'
         head += ',rate,amean_surf_concn'
         rates_file.set_event_list_header(head)
         rates_file.set_concn_rate_results(concn_array, rate_array)
         rates_file.write()
     return rates_file