bar_mass[-1] = np.array([mass_matrix.compute_mass_matrix (length = bar_lengths.ravel()[i], density = density_2, sigma=0.)[0] ])
else:
	bar_mass = np.array ([ mass_matrix.compute_mass_matrix (length = bar_lengths.ravel()[i], density = density_1, sigma=None)[0] for i in range (B.shape[0]) ])

#compute external forces (gravity :)
external_forces_1 = np.zeros(N.shape)

if default_gravity == True:
	force_distribution_gravity = lambda x: (0,0,-9.81) # Earth's gravity
else:
	force_distribution_gravity = lambda x: (0,0,-gravity) # Titan's Gravity

for i in xrange(B.shape[0]):
	#this is pretty complicated for something really simple...
	if i<(B.shape[0]-1):
		f1_1,f2_1 = mass_matrix.compute_consistent_nodal_forces_vector(length=bar_lengths.ravel()[i],density=density_1,force_distribution=force_distribution_gravity)
		from_ = B[i].argmin()
		to_ = B[i].argmax()
		external_forces_1[from_] = f1_1
		external_forces_1[to_] = f2_1
	else:	
		f1_1,f2_1 = mass_matrix.compute_consistent_nodal_forces_vector(length=bar_lengths.ravel()[i],density=density_2,force_distribution=force_distribution_gravity)
		from_ = B[i].argmin()
		to_ = B[i].argmax()
		external_forces_1[from_] = f1_1
		external_forces_1[to_] = f2_1

print 'Gravity Forces'
print external_forces_1

external_forces_1_func = lambda t: (1*t*external_forces_1) #gravity is applied
#computed center of mass (to decouple rotational and translational eq. of motion)
bar_sigma = [1,0,None,None,None,1]
bar_massmatrix = [] #strut mass matrices 
for i in xrange(ico.B.shape[0]):
	b, bar_sigma[i], dummy = mass_matrix.compute_mass_matrix(length = strut_lengths[i], sigma=bar_sigma[i], density=
		lambda x: 0.5*ico.bar_mass[i]*(strut_lengths[i]/ico.bar_lengths[i,0] if x<ico.bar_lengths[i,0]/strut_lengths[i] else strut_lengths[i]/ico.bar_lengths[i,1]))
	bar_massmatrix.append(b)
bar_massmatrix = np.array(bar_massmatrix)

#compute nodal forces due to gravity

external_forces = np.zeros(ico.N.shape)
force_distribution = lambda x: (0,0,-9.81) 
for i in xrange(ico.B.shape[0]):
	#this is pretty complicated for something really simple...
	f0,f1 = mass_matrix.compute_consistent_nodal_forces_vector(length=strut_lengths[i],density=lambda x: 0.5*ico.bar_mass[i]*(strut_lengths[i]/ico.bar_lengths[i,0] if x<ico.bar_lengths[i,0]/strut_lengths[i] else strut_lengths[i]/ico.bar_lengths[i,1]),force_distribution=force_distribution)
	from_ = ico.B[i].argmin()
	to_ = ico.B[i].argmax()
	external_forces[from_] = f0
	external_forces[to_] = f1


#these springs show up blue in the GUI (easier to spot the actuators)
#ico.spring_
tagged_springs = np.zeros(ico.C.shape[0])
tagged_springs[-6:] = 1
constrained_nodes[:] = 0

constrained_nodes[1] = 1
constrained_nodes[2] = 1
constrained_nodes[11] = 1
        for i in range(B.shape[0])
    ])

#compute external forces (gravity :)
external_forces_1 = np.zeros(N.shape)

if default_gravity == True:
    force_distribution_gravity = lambda x: (0, 0, -9.81)  # Earth's gravity
else:
    force_distribution_gravity = lambda x: (0, 0, -gravity)  # Titan's Gravity

for i in xrange(B.shape[0]):
    #this is pretty complicated for something really simple...
    if i < (B.shape[0] - 1):
        f1_1, f2_1 = mass_matrix.compute_consistent_nodal_forces_vector(
            length=bar_lengths.ravel()[i],
            density=density_1,
            force_distribution=force_distribution_gravity)
        from_ = B[i].argmin()
        to_ = B[i].argmax()
        external_forces_1[from_] = f1_1
        external_forces_1[to_] = f2_1
    else:
        f1_1, f2_1 = mass_matrix.compute_consistent_nodal_forces_vector(
            length=bar_lengths.ravel()[i],
            density=density_2,
            force_distribution=force_distribution_gravity)
        from_ = B[i].argmin()
        to_ = B[i].argmax()
        external_forces_1[from_] = f1_1
        external_forces_1[to_] = f2_1