Load the data to plot

Asked by Przemek

Hi,

I have a question about plotting the results from file. I generated some data and now I want to load them to compare with DEM simulation in real time. How I can do that?

BR
Przemek

Question information

Language:
English Edit question
Status:
Answered
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Jan Stránský (honzik) said :
#1

Hello,

could you please be more specific on what exactly you are looking for? Like at this time I want to see this, at that time I want to see that... Ideally with some simple example generated data and code..
This short description is too ambiguous, I can imagine various scenarios fitting the description..

Cheers
Jan

Revision history for this message
Przemek (przemekn) said :
#2

Hi,

I'm sorry for my incomprehensible question. Let me explain.

I generated data for analytical solution which I want to compare with DEM result simultaneously to proceeded simulation, e.g.

i1 - data from txt file
t1 - data from txt file
t2 - data from simulation

plot.plots={'i1':('t1, t2')}

BR
Przemek

Revision history for this message
Karol Brzezinski (kbrzezinski) said (last edit ):
#3

Hi Przemek,

MWE always makes it easier for everyone[1].

Do you mean something like this?

##### MWE
from yade import plot
import matplotlib.pyplot as plt

s =sphere((0,0,0),0.001)
O.bodies.append(s)
s.state.vel = (0,0,1)

O.engines += [PyRunner(command = "plot.addData(t = O.time, z = s.state.displ()[2])", virtPeriod = 10)]

O.dt = 1e-8

plot.plots = {'t':'z'}
plot.plot()

### adding own data
ax = plt.gcf().gca()# get current 'plot' by using standard Python library
ax.plot((10,20,30,40,50,60,70),(s10,20,30,40,50,60,70),'o')# add own data

O.run(int(1e7))
########

Cheers,
Karol

[1] https://www.yade-dem.org/wiki/Howtoask

Revision history for this message
Jan Stránský (honzik) said :
#4

I think there more options how to do it.
Below is one example.
Adjust it according to your needs - the information provided is still not very informative (e.g. we can only guess if "i" is O.iter or not, what "t1" and "t2" might be etc.)
The example blow is based on O.time

#### saved.txt
# time value
1 1.0
2 0.6
3 0.4
4 0.3
5 0.4
6 0.6
7 0.7
8 0.6
9 0.4
10 0.3
11 0.1
12 0.2
13 0.4
14 0.7
15 0.8
16 1.0
17 0.9
18 0.7
19 0.4
20 0.1
####

#### script.py
from yade import plot
import numpy

saved = numpy.loadtxt("saved.txt") # load saved data
savedTimes = saved[:,0] # 1st comlumn
savedValues = saved[:,1] # 2nd comlumn

def plotAddData():
    time = O.time
    # simulation vlaue
    value = 0.5 + 0.5 * sin(time)
    # interpolated saved value
    savedValue = numpy.interp(time,savedTimes,savedValues)
    plot.addData(
        time = time,
        value = value,
        savedValue = savedValue,
    )

O.engines = [
    PyRunner(virtPeriod=0.2, command="plotAddData()"),
]

plot.plots = {"time":("value","savedValue")}
plot.plot()

O.stopAtTime = 20

O.dt = 1e-6
O.run()
####

Cheers
Jan

Revision history for this message
Przemek (przemekn) said :
#5

Hi,

Thank you both. Now I get how to do that.

BR
Przemek

Can you help with this problem?

Provide an answer of your own, or ask Przemek for more information if necessary.

To post a message you must log in.