def draw_displacement_wrapper(gf, dt, event_type, a, r0=None, sigma=None): if ((event_type == EventType.COM_ESCAPE or event_type == EventType.SINGLE_ESCAPE) and sigma == None) or ( event_type == EventType.IV_ESCAPE and sigma != None ): # Escape through this coordinate. We already know the new r. # Todo. Let gf handle this. return a elif event_type == EventType.IV_REACTION and sigma != None: # Todo. Let gf handle this. return sigma rnd = myrandom.uniform() if __debug__: log.debug(" *drawR. " + gf.__class__.__name__) try: if r0 == None: r = gf.drawR(rnd, dt) else: r = gf.drawR(rnd, r0, dt) while r > a or r <= sigma: # redraw; shouldn't happen often if __debug__: log.debug(" *drawR: redraw") rnd = myrandom.uniform() if r0 == None: r = gf.drawR(rnd, dt) else: r = gf.drawR(rnd, r0, dt) except Exception, e: raise Exception("gf.drawR() failed, " "%s, rnd = %g, r0 = %s, dt = %g, %s" % (str(e), rnd, r0, dt, gf.dump()))
def draw_displacement_wrapper(gf, dt, event_type, a, r0=None, sigma=None): if(((event_type == EventType.COM_ESCAPE or event_type == EventType.SINGLE_ESCAPE) and sigma == None) or (event_type == EventType.IV_ESCAPE and sigma != None)): # Escape through this coordinate. We already know the new r. # Todo. Let gf handle this. return a elif event_type == EventType.IV_REACTION and sigma != None: # Todo. Let gf handle this. return sigma rnd = myrandom.uniform() if __debug__: log.debug(' *drawR. ' + gf.__class__.__name__) try: if r0 == None: r = gf.drawR(rnd, dt) else: r = gf.drawR(rnd, r0, dt) while r > a or r <= sigma: # redraw; shouldn't happen often if __debug__: log.debug(' *drawR: redraw') rnd = myrandom.uniform() if r0 == None: r = gf.drawR(rnd, dt) else: r = gf.drawR(rnd, r0, dt) except Exception, e: raise Exception('gf.drawR() failed, ' '%s, rnd = %g, r0 = %s, dt = %g, %s' % (str(e), rnd, r0, dt, gf.dump()))
def random_vector(r): v = [ myrandom.uniform(-1, 1), myrandom.uniform(-1, 1), myrandom.uniform(-1, 1) ] return _gfrd.normalize(v, r)
def random_vector2D(r): # Return a random 2D cartesian vector of length r. v = [myrandom.uniform(-1,1), myrandom.uniform(-1,1)] # Todo. return _gfrd.normalize(v, r) v = numpy.array(v) norm = numpy.linalg.norm(v) return v * (r / norm)
def random_vector2D(r): # Return a random 2D cartesian vector of length r. v = [myrandom.uniform(-1, 1), myrandom.uniform(-1, 1)] # Todo. return _gfrd.normalize(v, r) v = numpy.array(v) norm = numpy.linalg.norm(v) return v * (r / norm)
def random_position(self): """Only uniform if vector_x and vector_y have same length. """ return ( self.shape.position + myrandom.uniform(-1, 1) * self.shape.unit_x * self.shape.extent[0] + myrandom.uniform(-1, 1) * self.shape.unit_y * self.shape.extent[1] )
def random_position(self): """Returns a random position equidistributed within the region in space defined by negative signed distance. See also signed_distance_to(). """ corner = self.shape.position - self.size / 2. return numpy.array([ myrandom.uniform(corner[0], self.size[0]), myrandom.uniform(corner[1], self.size[1]), myrandom.uniform(corner[2], self.size[2]) ])
def random_position(self): """Returns a random position equidistributed within the region in space defined by negative signed distance. See also signed_distance_to(). """ corner = self.shape.position - self.size / 2.0 return numpy.array( [ myrandom.uniform(corner[0], self.size[0]), myrandom.uniform(corner[1], self.size[1]), myrandom.uniform(corner[2], self.size[2]), ] )
def draw_r_wrapper(gf, dt, a, sigma=None): rnd = myrandom.uniform() if __debug__: log.debug(' *drawR. ' + gf.__class__.__name__) try: r = gf.drawR(rnd, dt) while r > a or r <= sigma: # redraw; shouldn't happen often if __debug__: log.debug(' *drawR: redraw') rnd = myrandom.uniform() r = gf.drawR(rnd, dt) except Exception, e: raise Exception('gf.drawR() failed, ' '%s, rnd = %.16g, dt = %.16g, %s' % (str(e), rnd, dt, gf.dump()))
def random_vector2D(r): # Return a random 2D cartesian vector of length r. phi = myrandom.uniform(0, Pi2) v = [math.cos(phi), math.sin(phi)] # sincos # Todo. return _gfrd.normalize(v, r) v = numpy.array(v) norm = numpy.linalg.norm(v) return v * (r / norm)
def random_vector(r): # v, s = [0.0, 0.0, 0.0], 2.0 # while s > 1.0: # v[0] = myrandom.uniform (-1, 1) # v[1] = myrandom.uniform (-1, 1) # s = v[0] * v[0] + v[1] * v[1] # v[2] = -1 + 2 * s # a = 2 * numpy.sqrt(1 - s) # v[0] *= a # v[1] *= a cos_theta = myrandom.uniform(-1, 1) sin_theta = numpy.sqrt(1 - cos_theta * cos_theta) phi = myrandom.uniform(0, Pi2) sin_phi, cos_phi = math.sin(phi), math.cos(phi) # sincos v = [sin_theta * cos_phi, sin_theta * sin_phi, cos_theta] return _gfrd.normalize(v, r)
def draw_time_wrapper(gf): rnd = myrandom.uniform() if __debug__: log.debug(' *drawTime. ' + gf.__class__.__name__) try: dt = gf.drawTime(rnd) except Exception, e: raise Exception('gf.drawTime() failed, ' '%s, rnd = %.16g, %s' % (str(e), rnd, gf.dump()))
def draw_event_type_wrapper(gf, dt): rnd = myrandom.uniform() if __debug__: log.debug(' *drawEventType. ' + gf.__class__.__name__) try: event_type = gf.drawEventType(rnd, dt) except Exception, e: raise Exception('gf.drawEventType() failed, ' '%s, rnd = %.16g, dt = %.16g, %s' % (str(e), rnd, dt, gf.dump()))
def draw_eventtype_wrapper(gf, dt, r0): rnd = myrandom.uniform() if __debug__: log.debug(" *drawEventType. " + gf.__class__.__name__) try: event_type = gf.drawEventType(rnd, r0, dt) except Exception, e: raise Exception( "gf.drawEventType() failed, " "%s, rnd = %g, r0 = %g, dt = %g, %s" % (str(e), rnd, r0, dt, gf.dump()) )
def drawTime_wrapper(gf, r0=None): rnd = myrandom.uniform() if __debug__: log.debug(" *drawTime. " + gf.__class__.__name__) try: if r0 == None: # Todo. Let gf handle this. dt = gf.drawTime(rnd) else: dt = gf.drawTime(rnd, r0) except Exception, e: raise Exception("gf.drawTime() failed, " "%s, rnd = %g, %s" % (str(e), rnd, gf.dump()))
def draw_theta_wrapper(gf, r, dt): """Draw theta for the inter-particle vector. """ rnd = myrandom.uniform() if __debug__: log.debug(' *drawTheta. ' + gf.__class__.__name__) try: theta = gf.drawTheta(rnd, r, dt) except Exception, e: raise Exception('gf.drawTheta() failed, ' '%s, rnd = %.16g, r = %.16g, dt = %.16g' % (str(e), rnd, r, dt)) #, gf.dump()))
def drawTheta_wrapper(gf, r, r0, dt): """Draw theta for the inter-particle vector. """ rnd = myrandom.uniform() if __debug__: log.debug(" *drawTheta. " + gf.__class__.__name__) try: theta = gf.drawTheta(rnd, r, r0, dt) except Exception, e: raise Exception( "gf.drawTheta() failed, " "%s, rnd = %g, r = %g, r0 = %g, dt = %g" % (str(e), rnd, r, r0, dt) ) # , gf.dump()))
def drawTime_wrapper(gf, r0=None): rnd = myrandom.uniform() if __debug__: log.debug(' *drawTime. ' + gf.__class__.__name__) try: if r0 == None: # Todo. Let gf handle this. dt = gf.drawTime(rnd) else: dt = gf.drawTime(rnd, r0) except Exception, e: raise Exception('gf.drawTime() failed, ' '%s, rnd = %g, %s' % (str(e), rnd, gf.dump()))
rr['k'] = '.01' m.network_rules.add_reaction_rule(rr) nrw = _gfrd.NetworkRulesWrapper(m.network_rules) w = _gfrd.World(1., 10) region = _gfrd._CuboidalRegion("default", _gfrd.Box((.5, .5, .5), (1., 0., 0.), (0., 1., 0.), (0., 0., 1.), 1., 1., .1)) w.add_surface(region) for s in [S0, S1, S2]: w.add_species(_gfrd.SpeciesInfo(s.id, float(s['D']), float(s['radius']), s['surface'])) for i in xrange(0, 300): w.new_particle([S0, S1][i % 2], [myrandom.uniform(), myrandom.uniform(), myrandom.uniform()]) wn = vtk.vtkRenderWindow() int = wn.MakeRenderWindowInteractor() int.Initialize() int.SetRenderWindow(wn) r = vtk.vtkRenderer() wn.AddRenderer(r) actors = {} def create_actor(pp): s = vtk.vtkSphereSource() s.SetRadius(pp[1].radius) s.SetCenter(pp[1].position) m = vtk.vtkPolyDataMapper()
def random_unit_vector_s(): s = numpy.array([1.0, myrandom.uniform(0, Pi), myrandom.uniform(0, Pi2)]) return s
def rng_uniform(): '''Returns a positive random number ''' while True: rng = myrandom.uniform(0.0, 1.0) if rng > 0.0: return rng
def random_position(self): """Only uniform if vector_x and vector_y have same length. """ return self.shape.position + myrandom.uniform(-1, 1) * self.shape.unit_x * self.shape.extent[0] + \ myrandom.uniform(-1, 1) * self.shape.unit_y * self.shape.extent[1]
w = MyParticleContainer(1.0) region = _gfrd._CuboidalRegion( "default", _gfrd.Box((.5, .5, .5), (1., 0., 0.), (0., 1., 0.), (0., 0., 1.), 1., 1., .1)) w.add_surface(region) for s in [S0, S1, S2]: w.add_species( _gfrd.SpeciesInfo(s.id, float(s['D']), float(s['radius']), s['surface'])) for i in xrange(0, 300): w.new_particle( [S0, S1][i % 2], [myrandom.uniform(), myrandom.uniform(), myrandom.uniform()]) wn = vtk.vtkRenderWindow() int = wn.MakeRenderWindowInteractor() int.Initialize() int.SetRenderWindow(wn) r = vtk.vtkRenderer() wn.AddRenderer(r) actors = {} def create_actor(pp): s = vtk.vtkSphereSource()
def random_position(self): return (self.shape.position + myrandom.uniform(-1, 1) * self.shape.unit_z * self.shape.size)
def random_position(self): return self.shape.position + myrandom.uniform(-1, 1) * self.shape.unit_z * self.shape.size
def random_vector(r): v = [myrandom.uniform(-1,1), myrandom.uniform(-1,1), myrandom.uniform(-1,1)] return _gfrd.normalize(v, r)