Пример #1
0
 def __init__(self, form, strict=False):
     AbstractSeparatedParametrizedForm.__init__(self, form)
     form = expand_derivatives(form)
     form = expand_sum_product(form)
     form = rewrite_quotients(form)
     form = remove_complex_nodes(
         form)  # TODO support forms in the complex field
     self._form = form
     self._coefficients = list()  # of list of ParametrizedExpression
     self._placeholders = list()  # of list of Constants
     self._placeholder_names = list()  # of list of string
     self._form_with_placeholders = list()  # of forms
     self._form_unchanged = list()  # of forms
     # Internal usage
     self._NaN = float("NaN")
     # Strict mode when
     # * checking candidates to be added to coefficients which contain both parametrized and non parametrized leaves.
     # * checking for coefficients that are solution
     # If False (default)
     # * coefficient splitting is prevented, because separating the non parametrized part would result in more
     #   than one coefficient, and the candidate is accepted as the coefficient which contain both parametrized and non parametrized leaves.
     # * solutions are considered as parametrized
     # If True
     # * coefficient is split in order to assure that all coefficients only contains parametrized terms, at the expense of
     #   a larger number of coefficients
     # * solutions and geometric quantities (except normals) are prevented for being collected in coefficients
     self._strict = strict
Пример #2
0
    def __init__(self, form):
        # Preprocess form
        form = expand_derivatives(form)
        form = remove_complex_nodes(
            form)  # TODO support forms in the complex field
        # Extract spaces from forms
        len_spaces = len(form.arguments())
        assert len_spaces in (0, 1, 2)
        if len_spaces is 2:
            spaces = (form_argument_space(form,
                                          0), form_argument_space(form, 1))
        elif len_spaces is 1:
            spaces = (form_argument_space(form, 0), )
        elif len_spaces is 0:
            spaces = ()
        else:
            raise ValueError("Invalid arguments")
        # Create empty snapshot
        if len_spaces in (1, 2):

            def assemble_empty_snapshot():
                empty_snapshot = assemble(form, keep_diagonal=True)
                empty_snapshot.zero()
                empty_snapshot.generator = self
                return empty_snapshot
        elif len_spaces is 0:

            def assemble_empty_snapshot():
                return 0.
        else:
            raise ValueError("Invalid arguments")
        # Call Parent
        ParametrizedTensorFactory_Base.__init__(self, form, spaces,
                                                assemble_empty_snapshot)