def exercise1a(): """ Exercise 1a The goal of this exercise is to understand the relationship between muscle length and tension. Here you will re-create the isometric muscle contraction experiment. To do so, you will have to keep the muscle at a constant length and observe the force while stimulating the muscle at a constant activation.""" # Defination of muscles parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) pylog.info("Use the parameters object to change the muscle parameters") # Create muscle object muscle = Muscle(parameters) # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Set the initial condition x0 = [0.0, sys.muscle.L_OPT] # x0[0] --> muscle stimulation intial value # x0[1] --> muscle contracticle length initial value # Set the time for integration t_start = 0.0 t_stop = 0.5 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) # Evalute for a single muscle stimulation muscle_stimulation = np.arange(0, 1., 0.2) # Several muscle stretch muscle_stretches = np.arange(0, 0.3, 0.01) active_active = [] for stim in muscle_stimulation: active_forces = [] passive_forces = [] total = [] lengths = [] for stretch in muscle_stretches: # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=stim, muscle_length=stretch) active_forces.append(result.active_force[-1]) passive_forces.append(result.passive_force[-1]) total.append(result.active_force[-1] + result.passive_force[-1]) lengths.append(result.l_ce[-1]) active_active.append(active_forces) # Plotting plt.figure('Isometric muscle experiment 1') plt.plot(lengths, active_forces) plt.plot(lengths, passive_forces) plt.plot(lengths, total) plt.title('Isometric muscle experiment stimulation') plt.xlabel('Muscle stretch') plt.ylabel('Muscle force') plt.legend(('Active', 'Passive', 'Total')) plt.grid() plt.show() # Plotting plt.figure('Isometric muscle experiment 2') for i in range(len(muscle_stimulation)): plt.plot(lengths, active_active[i]) plt.title('Isometric muscle experiment') plt.xlabel('Muscle stretch') plt.ylabel('Muscle force') plt.legend(muscle_stimulation) plt.grid() plt.show() # Plotting #plt.figure('Isotonic muscle experiment') #plt.plot(result.time, result.v_ce) #plt.title('Isotonic muscle experiment') #plt.xlabel('Time [s]') #plt.ylabel('Muscle contractilve velocity') #plt.grid() #muscle with longer l_opt muscle.L_OPT = 0.5 muscle_stimulation = 1. lce = [] totalF = [] activeF = [] passiveF = [] for stretch in muscle_stretches: # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=stretch) activeF.append(result.active_force[-1]) passiveF.append(result.passive_force[-1]) lce.append(result.l_ce[-1]) totalF.append(result.active_force[-1] + result.passive_force[-1]) plt.figure('muscle with l_opt=0.5') plt.title('muscle with l_opt=0.5') plt.plot(lce, activeF) plt.plot(lce, passiveF) plt.plot(lce, totalF) plt.xlabel('Muscle Stretch') plt.ylabel('Force') plt.ylim((0, 4000)) plt.legend(('Active Force', 'Passive Force', 'Total Force')) plt.grid() #muscle with shorter l_opt t_start = 0.0 t_stop = 1 time_step = 0.005 time = np.arange(t_start, t_stop, time_step) muscle_stretches = np.arange(0, 0.3, 0.01) muscle.L_OPT = 0.075 muscle_stimulation = 1. lce = [] totalF = [] activeF = [] passiveF = [] plt.figure('muscle with l_opt=0.075') for stretch in muscle_stretches: # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=stretch) activeF.append(result.active_force[-1]) passiveF.append(result.passive_force[-1]) lce.append(result.l_ce[-1]) totalF.append(result.active_force[-1] + result.passive_force[-1]) plt.title('muscle with l_opt=0.075') plt.plot(lce, activeF) plt.plot(lce, passiveF) plt.plot(lce, totalF) plt.xlabel('Muscle Stretch') plt.ylabel('Force') plt.ylim((0, 4000)) plt.legend(('Active Force', 'Passive Force', 'Total Force')) plt.grid()
def exercise1c(): """ Exercice 1c """ # Defination of muscles parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) pylog.info("Use the parameters object to change the muscle parameters") # Create muscle object muscle = Muscle(parameters) # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Force-length curves # Set the initial condition x0 = [0.0, sys.muscle.L_OPT] # Set the time for integration t_start = 0.0 t_stop = 0.2 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) N_stretch = 40 activeF = np.zeros(N_stretch) passiveF = np.zeros(N_stretch) tendonF = np.zeros(N_stretch) lceF = np.zeros(N_stretch) # Evaluate for various optimal length l_opt_list = np.array([0.1, 0.3]) # Subplots grid n_plot = len(l_opt_list) n_subplot = int((np.sqrt(n_plot - 1)) + 1) if (n_plot <= n_subplot * (n_subplot - 1)): fig, axes = plt.subplots(n_subplot, n_subplot - 1) n_subplot2 = n_subplot - 1 else: fig, axes = plt.subplots(n_subplot, n_subplot) n_subplot2 = n_subplot for i, l_opt in enumerate(l_opt_list): # Evaluate for various muscle stretch muscle.L_OPT = l_opt stretch_min = muscle.L_OPT stretch_max = muscle.L_OPT * 3 muscle_stretch = np.arange(stretch_min, stretch_max, (stretch_max - stretch_min) / N_stretch) for stretch in range(len(muscle_stretch)): # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=1., muscle_length=muscle_stretch[stretch]) activeF[stretch] = result.active_force[-1] passiveF[stretch] = result.passive_force[-1] tendonF[stretch] = result.tendon_force[-1] lceF[stretch] = result.l_ce[-1] plt.subplot(n_subplot, n_subplot2, i + 1) plt.plot(lceF, 100 * activeF / muscle.F_MAX, label='Active Force') plt.plot(lceF, 100 * passiveF / muscle.F_MAX, label='Passive Force') plt.plot(lceF, 100 * tendonF / muscle.F_MAX, label='Tendon Force') plt.axvline(l_opt, linestyle="--", color="r") plt.xlim([l_opt - 0.3, l_opt + 0.3]) plt.ylim([0, 120]) plt.xlabel('Contractile element length') plt.ylabel('Force [% of $F_{max}$]') plt.title('Optimal length = {} [m]'.format(l_opt)) plt.legend() plt.grid() plt.suptitle( 'Force-length curves for isometric muscle experiment with various muscle optimal lengths' ) fig.tight_layout()