示例#1
0
# Get solution, forces, BCs

if problem == 'easy':
    solution_func = lambda x, y: -np.cos(x) * np.exp(np.sin(x)) * np.sin(y)
    force_func = lambda x, y: (2.0 * np.cos(x) + 3.0 * np.cos(x) * np.sin(x) -
                               np.cos(x)**3) * np.exp(np.sin(x)) * np.sin(y)
else:
    k = 10 * np.pi / 3
    solution_func = lambda x, y: np.exp(np.sin(k * x)) * np.sin(k * y)
    force_func = lambda x, y: k**2 * np.exp(np.sin(k * x)) * np.sin(k * y) * (
        np.cos(k * x)**2 - np.sin(k * x) - 1.0)

bc = solution_func(ebdy.bdy.x, ebdy.bdy.y)

f = EmbeddedFunction(ebdyc)
f.define_via_function(force_func)
ua = EmbeddedFunction(ebdyc)
ua.define_via_function(solution_func)
bc = BoundaryFunction(ebdyc)
bc.define_via_function(solution_func)

################################################################################
# Setup Poisson Solver

# generate inhomogeneous solver and solve that problem
solver = PoissonSolver(ebdyc, solver_type=solver_type)
ue = solver(f, tol=solver_tol, verbose=verbose, maxiter=100, restart=20)

# this isn't correct yet because we haven't applied boundary conditions
A = Laplace_Layer_Singular_Form(bdy, ifdipole=True) - 0.5 * np.eye(bdy.N)
bv = solver.get_boundary_values(ue)
示例#2
0
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)