Esempio n. 1
0
def test_2DmultiRegion(verbose=0):
    """Test for loading gmsh mesh through PUMI with multiple-regions"""
    testDir = os.path.dirname(os.path.abspath(__file__))
    Model = testDir + '/TwoQuads.dmg'
    Mesh = testDir + '/TwoQuads.smb'
    domain = Domain.PUMIDomain(
        dim=2, manager=MeshAdapt.AdaptManager())  #initialize the domain

    domain.AdaptManager.reconstructedFlag = 0  #this is used to indicate that no mesh reconstruction is being done.
    domain.AdaptManager.PUMIAdapter.loadModelAndMesh(bytes(Model, 'utf-8'),
                                                     bytes(Mesh, 'utf-8'))
    domain.faceList = [[14], [12], [11], [13], [15], [16]]
    domain.boundaryLabels = [1, 2, 3, 4, 5, 6]
    domain.regList = [[41], [42]]

    mesh = MeshTools.TriangularMesh()
    mesh.cmesh = cmeshTools.CMesh()
    comm = Comm.init()
    mesh.convertFromPUMI(domain,
                         domain.AdaptManager.PUMIAdapter,
                         domain.faceList,
                         domain.regList,
                         parallel=comm.size() > 1,
                         dim=domain.nd)
    ok(mesh.elementMaterialTypes[0] == 1)
    ok(mesh.elementMaterialTypes[-1] == 2)
Esempio n. 2
0
 def testCalculate_init(self):
     from proteus import Domain
     from proteus.mprans import SpatialTools as mst
     from proteus.mprans.BodyDynamics import PaddleBody
     domain2D = Domain.PlanarStraightLineGraphDomain()        
     pos = np.array([2.0, 0.1 , 0.0])
     dim = (0.3, 1.)
     paddle = mst.Rectangle(domain=domain2D, dim=dim, coords=[pos[0], pos[1]])
     
     PB=PaddleBody(paddle,substeps=20)
     PB.calculate_init()
     npt.assert_equal(PB.position,[pos[0],0.,0.])
     npt.assert_equal(PB.last_position,[pos[0],0.,0.])
     npt.assert_equal(PB.rotation,np.eye(3))
     npt.assert_equal(PB.last_rotation,np.eye(3))
     from proteus.mprans.BodyDynamics import getEulerAngles
     npt.assert_equal(PB.rotation_euler,getEulerAngles(PB.rotation))
     npt.assert_equal(PB.last_rotation_euler,getEulerAngles(PB.last_rotation))
     npt.assert_equal(PB.cV_init,np.array([(1.85,-0.4),
                                           (2.15,-0.4),
                                           (2.15,0.6),
                                           (1.85,0.6)]))
     npt.assert_equal(PB.cV,np.array([(1.85,-0.4),
                                           (2.15,-0.4),
                                           (2.15,0.6),
                                           (1.85,0.6)]))
     npt.assert_equal(PB.cV_last,np.array([(1.85,-0.4),
                                           (2.15,-0.4),
                                           (2.15,0.6),
                                           (1.85,0.6)]))
Esempio n. 3
0
 def testPaddleMotion(self):
     from proteus import Domain
     from proteus.mprans import SpatialTools as mst
     from proteus.mprans.BodyDynamics import PaddleBody
     domain2D = Domain.PlanarStraightLineGraphDomain()        
     pos = np.array([2.0, 0.1 , 0.0])
     dim = (0.3, 1.)
     paddle = mst.Rectangle(domain=domain2D, dim=dim, coords=[pos[0], pos[1]])
     
     PB=PaddleBody(paddle,substeps=20)
     PB.calculate_init()
     At  = [1.,0.,0.]
     Ar =  [0.1,0.,0.]
     Tt = Tr = [0.5,0.,0.]
     rampS = 0.1
     rampE = 0.1
     Tend = 2.
     PB.inputMotion(InputMotion=True, pivot=None,
                    At=At, Tt=Tt,
                    Ar=Ar, Tr=Tr,
                    rampStart=rampS, rampEnd =rampE, Tend = Tend)
     # tersting initial ramp
     times= [0.04, 0.95 ,1.93]
     for tt in times:
         ramp = min(1.,tt/rampS,(Tend-tt)/rampE)
         getVars = PB.imposeSinusoidalMotion(tt=tt)
         disp = ramp*np.array(At)*np.sin(2*np.pi/Tt[0]*tt)
         rot =  ramp*np.array(Ar)*np.sin(2*np.pi/Tt[0]*tt)
         disp = disp - (PB.last_position - PB.init_barycenter)
         npt.assert_equal(disp,getVars[0])
         npt.assert_equal(rot,getVars[1])
    def test_adaptIBM_adaptMesh(self):
        currentPath = os.path.dirname(os.path.abspath(__file__))
        runCommand = "cd " + currentPath + "; parun -l5 cylinder_so.py -C 'T=0.01 onlySaveFinalSolution=True genMesh=False usePUMI=True';"
        subprocess.check_call(runCommand, shell=True)

        #load initial mesh and extract element count
        domain = Domain.PUMIDomain(
            manager=MeshAdapt.AdaptManager())  #initialize the domain
        filePath = bytes(currentPath + '/', 'utf-8')
        domain.AdaptManager.PUMIAdapter.loadModelAndMesh(
            filePath + b"Reconstructed.dmg", filePath + b"Reconstructed.smb")
        mesh = MeshTools.TetrahedralMesh()
        mesh.convertFromPUMI(domain,
                             domain.AdaptManager.PUMIAdapter, [1], [1],
                             parallel=comm.size() > 1,
                             dim=2)
        nElements_initial = mesh.nElements_global

        #load final mesh and extract element count
        domain.AdaptManager.PUMIAdapter.loadModelAndMesh(
            filePath + b"Reconstructed.dmg", filePath + b"finalMesh.smb")
        mesh2 = MeshTools.TetrahedralMesh()
        mesh2.convertFromPUMI(domain,
                              domain.AdaptManager.PUMIAdapter, [1], [1],
                              parallel=comm.size() > 1,
                              dim=2)
        nElements_final = mesh2.nElements_global

        #adapted mesh should have less elements
        assert (nElements_final < nElements_initial)
