Example #1
0
 def __repr__(self):
     r = "Zero(%s, %s, %s)" % (
         repr(self.ufl_shape),
         repr(self.ufl_free_indices),
         repr(self.ufl_index_dimensions),
         )
     return as_native_str(r)
Example #2
0
 def __repr__(self):
     "Compute repr string of form. This can be huge for complicated forms."
     # Warning used for making sure we don't use this in the general pipeline:
     #warning("Calling repr on form is potentially expensive and should be avoided except during debugging.")
     # Not caching this because it can be huge
     itgs = ", ".join(repr(itg) for itg in self.integrals())
     r = "Form([" + itgs + "])"
     return as_native_str(r)
Example #3
0
    def __init__(self, *elements):
        self._elements = elements

        cell = elements[0].cell()
        if not all(e.cell() == cell for e in elements[1:]):
            error("Cell mismatch for sub elements of enriched element.")

        if isinstance(elements[0].degree(), int):
            degrees = {e.degree() for e in elements} - {None}
            degree = max(degrees) if degrees else None
        else:
            degree = tuple(map(max, zip(*[e.degree() for e in elements])))

        # We can allow the scheme not to be defined, but all defined
        # should be equal
        quad_schemes = [e.quadrature_scheme() for e in elements]
        quad_schemes = [qs for qs in quad_schemes if qs is not None]
        quad_scheme = quad_schemes[0] if quad_schemes else None
        if not all(qs == quad_scheme for qs in quad_schemes):
            error("Quadrature scheme mismatch.")

        value_shape = elements[0].value_shape()
        if not all(e.value_shape() == value_shape for e in elements[1:]):
            error("Element value shape mismatch.")

        reference_value_shape = elements[0].reference_value_shape()
        if not all(e.reference_value_shape() == reference_value_shape
                   for e in elements[1:]):
            error("Element reference value shape mismatch.")

        # mapping = elements[0].mapping() # FIXME: This fails for a mixed subelement here.
        # if not all(e.mapping() == mapping for e in elements[1:]):
        #    error("Element mapping mismatch.")

        # Get name of subclass: EnrichedElement or NodalEnrichedElement
        class_name = as_native_str(self.__class__.__name__)

        # Initialize element data
        FiniteElementBase.__init__(self, class_name, cell, degree, quad_scheme,
                                   value_shape, reference_value_shape)

        # Cache repr string
        self._repr = as_native_str(
            "%s(%s)" % (class_name, ", ".join(repr(e)
                                              for e in self._elements)))
Example #4
0
 def __repr__(self):
     r = "Integral(%s, %s, %s, %s, %s, %s)" % (
         repr(self._integrand),
         repr(self._integral_type),
         repr(self._ufl_domain),
         repr(self._subdomain_id),
         repr(self._metadata),
         repr(self._subdomain_data),
     )
     return as_native_str(r)
Example #5
0
 def __repr__(self):
     # For standard cells, return name of builtin cell object if
     # possible.  This reduces the size of the repr strings for
     # domains, elements, etc. as well
     gdim = self.geometric_dimension()
     tdim = self.topological_dimension()
     name = self.cellname()
     if gdim == tdim and name in cellname2dim:
         r = name
     else:
         r = "Cell(%s, %s)" % (repr(name), repr(gdim))
     return as_native_str(r)
Example #6
0
    def __init__(self, element):
        self._element = element
        self._repr = as_native_str("BrokenElement(%s)" % repr(element))

        family = "BrokenElement"
        cell = element.cell()
        degree = element.degree()
        quad_scheme = element.quadrature_scheme()
        value_shape = element.value_shape()
        reference_value_shape = element.reference_value_shape()
        FiniteElementBase.__init__(self, family, cell, degree, quad_scheme,
                                   value_shape, reference_value_shape)
Example #7
0
    def __init__(self, element):
        self._element = element
        self._repr = as_native_str("HDivElement(%s)" % repr(element))

        family = "TensorProductElement"
        cell = element.cell()
        degree = element.degree()
        quad_scheme = element.quadrature_scheme()
        value_shape = (element.cell().geometric_dimension(), )
        reference_value_shape = (element.cell().topological_dimension(), )

        # Skipping TensorProductElement constructor! Bad code smell, refactor to avoid this non-inheritance somehow.
        FiniteElementBase.__init__(self, family, cell, degree, quad_scheme,
                                   value_shape, reference_value_shape)
