def start(self): """ any code in the start function runs before MCS=0 """ # Generate plots for graphical reporting self.plot_win1 = self.add_new_plot_window( title='Total medium concentration', x_axis_title='Monte Carlo Step', y_axis_title='Total medium concentration', x_scale_type='linear', y_scale_type='linear', grid=True, config_options={'legend': True}) self.plot_win1.add_plot("ConcPTPMed", style='Dots', color='red', size=5) self.plot_win1.add_plot("ConcManMed", style='Dots', color='green', size=5) self.plot_win1.add_plot("ConcMan", style='Dots', color='blue', size=5) # Create plot window for Cell 1 volume and surface self.plot_win2 = self.add_new_plot_window( title='Total medium concentration errors', x_axis_title='Monte Carlo Step', y_axis_title='Errors', x_scale_type='linear', y_scale_type='linear', grid=True, config_options={'legend': True}) self.plot_win2.add_plot("ErrorConcPTPMed", style='Dots', color='red', size=5) self.plot_win2.add_plot("ErrorConcManMod", style='Dots', color='green', size=5) # Set all values to zero in cells f = CompuCell.getConcentrationField(self.simulator, "F1") for x, y, z in self.every_pixel(): if self.cell_field[x, y, z]: f[x, y, z] = 0.0
def start(self): self.yes_fluc_comp = CompuCell.getConcentrationField( self.simulator, "YesFlucComp") self.no_fluc_comp = CompuCell.getConcentrationField( self.simulator, "NoFlucComp")
def start(self): # initial condition for diffusion field field = CompuCell.getConcentrationField(self.simulator, "FGF") field[26:28, 26:28, 0:5] = 2000.0
def start(self): """ Loads specifications described in subclasses' start() :return: None """ # Check specified sample pixels if self.sample_set_pixels is not None: if not self.sample_set_pixels: self.sample_set_pixels = None for i in range(len(self.sample_set_pixels)): if isinstance(self.sample_set_pixels[i], CompuCell.Point3D): self.sample_set_pixels[i] = [self.sample_set_pixels[i].x, self.sample_set_pixels[i].y, self.sample_set_pixels[i].z] self.sample_set_pixels = [pixel for pixel in self.sample_set_pixels if (0 <= pixel[0] <= self.dim.x and 0 <= pixel[1] <= self.dim.y and 0 <= pixel[2] <= self.dim.z)] # Generate analytic solution if requested if self.analytic_setup is not None: self.analytic_sol = self.field.analytic_sol self.__lambda_generator() if self.analytic_setup != 'manual': for x, y, z in self.every_pixel(): self.analytic_sol[x, y, z] = self.analytic_lambda(x, y, z, 0) # Get solver fields and error fields if requested for field_name in self.fields_list_names: this_field = CompuCell.getConcentrationField(self.simulator, field_name) self.fields_list.append(this_field) self.fields_dict[this_field] = field_name if self.error_contours: self.error_fields_dict[this_field] = getattr(self.field, self.error_fields_names_dict[field_name]) self.max_error_dict[this_field] = 0.0 color_list = ['red', 'green', 'blue', 'black'] # Setup for comparing solver results if requested if self.compare_solvers: for field_s in self.fields_list: self.max_diff_dict[field_s] = {} for field_t in [this_field for this_field in self.fields_list if this_field is not field_s]: self.max_diff_dict[field_s][field_t] = 0.0 if self.analytic_setup is not None: self.max_diff_dict[field_s][self.analytic_sol] = 0.0 # For plotting differences at a particular step self.plot_win_comp = self.add_new_plot_window( title='Solver differences', x_axis_title='Solver label', y_axis_title='Max. relative difference', x_scale_type='Linear', y_scale_type='Linear', grid=True, config_options={'legend': True} ) # For plotting history of solver differences self.plot_win_comp_hist = self.add_new_plot_window( title='Solver differences history', x_axis_title='Step', y_axis_title='Max. relative difference', x_scale_type='Linear', y_scale_type='log', grid=True, config_options={'legend': True} ) idx = 0 for field, field_name in self.fields_dict.items(): self.plot_win_comp.add_plot(plot_name=field_name, style='Steps', color=color_list[idx], alpha=50) self.max_diff_legend_str[field] = {} for field_t, field_name_t in self.fields_dict.items(): if field is not field_t: field_comp_str = field_name + ' - ' + field_name_t self.max_diff_legend_str[field][field_t] = field_comp_str self.plot_win_comp_hist.add_plot(plot_name=field_comp_str, style='Dots') if self.analytic_setup is not None: field_comp_str = field_name + ' - analytic' self.max_diff_legend_str[field][self.analytic_sol] = field_comp_str self.plot_win_comp_hist.add_plot(plot_name=field_comp_str, style='Dots') idx += 1 # Prep for post-processing of sample set if requested if self.sample_set_pixels is not None: self.sample_set_values = {k: [] for k in self.fields_list} self.plot_win_sol = self.add_new_plot_window( title='Solution sample set', x_axis_title='Sample point number', y_axis_title='Sample value', x_scale_type='Linear', y_scale_type='Linear', grid=True, config_options={'legend': True} ) idx = 0 for field_name in self.fields_dict.values(): self.plot_win_sol.add_plot(field_name, style='Dots', color=color_list[idx]) idx += 1 if self.analytic_setup is not None: self.plot_win_sol.add_plot("analytic_sol", style='Dots', color=color_list[idx]) self.plot_win_err = self.add_new_plot_window( title='Solution sample set error', x_axis_title='Sample point number', y_axis_title='Sample value error', x_scale_type='Linear', y_scale_type='Linear', grid=True, config_options={'legend': True} ) self.plot_win_err.pW.setXRange(0, len(self.sample_set_pixels) - 1) self.plot_win_err.pW.setYRange(-1, 1) idx = 0 for field_name in self.fields_dict.values(): idx += 1 self.plot_win_err.add_plot(field_name, style='Dots', color=color_list[idx])
def step(self, mcs): """ type here the code that will run every frequency MCS :param mcs: current Monte Carlo step """ if self.pixel_tracker_plugin is None: return f = CompuCell.getConcentrationField(self.simulator, "F1") # Test modification of field values outside of core routines mcs_change_value = 1e3 if mcs == mcs_change_value: id_of_cell_to_change = 1 val_after_change = 1.0 for ptd in self.get_cell_pixel_list( self.fetch_cell_by_id(id_of_cell_to_change)): self.total_bias += val_after_change - f[ptd.pixel.x, ptd.pixel.y, 0] f[ptd.pixel.x, ptd.pixel.y, 0] = val_after_change # Without this call, modifications (other than by core routines) to a field with a solver using # FluctuationCompensator will likely cause numerical errors CompuCell.updateFluctuationCompensators() # Do testing mcs_min_test = 0 if mcs >= mcs_min_test: # For all periodic boundary conditions and any initial distribution, changes in these values # over simulation time should only be due to the accumulation of rounding errors in the # FluctuationCompensator algorithm total_ptp_medium = 0.0 total_man_medium = 0.0 total_man = 0.0 for ptd in self.pixel_tracker_plugin.getMediumPixelSet(): total_ptp_medium += f[ptd.pixel.x, ptd.pixel.y, ptd.pixel.z] for x, y, z in self.every_pixel(): this_f = f[x, y, z] total_man += this_f if not self.cell_field[x, y, z]: total_man_medium += this_f self.plot_win1.add_data_point('ConcPTPMed', mcs, total_ptp_medium) self.plot_win1.add_data_point('ConcManMed', mcs, total_man_medium) self.plot_win1.add_data_point('ConcMan', mcs, total_man) # This compares the total concentration counted by looping over the lattice (the old way) to the total # concentration counted from medium pixel sites returned by pixel tracker (a new feature). # Pixel tracker should be able to keep track of medium sites for single- and multi-threaded simulations # so that looping over the entire lattice is no longer necessary. # If pixel tracker isn't properly tracking medium sites, then errors will be non-zero here err = 0.0 if total_man_medium != 0: err = total_ptp_medium / total_man_medium - 1.0 self.plot_win2.add_data_point('ErrorConcPTPMed', mcs, err) if self.total_man_ini is None: self.total_man_ini = total_man # This compares the current total concentration to the initial total concentration. FluctuationCompensator # should be able to keep these values the same (neglecting machine errors) for domains with all periodic # boundary conditions, even when field values are modified outside of core routines (Metropolis and solver). # For FluctuationCompensator to account for modifications to any field outside of core routines, call # updateFluctuationCompensators after all modifications for a step have been made. # If a field is modified outside of core routines and updateFluctuationCompensators is not called, # then errors generated by FluctuationCompensator can be detected here # To test this functionality, make changes to field values, add all differences in field values due to # the changes to self.total_bias and see what happens when updateFluctuationCompensators is/isn't called err = 0.0 if self.total_man_ini != 0: err = (total_man - self.total_bias) / self.total_man_ini - 1.0 self.plot_win2.add_data_point('ErrorConcManMod', mcs, err)