a particle object stores a history of a single particle, each element of which is a particleInstance object.
| 126 | |
| 127 | #------------------------------------------------------------------------ |
| 128 | class particle(object): |
| 129 | """ |
| 130 | a particle object stores a history of a single particle, each |
| 131 | element of which is a particleInstance object. |
| 132 | """ |
| 133 | |
| 134 | __slots__ = ["pid", "originCPU", "dim", "finalized", |
| 135 | "history", "dataNames", "numInstances"] |
| 136 | |
| 137 | def __new__(cls, pid=None, originCPU=None, *args, **kwargs): |
| 138 | """ |
| 139 | Create a new particle instance in the global _particleDict |
| 140 | dictionary. |
| 141 | """ |
| 142 | |
| 143 | # before building a new particle, make sure it isn't already |
| 144 | # built by checking the global _particleDict |
| 145 | id = pid*_idFactor + originCPU |
| 146 | if id not in _particleDict: |
| 147 | obj = object.__new__(cls) |
| 148 | _particleDict[id] = obj |
| 149 | return _particleDict[id] |
| 150 | |
| 151 | |
| 152 | |
| 153 | def __init__(self, pid, originCPU, dim, dataNames): |
| 154 | """ |
| 155 | initialize a particle object |
| 156 | """ |
| 157 | |
| 158 | # a MAESTRO particle is identified by 2 numbers, the pid and |
| 159 | # the CPU that it was created on. Together, these uniquely |
| 160 | # identify the particle. |
| 161 | self.pid = pid |
| 162 | self.originCPU = originCPU |
| 163 | |
| 164 | # dimensionality of particle data |
| 165 | self.dim = dim |
| 166 | |
| 167 | # finalized is 1 when we have finished adding data and sorted |
| 168 | # the history in time-order |
| 169 | self.finalized = 0 |
| 170 | |
| 171 | # the history list will store instances of the particle at |
| 172 | # different times. |
| 173 | self.history = [] |
| 174 | |
| 175 | # the dataNames will store the names of the data associated |
| 176 | # with each particle instance |
| 177 | self.dataNames = list(dataNames) |
| 178 | |
| 179 | # keep track of the number of particle history instances we've |
| 180 | # stored |
| 181 | self.numInstances = 0 |
| 182 | |
| 183 | |
| 184 | |
| 185 | def addInstance(self, xyz=[-1.0,-1.0,-1.0],t=0.0, |