Ejemplo n.º 1
0
def test_new_integrateX_via_straight_cutted_quad3D_polynomial(order, domain, quad_dominated, alpha, dim):
    ngsglobals.msg_level = 0

    if (quad_dominated):
        mesh = MakeUniform3DGrid(quads = True, N=1, P1=(0,0,0),P2=(1,1,1))
    else:
        cube = OrthoBrick( Pnt(0,0,0), Pnt(1,1,1) ).bc(1)
        geom = CSGeometry()
        geom.Add (cube)
        ngmesh = geom.GenerateMesh(maxh=1.3, quad_dominated=quad_dominated)
        mesh = Mesh(ngmesh)
        
    levelset = 1 - 2*x- 2*y - 2*z
    val_pos = pow(2,-alpha-3)/(pow(alpha,3)+6*alpha*alpha + 11*alpha+6)
    referencevals = {POS: val_pos, NEG: 1./(alpha+1) - val_pos}
    
    lset_approx = GridFunction(H1(mesh,order=1))
    InterpolateToP1(levelset,lset_approx)
    
    f = dim**alpha
    
    integral = Integrate(levelset_domain = { "levelset" : lset_approx, "domain_type" : domain},
                         cf=f, mesh=mesh, order = order)
    error = abs(integral - referencevals[domain])
    
    assert error < 5e-15*(order+1)*(order+1)
Ejemplo n.º 2
0
def test_new_integrateX_via_sphere_geom_quad(order, domain):
    r=0.7234436998

    levelset = sqrt(x*x+y*y+z*z)-r
    referencevals = { POS : 1-pi*r*r*r/6, NEG : pi*r*r*r/6, IF : r*r*pi/2}

    n_ref = 6
    errors = []

    for i in range(n_ref):
        mesh = MakeUniform3DGrid(quads = True, N=int(pow(2,i)), P1=(0,0,0),P2=(1,1,1))
        print("i: " +str(i))
        print("Argument Meshing: ",str(int(pow(2,i))))
        
        V = H1(mesh,order=1)
        lset_approx = GridFunction(V)
        InterpolateToP1(levelset,lset_approx)
    
        f = CoefficientFunction(1)
    
        integral = Integrate(levelset_domain = { "levelset" : lset_approx, "domain_type" : domain},
                         cf=f, mesh=mesh, order = order)
        print("Result of Integration Reflevel ",i,", Key ",domain," : ", integral)
        errors.append(abs(integral - referencevals[domain]))
        
    eoc = [log(errors[i+1]/errors[i])/log(0.5) for i in range(n_ref-1)]

    print("L2-errors:", errors)
    print("experimental order of convergence (L2):", eoc)

    mean_eoc_array = eoc[1:]
    mean_eoc = sum(mean_eoc_array)/len(mean_eoc_array)
    assert mean_eoc > 1.75
Ejemplo n.º 3
0
def test_new_integrateX_via_straight_cutted_quad3D(order, domain,
                                                   quad_dominated):
    if (quad_dominated):
        mesh = MakeUniform3DGrid(quads=True, N=1, P1=(0, 0, 0), P2=(1, 1, 1))
    else:
        cube = OrthoBrick(Pnt(0, 0, 0), Pnt(1, 1, 1)).bc(1)
        geom = CSGeometry()
        geom.Add(cube)
        ngmesh = geom.GenerateMesh(maxh=1.3, quad_dominated=quad_dominated)
        mesh = Mesh(ngmesh)

    levelset = 1 - 2 * x - 2 * y - 2 * z
    referencevals = {POS: 1. / 48, NEG: 47. / 48, IF: sqrt(3) / 8}

    lset_approx = GridFunction(H1(mesh, order=1))
    InterpolateToP1(levelset, lset_approx)

    f = CoefficientFunction(1)

    integral = Integrate(levelset_domain={
        "levelset": lset_approx,
        "domain_type": domain
    },
                         cf=f,
                         mesh=mesh,
                         order=order)
    print("Integral: ", integral)
    error = abs(integral - referencevals[domain])

    assert error < 5e-15 * (order + 1) * (order + 1)
