Example #1
0
 def _set_conditions(self, conditions):
     if isinstance(conditions, tuple):
         for cond in conditions:
             if cond in ThresholdCheck._default_min_conditions:
                 self._conditions[cond] = self._min_threshold
             elif cond in ThresholdCheck._default_max_conditions:
                 self._conditions[cond] = self._max_threshold
             else:
                 raise ValueError(func_name(self) +
                                  "Given condition is not supported: {:s}".format(cond))
     elif isinstance(conditions, dict):
         for cond in conditions:
             if cond in ThresholdCheck._default_min_conditions or \
                     cond in ThresholdCheck._default_max_conditions:
                 self._conditions[cond] = conditions[cond]
             else:
                 raise ValueError(func_name(self) +
                                  "Given condition is not supported: {:s}".format(cond))
     elif conditions is None:
         pass
     else:
         raise ValueError(func_name(self) +
                          "Given conditions can not be parsed: {:s}".format(conditions))
    def init(self, coeffs=[1.0], func=None):
        """Sets and defines the weights function.

        Parameters
        ----------
        coeffs : :py:class:`numpy.ndarray` or :py:class:`list`
            Array of coefficients of the polynomial.
        func : :py:class:`str`
            Of format ``c0 + c1 x^1 + c2 x^2...``
            String representation of the polynomial.

        Notes
        -----
        Parsing of a string representation of the polynomial is not yet implemented.
        Usage will lead to a `NotImplementedError` exception.
        """
        super(PolynomialWeightFunction, self).init(coeffs, func=None)
        if func is not None and isinstance(func, str):
            # TODO: implement parsing of polynomial function string
            raise NotImplementedError(func_name(self) +
                                      "Parsing of polynomial function as string not yet possible.")
        elif coeffs is not None and \
                (isinstance(coeffs, np.ndarray) or isinstance(coeffs, list)):
            self.coefficients = np.array(coeffs)
Example #3
0
    def init(self, problem, integrator, **kwargs):
        """Initializes SDC solver with given problem and integrator.

        Parameters
        ----------
        num_time_steps : :py:class:`int`
            Number of time steps to be used within the time interval of the problem.
        num_nodes : :py:class:`int`
            *(otional)*
            number of nodes per time step
        nodes_type : :py:class:`.INodes`
            *(optional)*
            Type of integration nodes to be used (class name, **NOT instance**).
        weights_type : :py:class:`.IWeightFunction`
            *(optional)*
            Integration weights function to be used (class name, **NOT instance**).
        classic : :py:class:`bool`
            *(optional)*
            Flag for specifying the type of the SDC sweep.
            :py:class:`True`: *(default)* For the classic SDC as known from the literature;
            :py:class:`False`: For the modified SDC as developed by Torbjörn Klatt.


        Raises
        ------
        ValueError :

            * if given problem is not an :py:class:`.IInitialValueProblem`
            * if number of nodes per time step is not given; neither through ``num_nodes``, ``nodes_type`` nor
              ``integrator``

        See Also
        --------
        :py:meth:`.IIterativeTimeSolver.init`
            overridden method (with further parameters)
        :py:meth:`.IParallelSolver.init`
            mixed in overridden method (with further parameters)
        """
        assert_is_instance(problem, IInitialValueProblem, descriptor="Initial Value Problem", checking_obj=self)
        assert_condition(
            issubclass(integrator, IntegratorBase),
            ValueError,
            message="Integrator must be an IntegratorBase: NOT %s" % integrator.__mro__[-2].__name__,
            checking_obj=self,
        )

        super(ParallelSdc, self).init(problem, integrator=integrator, **kwargs)

        if "num_time_steps" in kwargs:
            self._num_time_steps = kwargs["num_time_steps"]

        if "num_nodes" in kwargs:
            self.__num_nodes = kwargs["num_nodes"]
        elif "nodes_type" in kwargs and kwargs["nodes_type"].num_nodes is not None:
            self.__num_nodes = kwargs["nodes_type"].num_nodes
        elif integrator.nodes_type is not None and integrator.nodes_type.num_nodes is not None:
            self.__num_nodes = integrator.nodes_type.num_nodes
        else:
            raise ValueError(func_name(self) + "Number of nodes per time step not given.")

        if "notes_type" in kwargs:
            self.__nodes_type = kwargs["notes_type"]

        if "weights_type" in kwargs:
            self.__weights_type = kwargs["weights_type"]

        if "classic" in kwargs:
            assert_is_instance(kwargs["classic"], bool, descriptor="Classic Flag", checking_obj=self)
            self._classic = kwargs["classic"]

        # TODO: need to store the exact solution somewhere else
        self.__exact = np.zeros(self.num_time_steps * (self.__num_nodes - 1) + 1, dtype=np.object)