Ejemplo n.º 1
0
def TensorConstant(domain, shape=None, symmetry=None, count=None):
    """UFL value: Represents a globally constant tensor valued coefficient."""
    domain = as_domain(domain)
    element = TensorElement("Real", domain.ufl_cell(), 0, shape=shape,
                            symmetry=symmetry)
    fs = FunctionSpace(domain, element)
    return Coefficient(fs, count=count)
Ejemplo n.º 2
0
    def __init__(
            self,
            integral_type,  # "dx" etc
            domain=None,
            subdomain_id="everywhere",
            metadata=None,
            subdomain_data=None):
        """
        integral_type:
            str, one of "cell", etc.,
            or short form "dx", etc.

        domain:
            an AbstractDomain object (most often a Mesh)

        subdomain_id:
            either string "everywhere",
            a single subdomain id int,
            or tuple of ints

        metadata:
            dict, with additional compiler-specific parameters
            affecting how code is generated, including parameters
            for optimization or debugging of generated code.

        subdomain_data:
            object representing data to interpret subdomain_id with.
        """
        # Map short name to long name and require a valid one
        self._integral_type = as_integral_type(integral_type)

        # Check that we either have a proper AbstractDomain or none
        self._domain = None if domain is None else as_domain(domain)
        if not (self._domain is None
                or isinstance(self._domain, AbstractDomain)):
            error("Invalid domain.")

        # Store subdomain data
        self._subdomain_data = subdomain_data
        # FIXME: Cannot require this (yet) because we currently have
        # no way to implement ufl_id for dolfin SubDomain
        # if not (self._subdomain_data is None or hasattr(self._subdomain_data, "ufl_id")):
        #     error("Invalid domain data, missing ufl_id() implementation.")

        # Accept "everywhere", single subdomain, or multiple
        # subdomains
        if isinstance(subdomain_id, tuple):
            for did in subdomain_id:
                if not isinstance(did, numbers.Integral):
                    error("Invalid subdomain_id %s." % (did, ))
        else:
            if not (subdomain_id in ("everywhere", )
                    or isinstance(subdomain_id, numbers.Integral)):
                error("Invalid subdomain_id %s." % (subdomain_id, ))
        self._subdomain_id = subdomain_id

        # Validate compiler options are None or dict
        if metadata is not None and not isinstance(metadata, dict):
            error("Invalid metadata.")
        self._metadata = metadata or EmptyDict
Ejemplo n.º 3
0
    def __init__(self,
                 integral_type,  # "dx" etc
                 domain=None,
                 subdomain_id="everywhere",
                 metadata=None,
                 subdomain_data=None):
        """
        integral_type:
            str, one of "cell", etc.,
            or short form "dx", etc.

        domain:
            an AbstractDomain object (most often a Mesh)

        subdomain_id:
            either string "everywhere",
            a single subdomain id int,
            or tuple of ints

        metadata:
            dict, with additional compiler-specific parameters
            affecting how code is generated, including parameters
            for optimization or debugging of generated code.

        subdomain_data:
            object representing data to interpret subdomain_id with.
        """
        # Map short name to long name and require a valid one
        self._integral_type = as_integral_type(integral_type)

        # Check that we either have a proper AbstractDomain or none
        self._domain = None if domain is None else as_domain(domain)
        if not (self._domain is None or isinstance(self._domain, AbstractDomain)):
            error("Invalid domain.")

        # Store subdomain data
        self._subdomain_data = subdomain_data
        # FIXME: Cannot require this (yet) because we currently have
        # no way to implement ufl_id for dolfin SubDomain
        # if not (self._subdomain_data is None or hasattr(self._subdomain_data, "ufl_id")):
        #     error("Invalid domain data, missing ufl_id() implementation.")

        # Accept "everywhere", single subdomain, or multiple
        # subdomains
        if isinstance(subdomain_id, tuple):
            for did in subdomain_id:
                if not isinstance(did, numbers.Integral):
                    error("Invalid subdomain_id %s." % (did,))
        else:
            if not (subdomain_id in ("everywhere",) or isinstance(subdomain_id, numbers.Integral)):
                error("Invalid subdomain_id %s." % (subdomain_id,))
        self._subdomain_id = subdomain_id

        # Validate compiler options are None or dict
        if metadata is not None and not isinstance(metadata, dict):
            error("Invalid metadata.")
        self._metadata = metadata or EmptyDict