Esempio n. 5
0
def tank2d(L=[1.0, 1.0, 1.0], fileprefix=None):
    boundaries = [
        'left', 'right', 'bottom', 'top', 'front', 'back', 'obstacle'
    ]
    boundaryTags = dict([(key, i + 1) for (i, key) in enumerate(boundaries)])
    vertices = [
        [0.0, 0.0],  #0
        [L[0], 0.0],  #1
        [L[0], L[1]],  #2
        [0.0, L[1]]
    ]  #3
    vertexFlags = [
        boundaryTags['left'], boundaryTags['right'], boundaryTags['right'],
        boundaryTags['left']
    ]
    segments = [[0, 1], [1, 2], [2, 3], [3, 0]]
    segmentFlags = [
        boundaryTags['front'], boundaryTags['right'], boundaryTags['back'],
        boundaryTags['left']
    ]
    regions = [[0.5 * L[0], 0.5 * L[1]]]
    regionFlags = [1.0]
    domain = Domain.PlanarStraightLineGraphDomain(fileprefix=fileprefix,
                                                  vertices=vertices,
                                                  vertexFlags=vertexFlags,
                                                  segments=segments,
                                                  segmentFlags=segmentFlags,
                                                  regions=regions,
                                                  regionFlags=regionFlags)
    #go ahead and add a boundary tags member
    domain.boundaryTags = boundaryTags
    return domain
 def test_gmsh_generation_3D(self):
     domain = Domain.PiecewiseLinearComplexDomain()
     cube = st.Cuboid(domain, dim=[2., 2., 2.])
     st.assembleDomain(domain)
     domain.writeGeo('gmsh_mesh_test_3D', he_max=0.1)
     gmsh_cmd = "gmsh {0:s} -v 10 -3 -o {1:s} -format msh".format(
         domain.geofile + ".geo", domain.geofile + ".msh")
     check_call(gmsh_cmd, shell=True)
     MeshTools.msh2simplex(domain.geofile, nd=3)
     # cek disabling exact tests due to cross-platform non-reproducibility
     # with open('gmsh_mesh_test_3D.node', 'r') as nodefile:
     #     npt.assert_equal(nodefile.readline(), '7674 3 0 1\n')
     # with open('gmsh_mesh_test_3D.edge', 'r') as edgefile:
     #     npt.assert_equal(edgefile.readline(), '9384 1\n')
     # with open('gmsh_mesh_test_3D.face', 'r') as facefile:
     #     npt.assert_equal(facefile.readline(), '6256 3 1\n')
     # with open('gmsh_mesh_test_3D.ele', 'r') as elefile:
     #     npt.assert_equal(elefile.readline(), '37473 4 1\n')
     with open('gmsh_mesh_test_3D.node', 'r') as nodefile:
         assert (abs(int(nodefile.readline().split()[0]) - 7674) / 7674.0 <
                 .02)
     with open('gmsh_mesh_test_3D.edge', 'r') as edgefile:
         assert (abs(int(edgefile.readline().split()[0]) - 9384) / 9384.0 <
                 .02)
     with open('gmsh_mesh_test_3D.face', 'r') as facefile:
         assert (abs(int(facefile.readline().split()[0]) - 6256) / 6256.0 <
                 .02)
     with open('gmsh_mesh_test_3D.ele', 'r') as elefile:
         assert (abs(int(elefile.readline().split()[0]) - 37473) / 37473.0 <
                 .02)
Esempio n. 7
0
 def testGetInertia(self):
     from proteus import Domain  
     from proteus import SpatialTools as st    
     from proteus.mprans import SpatialTools as mst
     from proteus.mprans import BodyDynamics as bd   
     # parameters
     domain2D = Domain.PlanarStraightLineGraphDomain()
     pos = np.array([1.0, 1.0, 0.0])
     dim = (0.3, 0.385)
     dt, substeps = 0.001, 20  
     caisson = mst.Rectangle(domain=domain2D, dim=dim, coords=[pos[0], pos[1]])
     caisson2D = bd.CaissonBody(shape=caisson, substeps=substeps)
     mst.assembleDomain(domain2D)      
     c2d = caisson2D
     c2d.nd = 2
     mass = c2d.mass = 50.0
     pivot = np.array([(caisson.vertices[0][0]+caisson.vertices[1][0])*0.5, caisson.vertices[0][1], 0.0])
     d = dx, dy, dz = pivot - caisson.barycenter
     # inertia transformation with different pivot 
     Ix = (old_div((dim[0]**2),12.)) + dy**2
     Iy = (old_div((dim[1]**2),12.)) + dx**2
     It = Ix + Iy 
     I = It*mass
     I1 = c2d.getInertia(vec=(0.,0.,1.), pivot=pivot)
     npt.assert_equal(I, I1)
Esempio n. 8
0
    def testOverturningModule(self):
        from proteus import Domain  
        from proteus import SpatialTools as st    
        from proteus.mprans import SpatialTools as mst
        from proteus.mprans import BodyDynamics as bd   

        # parameters
        domain2D = Domain.PlanarStraightLineGraphDomain()
        pos = np.array([1.0, 1.0, 0.0])
        dim = (0.3, 0.385)
        dt, substeps = 0.001, 20  
        caisson = mst.Rectangle(domain=domain2D, dim=dim, coords=[pos[0], pos[1]])
        caisson2D = bd.CaissonBody(shape=caisson, substeps=substeps)
        mst.assembleDomain(domain2D)      
        c2d = caisson2D
        c2d.nd = 2
        dt_sub = c2d.dt_sub = float(old_div(dt,substeps))
        Krot = 200000.
        Crot = 2000.
        c2d.Krot, c2d.Crot =  Krot, Crot
        c2d.substeps, c2d.dt, c2d.ang_acc = substeps, dt, c2d.getAngularAcceleration()
        c2d.setFriction(friction=True, m_static=0.0, m_dynamic=0.0, tolerance=0.000001, grainSize=0.02)
        rotation, last_rotation = c2d.Shape.coords_system, c2d.Shape.coords_system
        ang_vel, last_ang_vel = np.array([0., 0., 0.]), np.array([0., 0., 0.])
        F = Fx, Fy, Fz = np.array([200., -300., 0.0])
        M =  np.array([0., 0., 10.0])
        init_barycenter, last_position = pos, pos     
        c2d.F, c2d.M, c2d.init_barycenter, c2d.last_position = F, M, init_barycenter, last_position  
        eps = 10.**-30
        mass = c2d.mass = 50.0
        # moment and inertia transformations
        pivot = c2d.pivot_friction = np.array([(caisson.vertices[0][0]+caisson.vertices[1][0])*0.5, caisson.vertices[0][1], 0.0])
        barycenter = caisson.barycenter
        distance = dx, dy, dz = pivot - barycenter
        Mpivot = np.array([0., 0., dx*Fy-dy*Fx]) # Moment calculated in pivot
        Mp = M - Mpivot # Moment transformation through the new pivot
        Ix = (old_div((dim[0]**2),12.)) + dy**2
        Iy = (old_div((dim[1]**2),12.)) + dx**2
        It = Ix + Iy    
        I = It*mass
        c2d.springs = True
        # runge-kutta calculation
        c2d.scheme = 'Runge_Kutta'
        rz0, vrz0 = atan2(last_rotation[0,1], last_rotation[0,0]), last_ang_vel[2]
        arz0 = old_div((Mp[2] - Crot*vrz0 - Krot*rz0), I)
        rz, vrz, arz = bd.runge_kutta(rz0, vrz0, arz0, dt_sub, substeps, Mp[2], Krot, Crot, I, False)
        # calculation with bodydynamics mopdule
        c2d.cV_init = c2d.cV = c2d.cV_last = caisson.vertices
        c2d.inertia = c2d.getInertia(pivot=pivot)
        c2d.overturning_module(dt)    
        # test
        ang_disp = rz - rz0
        npt.assert_equal(c2d.ang_disp[2], ang_disp)
        npt.assert_equal(c2d.ang_vel[2], vrz)
        npt.assert_equal(c2d.ang_acc[2], arz)
