• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utilities.assert_condition函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pypint.utilities.assert_condition函数的典型用法代码示例。如果您正苦于以下问题:Python assert_condition函数的具体用法?Python assert_condition怎么用?Python assert_condition使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了assert_condition函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: residual

    def residual(self, iteration):
        """Accessor for the residuals of a specific iteration.

        Parameters
        ----------
        iteration : :py:class:`int`
            0-based index of the iteration.
            ``-1`` means last iteration.

        Returns
        -------
        residual : instance of :py:attr:`.Residual`
            or :py:class:`None` if no solutions are stored.

        Raises
        ------
        ValueError :
            If given ``iteration`` index is not in the valid range.
        """
        if len(self._data) > 0:
            assert_condition(iteration in range(-1, len(self._data)), ValueError,
                             message="Iteration index not within valid range: {:d} not in [-1, {:d}"
                                     .format(iteration, len(self._data)),
                             checking_obj=self)
            if self._data_type == StepSolutionData:
                return np.array(self._data[iteration].residual, dtype=np.object)
            else:
                return self._data[iteration].residuals
        else:
            return None
开发者ID:DiMoser,项目名称:PyPinT,代码行数:30,代码来源:iterative_solution.py


示例2: value

 def value(self, value):
     assert_condition(not self.finalized, AttributeError,
                      message="Cannot change this solution data storage any more.", checking_obj=self)
     assert_is_instance(value, np.ndarray, descriptor="Values", checking_obj=self)
     self._dim = value.shape
     self._numeric_type = value.dtype
     self._data = value
开发者ID:DiMoser,项目名称:PyPinT,代码行数:7,代码来源:step_solution_data.py


示例3: write_buffer

    def write_buffer(self, tag=None, **kwargs):
        """Writes data into this communicator's buffer

        Parameters
        ----------
        value :
            data values to be send to the next solver
        time_point : :py:class:`float`
            time point of the data values
        flag : :py:class:`.Message.SolverFlag`
            message flag

        Raises
        ------
        ValueError

            * if no arguments are given
            * if ``time_point`` is not a :py:class:`float`
        """
        assert_condition(len(kwargs) > 0, ValueError, "At least one argument must be given.", self)

        if tag not in self._buffer:
            self._buffer[tag] = Message()
            self.write_buffer(tag=tag, **kwargs)

        if "value" in kwargs:
            self._buffer[tag].value = deepcopy(kwargs["value"])

        if "time_point" in kwargs:
            assert_is_instance(kwargs["time_point"], float, descriptor="Time Point", checking_obj=self)
            self._buffer[tag].time_point = deepcopy(kwargs["time_point"])

        if "flag" in kwargs:
            self._buffer[tag].flag = deepcopy(kwargs["flag"])
开发者ID:kidaa,项目名称:PyPinT,代码行数:34,代码来源:i_communication_provider.py


示例4: evaluate

    def evaluate(self, data, **kwargs):
        """Applies this integrator to given data in specified time interval.

        Parameters
        ----------
        data : :py:class:`numpy.ndarray`
            Data vector of the values at given time points.
            Its length must equal the number of integration nodes.
        time_start : :py:class:`float`
            *(optional)*
            Begining of the time interval to integrate over.
        time_end : :py:class:`float`
            *(optional)*
            End of the time interval to integrate over.

        Raises
        ------
        ValueError :

            * if ``data`` is not a :py:class:`numpy.ndarray`
            * if either ``time_start`` or ``time_end`` are not given
            * if ``time_start`` is larger or equals ``time_end``
        """
        assert_is_instance(data, np.ndarray, descriptor="Data to integrate", checking_obj=self)
        assert_condition("time_start" in kwargs or "time_end" in kwargs,
                         ValueError, message="Either start or end of time interval need to be given.",
                         checking_obj=self)
        assert_condition(kwargs["time_start"] < kwargs["time_end"],
                         ValueError,
                         message="Time interval need to be non-zero positive: [{:f}, {:f}]"
                                 .format(kwargs["time_start"], kwargs["time_end"]),
                         checking_obj=self)
开发者ID:DiMoser,项目名称:PyPinT,代码行数:32,代码来源:integrator_base.py


