Source code for src.spaces.base
# -*- coding: utf-8 -*-
# noinspection PyUnresolvedReferences
r"""
Each space is an instance of a particular space class which inherits :class:`SpaceBase`.
.. autoclass:: src.spaces.base.SpaceBase
:members: mesh, manifold, m, n, make_form
"""
from tools.frozen import Frozen
from src.config import get_embedding_space_dim
from src.form.main import Form
from src.spaces.finite import SpaceFiniteSetting
from tools.miscellaneous.random_ import string_digits
from time import time
[docs]
class SpaceBase(Frozen):
""""""
def __init__(self, mesh, orientation):
""""""
self._objective = None
# when initializing, it has no objective instance. And when we generate an objective of a
# abstract space, we store the last objective one with this attribute.
self._mesh = mesh
assert orientation in ('inner', 'outer', 'i', 'o', None, 'None'), \
f"orientation={orientation} is wrong, must be one of ('inner', 'outer', 'i', 'o', None)."
if orientation == 'i':
orientation = 'inner'
elif orientation == 'o':
orientation = 'outer'
elif orientation in (None, 'unknown', 'None'):
orientation = 'unknown'
else:
pass
self._orientation = orientation
self._finite = None # the finite setting
@property
def _pure_lin_repr(self):
""""""
raise NotImplementedError()
@property
def mesh(self):
"""The mesh I am built on."""
return self._mesh
@property
def manifold(self):
"""The manifold I am built on."""
return self.mesh.manifold
@property
def orientation(self):
"""My orientation."""
return self._orientation
@property
def opposite_orientation(self):
if self.orientation == 'inner':
return 'outer'
elif self.orientation == 'outer':
return 'inner'
elif self.orientation == 'unknown':
return 'unknown'
@property
def n(self):
"""the dimensions of the mesh I am living in."""
return self.mesh.ndim
@property
def m(self):
"""the dimensions of the space I am living in."""
return get_embedding_space_dim()
def make_random_form(self):
"""Usually used as intermediate forms."""
sym = string_digits(8)
t = time()
random_sym_repr = sym+str(t)[-5:]
random_lin_repr = str(hash(random_sym_repr))
return self.make_form(random_sym_repr, random_lin_repr)
def __eq__(self, other):
""""""
return self.__repr__() == other.__repr__()
@staticmethod
def _is_space():
"""A private signature/tag."""
return True
@property
def finite(self):
if self._finite is None:
self._finite = SpaceFiniteSetting(self)
return self._finite
def d(self):
"""d (self)"""
from src.spaces.operators import d
return d(self)