Esempio n. 9
0
def get_domain_one_box(x0=(0.0, 0.0, 0.0), L=(1.0, 1.0, 1.0), he=0.001):
    boundaries = ['left', 'right', 'bottom', 'top', 'front', 'back']
    boundaryTags = dict([(key, i + 1) for (i, key) in enumerate(boundaries)])
    x1 = (x0[0] + L[0], x0[1] + L[1], x0[2] + L[2])
    vertices = [(x0[0], x0[1], x0[2]), (x1[0], x0[1], x0[2]),
                (x1[0], x1[1], x0[2]), (x0[0], x1[1], x0[2]),
                (x0[0], x0[1], x1[2]), (x1[0], x0[1], x1[2]),
                (x1[0], x1[1], x1[2]), (x0[0], x1[1], x1[2])]
    vertexFlags = [
        boundaryTags['bottom'],
        boundaryTags['bottom'],
        boundaryTags['top'],
        boundaryTags['top'],
        boundaryTags['bottom'],
        boundaryTags['bottom'],
        boundaryTags['top'],
        boundaryTags['top'],
    ]

    planes = []
    planeFlags = []
    planeHolds = []
    planes.extend([[
        [0, 1, 2, 3],
    ], [
        [4, 5, 6, 7],
    ], [[0, 3, 7, 4]], [[1, 2, 6, 5]], [[0, 1, 5, 4]], [[2, 3, 7, 6]]])
    planeFlags.extend([
        boundaryTags['back'],
        boundaryTags['front'],
        boundaryTags['left'],
        boundaryTags['right'],
        boundaryTags['bottom'],
        boundaryTags['top'],
    ])
    planeHolds.extend([[], [], [], [], [], []])

    regions = [
        [0.5 * (x0[0] + x1[0]), 0.5 * (x0[1] + x1[1]), 0.5 * (x0[2] + x1[2])],
    ]
    regionFlags = [
        1,
    ]
    regionConstraints = [0.5 * he**2]

    domain = Domain.PiecewiseLinearComplexDomain(
        vertices=vertices,
        facets=planes,
        facetFlags=planeFlags,
        facetHoles=planeHolds,
        regions=regions,
        regionFlags=regionFlags,
        regionConstraints=regionConstraints)
    return domain, boundaryTags, x0, x1
Esempio n. 10
0
def boxInTank3d(L=[1.0, 1.0, 1.0], box_xy=[0.25, 0.25], box_L=[0.5, 0.5, 0.5]):
    boundaries = [
        'left', 'right', 'bottom', 'top', 'front', 'back', 'obstacle'
    ]
    boundaryTags = dict([(key, i + 1) for (i, key) in enumerate(boundaries)])
    holes = [[
        0.5 * box_L[0] + box_xy[0], 0.5 * box_L[1] + box_xy[1], 0.5 * box_L[2]
    ]]
    vertices = [
        [0.0, 0.0, 0.0],  #0
        [L[0], 0.0, 0.0],  #1
        [L[0], L[1], 0.0],  #2
        [0.0, L[1], 0.0],  #3
        [0.0, 0.0, L[2]],  #4
        [L[0], 0.0, L[2]],  #5
        [L[0], L[1], L[2]],  #6
        [0.0, L[1], L[2]],  #7
        [box_xy[0], box_xy[1], 0.0],  #8
        [box_xy[0] + box_L[0], box_xy[1], 0.0],  #9
        [box_xy[0] + box_L[0], box_xy[1] + box_L[1], 0.0],  #10
        [box_xy[0], box_xy[1] + box_L[1], 0.0],  #11
        [box_xy[0], box_xy[1], box_L[2]],  #12
        [box_xy[0] + box_L[0], box_xy[1], box_L[2]],  #13
        [box_xy[0] + box_L[0], box_xy[1] + box_L[1], box_L[2]],  #14
        [box_xy[0], box_xy[1] + box_L[1], box_L[2]]
    ]  #15
    vertexFlags = [
        boundaryTags['left'], boundaryTags['right'], boundaryTags['right'],
        boundaryTags['left'], boundaryTags['left'], boundaryTags['right'],
        boundaryTags['right'], boundaryTags['left'], boundaryTags['obstacle'],
        boundaryTags['obstacle'], boundaryTags['obstacle'],
        boundaryTags['obstacle'], boundaryTags['obstacle'],
        boundaryTags['obstacle'], boundaryTags['obstacle'],
        boundaryTags['obstacle']
    ]
    facets = [[[0, 1, 2, 3], [8, 9, 10, 11]], [[0, 1, 5, 4]], [[1, 2, 6, 5]],
              [[2, 3, 7, 6]], [[3, 0, 4, 7]], [[4, 5, 6, 7]], [[8, 9, 13, 12]],
              [[9, 10, 14, 13]], [[10, 11, 15, 14]], [[11, 8, 12, 15]],
              [[12, 13, 14, 15]]]
    facetFlags = [
        boundaryTags['bottom'], boundaryTags['front'], boundaryTags['right'],
        boundaryTags['back'], boundaryTags['left'], boundaryTags['top'],
        boundaryTags['obstacle'], boundaryTags['obstacle'],
        boundaryTags['obstacle'], boundaryTags['obstacle'],
        boundaryTags['obstacle']
    ]
    domain = Domain.PiecewiseLinearComplexDomain(vertices=vertices,
                                                 vertexFlags=vertexFlags,
                                                 facets=facets,
                                                 facetFlags=facetFlags,
                                                 holes=holes)
    #go ahead and add a boundary tags member
    domain.boundaryTags = boundaryTags
    return domain
Esempio n. 11
0
def cylinder2d(height=1.0,
               length=1.0,
               radius=0.25,
               center=[0.5, 0.5],
               n_points_on_obstacle=10,
               cross_section=circular_cross_section):
    #enumerate the boundaries so we can supply integer flags for vertices and segments
    boundaries = ['upstream', 'downstream', 'bottom', 'top', 'obstacle']
    boundaryTags = dict([(key, i + 1) for (i, key) in enumerate(boundaries)])
    #now work around the domain from (0.0,0.0) going counterclockwise building vertices and segments (and flags)
    vertices = [[0.0, 0.0], [length, 0.0], [length, height], [0.0, height]]
    vertexFlags = [
        boundaryTags['bottom'], boundaryTags['bottom'], boundaryTags['top'],
        boundaryTags['top']
    ]
    segments = [[0, 1], [1, 2], [2, 3], [3, 0]]
    segmentFlags = [
        boundaryTags['bottom'], boundaryTags['downstream'],
        boundaryTags['top'], boundaryTags['upstream']
    ]
    #now do the vertices and segments on the cylinder
    theta = 0.0
    pb = cross_section(center, radius, theta)
    vertices.append([pb[0], pb[1]])
    vertexFlags.append(boundaryTags['obstacle'])
    for gb in range(1, n_points_on_obstacle):
        theta = float(gb) / float(n_points_on_obstacle) * 2.0 * math.pi
        pb = cross_section(center, radius, theta)
        vertices.append([pb[0], pb[1]])
        vertexFlags.append(boundaryTags['obstacle'])
        nv = len(vertices)
        segments.append((nv - 2, nv - 1))
        segmentFlags.append(boundaryTags['obstacle'])
    segments.append((nv - 1, nv - n_points_on_obstacle))
    segmentFlags.append(boundaryTags['obstacle'])
    #done with vertices and segments
    #holes
    holes = [center]
    #regions (just pick a point inside to indicate the flow region)
    regions = [[
        vertices[0][0] + length * 1.0e-8, vertices[0][1] + length * 1.0e-8
    ]]
    regionFlags = [1]
    #construct domain object
    domain = Domain.PlanarStraightLineGraphDomain(vertices=vertices,
                                                  vertexFlags=vertexFlags,
                                                  segments=segments,
                                                  segmentFlags=segmentFlags,
                                                  holes=holes,
                                                  regions=regions,
                                                  regionFlags=regionFlags)
    #go ahead and add a boundary tags member
    domain.boundaryTags = boundaryTags
    return domain