示例5: _init_new_iteration

    def _init_new_iteration(self):
        _current_state = self.state.current_iteration
        _previous_iteration = self.state.previous_iteration

        # set initial values
        for _level_index in range(0, self.ml_provider.num_levels):
            _current_state.add_finer_level(self.ml_provider.integrator(_level_index).num_nodes - 1)
            _level = _current_state.finest_level
            assert_condition(len(_level) == self.ml_provider.integrator(_level_index).num_nodes - 1,
                             RuntimeError, "Number of Steps on Level %d not correct (%d)"
                             % (len(_level), self.ml_provider.integrator(_level_index).num_nodes - 1),
                             checking_obj=self)

            _level.initial = deepcopy(self.state.initial)
            if _previous_iteration is None:
                _level.broadcast(_level.initial.value)

            for _step_index in range(0, len(_level)):
                _level[_step_index].delta_tau = self.__deltas[_level_index][_step_index + 1]
                _level[_step_index].solution.time_point = self.__time_points[_level_index][_step_index + 1]
                if _previous_iteration is not None:
                    _level[_step_index].value = _previous_iteration[_level_index][_step_index].value.copy()

        assert_condition(len(self.state.current_iteration) == self.ml_provider.num_levels,
                         RuntimeError, "Number of levels in current state not correct."
                                       " (this shouldn't have happend)",
                         checking_obj=self)
开发者ID:DiMoser,项目名称:PyPinT,代码行数:27,代码来源:ml_sdc.py


示例6: finalize

 def finalize(self):
     assert_condition(not self.finalized, RuntimeError,
                      message="This {} is already done.".format(class_name(self)),
                      checking_obj=self)
     self._solution = self.finest_level.solution
     self._current_index = 0
     self._finalized = True
开发者ID:DiMoser,项目名称:PyPinT,代码行数:7,代码来源:mlsdc_solver_state.py


示例7: values

 def values(self, values):
     assert_condition(values.shape[0] == (len(self) + 1), ValueError,
                      "Number of values does not match number of nodes: %d != %d"
                      % (values.shape[0], (len(self) + 1)),
                      checking_obj=self)
     for _step in range(0, len(self)):
         self[_step].value = values[_step + 1].copy()
开发者ID:DiMoser,项目名称:PyPinT,代码行数:7,代码来源:mlsdc_solver_state.py


示例8: __init__

    def __init__(self, **kwargs):
        """
        Parameters
        ----------
        solution_class : :py:class:`.ISolution`, :py:class:`.StepSolutionData` or :py:class:`.TrajectorySolutionData`

        element_type : :py:class:`.IStepState` or :py:class:`.IStateItertor`

        num_states : :py:class:`int`
            *(optional)*

        Raises
        ------
        ValueError
            if ``num_states`` is not a non-zero positive integer
        """
        assert_named_argument('solution_class', kwargs, descriptor="Solution Type", checking_obj=self)
        assert_named_argument('element_type', kwargs, descriptor="Element Type", checking_obj=self)
        self._solution = kwargs['solution_class']()
        del kwargs['solution_class']
        self._element_type = kwargs['element_type']
        del kwargs['element_type']
        self._states = []
        self._current_index = 0
        self._finalized = False

        if 'num_states' in kwargs:
            _num_states = kwargs['num_states']
            assert_condition(isinstance(_num_states, int) and _num_states > 0,
                             ValueError, message="Number of states must be a non-zero positive integer: NOT {}"
                                                 .format(_num_states),
                             checking_obj=self)
            self._states = [self._element_type(**kwargs) for i in range(0, _num_states)]
开发者ID:DiMoser,项目名称:PyPinT,代码行数:33,代码来源:i_solver_state.py


示例9: construct_space_tensor

    def construct_space_tensor(self, number_of_points_list, stencil=None):
        """Constructs the Spacetensor which is important for the evaluation in the case of Dirichlet boundary conditions

        Parameters
        ----------
        number_of_points_list : :py:class:`int` or :py:class:`numpy.ndarray`
            Number of points which will be distributed equiv-spaced on the grid
        """
        if isinstance(number_of_points_list, (int, float, complex)):
            assert_is_instance(stencil, Stencil, descriptor="Stencil", checking_obj=self)
            npoints = int(number_of_points_list)
            # LOG.debug("Your number %s was modified to %s" % (number_of_points_list, npoints))
            assert_condition(npoints > max(stencil.arr.shape), ValueError,
                             message="Not enough points for the stencil", checking_obj=self)
            npoints = np.asarray([npoints] * len(self.spacial_dim))
        elif isinstance(number_of_points_list, np.ndarray):
            assert_condition(len(number_of_points_list.shape) == 1 and number_of_points_list.size == len(self.spacial_dim),
                             ValueError, message="The number_of_points list is wrong", checking_obj=self)
            npoints = np.floor(number_of_points_list)
        else:
            raise ValueError("Wrong number of points list")

        # first we assign the memory using numpy
        # spt(npoints,dim)
        self._act_npoints = npoints
        lspc = []
        for i in range(len(self.spacial_dim)):
            lspc.append(np.linspace(self._geometry[i, 0], self._geometry[i, 1], npoints[i]))
        if len(self.spacial_dim) > 1:
            space_tensor = np.asarray(np.meshgrid(*lspc))
        else:
            space_tensor = np.linspace(self._geometry[0, 0], self._geometry[0, 1], npoints)

        return space_tensor
