Exemplo n.º 1
0
	def __init__(self,N,Omega):

		self.mesh = smartminex_tayhoomesh.getmake_mesh(N)
		self.N = N
		self.V = VectorFunctionSpace(self.mesh, "CG", 2)
		self.Q = FunctionSpace(self.mesh, "CG", 1)
		self.velbcs = setget_velbcs_zerosq(self.mesh, self.V)
		self.Pdof = 0  #dof removed in the p approximation
		self.omega = Omega
		self.nu = 0
		self.fp = Constant((0))
		self.fv = Expression(("40*nu*pow(x[0],2)*pow(x[1],3)*sin(omega*t) - 60*nu*pow(x[0],2)*pow(x[1],2)*sin(omega*t) + 24*nu*pow(x[0],2)*x[1]*pow((x[0] - 1),2)*sin(omega*t) + 20*nu*pow(x[0],2)*x[1]*sin(omega*t) - 12*nu*pow(x[0],2)*pow((x[0] - 1),2)*sin(omega*t) - 32*nu*x[0]*pow(x[1],3)*sin(omega*t) + 48*nu*x[0]*pow(x[1],2)*sin(omega*t) - 16*nu*x[0]*x[1]*sin(omega*t) + 8*nu*pow(x[1],3)*pow((x[0] - 1),2)*sin(omega*t) - 12*nu*pow(x[1],2)*pow((x[0] - 1),2)*sin(omega*t) + 4*nu*x[1]*pow((x[0] - 1),2)*sin(omega*t) - 4*pow(x[0],3)*pow(x[1],2)*pow((x[0] - 1),3)*(2*x[0] - 1)*pow((x[1] - 1),2)*(2*x[1]*(x[1] - 1) + x[1]*(2*x[1] - 1) + (x[1] - 1)*(2*x[1] - 1) - 2*pow((2*x[1] - 1),2))*pow(sin(omega*t),2) - 4*pow(x[0],2)*pow(x[1],3)*pow((x[0] - 1),2)*omega*cos(omega*t) + 6*pow(x[0],2)*pow(x[1],2)*pow((x[0] - 1),2)*omega*cos(omega*t) - 2*pow(x[0],2)*x[1]*pow((x[0] - 1),2)*omega*cos(omega*t) + 2*x[0]*pow(x[1],2)*sin(omega*t) - 2*x[0]*x[1]*sin(omega*t) - pow(x[1],2)*sin(omega*t) + x[1]*sin(omega*t)", "-40*nu*pow(x[0],3)*pow(x[1],2)*sin(omega*t) + 32*nu*pow(x[0],3)*x[1]*sin(omega*t) - 8*nu*pow(x[0],3)*pow((x[1] - 1),2)*sin(omega*t) + 60*nu*pow(x[0],2)*pow(x[1],2)*sin(omega*t) - 48*nu*pow(x[0],2)*x[1]*sin(omega*t) + 12*nu*pow(x[0],2)*pow((x[1] - 1),2)*sin(omega*t) - 24*nu*x[0]*pow(x[1],2)*pow((x[1] - 1),2)*sin(omega*t) - 20*nu*x[0]*pow(x[1],2)*sin(omega*t) + 16*nu*x[0]*x[1]*sin(omega*t) - 4*nu*x[0]*pow((x[1] - 1),2)*sin(omega*t) + 12*nu*pow(x[1],2)*pow((x[1] - 1),2)*sin(omega*t) + 4*pow(x[0],3)*pow(x[1],2)*pow((x[1] - 1),2)*omega*cos(omega*t) - 4*pow(x[0],2)*pow(x[1],3)*pow((x[0] - 1),2)*pow((x[1] - 1),3)*(2*x[1] - 1)*(2*x[0]*(x[0] - 1) + x[0]*(2*x[0] - 1) + (x[0] - 1)*(2*x[0] - 1) - 2*pow((2*x[0] - 1),2))*pow(sin(omega*t),2) - 6*pow(x[0],2)*pow(x[1],2)*pow((x[1] - 1),2)*omega*cos(omega*t) + 2*pow(x[0],2)*x[1]*sin(omega*t) - pow(x[0],2)*sin(omega*t) + 2*x[0]*pow(x[1],2)*pow((x[1] - 1),2)*omega*cos(omega*t) - 2*x[0]*x[1]*sin(omega*t) + x[0]*sin(omega*t)"), t=0, nu=self.nu, omega = self.omega )

		self.v = Expression((
			"sin(omega*t)*x[0]*x[0]*(1 - x[0])*(1 - x[0])*2*x[1]*(1 - x[1])*(2*x[1] - 1)", 
			"sin(omega*t)*x[1]*x[1]*(1 - x[1])*(1 - x[1])*2*x[0]*(1 - x[0])*(1 - 2*x[0])"), omega = self.omega, t = 0)
		self.vdot = Expression((
			"omega*cos(omega*t)*x[0]*x[0]*(1 - x[0])*(1 - x[0])*2*x[1]*(1 - x[1])*(2*x[1] - 1)",
			"omega*cos(omega*t)*x[1]*x[1]*(1 - x[1])*(1 - x[1])*2*x[0]*(1 - x[0])*(1 - 2*x[0])"), omega = self.omega, t = 0)
		self.p =  Expression(("sin(omega*t)*x[0]*(1-x[0])*x[1]*(1-x[1])"), omega = self.omega, t = 0)

		bcinds = []
		for bc in self.velbcs:
			bcdict = bc.get_boundary_values()
			bcinds.extend(bcdict.keys())

		# indices of the inner velocity nodes
		self.invinds = np.setdiff1d(range(self.V.dim()),bcinds)