Example #8
0
def attach_ufl_id(cls):
    """Equip class with ``.ufl_id()`` and handle bookkeeping.

    Usage:

        1. Apply to class::

            @attach_ufl_id
            class MyClass(object):

        2. If ``__slots__`` is defined, include ``_ufl_id`` attribute::

            __slots__ = ("_ufl_id",)

        3. Add keyword argument to constructor::

            def __init__(self, *args, ufl_id=None):

        4. Call ``self._init_ufl_id`` with ``ufl_id`` and assign to ``._ufl_id``
           attribute::

            self._ufl_id = self._init_ufl_id(ufl_id)

    Result:

        ``MyClass().ufl_id()`` returns unique value for each constructed object.

    """

    def _get_ufl_id(self):
        "Return the ufl_id of this object."
        return self._ufl_id

    def _init_ufl_id(cls):
        "Initialize new ufl_id for the object under construction."
        # Bind cls with closure here
        def init_ufl_id(self, ufl_id):
            if ufl_id is None:
                ufl_id = cls._ufl_global_id
            cls._ufl_global_id = max(ufl_id, cls._ufl_global_id) + 1
            return ufl_id
        return init_ufl_id

    # Modify class:
    if hasattr(cls, "__slots__"):
        assert as_native_str("_ufl_id") in cls.__slots__
    cls._ufl_global_id = 0
    cls.ufl_id = _get_ufl_id
    cls._init_ufl_id = _init_ufl_id(cls)
    return cls
Example #9
0
    def __repr__(self):
        "Return a repr string for this Measure."
        global integral_type_to_measure_name

        args = []
        args.append(repr(self._integral_type))

        if self._subdomain_id is not None:
            args.append("subdomain_id=%s" % repr(self._subdomain_id))
        if self._domain is not None:
            args.append("domain=%s" % repr(self._domain))
        if self._metadata:  # Stored as EmptyDict if None
            args.append("metadata=%s" % repr(self._metadata))
        if self._subdomain_data is not None:
            args.append("subdomain_data=%s" % repr(self._subdomain_data))

        r = "%s(%s)" % (type(self).__name__, ', '.join(args))
        return as_native_str(r)
Example #10
0
    def __init__(self, function_space, count=None):
        FormArgument.__init__(self)
        counted_init(self, count, Coefficient)

        if isinstance(function_space, FiniteElementBase):
            # For legacy support for .ufl files using cells, we map
            # the cell to The Default Mesh
            element = function_space
            domain = default_domain(element.cell())
            function_space = FunctionSpace(domain, element)
        elif not isinstance(function_space, AbstractFunctionSpace):
            error("Expecting a FunctionSpace or FiniteElement.")

        self._ufl_function_space = function_space
        self._ufl_shape = function_space.ufl_element().value_shape()

        self._repr = as_native_str(
            "Coefficient(%s, %s)" %
            (repr(self._ufl_function_space), repr(self._count)))
Example #11
0
    def __init__(self, element, restriction_domain):
        if not isinstance(element, FiniteElementBase):
            error("Expecting a finite element instance.")
        if restriction_domain not in valid_restriction_domains:
            error("Expecting one of the strings %s." %
                  (valid_restriction_domains, ))

        FiniteElementBase.__init__(self, "RestrictedElement", element.cell(),
                                   element.degree(),
                                   element.quadrature_scheme(),
                                   element.value_shape(),
                                   element.reference_value_shape())

        self._element = element

        self._restriction_domain = restriction_domain

        self._repr = as_native_str(
            "RestrictedElement(%s, %s)" %
            (repr(self._element), repr(self._restriction_domain)))
Example #12
0
    def __init__(self, function_space, number, part=None):
        FormArgument.__init__(self)

        if isinstance(function_space, FiniteElementBase):
            # For legacy support for .ufl files using cells, we map the cell to
            # the default Mesh
            element = function_space
            domain = default_domain(element.cell())
            function_space = FunctionSpace(domain, element)
        elif not isinstance(function_space, AbstractFunctionSpace):
            error("Expecting a FunctionSpace or FiniteElement.")

        self._ufl_function_space = function_space
        self._ufl_shape = function_space.ufl_element().value_shape()

        if not isinstance(number, numbers.Integral):
            error("Expecting an int for number, not %s" % (number, ))
        if part is not None and not isinstance(part, numbers.Integral):
            error("Expecting None or an int for part, not %s" % (part, ))
        self._number = number
        self._part = part

        self._repr = as_native_str("Argument(%s, %s, %s)" % (repr(
            self._ufl_function_space), repr(self._number), repr(self._part)))
