def __generateNMuscle(self): ''' Generate nMuscles connected muscle ''' nEx = 7 nEy = 4 nEz = 1 #7 for nM in range(self.nMuscles): for x in range(nEx): for y in range(nEy): for z in range(nEz): p_x = Const.xmax / 2.0 + float( x) * Const.r0 - nEx * Const.r0 / 2.0 - Const.r0 * ( nEx) / 2.0 + Const.r0 * (nEx + 0.4) * float(nM > 2) p_y = Const.ymax / 2.0 + y * Const.r0 - nEy * Const.r0 / 2.0 p_z = Const.zmax / 2.0 + z * Const.r0 - nEz * Const.r0 / 2.0 - ( nM <= 2) * (nM - 1) * (nEz * Const.r0) - float( nM > 2) * ( Const.r0 / 2 + (nM - 4) * Const.r0) * nEz - ( nM == 1) * Const.r0 / 2.5 - ( nM == 2) * Const.r0 * 2 / 2.5 + ( nM == 4) * Const.r0 / 2.5 particle = Particle(p_x, p_y, p_z, Const.elastic_particle) particle.setVelocity( Float4(0.0, 0.0, 0.0, Const.elastic_particle)) self.particles.append(particle)
def extract_particles(self, p_type, line, xml_pattern, vertex_pattern): particles = [] for xml in re.finditer(xml_pattern, line.rstrip()): for vertex in re.finditer(vertex_pattern, xml.group(2)): p_x = vertex.group(1) p_y = vertex.group(2) p_z = vertex.group(3) particle = Particle(float(p_x),float(p_y),float(p_z),float(p_type)) particle.setVelocity(Float4(0.0,0.0,0.0,float(p_type))) particles.append(particle) return particles
def import_conf(self, in_file): boundbox_sect = True particle_sect = False boundry_box = [] particles = [] with open(in_file, "r") as ins: for line in ins: if line.rstrip() == "[velocity]": particle_sect = False elif line.rstrip() == "[position]": boundbox_sect = False particle_sect = True elif boundbox_sect == True and line.rstrip() != "": boundry_box.append(float(line.rstrip())) elif particle_sect == True and line.rstrip() != "": p_x,p_y,p_z,p_t = line.rstrip().split("\t") p_type = "{0:.2g}".format(float(p_t)) particle = Particle(float(p_x),float(p_y),float(p_z),float(p_type)) particle.setVelocity(Float4(0.0,0.0,0.0,float(p_type))) particles.append(particle) return boundry_box, particles
def __generateElasticCub(self): ''' In this function we generate elastic worm ''' nx = (int)((Const.xmax - Const.xmin) / Const.r0) #X ny = (int)((Const.ymax - Const.ymin) / Const.r0) #Y nz = (int)((Const.zmax - Const.zmin) / Const.r0) #Z nEx = 9 nEy = 5 nEz = 35 for x in range(nEx): for y in range(nEy): for z in range(nEz): p_x = Const.xmax / 2 + x * Const.r0 - nEx * Const.r0 / 2 p_y = Const.ymax / 2 + y * Const.r0 - nEy * Const.r0 / 2 + Const.ymax * 3 / 8 p_z = Const.zmax / 2 + z * Const.r0 - nEz * Const.r0 / 2 particle = Particle(p_x, p_y, p_z, Const.elastic_particle) particle.setVelocity( Float4(0.0, 0.0, 0.0, Const.elastic_particle)) self.particles.append(particle)
def __generateBoundaryParticles(self): ''' Generate boundary particles: Boundary particles can locate in three different places first it can be at box corner, second at box edge and third at box face. We should take it into account when calculating a velocity for boundary particle because a velocity should have a length == 1 also vector vector of velocity should have direction ?? TODO: generate better comment ''' nx = int((Const.xmax - Const.xmin) / Const.r0) # Numbers of boundary particles on X-axis ny = int((Const.ymax - Const.ymin) / Const.r0) # Numbers of boundary particles on Y-axis nz = int((Const.zmax - Const.zmin) / Const.r0) # Numbers of boundary particles on Z-axis # 1 - top and bottom for ix in range(nx): for iy in range(ny): if ((ix == 0) or (ix == nx - 1)) or ((iy == 0) or (iy == ny - 1)): if ((ix == 0) or (ix == nx - 1)) and ((iy == 0) or (iy == ny - 1)): #corners x = ix * Const.r0 + Const.r0 / 2.0 y = iy * Const.r0 + Const.r0 / 2.0 z = 0.0 * Const.r0 + Const.r0 / 2.0 vel_x = (1.0 * float(ix == 0) - 1.0 * float(ix == nx - 1)) / math.sqrt(3.0) vel_y = (1.0 * float(iy == 0) - 1.0 * float(iy == ny - 1)) / math.sqrt(3.0) vel_z = 1.0 / math.sqrt(3.0) particle1 = Particle(x, y, z, Const.boundary_particle) particle1.setVelocity(Float4(vel_x, vel_y, vel_z)) x = ix * Const.r0 + Const.r0 / 2.0 y = iy * Const.r0 + Const.r0 / 2.0 z = (nz - 1.0) * Const.r0 + Const.r0 / 2.0 vel_x = (1.0 * float(ix == 0) - 1.0 * float(ix == nx - 1)) / math.sqrt(3.0) vel_y = (1.0 * float(iy == 0) - 1.0 * float(iy == ny - 1)) / math.sqrt(3.0) vel_z = -1.0 / math.sqrt(3.0) particle2 = Particle(x, y, z, Const.boundary_particle) particle2.setVelocity(Float4(vel_x, vel_y, vel_z)) self.particles.append(particle1) self.particles.append(particle2) else: #edges x = ix * Const.r0 + Const.r0 / 2.0 y = iy * Const.r0 + Const.r0 / 2.0 z = 0.0 * Const.r0 + Const.r0 / 2.0 vel_x = (1.0 * (float(ix == 0) - float(ix == nx - 1)) ) / math.sqrt(2.0) vel_y = (1.0 * (float(iy == 0) - float(iy == ny - 1)) ) / math.sqrt(2.0) vel_z = 1.0 / math.sqrt(2.0) particle1 = Particle(x, y, z, Const.boundary_particle) particle1.setVelocity(Float4(vel_x, vel_y, vel_z)) x = ix * Const.r0 + Const.r0 / 2.0 y = iy * Const.r0 + Const.r0 / 2.0 z = (nz - 1.0) * Const.r0 + Const.r0 / 2.0 vel_x = (1.0 * (float(ix == 0) - float(ix == nx - 1)) ) / math.sqrt(2.0) vel_y = (1.0 * (float(iy == 0) - float(iy == ny - 1)) ) / math.sqrt(2.0) vel_z = -1.0 / math.sqrt(2.0) particle2 = Particle(x, y, z, Const.boundary_particle) particle2.setVelocity(Float4(vel_x, vel_y, vel_z)) self.particles.append(particle1) self.particles.append(particle2) else: #planes x = ix * Const.r0 + Const.r0 / 2.0 y = iy * Const.r0 + Const.r0 / 2.0 z = 0.0 * Const.r0 + Const.r0 / 2.0 vel_x = 0.0 vel_y = 0.0 vel_z = 1.0 particle1 = Particle(x, y, z, Const.boundary_particle) particle1.setVelocity(Float4(vel_x, vel_y, vel_z)) x = ix * Const.r0 + Const.r0 / 2.0 y = iy * Const.r0 + Const.r0 / 2.0 z = (nz - 1.0) * Const.r0 + Const.r0 / 2.0 vel_x = 0.0 vel_y = 0.0 vel_z = -1.0 particle2 = Particle(x, y, z, Const.boundary_particle) particle2.setVelocity(Float4(vel_x, vel_y, vel_z)) self.particles.append(particle1) self.particles.append(particle2) #2 - side walls OX-OZ and opposite for ix in range(nx): for iz in range(1, nz - 1): if (ix == 0) or (ix == nx - 1): x = ix * Const.r0 + Const.r0 / 2.0 y = 0.0 * Const.r0 + Const.r0 / 2.0 z = iz * Const.r0 + Const.r0 / 2.0 vel_x = 0.0 vel_y = 1.0 / math.sqrt(2.0) vel_z = 1.0 * (float(iz == 0) - float(iz == nz - 1)) / math.sqrt(2.0) particle1 = Particle(x, y, z, Const.boundary_particle) particle1.setVelocity(Float4(vel_x, vel_y, vel_z)) x = ix * Const.r0 + Const.r0 / 2.0 y = (ny - 1) * Const.r0 + Const.r0 / 2.0 z = iz * Const.r0 + Const.r0 / 2.0 vel_x = 0.0 vel_y = -1.0 / math.sqrt(2.0) vel_z = 1.0 * (float(iz == 0) - float(iz == nz - 1)) / math.sqrt(2.0) particle2 = Particle(x, y, z, Const.boundary_particle) particle2.setVelocity(Float4(vel_x, vel_y, vel_z)) self.particles.append(particle1) self.particles.append(particle2) else: x = ix * Const.r0 + Const.r0 / 2.0 y = 0.0 * Const.r0 + Const.r0 / 2.0 z = iz * Const.r0 + Const.r0 / 2.0 vel_x = 0.0 vel_y = 1.0 vel_z = 0.0 particle1 = Particle(x, y, z, Const.boundary_particle) particle1.setVelocity(Float4(vel_x, vel_y, vel_z)) x = ix * Const.r0 + Const.r0 / 2.0 y = (ny - 1) * Const.r0 + Const.r0 / 2.0 z = iz * Const.r0 + Const.r0 / 2.0 vel_x = 0.0 vel_y = -1.0 vel_z = 0.0 particle2 = Particle(x, y, z, Const.boundary_particle) particle2.setVelocity(Float4(vel_x, vel_y, vel_z)) self.particles.append(particle1) self.particles.append(particle2) #3 - side walls OY-OZ and opposite for iy in range(1, ny - 1): for iz in range(1, nz - 1): x = 0.0 * Const.r0 + Const.r0 / 2.0 y = iy * Const.r0 + Const.r0 / 2.0 z = iz * Const.r0 + Const.r0 / 2.0 vel_x = 1.0 vel_y = 0.0 vel_z = 0.0 particle1 = Particle(x, y, z, Const.boundary_particle) particle1.setVelocity(Float4(vel_x, vel_y, vel_z)) x = (nx - 1) * Const.r0 + Const.r0 / 2.0 y = iy * Const.r0 + Const.r0 / 2.0 z = iz * Const.r0 + Const.r0 / 2.0 vel_x = -1.0 vel_y = 0.0 vel_z = 0.0 particle2 = Particle(x, y, z, Const.boundary_particle) particle2.setVelocity(Float4(vel_x, vel_y, vel_z)) self.particles.append(particle1) self.particles.append(particle2)