Ejemplo n.º 4
0
def test_cell_legacy_case():
    # Passing cell like old code does
    D = as_domain(triangle)

    V = FiniteElement("CG", triangle, 1)
    f = Coefficient(V)
    assert f.ufl_domains() == (D, )

    M = f * dx
    assert M.ufl_domains() == (D, )
Ejemplo n.º 5
0
def test_cell_legacy_case():
    # Passing cell like old code does
    D = as_domain(triangle)

    V = FiniteElement("CG", triangle, 1)
    f = Coefficient(V)
    assert f.ufl_domains() == (D, )

    M = f * dx
    assert M.ufl_domains() == (D, )
Ejemplo n.º 6
0
def TensorConstant(domain, shape=None, symmetry=None, count=None):
    """UFL value: Represents a globally constant tensor valued coefficient."""
    domain = as_domain(domain)
    element = TensorElement("Real",
                            domain.ufl_cell(),
                            0,
                            shape=shape,
                            symmetry=symmetry)
    fs = FunctionSpace(domain, element)
    return Coefficient(fs, count=count)
Ejemplo n.º 7
0
    def __init__(self, domain, shape=(), count=None):
        Terminal.__init__(self)
        counted_init(self, count=count, countedclass=Constant)

        self._ufl_domain = as_domain(domain)
        self._ufl_shape = shape

        # Repr string is build in such way, that reconstruction
        # with eval() is possible
        self._repr = "Constant({}, {}, {})".format(repr(self._ufl_domain),
                                                   repr(self._ufl_shape),
                                                   repr(self._count))
Ejemplo n.º 8
0
    def __call__(self,
                 subdomain_id=None,
                 metadata=None,
                 domain=None,
                 subdomain_data=None,
                 degree=None,
                 scheme=None,
                 rule=None):
        """Reconfigure measure with new domain specification or metadata."""

        # Deprecation of 'rule' in favour of 'scheme'
        if rule is not None:
            deprecate("Measure argument 'rule' has been renamed to 'scheme'.")
            assert scheme is None or scheme == rule
            scheme = rule

        # Let syntax dx() mean integral over everywhere
        all_args = (subdomain_id, metadata, domain, subdomain_data, degree,
                    scheme)
        if all(arg is None for arg in all_args):
            return self.reconstruct(subdomain_id="everywhere")

        # Let syntax dx(domain) or dx(domain, metadata) mean integral
        # over entire domain.  To do this we need to hijack the first
        # argument:
        if subdomain_id is not None and (
                isinstance(subdomain_id, AbstractDomain)
                or hasattr(subdomain_id, 'ufl_domain')):
            if domain is not None:
                error(
                    "Ambiguous: setting domain both as keyword argument and first argument."
                )
            subdomain_id, domain = "everywhere", as_domain(subdomain_id)

        # If degree or scheme is set, inject into metadata. This is a
        # quick fix to enable the dx(..., degree=3) notation.
        # TODO: Make degree and scheme properties of integrals instead of adding to metadata.
        if (degree, scheme) != (None, None):
            metadata = {} if metadata is None else metadata.copy()
            if degree is not None:
                metadata["quadrature_degree"] = degree
            if scheme is not None:
                metadata["quadrature_rule"] = scheme

        # If we get any keywords, use them to reconstruct Measure.
        # Note that if only one argument is given, it is the
        # subdomain_id, e.g. dx(3) == dx(subdomain_id=3)
        return self.reconstruct(subdomain_id=subdomain_id,
                                domain=domain,
                                metadata=metadata,
                                subdomain_data=subdomain_data)
Ejemplo n.º 9
0
def test_construct_domains_from_cells():
    for cell in all_cells:
        D0 = Mesh(cell)
        D1 = default_domain(cell)
        D2 = as_domain(cell)
        assert D0 is not D1
        assert D0 is not D2
        assert D1 is D2
        if 0:
            print()
            for D in (D1, D2):
                print(('id', id(D)))
                print(('str', str(D)))
                print(('repr', repr(D)))
                print()
        assert D0 != D1
        assert D0 != D2
        assert D1 == D2
Ejemplo n.º 10
0
def test_construct_domains_from_cells():
    for cell in all_cells:
        D0 = Mesh(cell)
        D1 = default_domain(cell)
        D2 = as_domain(cell)
        assert D0 is not D1
        assert D0 is not D2
        assert D1 is D2
        if 0:
            print()
            for D in (D1, D2):
                print(('id', id(D)))
                print(('str', str(D)))
                print(('repr', repr(D)))
                print()
        assert D0 != D1
        assert D0 != D2
        assert D1 == D2