Example #13
0
 def __repr__(self):
     "Default repr string construction for operators."
     # This should work for most cases
     r = "%s(%s)" % (self._ufl_class_.__name__, ", ".join(
         repr(op) for op in self.ufl_operands))
     return as_native_str(r)
Example #14
0
 def __repr__(self):
     r = "%s(%s)" % (type(self).__name__, repr(self._value))
     return as_native_str(r)
Example #15
0
 def __repr__(self):
     r = "Label(%d)" % self._count
     return as_native_str(r)
Example #16
0
    def __init__(self,
                 family,
                 cell=None,
                 degree=None,
                 form_degree=None,
                 quad_scheme=None,
                 variant=None):
        """Create finite element.

        *Arguments*
            family (string)
               The finite element family
            cell
               The geometric cell
            degree (int)
               The polynomial degree (optional)
            form_degree (int)
               The form degree (FEEC notation, used when field is
               viewed as k-form)
            quad_scheme
               The quadrature scheme (optional)
            variant
               Hint for the local basis function variant (optional)
        """
        # Note: Unfortunately, dolfin sometimes passes None for
        # cell. Until this is fixed, allow it:
        if cell is not None:
            cell = as_cell(cell)

        family, short_name, degree, value_shape, reference_value_shape, sobolev_space, mapping = canonical_element_description(
            family, cell, degree, form_degree)

        # TODO: Move these to base? Might be better to instead
        # simplify base though.
        self._sobolev_space = sobolev_space
        self._mapping = mapping
        self._short_name = short_name
        self._variant = variant

        # Finite elements on quadrilaterals have an IrreducibleInt as degree
        if cell is not None:
            if cell.cellname() == "quadrilateral":
                from ufl.algorithms.estimate_degrees import IrreducibleInt
                degree = IrreducibleInt(degree)

        # Type check variant
        if variant is not None and not isinstance(variant, str):
            raise ValueError("Illegal variant: must be string or None")

        # Initialize element data
        FiniteElementBase.__init__(self, family, cell, degree, quad_scheme,
                                   value_shape, reference_value_shape)

        # Cache repr string
        qs = self.quadrature_scheme()
        if qs is None:
            quad_str = ""
        else:
            quad_str = ", quad_scheme=%s" % repr(qs)
        v = self.variant()
        if v is None:
            var_str = ""
        else:
            var_str = ", variant=%s" % repr(qs)
        self._repr = as_native_str("FiniteElement(%s, %s, %s%s%s)" %
                                   (repr(self.family()), repr(self.cell()),
                                    repr(self.degree()), quad_str, var_str))
        assert '"' not in self._repr
Example #17
0
 def __repr__(self):
     r = "ExprList(*%s)" % repr(self.ufl_operands)
     return as_native_str(r)
Example #18
0
 def __repr__(self):
     r = "TensorProductMesh(%s, %s)" % (repr(
         self._ufl_meshes), repr(self._ufl_id))
     return as_native_str(r)
Example #19
0
 def __repr__(self):
     r = "SobolevSpace(%s, %s)" % (repr(self.name), repr(list(
         self.parents)))
     return as_native_str(r)
Example #20
0
 def __repr__(self):
     r = "Identity(%d)" % self._dim
     return as_native_str(r)
Example #21
0
 def __repr__(self):
     r = "FunctionSpace(%s, %s)" % (repr(
         self._ufl_domain), repr(self._ufl_element))
     return as_native_str(r)
Example #22
0
 def __repr__(self):
     r = "TensorProductFunctionSpace(*%s)" % repr(self._ufl_function_spaces)
     return as_native_str(r)
Example #23
0
 def __repr__(self):
     r = "MixedFunctionSpace(*%s)" % repr(self._ufl_function_spaces)
     return as_native_str(r)
Example #24
0
 def __repr__(self):
     r = "%s(%s)" % (self._ufl_class_.__name__, repr(self._domain))
     return as_native_str(r)
Example #25
0
 def __repr__(self):
     tdim = self.topological_dimension()
     r = "MeshView(%s, %s, %s)" % (repr(
         self._ufl_mesh), repr(tdim), repr(self._ufl_id))
     return as_native_str(r)
Example #26
0
 def __repr__(self):
     r = "PermutationSymbol(%d)" % self._dim
     return as_native_str(r)
Example #27
0
 def __repr__(self):
     r = "Equation(%s, %s)" % (repr(self.lhs), repr(self.rhs))
     return as_native_str(r)
Example #28
0
 def __repr__(self):
     r = "Mesh(%s, %s)" % (repr(
         self._ufl_coordinate_element), repr(self._ufl_id))
     return as_native_str(r)