开发者ID:DiMoser,项目名称:PyPinT,代码行数:34,代码来源:multigrid_problem_mixin.py


示例10: _add_iteration

 def _add_iteration(self):
     assert_condition(self.num_level > 0,
                      ValueError,
                      message="Number of number of levels and nodes per level must be larger 0: NOT {}"
                              .format(self.num_level),
                      checking_obj=self)
     self._states.append(self._element_type(num_level=self.num_level))
开发者ID:DiMoser,项目名称:PyPinT,代码行数:7,代码来源:mlsdc_solver_state.py


示例11: fas_correction

 def fas_correction(self, fas_correction):
     assert_condition(fas_correction.shape[0] == (len(self) + 1), ValueError,
                      "Number of FAS Corrections does not match number of nodes: %d != %d"
                      % (fas_correction.shape[0], (len(self) + 1)),
                      checking_obj=self)
     for _step in range(0, len(self)):
         self[_step].fas_correction = fas_correction[_step + 1] - fas_correction[_step]
开发者ID:DiMoser,项目名称:PyPinT,代码行数:7,代码来源:mlsdc_solver_state.py


示例12: coarse_corrections

 def coarse_corrections(self, coarse_correction):
     assert_condition(coarse_correction.shape[0] == (len(self) + 1), ValueError,
                      "Number of Coarse Corrections does not match number of nodes: %d != %d"
                      % (coarse_correction.shape[0], (len(self) + 1)),
                      checking_obj=self)
     for _step in range(0, len(self)):
         self[_step].coarse_correction = coarse_correction[_step + 1]
开发者ID:DiMoser,项目名称:PyPinT,代码行数:7,代码来源:mlsdc_solver_state.py


示例13: _add_iteration

 def _add_iteration(self):
     assert_condition(self.num_time_steps > 0 and self.num_nodes > 0,
                      ValueError, message="Number of time steps and nodes per time step must be larger 0: NOT {}, {}"
                      .format(self.num_time_steps, self.num_nodes),
                      checking_obj=self)
     self._states.append(self._element_type(num_states=self.num_nodes,
                                            num_time_steps=self.num_time_steps))
开发者ID:DiMoser,项目名称:PyPinT,代码行数:7,代码来源:i_solver_state.py


示例14: add_coefficient

    def add_coefficient(self, coefficient, power):
        """Adds or sets the coefficient :math:`c` of :math:`cx^p` for a specific :math:`p`.

        The polynomial gets automatically extended to hold the new coefficient in case it didn't included the specified
        power previously.
        Unset, but skipped powers have a coefficient of zero by default.

        Parameters
        ----------
        coefficient : :py:class:`float`
            Coefficient :math:`c` of :math:`cx^p`.
        power : :py:class:`int`
             Power :math:`p` of :math:`cx^p`.

        Examples
        --------
        >>> polyWeights = PolynomialWeightFunction()
        >>> # To set the coefficient of x^3 to 3.14 use:
        >>> polyWeights.add_coefficient(3.14, 3)
        >>> # Similar, to set the constant coefficient 42, e.i. 42*x^0, use:
        >>> polyWeights.add_coefficient(42, 0)
        """
        assert_is_instance(power, int, descriptor="Power", checking_obj=self)
        assert_condition(power >= 0, ValueError,
                         message="Power must be zero or positive: {:d}".format(power), checking_obj=self)

        if self._coefficients.size <= power + 1:
            self._coefficients = np.resize(self._coefficients, (power + 1))

        self._coefficients[power] = coefficient
开发者ID:DiMoser,项目名称:PyPinT,代码行数:30,代码来源:polynomial_weight_function.py


示例15: solution

    def solution(self, iteration):
        """Accessor for the solution of a specific iteration.

        Parameters
        ----------
        iteration : :py:class:`int`
            0-based index of the iteration.
            ``-1`` means last iteration.

        Returns
        -------
        solution : instance of :py:attr:`.data_storage_type`
            or :py:class:`None` if no solutions are stored.

        Raises
        ------
        ValueError :
            If given ``iteration`` index is not in the valid range.
        """
        if len(self._data) > 0:
            assert_condition(iteration in range(-1, len(self._data)), ValueError,
                             message="Iteration index not within valid range: {:d} not in [-1, {:d}"
                                     .format(iteration, len(self._data)),
                             checking_obj=self)
            return self._data[iteration]
        else:
            return None
