1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#!/usr/bin/env python
# encoding: utf-8
"""
_BreakpointSegment.py
Created by Graham Dennis on 2008-03-15.
Copyright (c) 2008-2012, Graham Dennis
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from xpdeint.Segments._Segment import _Segment
from xpdeint.ParserException import ParserException
from xpdeint.Utilities import lazy_property
class _BreakpointSegment (_Segment):
def __init__(self, *args, **KWs):
_Segment.__init__(self, *args, **KWs)
self.filename = None
self.field = None
self.outputGroups = 1
@lazy_property
def outputComponents(self):
result = []
for vector in self.orderedDependencies:
for componentName in vector.components:
result.append(componentName + 'R')
if vector.type == 'complex':
result.append(componentName + 'I')
return result
def bindNamedVectors(self):
super(_Segment, self).bindNamedVectors()
aVector = list(self.dependencies)[0]
for vector in self.dependencies:
if not vector.field.dimensions == aVector.field.dimensions:
raise ParserException(self.xmlElement, "All vectors for a breakpoint element must be have the same dimensions.\n"
"The conflicting vectors are: '%s' and '%s'." % (vector.name, aVector.name))
self.field = aVector.field
# We rely on a constant order for our dependencies when writing out
self.orderedDependencies = list(self.dependencies)
def preflight(self):
super(_Segment, self).preflight()
if self.dependenciesEntity.xmlElement.hasAttribute('basis'):
spaceString = self.dependenciesEntity.xmlElement.getAttribute('basis')
self.breakpointBasis = \
self.field.basisFromString(
self.dependenciesEntity.xmlElement.getAttribute('basis'),
xmlElement = self.dependenciesEntity.xmlElement
)
else:
self.breakpointBasis = self.field.defaultCoordinateBasis
# Use the output format used for output if one isn't specified
if not self.hasattr('outputFormat'):
self.outputFormat = type(self.getVar('features')['Output'].outputFormat)(
parent = self,
**self.argumentsToTemplateConstructors
)
self._children.append(self.outputFormat)
if self.outputFormat.name == 'hdf5':
# HDF5 doesn't like writing out data when the order of dimensions in the file and
# in memory aren't the same. It's slow. So we make sure that we sample in the same
# order that we would write out to file. But only for HDF5 as this requires extra
# MPI Transpose operations at each sample.
driver = self._driver
self.breakpointBasis = driver.canonicalBasisForBasis(self.breakpointBasis, noTranspose = True)
self.registerVectorsRequiredInBasis(self.dependencies, self.breakpointBasis)
|