def jump_condition(x,y,u):
     u_desired = desired_func(x,y)
     u_n_desired = hf.norm_grad(u_desired,(x,y),lvl_func)
     #for Robin boundary condition only
     def sigma(x,y):
         return -0.25 * (hf.XYtoR(x-x0, y-y0)+10**-17)
     
     sigma_Robin = sigma(x, y)
     g_Robin = u_desired + sigma_Robin * u_n_desired
     #################################
     
     if(bnd_type == "Dirichlet"):
         a_mesh = - u_desired
         b_mesh = - beta_m * hf.grad_frame(u,(x,y),lvl_func)
         
     elif(bnd_type == "Neumann"):
         a_mesh = - u
         b_mesh = - beta_m * u_n_desired
     
     elif(bnd_type == "Robin_u"):
         a_mesh = - u
         b_mesh = - beta_m * (g_Robin - u)/sigma_Robin
         
     elif(bnd_type == "Robin_u_n"):
         a_mesh = -(g_Robin - sigma_Robin*u_n_desired)
         b_mesh = - beta_m * hf.grad_frame(u,(x,y),lvl_func)
         
     elif(bnd_type == "exact"):
         a_mesh = - u_desired
         b_mesh = - beta_m * u_n_desired
     else:
         raise Exception("error: invalid boundary format")
     return (a_mesh, b_mesh)
Пример #2
0
def get_source(a, b, mesh, lvl_func_, f_mat_):
    xmesh, ymesh = mesh
    h = xmesh[0, 1] - xmesh[0, 0]
    phi = lvl_func_(xmesh, ymesh)
    #in the soruce term paper, the phi they use are inverted
    phi_inv = -phi

    #Discretization of the source term - formula (prev paper)
    #    S_mat = np.zeros_like(xmesh)
    #    H_h_mat = H(phi_inv,h)
    #    H_mat = np.heaviside(phi_inv,1)
    #    delta_mat = delta(phi_inv,h)
    #    S_mat = a*hf.laplace(H_mat,h,h) - (hf.norm_grad(a,(xmesh,ymesh),lvl_func_) + b)*delta_mat*hf.abs_grad(phi_inv,h,h) + H_h_mat * f_mat_

    #Discretization of the source term - formula (8)
    #    a_eff = (a + (hf.norm_grad(a,(xmesh,ymesh),lvl_func_) - b) * phi_inv / (hf.abs_grad(phi_inv,h,h)+singular_null))
    #    H_h_mat = H(phi_inv,h)
    #    H_mat = np.heaviside(phi_inv,1)
    #    S_mat = hf.laplace(a_eff * H_mat,h,h) - H_h_mat * hf.laplace(a_eff,h,h) + H_h_mat * f_mat_

    #Discretization of the source term - formula (7)
    H_h_mat = H(phi_inv, h)
    H_mat = np.heaviside(phi_inv, 1)
    term1 = hf.laplace(a * H_mat, h, h)
    term2 = -H_h_mat * hf.laplace(a, h, h)
    term3 = -(b - hf.norm_grad(a, (xmesh, ymesh), lvl_func_)) * delta(
        phi_inv, h) * hf.abs_grad(phi_inv, h, h)
    term4 = H_h_mat * f_mat_
    S_mat = term1 + term2 + term3 + term4

    return S_mat
Пример #3
0
def source_test():
    setup_grid(64)
    setup_equations("exact")
    phi = lvl_func(xmesh, ymesh)
    a_mesh = desired_func(xmesh, ymesh)
    b_mesh = hf.norm_grad(a_mesh, (xmesh, ymesh), lvl_func)
    source = get_source(a_mesh, b_mesh, (xmesh, ymesh), lvl_func,
                        rhs_func(xmesh, ymesh))
    plt.pcolor(xmesh, ymesh, source)
    plt.xlabel("x")
    plt.ylabel("y")
    plt.colorbar()
    return H(-phi, h)