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)
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
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
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
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
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
def gl_3_3d(width, h=10.0): """ A 3d levee profile for the sacramento levee modeling """ boundaryLegend = { 'left': 1, 'right': 2, 'front': 3, 'back': 4, 'bottom': 5, 'top': 6, 'inner': 0 } vertices_front = [ [0.0, 0.0, 0.0], #0 [0.0, 0.0, h], #1 [0.0, 0.0, 2 * h], #2 [0.6 * h, 0.0, 2 * h], #3 [0.8 * h, 0.0, 2 * h], #4 [2.0 * h, 0.0, 2 * h], #5 [4.0 * h, 0.0, h], #6 [5.2 * h, 0.0, h], #7 [5.4 * h, 0.0, h], #8 [6.0 * h, 0.0, h], #9 [6.0 * h, 0.0, 0], #10 [0.8 * h + 2 * (2 * h - 0.6 * h), 0.0, 0.6 * h], #11 [5.2 * h - 0.4 * h, 0.0, 0.6 * h], #12 [5.2 * h - 0.4 * h, 0.0, 0.4 * h], #13 [0.6 * h + 2.0 * (2.0 * h - 0.4 * h), 0.0, 0.4 * h] ] #14 vertexFlags_front = [ boundaryLegend['left'], boundaryLegend['left'], boundaryLegend['left'], boundaryLegend['top'], boundaryLegend['top'], boundaryLegend['top'], boundaryLegend['top'], boundaryLegend['top'], boundaryLegend['top'], boundaryLegend['right'], boundaryLegend['right'], boundaryLegend['inner'], boundaryLegend['inner'], boundaryLegend['inner'], boundaryLegend['inner'] ] 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, 14, 13, 8, 9, 10]], #front 1 [[3, 4, 11, 12, 7, 8, 13, 14]], #front 2 [[4, 5, 6, 7, 12, 11]], #front 3 [[15, 16, 17, 18, 29, 28, 23, 24, 25]], #back 1 [[18, 19, 26, 27, 22, 23, 28, 29]], #back 2 [[19, 20, 21, 22, 27, 26]], #back 3 [[0, 1, 2, 17, 16, 15]], #left [[10, 9, 24, 25]], #right [[0, 15, 25, 10]], #bottom [[2, 17, 18, 3]], #top 1 [[3, 18, 19, 4]], #top 2 [[4, 19, 20, 5]], #top 3 [[5, 20, 21, 6]], #top 4 [[6, 21, 22, 7]], #top 5 [[7, 22, 23, 8]], #top 6 [[8, 23, 24, 9]], #top 7 [[3, 18, 29, 14]], #innner left [[4, 19, 26, 11]], #innner right [[11, 26, 27, 12]], #inner top [[14, 29, 28, 13]], #inner bottom [[12, 27, 22, 7]], #inner left top [[13, 28, 23, 8]] ] #inner right bottom facetFlags = [ boundaryLegend['front'], boundaryLegend['front'], boundaryLegend['front'], boundaryLegend['back'], boundaryLegend['back'], boundaryLegend['back'], boundaryLegend['left'], boundaryLegend['right'], boundaryLegend['bottom'], boundaryLegend['top'], boundaryLegend['top'], boundaryLegend['top'], boundaryLegend['top'], boundaryLegend['top'], boundaryLegend['top'], boundaryLegend['top'], boundaryLegend['inner'], boundaryLegend['inner'], boundaryLegend['inner'], boundaryLegend['inner'], boundaryLegend['inner'], boundaryLegend['inner'] ] regions = [[h / 2.0, width / 2.0, h / 2], [4.0 * h, width / 2.0, 0.5 * h], [4.0 * h, width / 2.0, 0.75 * h]] regionFlags = [1, 2, 3] domain = Domain.PiecewiseLinearComplexDomain(vertices=vertices, vertexFlags=vertexFlags, facets=facets, facetFlags=facetFlags, regions=regions, regionFlags=regionFlags) domain.boundaryFlags = boundaryLegend domain.regionLegend = { 'levee': 1, 'leveeFace': 3, 'defect': 2, 'default': 0 } return domain
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 # 2d case 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 = (old_div((dim[0]**2),12.)) Iy = (old_div((dim[1]**2),12.)) It = Ix + Iy mass = 50.0 I1 = It*mass c2d.mass = mass c2d.It = It I2 = c2d.getInertia() npt.assert_equal(I1, I2) # 3d case pos, dim, caisson = [], [], [] domain3D = Domain.PiecewiseLinearComplexDomain() pos = np.array([0.0, 0.0, 0.0]) dim = (0.3, 0.385, 0.4) angle = radians(10.) Ix = (old_div((dim[0]**2),12.)) Iy = (old_div((dim[1]**2),12.)) Iz = (old_div((dim[2]**2),12.)) It = np.array([ [Iz + Iy, 0.0, 0.0], [0.0, Ix + Iz, 0.0], [0.0, 0.0, Ix + Iy] ]) mass = 50.0 # rotational axis and versors ax, ay, az = axis = np.array([1., 1., 1.]) mod = np.sqrt((ax**2)+(ay**2)+(az**2)) axis_ver = (old_div(axis,mod)) # shape caisson = mst.Cuboid(domain=domain3D, dim=dim, coords=[pos[0], pos[1], pos[2]]) caisson.rotate(rot=angle, axis=axis) coords_system = caisson.coords_system caisson3D = bd.RigidBody(shape=caisson) mst.assembleDomain(domain3D) # rotational operator for inertia calculation on an arbitrary axis rotx, roty, rotz = np.dot(axis_ver, np.linalg.inv(coords_system)) rot = np.array([ [(rotx**2), rotx*roty, rotx*rotz], [roty*rotx, (roty**2), roty*rotz], [rotz*rotx, rotz*roty, (rotz**2)] ]) #inertia = np.einsum('ij,ij->', mass*It, rot) inertia = np.sum(mass*It*rot) # testing from BodyDynamics c3d = caisson3D c3d.nd = 3 c3d.mass = mass c3d.It = It c3d.coords_system = coords_system I = c3d.getInertia(vec=axis) npt.assert_equal(I, inertia)
def gl_6_3d(width): """ A 3d levee profile for the sacramento levee modeling """ boundaryLegend = { 'left': 1, 'right': 2, 'front': 3, 'back': 4, 'bottom': 5, 'top': 6, 'leftTop': 7, 'rightTop': 8 } vertices_front = [ [0.0, 0.0, 0.0], #0 [0.0, 0.0, 7.3], #1 [33.5, 0.0, 7.3], #2 [33.5 + old_div(21.3, tan(2.0 * pi * 18.0 / 360.0)), 0.0, 7.3 + 21.3], #3 [ 33.5 + old_div(21.3, tan(2.0 * pi * 18.0 / 360.0)) + 7.3, 0.0, 7.3 + 21.3 ], #4 [33.5 + 124.4, 0.0, 7.3], #5 [2 * 33.5 + 124.4, 0.0, 7.3], #6 [2 * 33.5 + 124.4, 0.0, 0.0] ] #7 vertexFlags_front = [ boundaryLegend['left'], #0 boundaryLegend['left'], #1 boundaryLegend['leftTop'], #2 boundaryLegend['leftTop'], #3 boundaryLegend['rightTop'], #4 boundaryLegend['rightTop'], #5 boundaryLegend['right'], #6 boundaryLegend['right'] ] #7 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, 4, 5, 6, 7]], #front [[8, 9, 10, 11, 12, 13, 14, 15]], #back [[0, 1, 9, 8]], #left [[1, 9, 10, 2]], #leftTop1 [[2, 10, 11, 3]], #leftTop2 [[3, 11, 12, 4]], #top [[4, 12, 13, 5]], #rightTop2 [[5, 13, 14, 6]], #rightTop1 [[6, 14, 15, 7]], #right [[0, 8, 15, 7]] ] #bottom facetFlags = [ boundaryLegend['front'], boundaryLegend['back'], boundaryLegend['left'], boundaryLegend['leftTop'], boundaryLegend['leftTop'], boundaryLegend['top'], boundaryLegend['rightTop'], boundaryLegend['rightTop'], boundaryLegend['right'], boundaryLegend['bottom'] ] regions = [[0.001, 0.001, 0.001]] 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
def beach_erosion_board_with_sponge_layer_3d(spongeLayerWidth=0.2, domainHeightPad=2.0, inflowLength=2.0, beachLength=4.48, beachSlope =0.1, h_c=0.054, h_s=0.081, s =3.0, B = 0.0896, s_2= -0.2, backStepFraction=0.25, outflowLength=0.5, width = 0.5): """ generate waves and runup on WES beach erosion board embankment units should be meters by default z=0 beach slope (1/10) 1/s slope 1/s_2 slope |--------|----------------|-----------|-------|-----------|-----| 0 x_bs x_be x_se x_ce x_bse L x_bs = inflow pad (2 [m] default), z(x) = 0, [0,x_bs] x_be = x_bs + beachLength (4.48 [m]) z(x) = 0.0 + (x-x_bs)beachSlope, [x_bs,x_be] x_se = x_be + (h_c + h_s)*s, h_c and h_s from Sitanggang Lynnett report z(x) = (x-x_be)1/s + z(x_be), [x_be,x_se] x_ce = x_se + B [m] z(x) = z(x_se), [x_se,x_ce] x_bse= x_ce + (h_c + h_s)*backStepFraction*s_2 z(x) = z(x_ce) + (x-x_ce)*1/s_2 [x_ce,x_bse] x_L = x_bse + outflowLength [m] z(x) = z(x_bse), [x_bse,L] total domain height = z(x_se) + domainHeightPad """ #describe bathymetry as above x_0 = 0.0 x_sl = x_0 + spongeLayerWidth x_bs = x_0 + inflowLength; x_be = x_bs + beachLength x_se = x_be + (h_c+h_s)*s x_ce = x_se + B x_bse= x_ce + (h_c+h_s)*backStepFraction*abs(s_2) def bathymetry(x): if x[0] <= x_bs: return 0.0 if x[0] <= x_be: return 0.0 + (x[0]-x_bs)*beachSlope if x[0] <= x_se: return bathymetry([x_be]) + (x[0]-x_be)/s if x[0] <= x_ce: return bathymetry([x_se]) if x[0] <= x_bse: return bathymetry([x_ce]) + (x[0]-x_ce)/s_2 return bathymetry([x_bse]) def bathymetryGrad(x): if x[0] <= x_bs: return (0.0,0.0) if x[0] <= x_be: return (beachSlope,0.0) #beach slope if x[0] <= x_se: return (1.0/s,0.0) if x[0] <= x_ce: return (0.0,0.0) if x[0] <= x_bse: return (1./s_2,0.0) return (0.0,0.0) x_L = x_bse + outflowLength z_L = bathymetry([x_se]) + domainHeightPad L = [x_L,width,z_L] #xpoints = [x_0,x_bs,x_be,x_se,x_ce,x_bse,x_L] xpoints = [x_0,x_sl,x_bs,x_be,x_se,x_ce,x_bse,x_L] zpoints = [bathymetry([x]) for x in xpoints] bathymetryPoints = [[x,0.0,z] for x,z in zip(xpoints,zpoints)] backHeight = bathymetry([x_bse]) #have to assume points in correct order #pad for inflow outflow pSW = bathymetryPoints[0] pSE= bathymetryPoints[-1] #now get top corners of domain minY = 0.0 pNW = [pSW[0],0.0,minY+z_L] pNE = [pSE[0],0.0,minY+z_L] pSpongeTop = [x_sl,0.0,minY+z_L] #check vertical coordinates tmp = sorted(bathymetryPoints,cmp=lambda x,y: int(x[2]-y[2])) assert minY <= tmp[0][1], "found point below proposed block floor minY=%s tmp[0]= " % (minY,tmp[0]) assert minY+ z_L > tmp[-1][1], "found point above proposed block ceiling maxnY=%s tmp[-1]= " % (minY+z_L, tmp[-1]) frontVertices = [p for p in bathymetryPoints] #start with NW corner and work way around #left frontVertices.insert(0,pNW) frontVertices.append(pNE) frontVertices.append(pSpongeTop) nfrontVertices = len(frontVertices) backVertices = [[v[0],width,v[2]] for v in frontVertices] vertices = frontVertices+backVertices boundaries=['left','right','bottom','top','front','back','sponge'] boundaryTags=dict([(key,i+1) for (i,key) in enumerate(boundaries)]) facets = [] facetFlags=[] front_facets=[[vN for vN in range(nfrontVertices)]] facets.append(front_facets) facetFlags.append(boundaryTags['front']) back_facets=[[vN for vN in range(nfrontVertices,2*nfrontVertices)]] facets.append(back_facets) facetFlags.append(boundaryTags['back']) top_facets=[[vN for vN in [0,nfrontVertices-1,nfrontVertices*2-1,nfrontVertices]]]#[[vN for vN in range(0,nfrontVertices+1)]] facets.append(top_facets) facetFlags.append(boundaryTags['top']) right_facets=[[vN for vN in [nfrontVertices-2,nfrontVertices-1,2*nfrontVertices-1,2*nfrontVertices-2]]]#[[vN for vN in range(1,1+(nfrontVertices+1))]] facets.append(right_facets) facetFlags.append(boundaryTags['right']) left_facets=[[vN for vN in [0,nfrontVertices,nfrontVertices+1,1]]] facets.append(left_facets) facetFlags.append(boundaryTags['left']) for vN in range(1,nfrontVertices-2): bottom_facet=[[vN,vN+1,vN+1+nfrontVertices,vN+nfrontVertices]] facets.append(bottom_facet) facetFlags.append(boundaryTags['bottom']) #sponge layer boundary sponge_facets=[[vN for vN in [2,2+nfrontVertices,2*nfrontVertices-1,nfrontVertices-1]]] facets.append(sponge_facets) facetFlags.append(boundaryTags['sponge']) fluid_center = [0.5*(x_sl+x_bs),0.5*width,0.5*domainHeightPad] sponge_center= [0.5*(x_0+x_sl),0.5*width,0.5*domainHeightPad] regions = [fluid_center,sponge_center] regionFlags = [0,1] domain = Domain.PiecewiseLinearComplexDomain(vertices=vertices, facets=facets, facetFlags=facetFlags, regions=regions, regionFlags=regionFlags) domain.backHeight = backHeight domain.backHeight = backHeight domain.x_0 = x_0; domain.x_be= x_be domain.x_bs= x_bs; domain.x_se= x_se domain.x_ce= x_ce; domain.x_bse=x_bse domain.inflowLength= inflowLength; domain.beachLength = beachLength domain.s = s; domain.B = B; domain.s_2 = s_2 domain.h_c= h_c; domain.h_s = h_s domain.bathymetry = bathymetry ; domain.bathymetryGrad = bathymetryGrad #go ahead and add a boundary tags member domain.boundaryTags = boundaryTags return domain
def get_domain_one_box_with_one_shelf(x0=(0.0, 0.0, 0.0), L=(1.0, 1.0, 1.0), he=0.001, he2=None, he3=None, L1=None, L2=None): 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]) if L1 == None: L1 = 0.4 * L[1] if L2 == None: L2 = 0.6 * L[1] x2 = (x0[0], x0[1] + L1, x0[2]) x3 = (x1[0], x0[1] + L2, x1[2]) if he2 == None: he2 = he if he3 == None: he3 = he2 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]), (x2[0], x2[1], x2[2]), (x3[0], x2[1], x2[2]), (x3[0], x3[1], x2[2]), (x2[0], x3[1], x2[2]), (x2[0], x2[1], x3[2]), (x3[0], x2[1], x3[2]), (x3[0], x3[1], x3[2]), (x2[0], x3[1], x3[2])] vertexFlags = [ boundaryTags['bottom'], boundaryTags['bottom'], boundaryTags['top'], boundaryTags['top'], boundaryTags['bottom'], boundaryTags['bottom'], boundaryTags['top'], boundaryTags['top'], 0, 0, 0, 0, 0, 0, 0, 0, ] planes = [] planeFlags = [] planeHolds = [] planes.extend([[[0, 1, 9, 10, 2, 3, 11, 8], [8, 9], [10, 11]], [[4, 5, 13, 14, 6, 7, 15, 12], [12, 13], [14, 15]], [[0, 8, 11, 3, 7, 15, 12, 4], [8, 12], [15, 11]], [[1, 9, 10, 2, 6, 14, 13, 5], [9, 13], [14, 10]], [[0, 1, 5, 4]], [[2, 3, 7, 6]]]) planeFlags.extend([ boundaryTags['back'], boundaryTags['front'], boundaryTags['left'], boundaryTags['right'], boundaryTags['bottom'], boundaryTags['top'], ]) planeHolds.extend([[], [], [], [], [], []]) planes.extend([ [[10, 11, 15, 14]], [[8, 9, 13, 12]], ]) planeFlags.extend([0, 0]) planeHolds.extend([ [], [], ]) regions = [ (0.5 * (x0[0] + x1[0]), 0.5 * (x0[1] + x2[1]), 0.5 * (x0[2] + x1[2])), (0.5 * (x0[0] + x1[0]), 0.5 * (x2[1] + x3[1]), 0.5 * (x0[2] + x1[2])), (0.5 * (x0[0] + x1[0]), 0.5 * (x3[1] + x1[1]), 0.5 * (x0[2] + x1[2])) ] regionFlags = [1, 2, 3] regionConstraints = [ 0.5 * he**2, 0.5 * (he2)**2, 0.5 * (he3)**2, ] domain = Domain.PiecewiseLinearComplexDomain( vertices=vertices, facets=planes, facetFlags=planeFlags, facetHoles=planeHolds, regions=regions, regionFlags=regionFlags, regionConstraints=regionConstraints) return domain, boundaryTags, x0, x1, x2, x3
def cylinder3d(fileprefix, height=1.0, length=1.0, width=1.0, radius=0.1, center=(0.5, 0.5, 0.5), n_points_on_obstacle=2 * 21 - 2, cross_section=circular_cross_section, thetaOffset=0.0): boundaries = [ 'upstream', 'downstream', 'bottom', 'top', 'front', 'back', 'obstacle' ] boundaryTags = dict([(key, i + 1) for (i, key) in enumerate(boundaries)]) #work around the domain from (0.0,0.0) going counterclockwise vertexKeys = [ 'upstream_bottom', 'downstream_bottom', 'downstream_top', 'upstream_top' ] vertices = [[0.0, 0.0], [length, 0.0], [length, height], [0.0, height]] vertexFlags = [ boundaryTags['bottom'], boundaryTags['bottom'], boundaryTags['top'], boundaryTags['top'] ] nv = len(vertices) #cylinder theta = thetaOffset pb = cross_section(center, radius, theta) vertices.append([pb[0], pb[1]]) vertexKeys.append('obstacle_' + ` 0 `) 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 + thetaOffset pb = cross_section(center, radius, theta) vertexKeys.append('obstacle_' + ` gb `) vertices.append([pb[0], pb[1]]) vertexFlags.append(boundaryTags['obstacle']) #now need to convert rep to 3D vertices3dDict = {} vertices3d = [] vertexFlags3d = [] facets3d = [] facetFlags3d = [] facetHoles3d = [] front_cylinder = [] back_cylinder = [] for vN, v in enumerate(vertices): vertices3dDict[vertexKeys[vN] + '_front'] = vN vertices3d.append([v[0], 0.0, v[1]]) vertexFlags3d.append(vertexFlags[vN]) if 'obstacle' in vertexKeys[vN]: front_cylinder.append(vN) for vN, v in enumerate(vertices): vertices3dDict[vertexKeys[vN] + '_back'] = vN + len(vertices) vertices3d.append([v[0], width, v[1]]) vertexFlags3d.append(vertexFlags[vN]) if 'obstacle' in vertexKeys[vN]: back_cylinder.append(vN + len(vertices)) #upstream facets3d.append([[ vertices3dDict['upstream_bottom_front'], vertices3dDict['upstream_bottom_back'], vertices3dDict['upstream_top_back'], vertices3dDict['upstream_top_front'] ]]) facetFlags3d.append(boundaryTags['upstream']) facetHoles3d.append([]) #downstream facets3d.append([[ vertices3dDict['downstream_bottom_front'], vertices3dDict['downstream_bottom_back'], vertices3dDict['downstream_top_back'], vertices3dDict['downstream_top_front'] ]]) facetFlags3d.append(boundaryTags['downstream']) facetHoles3d.append([]) #top facets3d.append([[ vertices3dDict['upstream_top_front'], vertices3dDict['downstream_top_front'], vertices3dDict['downstream_top_back'], vertices3dDict['upstream_top_back'] ]]) facetFlags3d.append(boundaryTags['top']) facetHoles3d.append([]) #bottom facets3d.append([[ vertices3dDict['upstream_bottom_front'], vertices3dDict['downstream_bottom_front'], vertices3dDict['downstream_bottom_back'], vertices3dDict['upstream_bottom_back'] ]]) facetFlags3d.append(boundaryTags['bottom']) facetHoles3d.append([]) #front facets3d.append([[ vertices3dDict['upstream_bottom_front'], vertices3dDict['downstream_bottom_front'], vertices3dDict['downstream_top_front'], vertices3dDict['upstream_top_front'] ], front_cylinder]) facetFlags3d.append(boundaryTags['front']) facetHoles3d.append([(center[0], 0.0, center[2])]) #back facets3d.append([[ vertices3dDict['upstream_bottom_back'], vertices3dDict['downstream_bottom_back'], vertices3dDict['downstream_top_back'], vertices3dDict['upstream_top_back'] ], back_cylinder]) facetFlags3d.append(boundaryTags['back']) facetHoles3d.append([(center[0], width, center[2])]) #cylinder for fN in range(n_points_on_obstacle - 1): facets3d.append([[ front_cylinder[fN], back_cylinder[fN], back_cylinder[fN + 1], front_cylinder[fN + 1] ]]) facetFlags3d.append(boundaryTags['obstacle']) facetHoles3d.append([]) facets3d.append([[ front_cylinder[-1], back_cylinder[-1], back_cylinder[0], front_cylinder[0] ]]) facetFlags3d.append(boundaryTags['obstacle']) facetHoles3d.append([]) print vertices3d, vertexFlags3d, facets3d, facetFlags3d, facetHoles3d domain = Domain.PiecewiseLinearComplexDomain(vertices=vertices3d, vertexFlags=vertexFlags3d, facets=facets3d, facetFlags=facetFlags3d, facetHoles=facetHoles3d) domain.boundaryTags = boundaryTags return domain
if quasi2D: width = he L = [length, width, downstream_height] polyfile = "step3d" boundaryTags = step3d.genPoly(fileprefix=polyfile, width=width, upstream_height=upstream_height, downstream_height=downstream_height, upstream_length=upstream_length, downstream_length=downstream_length, step_fun=step3d.linear_profile, n_points_on_step=2, step_length=0.0) domain = Domain.PiecewiseLinearComplexDomain(fileprefix=polyfile) #go ahead and add a boundary tags member domain.boundaryTags = boundaryTags domain.writePoly("mesh") domain.writePLY("mesh") domain.writeAsymptote("mesh") triangleOptions = "VApq1.25q12ena%e" % ((he**3) / 6.0, ) # nLevels = 1 parallelPartitioningType = proteus.MeshTools.MeshParallelPartitioningTypes.element nLayersOfOverlapForParallel = 0 #---------------------------------------------------- # Physical coefficients #---------------------------------------------------- Re = 20000.0 #3025.0
def wigley3d(fileprefix, height=10.0, length=100.0, width=25.0, hull_beam=10.0, hull_draft=8.0, hull_length=50.0, hull_center=(100.0 / 2.0, 25.0 / 2.0, 10.0 / 2.0), n_points_draft=3, n_points_length=3): boundaries = [ 'left', 'right', 'bottom', 'top', 'front', 'back', 'obstacle' ] boundaryTags = dict([(key, i + 1) for (i, key) in enumerate(boundaries)]) #work around the domain from (0.0,0.0) going counterclockwise vertices = [ [0.0, 0.0, 0.0], #0 [length, 0.0, 0.0], #1 [length, 0.0, height], #2 [0.0, 0.0, height], #3 [0.0, width, 0.0], #4 [length, width, 0.0], #5 [length, width, height], #6 [0.0, width, height] ] #7 vertexFlags = [ boundaryTags['bottom'], boundaryTags['bottom'], boundaryTags['top'], boundaryTags['top'], boundaryTags['bottom'], boundaryTags['bottom'], boundaryTags['top'], boundaryTags['top'] ] facets = [ [[0, 1, 2, 3]], #front [[4, 5, 6, 7]], #back [[0, 1, 5, 4]], #bottom [[2, 3, 7, 6]], #top [[0, 3, 7, 4]], #left [[1, 2, 6, 5]] ] #right facetFlags = [ boundaryTags['front'], boundaryTags['back'], boundaryTags['bottom'], boundaryTags['top'], boundaryTags['left'], boundaryTags['right'] ] holes = [] #wigley hull parameters dx = hull_length / float(n_points_length - 1) dz = hull_draft / float(n_points_draft - 1) #grid on right half of hull for i in range(n_points_length): for j in range(n_points_draft): x = i * dx z = j * dz y = 0.5 * hull_beam * (1.0 - (2.0 * (x - 0.5 * hull_length) / hull_length)** 2) * (1.0 - ((hull_draft - z) / hull_draft)**2) vertices.append([ x + hull_center[0] - 0.5 * hull_length, y + hull_center[1], z + hull_center[2] - 0.5 * hull_draft ]) vertexFlags.append(boundaryTags['obstacle']) def vN_right(i, j): return 8 + i * n_points_draft + j for i in range(n_points_length - 1): for j in range(n_points_draft - 1): if i < n_points_length / 2: facets.append([[ vN_right(i, j), vN_right(i + 1, j + 1), vN_right(i + 1, j) ]]) facetFlags.append(boundaryTags['obstacle']) facets.append([[ vN_right(i, j), vN_right(i, j + 1), vN_right(i + 1, j + 1) ]]) facetFlags.append(boundaryTags['obstacle']) else: facets.append( [[vN_right(i, j), vN_right(i, j + 1), vN_right(i + 1, j)]]) facetFlags.append(boundaryTags['obstacle']) facets.append([[ vN_right(i, j + 1), vN_right(i + 1, j + 1), vN_right(i + 1, j) ]]) facetFlags.append(boundaryTags['obstacle']) #grid on left half of hull for i in range(1, n_points_length - 1): for j in range(1, n_points_draft): x = i * dx z = j * dz y = 0.5 * hull_beam * (1.0 - (2.0 * (x - 0.5 * hull_length) / hull_length)** 2) * (1.0 - ((hull_draft - z) / hull_draft)**2) vertices.append([ x + hull_center[0] - 0.5 * hull_length, hull_center[1] - y, z + hull_center[2] - 0.5 * hull_draft ]) vertexFlags.append(boundaryTags['obstacle']) def vN_left(i, j): if i == 0 or j == 0: return vN_right(i, j) if i == (n_points_length - 1): # or j==(n_points_draft-1): return vN_right(i, j) else: return 8 + n_points_length * n_points_draft + (i - 1) * ( n_points_draft - 1) + j - 1 for i in range(n_points_length - 1): for j in range(n_points_draft - 1): if i < n_points_length / 2: facets.append( [[vN_left(i, j), vN_left(i + 1, j + 1), vN_left(i + 1, j)]]) facetFlags.append(boundaryTags['obstacle']) facets.append( [[vN_left(i, j), vN_left(i, j + 1), vN_left(i + 1, j + 1)]]) facetFlags.append(boundaryTags['obstacle']) else: facets.append( [[vN_left(i, j), vN_left(i, j + 1), vN_left(i + 1, j)]]) facetFlags.append(boundaryTags['obstacle']) facets.append([[ vN_left(i, j + 1), vN_left(i + 1, j + 1), vN_left(i + 1, j) ]]) facetFlags.append(boundaryTags['obstacle']) topFacet = [] for i in range(n_points_length): topFacet.append(vN_right(i, n_points_draft - 1)) for i in range(n_points_length - 1, 0, -1): topFacet.append(vN_left(i, n_points_draft - 1)) facets.append([topFacet]) facetFlags.append(boundaryTags['obstacle']) #for v in vertices: print v #for f in facets: print f holes.append(hull_center) domain = Domain.PiecewiseLinearComplexDomain(vertices=vertices, vertexFlags=vertexFlags, facets=facets, facetFlags=facetFlags, holes=holes) domain.boundaryTags = boundaryTags return domain
def boxesInTank3d(L=[1.0,1.0,1.0], nBoxes_xy=[10,10], boxScale=[0.5,0.5,0.35], random_height=False): rg = random.Random() boundaries=['upstream','downstream','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 # [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['upstream'], boundaryTags['downstream'], boundaryTags['downstream'], boundaryTags['upstream'], boundaryTags['upstream'], boundaryTags['downstream'], boundaryTags['downstream'], boundaryTags['upstream']] # boundaryTags['obstacle'], # boundaryTags['obstacle'], # boundaryTags['obstacle'], # boundaryTags['obstacle'], # boundaryTags['obstacle'], # boundaryTags['obstacle'], # boundaryTags['obstacle'], # boundaryTags['obstacle']] 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]]] # [[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['downstream'], boundaryTags['back'], boundaryTags['upstream'], boundaryTags['top']] # boundaryTags['obstacle'], # boundaryTags['obstacle'], # boundaryTags['obstacle'], # boundaryTags['obstacle'], # boundaryTags['obstacle']] holes=[] dx = L[0]/float(nBoxes_xy[0]) dy = L[1]/float(nBoxes_xy[1]) hbdx = 0.5*boxScale[0]*dx hbdy = 0.5*boxScale[1]*dy for i in range(nBoxes_xy[0]): for j in range(nBoxes_xy[1]): if i == nBoxes_xy[0] - 1 and j%2 == 1: continue center = [i*dx + 0.5*dx+(j%2)*0.5*dx,j*dy+0.5*dy] holes.append(center+[0.5*boxScale[2]*L[2]]) hz = boxScale[2]*L[2] if random_height: hz *= rg.gauss(1.0,0.1) n=len(vertices) vertices.append([center[0]-hbdx,center[1]-hbdy,0.0]) vertices.append([center[0]-hbdx,center[1]+hbdy,0.0]) vertices.append([center[0]+hbdx,center[1]+hbdy,0.0]) vertices.append([center[0]+hbdx,center[1]-hbdy,0.0]) vertices.append([center[0]-hbdx,center[1]-hbdy,hz]) vertices.append([center[0]-hbdx,center[1]+hbdy,hz]) vertices.append([center[0]+hbdx,center[1]+hbdy,hz]) vertices.append([center[0]+hbdx,center[1]-hbdy,hz]) vertexFlags.append(boundaryTags['obstacle']) vertexFlags.append(boundaryTags['obstacle']) vertexFlags.append(boundaryTags['obstacle']) vertexFlags.append(boundaryTags['obstacle']) vertexFlags.append(boundaryTags['obstacle']) vertexFlags.append(boundaryTags['obstacle']) vertexFlags.append(boundaryTags['obstacle']) vertexFlags.append(boundaryTags['obstacle']) facets[0].append([n+0,n+1,n+2,n+3])#bottom facets.append([[n+0,n+1,n+5,n+4]])#upstream facets.append([[n+1,n+2,n+6,n+5]])#back facets.append([[n+2,n+3,n+7,n+6]])#downstream facets.append([[n+3,n+0,n+4,n+7]])#front facets.append([[n+4,n+5,n+6,n+7]])#top facetFlags.append(boundaryTags['obstacle']) facetFlags.append(boundaryTags['obstacle']) facetFlags.append(boundaryTags['obstacle']) facetFlags.append(boundaryTags['obstacle']) facetFlags.append(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
("he", 0.5, "Max mesh element diameter"), ("ARTIFICIAL_VISCOSITY", 3, "artificial viscosity")]) waterLevel = 0.75 leeward_wl = 0.25 pro_wl = 0.5 g = np.array([0., 0.0, -9.81]) he = opts.he # ****************** # # ***** GAUGES ***** # # ****************** # # *************************** # # ***** DOMAIN AND MESH ***** # # *************************** # domain = Domain.PiecewiseLinearComplexDomain() boundaries = ['gate', 'left', 'right', 'bottom', 'top', 'front', 'back'] boundaryTags = dict([(key, i + 1) for (i, key) in enumerate(boundaries)]) boundaryOrientations = { 'gate': np.array([-1., 0., 0.]), 'left': np.array([-1., 0., 0.]), 'right': np.array([+1., 0., 0.]), 'bottom': np.array([0., 0., -1.]), 'top': np.array([0., 0., +1.]), 'front': np.array([0., +1., 0.]), 'back': np.array([0., -1., 0.]), } vertices = [ [0.0, 0.0, 0.0], #0
[], [], [], []] 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, facetHoles=facetHoles, facetFlags=facetFlags, regions=regions, regionFlags=regionFlags) #go ahead and add a boundary tags member domain.boundaryTags = boundaryTags domain.writePoly("mesh") domain.writePLY("mesh") domain.writeAsymptote("mesh") triangleOptions="VApq2q10ena%21.16e" % ((he**3)/6.0,) # Numerical parameters ns_shockCapturingFactor = 0.1 ls_shockCapturingFactor = 0.1 ls_sc_uref = 1.0
def get_pseudo_3D_cylinder_box_domain(x0=(0.0, 0.0, 0.0), L=(1.0, 1.0, 1.0), x2=None, x3=None, radius=0.1, center=(0.5, 0.5), n_points_on_obstacle=2 * 21 - 2, cross_section=circular_cross_section, thetaOffset=0.0, he=1.0, he2=None, he3=None): if he2 == None: he2 = he if he3 == None: he3 = he2 x1 = (x0[0] + L[0], x0[1] + L[1], x0[2] + L[2]) if x2 == None: x2 = (0.25 * (x0[0] + x1[0]), 0.25 * (x0[1] + x1[1])) if x3 == None: x3 = (0.75 * (x0[0] + x1[0]), 0.75 * (x0[1] + x1[1])) boundaries = [ 'left', 'right', 'bottom', 'top', 'front', 'back', ] boundaryTags = dict([(key, i + 1) for (i, key) in enumerate(boundaries)]) #work around the domain from (0.0,0.0) going counterclockwise vertexKeys = ['left_bottom', 'right_bottom', 'right_top', 'left_top'] vertices = [[x0[0], x0[1]], [x1[0], x0[1]], [x1[0], x1[1]], [x0[0], x1[1]]] vertexFlags = [ boundaryTags['bottom'], boundaryTags['bottom'], boundaryTags['top'], boundaryTags['top'] ] #cylinder theta = thetaOffset pb = cross_section(center, radius, theta) vertices.append([pb[0], pb[1]]) vertexKeys.append('obstacle_{0}'.format(0)) vertexFlags.append(boundaryTags['back']) for gb in range(1, n_points_on_obstacle): theta = float(gb) / float( n_points_on_obstacle) * 2.0 * math.pi + thetaOffset pb = cross_section(center, radius, theta) vertexKeys.append('obstacle_{0}'.format(gb)) vertices.append([pb[0], pb[1]]) vertexFlags.append(boundaryTags['back']) #box vertexKeys.extend(['box_1', 'box_2', 'box_3', 'box_4']) vertices.extend([[x2[0], x2[1]], [x3[0], x2[1]], [x3[0], x3[1]], [x2[0], x3[1]]]) vertexFlags.extend([ boundaryTags['back'], boundaryTags['back'], boundaryTags['back'], boundaryTags['back'] ]) #convert to 3D vertices3dDict = {} vertices3d = [] vertexFlags3d = [] facets3d = [] facetFlags3d = [] facetHoles3d = [] front_cylinder = [] back_cylinder = [] front_box = [] back_box = [] for vN, v in enumerate(vertices): vertices3dDict[vertexKeys[vN] + '_back'] = vN vertices3d.append([v[0], v[1], x0[2]]) vertexFlags3d.append( boundaryTags['back']) #note that the original tag is back if 'obstacle' in vertexKeys[vN]: back_cylinder.append(vN) if 'box' in vertexKeys[vN]: back_box.append(vN) for vN, v in enumerate(vertices): vertices3dDict[vertexKeys[vN] + '_front'] = vN + len(vertices) vertices3d.append([v[0], v[1], x1[2]]) vertexFlags3d.append( boundaryTags['front']) #note that the original tag is back if 'obstacle' in vertexKeys[vN]: front_cylinder.append(vN + len(vertices)) if 'box' in vertexKeys[vN]: front_box.append(vN + len(vertices)) #left facets3d.append([[ vertices3dDict['left_bottom_front'], vertices3dDict['left_bottom_back'], vertices3dDict['left_top_back'], vertices3dDict['left_top_front'] ]]) facetFlags3d.append(boundaryTags['left']) facetHoles3d.append([]) #right facets3d.append([[ vertices3dDict['right_bottom_front'], vertices3dDict['right_bottom_back'], vertices3dDict['right_top_back'], vertices3dDict['right_top_front'] ]]) facetFlags3d.append(boundaryTags['right']) facetHoles3d.append([]) #top facets3d.append([[ vertices3dDict['left_top_front'], vertices3dDict['right_top_front'], vertices3dDict['right_top_back'], vertices3dDict['left_top_back'] ]]) facetFlags3d.append(boundaryTags['top']) facetHoles3d.append([]) #bottom facets3d.append([[ vertices3dDict['left_bottom_front'], vertices3dDict['right_bottom_front'], vertices3dDict['right_bottom_back'], vertices3dDict['left_bottom_back'] ]]) facetFlags3d.append(boundaryTags['bottom']) facetHoles3d.append([]) #front facets3d.append([[ vertices3dDict['left_bottom_front'], vertices3dDict['right_bottom_front'], vertices3dDict['right_top_front'], vertices3dDict['left_top_front'] ], front_cylinder, front_box]) #add points on the front circle facetFlags3d.append(boundaryTags['front']) facetHoles3d.append([]) #back facets3d.append([[ vertices3dDict['left_bottom_back'], vertices3dDict['right_bottom_back'], vertices3dDict['right_top_back'], vertices3dDict['left_top_back'] ], back_cylinder, back_box]) #add points on the back circle facetFlags3d.append(boundaryTags['back']) facetHoles3d.append([]) #cylinder for fN in range(n_points_on_obstacle - 1): facets3d.append([[ front_cylinder[fN], back_cylinder[fN], back_cylinder[fN + 1], front_cylinder[fN + 1] ]]) facetFlags3d.append(0) facetHoles3d.append([]) facets3d.append([[ front_cylinder[-1], back_cylinder[-1], back_cylinder[0], front_cylinder[0] ]]) facetFlags3d.append(0) facetHoles3d.append([]) #sides of box for fN in range(3): facets3d.append([[ front_box[fN], back_box[fN], back_box[fN + 1], front_box[fN + 1] ]]) facetFlags3d.append(0) facetHoles3d.append([]) facets3d.append([[front_box[-1], back_box[-1], back_box[0], front_box[0]]]) facetFlags3d.append(0) facetHoles3d.append([]) #region regions = [(center[0], center[1], 0.5 * (x0[2] + x1[2])), (0.1 * x2[0] + 0.9 * x3[0], 0.1 * x2[1] + 0.9 * x3[1], 0.5 * (x0[2] + x1[2])), (0.1 * x0[0] + 0.9 * x1[0], 0.1 * x0[1] + 0.9 * x1[1], 0.5 * (x0[2] + x1[2]))] regionFlags = [1, 2, 3] regionConstraints = [0.5 * he2**2, 0.5 * he3**2, 0.5 * (he)**2] # make domain domain = Domain.PiecewiseLinearComplexDomain( vertices=vertices3d, vertexFlags=vertexFlags3d, facets=facets3d, facetFlags=facetFlags3d, facetHoles=facetHoles3d, regions=regions, regionFlags=regionFlags, regionConstraints=regionConstraints) domain.boundaryTags = boundaryTags return domain, boundaryTags
[[11,8,12,15]], [[12,13,14,15]]] facetFlags=[boundaryTags['bottom'], boundaryTags['front'], boundaryTags['right'], boundaryTags['back'], boundaryTags['left'], boundaryTags['top'], boundaryTags['box_front'], boundaryTags['box_right'], boundaryTags['box_back'], boundaryTags['box_left'], boundaryTags['box_top']] domain = Domain.PiecewiseLinearComplexDomain(vertices=vertices, vertexFlags=vertexFlags, facets=facets, facetFlags=facetFlags, holes=holes) #go ahead and add a boundary tags member domain.boundaryTags = boundaryTags domain.writePoly("mesh") domain.writePLY("mesh") domain.writeAsymptote("mesh") triangleOptions="VApq1.25q12ena%e" % ((he**3)/6.0,) logEvent("""Mesh generated using: tetgen -%s %s""" % (triangleOptions,domain.polyfile+".poly")) # Time stepping T=6.00 dt_init =0.001 dt_fixed = 0.1/Refinement
def get_domain_two_box(x0=(0.0, 0.0, 0.0), L=(1.0, 1.0, 1.0), he=0.001, he2=None, x2=None, x3=None): 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]) if x2 == None: x2 = (0.25 * (x0[0] + x1[0]), 0.25 * (x0[1] + x1[1]), 0.25 * (x0[2] + x1[2])) if x3 == None: x3 = (0.75 * (x0[0] + x1[0]), 0.75 * (x0[1] + x1[1]), 0.75 * (x0[2] + x1[2])) if he2 == None: he2 = he 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]), (x2[0], x2[1], x2[2]), (x3[0], x2[1], x2[2]), (x3[0], x3[1], x2[2]), (x2[0], x3[1], x2[2]), (x2[0], x2[1], x3[2]), (x3[0], x2[1], x3[2]), (x3[0], x3[1], x3[2]), (x2[0], x3[1], x3[2])] vertexFlags = [ boundaryTags['bottom'], boundaryTags['bottom'], boundaryTags['top'], boundaryTags['top'], boundaryTags['bottom'], boundaryTags['bottom'], boundaryTags['top'], boundaryTags['top'], 0, 0, 0, 0, 0, 0, 0, 0 ] 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([[], [], [], [], [], []]) planes.extend([[[8, 9, 10, 11]], [[12, 13, 14, 15]], [[8, 11, 15, 12]], [[9, 10, 14, 13]], [[8, 9, 13, 12]], [[10, 11, 15, 14]]]) planeFlags.extend([0, 0, 0, 0, 0, 0]) planeHolds.extend([[], [], [], [], [], []]) regions = [ (0.5 * (x2[0] + x3[0]), 0.5 * (x2[1] + x3[1]), 0.5 * (x2[2] + x3[2])), (0.5 * (x3[0] + x1[0]), 0.5 * (x3[1] + x1[1]), 0.5 * (x3[2] + x1[2])) ] regionFlags = [1, 2] regionConstraints = [0.5 * (he2)**2, 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, x2, x3