Ejemplo n.º 1
0
	def segmentation_type(self):
		"""
		Return appropriate segmentation type based on this configuration
		
		:returns: Low-level segmentation type
		"""
		classname = ''.join([self.cell_tag.title(), self.coord_system.title(), str(self.dim), 'D_Segmentation'])
		return _wrapper.__getattribute__(classname)
Ejemplo n.º 2
0
	def point_type(self):
		"""
		Return appropriate point type based on this configuration
		
		:returns: Low-level point type
		"""
		classname = ''.join(['Point', self.coord_system.title(), str(self.dim), 'D'])
		return _wrapper.__getattribute__(classname)
Ejemplo n.º 3
0
	def make_accessor(self, accessor_type):
		"""
		Create a new low-level (:mod:`viennagrid.wrapper`) accessor or field based on this configuration.
		
		:param domain: Domain on which to base the segmentation.
		:type domain: A domain class from :mod:`viennagrid.wrapper` which matches this configuration class
		
		:returns: Low-level accessors or field
		"""
		classname = ''.join([self.cell_tag.title(), self.coord_system.title(), str(self.dim), 'D_', accessor_type.title(), '_Accessor'])
		cls = _wrapper.__getattribute__(classname)
		return cls()
Ejemplo n.º 4
0
	def __init__(self, *args, **kwargs):
		"""
		Define a new point specifying its coordinate system, dimension and, optionally, coordinates.
		
		Args:
			coordinates of the point (optional)
		
		Kwargs:
			* coord_system: coordinate system tag (if omitted, cartesian is assumed)
			* dim: dimension of the space (optional if coordinates are specified)
		"""
		
		super(Point, self).__init__()
		
		_coords = None
		_coord_system = None
		_dim = None
		
		# Extract coordinate system tag from keyword arguments or use default (cartesian)
		try:
			_coord_system = kwargs['coord_system']
		except KeyError:
			_coord_system = config.CARTESIAN
		else:
			if not isinstance(_coord_system, str):
				raise TypeError('Coordinate system tag must be a string.')
			if _coord_system not in config.COORD_SYSTEM_TAGS:
				raise ValueError('Unknown coordinate system tag.')
		
		# If point coordinates (2 or 3 positional arguments) have been specified, store coordinates
		# and imply dimension of the space.
		if len(args) in config.SUPPORTED_DIMENSIONS[_coord_system]:
			for i, elem in enumerate(args):
				if not isinstance(elem, (int, long, float, complex)):
					cls_name = elem.__class__.__name__
					raise TypeError('Coordinate %(i)d is non-numeric. Point coordinates must be numeric, got an instance of "%(cls_name)s" instead.' % locals())
			_coords = args
			_dim = len(args)
			
			# Check if keyword argument 'dim' matches number of positional arguments (point coordinates).
			# If it matches or has not been specified, ignore. If it does not match, raise an exception.
			try:
				dim = kwargs['dim']
			except KeyError:
				pass
			else:
				if not isinstance(dim, int):
					raise TypeError('Dimension must be an integer.')
				if dim != _dim:
					raise ValueError('Keyword argument "dim" does not match number of positional arguments.')
				_dim = dim
		# If no positional arguments have been specified, initialize coordinates to zero and extract
		# dimension from keyword arguments. If no dimension has been specified, raise an exception.
		elif not args:
			try:
				dim = kwargs['dim']
			except KeyError:
				if len(config.SUPPORTED_DIMENSIONS[_coord_system]) == 1:
					_dim = config.SUPPORTED_DIMENSIONS[_coord_system][0]
				else:
					raise TypeError('Space dimension has not been specified. You must either specify the dimension or the point coordinates.')
			else:
				if not isinstance(dim, int):
					raise TypeError('Dimension must be an integer.')
				if dim not in config.SUPPORTED_DIMENSIONS[_coord_system]:
					coord_system_name = _coord_system
					supported_dims = ', '.join(str(x) for x in config.SUPPORTED_DIMENSIONS[_coord_system])
					raise ValueError('Unsupported dimension. Only the following dimensions are supported for %(coord_system_name)s points: %(supported_dims)s.' % locals())
				_dim = dim
			_coords = [0 for i in range(0, _dim)]
		# If an invalid number of positional arguments has been provided, raise an exception
		else:
			coord_system_name = _coord_system
			supported_dims = ', '.join(['0'] + [str(x) for x in config.SUPPORTED_DIMENSIONS[_coord_system]])
			raise TypeError('Point() for %(coord_system_name)s points must take any of the following numbers of positional arguments: %(supported_dims)s.' % locals())
		
		classname = ''.join(['Point', _coord_system.title(), str(_dim), 'D'])
		PointType = wrapper.__getattribute__(classname)
		self._point = PointType(*_coords)