末尾が連番のものの処理を一気にしたいです。
python
1class DamBreak3DGeometry(object): 2 def __init__( 3 self, container_height=1.0, container_width=0.6, container_length=11.0, 4 fluid_column_height=0.50, fluid_column_width=0.6, fluid_column_length=1.60, 5 obstacle0_center_x=8.00, obstacle0_center_y=0, 6 obstacle0_r=0.05, obstacle0_height=0.8, 7 obstacle1_center_x=8.00, obstacle1_center_y=-0.06, 8 obstacle1_r=0.05, obstacle1_height=0.8, 9 nboundary_layers=5, with_obstacle0=True,with_obstacle1=True, 10 dx=0.02, hdx=1.2, rho0=1000.0): 11 12 # save the geometry detail 13 self.container_length = container_length 14 self.container_width = container_width 15 self.container_height = container_height 16 self.fluid_column_length=fluid_column_length 17 self.fluid_column_width=fluid_column_width 18 self.fluid_column_height=fluid_column_height 19 20 21 self.obstacle0_center_x = obstacle0_center_x 22 self.obstacle0_center_y = obstacle0_center_y 23 self.obstacle0_r = obstacle0_r 24 self.obstacle0_height = obstacle0_height 25 26 self.obstacle1_center_x = obstacle1_center_x 27 self.obstacle1_center_y = obstacle1_center_y 28 self.obstacle1_r = obstacle1_r 29 self.obstacle1_height = obstacle1_height 30 31 32 self.nboundary_layers=nboundary_layers 33 self.dx=dx 34 35 self.hdx = hdx 36 self.rho0 = rho0 37 self.with_obstacle0 = with_obstacle0 38 self.with_obstacle1 = with_obstacle1 39 40 def create_particles(self, **kwargs): 41 fluid_column_height=self.fluid_column_height 42 fluid_column_width=self.fluid_column_width 43 fluid_column_length=self.fluid_column_length 44 45 container_height = self.container_height 46 container_length = self.container_length 47 container_width = self.container_width 48 49 obstacle0_center_x = self.obstacle0_center_x 50 obstacle0_center_y = self.obstacle0_center_y 51 obstacle0_r = self.obstacle0_r 52 obstacle0_height = self.obstacle0_height 53 54 55 56 nboundary_layers = self.nboundary_layers 57 dx = self.dx 58 59 # get the domain limits 60 ghostlims = nboundary_layers * dx 61 62 xmin, xmax = 0.0 -ghostlims, container_length + ghostlims 63 zmin, zmax = 0.0 - ghostlims, container_height + ghostlims 64 65 cw2 = 0.5 * container_width 66 ymin, ymax = -cw2 - ghostlims, cw2 + ghostlims 67 68 # create all particles 69 eps = 0.1 * dx 70 xx, yy, zz = numpy.mgrid[xmin:xmax+eps:dx, 71 ymin:ymax+eps:dx, 72 zmin:zmax+eps:dx] 73 74 x = xx.ravel(); y = yy.ravel(); z = zz.ravel() 75 76 # create a dummy particle array from which we'll sort 77 pa = get_particle_array_wcsph(name='block', x=x, y=y, z=z) 78 79 # get the individual arrays 80 indices = [] 81 findices = [] 82 oindices = [] 83 84 85 86 obr0 = 2**obstacle0_r 87 obh0 = obstacle0_height 88 ocx0 = obstacle0_center_x 89 ocy0 = obstacle0_center_y 90 91 92 93 obr1 = 2**obstacle1_r 94 obh1 = obstacle1_height 95 ocx1 = obstacle1_center_x 96 ocy1 = obstacle1_center_y 97 98 99 for i in range(x.size): 100 xi = x[i]; yi = y[i]; zi = z[i] 101 102 # fluid 103 if ( (0 < xi <= fluid_column_length) and \ 104 (-cw2 < yi < cw2) and \ 105 (0 < zi <= fluid_column_height) ): 106 107 findices.append(i) 108 #obstacle 109 if ( (ocx0 - xi)**2 + (ocy0 - yi)**2 <= obr0 and \ 110 (0 < zi <= obh0) ): 111 112 oindices.append(i) 113 114 if ( (ocx1 - xi)**2 + (ocy1 - yi)**2 <= obr1 and \ 115 (0 < zi <= obh1) ): 116 117 oindices.append(i) 118
というコードがあり、これはまず円柱、箱、水の位置を定義しその範囲内に粒子を詰めることにより物理的影響などを計算するというものです。
この円柱を増やしたいためfor文で
python
1class DamBreak3DGeometry(object): 2 def __init__( 3 self, container_height=1.0, container_width=0.6, container_length=11.0, 4 fluid_column_height=0.50, fluid_column_width=0.6, fluid_column_length=1.60, 5 obstacle0_center_x=8.00, obstacle0_center_y=0, 6 obstacle0_r=0.05, obstacle0_height=0.8, 7 obstacle1_center_x=8.00, obstacle1_center_y=-0.06, 8 obstacle1_r=0.05, obstacle1_height=0.8, 9 nboundary_layers=5, with_obstacle0=True,with_obstacle1=True, 10 dx=0.02, hdx=1.2, rho0=1000.0): 11 12 # save the geometry detail 13 self.container_r = container_r 14 self.container_height = container_height 15 self.fluid_column_length=fluid_column_length 16 self.fluid_column_width=fluid_column_width 17 self.fluid_column_height=fluid_column_height 18 19 for k in range (1): 20 center_x = "obstacle%d_center_x"%(k) 21 self.center_x = center_x 22 center_y = "obstacle%d_center_y"%(k) 23 self.center_y = center_y 24 r = "obstacle%d_r%"(k) 25 self.r = r 26 height = "obstacle%d_height"%(k) 27 self.height = height 28 29 30 self.nboundary_layers=nboundary_layers 31 self.dx=dx 32 33 self.hdx = hdx 34 self.rho0 = rho0 35 self.with_obstacle0 = with_obstacle0 36 self.with_obstacle1 = with_obstacle1 37 38 def create_particles(self, **kwargs): 39 fluid_column_height=self.fluid_column_height 40 fluid_column_width=self.fluid_column_width 41 fluid_column_length=self.fluid_column_length 42 43 container_height = self.container_height 44 container_length = self.container_length 45 container_width = self.container_width 46 47 for k in range (1): 48 center_x = "obstacle%d_center_x"%(k) 49 center_x = self.center_x 50 center_y = "obstacle%d_center_y"%(k) 51 center_y = self.center_y 52 r = "obstacle%d_r"%(k) 53 r = self.r 54 height = "obstacle%d_height"%(k) 55 height = self.height 56 57 58 59 nboundary_layers = self.nboundary_layers 60 dx = self.dx 61 62 # get the domain limits 63 ghostlims = nboundary_layers * dx 64 65 xmin, xmax = 0.0 -ghostlims, container_length + ghostlims 66 zmin, zmax = 0.0 - ghostlims, container_height + ghostlims 67 68 cw2 = 0.5 * container_width 69 ymin, ymax = -cw2 - ghostlims, cw2 + ghostlims 70 71 # create all particles 72 eps = 0.1 * dx 73 xx, yy, zz = numpy.mgrid[xmin:xmax+eps:dx, 74 ymin:ymax+eps:dx, 75 zmin:zmax+eps:dx] 76 77 x = xx.ravel(); y = yy.ravel(); z = zz.ravel() 78 79 # create a dummy particle array from which we'll sort 80 pa = get_particle_array_wcsph(name='block', x=x, y=y, z=z) 81 82 # get the individual arrays 83 indices = [] 84 findices = [] 85 oindices = [] 86 87 88 for k in range (1): 89 obrk = "2 ** obstacle%d_r"%(k) 90 obhk = "obstacle%d_height"%(k) 91 ocxk = "obstacle%d_center_x"%(k) 92 ocyk = "obstacle%d_center_y"%(k) 93 94 95 for i in range(x.size): 96 xi = x[i]; yi = y[i]; zi = z[i] 97 98 # fluid 99 if ( (0 < xi <= fluid_column_length) and \ 100 (-cw2 < yi < cw2) and \ 101 (0 < zi <= fluid_column_height) ): 102 103 findices.append(i) 104 for k in range (1): 105 106 if ( (ocxk - xi)**2 + (ocyk - yi)**2 <= obrk and \ 107 (0 < zi <= obh) ): 108 109 oindices.append(i) 110 111 112
としてみたのですが、TypeError: unsupported operand type(s) for -: 'str' and 'str'
となってしまい実行できません。この場合最後のif文のループに問題があるのでしょうか?
コードについて修正させていただきました。
cotainarのなかにおいたobstacleに対しfluidがどのように作用するか、というプログラミングの一部抜粋です。
回答1件
あなたの回答
tips
プレビュー