# Time series¶

This example illustrates the TIME_SERIES functionality in Solfec-1.0. The input files for this example are located in the solfec-1.0/examples/time–series directory. These are:

README – a text based summary of the examples

basic–ts.py – example of simple time series without a simulation

cached–ts.py – example of the partially cached time series capablity

labeled–ts.py – example of the labeled time series capability

ts–gen.py – generates time series data files ts–data–{1 .. 10}.txt

ts–data–{0 .. 10}.txt – time series data files

TIME_SERIES object can be used in Solfec-1.0 to prescribe time–dependent constraints and
loads. The three minimalist input files included with this example illustrate the ways the time series can be used:
Listing 11, Listing 12, Listing 13 below include comments and are self–explanatory. An animated output of the *cached–ts.py*
example is included as video 1.

```
1# basic applications of TIME_SERIES (points)
2import os
3d0 = os.path.dirname(os.path.realpath(__file__))
4
5tms1 = TIME_SERIES (d0+'/ts-data-0.txt');
6print 'From file:'
7print tms1.times
8print tms1.values
9
10list2 = [0, 10, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16];
11tms2 = TIME_SERIES (list2);
12print 'From [t0,v0, t1,v1, ..] list:'
13print tms2.times
14print tms2.values
15
16list3 = [[0, 10], [1, 11], [2, 12], [3, 13], [4, 14], [5, 15], [6, 16]];
17tms3 = TIME_SERIES (list3);
18print 'From [[t0,v0], [t1,v1], ...] list:'
19print tms3.times
20print tms3.values
21
22tms4 = tms3.derivative
23print 'Derivative:'
24print tms4.times
25print tms4.values
26
27tms5 = tms3.integral
28print 'Integral:'
29print tms5.times
30print tms5.values
```

```
1# partially cached TIME_SERIES ('data.txt', cache = N) example
2import os
3d0 = os.path.dirname(os.path.realpath(__file__))
4
5# create SOLFEC object and bulk material
6solfec = SOLFEC ('DYNAMIC', 1E-3, 'out/cached-ts')
7mat = BULK_MATERIAL (solfec, model = 'KIRCHHOFF',
8 young = 1E9, poisson = 0.3, density = 1E3)
9
10# create 10 rigid spheres following along the y-direction
11# the time series based displacement history; note that
12# in this case we use a unique time series for each body;
13# should the number of bodies and the size of the time series
14# be large - this would easily lead to using up all memory;
15# using partially cached time series allows to avoid this
16# issue; in our case we have 100 data points per series and
17# we set the partial cache size to 10; this means that only
18# 10 points are stored in memory, per series, at any time;
19for i in range (1, 11):
20 tms = TIME_SERIES (d0+'/ts-data-%d.txt' % i, cache = 10)
21 sph = SPHERE ((i, 0, 0), 0.4, 1, 1)
22 bod = BODY (solfec, 'RIGID', sph, mat)
23 SET_DISPLACEMENT (bod, (i, 0, 0), (0, 1, 0), tms)
24
25# create constraints solver and run simulation
26slv = NEWTON_SOLVER()
27RUN (solfec, slv, 1.0)
```

```
1# labeled TIME_SERIES ('data.txt', label = 'string') example
2import os
3d0 = os.path.dirname(os.path.realpath(__file__))
4
5# create SOLFEC object and bulk material
6solfec = SOLFEC ('DYNAMIC', 1E-3, 'out/labeled-ts')
7mat = BULK_MATERIAL (solfec, model = 'KIRCHHOFF',
8 young = 1E9, poisson = 0.3, density = 1E3)
9
10# create labeled time series object
11tms = TIME_SERIES (d0+'/ts-data-1.txt', label = 'data-1')
12
13# create 10 rigid spheres following along the y-direction
14# the time series based displacement history; note that
15# in this case, because the time series object was labeled,
16# only a single copy of the time series object will be used
17# internally - saving memory; should 'tms' be unlabeled 10
18# separate data sets would be used;
19for i in range (0, 10):
20 sph = SPHERE ((i, 0, 0), 0.4, 1, 1)
21 bod = BODY (solfec, 'RIGID', sph, mat)
22 SET_DISPLACEMENT (bod, (i, 0, 0), (0, 1, 0), tms)
23
24# create constraints solver and run simulation
25slv = NEWTON_SOLVER()
26RUN (solfec, slv, 1.0)
```

- 1
Animated output of the cached–ts.py example from Listing 12.