def __rmul__(self, other): form_mul = other * self._form output = _ParametrizedTensorFactory.__new__(type(self), form_mul) output.__init__(form_mul) add_to_map_from_parametrized_operator_to_problem( output, get_problem_from_parametrized_operator(self)) return output
def _product(thetas: ThetaType, operators: tuple_of(ParametrizedTensorFactory)): operators_as_forms = tuple(operator._form for operator in operators) try: output = _product_parametrized_tensor_factories_output_cache[ operators_as_forms] except KeyError: # Keep the operators as ParametrizedTensorFactories and delay assembly as long as possible output = _product(thetas, operators_as_forms) output = ParametrizedTensorFactory(output.sum_product_return_value) problems = [ get_problem_from_parametrized_operator(operator) for operator in operators ] assert all([problem is problems[0] for problem in problems]) add_to_map_from_parametrized_operator_to_problem(output, problems[0]) output = ProductOutput(output) _product_parametrized_tensor_factories_output_cache[ operators_as_forms] = output _product_parametrized_tensor_factories_constants_cache[ operators_as_forms] = _product_forms_constants_cache[ operators_as_forms] return output else: constants = _product_parametrized_tensor_factories_constants_cache[ operators_as_forms] for (theta, constant) in zip(thetas, constants): theta = float(theta) constant.assign(theta) return output
def _prepare_truth_operators_as_expansion_storage(self): from rbnics.backends import NonAffineExpansionStorage assert self._type == "operators" assert self.order() is 1 extracted_operators = tuple(op._form for op in self._content["truth_operators"]) assert "truth_operators_as_expansion_storage" not in self._content self._content["truth_operators_as_expansion_storage"] = NonAffineExpansionStorage(extracted_operators) problems = [get_problem_from_parametrized_operator(op) for op in self._content["truth_operators"]] assert all([problem is problems[0] for problem in problems]) for extracted_operator in self._content["truth_operators_as_expansion_storage"]: add_to_map_from_parametrized_operator_to_problem(extracted_operator, problems[0])
def __add__(self, other): form_sum = self._form + other._form output = _ParametrizedTensorFactory.__new__(type(self), form_sum) output.__init__(form_sum) problems = [ get_problem_from_parametrized_operator(operator) for operator in (self, other) ] assert all([problem is problems[0] for problem in problems]) add_to_map_from_parametrized_operator_to_problem( output, problems[0]) return output
def __rmul__(self, other): form_mul = other * self._form output = _ParametrizedTensorFactory.__new__(type(self), form_mul) output.__init__(form_mul) # Set corresponding problem add_to_map_from_parametrized_operator_to_problem( output, get_problem_from_parametrized_operator(self)) # Automatically compute name starting from current name. output._name = _ParametrizedTensorFactory._hash_name( str(other) + " * " + self.name()) # This method is only used by exact parametrized operator evaluations, and not by DEIM. # Thus, description (which is called by DEIM during the offline phase) must never be used, # and the code should give an error if it is used by mistake. del output._description # Return return output
def __mul__(self, other): form_mul = self._form * other output = _ParametrizedTensorFactory.__new__(type(self), form_mul) output.__init__(form_mul) # Set corresponding problem add_to_map_from_parametrized_operator_to_problem( output, get_problem_from_parametrized_operator(self)) # Do not recompute name, as the computed name would: # * account that other is a solution (or its derivative) while called from an high fidelity solve, because of # known mapping from truth solution to truth problem. # * not be able account that other is the high fidelity representation of a reduced solution, because mapping # from (high fidelity representation of) reduced solution to truth problem is not known, as a new # reduced solution (and corresponding representation) is generated at every reduced solve # Simply re-use the existing name with a custom suffix. output._name = _ParametrizedTensorFactory._hash_name( self.name() + "_mul_function") # This method is only used by exact parametrized operator evaluations, and not by DEIM. # Thus, description (which is called by DEIM during the offline phase) must never be used, # and the code should give an error if it is used by mistake. del output._description # Return return output
def __add__(self, other): form_sum = self._form + other._form output = _ParametrizedTensorFactory.__new__(type(self), form_sum) output.__init__(form_sum) # Set corresponding problem problems = [ get_problem_from_parametrized_operator(operator) for operator in (self, other) ] assert all([problem is problems[0] for problem in problems]) add_to_map_from_parametrized_operator_to_problem( output, problems[0]) # Automatically compute name starting from names of addends output._name = _ParametrizedTensorFactory._hash_name(self.name() + " + " + other.name()) # This method is only used by exact parametrized operator evaluations, and not by DEIM. # Thus, description (which is called by DEIM during the offline phase) must never be used, # and the code should give an error if it is used by mistake. del output._description # Return return output