Ejemplo n.º 4
0
def test_new_integrateX_via_straight_cutted_quad3D_polynomial_zero_val_challenge(
        order=4, domain=POS, alpha=2, dim=x):
    ngsglobals.msg_level = 0

    mesh = MakeUniform3DGrid(quads=True, N=2, P1=(0, 0, 0), P2=(1, 1, 1))

    levelset = 1 - 2 * x - 2 * y - 2 * z
    val_pos = pow(
        2, -alpha - 3) / (pow(alpha, 3) + 6 * alpha * alpha + 11 * alpha + 6)
    referencevals = {POS: val_pos, NEG: 1. / (alpha + 1) - val_pos}
    print("Val_pos: ", val_pos)

    lset_approx = GridFunction(H1(mesh, order=1))
    InterpolateToP1(levelset, lset_approx)

    f = dim**alpha

    integral = Integrate(levelset_domain={
        "levelset": lset_approx,
        "domain_type": domain,
        "quad_dir_policy": OPTIMAL
    },
                         cf=f,
                         mesh=mesh,
                         order=order)
    print("Integral:", integral)
    error = abs(integral - referencevals[domain])

    assert error < 5e-15 * (order + 1) * (order + 1)
Ejemplo n.º 5
0
def test_new_integrateX_TPMC_case_quad3D2(order, quad_dominated, high_order):
    if quad_dominated:
        mesh = MakeUniform3DGrid(quads=True, N=10, P1=(0, 0, 0), P2=(1, 1, 1))
    else:
        geom = CSGeometry()
        geom.Add(OrthoBrick(Pnt(0, 0, 0), Pnt(1, 1, 1)).bc(1))
        ngmesh = geom.GenerateMesh(maxh=0.2134981)
        for i in range(4):
            ngmesh.Refine()
        mesh = Mesh(ngmesh)

    #phi = -4*(1-x)*(1-y)*(1-z) + 4*(1-x)*(1-y)*z -1*(1-x)*y*(1-z) - 1*(1-x)*y*z + 2*x*(1-y)*(1-z) -3 *x*(1-y)*z + 5 * x * y * (1-z) -1 *x *y*z
    phi = x * ((7 * y - 13) * z + 6) + y * (3 - 8 * z) + 8 * z - 4

    if high_order:
        print("Creating LevelSetMeshAdaptation class")
        lsetmeshadap = LevelSetMeshAdaptation(mesh,
                                              order=order,
                                              threshold=0.2,
                                              discontinuous_qn=True)
        lsetp1 = lsetmeshadap.lset_p1
        deformation = lsetmeshadap.CalcDeformation(phi)

        mesh.SetDeformation(deformation)
    else:
        lsetp1 = GridFunction(H1(mesh, order=1))
        lsetp1.Set(phi)

    f = CoefficientFunction(1)

    print("Doing integration")
    for domain in [POS, NEG, IF]:
        integral = Integrate(levelset_domain={
            "levelset": lsetp1,
            "domain_type": domain
        },
                             cf=f,
                             mesh=mesh,
                             order=order)
        print("Integral: ", integral, " ; domain = ", domain)

        if domain == IF:
            assert abs(integral - 1.82169) < 5e-3
        elif domain == NEG:
            assert abs(integral - 0.51681) < 1e-3
        else:
            assert abs(integral - 0.48319) < 1e-3
Ejemplo n.º 6
0
def test_new_integrateX_via_straight_cutted_quad3D(order, domain, quad_dominated):
    mesh = MakeUniform3DGrid(quads = True, N=2, P1=(0,0,0),P2=(1,1,1))
    
    levelset = 1 - 2*x - 2*y - 2*z
    referencevals = { POS : 1./48, NEG : 47./48, IF : sqrt(3)/8 }
    
    lset_approx = GridFunction(H1(mesh,order=1))
    InterpolateToP1(levelset,lset_approx)
    
    f = CoefficientFunction(1)
    
    integral = Integrate(levelset_domain = { "levelset" : lset_approx, "domain_type" : domain},
                         cf=f, mesh=mesh, order = order)
    print("Integral: ", integral)
    error = abs(integral - referencevals[domain])
    
    assert error < 5e-15*(order+1)*(order+1)
Ejemplo n.º 7
0
def test_new_integrateX_TPMC_case_quad3D(order, domain, quad_dominated):
    mesh = MakeUniform3DGrid(quads = True, N=1, P1=(0,0,0),P2=(1,1,1))
    lset_approx = GridFunction(H1(mesh,order=1))
    for i,v in enumerate([-4,4,-1,-1,2,-3,5,-1]):
        lset_approx.vec[i] = v
    
    f = CoefficientFunction(1)
    
    integral = Integrate(levelset_domain = { "levelset" : lset_approx, "domain_type" : domain},
                         cf=f, mesh=mesh, order = order, heapsize=10000000)
    print("Integral: ", integral)

    if domain == IF:
        assert integral < 10
    elif domain == NEG:
        assert abs(integral - 0.5167820912197415) < 3.4e-3
    else:
        assert abs(integral - 0.4825797907263282) < 3.4e-3