Esempio n. 12
0
    def testStoreLastValues(self):
        from proteus import Domain  
        from proteus.mprans import SpatialTools as st
        from proteus.mprans import BodyDynamics as bd   
        domain = Domain.PlanarStraightLineGraphDomain()
        pos = np.array([1.0, 1.0, 0.0])
        rot = np.array([ [1.,0.,0.], [0.,1.,0.], [0.,0.,1.] ])  
        dim=(0.3, 0.385)
        caisson = st.Rectangle(domain, dim=dim, coords=[pos[0], pos[1]])
        caisson2D = bd.RigidBody(shape=caisson)
        st.assembleDomain(domain)      
        c2d = caisson2D
        nd = 2
        anglez = radians(5.0)
        rotz = np.array([  [  cos(anglez),  sin(anglez),  0.0 ],
                           [ -sin(anglez),  cos(anglez),  0.0 ],
                           [  0.0,         0.0,           1.0 ] ])

        c2d.calculate_init()

        # Imposing values on rigid body's parameters
        c2d.position = np.array([2.0, 3.0, 0.0])
        c2d.velocity = np.array([0.5, -0.3, 0.0])
        c2d.acceleration = np.array([0.1, 0.2, 0.0])
        c2d.rotation = rotz
        c2d.rotation_euler =  bd.getEulerAngles(rotz)
        c2d.ang_disp = np.array([0.0, 0.0, 0.001])
        c2d.ang_vel = np.array([0.0, 0.0, -0.003])
        c2d.ang_acc = np.array([0.0, 0.0, 0.005])
        c2d.F = np.array([100.0, -300.0, 0.0])
        c2d.M = np.array([0.0, 0.0, 50.0])
        c2d.pivot = c2d.barycenter
        c2d.ux = 0.5
        c2d.uy = 0.05
        c2d.uz = 0.0

        c2d._store_last_values()
        
        npt.assert_equal(c2d.position, c2d.last_position)
        npt.assert_equal(c2d.velocity, c2d.last_velocity)
        npt.assert_equal(c2d.acceleration, c2d.last_acceleration)
        npt.assert_equal(c2d.rotation, c2d.last_rotation)
        npt.assert_equal(c2d.rotation_euler, c2d.last_rotation_euler)
        npt.assert_equal(c2d.ang_disp, c2d.last_ang_disp)
        npt.assert_equal(c2d.ang_vel, c2d.last_ang_vel)
        npt.assert_equal(c2d.ang_acc, c2d.last_ang_acc)
        npt.assert_equal(c2d.F, c2d.last_F)
        npt.assert_equal(c2d.M, c2d.last_M)
        npt.assert_equal(c2d.pivot, c2d.last_pivot)
        npt.assert_equal(c2d.ux, c2d.last_ux)
        npt.assert_equal(c2d.uy, c2d.last_uy)
        npt.assert_equal(c2d.uz, c2d.last_uz)
def gl_5_3d(width, h):
    """
    A 3d levee profile for the sacramento levee modeling
    """
    boundaryLegend = {
        'left': 1,
        'right': 2,
        'front': 3,
        'back': 4,
        'bottom': 5,
        'top': 6
    }
    vertices_front = [
        [0.0, 0.0, 0.0],  #0
        [0.0, 0.0, h],  #1
        [1.2 * h, 0.0, h],  #2
        [3.2 * h, 0.0, 0.0]
    ]  #3
    vertexFlags_front = [
        boundaryLegend['left'], boundaryLegend['left'], boundaryLegend['top'],
        boundaryLegend['top']
    ]
    vertices_back = [[v[0], width, v[2]] for v in vertices_front]
    vertexFlags_back = vertexFlags_front
    vertices = vertices_front + vertices_back
    vertexFlags = vertexFlags_front + vertexFlags_back
    facets = [
        [[0, 1, 2, 3]],  #front
        [[4, 5, 6, 7]],  #back
        [[0, 1, 5, 4]],  #left
        [[3, 2, 6, 7]],  #right
        [[0, 4, 7, 3]],  #bottom
        [[1, 5, 6, 2]]
    ]  #top
    facetFlags = [
        boundaryLegend['front'], boundaryLegend['back'],
        boundaryLegend['left'], boundaryLegend['top'],
        boundaryLegend['bottom'], boundaryLegend['top']
    ]
    regions = [[h, width / 2.0, h]]
    regionFlags = [1]
    print vertices, vertexFlags, facets, facetFlags, regions, regionFlags
    domain = Domain.PiecewiseLinearComplexDomain(vertices=vertices,
                                                 vertexFlags=vertexFlags,
                                                 facets=facets,
                                                 facetFlags=facetFlags,
                                                 regions=regions,
                                                 regionFlags=regionFlags)
    domain.boundaryFlags = boundaryLegend
    domain.regionLegend = {'levee': 1, 'default': 0}
    return domain
Esempio n. 14
0
def build_PSLG():
    """
    build PlanarStraightLineGraph and return
    """
    from proteus import Domain
    v, s, vf, sf, btags = build_vertices_and_segments()

    domain = Domain.PlanarStraightLineGraphDomain(vertices=v,
                                                  segments=s,
                                                  vertexFlags=vf,
                                                  segmentFlags=sf)
    domain.boundaryTags = btags

    return domain
