Coverage for src/pymor/parameters/functionals : 58%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
# This file is part of the pyMOR project (http://www.pymor.org). # Copyright Holders: Rene Milk, Stephan Rave, Felix Schindler # License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
'''|ParameterFunctional| returning a component of the given parameter.
Parameters ---------- component_name The name of the component to return. component_shape The shape of the component. coordinates If not `None` return `mu[component_name][coordinates]` instead of `mu[component_name]`. name Name of the functional. '''
component_shape = tuple() if component_shape == 0 else (component_shape,)
mu = self.parse_parameter(mu) if self.coordinates is None: return mu[self.component_name] else: return mu[self.component_name][self.coordinates]
'''A wrapper making an arbitrary Python function a |ParameterFunctional|
Parameters ---------- parameter_type The |ParameterType| of the |Parameters| the functional takes. mapping The function to wrap. The function is of the form `mapping(mu)`. name The name of the functional. '''
self.name = name self._mapping = mapping self.build_parameter_type(parameter_type, local_global=True)
mu = self.parse_parameter(mu) return self._mapping(mu)
'''Turns a Python expression given as a string into a |ParameterFunctional|.
Some |NumPy| arithmetic functions like 'sin', 'log', 'min' are supported. For a full list see the `functions` class attribute.
.. warning:: :meth:`eval` is used to evaluate the given expression. As a consequence, using this class with expression strings from untrusted sources will cause mayhem and destruction!
Parameters ---------- expression The Python expression for the functional as a string. parameter_type The |ParameterType| of the |Parameters| the functional takes. '''
'sinh', 'cosh', 'tanh', 'arcsinh', 'arccosh', 'arctanh', 'exp', 'exp2', 'log', 'log2', 'log10', 'min', 'minimum', 'max', 'maximum', }}
self.expression = expression code = compile(expression, '<dune expression>', 'eval') mapping = lambda mu: eval(code, self.functions, mu) super(ExpressionParameterFunctional, self).__init__(mapping, parameter_type, name)
return 'ExpressionParameterFunctional({}, {})'.format(self.expression, repr(self.parameter_type))
return (self.expression, self.parameter_type, self.name)
self.__init__(*state) |