def Fraction(x): buff = Fra(x).limit_denominator(100000) n, d = buff.numerator, buff.denominator if n > 1e2: return fractObj(round(x, 8), 1) else: return fractObj(n, d)
def test_gen(self): l_xi = sympy.symbols('xi_1') l_syms, l_basis = Line.gen(0) self.assertEqual(l_syms, [l_xi]) self.assertEqual(l_basis, [1]) l_syms, l_basis = Line.gen(1) self.assertEqual(l_syms, [l_xi]) self.assertEqual(l_basis, [sympy.sympify(1), 2 * l_xi - 1]) l_syms, l_basis = Line.gen(2) self.assertEqual(l_syms, [l_xi]) self.assertEqual(l_basis, [ sympy.sympify(1), 2 * l_xi - 1, Fra(3, 2) * (2 * l_xi - 1)**2 - Fra(1, 2) ]) l_syms, l_basis = Line.gen(3) self.assertEqual(l_syms, [l_xi]) self.assertEqual(l_basis, [ sympy.sympify(1), 2 * l_xi - 1, Fra(3, 2) * (2 * l_xi - 1)**2 - Fra(1, 2), -3 * l_xi + Fra(5, 2) * (2 * l_xi - 1)**3 + Fra(3, 2) ])
def intSfDg(i_deg, i_symsS, i_symsV): assert (len(i_symsV) == 3) assert (len(i_symsS) == 2) # tet type l_ty = edge_pre.types.Tet.Tet(i_deg) # substitutes for the volume coordinates l_subs = ( ((i_symsV[0], i_symsS[1]), (i_symsV[1], i_symsS[0]), (i_symsV[2], 0)), ((i_symsV[0], i_symsS[0]), (i_symsV[1], 0), (i_symsV[2], i_symsS[1])), ((i_symsV[0], 0), (i_symsV[1], i_symsS[1]), (i_symsV[2], i_symsS[0])), ((i_symsV[0], 1 - i_symsS[0] - i_symsS[1]), (i_symsV[1], i_symsS[0]), (i_symsV[2], i_symsS[1])), ) # sub-face intgration intervals l_intSf = [] # inc from one vertex to the next l_inc = l_ty.ves[1][0] - l_ty.ves[0][0] assert (l_inc == l_ty.ves[2][1] - l_ty.ves[0][1]) assert (l_inc == l_ty.ves[3][2] - l_ty.ves[0][2]) l_inc = Fra(l_inc, l_ty.n_ses) # set intervals for l_e2 in range(l_ty.n_ses): for l_e1 in range(l_ty.n_ses - l_e2): l_intSf = l_intSf + [[(i_symsS[0], l_e1 * l_inc, (l_e1 + 1) * l_inc - (i_symsS[1] - l_e2 * l_inc)), (i_symsS[1], l_e2 * l_inc, (l_e2 + 1) * l_inc)]] # add second triangle only if not the last quad if (l_e1 != l_ty.n_ses - l_e2 - 1): l_intSf = l_intSf + [[(i_symsS[0], (l_e1 + 1) * l_inc - (i_symsS[1] - l_e2 * l_inc), (l_e1 + 1) * l_inc), (i_symsS[1], l_e2 * l_inc, (l_e2 + 1) * l_inc)]] # check that we got all sub-triangles assert (len(l_intSf) == l_ty.n_sfs) return l_subs, [l_intSf, l_intSf, l_intSf, l_intSf]
def svs(i_deg): l_ty = edge_pre.types.Tet.Tet(i_deg) # inc from one vertex to the next l_inc = l_ty.ves[1][0] - l_ty.ves[0][0] assert (l_inc == l_ty.ves[2][1] - l_ty.ves[0][1]) assert (l_inc == l_ty.ves[3][2] - l_ty.ves[0][2]) l_inc = Fra(l_inc, l_ty.n_ses) # vertices l_svs = [] for l_e3 in range(l_ty.n_ses + 1): for l_e2 in range(l_ty.n_ses + 1 - l_e3): for l_e1 in range(l_ty.n_ses + 1 - l_e3 - l_e2): l_svs = l_svs + [[ l_ty.ves[0][0] + l_e1 * l_inc, l_ty.ves[0][1] + l_e2 * l_inc, l_ty.ves[0][2] + l_e3 * l_inc ]] return l_svs
def test_intSc( self ): # first order l_intIn, l_intSend, l_intSurf = Hex.intSc( 0, ['xi0', 'xi1', 'xi2'] ) self.assertEqual( l_intIn, [] ) self.assertEqual( l_intSend, [ [ ( 'xi0', 0, 1 ), ( 'xi1', 0, 1 ), ( 'xi2', 0, 1 ) ] ] ) self.assertEqual( l_intSurf, [ [ [ ( 'xi0', 0, 1 ), ( 'xi1', 0, 1 ), ( 'xi2', 0, 1 ) ] ] for l_sf in range(6) ] ) # second order l_intIn, l_intSend, l_intSurf = Hex.intSc( 1, ['xi0', 'xi1', 'xi2'] ) self.assertEqual( l_intIn, [ [ ( 'xi0', Fra(1,3), Fra(2,3) ), ( 'xi1', Fra(1,3), Fra(2,3) ), ( 'xi2', Fra(1,3), Fra(2,3) ) ] ] ) self.assertEqual( l_intSend, [ [ ( 'xi0', Fra(0,3), Fra(1,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(1,3), Fra(2,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(2,3), Fra(3,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(0,3), Fra(1,3) ), ( 'xi1', Fra(1,3), Fra(2,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(1,3), Fra(2,3) ), ( 'xi1', Fra(1,3), Fra(2,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(2,3), Fra(3,3) ), ( 'xi1', Fra(1,3), Fra(2,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(0,3), Fra(1,3) ), ( 'xi1', Fra(2,3), Fra(3,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(1,3), Fra(2,3) ), ( 'xi1', Fra(2,3), Fra(3,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(2,3), Fra(3,3) ), ( 'xi1', Fra(2,3), Fra(3,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(0,3), Fra(1,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(1,3), Fra(2,3) ) ], [ ( 'xi0', Fra(1,3), Fra(2,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(1,3), Fra(2,3) ) ], [ ( 'xi0', Fra(2,3), Fra(3,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(1,3), Fra(2,3) ) ], [ ( 'xi0', Fra(0,3), Fra(1,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(2,3), Fra(3,3) ) ], [ ( 'xi0', Fra(1,3), Fra(2,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(2,3), Fra(3,3) ) ], [ ( 'xi0', Fra(2,3), Fra(3,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(2,3), Fra(3,3) ) ], [ ( 'xi0', Fra(2,3), Fra(3,3) ), ( 'xi1', Fra(1,3), Fra(2,3) ), ( 'xi2', Fra(1,3), Fra(2,3) ) ], [ ( 'xi0', Fra(2,3), Fra(3,3) ), ( 'xi1', Fra(2,3), Fra(3,3) ), ( 'xi2', Fra(1,3), Fra(2,3) ) ], [ ( 'xi0', Fra(2,3), Fra(3,3) ), ( 'xi1', Fra(1,3), Fra(2,3) ), ( 'xi2', Fra(2,3), Fra(3,3) ) ], [ ( 'xi0', Fra(2,3), Fra(3,3) ), ( 'xi1', Fra(2,3), Fra(3,3) ), ( 'xi2', Fra(2,3), Fra(3,3) ) ], [ ( 'xi0', Fra(0,3), Fra(1,3) ), ( 'xi1', Fra(2,3), Fra(3,3) ), ( 'xi2', Fra(1,3), Fra(2,3) ) ], [ ( 'xi0', Fra(1,3), Fra(2,3) ), ( 'xi1', Fra(2,3), Fra(3,3) ), ( 'xi2', Fra(1,3), Fra(2,3) ) ], [ ( 'xi0', Fra(0,3), Fra(1,3) ), ( 'xi1', Fra(2,3), Fra(3,3) ), ( 'xi2', Fra(2,3), Fra(3,3) ) ], [ ( 'xi0', Fra(1,3), Fra(2,3) ), ( 'xi1', Fra(2,3), Fra(3,3) ), ( 'xi2', Fra(2,3), Fra(3,3) ) ], [ ( 'xi0', Fra(0,3), Fra(1,3) ), ( 'xi1', Fra(1,3), Fra(2,3) ), ( 'xi2', Fra(1,3), Fra(2,3) ) ], [ ( 'xi0', Fra(0,3), Fra(1,3) ), ( 'xi1', Fra(1,3), Fra(2,3) ), ( 'xi2', Fra(2,3), Fra(3,3) ) ], [ ( 'xi0', Fra(1,3), Fra(2,3) ), ( 'xi1', Fra(1,3), Fra(2,3) ), ( 'xi2', Fra(2,3), Fra(3,3) ) ] ] ) self.assertEqual( l_intSurf[0:2], [ [ [ ( 'xi0', Fra(0,3), Fra(1,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(1,3), Fra(2,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(2,3), Fra(3,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(0,3), Fra(1,3) ), ( 'xi1', Fra(1,3), Fra(2,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(1,3), Fra(2,3) ), ( 'xi1', Fra(1,3), Fra(2,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(2,3), Fra(3,3) ), ( 'xi1', Fra(1,3), Fra(2,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(0,3), Fra(1,3) ), ( 'xi1', Fra(2,3), Fra(3,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(1,3), Fra(2,3) ), ( 'xi1', Fra(2,3), Fra(3,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(2,3), Fra(3,3) ), ( 'xi1', Fra(2,3), Fra(3,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ] ], [ [ ( 'xi0', Fra(0,3), Fra(1,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(1,3), Fra(2,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(2,3), Fra(3,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(0,3), Fra(1,3) ) ], [ ( 'xi0', Fra(0,3), Fra(1,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(1,3), Fra(2,3) ) ], [ ( 'xi0', Fra(1,3), Fra(2,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(1,3), Fra(2,3) ) ], [ ( 'xi0', Fra(2,3), Fra(3,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(1,3), Fra(2,3) ) ], [ ( 'xi0', Fra(0,3), Fra(1,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(2,3), Fra(3,3) ) ], [ ( 'xi0', Fra(1,3), Fra(2,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(2,3), Fra(3,3) ) ], [ ( 'xi0', Fra(2,3), Fra(3,3) ), ( 'xi1', Fra(0,3), Fra(1,3) ), ( 'xi2', Fra(2,3), Fra(3,3) ) ] ] ] )
def test_gatherLine(self): # # 2nd order # l_syms, l_basis = edge_pre.dg.basis.Line.gen(1) l_int = [(l_syms[0], 0, 1)] l_mapsSc, l_detsSc = edge_pre.sc.grid.Line.intSc(1, l_syms) l_gather = Project.gather(l_syms, l_basis, l_int, l_mapsSc[0] + l_mapsSc[1], l_detsSc[0] + l_detsSc[1]) l_gatherUt = sympy.Matrix([[Fra(1, 3), 0], [Fra(1, 3), -Fra(3, 4)], [Fra(1, 3), Fra(3, 4)]]) self.assertEqual(l_gather, l_gatherUt) # # 3rd order # l_syms, l_basis = edge_pre.dg.basis.Line.gen(2) l_int = [(l_syms[0], 0, 1)] l_mapsSc, l_detsSc = edge_pre.sc.grid.Line.intSc(2, l_syms) l_gather = Project.gather(l_syms, l_basis, l_int, l_mapsSc[0] + l_mapsSc[1], l_detsSc[0] + l_detsSc[1]) l_gatherUt = sympy.Matrix([[Fra(1, 5), -Fra(1, 4), -Fra(25, 84)], [Fra(1, 5), 0, -Fra(25, 42)], [Fra(1, 5), Fra(1, 4), -Fra(25, 84)], [Fra(1, 5), -Fra(1, 2), Fra(25, 42)], [Fra(1, 5), Fra(1, 2), Fra(25, 42)]]) self.assertEqual(l_gather, l_gatherUt)
def test_intSfDg(self): l_xi0 = sympy.symbols('xi_0') l_xi1 = sympy.symbols('xi_1') l_xi2 = sympy.symbols('xi_2') l_chi0 = sympy.symbols('chi_0') l_chi1 = sympy.symbols('chi_1') # 1st order l_subs, l_intSfDg = Hex.intSfDg(0, [l_chi0, l_chi1], [l_xi0, l_xi1, l_xi2]) self.assertEqual(l_subs, (((l_xi0, l_chi1), (l_xi1, l_chi0), (l_xi2, 0)), ((l_xi0, l_chi0), (l_xi1, 0), (l_xi2, l_chi1)), ((l_xi0, 1), (l_xi1, l_chi0), (l_xi2, l_chi1)), ((l_xi0, l_chi1), (l_xi1, 1), (l_xi2, l_chi0)), ((l_xi0, 0), (l_xi1, l_chi1), (l_xi2, l_chi0)), ((l_xi0, l_chi0), (l_xi1, l_chi1), (l_xi2, 1)))) self.assertEqual( l_intSfDg, [ [ # DG face 0 [(l_chi0, 0, 1), (l_chi1, 0, 1)] ], [ # DG face 1 [(l_chi0, 0, 1), (l_chi1, 0, 1)] ], [ # DG face 2 [(l_chi0, 0, 1), (l_chi1, 0, 1)] ], [ # DG face 3 [(l_chi0, 0, 1), (l_chi1, 0, 1)] ], [ # DG face 4 [(l_chi0, 0, 1), (l_chi1, 0, 1)] ], [ # DG face 5 [(l_chi0, 0, 1), (l_chi1, 0, 1)] ] ]) # 2nd order l_subs, l_intSfDg = Hex.intSfDg(1, [l_chi0, l_chi1], [l_xi0, l_xi1, l_xi2]) self.assertEqual(l_subs, (((l_xi0, l_chi1), (l_xi1, l_chi0), (l_xi2, 0)), ((l_xi0, l_chi0), (l_xi1, 0), (l_xi2, l_chi1)), ((l_xi0, 1), (l_xi1, l_chi0), (l_xi2, l_chi1)), ((l_xi0, l_chi1), (l_xi1, 1), (l_xi2, l_chi0)), ((l_xi0, 0), (l_xi1, l_chi1), (l_xi2, l_chi0)), ((l_xi0, l_chi0), (l_xi1, l_chi1), (l_xi2, 1)))) self.assertEqual( l_intSfDg, [ [ # DG face 0 [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))] ], [ # DG face 1 [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))] ], [ # DG face 2 [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))] ], [ # DG face 3 [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))] ], [ # DG face 4 [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))] ], [ # DG face 5 [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(0, 3), Fra(1, 3))], [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(1, 3), Fra(2, 3))], [(l_chi0, Fra(0, 3), Fra(1, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))], [(l_chi0, Fra(1, 3), Fra(2, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))], [(l_chi0, Fra(2, 3), Fra(3, 3)), (l_chi1, Fra(2, 3), Fra(3, 3))] ] ])
def test_scatterLine(self): # # 2nd order # l_syms, l_basis = edge_pre.dg.basis.Line.gen( 1 ) l_intIn, l_intSend, l_intSurf = edge_pre.sc.grid.Line.intSc( 1, l_syms ) # inner sub-cells l_scatter = Project.scatter( l_basis, l_intIn ) l_scatterUt = sympy.Matrix([[1], [0]]) self.assertEqual( l_scatter, l_scatterUt ) # send sub-cells l_scatter = Project.scatter( l_basis, l_intSend ) l_scatterUt = sympy.Matrix( [ [1, 1 ], [-Fra(2, 3), Fra(2, 3)] ]) self.assertEqual( l_scatter, l_scatterUt ) # surf sub-cells, face 1 l_scatter = Project.scatter( l_basis, l_intSurf[0] ) l_scatterUt = sympy.Matrix( [ [1, ], [-Fra(2, 3) ] ]) self.assertEqual( l_scatter, l_scatterUt ) # surf sub-cells, face2 l_scatter = Project.scatter( l_basis, l_intSurf[1] ) l_scatterUt = sympy.Matrix( [ [1, ], [Fra(2, 3) ] ]) self.assertEqual( l_scatter, l_scatterUt ) # # 3rd order # l_syms, l_basis = edge_pre.dg.basis.Line.gen( 2 ) l_intIn, l_intSend, l_intSurf = edge_pre.sc.grid.Line.intSc( 2, l_syms ) # inner sub-cells l_scatter = Project.scatter( l_basis, l_intIn ) l_scatterUt = sympy.Matrix( [ [ 1, 1, 1 ], [ -Fra(2, 5), 0, Fra(2, 5) ], [ -Fra(6, 25), -Fra(12,25), -Fra(6,25) ] ]) self.assertEqual( l_scatter, l_scatterUt ) # send sub-cells l_scatter = Project.scatter( l_basis, l_intSend ) l_scatterUt = sympy.Matrix( [ [ 1, 1 ], [ -Fra(4, 5), Fra(4, 5) ], [ Fra(12, 25), Fra(12,25) ] ]) self.assertEqual( l_scatter, l_scatterUt ) # surf sub-cells, face 1 l_scatter = Project.scatter( l_basis, l_intSurf[0] ) l_scatterUt = sympy.Matrix( [ [ 1 ], [ -Fra(4, 5) ], [ Fra(12, 25) ] ]) self.assertEqual( l_scatter, l_scatterUt ) # surf sub-cells, face 2 l_scatter = Project.scatter( l_basis, l_intSurf[0] ) l_scatterUt = sympy.Matrix( [ [ 1 ], [ -Fra(4, 5) ], [ Fra(12, 25) ] ]) self.assertEqual( l_scatter, l_scatterUt )
def test_intSfDg(self): l_subs, l_intSfDg = Quad.intSfDg(1, ['chi0'], ['xi0', 'xi1']) # check substitutions self.assertEqual(l_subs, ((('xi0', 'chi0'), ('xi1', 0)), (('xi0', 1), ('xi1', 'chi0')), (('xi0', 'chi0'), ('xi1', 1)), (('xi0', 0), ('xi1', 'chi0')))) # check intervals self.assertEqual( l_intSfDg, [ [ # DG face0 [('chi0', Fra(0, 3), Fra(1, 3))], [('chi0', Fra(1, 3), Fra(2, 3))], [('chi0', Fra(2, 3), Fra(3, 3))] ], [ # DG face1 [('chi0', Fra(0, 3), Fra(1, 3))], [('chi0', Fra(1, 3), Fra(2, 3))], [('chi0', Fra(2, 3), Fra(3, 3))] ], [ # DG face2 [('chi0', Fra(2, 3), Fra(3, 3))], [('chi0', Fra(1, 3), Fra(2, 3))], [('chi0', Fra(0, 3), Fra(1, 3))] ], [ # DG face3 [('chi0', Fra(2, 3), Fra(3, 3))], [('chi0', Fra(1, 3), Fra(2, 3))], [('chi0', Fra(0, 3), Fra(1, 3))] ] ])
def test_intSc(self): # second order l_intIn, l_intSend, l_intSurf = Quad.intSc(1, ['xi0', 'xi1']) self.assertEqual(l_intIn, [[('xi0', Fra(1, 3), Fra(2, 3)), ('xi1', Fra(1, 3), Fra(2, 3))]]) self.assertEqual(l_intSend, [[('xi0', Fra(0, 3), Fra(1, 3)), ('xi1', Fra(0, 3), Fra(1, 3))], [('xi0', Fra(1, 3), Fra(2, 3)), ('xi1', Fra(0, 3), Fra(1, 3))], [('xi0', Fra(2, 3), Fra(3, 3)), ('xi1', Fra(0, 3), Fra(1, 3))], [('xi0', Fra(2, 3), Fra(3, 3)), ('xi1', Fra(1, 3), Fra(2, 3))], [('xi0', Fra(2, 3), Fra(3, 3)), ('xi1', Fra(2, 3), Fra(3, 3))], [('xi0', Fra(1, 3), Fra(2, 3)), ('xi1', Fra(2, 3), Fra(3, 3))], [('xi0', Fra(0, 3), Fra(1, 3)), ('xi1', Fra(2, 3), Fra(3, 3))], [('xi0', Fra(0, 3), Fra(1, 3)), ('xi1', Fra(1, 3), Fra(2, 3))]]) self.assertEqual(l_intSurf[0], [[('xi0', Fra(0, 3), Fra(1, 3)), ('xi1', Fra(0, 3), Fra(1, 3))], [('xi0', Fra(1, 3), Fra(2, 3)), ('xi1', Fra(0, 3), Fra(1, 3))], [('xi0', Fra(2, 3), Fra(3, 3)), ('xi1', Fra(0, 3), Fra(1, 3))]]) self.assertEqual(l_intSurf[1], [[('xi0', Fra(2, 3), Fra(3, 3)), ('xi1', Fra(0, 3), Fra(1, 3))], [('xi0', Fra(2, 3), Fra(3, 3)), ('xi1', Fra(1, 3), Fra(2, 3))], [('xi0', Fra(2, 3), Fra(3, 3)), ('xi1', Fra(2, 3), Fra(3, 3))]]) self.assertEqual(l_intSurf[2], [[('xi0', Fra(2, 3), Fra(3, 3)), ('xi1', Fra(2, 3), Fra(3, 3))], [('xi0', Fra(1, 3), Fra(2, 3)), ('xi1', Fra(2, 3), Fra(3, 3))], [('xi0', Fra(0, 3), Fra(1, 3)), ('xi1', Fra(2, 3), Fra(3, 3))]]) self.assertEqual(l_intSurf[3], [[('xi0', Fra(0, 3), Fra(1, 3)), ('xi1', Fra(2, 3), Fra(3, 3))], [('xi0', Fra(0, 3), Fra(1, 3)), ('xi1', Fra(1, 3), Fra(2, 3))], [('xi0', Fra(0, 3), Fra(1, 3)), ('xi1', Fra(0, 3), Fra(1, 3))]])
def test_intSfDg(self): l_xi0 = sympy.symbols('xi_0') l_xi1 = sympy.symbols('xi_1') l_xi2 = sympy.symbols('xi_2') l_chi0 = sympy.symbols('chi_0') l_chi1 = sympy.symbols('chi_1') # second order l_subs, l_intSfDg = Tet.intSfDg( 1, [l_chi0, l_chi1], [l_xi0, l_xi1, l_xi2] ) # check substitutions self.assertEqual( l_subs, ( ( ( l_xi0, l_chi1 ), ( l_xi1, l_chi0 ), ( l_xi2, 0 ) ), ( ( l_xi0, l_chi0 ), ( l_xi1, 0 ), ( l_xi2, l_chi1 ) ), ( ( l_xi0, 0 ), ( l_xi1, l_chi1 ), ( l_xi2, l_chi0 ) ), ( ( l_xi0, 1-l_chi0-l_chi1 ), ( l_xi1, l_chi0 ), ( l_xi2, l_chi1 ) ) ) ) for l_fa in l_intSfDg: self.assertEqual( l_fa, [ # first quad [ ( l_chi0, Fra(0,3), Fra(1,3)-l_chi1 ), ( l_chi1, Fra(0,3), Fra(1,3) ) ], [ ( l_chi0, Fra(1,3)-l_chi1, Fra(1,3) ), ( l_chi1, Fra(0,3), Fra(1,3) ) ], # second quad [ ( l_chi0, Fra(1,3), Fra(2,3)-l_chi1 ), ( l_chi1, Fra(0,3), Fra(1,3) ) ], [ ( l_chi0, Fra(2,3)-l_chi1, Fra(2,3) ), ( l_chi1, Fra(0,3), Fra(1,3) ) ], # third quad [ ( l_chi0, Fra(2,3), Fra(3,3)-l_chi1 ), ( l_chi1, Fra(0,3), Fra(1,3) ) ], # fourth quad [ ( l_chi0, Fra(0,3), Fra(1,3)-(l_chi1-Fra(1,3)) ), ( l_chi1, Fra(1,3), Fra(2,3) ) ], [ ( l_chi0, Fra(1,3)-(l_chi1-Fra(1,3)), Fra(1,3) ), ( l_chi1, Fra(1,3), Fra(2,3) ) ], # fifth quad [ ( l_chi0, Fra(1,3), Fra(2,3)-(l_chi1-Fra(1,3)) ), ( l_chi1, Fra(1,3), Fra(2,3) ) ], # sixth quad [ ( l_chi0, Fra(0,3), Fra(1,3)-(l_chi1-Fra(2,3)) ), ( l_chi1, Fra(2,3), Fra(3,3) ) ], ] )
def test_svs(self): # FV l_svs = Tet.svs( 0 ) self.assertEqual( l_svs, [ [0,0,0], [1,0,0], [0,1,0], [0,0,1] ] ) # 2nd order l_svs = Tet.svs( 1 ) self.assertEqual( l_svs, [ [ 0, 0, 0 ], [ Fra(1,3), 0, 0 ], [ Fra(2,3), 0, 0 ], [ Fra(3,3), 0, 0 ], [ 0, Fra(1,3), 0 ], [ Fra(1,3), Fra(1,3), 0 ], [ Fra(2,3), Fra(1,3), 0 ], [ 0, Fra(2,3), 0 ], [ Fra(1,3), Fra(2,3), 0 ], [ 0, Fra(3,3), 0 ], [ 0, Fra(0,3), Fra(1,3) ], [ Fra(1,3), Fra(0,3), Fra(1,3) ], [ Fra(2,3), Fra(0,3), Fra(1,3) ], [ 0, Fra(1,3), Fra(1,3) ], [ Fra(1,3), Fra(1,3), Fra(1,3) ], [ 0, Fra(2,3), Fra(1,3) ], [ 0, Fra(0,3), Fra(2,3) ], [ Fra(1,3), Fra(0,3), Fra(2,3) ], [ Fra(0,3), Fra(1,3), Fra(2,3) ], [ Fra(0,3), Fra(0,3), Fra(3,3) ] ] )
def test_intSc(self): l_xi0 = sympy.symbols('xi_0') l_xi1 = sympy.symbols('xi_1') # second order l_intIn, l_intSend, l_intSurf = Tria.intSc(1, [l_xi0, l_xi1]) # inner intervals self.assertEqual(l_intIn, [[(l_xi0, Fra(1, 3) - l_xi1, Fra(1, 3)), (l_xi1, Fra(0, 3), Fra(1, 3))], [(l_xi0, Fra(2, 3) - l_xi1, Fra(2, 3)), (l_xi1, Fra(0, 3), Fra(1, 3))], [(l_xi0, Fra(1, 3) - (l_xi1 - Fra(1, 3)), Fra(1, 3)), (l_xi1, Fra(1, 3), Fra(2, 3))]]) # send intervals self.assertEqual(l_intSend, [[(l_xi0, Fra(0, 3), Fra(1, 3) - l_xi1), (l_xi1, Fra(0, 3), Fra(1, 3))], [(l_xi0, Fra(1, 3), Fra(2, 3) - l_xi1), (l_xi1, Fra(0, 3), Fra(1, 3))], [(l_xi0, Fra(2, 3), Fra(3, 3) - l_xi1), (l_xi1, Fra(0, 3), Fra(1, 3))], [(l_xi0, Fra(1, 3), Fra(2, 3) - (l_xi1 - Fra(1, 3))), (l_xi1, Fra(1, 3), Fra(2, 3))], [(l_xi0, Fra(0, 3), Fra(1, 3) - (l_xi1 - Fra(2, 3))), (l_xi1, Fra(2, 3), Fra(3, 3))], [(l_xi0, Fra(0, 3), Fra(1, 3) - (l_xi1 - Fra(1, 3))), (l_xi1, Fra(1, 3), Fra(2, 3))]]) # DG intervals self.assertEqual(l_intSurf[0], [[(l_xi0, Fra(0, 3), Fra(1, 3) - l_xi1), (l_xi1, Fra(0, 3), Fra(1, 3))], [(l_xi0, Fra(1, 3), Fra(2, 3) - l_xi1), (l_xi1, Fra(0, 3), Fra(1, 3))], [(l_xi0, Fra(2, 3), Fra(3, 3) - l_xi1), (l_xi1, Fra(0, 3), Fra(1, 3))]]) self.assertEqual(l_intSurf[1], [[(l_xi0, Fra(2, 3), Fra(3, 3) - l_xi1), (l_xi1, Fra(0, 3), Fra(1, 3))], [(l_xi0, Fra(1, 3), Fra(2, 3) - (l_xi1 - Fra(1, 3))), (l_xi1, Fra(1, 3), Fra(2, 3))], [(l_xi0, Fra(0, 3), Fra(1, 3) - (l_xi1 - Fra(2, 3))), (l_xi1, Fra(2, 3), Fra(3, 3))]]) self.assertEqual(l_intSurf[2], [[(l_xi0, Fra(0, 3), Fra(1, 3) - (l_xi1 - Fra(2, 3))), (l_xi1, Fra(2, 3), Fra(3, 3))], [(l_xi0, Fra(0, 3), Fra(1, 3) - (l_xi1 - Fra(1, 3))), (l_xi1, Fra(1, 3), Fra(2, 3))], [(l_xi0, Fra(0, 3), Fra(1, 3) - l_xi1), (l_xi1, Fra(0, 3), Fra(1, 3))]])
def scTySf(i_deg): # special handling for degree 0 elements if (i_deg == 0): return [], [[0, 1, 2, 3]] # get sub-vertices l_svs = svs(i_deg) # get sub-faces l_scSfSvIn, l_scSfSvSend, l_scSfSvRecv = scSfSv(i_deg) # define normals l_normals = [] l_normals = l_normals + [sympy.Matrix([0, 0, 1])] l_normals = l_normals + [sympy.Matrix([0, 1, 0])] l_normals = l_normals + [sympy.Matrix([1, 0, 0])] l_normals = l_normals + [ sympy.Matrix([ -sympy.sqrt(Fra(1, 3)), -sympy.sqrt(Fra(1, 3)), -sympy.sqrt(Fra(1, 3)) ]) ] l_normals = l_normals + [ sympy.Matrix([-sympy.sqrt(Fra(1, 2)), -sympy.sqrt(Fra(1, 2)), 0]) ] l_normals = l_normals + [ sympy.Matrix([-sympy.sqrt(Fra(1, 2)), 0, -sympy.sqrt(Fra(1, 2))]) ] # define empty sub-cell types l_scTySf = [[], []] # iterate over sub-faces for l_ty in range(2): for l_sc in [l_scSfSvIn, l_scSfSvSend][l_ty]: # add empty list l_scTySf[l_ty] = l_scTySf[l_ty] + [[]] for l_sf in l_sc: # assemble three points l_or = sympy.Matrix(l_svs[l_sf[0]]) l_p0 = sympy.Matrix(l_svs[l_sf[1]]) l_p1 = sympy.Matrix(l_svs[l_sf[2]]) # assemble edges l_e0 = l_p0 - l_or l_e1 = l_p1 - l_or # compute normalized cross product l_cr = l_e0.cross(l_e1).normalized() # determine type of normal for l_no in range(len(l_normals)): if l_cr == l_normals[l_no]: l_ri = 1 break elif l_cr == -l_normals[l_no]: l_ri = 0 break # make sure we found the correct normal assert (l_no != len(l_normals) - 1) # determine if this a partial DG face l_pd = 0 if l_ty == 1: # bottom if (l_or[2] == 0 and l_p0[2] == 0 and l_p1[2] == 0): assert (l_no == 0) l_pd = 1 elif (l_or[1] == 0 and l_p0[1] == 0 and l_p1[1] == 0): assert (l_no == 1) l_pd = 1 elif (l_or[0] == 0 and l_p0[0] == 0 and l_p1[0] == 0): assert (l_no == 2) l_pd = 1 elif (l_or[0] == sympy.sympify(1) - l_or[1] - l_or[2] and l_p0[0] == sympy.sympify(1) - l_p0[1] - l_p0[2] and l_p1[0] == sympy.sympify(1) - l_p1[1] - l_p1[2]): assert (l_no == 3) l_pd = 1 # add sub-cell type if l_pd == 0: l_scTySf[l_ty][-1] = l_scTySf[l_ty][-1] + [ 8 + l_ri * 6 + l_no ] else: assert (l_no < 4) l_scTySf[l_ty][-1] = l_scTySf[l_ty][-1] + [ 0 + l_ri * 4 + l_no ] return l_scTySf[0], l_scTySf[1]
def test_intSfDg(self): # 1st order l_subs, l_intSfDg = Hex.intSfDg( 0, ['chi0', 'chi1'], ['xi0', 'xi1', 'xi2'] ) self.assertEqual( l_subs, ( ( ( 'xi0', 'chi0' ), ( 'xi1', 'chi1' ), ( 'xi2', 0 ) ), ( ( 'xi0', 'chi0' ), ( 'xi1', 0 ), ( 'xi2', 'chi1' ) ), ( ( 'xi0', 1 ), ( 'xi1', 'chi0' ), ( 'xi2', 'chi1' ) ), ( ( 'xi0', 'chi0' ), ( 'xi1', 1 ), ( 'xi2', 'chi1' ) ), ( ( 'xi0', 0 ), ( 'xi1', 'chi0' ), ( 'xi2', 'chi1' ) ), ( ( 'xi0', 'chi0' ), ( 'xi1', 'chi1' ), ( 'xi2', 1 ) ) ) ) self.assertEqual( l_intSfDg, [ [ # DG face 0 [ ( 'chi0', 0, 1 ), ( 'chi1', 0, 1 ) ] ], [ # DG face 1 [ ( 'chi0', 0, 1 ), ( 'chi1', 0, 1 ) ] ], [ # DG face 2 [ ( 'chi0', 0, 1 ), ( 'chi1', 0, 1 ) ] ], [ # DG face 3 [ ( 'chi0', 0, 1 ), ( 'chi1', 0, 1 ) ] ], [ # DG face 4 [ ( 'chi0', 0, 1 ), ( 'chi1', 0, 1 ) ] ], [ # DG face 5 [ ( 'chi0', 0, 1 ), ( 'chi1', 0, 1 ) ] ] ] ) # 2nd order l_subs, l_intSfDg = Hex.intSfDg( 1, ['chi0', 'chi1'], ['xi0', 'xi1', 'xi2'] ) self.assertEqual( l_subs, ( ( ( 'xi0', 'chi0' ), ( 'xi1', 'chi1' ), ( 'xi2', 0 ) ), ( ( 'xi0', 'chi0' ), ( 'xi1', 0 ), ( 'xi2', 'chi1' ) ), ( ( 'xi0', 1 ), ( 'xi1', 'chi0' ), ( 'xi2', 'chi1' ) ), ( ( 'xi0', 'chi0' ), ( 'xi1', 1 ), ( 'xi2', 'chi1' ) ), ( ( 'xi0', 0 ), ( 'xi1', 'chi0' ), ( 'xi2', 'chi1' ) ), ( ( 'xi0', 'chi0' ), ( 'xi1', 'chi1' ), ( 'xi2', 1 ) ) ) ) self.assertEqual( l_intSfDg, [ [ # DG face 0 [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ] ], [ # DG face 1 [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ] ], [ # DG face 2 [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ] ], [ # DG face 3 [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ] ], [ # DG face 4 [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ] ], [ # DG face 5 [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(0,3), Fra(1,3) ) ], [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(1,3), Fra(2,3) ) ], [ ( 'chi0', Fra(0,3), Fra(1,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ], [ ( 'chi0', Fra(1,3), Fra(2,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ], [ ( 'chi0', Fra(2,3), Fra(3,3) ), ( 'chi1', Fra(2,3), Fra(3,3) ) ] ] ] )
def test_gatherLine(self): # # 2nd order # l_syms, l_basis = edge_pre.dg.basis.Line.gen( 1 ) l_intIn, l_intSend, l_intSurf = edge_pre.sc.grid.Line.intSc( 1, l_syms ) l_gather = Project.gather( l_basis, l_intIn+l_intSend ) l_gatherUt = sympy.Matrix( [ [ Fra(1, 3), 0 ], [ Fra(1, 3), -Fra(3, 4) ], [ Fra(1, 3), Fra(3, 4) ] ]) self.assertEqual( l_gather, l_gatherUt ) # # 3rd order # l_syms, l_basis = edge_pre.dg.basis.Line.gen( 2 ) l_intIn, l_intSend, l_intSurf = edge_pre.sc.grid.Line.intSc( 2, l_syms ) l_gather = Project.gather( l_basis, l_intIn+l_intSend ) l_gatherUt = sympy.Matrix( [ [ Fra(1, 5), -Fra(1, 4), -Fra(25, 84) ], [ Fra(1, 5), 0, -Fra(25, 42) ], [ Fra(1, 5), Fra(1, 4), -Fra(25, 84) ], [ Fra(1, 5), -Fra(1, 2), Fra(25, 42) ], [ Fra(1, 5), Fra(1, 2), Fra(25, 42) ] ]) self.assertEqual( l_gather, l_gatherUt )
def test_intSfDg(self): l_xi0 = sympy.symbols('xi_0') l_xi1 = sympy.symbols('xi_1') l_chi0 = sympy.symbols('chi_0') # second order l_subs, l_intSfDg = Tria.intSfDg( 1, [l_chi0], [l_xi0, l_xi1] ) # check substitutions self.assertEqual( l_subs, ( ( ( l_xi0, l_chi0 ), ( l_xi1, 0 ) ), ( ( l_xi0, 1-l_chi0 ), ( l_xi1, l_chi0 ) ), ( ( l_xi0, 0 ), ( l_xi1, l_chi0 ) ) ) ) # check intervals self.assertEqual( l_intSfDg, [ [ # DG face0 [ ( l_chi0, Fra(0,3), Fra(1,3) ) ], [ ( l_chi0, Fra(1,3), Fra(2,3) ) ], [ ( l_chi0, Fra(2,3), Fra(3,3) ) ] ], [ # DG face1 [ ( l_chi0, Fra(0,3), Fra(1,3) ) ], [ ( l_chi0, Fra(1,3), Fra(2,3) ) ], [ ( l_chi0, Fra(2,3), Fra(3,3) ) ] ], [ # DG face3 [ ( l_chi0, Fra(2,3), Fra(3,3) ) ], [ ( l_chi0, Fra(1,3), Fra(2,3) ) ], [ ( l_chi0, Fra(0,3), Fra(1,3) ) ] ] ] ) # third order l_subs, l_intSfDg = Tria.intSfDg( 2, [l_chi0], [l_xi0, l_xi1] ) # check substitutions self.assertEqual( l_subs, ( ( ( l_xi0, l_chi0 ), ( l_xi1, 0 ) ), ( ( l_xi0, 1-l_chi0 ), ( l_xi1, l_chi0 ) ), ( ( l_xi0, 0 ), ( l_xi1, l_chi0 ) ) ) ) self.assertEqual( l_intSfDg, [ [ # DG face0 [ ( l_chi0, Fra(0,5), Fra(1,5) ) ], [ ( l_chi0, Fra(1,5), Fra(2,5) ) ], [ ( l_chi0, Fra(2,5), Fra(3,5) ) ], [ ( l_chi0, Fra(3,5), Fra(4,5) ) ], [ ( l_chi0, Fra(4,5), Fra(5,5) ) ] ], [ # DG face1 [ ( l_chi0, Fra(0,5), Fra(1,5) ) ], [ ( l_chi0, Fra(1,5), Fra(2,5) ) ], [ ( l_chi0, Fra(2,5), Fra(3,5) ) ], [ ( l_chi0, Fra(3,5), Fra(4,5) ) ], [ ( l_chi0, Fra(4,5), Fra(5,5) ) ] ], [ # DG face3 [ ( l_chi0, Fra(4,5), Fra(5,5) ) ], [ ( l_chi0, Fra(3,5), Fra(4,5) ) ], [ ( l_chi0, Fra(2,5), Fra(3,5) ) ], [ ( l_chi0, Fra(1,5), Fra(2,5) ) ], [ ( l_chi0, Fra(0,5), Fra(1,5) ) ] ] ] )
def test_svs(self): # 1st order l_svs = Hex.svs(0) self.assertEqual(l_svs, [[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0], [0, 0, 1], [1, 0, 1], [0, 1, 1], [1, 1, 1]]) # 2nd order l_svs = Hex.svs(1) self.assertEqual(l_svs, [ [0, 0, 0], [Fra(1, 3), 0, 0], [Fra(2, 3), 0, 0], [Fra(3, 3), 0, 0], [0, Fra(1, 3), 0], [Fra(1, 3), Fra(1, 3), 0], [Fra(2, 3), Fra(1, 3), 0], [Fra(3, 3), Fra(1, 3), 0], [0, Fra(2, 3), 0], [Fra(1, 3), Fra(2, 3), 0], [Fra(2, 3), Fra(2, 3), 0], [Fra(3, 3), Fra(2, 3), 0], [0, Fra(3, 3), 0], [Fra(1, 3), Fra(3, 3), 0], [Fra(2, 3), Fra(3, 3), 0], [Fra(3, 3), Fra(3, 3), 0], [0, 0, Fra(1, 3)], [Fra(1, 3), 0, Fra(1, 3)], [Fra(2, 3), 0, Fra(1, 3)], [Fra(3, 3), 0, Fra(1, 3)], [0, Fra(1, 3), Fra(1, 3)], [Fra(1, 3), Fra(1, 3), Fra(1, 3)], [Fra(2, 3), Fra(1, 3), Fra(1, 3)], [Fra(3, 3), Fra(1, 3), Fra(1, 3)], [0, Fra(2, 3), Fra(1, 3)], [Fra(1, 3), Fra(2, 3), Fra(1, 3)], [Fra(2, 3), Fra(2, 3), Fra(1, 3)], [Fra(3, 3), Fra(2, 3), Fra(1, 3)], [0, Fra(3, 3), Fra(1, 3)], [Fra(1, 3), Fra(3, 3), Fra(1, 3)], [Fra(2, 3), Fra(3, 3), Fra(1, 3)], [Fra(3, 3), Fra(3, 3), Fra(1, 3)], [0, 0, Fra(2, 3)], [Fra(1, 3), 0, Fra(2, 3)], [Fra(2, 3), 0, Fra(2, 3)], [Fra(3, 3), 0, Fra(2, 3)], [0, Fra(1, 3), Fra(2, 3)], [Fra(1, 3), Fra(1, 3), Fra(2, 3)], [Fra(2, 3), Fra(1, 3), Fra(2, 3)], [Fra(3, 3), Fra(1, 3), Fra(2, 3)], [0, Fra(2, 3), Fra(2, 3)], [Fra(1, 3), Fra(2, 3), Fra(2, 3)], [Fra(2, 3), Fra(2, 3), Fra(2, 3)], [Fra(3, 3), Fra(2, 3), Fra(2, 3)], [0, Fra(3, 3), Fra(2, 3)], [Fra(1, 3), Fra(3, 3), Fra(2, 3)], [Fra(2, 3), Fra(3, 3), Fra(2, 3)], [Fra(3, 3), Fra(3, 3), Fra(2, 3)], [0, 0, Fra(3, 3)], [Fra(1, 3), 0, Fra(3, 3)], [Fra(2, 3), 0, Fra(3, 3)], [Fra(3, 3), 0, Fra(3, 3)], [0, Fra(1, 3), Fra(3, 3)], [Fra(1, 3), Fra(1, 3), Fra(3, 3)], [Fra(2, 3), Fra(1, 3), Fra(3, 3)], [Fra(3, 3), Fra(1, 3), Fra(3, 3)], [0, Fra(2, 3), Fra(3, 3)], [Fra(1, 3), Fra(2, 3), Fra(3, 3)], [Fra(2, 3), Fra(2, 3), Fra(3, 3)], [Fra(3, 3), Fra(2, 3), Fra(3, 3)], [0, Fra(3, 3), Fra(3, 3)], [Fra(1, 3), Fra(3, 3), Fra(3, 3)], [Fra(2, 3), Fra(3, 3), Fra(3, 3)], [Fra(3, 3), Fra(3, 3), Fra(3, 3)], ])
def test_svs(self): # FV l_svs = Tria.svs( 0 ) self.assertEqual( l_svs, [ [0,0], [1,0], [0,1] ] ) # 2nd order l_svs = Tria.svs( 1 ) self.assertEqual( l_svs, [ [0, 0 ], [Fra(1,3), 0], [Fra(2,3), 0], [1, 0], [0, Fra(1,3)], [Fra(1,3), Fra(1,3)], [Fra(2,3), Fra(1,3)], [0, Fra(2,3)], [Fra(1,3), Fra(2,3)], [0, 1] ] ) # 3rd order l_svs = Tria.svs( 2 ) self.assertEqual( l_svs, [ [0, 0], [Fra(1,5), 0], [Fra(2,5), 0], [Fra(3,5), 0], [Fra(4,5), 0], [1, 0], [0, Fra(1,5)], [Fra(1,5), Fra(1,5)], [Fra(2,5), Fra(1,5)], [Fra(3,5), Fra(1,5)], [Fra(4,5), Fra(1,5)], [0, Fra(2,5)], [Fra(1,5), Fra(2,5)], [Fra(2,5), Fra(2,5)], [Fra(3,5), Fra(2,5)], [0, Fra(3,5)], [Fra(1,5), Fra(3,5)], [Fra(2,5), Fra(3,5)], [0, Fra(4,5)], [Fra(1,5), Fra(4,5)], [0, 1] ] )
def test_gen(self): l_xi1 = sympy.symbols('xi_1') l_xi2 = sympy.symbols('xi_2') l_syms, l_basis = Quad.gen(0) self.assertEqual(l_syms, [l_xi1, l_xi2]) self.assertEqual(l_basis, [1]) l_syms, l_basis = Quad.gen(1) self.assertEqual(l_syms, [l_xi1, l_xi2]) self.assertEqual(l_basis, [ 1, 2 * l_xi1 - 1, 2 * l_xi2 - 1, (2 * l_xi1 - 1) * (2 * l_xi2 - 1) ]) l_syms, l_basis = Quad.gen(2) self.assertEqual(l_syms, [l_xi1, l_xi2]) self.assertEqual(l_basis, [ sympy.sympify(1), 2 * l_xi1 - 1, Fra(3, 2) * (2 * l_xi1 - 1)**2 - Fra(1, 2), 2 * l_xi2 - 1, (2 * l_xi1 - 1) * (2 * l_xi2 - 1), (2 * l_xi2 - 1) * (Fra(3, 2) * (2 * l_xi1 - 1)**2 - Fra(1, 2)), Fra(3, 2) * (2 * l_xi2 - 1)**2 - Fra(1, 2), (2 * l_xi1 - 1) * (Fra(3, 2) * (2 * l_xi2 - 1)**2 - Fra(1, 2)), ((Fra(3, 2) * (2 * l_xi2 - 1)**2 - Fra(1, 2))) * ((Fra(3, 2) * (2 * l_xi1 - 1)**2 - Fra(1, 2))) ])
def test_gen(self): l_xi1 = sympy.symbols('xi_1') l_xi2 = sympy.symbols('xi_2') l_xi3 = sympy.symbols('xi_3') # P3, hierarchical storage l_basisUt = [ sympy.sympify(1), 4 * l_xi3 - 1, 3 * l_xi2 + l_xi3 - 1, 2 * l_xi1 + l_xi2 + l_xi3 - 1, 15 * l_xi3**2 - 10 * l_xi3 + 1, (6 * l_xi3 - 1) * (3 * l_xi2 + l_xi3 - 1), 10 * l_xi2**2 + 8 * l_xi2 * l_xi3 - 8 * l_xi2 + l_xi3**2 - 2 * l_xi3 + 1, (6 * l_xi3 - 1) * (2 * l_xi1 + l_xi2 + l_xi3 - 1), (5 * l_xi2 + l_xi3 - 1) * (2 * l_xi1 + l_xi2 + l_xi3 - 1), -Fra(1, 2) * (l_xi2 + l_xi3 - 1)**2 + Fra(3, 2) * (2 * l_xi1 + l_xi2 + l_xi3 - 1)**2, 56 * l_xi3**3 - 63 * l_xi3**2 + 18 * l_xi3 - 1, (3 * l_xi2 + l_xi3 - 1) * (14 * l_xi3 + 7 * (2 * l_xi3 - 1)**2 - 6), -(8 * l_xi3 - 1) * (4 * l_xi2 * (l_xi3 - 1)**2 + 3 * (l_xi3 - 1)**3 - 5 * (l_xi3 - 1) * (2 * l_xi2 + l_xi3 - 1)**2) / (2 * l_xi3 - 2), 35 * l_xi2**3 + 45 * l_xi2**2 * l_xi3 - 45 * l_xi2**2 + 15 * l_xi2 * l_xi3**2 - 30 * l_xi2 * l_xi3 + 15 * l_xi2 + l_xi3**3 - 3 * l_xi3**2 + 3 * l_xi3 - 1, (14 * l_xi3 + 7 * (2 * l_xi3 - 1)**2 - 6) * (2 * l_xi1 + l_xi2 + l_xi3 - 1), (8 * l_xi3 - 1) * (5 * l_xi2 + l_xi3 - 1) * (2 * l_xi1 + l_xi2 + l_xi3 - 1), -(36 * l_xi2 * (l_xi3 - 1)**2 + 17 * (l_xi3 - 1)**3 - 21 * (l_xi3 - 1) * (2 * l_xi2 + l_xi3 - 1)**2) * (2 * l_xi1 + l_xi2 + l_xi3 - 1) / (4 * l_xi3 - 4), Fra(1, 2) * (8 * l_xi3 - 1) * (-(l_xi2 + l_xi3 - 1)**2 + 3 * (2 * l_xi1 + l_xi2 + l_xi3 - 1)**2), Fra(1, 2) * (-(l_xi2 + l_xi3 - 1)**2 + 3 * (2 * l_xi1 + l_xi2 + l_xi3 - 1)**2) * (7 * l_xi2 + l_xi3 - 1), -(6 * l_xi1 * (l_xi2 + l_xi3 - 1)**3 + 3 * (l_xi2 + l_xi3 - 1)**4 - 5 * (l_xi2 + l_xi3 - 1) * (2 * l_xi1 + l_xi2 + l_xi3 - 1)**3) / (2 * l_xi2 + 2 * l_xi3 - 2) ] # check FV basis l_syms, l_basis = Tet.gen(0) self.assertEqual(l_syms, [l_xi1, l_xi2, l_xi3]) self.assertEqual(l_basis, [sympy.sympify(1)]) # check degree 1 l_syms, l_basis = Tet.gen(1) self.assertEqual(l_syms, [l_xi1, l_xi2, l_xi3]) self.assertEqual(len(l_basis), 4) for l_ba in range(4): self.assertEqual(sympy.simplify(l_basis[l_ba] - l_basisUt[l_ba]), 0) # check degree 2 l_syms, l_basis = Tet.gen(2) self.assertEqual(l_syms, [l_xi1, l_xi2, l_xi3]) self.assertEqual(len(l_basis), 10) for l_ba in range(10): self.assertEqual(sympy.simplify(l_basis[l_ba] - l_basisUt[l_ba]), 0) # check degree 3 l_syms, l_basis = Tet.gen(3) self.assertEqual(l_syms, [l_xi1, l_xi2, l_xi3]) self.assertEqual(len(l_basis), 20) for l_ba in range(20): self.assertEqual(sympy.simplify(l_basis[l_ba] - l_basisUt[l_ba]), 0)