OpenMPCD
OrientationAngles.py
1 from .Base import Base
2 
3 class OrientationAngles(Base):
4  """
5  Class for analysis of the orientation of the eigenvectors of the gyration
6  tensor, relative to the flow direction.
7  """
8 
9  def __init__(self, run):
10  """
11  The constructor.
12 
13  @param[in] run
14  The run to analyze, as an instance of `Run`.
15  """
16 
17  super(OrientationAngles, self).__init__(run)
18 
19 
21  """
22  Returns a `matplotlib.axes.Axes` object that contains a plot of the
23  orientation angles of the three eigenvectors of the gyration tensor with
24  the flow direction, with the horizontal axis showing the simulation
25  time `t`, and the vertical axis showing the angles in radians.
26  """
27 
28  import matplotlib.figure
29 
30  figure = matplotlib.figure.Figure()
31  axes = figure.add_subplot(1, 1, 1)
32  lines = []
33  legendLabels = []
34 
35  data = self.getValueAsFunctionOfTime()
36  angles = [[], [], []]
37  for datum in data.values():
38  for i in [0, 1, 2]:
39  angles[i].append(datum[i][1])
40 
41  _line, = axes.plot(data.keys(), angles[0])
42  lines.append(_line)
43  legendLabels.append("Orientation Angle: Smallest Eigenvalue")
44 
45  _line, = axes.plot(data.keys(), angles[1])
46  lines.append(_line)
47  legendLabels.append("Orientation Angle: Middle Eigenvalue")
48 
49  _line, = axes.plot(data.keys(), angles[2])
50  lines.append(_line)
51  legendLabels.append("Orientation Angle: Largest Eigenvalue")
52 
53  axes.legend(lines, legendLabels)
54 
55  axes.set_title("Star Polymer Orientation Angles")
56  axes.set_xlabel("Simulation Time t")
57  axes.set_ylabel("Orientation Angles [rad]")
58 
59  return axes
60 
61 
62  def _computeValueAsFunctionOfTime(self):
63  """
64  Takes the raw simulation output, and computes the orientation angles as
65  a function of time. The result is returned as an
66  `collcections.OrderedDict`.
67  """
68 
69  from collections import OrderedDict
70 
71  config = self.getRun().getConfiguration()
72  snapshots = self._getSnapshots()
73  starPolymers = self._getStarPolymers()
74 
75  ret = OrderedDict()
76  timestep = config["mpc.timestep"]
77  time = timestep * config["mpc.warmupSteps"]
78 
79  while True:
80  time += timestep
81 
82  particles = snapshots.readTimestep()
83  particles.setUniformMass(starPolymers.getParticleMass())
84 
85  if particles.isEmpty():
86  break
87 
88  particles.shiftToCenterOfMassFrame()
89  starPolymers.setParticles(particles)
90 
91  ret[time] = particles.getOrientationAngles(self._getFlowDirection())
92 
93  return ret
94 
95 
96  def _getCacheFilename(self):
97  """
98  Returns the filename where cached data is (expected to be) saved to.
99  """
100 
101  return "orientationAngles.txt"
102 
103 
104  def _getCacheMetadata(self):
105  """
106  Returns the cache metadata.
107  """
108 
109  cacheVersion = 2
110 
111  metadata = \
112  {
113  "cacheVersion": cacheVersion,
114  "flowDirection": self._getFlowDirection()
115  }
116  return metadata
117 
118 
119  def _getCacheValueInterpreter(self):
120  """
121  Returns what is to be used as the `valueInterpreter` argument to
122  `Cache.getDataOrderedDict`.
123  """
124 
125  def valueInterpreter(string):
126  import ast
127  return ast.literal_eval(string)
128 
129  return valueInterpreter
130 
131 
132  def _getFlowDirection(self):
133  """
134  Returns the flow direction of shear flow.
135  """
136 
137  return [1.0, 0.0, 0.0]
MPCDAnalysis.StarPolymersAnalysis.Base.Base.getRun
def getRun(self)
Definition: Base.py:44
MPCDAnalysis.StarPolymersAnalysis.OrientationAngles.OrientationAngles.getMPLAxesForValueAsFunctionOfTime
def getMPLAxesForValueAsFunctionOfTime(self)
Definition: OrientationAngles.py:29
MPCDAnalysis.StarPolymersAnalysis.OrientationAngles.OrientationAngles.__init__
def __init__(self, run)
Definition: OrientationAngles.py:17
MPCDAnalysis.StarPolymersAnalysis.Base.Base._getSnapshots
def _getSnapshots(self)
Definition: Base.py:112
MPCDAnalysis.StarPolymersAnalysis.OrientationAngles.OrientationAngles._getFlowDirection
def _getFlowDirection(self)
Definition: OrientationAngles.py:143
MPCDAnalysis.StarPolymersAnalysis.Base.Base.getValueAsFunctionOfTime
def getValueAsFunctionOfTime(self)
Definition: Base.py:56
MPCDAnalysis.StarPolymersAnalysis.Base.Base._getStarPolymers
def _getStarPolymers(self)
Definition: Base.py:123