← Back to team overview

yade-users team mailing list archive

Re: [Question #227428]: plot multiple plots at different iterPeriods

 

Question #227428 on Yade changed:
https://answers.launchpad.net/yade/+question/227428

    Status: Open => Answered

Christian Jakob proposed the following answer:
Hallo Eugen,

Ich persoenlich bevorzuge Daten waehrend der Rechnung in einer Textdatei zu speichern ...
Personally I prefer to store data during simulation in a text file ...

e.g. every 100th step:

f = open(outputfilename, 'a')
f.write('%f %f %f %f %f' % (vel_av,coord_num,poro_now,F_unbal,rel_time))
for x in range(0,3):
	for y in range(0,3):
		f.write(' %f' % cap_stress[x,y])
f.write('%f %f %f %f %f %f %f %f %f %f' % (E_kin_trans,E_kin_rot,E_pot,E_total,local_damp_dissip,norm_damp_dissip,shear_damp_dissip,fric_dissip,plastic_dissip,E_dissip))
f.write('\n')
f.close()

Nachdem die Rechnung beendet ist, wird die Datei ausgelesen und die plots erzeugt...
After simulation finished, file is read and plots are created ...

(here my full script:)

#!/usr/bin/python
# -*- coding: utf-8 -*-

vel_av_list		= []
coord_list		= []
poro_list		= []
F_unbal_list	= []
rel_time_list	= []
trace_stress	= []
E_kin_trans_list= []
E_kin_rot_list	= []
E_pot_list		= []
E_total_list	= []
local_damp_dissip_list	= []
norm_damp_dissip_list	= []
shear_damp_dissip_list	= []
fric_dissip_list		= []
plastic_dissip_list		= []
E_dissip_list			= []

#get data from table file:
f = open(outputfilename, 'r')
c_line = 0
for line in f:
	c_line += 1
	if c_line == 1:
		header = str(line)
	else:
		tmp_line = str(line)
		tmp_value_list = tmp_line.split(" ")
		vel_av_list.append(float(tmp_value_list[0]))
		coord_list.append(float(tmp_value_list[1]))
		poro_list.append(float(tmp_value_list[2]))
		F_unbal_list.append(float(tmp_value_list[3]))
		rel_time_list.append(float(tmp_value_list[4]))
		trace_stress.append(float(tmp_value_list[5]) + float(tmp_value_list[9]) + float(tmp_value_list[13]))
		E_kin_trans_list.append(float(tmp_value_list[14]))
		E_kin_rot_list.append(float(tmp_value_list[15]))
		E_pot_list.append(float(tmp_value_list[16]))
		E_total_list.append(float(tmp_value_list[17]))
		local_damp_dissip_list.append(float(tmp_value_list[18]))
		norm_damp_dissip_list.append(float(tmp_value_list[19]))
		shear_damp_dissip_list.append(float(tmp_value_list[20]))
		fric_dissip_list.append(float(tmp_value_list[21]))
		plastic_dissip_list.append(float(tmp_value_list[22]))
		E_dissip_list.append(float(tmp_value_list[23]))
f.close()

#get maximum and minimum of porosity:
poro_max = max(poro_list)
poro_min = min(poro_list)

### make a nice plot:
from pylab import *		#overwrites angle, box, ... see 0-generate.py

font_global = {'family':'serif','weight':'normal'}
rc('font', **font_global)

# adapt font and style to latex-similar pendant:
from matplotlib.font_manager import FontProperties
font = FontProperties()
font.set_size('x-large')
font.set_family('serif')
# for more arguments see here:
# http://matplotlib.sourceforge.net/api/font_manager_api.html?highlight=set_size#matplotlib.font_manager.FontProperties

figure()
plot(rel_time_list, vel_av_list, label = 'average velocity of particles')
xlabel('time in [s]',fontproperties=font)
ylabel('average velocity in [m/s]',fontproperties=font)
savefig(savefigname_av_vel)

figure()
plot(rel_time_list, coord_list, label = 'coordination number')
xlabel('time in [s]',fontproperties=font)
ylabel('coordination number',fontproperties=font)
savefig(savefigname_coord)

figure()
plot(rel_time_list, poro_list, label = 'porosity')
xlabel('time in [s]',fontproperties=font)
ylabel('porosity in [%]',fontproperties=font)
ylim(poro_min-1,poro_max+1)
savefig(savefigname_poro)

figure()
plot(rel_time_list, F_unbal_list, label = 'unbalanced force')
xlabel('time in [s]',fontproperties=font)
ylabel('unbalanced force in [%]',fontproperties=font)
savefig(savefigname_unbal)

figure()
plot(rel_time_list, trace_stress, label = 'capillary stress')
xlabel('time in [s]',fontproperties=font)
ylabel('capillary stress in [N/m^2]',fontproperties=font)
savefig(savefigname_stress)

figure()
plot(rel_time_list, E_kin_trans_list, label = 'translational energy')
plot(rel_time_list, E_kin_rot_list, label = 'rotational energy')
plot(rel_time_list, E_pot_list, label = 'potential energy')
plot(rel_time_list, E_total_list, label = 'total energy (sum)')
xlabel('time in [s]',fontproperties=font)
ylabel('energy in [J]',fontproperties=font)
legend()
savefig(savefigname_energy)

figure()
plot(rel_time_list, local_damp_dissip_list, label = 'energy dissipation from local damping')
plot(rel_time_list, norm_damp_dissip_list, label = 'energy dissipation from viscous normal damping')
plot(rel_time_list, shear_damp_dissip_list, label = 'energy dissipation from viscous shear damping')
plot(rel_time_list, fric_dissip_list, label = 'energy dissipation from friction')
plot(rel_time_list, plastic_dissip_list, label = 'energy dissipation from plastic deformation')
plot(rel_time_list, E_dissip_list, label = 'total energy dissipation (sum)')
xlabel('time in [s]',fontproperties=font)
ylabel('energy dissipation in [J]',fontproperties=font)
legend()
savefig(savefigname_energy_dissip)

hope it helps,

Gruss aus Freiberg ;)

Christian

-- 
You received this question notification because you are a member of
yade-users, which is an answer contact for Yade.