Esempio n. 15
0
    def testStep(self):
        from proteus import Domain
        from proteus import SpatialTools as st
        from proteus.mprans import SpatialTools as mst
        from proteus.mprans import BodyDynamics as bd

        # parameters
        domain2D = Domain.PlanarStraightLineGraphDomain()
        pos = np.array([1.0, 1.0, 0.0])
        dim = (0.3, 0.385)
        caisson = mst.Rectangle(domain=domain2D,
                                dim=dim,
                                coords=[pos[0], pos[1]])
        caisson2D = bd.RigidBody(shape=caisson)
        mst.assembleDomain(domain2D)
        c2d = caisson2D
        nd = c2d.nd = 2
        Ix = ((dim[0]**2) / 12.)
        Iy = ((dim[1]**2) / 12.)
        It = Ix + Iy
        mass = 50.0
        I = mass * It
        c2d.mass, c2d.It = mass, It
        init_barycenter, last_position, last_velocity, last_rotation, last_ang_vel = pos, pos * 2.0, np.array(
            [0.05, 0.07,
             0.0]), np.array([0.0, 0.0, 0.0001]), np.array([0., 0., 0.0000002])
        c2d.init_barycenter, c2d.last_position, c2d.last_velocity, c2d.last_rotation, c2d.last_ang_vel = init_barycenter, last_position, last_velocity, last_rotation, last_ang_vel
        F = Fx, Fy, Fz = np.array([200., 300., 0.0])
        M = Mx, My, Mz = np.array([0., 0., 50.0])
        dt, substeps = 0.001, 20
        dt_sub = c2d.dt_sub = float(dt / substeps)
        c2d.F, c2d.substeps, c2d.dt, c2d.acceleration = F, substeps, dt, c2d.getAcceleration(
        )
        c2d.InputMotion = False
        c2d.scheme = 'Forward_Euler'
        h, tra_velocity = bd.forward_euler(last_position, last_velocity,
                                           F / mass, dt)
        rot, rot_velocity = bd.forward_euler(last_rotation, last_ang_vel,
                                             M / I, dt)
        if rot[2] < 0.0: rot[2] = -rot[2]
        # 2d calculation
        caisson.translate(h[:nd]), caisson.rotate(rot[2])
        posTra1, rot1 = caisson.barycenter, caisson.coords_system
        # 2d from bodydynamics
        caisson.translate(-h[:nd]), caisson.rotate(-rot[2])
        c2d.step(dt)
        posTra2, rot2 = c2d.position, c2d.rotation[:nd, :nd]
        npt.assert_allclose(posTra1, posTra2, atol=1e-10)
        npt.assert_allclose(rot1, rot2, atol=1e-10)
Esempio n. 16
0
    def testGetDisplacement(self):
        from proteus import Domain
        from proteus import SpatialTools as st
        from proteus.mprans import SpatialTools as mst
        from proteus.mprans import BodyDynamics as bd

        # parameters
        domain2D = Domain.PlanarStraightLineGraphDomain()
        pos = np.array([1.0, 1.0, 0.0])
        dim = (0.3, 0.385)
        caisson = mst.Rectangle(domain=domain2D,
                                dim=dim,
                                coords=[pos[0], pos[1]])
        caisson2D = bd.RigidBody(shape=caisson)
        mst.assembleDomain(domain2D)
        c2d = caisson2D
        c2d.nd = 2
        Ix = ((dim[0]**2) / 12.)
        Iy = ((dim[1]**2) / 12.)
        It = Ix + Iy
        mass = 50.0
        c2d.mass, c2d.It = mass, It
        Kx, Ky, Kz = K = [200000., 250000., 0.0]
        Cx, Cy, Cz = C = [2000., 4000., 0.0]
        c2d.Kx, c2d.Ky, c2d.Kz, c2d.Cx, c2d.Cy, c2d.Cz = Kx, Ky, Kz, Cx, Cy, Cz
        init_barycenter, last_position, last_velocity = pos, pos * 2.0, np.array(
            [0.05, 0.07, 0.0])
        c2d.init_barycenter, c2d.last_position, c2d.last_velocity = init_barycenter, last_position, last_velocity
        Fx, Fy, Fz = F = np.array([200., 300., 0.0])
        dt, substeps = 0.001, 50
        dt_sub = c2d.dt_sub = float(dt / substeps)
        c2d.F, c2d.substeps, c2d.dt, c2d.acceleration = F, substeps, dt, c2d.getAcceleration(
        )

        # runge-kutta calculation
        c2d.scheme = 'Runge_Kutta'
        u0 = ux0, uy0, uz0 = last_position - init_barycenter
        v0 = vx0, vy0, vz0 = last_velocity
        a0 = ax0, ay0, az0 = (F - C * v0 - K * u0) / mass
        for ii in range(substeps):
            ux, vx, ax = bd.runge_kutta(ux0, vx0, ax0, dt_sub, substeps, Fx,
                                        Kx, Cx, mass, False)
            uy, vy, ay = bd.runge_kutta(uy0, vy0, ay0, dt_sub, substeps, Fy,
                                        Ky, Cy, mass, False)
            uz, vz, az = bd.runge_kutta(uz0, vz0, az0, dt_sub, substeps, Fz,
                                        Kz, Cz, mass, False)
        h = hx, hy, hz = [ux - ux0, uy - uy0, uz - uz0]
        c2d.h = c2d.getDisplacement(dt)
        npt.assert_equal(c2d.h, h)
Esempio n. 17
0
 def test_gmsh_generation_2D(self):
     domain = Domain.PlanarStraightLineGraphDomain()
     domain.vertices = [[0., 0., 0.], [5., 0., 0.], [5., 5., 0.],
                        [0., 5., 0.]]
     domain.segments = [[0, 1], [1, 2], [2, 3], [3, 0]]
     domain.facets = [[[0, 1, 2, 3]]]
     domain.writeGeo('gmsh_mesh_test_2D', he_max=0.1)
     gmsh_cmd = "gmsh {0:s} -v 10 -2 -o {1:s} -format msh".format(
         domain.geofile + ".geo", domain.geofile + ".msh")
     check_call(gmsh_cmd, shell=True)
     MeshTools.msh2simplex(domain.geofile, nd=2)
     with open('gmsh_mesh_test_2D.node', 'r') as nodefile:
         npt.assert_equal(nodefile.readline(), '3425 2 0 1\n')
     with open('gmsh_mesh_test_2D.edge', 'r') as edgefile:
         npt.assert_equal(edgefile.readline(), '10072 1\n')
     with open('gmsh_mesh_test_2D.ele', 'r') as elefile:
         npt.assert_equal(elefile.readline(), '6648 3 1\n')
Esempio n. 18
0
def test_parallelLoadPUMI(verbose=0):
    """Test to load parallel PUMI model and mesh"""
    comm = Comm.init()
    eq(comm.size(),2)
    testDir=os.path.dirname(os.path.abspath(__file__))
    domain = Domain.PUMIDomain()
    Model=testDir+ '/Prism.dmg'
    Mesh=testDir + '/Prism.smb'
    domain.PUMIMesh=MeshAdaptPUMI.MeshAdaptPUMI()
    domain.PUMIMesh.loadModelAndMesh(Model, Mesh)
    mesh = MeshTools.TetrahedralMesh()
    mesh.cmesh = cmeshTools.CMesh()
    mesh.convertFromPUMI(domain.PUMIMesh, domain.faceList, parallel = comm.size() > 1, dim = domain.nd)
    eq(mesh.nElements_global,8148)
    eq(mesh.nNodes_global,1880)
    eq(mesh.nEdges_global,11001)
    eq(mesh.nElementBoundaries_global,17270)
