def __init__(self, cellname, geometric_dimension=None):
        "Initialize basic cell description."
        # The cellname must be one of the predefined names
        ufl_assert(cellname in cellname2dim,
                   "Invalid cellname %s." % (cellname, ))
        self._cellname = cellname

        # The topological dimension is defined by the cell type
        self._topological_dimension = cellname2dim[self._cellname]

        # The geometric dimension defaults to equal
        # the topological dimension if undefined
        ufl_assert(
            geometric_dimension is None
            or isinstance(geometric_dimension, int),
            "Expecting an integer dimension, not '%r'" %
            (geometric_dimension, ))
        self._geometric_dimension = geometric_dimension or self._topological_dimension

        # Check for consistency in dimensions.
        # NB! Note that the distinction between topological
        # and geometric dimensions has yet to be used in
        # practice, so don't trust it too much :)
        ufl_assert(self._topological_dimension <= self._geometric_dimension,
                   "Cannot embed a %sD cell in %sD" %\
                       (istr(self._topological_dimension), istr(self._geometric_dimension)))

        # Cache repr string
        self._repr = "Cell(%r, %r)" % (self._cellname,
                                       self._geometric_dimension)

        # Attach expression nodes derived from this cell TODO: Derive these from domain instead
        self._n = FacetNormal(self)
        self._x = SpatialCoordinate(self)

        self._xi = LocalCoordinate(self)
        self._J = GeometryJacobi(self)
        self._Jinv = InverseGeometryJacobi(self)
        self._detJ = GeometryJacobiDeterminant(self)

        self._volume = CellVolume(self)
        self._circumradius = Circumradius(self)
        self._cellsurfacearea = CellSurfaceArea(self)
        self._facetarea = FacetArea(self)
        self._minfacetedgelength = MinFacetEdgeLength(self)
        self._maxfacetedgelength = MaxFacetEdgeLength(self)
        self._facetdiameter = FacetDiameter(self)
Example #2
0
 def __str__(self):
     "Format as string for pretty printing."
     sym = ""
     if isinstance(self._symmetry, dict):
         tmp = ", ".join("%s -> %s" % (a,b) for (a,b) in self._symmetry.iteritems())
         sym = " with symmetries (%s)" % tmp
     elif self._symmetry:
         sym = " with symmetry"
     return "<%s tensor element of degree %s and shape %s on a %s%s>" % \
         (self.family(), istr(self.degree()), self.value_shape(), self.domain(), sym)
    def __init__(self, cellname, geometric_dimension=None):
        "Initialize basic cell description."
        # The cellname must be one of the predefined names
        ufl_assert(cellname in cellname2dim, "Invalid cellname %s." % (cellname,))
        self._cellname = cellname

        # The topological dimension is defined by the cell type
        self._topological_dimension = cellname2dim[self._cellname]

        # The geometric dimension defaults to equal
        # the topological dimension if undefined
        ufl_assert(geometric_dimension is None or isinstance(geometric_dimension, int),
                   "Expecting an integer dimension, not '%r'" % (geometric_dimension,))
        self._geometric_dimension = geometric_dimension or self._topological_dimension

        # Check for consistency in dimensions.
        # NB! Note that the distinction between topological
        # and geometric dimensions has yet to be used in
        # practice, so don't trust it too much :)
        ufl_assert(self._topological_dimension <= self._geometric_dimension,
                   "Cannot embed a %sD cell in %sD" %\
                       (istr(self._topological_dimension), istr(self._geometric_dimension)))

        # Cache repr string
        self._repr = "Cell(%r, %r)" % (self._cellname, self._geometric_dimension)

        # Attach expression nodes derived from this cell TODO: Derive these from domain instead
        self._n = FacetNormal(self)
        self._x = SpatialCoordinate(self)

        self._xi = LocalCoordinate(self)
        self._J = GeometryJacobi(self)
        self._Jinv = InverseGeometryJacobi(self)
        self._detJ = GeometryJacobiDeterminant(self)

        self._volume = CellVolume(self)
        self._circumradius = Circumradius(self)
        self._cellsurfacearea = CellSurfaceArea(self)
        self._facetarea = FacetArea(self)
        self._minfacetedgelength = MinFacetEdgeLength(self)
        self._maxfacetedgelength = MaxFacetEdgeLength(self)
        self._facetdiameter = FacetDiameter(self)
 def __str__(self):
     return "<%s cell in %sD>" % (istr(self._cellname),
                                  istr(self._geometric_dimension))
 def __str__(self):
     return "<%s cell in %sD>" % (istr(
         self._cellname), istr(self._geometric_dimension))
    def __init__(self,
                 family,
                 domain=None,
                 degree=None,
                 quad_scheme=None,
                 form_degree=None):
        """Create finite element

        *Arguments*
            family (string)
               The finite element family
            domain
               The geometric domain
            degree (int)
               The polynomial degree (optional)
            quad_scheme
               The quadrature scheme (optional)
            form_degree (int)
               The form degree (FEEC notation, used when field is
               viewed as k-form)
        """
        if domain is None:
            cell = None
        else:
            domain = as_domain(domain)
            cell = domain.cell()
            ufl_assert(cell is not None, "Missing cell in given domain.")

        # Check whether this family is an alias for something else
        if family in aliases:
            (name, cell, r) = aliases[family](family, cell, degree,
                                              form_degree)
            #info_blue("%s, is an alias for %s " % (
            #        (family, cell, degree, form_degree),
            #        (name, cell, r)))

            # FIXME: Need to init here with domain instead of using cell from aliases, is that ok?
            ufl_assert(cell == domain.cell(),
                       "Breaking assumption in element alias mapping.")
            self.__init__(name, domain, r, quad_scheme)
            return

        # Check that the element family exists
        ufl_assert(family in ufl_elements,
                   'Unknown finite element "%s".' % family)

        # Check that element data is valid (and also get common family name)
        (family, self._short_name, value_rank, krange, cellnames) =\
            ufl_elements[family]

        # Validate cellname if a valid cell is specified
        cellname = None if cell is None else cell.cellname()
        ufl_assert(
            cellname in cellnames,
            'Cellname "%s" invalid for "%s" finite element.' %
            (cellname, family))

        # Validate degree if specified
        if degree is not None:
            ufl_assert(krange is not None,
                       'Degree "%s" invalid for "%s" finite element, '\
                           'should be None.' % (degree, family))
            kmin, kmax = krange
            ufl_assert(kmin is None or degree >= kmin,
                       'Degree "%s" invalid for "%s" finite element.' %\
                           (degree, family))
            ufl_assert(kmax is None or degree <= kmax,
                   'Degree "%s" invalid for "%s" finite element.' %\
                           (istr(degree), family))

        # Set value dimension (default to using geometric dimension in each axis)
        if value_rank == 0:
            value_shape = ()
        else:
            ufl_assert(
                domain is not None,
                "Cannot infer shape of element without a domain with geometric dimension."
            )
            dim = domain.geometric_dimension()
            value_shape = (dim, ) * value_rank

        # Initialize element data
        super(FiniteElement, self).__init__(family, domain, degree,
                                            quad_scheme, value_shape)

        # Cache repr string
        self._repr = "FiniteElement(%r, %r, %r, %r)" % (
            self.family(), self.domain(), self.degree(),
            self.quadrature_scheme())
 def shortstr(self):
     "Format as string for pretty printing."
     return "%s%s(%s)" % (self._short_name, istr(
         self.degree()), istr(self.quadrature_scheme()))
 def __str__(self):
     "Format as string for pretty printing."
     qs = self.quadrature_scheme()
     qs = "" if qs is None else "(%s)" % qs
     return "<%s%s%s on a %s>" % (self._short_name, istr(self.degree()),\
                                        qs, self.domain())