Exemplo n.º 2
0
    def test_rearrange_matrices(self):
        """check the algorithm rearranging for B2, solve the

		rearranged system and sort back the solution vector 
		The rearr. is done by swapping columns in the coeff matrix,
		thus the resort is done by swapping the entries of the solution
		vector"""

        from dolfin import *
        import test_time_schemes as tts
        import dolfin_to_nparrays as dtn
        from smamin_utils import col_columns_atend, revert_sort_tob2
        import smartminex_tayhoomesh

        N = 32
        mesh = smartminex_tayhoomesh.getmake_mesh(N)

        V = VectorFunctionSpace(mesh, "CG", 2)
        Q = FunctionSpace(mesh, "CG", 1)

        velbcs = tts.setget_velbcs_zerosq(mesh, V)

        bcinds = []
        for bc in velbcs:
            bcdict = bc.get_boundary_values()
            bcinds.extend(bcdict.keys())

            # indices of the inner velocity nodes
        invinds = np.setdiff1d(range(V.dim()), bcinds)

        Ma, Aa, BTa, Ba, MPa = dtn.get_sysNSmats(V, Q)

        Mc = Ma[invinds, :][:, invinds]
        Ac = Aa[invinds, :][:, invinds]
        Bc = Ba[:, invinds]
        BTc = BTa[invinds, :]

        B2BubInds = smartminex_tayhoomesh.get_B2_bubbleinds(N, V, mesh)
        # B2BubInds = np.array([2,4])
        # we need the B2Bub indices in the reduced setting vc
        # this gives a masked array of boolean type
        B2BubBool = np.in1d(np.arange(V.dim())[invinds], B2BubInds)
        # B2BubInds = np.arange(len(B2BubIndsBool

        Nv = len(invinds)
        Np = Q.dim()
        dt = 1.0 / N

        # the complement of the bubble index in the inner nodes
        BubIndC = ~B2BubBool  # np.setdiff1d(np.arange(Nv),B2BubBool)
        # the bubbles as indices
        B2BI = np.arange(len(B2BubBool))[B2BubBool]

        # Reorder the matrices for smart min ext
        MSme = col_columns_atend(Mc, B2BI)
        BSme = col_columns_atend(Bc, B2BI)

        B1Sme = BSme[:, : Nv - (Np - 1)]
        B2Sme = BSme[:, Nv - (Np - 1) :]

        M1Sme = MSme[:, : Nv - (Np - 1)]
        M2Sme = MSme[:, Nv - (Np - 1) :]

        IterA1 = sps.hstack([sps.hstack([M1Sme, dt * M2Sme]), -dt * BTc[:, 1:]])

        IterA2 = sps.hstack([sps.hstack([B1Sme[1:, :], dt * B2Sme[1:, :]]), sps.csr_matrix((Np - 1, (Np - 1)))])
        # The rearranged coefficient matrix
        IterARa = sps.vstack([IterA1, IterA2])

        IterAqq = sps.hstack([Mc, -dt * BTc[:, 1:]])
        IterAp = sps.hstack([Bc[1:, :], sps.csr_matrix((Np - 1, Np - 1))])
        # The actual coefficient matrix
        IterA = sps.vstack([IterAqq, IterAp])

        rhs = np.random.random((Nv + Np - 1, 1))

        SolActu = sps.linalg.spsolve(IterA, rhs)
        SolRa = sps.linalg.spsolve(IterARa, rhs)

        # Sort it back
        # manually
        SortBack = np.zeros((Nv + Np - 1, 1))
        # q1
        SortBack[BubIndC, 0] = SolRa[: Nv - (Np - 1)]
        # tq2
        SortBack[B2BI, 0] = dt * SolRa[Nv - (Np - 1) : Nv]
        SortBack[Nv:, 0] = SolRa[Nv:]

        SolRa = np.atleast_2d(SolRa).T

        # and by function
        SolRa[Nv - (Np - 1) : Nv, 0] = dt * SolRa[Nv - (Np - 1) : Nv, 0]
        SB2 = revert_sort_tob2(SolRa[:Nv,], B2BI)
        SB2 = np.vstack([SB2, SolRa[Nv:,]])
        # SB2v = np.atleast_2d(SB2)

        SolActu = np.atleast_2d(SolActu)
        SortBack = np.atleast_2d(SortBack).T

        # print SolActu
        # print SolRa
        # print SortBack
        # print SB2

        self.assertTrue(np.allclose(SolActu, SortBack, atol=1e-6))
        self.assertTrue(np.allclose(SolActu, SB2.T, atol=1e-6))