from sympy import *
init_printing(use_latex='mathjax')
from IPython import display

display.SVG('oiq-exam-1.svg')

from sdutil2 import SD, FEF
var('EI theta_a theta_b theta_c theta_d')
Mab,Mba,Vab,Vba = SD(6,EI,theta_a,theta_b) + FEF.p(6,180,4)
Mbc,Mcb,Vbc,Vcb = SD(8,2*EI,theta_b,theta_c) + FEF.udl(8,45)
Mcd,Mdc,Vcd,Vdc = SD(6,EI,theta_c,theta_d)

Mab

"""
Explanation: OIQ-Exam-Question-1 (Version 2)
Technical exam question from Ordre des ingénieurs du Québec.  Obviously meant to be done using moment-distribution, but even easier using slope-deflection.  This version use a newer 'sdutil' that also computes end shears.
End of explanation
"""


soln = solve( [Mab,Mba+Mbc,Mcb+Mcd,Mdc],[theta_a,theta_b,theta_c,theta_d] )
soln

"""
Explanation: Solve equilbrium equations for rotations:
End of explanation
"""


[m.subs(soln) for m in [Mab,Mba,Mbc,Mcb,Mcd,Mdc]]

"""
Explanation: Member end moments:
End of explanation
"""


[v.subs(soln).n(4) for v in [Vab,Vba,Vbc,Vcb,Vcd,Vdc]]

"""
Explanation: Member end shears:
End of explanation
"""


Ra = Vab
Rb = Vbc - Vba
Rc = Vcd - Vcb
Rd = -Vdc
[r.subs(soln).n(4) for r in [Ra,Rb,Rc,Rd]]

"""
Explanation: Reactions:
End of explanation
"""


# sum forces in vertical dirn.
(Ra+Rb+Rc+Rd - 180 - 45*8).subs(soln)

# sum moments about left
(-Rb*6 - Rc*(6+8) -Rd*(6+8+6) + 180*4 + 45*8*(6 + 8/2.)).subs(soln)

Ra.expand()

"""
Explanation: Check overal equilibrium
End of explanation
"""


