def __call__(self, fu, fv, **kwargs): # separate the components fuc = fu.get_smoothed_grid_value() fvc = fv.get_smoothed_grid_value() fur_list = fu.get_radial_value_list() fvr_list = fv.get_radial_value_list() uc, vc, pc = self._grid_solve(fuc, fvc) # interpolate the solution to the interface bus = self.ebdyc.interpolate_grid_to_interface( uc, order=self.interpolation_order, cutoff=False) bvs = self.ebdyc.interpolate_grid_to_interface( vc, order=self.interpolation_order, cutoff=False) # get the grid solution's derivatives ucx, ucy = self.dx(uc), self.dy(uc) vcx, vcy = self.dx(vc), self.dy(vc) # compute the grid solutions stress tcxx = 2 * ucx - pc tcxy = ucy + vcx tcyy = 2 * vcy - pc # interpolate these to the interface btxxs = self.ebdyc.interpolate_grid_to_interface( tcxx, order=self.interpolation_order, cutoff=False) btxys = self.ebdyc.interpolate_grid_to_interface( tcxy, order=self.interpolation_order, cutoff=False) btyys = self.ebdyc.interpolate_grid_to_interface( tcyy, order=self.interpolation_order, cutoff=False) # convert these from lists to vectors bul, bvl = self.ebdyc.v2l(bus), self.ebdyc.v2l(bvs) btxxl, btxyl, btyyl = self.ebdyc.v2l(btxxs), self.ebdyc.v2l( btxys), self.ebdyc.v2l(btyys) # compute the needed layer potentials sigmag_list = [] for helper, fur, fvr, bu, bv, btxx, btxy, btyy in zip( self.helpers, fur_list, fvr_list, bul, bvl, btxxl, btxyl, btyyl): sigmag_list.append( helper(fur, fvr, bu, bv, btxx, btxy, btyy, **kwargs)) # we now need to evaluate this onto the grid / interface points sigmag = np.column_stack(sigmag_list) out = self.Layer_Apply(self.grid_sources, self.ebdyc.grid_pnai, sigmag) # need to divide this apart gu, bus = self.ebdyc.divide_pnai(out[0]) gv, bvs = self.ebdyc.divide_pnai(out[1]) gp, bps = self.ebdyc.divide_pnai(out[2]) # we can now add gu directly to uc uc[self.ebdyc.phys_not_in_annulus] += gu vc[self.ebdyc.phys_not_in_annulus] += gv pc[self.ebdyc.phys_not_in_annulus] += gp # we have to send the bslps back to the indivdual ebdys to deal with them single_ebdy = len(self.ebdyc) == 1 urs, vrs, prs = zip(*[ helper.correct(bu, bv, bp, single_ebdy) for helper, bu, bv, bp in zip(self.helpers, bus, bvs, bps) ]) # interpolate urs onto uc _ = self.ebdyc.interpolate_radial_to_grid1(urs, uc) _ = self.ebdyc.interpolate_radial_to_grid1(vrs, vc) _ = self.ebdyc.interpolate_radial_to_grid1(prs, pc) uc *= self.ebdyc.phys vc *= self.ebdyc.phys pc *= self.ebdyc.phys u = EmbeddedFunction(self.ebdyc) v = EmbeddedFunction(self.ebdyc) p = EmbeddedFunction(self.ebdyc) u.load_data(uc, urs) v.load_data(vc, vrs) p.load_data(pc, prs) return u, v, p
# get heaviside function MOL = SlepianMollifier(slepian_r) # construct boundary bdy = GSB(c=star(nb, a=0.2, f=5)) bh = bdy.dt*bdy.speed.min() # construct embedded boundary ebdy = EmbeddedBoundary(bdy, True, M, bh*1, heaviside=MOL.step) ebdys = [ebdy,] ebdyc = EmbeddedBoundaryCollection([ebdy,]) # register the grid print('\nRegistering the grid') # ebdyc.register_grid(grid) ebdyc.generate_grid(bh, bh) # construct an embedded function f = EmbeddedFunction(ebdyc) f.define_via_function(lambda x, y: np.sin(x)*np.exp(y)) # try saving ebdy ebdy_dict = ebdy.save() ebdy2 = LoadEmbeddedBoundary(ebdy_dict) # try saving ebdyc ebdyc_dict = ebdyc.save() ebdyc2 = LoadEmbeddedBoundaryCollection(ebdyc_dict) # try saving f f_full_dict = f.full_save() f_dict = f.save() f2, _ = LoadEmbeddedFunction(f_dict, ebdyc2) f3, ebdyc3 = LoadEmbeddedFunction(f_full_dict)
fu = fu_function(grid.xg, grid.yg) fv = fv_function(grid.xg, grid.yg) ua = u_function(grid.xg, grid.yg) va = v_function(grid.xg, grid.yg) fu_rs = [fu_function(ebdy.radial_x, ebdy.radial_y) for ebdy in ebdys] fv_rs = [fv_function(ebdy.radial_x, ebdy.radial_y) for ebdy in ebdys] ua_rs = [u_function(ebdy.radial_x, ebdy.radial_y) for ebdy in ebdys] va_rs = [v_function(ebdy.radial_x, ebdy.radial_y) for ebdy in ebdys] pa_rs = [p_function(ebdy.radial_x, ebdy.radial_y) for ebdy in ebdys] pa_rs = [pa_r - np.mean(pa_r) for pa_r in pa_rs] upper_u = np.concatenate( [u_function(ebdy.bdy.x, ebdy.bdy.y) for ebdy in ebdys]) upper_v = np.concatenate( [v_function(ebdy.bdy.x, ebdy.bdy.y) for ebdy in ebdys]) _fu = EmbeddedFunction(ebdyc) _fu.load_data(fu, fu_rs) fu = _fu _fv = EmbeddedFunction(ebdyc) _fv.load_data(fv, fv_rs) fv = _fv # setup the solver solver = StokesSolver(ebdyc, solver_type=solver_type) uc, vc, pc = solver(fu, fv, tol=1e-12, verbose=verbose) ur = urs[0] vr = vrs[0] if plot: mue = np.ma.array(uc, mask=ebdyc.ext) fig, ax = plt.subplots()