Esempio n. 19
0
def beachBakhtyar3d(L=[8.5, 1.0, 0.8], Lb=3.5):
    boundaries = [
        'left', 'right', 'bottom', 'top', 'front', 'back', 'obstacle'
    ]
    boundaryTags = dict([(key, i + 1) for (i, key) in enumerate(boundaries)])
    vertices = [
        [0.0, 0.0, 0.0],  #0
        [Lb, 0.0, 0.0],  #1
        [L[0], 0.0, 0.5],  #2
        [L[0], 0.0, L[2]],  #3
        [0.0, 0.0, L[2]],  #4
        [0.0, L[1], 0.0],  #5
        [Lb, L[1], 0.0],  #6
        [L[0], L[1], 0.5],  #7
        [L[0], L[1], L[2]],  #8
        [0.0, L[1], L[2]]
    ]  #9
    vertexFlags = [
        boundaryTags['left'],  #0
        boundaryTags['bottom'],  #1
        boundaryTags['right'],  #2
        boundaryTags['right'],  #3
        boundaryTags['left'],  #4
        boundaryTags['left'],  #5
        boundaryTags['bottom'],  #6
        boundaryTags['right'],  #7
        boundaryTags['right'],  #8
        boundaryTags['left']
    ]  #9
    facets = [[[0, 1, 2, 3, 4]], [[0, 4, 9, 5]], [[2, 3, 8, 7]], [[3, 4, 9,
                                                                   8]],
              [[0, 1, 6, 5]], [[1, 2, 7, 6]], [[5, 6, 7, 8, 9]]]
    facetFlags = [
        boundaryTags['front'], boundaryTags['left'], boundaryTags['right'],
        boundaryTags['top'], boundaryTags['bottom'], boundaryTags['bottom'],
        boundaryTags['back']
    ]
    domain = Domain.PiecewiseLinearComplexDomain(vertices=vertices,
                                                 vertexFlags=vertexFlags,
                                                 facets=facets,
                                                 facetFlags=facetFlags)
    #go ahead and add a boundary tags member
    domain.boundaryTags = boundaryTags
    return domain
Esempio n. 20
0
def gauge_setup(nd, total_nodes=None):
    comm = Comm.get()

    #Simplified Physics
    p.name = "test_gauges"

    p.nd = nd

    class LinearSolution(object):
        def uOfXT(self, x, t):
            return (x[0] + 10 * x[1] + 100 * x[2]) * (t + 1.0)

    p.initialConditions = {0: LinearSolution()}
    p.dirichletConditions = {0: lambda x, flag: None}
    p.domain = Domain.RectangularDomain(name="test_gauges_domain")
    p.coefficients = TransportCoefficients.PoissonEquationCoefficients(
        aOfX=[lambda x: np.eye(p.nd, p.nd)], fOfX=[lambda x: 0], nc=1, nd=p.nd)
    #Simplified and Incomplete Numerics
    n.femSpaces = {0: FemTools.C0_AffineLinearOnSimplexWithNodalBasis}
    n.elementQuadrature = Quadrature.SimplexGaussQuadrature(p.nd, 3)
    n.elementBoundaryQuadrature = Quadrature.SimplexGaussQuadrature(
        p.nd - 1, 3)
    n.numericalFluxType = NumericalFlux.NoFlux
    n.cfluxtag = None
    n.conservativeFlux = None

    if total_nodes is None:
        total_nodes = 2 * comm.size()

    if p.nd == 1:
        mlMesh = build1DMesh(p, total_nodes + 1)
    elif p.nd == 2:
        nnx = nny = int(ceil(sqrt(total_nodes))) + 1
        mlMesh = build2DMesh(p, nnx, nny)
    elif p.nd == 3:
        nnx = nny = nnz = int(ceil(pow(total_nodes, old_div(1.0, 3.0)))) + 1
        mlMesh = build3DMesh(p, nnx, nny, nnz)

    model = Transport.MultilevelTransport(p, n, mlMesh)

    return model, p.initialConditions
Esempio n. 21
0
def test_2DparallelLoadPUMI(verbose=0):
    """Test to load 2D parallel PUMI model and mesh"""
    comm = Comm.init()
    eq(comm.size(), 2)
    testDir = os.path.dirname(os.path.abspath(__file__))
    domain = Domain.PUMIDomain(dim=2)
    Model = testDir + '/Rectangle.dmg'
    Mesh = testDir + '/Rectangle.smb'
    domain.PUMIMesh = MeshAdaptPUMI.MeshAdaptPUMI()
    domain.PUMIMesh.loadModelAndMesh(Model, Mesh)
    mesh = MeshTools.TriangularMesh()
    mesh.cmesh = cmeshTools.CMesh()
    mesh.convertFromPUMI(domain.PUMIMesh,
                         domain.faceList,
                         domain.regList,
                         parallel=comm.size() > 1,
                         dim=domain.nd)
    eq(mesh.nElements_global, 8)
    eq(mesh.nNodes_global, 10)
    eq(mesh.nEdges_global, 17)
    eq(mesh.nElementBoundaries_global, 17)
Esempio n. 22
0
    def testGetAngularAcceleration(self):
        from proteus import Domain  
        from proteus.mprans import SpatialTools as st
        from proteus.mprans import BodyDynamics as bd   
        domain = Domain.PlanarStraightLineGraphDomain()
        pos = np.array([1.0, 1.0, 0.0])
        rot = np.array([ [1.,0.,0.], [0.,1.,0.], [0.,0.,1.] ])    
        dim=(0.3, 0.385)
        caisson = st.Rectangle(domain, dim=dim, coords=[pos[0], pos[1]])
        caisson2D = bd.RigidBody(shape=caisson)
        st.assembleDomain(domain)      
        c2d = caisson2D

        F = np.array([100.0, -200.0, 10.0])
        mass = 150.0
        acceleration = old_div(F,mass)

        c2d.F = F
        c2d.mass = mass
        c2d.acceleration = c2d.getAcceleration()
        npt.assert_equal(c2d.acceleration, acceleration)
Esempio n. 23
0
def test_2DmultiRegion(verbose=0):
    """Test for loading gmsh mesh through PUMI with multiple-regions"""
    testDir = os.path.dirname(os.path.abspath(__file__))
    Model = testDir + '/TwoQuads.dmg'
    Mesh = testDir + '/TwoQuads.smb'
    domain = Domain.PUMIDomain(dim=2)  #initialize the domain
    domain.PUMIMesh = MeshAdaptPUMI.MeshAdaptPUMI()
    domain.PUMIMesh.loadModelAndMesh(Model, Mesh)
    domain.faceList = [[14], [12], [11], [13], [15], [16]]
    domain.regList = [[41], [42]]

    mesh = MeshTools.TriangularMesh()
    mesh.cmesh = cmeshTools.CMesh()
    comm = Comm.init()

    mesh.convertFromPUMI(domain.PUMIMesh,
                         domain.faceList,
                         domain.regList,
                         parallel=comm.size() > 1,
                         dim=domain.nd)
    ok(mesh.elementMaterialTypes[0] == 1)
    ok(mesh.elementMaterialTypes[-1] == 2)
Esempio n. 24
0
    def testCalculateInit(self):
        from proteus import Domain  
        from proteus.mprans import SpatialTools as st
        from proteus.mprans import BodyDynamics as bd   
        domain = Domain.PlanarStraightLineGraphDomain()
        pos = np.array([1.0, 1.0, 0.0])
        rot = np.array([ [1.,0.,0.], [0.,1.,0.], [0.,0.,1.] ])  
        dim=(0.3, 0.385)
        caisson = st.Rectangle(domain, dim=dim, coords=[pos[0], pos[1]])
        caisson2D = bd.RigidBody(shape=caisson)
        st.assembleDomain(domain)      
        c2d = caisson2D
        nd = 2
        angle = bd.getEulerAngles(rot)

        c2d.calculate_init()

        npt.assert_equal(c2d.position, pos)
        npt.assert_equal(c2d.last_position, pos)
        npt.assert_equal(c2d.rotation, rot)
        npt.assert_equal(c2d.last_rotation, rot)
        npt.assert_equal(c2d.rotation_euler, angle)
        npt.assert_equal(c2d.last_rotation_euler, angle)