Example #9
0
 def __str__(self):
     "Format as string for pretty printing."
     return "<%s vector element of degree %s on a %s: %d x %s>" % \
            (self.family(), istr(self.degree()), self.domain(),
             len(self._sub_elements), self._sub_element)
    def __init__(self, family, domain=None, degree=None, quad_scheme=None,
                 form_degree=None):
        """Create finite element

        *Arguments*
            family (string)
               The finite element family
            domain
               The geometric domain
            degree (int)
               The polynomial degree (optional)
            quad_scheme
               The quadrature scheme (optional)
            form_degree (int)
               The form degree (FEEC notation, used when field is
               viewed as k-form)
        """
        if domain is None:
            cell = None
        else:
            domain = as_domain(domain)
            cell = domain.cell()
            ufl_assert(cell is not None, "Missing cell in given domain.")

        # Check whether this family is an alias for something else
        if family in aliases:
            (name, cell, r) = aliases[family](family, cell, degree, form_degree)
            #info_blue("%s, is an alias for %s " % (
            #        (family, cell, degree, form_degree),
            #        (name, cell, r)))

            # FIXME: Need to init here with domain instead of using cell from aliases, is that ok?
            ufl_assert(cell == domain.cell(),
                       "Breaking assumption in element alias mapping.")
            self.__init__(name, domain, r, quad_scheme)
            return

        # Check that the element family exists
        ufl_assert(family in ufl_elements,
                   'Unknown finite element "%s".' % family)

        # Check that element data is valid (and also get common family name)
        (family, self._short_name, value_rank, krange, cellnames) =\
            ufl_elements[family]

        # Validate cellname if a valid cell is specified
        cellname = None if cell is None else cell.cellname()
        ufl_assert(cellname in cellnames,
                   'Cellname "%s" invalid for "%s" finite element.' % (cellname, family))

        # Validate degree if specified
        if degree is not None:
            ufl_assert(krange is not None,
                       'Degree "%s" invalid for "%s" finite element, '\
                           'should be None.' % (degree, family))
            kmin, kmax = krange
            ufl_assert(kmin is None or degree >= kmin,
                       'Degree "%s" invalid for "%s" finite element.' %\
                           (degree, family))
            ufl_assert(kmax is None or degree <= kmax,
                   'Degree "%s" invalid for "%s" finite element.' %\
                           (istr(degree), family))

        # Set value dimension (default to using geometric dimension in each axis)
        if value_rank == 0:
            value_shape = ()
        else:
            ufl_assert(domain is not None,
                       "Cannot infer shape of element without a domain with geometric dimension.")
            dim = domain.geometric_dimension()
            value_shape = (dim,)*value_rank

        # Initialize element data
        super(FiniteElement, self).__init__(family, domain, degree,
                                            quad_scheme, value_shape)

        # Cache repr string
        self._repr = "FiniteElement(%r, %r, %r, %r)" % (
            self.family(), self.domain(), self.degree(), self.quadrature_scheme())
 def shortstr(self):
     "Format as string for pretty printing."
     return "%s%s(%s)" % (self._short_name, istr(self.degree()),
                          istr(self.quadrature_scheme()))
 def __str__(self):
     "Format as string for pretty printing."
     qs = self.quadrature_scheme()
     qs = "" if qs is None else "(%s)" % qs
     return "<%s%s%s on a %s>" % (self._short_name, istr(self.degree()),\
                                        qs, self.domain())