开发者ID:DiMoser,项目名称:PyPinT,代码行数:27,代码来源:iterative_solution.py


示例16: time_interval

 def time_interval(self, value):
     assert_is_instance(value, np.ndarray, descriptor="Time Interval", checking_obj=self)
     assert_condition(value.size == 2, ValueError,
                      message="Time Interval must have two values: NOT %d" % value.size)
     self.validate_time_interval(start=value[0], end=value[1])
     self.time_start = value[0]
     self.time_end = value[1]
开发者ID:DiMoser,项目名称:PyPinT,代码行数:7,代码来源:transient_problem_mixin.py


示例17: link_solvers

    def link_solvers(self, *args, **kwargs):
        """Links the given communicators with this communicator

        Parameters
        ----------
        previous : :py:class:`.ForwardSendingMessaging`
            communicator of the previous solver
        next : :py:class:`.ForwardSendingMessaging`
            communicator of the next solver

        Raises
        ------
        ValueError
            if one of the two communicators of the specified type is not given
        """
        super(ForwardSendingMessaging, self).link_solvers(*args, **kwargs)
        assert_condition(len(kwargs) == 2,
                         ValueError, message="Exactly two communicators must be given: NOT %d" % len(kwargs),
                         checking_obj=self)

        assert_named_argument('previous', kwargs, types=ForwardSendingMessaging, descriptor="Previous Communicator",
                              checking_obj=self)
        self._previous = kwargs['previous']

        assert_named_argument('next', kwargs, types=ForwardSendingMessaging, descriptor="Next Communicator",
                              checking_obj=self)
        self._next = kwargs['next']
开发者ID:DiMoser,项目名称:PyPinT,代码行数:27,代码来源:forward_sending_messaging.py


示例18: __init__

    def __init__(self, fine_level, coarse_level, rst_stencil, ipl_stencil):
        assert_is_instance(fine_level, MultigridLevel1D, "Not an MultigridLevel1D")
        assert_is_instance(coarse_level, MultigridLevel1D, "Not an MultigridLevel1D")

        self.fl = fine_level
        self.cl = coarse_level

        assert_is_instance(ipl_stencil, InterpolationByStencilListIn1D)
        assert_is_instance(rst_stencil, RestrictionStencilPure)
        assert_condition(rst_stencil.ndim == 1,
                         ValueError, "Restriction Stencil"
                         + "has not the dimension 1")
        self.ipl = ipl_stencil
        self.rst = rst_stencil
        self.ipl_fine_views = []
        self.ipl_coarse_views = []
        # collect the views which are needed,
        if self.ipl.mode == "own":
            self.ipl_fine_views.append(self.fl.evaluable_view(
                self.ipl.stencil_list[0]))
            self.ipl_coarse_views(self.cl.mid)
        elif self.ipl.mode == "list":
            for stencil in self.ipl.stencil_list:
                self.ipl_fine_views.append(self.fl.evaluable_view(stencil))
                self.ipl_coarse_views.append(self.cl.mid)
        else:
            raise NotImplementedError("What do you have in mind?")

        self.rst_fine_view = self.fl.evaluable_view(self.rst)
        self.rst_coarse_view = self.cl.mid
开发者ID:DiMoser,项目名称:PyPinT,代码行数:30,代码来源:multigrid_level_provider.py


示例19: __eq__

 def __eq__(self, other):
     assert_condition(isinstance(other, self.__class__), TypeError,
                      message="Can not compare {} with {}".format(self.__class__, class_name(other)),
                      checking_obj=self)
     return (
         self.numeric_type == other.numeric_type
         and np.array_equal(self.value, other.value)
     )
开发者ID:DiMoser,项目名称:PyPinT,代码行数:8,代码来源:i_diagnosis_value.py


示例20: used_iterations

 def used_iterations(self, used_iterations):
     assert_condition(not self.finalized, ValueError,
                      message="Solution cannot be changed any more.", checking_obj=self)
     assert_condition(used_iterations > 0, ValueError,
                      message="Number of used iterations must be non-zero positive: NOT {:d}"
                              .format(used_iterations),
                      checking_obj=self)
     self._used_iterations = used_iterations
开发者ID:DiMoser,项目名称:PyPinT,代码行数:8,代码来源:i_solution.py



注:本文中的pypint.utilities.assert_condition函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utilities.assert_is_instance函数代码示例发布时间:2022-05-27
下一篇:
Python pypika.Query类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap