~fluidity-core/fluidity/refactor-netcdf

« back to all changes in this revision

Viewing changes to tests/mphase_rogue_shock_tube_dense_bed_nylon/get_cloud_front.py

  • Committer: Jon Hill
  • Date: 2013-05-19 09:42:51 UTC
  • mfrom: (3981.7.211 fluidity)
  • Revision ID: jon.hill@imperial.ac.uk-20130519094251-igcsjwdskghswxlo
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
''' 
 
4
   Python script to measure the position of the particle cloud front in
 
5
   simulations of the shock tube experiment by Rogue et al. (1998).
 
6
   Written by Christian Jacobs.
 
7
'''
 
8
 
 
9
from fluidity_tools import stat_parser
 
10
import vtktools
 
11
import numpy, scipy, pylab
 
12
import os
 
13
from math import sqrt, fabs
 
14
import sys
 
15
 
 
16
def get_cloud_front(path_prefix, n_files, resolution, threshold):
 
17
   
 
18
   # Size of the domain
 
19
   lx = 0.025
 
20
   ly = 4.5
 
21
   
 
22
   # Arrays to store the results
 
23
   # Note: n_files is the number of VTU files to be read.
 
24
   upper_positions = numpy.zeros(n_files)
 
25
   lower_positions = numpy.zeros(n_files)
 
26
   times = numpy.zeros(n_files)
 
27
 
 
28
   path = path_prefix# + "/output/"
 
29
      
 
30
   # For each vtu file...
 
31
   for i in range(0, n_files, 20):
 
32
      # Open the VTU files one by one
 
33
      try:
 
34
         file = vtktools.vtu(path + '/mphase_rogue_shock_tube_dense_bed_nylon_' + str(i) + '.pvtu')  
 
35
      except:
 
36
         print "WARNING: Could not open VTU file!"
 
37
         front_position[i] = 0
 
38
         times[i] = 0
 
39
         continue
 
40
      file.GetFieldNames()
 
41
      
 
42
      time = max(file.GetScalarField('Gas::Time'))
 
43
      print "At time t = %f s" % time
 
44
      
 
45
      # Generate a set of probe positions
 
46
      probes = numpy.linspace(1.35, 1.7, (ly/resolution))
 
47
      
 
48
      # Loop over each of the probes in the y direction, from the top down
 
49
      for j in range(len(probes)-1, -1, -1):
 
50
         vfrac = vtktools.vtu.ProbeData(file, numpy.array([[0.0, probes[j], 0]]), 'Particles::PhaseVolumeFraction')
 
51
         if(vfrac >= 0.3):
 
52
            upper_positions[i] = probes[j]
 
53
            break
 
54
            
 
55
      for j in range(0, len(probes)):
 
56
         vfrac = vtktools.vtu.ProbeData(file, numpy.array([[0.0, probes[j], 0]]), 'Particles::PhaseVolumeFraction')
 
57
         if(vfrac >= 0.01):
 
58
            lower_positions[i] = probes[j]
 
59
            break
 
60
 
 
61
      times[i] = time - 0.0008
 
62
         
 
63
   return times, upper_positions, lower_positions
 
64
   
 
65
#get_cloud_front(sys.argv[1], int(sys.argv[2]), float(sys.argv[3]), float(sys.argv[4]))
 
66
 
 
67
times, upper_positions, lower_positions = get_cloud_front("./", 501, 0.0085, 0.05)
 
68
 
 
69
f = open('upper.prn', 'r')
 
70
experimental_times = []
 
71
experimental_positions = []
 
72
for line in f:
 
73
   (t, p) = line.split("\t")
 
74
   experimental_times.append(float(t))
 
75
   experimental_positions.append(float(p)*100)
 
76
f.close()
 
77
pylab.plot(experimental_times, experimental_positions, '-r', label="Experimental (upper)")
 
78
 
 
79
f = open('lower.prn', 'r')
 
80
experimental_times = []
 
81
experimental_positions = []
 
82
for line in f:
 
83
   (t, p) = line.split("\t")
 
84
   experimental_times.append(float(t))
 
85
   experimental_positions.append(float(p)*100)
 
86
f.close()
 
87
pylab.plot(experimental_times, experimental_positions, '-b', label="Experimental (lower)")
 
88
 
 
89
for i in range(0, len(upper_positions)):
 
90
   upper_positions[i] = (upper_positions[i] - 1.35)*100 # Centre abscissa and convert to cm.
 
91
   lower_positions[i] = (lower_positions[i] - 1.35)*100 # Centre abscissa and convert to cm.
 
92
pylab.plot(times, upper_positions, 'ro', label="Fluidity (upper)")
 
93
pylab.plot(times, lower_positions, 'bo', label="Fluidity (lower)")
 
94
pylab.axis([0, 0.004, 0, 10])
 
95
pylab.title("Position of lower and upper front of a 2 cm particle bed")
 
96
pylab.xlabel("Time (s)")
 
97
pylab.ylabel("Distance from bottom of particle bed (cm)")
 
98
pylab.legend(loc=2)
 
99
pylab.savefig('test.png')
 
100