Esempio n. 25
0
def tank3d(L=[1.0, 1.0, 1.0]):
    boundaries = [
        'left', 'right', 'bottom', 'top', 'front', 'back', 'obstacle'
    ]
    boundaryTags = dict([(key, i + 1) for (i, key) in enumerate(boundaries)])
    vertices = [
        [0.0, 0.0, 0.0],  #0
        [L[0], 0.0, 0.0],  #1
        [L[0], L[1], 0.0],  #2
        [0.0, L[1], 0.0],  #3
        [0.0, 0.0, L[2]],  #4
        [L[0], 0.0, L[2]],  #5
        [L[0], L[1], L[2]],  #6
        [0.0, L[1], L[2]]
    ]  #7
    vertexFlags = [
        boundaryTags['left'], boundaryTags['right'], boundaryTags['right'],
        boundaryTags['left'], boundaryTags['left'], boundaryTags['right'],
        boundaryTags['right'], boundaryTags['left']
    ]
    facets = [[[0, 1, 2, 3]], [[0, 1, 5, 4]], [[1, 2, 6, 5]], [[2, 3, 7, 6]],
              [[3, 0, 4, 7]], [[4, 5, 6, 7]]]
    facetFlags = [
        boundaryTags['bottom'], boundaryTags['front'], boundaryTags['right'],
        boundaryTags['back'], boundaryTags['left'], boundaryTags['top']
    ]
    regions = [[0.5 * L[0], 0.5 * L[1], 0.5 * L[2]]]
    regionFlags = [1.0]
    domain = Domain.PiecewiseLinearComplexDomain(vertices=vertices,
                                                 vertexFlags=vertexFlags,
                                                 facets=facets,
                                                 facetFlags=facetFlags,
                                                 regions=regions,
                                                 regionFlags=regionFlags)
    #go ahead and add a boundary tags member
    domain.boundaryTags = boundaryTags
    return domain
Esempio n. 26
0
def test_poiseuilleError(verbose=0):
    """Test for loading gmsh mesh through PUMI, estimating error for 
    a Poiseuille flow case. The estimated error should be larger than the
    exact error in the seminorm"""
    testDir = os.path.dirname(os.path.abspath(__file__))
    Model = testDir + '/Couette.null'
    Mesh = testDir + '/Couette.msh'

    domain = Domain.PUMIDomain()  #initialize the domain
    domain.PUMIMesh = MeshAdaptPUMI.MeshAdaptPUMI(hmax=0.01,
                                                  hmin=0.008,
                                                  numIter=1,
                                                  sfConfig='ERM',
                                                  maType='isotropic',
                                                  logType='off')
    domain.PUMIMesh.loadModelAndMesh(Model, Mesh)
    domain.faceList = [[80], [76], [42], [24], [82], [78]]

    mesh = MeshTools.TetrahedralMesh()
    mesh.cmesh = cmeshTools.CMesh()
    comm = Comm.init()

    nElements_initial = mesh.nElements_global
    mesh.convertFromPUMI(domain.PUMIMesh,
                         domain.faceList,
                         domain.regList,
                         parallel=comm.size() > 1,
                         dim=domain.nd)

    domain.PUMIMesh.transferFieldToPUMI("coordinates", mesh.nodeArray)

    rho = numpy.array([998.2, 998.2])
    nu = numpy.array([1.004e-6, 1.004e-6])
    g = numpy.asarray([0.0, 0.0, 0.0])
    deltaT = 1.0  #dummy number
    domain.PUMIMesh.transferPropertiesToPUMI(rho, nu, g, deltaT)

    #Poiseuille Flow
    Ly = 0.2
    Lz = 0.05
    Re = 100
    Umax = Re * nu[0] / Lz

    def vOfX(x):
        return 4 * Umax / (Lz**2) * (x[2]) * (Lz - x[2])

    def dvOfXdz(x):
        return 4 * Umax / (Lz**2) * (Lz - 2 * x[2])

    #hard code solution
    vector = numpy.zeros((mesh.nNodes_global, 3), 'd')
    dummy = numpy.zeros(mesh.nNodes_global)

    vector[:, 0] = dummy
    vector[:, 1] = 4 * Umax / (Lz**2) * (mesh.nodeArray[:, 2]) * (
        Lz - mesh.nodeArray[:, 2])  #v-velocity
    vector[:, 2] = dummy
    domain.PUMIMesh.transferFieldToPUMI("velocity", vector)

    scalar = numpy.zeros((mesh.nNodes_global, 1), 'd')
    domain.PUMIMesh.transferFieldToPUMI("p", scalar)

    scalar[:, 0] = mesh.nodeArray[:, 2]
    domain.PUMIMesh.transferFieldToPUMI("phi", scalar)
    del scalar

    scalar = numpy.zeros((mesh.nNodes_global, 1), 'd') + 1.0
    domain.PUMIMesh.transferFieldToPUMI("vof", scalar)

    errorTotal = domain.PUMIMesh.get_local_error()

    # load the femspace with linear basis and get the quadrature points on a reference element
    elementQuadrature = Quadrature.SimplexGaussQuadrature(domain.nd, 3)

    ok(mesh.nNodes_element == 4)  #confirm all of the elements have 4 nodes

    #hard code computation for H1 seminorm; ideally will be reformatted using the classes within proteus
    derivativeArrayRef = [[1, 0, 0], [0, 1, 0], [0, 0, 1], [-1, -1, -1]]
    error = 0
    for eID in range(mesh.nElements_global):
        nodes = mesh.elementNodesArray[eID]
        coords = []
        for i in range(mesh.nNodes_element):
            coords.append(mesh.nodeArray[nodes[i]])
        J = numpy.matrix([[
            coords[0][0] - coords[3][0], coords[1][0] - coords[3][0],
            coords[2][0] - coords[3][0]
        ],
                          [
                              coords[0][1] - coords[3][1],
                              coords[1][1] - coords[3][1],
                              coords[2][1] - coords[3][1]
                          ],
                          [
                              coords[0][2] - coords[3][2],
                              coords[1][2] - coords[3][2],
                              coords[2][2] - coords[3][2]
                          ]])
        invJ = J.I
        detJ = numpy.linalg.det(J)
        gradPhi_h = 0
        for k in range(len(elementQuadrature.points)):
            tempQpt = 0
            zCoord = elementQuadrature.points[k][0]*coords[0][2] \
                +elementQuadrature.points[k][1]*coords[1][2] \
                +elementQuadrature.points[k][2]*coords[2][2] \
                +(1-elementQuadrature.points[k][0]-elementQuadrature.points[k][1]-elementQuadrature.points[k][2])*coords[3][2]
            for i in range(mesh.nNodes_element):
                temp = 0
                for j in range(domain.nd):
                    temp = temp + derivativeArrayRef[i][j] * invJ[j, 2]
                tempQpt = tempQpt + vector[nodes[i]][1] * temp
            exactgradPhi = dvOfXdz([0, 0, zCoord])
            gradPhi_h = gradPhi_h + tempQpt
            error = error + (exactgradPhi - gradPhi_h
                             )**2 * elementQuadrature.weights[k] * abs(detJ)

    error = sqrt(error)
    ok(error < errorTotal)
