import sympy as sp
s = sp.Symbol
print 'sympy version ' + sp.__version__ + '\n'
def s_print(func_str, repl_str=None):
'''Print function and replace subexpression'''
print func_str + ' = \n'
if repl_str != None:
sp.pprint(eval(func_str).subs(eval(repl_str), s(repl_str)))
else:
sp.pprint(eval(func_str))
print '\n'
# (1) C_vss
phi, phi_t, C_t = sp.symbols('phi phi_t C_t')
C_vss = (sp.sqrt(2) + 1)*C_t*(sp.sqrt(1 + phi/phi_t) - 1)
s_print('C_vss')
# (2) D_star
C_vth, D_th = sp.symbols('C_vth D_th')
D_star = C_vss/C_vth * D_th
s_print('D_star', 'C_vss')
# (3) f_v
f_max, k_1, Phi = sp.symbols('f_max k_1, Phi')
f_v = f_max * (1 - sp.exp(-k_1 * (D_star/phi)**(sp.Rational(3,2))))
s_print('f_v', 'D_star')