Exemple #1
0
    '''
    If you run this module as main, you'll get some plots.
    '''
    from scipy.special import kv as kv
    from scipy.special import kn as kn
    from matplotlib import pyplot as plt

    import helper
    import container
    
    x = np.linspace( 0.0, 0.1, num=500, endpoint=True )
  
    d = 2
    if d == 2:
        cot = container.Container( "square",
                                   helper.get_mesh( "square", 100 ), 
                                   25,
                                   gamma = 1 )
        kappa = cot.kappa
        factor = cot.factor
        Phi1x  =  1. / 2 / math.pi * kn( 0, kappa*x )
        dPhi1x = -1. / 2 / math.pi * kappa * kn( 1, kappa*x )
        Phi2x  =  cot.factor * x * kappa * kn( 1, kappa*x )
        dPhi2x = -cot.factor * kappa * kappa*x * kn( 0, kappa*x )
  
    else:
        cot = container.Container( "cube",
                                   helper.get_mesh( "cube", 99 ),
                                   121,
                                   gamma = 1 )
        kappa = cot.kappa
Exemple #2
0
        tmp = -kappa * factor * kappara * (k0 * k0 + k1 * k1) / ra

        return (np.sum(tmp * x0) / n ** 2, np.sum(tmp * x1) / n ** 2)

    def denom2D(x0, x1, kappa, n, factor=1):
        ra = np.sqrt(x0 * x0 + x1 * x1) + 1e-13
        kappara = kappa * ra
        tmp = factor * kappara * sp.kv(1.0, kappara) * sp.kn(0, kappara)
        return 2.0 * np.sum(tmp) / n ** 2

    n = 17 * 13 * 17
    x0 = np.linspace(0, 1.0, n, endpoint=False)
    x1 = np.linspace(-0.5, 0.5, n, endpoint=False)
    X0, X1 = np.meshgrid(x0, x1)

    mesh_obj = helper.get_mesh("square", 50)
    alpha = 15.0
    cot = container.Container("square", mesh_obj, alpha)

    factor = cot.factor / 2.0 / math.pi
    denom = denom2D(X0, X1, cot.kappa, n, factor=factor)
    enum = np.array(enum2D(X0, X1, cot.kappa, n, factor=factor))
    nx_beta = enum / denom

    b = betas.Beta2DAdaptive(cot)
    cb_beta = b(0.0, 0.5)

    b = betas.Beta2D(cot)
    fe_beta = b(0.0, 0.5)

    b = betas.Beta2DRadial(cot)
Exemple #3
0
def bdryBetas( mesh_name,
               A,
               quad,
               normal,
               dims ):
    
    beta_file = "data/" + mesh_name + "/beta_" + quad + "_" + str(dims) + ".txt"
    helper.empty_file( beta_file )
    print beta_file
        
    mesh_obj = helper.get_mesh( mesh_name, dims )

    cot = container.Container( mesh_name,
                               mesh_obj,
                               dic[mesh_name].alpha,
                               quad = quad )

    beta_obj = cot.chooseBeta()
        
    if "adaptive" in quad:
        
        for s in np.linspace( 0, 1, num=77, endpoint=True):
            v = np.zeros( cot.dim )
            v[-1] = s
            if cot.dim == 3:
                v[1] = .5
            y = np.dot( A , v )
            beta = beta_obj( y )
            helper.add_point( beta_file,
                              s,
                              np.dot( beta, normal ) )
        return
            
    coo = mesh_obj.coordinates()
    

    if "parallelogram" in mesh_name:
        h = 1e-5
    elif "square" in mesh_name:
        h = 1e-9
    else:
        h = 1./dims
    total_time = 0
    counter = 0

    for i in range(coo.shape[0]):
        
        y = coo[i,:]
        inv = np.linalg.solve( A, y )
        doit = ( abs(inv[0]) < h )

        if cot.dim == 3:
            doit = doit and abs(inv[1]-0.5) < h
        if doit:
            counter = counter + 1
            start = time.time()
            beta = beta_obj( y ) 
            total_time = total_time + time.time() - start
            # print "Point = " + str( y )
            # print "Beta  = " + str(beta)
            # print
            
            helper.add_point( beta_file,
                              inv[-1],
                              np.dot( beta, normal ) )
    print "Average time per eval = " + str(total_time/counter)