Ejemplo n.º 11
0
    def __call__(self, subdomain_id=None, metadata=None, domain=None,
                 subdomain_data=None, degree=None, scheme=None, rule=None):
        """Reconfigure measure with new domain specification or metadata."""

        # Deprecation of 'rule' in favour of 'scheme'
        if rule is not None:
            deprecate("Measure argument 'rule' has been renamed to 'scheme'.")
            assert scheme is None or scheme == rule
            scheme = rule

        # Let syntax dx() mean integral over everywhere
        all_args = (subdomain_id, metadata, domain, subdomain_data,
                    degree, scheme)
        if all(arg is None for arg in all_args):
            return self.reconstruct(subdomain_id="everywhere")

        # Let syntax dx(domain) or dx(domain, metadata) mean integral
        # over entire domain.  To do this we need to hijack the first
        # argument:
        if subdomain_id is not None and (isinstance(subdomain_id,
                                                    AbstractDomain) or
                                         hasattr(subdomain_id, 'ufl_domain')):
            if domain is not None:
                error("Ambiguous: setting domain both as keyword argument and first argument.")
            subdomain_id, domain = "everywhere", as_domain(subdomain_id)

        # If degree or scheme is set, inject into metadata. This is a
        # quick fix to enable the dx(..., degree=3) notation.
        # TODO: Make degree and scheme properties of integrals instead of adding to metadata.
        if (degree, scheme) != (None, None):
            metadata = {} if metadata is None else metadata.copy()
            if degree is not None:
                metadata["quadrature_degree"] = degree
            if scheme is not None:
                metadata["quadrature_rule"] = scheme

        # If we get any keywords, use them to reconstruct Measure.
        # Note that if only one argument is given, it is the
        # subdomain_id, e.g. dx(3) == dx(subdomain_id=3)
        return self.reconstruct(subdomain_id=subdomain_id, domain=domain,
                                metadata=metadata,
                                subdomain_data=subdomain_data)
Ejemplo n.º 12
0
 def __init__(self, domain):
     Terminal.__init__(self)
     self._domain = as_domain(domain)
Ejemplo n.º 13
0
 def __init__(self, domain):
     Terminal.__init__(self)
     self._domain = as_domain(domain)
Ejemplo n.º 14
0
def test_as_domain_from_cell_is_equal():
    for cell in all_cells:
        D1 = as_domain(cell)
        D2 = as_domain(cell)
        assert D1 == D2
Ejemplo n.º 15
0
def VectorConstant(domain, dim=None, count=None):
    """UFL value: Represents a globally constant vector valued coefficient."""
    domain = as_domain(domain)
    element = VectorElement("Real", domain.ufl_cell(), 0, dim)
    fs = FunctionSpace(domain, element)
    return Coefficient(fs, count=count)
Ejemplo n.º 16
0
def Constant(domain, count=None):
    """UFL value: Represents a globally constant scalar valued coefficient."""
    domain = as_domain(domain)
    element = FiniteElement("Real", domain.ufl_cell(), 0)
    fs = FunctionSpace(domain, element)
    return Coefficient(fs, count=count)
Ejemplo n.º 17
0
def TensorConstant(domain, count=None):
    domain = as_domain(domain)
    return Constant(domain,
                    shape=(domain.geometric_dimension(),
                           domain.geometric_dimension()),
                    count=count)
Ejemplo n.º 18
0
def VectorConstant(domain, dim=None, count=None):
    """UFL value: Represents a globally constant vector valued coefficient."""
    domain = as_domain(domain)
    element = VectorElement("Real", domain.ufl_cell(), 0, dim)
    fs = FunctionSpace(domain, element)
    return Coefficient(fs, count=count)
Ejemplo n.º 19
0
def Constant(domain, count=None):
    """UFL value: Represents a globally constant scalar valued coefficient."""
    domain = as_domain(domain)
    element = FiniteElement("Real", domain.ufl_cell(), 0)
    fs = FunctionSpace(domain, element)
    return Coefficient(fs, count=count)
Ejemplo n.º 20
0
def test_as_domain_from_cell_is_equal():
    for cell in all_cells:
        D1 = as_domain(cell)
        D2 = as_domain(cell)
        assert D1 == D2