# Linear operator equation
LU_l = (1/Re)*(-dx(p1) + 2*dx(dx(U1)) + dy(U1y) + dx(V1y) - RaEr*(dx(Q11_1)) - RaEr*(dy(Q12_1))) + lift(tau_U12)
LU_r = - (U1*dx(U) + V1*dy(U)) - (U*dx(U1) + V*dy(U1))
LV_l = (1/Re)*(-dy(p1) + dx(U1y) + dx(dx(V1)) + 2*dy(V1y) - RaEr*(dx(Q12_1) - dy(Q11_1))) + lift(tau_V12)
LV_r = - (U1*dx(V) + V1*dy(V)) - (U*dx(V1) + V*dy(V1))
LQ11_l = lam*dx(U1) + Q11_1 + dx(dx(Q11_1)) + dy(Q11_1y) + lift(tau_Q11_21)
LQ11_r = - (30*Q11*Q11*Q11_1 + 10*Q12*Q12*Q11_1 + 20*Q12*Q12_1*Q11)- (U*dx(Q11_1) + V*dy(Q11_1) + U1*dx(Q11) + V1*dy(Q11)) + (dy(U))*Q12_1 + (dy(U1))*Q12 - (dx(V))*Q12_1 - (dx(V1))*Q12
LQ12_l = (lam/2)*(dy(U1) + dx(V1)) + Q12_1 + dx(dx(Q12_1)) + dy(Q12_1y) + lift(tau_Q12_21)
LQ12_r = - (10*Q11**2*Q12_1 + 30*Q12**2*Q12_1 + 20*Q11*Q12*Q11_1)- (U*dx(Q12_1) + V*dy(Q12_1) + U1*dx(Q12) + V1*dy(Q12)) - (dy(U))*Q11_1 - (dy(U1))*Q11 + (dx(V))*Q11_1 + (dx(V1))*Q11
# Divergence free condition
divU1 = (dx(U1)) + (V1y) + tau_p1
# Define N: Residuals
N1 = (1/T)*drho(U) - FU
N2 = (1/T)*drho(V) - FV
N3 = (1/T)*drho(Q11) - FQ11
N4 = (1/T)*drho(Q12) - FQ12
G2_rhs = integral((1/T**2)*(drho(U)*N1 + drho(V)*N2 + drho(Q11)*N3 + drho(Q12)*N4))
Equation_LHS_U = (1/T)*drho(U1) - LU_l - LU_r
Equation_RHS_U = -(1/T)*drho(U) + FU + (1/T**2)*G2*drho(U)
Equation_LHS_V = (1/T)*drho(V1) - LV_l - LV_r
Equation_RHS_V = -(1/T)*drho(V) + FV + (1/T**2)*G2*drho(V)
Equation_LHS_Q11 = (1/T)*drho(Q11_1) - LQ11_l - LQ11_r
Equation_RHS_Q11 = -(1/T)*drho(Q11) + FQ11 + (1/T**2)*G2*drho(Q11)
Equation_LHS_Q12 = (1/T)*drho(Q12_1) - LQ12_l - LQ12_r
Equation_RHS_Q12 = -(1/T)*drho(Q12) + FQ12 + (1/T**2)*G2*drho(Q12)
# problem
problem = d3.LBVP([U1,V1,Q11_1,Q12_1,p1,tau_U11,tau_U12,tau_V11,tau_V12,tau_Q11_11,tau_Q11_21,tau_Q12_11,tau_Q12_21,tau_p1], namespace = locals())
problem.add_equation("Equation_LHS_U = Equation_RHS_U")
problem.add_equation("Equation_LHS_V = Equation_RHS_V")
problem.add_equation("Equation_LHS_Q11 = Equation_RHS_Q11")
problem.add_equation("Equation_LHS_Q12 = Equation_RHS_Q12")
problem.add_equation("divU1 = 0")
problem.add_equation("integ_xy(p1) = 0") # pressure gauge
problem.add_equation("U1(y=0)=0")
problem.add_equation("U1(y=h)=0")
problem.add_equation("V1(y=0)=0")
problem.add_equation("V1(y=h)=0")
problem.add_equation("Q11_1(y=0) = 0")
problem.add_equation("Q11_1(y=h)= 0")
problem.add_equation("Q12_1(y=0) = 0")
problem.add_equation("Q12_1(y=h) = 0")