def __init__(self, config): self._fm = FunctionManagerINI(config) self._setup_mesh(self._fm.getpath('fem', 'mesh')[:-5]) self._load_config(self._fm.getpath('fem', 'config')) self.global_preprocessing_time = fc.Stopwatch() self.local_preprocessing_time = fc.Stopwatch() self.solving_time = fc.Stopwatch() self._set_degree(self.degree)
def sample(self, r, potential, fem=None): if fem is None: fem = self._fem self._anything_new = True try: idx_r = np.where(np.isclose(self.R, r))[0][0] except IndexError: print(self.R) print(r) print(self.R - r) raise sampling_time = np.nan if potential is not None: logging.info('Sampling 3D') hits = 0 exceptions = 0 misses = 0 r2 = self.scalp_radius**2 XZ = np.array(list(self._xz)) sample_stopwatch = fc.Stopwatch() with sample_stopwatch: for idx_xz, (x, z) in enumerate(XZ): r_xz_2 = x**2 + z**2 if r_xz_2 > r2: misses += len(self.Y_SAMPLE) continue for idx_y, y in enumerate(self.Y_SAMPLE): if r_xz_2 + y**2 > r2: misses += 1 continue try: v = potential(x, y, z) except Exception as e: if x < 0 or z < 0 or abs( y ) > self.scalp_radius or x > self.scalp_radius or z > self.scalp_radius: logger.warning('coords out of bounding box') exceptions += 1 else: hits += 1 self.POTENTIAL[idx_r, idx_xz, idx_y] = v sampling_time = float(sample_stopwatch) logger.info('H={} ({:.2f}),\tM={} ({:.2f}),\tE={} ({:.2f})'.format( hits, hits / float(hits + misses + exceptions), misses, misses / float(hits + misses + exceptions), exceptions, exceptions / float(hits + exceptions))) self.STATS.append( (r, sampling_time, fem.iterations, float(fem.solving_time), float(fem.local_preprocessing_time), float(fem.global_preprocessing_time))) self.COMPLETED[idx_r] = True return 0 if np.isnan(sampling_time) else sampling_time
def sample(self, r, potential, fem=None): if fem is None: fem = self._fem self._anything_new = True try: idx_r = np.where(np.isclose(self.R, r))[0][0] except IndexError: print(self.R) print(r) print(self.R - r) raise sampling_time = np.nan if potential is not None: logging.info('Sampling 2D') angle = fem.FRACTION_OF_SPACE * np.pi SIN_COS = np.array([np.sin(angle), np.cos(angle)]) r2 = self.scalp_radius**2 sample_stopwatch = fc.Stopwatch() with sample_stopwatch: for idx_xz, xz in enumerate(self.X_SAMPLE): x, z = SIN_COS * xz xz2 = xz**2 for idx_y, y in enumerate(self.Y_SAMPLE): if xz2 + y**2 > r2: continue try: v = potential(x, y, z) except Exception as e: pass else: self.POTENTIAL[idx_r, idx_xz, idx_y] = v sampling_time = float(sample_stopwatch) self.STATS.append( (r, sampling_time, fem.iterations, float(fem.solving_time), float(fem.local_preprocessing_time), float(fem.global_preprocessing_time))) self.COMPLETED[idx_r] = True return 0 if np.isnan(sampling_time) else sampling_time
'k': k, 'slice_thickness': controller.slice_thickness, 'slice_radius': controller.slice_radius, 'slice_conductivity': controller.slice_conductivity, 'saline_conductivity': controller.saline_conductivity, 'degree': degree, 'STATS': stats, 'sampling_frequency': controller.sampling_frequency, } POTENTIAL = controller.POTENTIAL results['POTENTIAL'] = POTENTIAL AS = controller.A results['A'] = AS save_stopwatch = fc.Stopwatch() anything_new = False with fc.Stopwatch() as unsaved_time: for idx_y, src_y in enumerate(X): for idx_x, src_x in enumerate(X): for idx_z, src_z in enumerate(X[:idx_x + 1]): logger.info( 'Gaussian SD={}, x={}, y={}, z={} ({}, deg={})' .format(sd, src_x, src_y, src_z, mesh_name, degree)) idx_xz = idx_x * (idx_x + 1) // 2 + idx_z if not np.isnan(AS[idx_y, idx_xz]): logger.info('Already found, skipping') continue