def assemble(f, tensor=None, bcs=None, form_compiler_parameters=None, inverse=False, nest=None): """Evaluate f. :arg f: a :class:`ufl.Form` or :class:`ufl.core.expr.Expr`. :arg tensor: an existing tensor object to place the result in (optional). :arg bcs: a list of boundary conditions to apply (optional). :arg form_compiler_parameters: (optional) dict of parameters to pass to the form compiler. Ignored if not assembling a :class:`ufl.Form`. Any parameters provided here will be overridden by parameters set on the :class;`ufl.Measure` in the form. For example, if a :data:`quadrature_degree` of 4 is specified in this argument, but a degree of 3 is requested in the measure, the latter will be used. :arg inverse: (optional) if f is a 2-form, then assemble the inverse of the local matrices. :arg nest: (optional) flag indicating if a 2-form (matrix) on a mixed space should be assembled as a block matrix (if :data:`nest` is :data:`True`) or not. The default value is taken from the parameters dict :data:`parameters["matnest"]`. If f is a :class:`ufl.Form` then this evaluates the corresponding integral(s) and returns a :class:`float` for 0-forms, a :class:`.Function` for 1-forms and a :class:`.Matrix` for 2-forms. If f is an expression other than a form, it will be evaluated pointwise on the :class:`.Function`\s in the expression. This will only succeed if all the Functions are on the same :class:`.FunctionSpace` If ``tensor`` is supplied, the assembled result will be placed there, otherwise a new object of the appropriate type will be returned. If ``bcs`` is supplied and ``f`` is a 2-form, the rows and columns of the resulting :class:`.Matrix` corresponding to boundary nodes will be set to 0 and the diagonal entries to 1. If ``f`` is a 1-form, the vector entries at boundary nodes are set to the boundary condition values. """ if isinstance(f, ufl.form.Form): return _assemble(f, tensor=tensor, bcs=solving._extract_bcs(bcs), form_compiler_parameters=form_compiler_parameters, inverse=inverse, nest=nest) elif isinstance(f, ufl.core.expr.Expr): return assemble_expressions.assemble_expression(f) else: raise TypeError("Unable to assemble: %r" % f)
def assemble(f, tensor=None, bcs=None, form_compiler_parameters=None, inverse=False, nest=None): """Evaluate f. :arg f: a :class:`~ufl.classes.Form` or :class:`~ufl.classes.Expr`. :arg tensor: an existing tensor object to place the result in (optional). :arg bcs: a list of boundary conditions to apply (optional). :arg form_compiler_parameters: (optional) dict of parameters to pass to the form compiler. Ignored if not assembling a :class:`~ufl.classes.Form`. Any parameters provided here will be overridden by parameters set on the :class:`~ufl.classes.Measure` in the form. For example, if a ``quadrature_degree`` of 4 is specified in this argument, but a degree of 3 is requested in the measure, the latter will be used. :arg inverse: (optional) if f is a 2-form, then assemble the inverse of the local matrices. :arg nest: (optional) flag indicating if a 2-form (matrix) on a mixed space should be assembled as a block matrix (if ``nest`` is ``True``) or not. The default value is taken from the parameters dict, ``parameters["matnest"]``. If f is a :class:`~ufl.classes.Form` then this evaluates the corresponding integral(s) and returns a :class:`float` for 0-forms, a :class:`.Function` for 1-forms and a :class:`.Matrix` for 2-forms. If f is an expression other than a form, it will be evaluated pointwise on the :class:`.Function`\s in the expression. This will only succeed if all the Functions are on the same :class:`.FunctionSpace`. If ``tensor`` is supplied, the assembled result will be placed there, otherwise a new object of the appropriate type will be returned. If ``bcs`` is supplied and ``f`` is a 2-form, the rows and columns of the resulting :class:`.Matrix` corresponding to boundary nodes will be set to 0 and the diagonal entries to 1. If ``f`` is a 1-form, the vector entries at boundary nodes are set to the boundary condition values. """ if isinstance(f, ufl.form.Form): return _assemble(f, tensor=tensor, bcs=solving._extract_bcs(bcs), form_compiler_parameters=form_compiler_parameters, inverse=inverse, nest=nest) elif isinstance(f, ufl.core.expr.Expr): return assemble_expressions.assemble_expression(f) else: raise TypeError("Unable to assemble: %r" % f)
def assemble(f, tensor=None, bcs=None, form_compiler_parameters=None, inverse=False, mat_type=None, sub_mat_type=None, appctx={}, options_prefix=None, **kwargs): """Evaluate f. :arg f: a :class:`~ufl.classes.Form`, :class:`~ufl.classes.Expr` or a :class:`~slate.TensorBase` expression. :arg tensor: an existing tensor object to place the result in (optional). :arg bcs: a list of boundary conditions to apply (optional). :arg form_compiler_parameters: (optional) dict of parameters to pass to the form compiler. Ignored if not assembling a :class:`~ufl.classes.Form`. Any parameters provided here will be overridden by parameters set on the :class:`~ufl.classes.Measure` in the form. For example, if a ``quadrature_degree`` of 4 is specified in this argument, but a degree of 3 is requested in the measure, the latter will be used. :arg inverse: (optional) if f is a 2-form, then assemble the inverse of the local matrices. :arg mat_type: (optional) string indicating how a 2-form (matrix) should be assembled -- either as a monolithic matrix ('aij' or 'baij'), a block matrix ('nest'), or left as a :class:`.ImplicitMatrix` giving matrix-free actions ('matfree'). If not supplied, the default value in ``parameters["default_matrix_type"]`` is used. BAIJ differs from AIJ in that only the block sparsity rather than the dof sparsity is constructed. This can result in some memory savings, but does not work with all PETSc preconditioners. BAIJ matrices only make sense for non-mixed matrices. :arg sub_mat_type: (optional) string indicating the matrix type to use *inside* a nested block matrix. Only makes sense if ``mat_type`` is ``nest``. May be one of 'aij' or 'baij'. If not supplied, defaults to ``parameters["default_sub_matrix_type"]``. :arg appctx: Additional information to hang on the assembled matrix if an implicit matrix is requested (mat_type "matfree"). :arg options_prefix: PETSc options prefix to apply to matrices. If f is a :class:`~ufl.classes.Form` then this evaluates the corresponding integral(s) and returns a :class:`float` for 0-forms, a :class:`.Function` for 1-forms and a :class:`.Matrix` or :class:`.ImplicitMatrix` for 2-forms. If f is an expression other than a form, it will be evaluated pointwise on the :class:`.Function`\s in the expression. This will only succeed if all the Functions are on the same :class:`.FunctionSpace`. If f is a Slate tensor expression, then it will be compiled using Slate's linear algebra compiler. If ``tensor`` is supplied, the assembled result will be placed there, otherwise a new object of the appropriate type will be returned. If ``bcs`` is supplied and ``f`` is a 2-form, the rows and columns of the resulting :class:`.Matrix` corresponding to boundary nodes will be set to 0 and the diagonal entries to 1. If ``f`` is a 1-form, the vector entries at boundary nodes are set to the boundary condition values. """ if "nest" in kwargs: nest = kwargs.pop("nest") from firedrake.logging import warning, RED warning( RED % "The 'nest' argument is deprecated, please set 'mat_type' instead") if nest is not None: mat_type = "nest" if nest else "aij" collect_loops = kwargs.pop("collect_loops", False) allocate_only = kwargs.pop("allocate_only", False) if len(kwargs) > 0: raise TypeError("Unknown keyword arguments '%s'" % ', '.join(kwargs.keys())) if isinstance(f, (ufl.form.Form, slate.TensorBase)): return _assemble(f, tensor=tensor, bcs=solving._extract_bcs(bcs), form_compiler_parameters=form_compiler_parameters, inverse=inverse, mat_type=mat_type, sub_mat_type=sub_mat_type, appctx=appctx, collect_loops=collect_loops, allocate_only=allocate_only, options_prefix=options_prefix) elif isinstance(f, ufl.core.expr.Expr): return assemble_expressions.assemble_expression(f) else: raise TypeError("Unable to assemble: %r" % f)
def assemble(f, tensor=None, bcs=None, form_compiler_parameters=None, inverse=False, mat_type=None, sub_mat_type=None, appctx={}, options_prefix=None, **kwargs): r"""Evaluate f. :arg f: a :class:`~ufl.classes.Form`, :class:`~ufl.classes.Expr` or a :class:`~slate.TensorBase` expression. :arg tensor: an existing tensor object to place the result in (optional). :arg bcs: a list of boundary conditions to apply (optional). :arg form_compiler_parameters: (optional) dict of parameters to pass to the form compiler. Ignored if not assembling a :class:`~ufl.classes.Form`. Any parameters provided here will be overridden by parameters set on the :class:`~ufl.classes.Measure` in the form. For example, if a ``quadrature_degree`` of 4 is specified in this argument, but a degree of 3 is requested in the measure, the latter will be used. :arg inverse: (optional) if f is a 2-form, then assemble the inverse of the local matrices. :arg mat_type: (optional) string indicating how a 2-form (matrix) should be assembled -- either as a monolithic matrix ('aij' or 'baij'), a block matrix ('nest'), or left as a :class:`.ImplicitMatrix` giving matrix-free actions ('matfree'). If not supplied, the default value in ``parameters["default_matrix_type"]`` is used. BAIJ differs from AIJ in that only the block sparsity rather than the dof sparsity is constructed. This can result in some memory savings, but does not work with all PETSc preconditioners. BAIJ matrices only make sense for non-mixed matrices. :arg sub_mat_type: (optional) string indicating the matrix type to use *inside* a nested block matrix. Only makes sense if ``mat_type`` is ``nest``. May be one of 'aij' or 'baij'. If not supplied, defaults to ``parameters["default_sub_matrix_type"]``. :arg appctx: Additional information to hang on the assembled matrix if an implicit matrix is requested (mat_type "matfree"). :arg options_prefix: PETSc options prefix to apply to matrices. If f is a :class:`~ufl.classes.Form` then this evaluates the corresponding integral(s) and returns a :class:`float` for 0-forms, a :class:`.Function` for 1-forms and a :class:`.Matrix` or :class:`.ImplicitMatrix` for 2-forms. If f is an expression other than a form, it will be evaluated pointwise on the :class:`.Function`\s in the expression. This will only succeed if all the Functions are on the same :class:`.FunctionSpace`. If f is a Slate tensor expression, then it will be compiled using Slate's linear algebra compiler. If ``tensor`` is supplied, the assembled result will be placed there, otherwise a new object of the appropriate type will be returned. If ``bcs`` is supplied and ``f`` is a 2-form, the rows and columns of the resulting :class:`.Matrix` corresponding to boundary nodes will be set to 0 and the diagonal entries to 1. If ``f`` is a 1-form, the vector entries at boundary nodes are set to the boundary condition values. """ if "nest" in kwargs: nest = kwargs.pop("nest") from firedrake.logging import warning, RED warning(RED % "The 'nest' argument is deprecated, please set 'mat_type' instead") if nest is not None: mat_type = "nest" if nest else "aij" collect_loops = kwargs.pop("collect_loops", False) allocate_only = kwargs.pop("allocate_only", False) if len(kwargs) > 0: raise TypeError("Unknown keyword arguments '%s'" % ', '.join(kwargs.keys())) if isinstance(f, (ufl.form.Form, slate.TensorBase)): loops = _assemble(f, tensor=tensor, bcs=solving._extract_bcs(bcs), form_compiler_parameters=form_compiler_parameters, inverse=inverse, mat_type=mat_type, sub_mat_type=sub_mat_type, appctx=appctx, assemble_now=not collect_loops, allocate_only=allocate_only, options_prefix=options_prefix) loops = tuple(loops) if collect_loops and not allocate_only: # Will this be useful? return loops else: for l in loops: m = l() return m elif isinstance(f, ufl.core.expr.Expr): return assemble_expressions.assemble_expression(f) else: raise TypeError("Unable to assemble: %r" % f)
def assemble(expr, tensor=None, bcs=None, *, diagonal=False, assembly_type="solution", form_compiler_parameters=None, mat_type=None, sub_mat_type=None, appctx={}, options_prefix=None): r"""Evaluate expr. :arg expr: a :class:`~ufl.classes.Form`, :class:`~ufl.classes.Expr` or a :class:`~slate.TensorBase` expression. :arg tensor: Existing tensor object to place the result in. :arg bcs: Iterable of boundary conditions to apply. :kwarg diagonal: If assembling a matrix is it diagonal? :kwarg assembly_type: String indicating how boundary conditions are applied (may be ``"solution"`` or ``"residual"``). If ``"solution"`` then the boundary conditions are applied as expected whereas ``"residual"`` zeros the selected components of the tensor. :kwarg form_compiler_parameters: Dictionary of parameters to pass to the form compiler. Ignored if not assembling a :class:`~ufl.classes.Form`. Any parameters provided here will be overridden by parameters set on the :class:`~ufl.classes.Measure` in the form. For example, if a ``quadrature_degree`` of 4 is specified in this argument, but a degree of 3 is requested in the measure, the latter will be used. :kwarg mat_type: String indicating how a 2-form (matrix) should be assembled -- either as a monolithic matrix (``"aij"`` or ``"baij"``), a block matrix (``"nest"``), or left as a :class:`.ImplicitMatrix` giving matrix-free actions (``'matfree'``). If not supplied, the default value in ``parameters["default_matrix_type"]`` is used. BAIJ differs from AIJ in that only the block sparsity rather than the dof sparsity is constructed. This can result in some memory savings, but does not work with all PETSc preconditioners. BAIJ matrices only make sense for non-mixed matrices. :kwarg sub_mat_type: String indicating the matrix type to use *inside* a nested block matrix. Only makes sense if ``mat_type`` is ``nest``. May be one of ``"aij"`` or ``"baij"``. If not supplied, defaults to ``parameters["default_sub_matrix_type"]``. :kwarg appctx: Additional information to hang on the assembled matrix if an implicit matrix is requested (mat_type ``"matfree"``). :kwarg options_prefix: PETSc options prefix to apply to matrices. :returns: See below. If expr is a :class:`~ufl.classes.Form` or Slate tensor expression then this evaluates the corresponding integral(s) and returns a :class:`float` for 0-forms, a :class:`.Function` for 1-forms and a :class:`.Matrix` or :class:`.ImplicitMatrix` for 2-forms. In the case of 2-forms the rows correspond to the test functions and the columns to the trial functions. If expr is an expression other than a form, it will be evaluated pointwise on the :class:`.Function`\s in the expression. This will only succeed if all the Functions are on the same :class:`.FunctionSpace`. If ``tensor`` is supplied, the assembled result will be placed there, otherwise a new object of the appropriate type will be returned. If ``bcs`` is supplied and ``expr`` is a 2-form, the rows and columns of the resulting :class:`.Matrix` corresponding to boundary nodes will be set to 0 and the diagonal entries to 1. If ``expr`` is a 1-form, the vector entries at boundary nodes are set to the boundary condition values. .. note:: For 1-form assembly, the resulting object should in fact be a *cofunction* instead of a :class:`.Function`. However, since cofunctions are not currently supported in UFL, functions are used instead. """ if isinstance(expr, (ufl.form.Form, slate.TensorBase)): return assemble_form(expr, tensor, bcs, diagonal, assembly_type, form_compiler_parameters, mat_type, sub_mat_type, appctx, options_prefix) elif isinstance(expr, ufl.core.expr.Expr): return assemble_expressions.assemble_expression(expr) else: raise TypeError(f"Unable to assemble: {expr}")