@@ -133,18 +133,18 @@ def u_exact(self, t):
133133 if self .init_type == 'circle' :
134134 r2 = (self .X [0 ] - 0.5 ) ** 2 + (self .X [1 ] - 0.5 ) ** 2
135135 if self .spectral :
136- tmp = 0.5 * (1.0 + np . tanh ((self .radius - np .sqrt (r2 )) / (np .sqrt (2 ) * self .eps )))
136+ tmp = 0.5 * (1.0 + self . xp . tanh ((self .radius - self . xp .sqrt (r2 )) / (np .sqrt (2 ) * self .eps )))
137137 me [:] = self .fft .forward (tmp )
138138 else :
139- me [:] = 0.5 * (1.0 + np . tanh ((self .radius - np .sqrt (r2 )) / (np .sqrt (2 ) * self .eps )))
139+ me [:] = 0.5 * (1.0 + self . xp . tanh ((self .radius - self . xp .sqrt (r2 )) / (np .sqrt (2 ) * self .eps )))
140140 elif self .init_type == 'circle_rand' :
141141 ndim = len (me .shape )
142- L = int (self .L )
142+ L = int (self .L [ 0 ] )
143143 # get random radii for circles/spheres
144- np .random .seed (1 )
144+ self . xp .random .seed (1 )
145145 lbound = 3.0 * self .eps
146146 ubound = 0.5 - self .eps
147- rand_radii = (ubound - lbound ) * np .random .random_sample (size = tuple ([L ] * ndim )) + lbound
147+ rand_radii = (ubound - lbound ) * self . xp .random .random_sample (size = tuple ([L ] * ndim )) + lbound
148148 # distribute circles/spheres
149149 tmp = newDistArray (self .fft , False )
150150 if ndim == 2 :
@@ -153,14 +153,14 @@ def u_exact(self, t):
153153 # build radius
154154 r2 = (self .X [0 ] + i - L + 0.5 ) ** 2 + (self .X [1 ] + j - L + 0.5 ) ** 2
155155 # add this blob, shifted by 1 to avoid issues with adding up negative contributions
156- tmp += np .tanh ((rand_radii [i , j ] - np .sqrt (r2 )) / (np .sqrt (2 ) * self .eps )) + 1
156+ tmp += self . xp .tanh ((rand_radii [i , j ] - np .sqrt (r2 )) / (np .sqrt (2 ) * self .eps )) + 1
157157 # normalize to [0,1]
158158 tmp *= 0.5
159- assert np .all (tmp <= 1.0 )
159+ assert self . xp .all (tmp <= 1.0 )
160160 if self .spectral :
161161 me [:] = self .fft .forward (tmp )
162162 else :
163- me [:] = tmp [:]
163+ self . xp . copyto ( me , tmp )
164164 else :
165165 raise NotImplementedError ('type of initial value not implemented, got %s' % self .init_type )
166166
@@ -219,14 +219,14 @@ def eval_f(self, u, t):
219219 tmpf = self .dtype_f (self .init , val = 0.0 )
220220
221221 # build sum over RHS without driving force
222- Rt_local = float (np .sum (self .fft .backward (f .impl ) + tmpf ))
222+ Rt_local = float (self . xp .sum (self .fft .backward (f .impl ) + tmpf ))
223223 if self .comm is not None :
224224 Rt_global = self .comm .allreduce (sendobj = Rt_local , op = MPI .SUM )
225225 else :
226226 Rt_global = Rt_local
227227
228228 # build sum over driving force term
229- Ht_local = float (np .sum (6.0 * tmp * (1.0 - tmp )))
229+ Ht_local = float (self . xp .sum (6.0 * tmp * (1.0 - tmp )))
230230 if self .comm is not None :
231231 Ht_global = self .comm .allreduce (sendobj = Ht_local , op = MPI .SUM )
232232 else :
@@ -247,14 +247,14 @@ def eval_f(self, u, t):
247247 f .expl = - 2.0 / self .eps ** 2 * u * (1.0 - u ) * (1.0 - 2.0 * u )
248248
249249 # build sum over RHS without driving force
250- Rt_local = float (np .sum (f .impl + f .expl ))
250+ Rt_local = float (self . xp .sum (f .impl + f .expl ))
251251 if self .comm is not None :
252252 Rt_global = self .comm .allreduce (sendobj = Rt_local , op = MPI .SUM )
253253 else :
254254 Rt_global = Rt_local
255255
256256 # build sum over driving force term
257- Ht_local = float (np .sum (6.0 * u * (1.0 - u )))
257+ Ht_local = float (self . xp .sum (6.0 * u * (1.0 - u )))
258258 if self .comm is not None :
259259 Ht_global = self .comm .allreduce (sendobj = Ht_local , op = MPI .SUM )
260260 else :
0 commit comments