Esempio n. 27
0
parallelPartitioningType = proteus.MeshTools.MeshParallelPartitioningTypes.node
nLayersOfOverlapForParallel = 0
use_petsc4py=True#False

if useHex: 
    hex=True 

    comm=Comm.get()	
    if comm.isMaster():	
        size = numpy.array([[0.520,0.510   ,0.520],
	                    [0.330,0.335833,0.330],
			    [0.320,0.325   ,0.000]])/float(Refinement)
        numpy.savetxt('size.mesh', size)
        failed = os.system("../../scripts/marinHexMesh")      
     
    domain = Domain.MeshHexDomain("marinHex") 
else:
    L      = [3.22,1.0,1.0]
    box_L  = [0.161,0.403,0.161]
    box_xy = [2.3955,0.2985]
    #he = L[0]/float(6.5*Refinement)
    he = L[0]/64.0
    he*=0.5#256
    boundaries=['left','right','bottom','top','front','back','box_left','box_right','box_top','box_front','box_back',]
    boundaryTags=dict([(key,i+1) for (i,key) in enumerate(boundaries)])
    bt = boundaryTags
    holes = [[0.5*box_L[0]+box_xy[0],0.5*box_L[1]+box_xy[1],0.5*box_L[2]]]
    vertices=[[0.0,0.0,0.0],#0
              [L[0],0.0,0.0],#1
              [L[0],L[1],0.0],#2
              [0.0,L[1],0.0],#3
Esempio n. 28
0
rho_0 = 998.2
nu_0 = 1.004e-6

# Air
rho_1 = 1.205
nu_1 = 1.500e-5

g = [0., -9.81, 0.]
# ****************** #
# ***** GAUGES ***** #
# ****************** #

# *************************** #
# ***** DOMAIN AND MESH ***** #
# ****************** #******* #
domain = Domain.PlanarStraightLineGraphDomain()

# ----- TANK ----- #
boundaryOrientations = {
    'y-': np.array([0., -1., 0.]),
    'x+': np.array([+1., 0., 0.]),
    'y+': np.array([0., +1., 0.]),
    'x-': np.array([-1., 0., 0.]),
    'airvent': np.array([-1., 0., 0.]),
}
boundaryTags = {
    'y-': 1,
    'x+': 2,
    'y+': 3,
    'x-': 4,
    'airvent': 5,
he = L[0]/float(4*Refinement-1)
#he*=0.5
#he*=0.5
#he*=0.5
#he*=0.5
weak_bc_penalty_constant = 100.0
nLevels = 1
#parallelPartitioningType = proteus.MeshTools.MeshParallelPartitioningTypes.element
parallelPartitioningType = proteus.MeshTools.MeshParallelPartitioningTypes.node
nLayersOfOverlapForParallel = 0
structured=False  
if useHex:   
    nnx=4*Refinement+1
    nny=2*Refinement+1
    hex=True    
    domain = Domain.RectangularDomain(L)
else:
    boundaries=['left','right','bottom','top','front','back']
    boundaryTags=dict([(key,i+1) for (i,key) in enumerate(boundaries)])
    if structured:
        nnx=4*Refinement
        nny=2*Refinement
    else:
        vertices=[[0.0,0.0],#0
                  [L[0],0.0],#1
                  [L[0],L[1]],#2
                  [0.0,L[1]]]#3
        vertexFlags=[boundaryTags['bottom'],
                     boundaryTags['bottom'],
                     boundaryTags['top'],
                     boundaryTags['top']]
Esempio n. 30
0
def test_2DgmshLoadAndAdapt(verbose=0):
    """Test for loading gmsh mesh through PUMI, estimating error and adapting for 
    a 2D Couette flow case"""
    testDir=os.path.dirname(os.path.abspath(__file__))
    Model=testDir + '/Couette2D.null'
    Mesh=testDir + '/Couette2D.msh'
    domain = Domain.PUMIDomain(dim=2) #initialize the domain
    domain.PUMIMesh=MeshAdaptPUMI.MeshAdaptPUMI(hmax=0.01, hmin=0.008, numIter=1,sfConfig=b'ERM',maType=b'isotropic',targetError=1)
    domain.PUMIMesh.loadModelAndMesh(bytes(Model,'utf-8'), bytes(Mesh,'utf-8'))
    domain.faceList=[[14],[12],[11],[13]]
    domain.boundaryLabels=[1,2,3,4]

    mesh = MeshTools.TriangularMesh()
    mesh.cmesh = cmeshTools.CMesh()
    comm = Comm.init()

    nElements_initial = mesh.nElements_global
    mesh.convertFromPUMI(domain,domain.PUMIMesh, domain.faceList,domain.regList, parallel = comm.size() > 1, dim = domain.nd)

    domain.PUMIMesh.transferFieldToPUMI(b"coordinates",mesh.nodeArray)

    rho = numpy.array([998.2,998.2])
    nu = numpy.array([1.004e-6, 1.004e-6])
    g = numpy.asarray([0.0,0.0])
    deltaT = 1.0 #dummy number
    epsFact = 1.0 #dummy number
    domain.PUMIMesh.transferPropertiesToPUMI(rho,nu,g,deltaT,epsFact)

    #Couette Flow
    Lz = 0.05
    Uinf = 2e-3
    #hard code solution
    vector=numpy.zeros((mesh.nNodes_global,3),'d')
    dummy = numpy.zeros(mesh.nNodes_global); 
    vector[:,0] = Uinf*mesh.nodeArray[:,1]/Lz #v-velocity
    vector[:,1] = dummy
    vector[:,2] = dummy
    domain.PUMIMesh.transferFieldToPUMI(b"velocity", vector)
    del vector
    del dummy

    scalar=numpy.zeros((mesh.nNodes_global,1),'d')
    domain.PUMIMesh.transferFieldToPUMI(b"p", scalar)

    scalar[:,0] = mesh.nodeArray[:,1]
    domain.PUMIMesh.transferFieldToPUMI(b"phi", scalar)
    del scalar

    scalar = numpy.zeros((mesh.nNodes_global,1),'d')+1.0
    domain.PUMIMesh.transferFieldToPUMI(b"vof", scalar)

    errorTotal=domain.PUMIMesh.get_local_error()
    ok(errorTotal<1e-14)

    #ok(domain.PUMIMesh.willAdapt(),1)

    domain.PUMIMesh.adaptPUMIMesh()
    
    mesh = MeshTools.TriangularMesh()
    mesh.convertFromPUMI(domain,domain.PUMIMesh,
                     domain.faceList,
                     domain.regList,
                     parallel = comm.size() > 1,
                     dim = domain.nd)
    nElements_final = mesh.nElements_global
    ok(nElements_final>nElements_initial)