B u `@sddlmZddlmZddlmZddlmZmZm Z m Z dZ e dGdddeZ Gd d d e e ZGd d d e e Zd S))ModelComponentFactory) ContinuousSet) DAE_Error) Expression_GeneralExpressionDataSimpleExpressionIndexedExpression)Integralz#Integral Expression in a DAE model.cs0eZdZdZfddZddZddZZS)r aY Represents an integral over a continuous domain The :py:class:`Integral` component can be used to represent an integral taken over the entire domain of a :py:class:`ContinuousSet`. Once every :py:class:`ContinuousSet` in a model has been discretized, any integrals in the model will be converted to algebraic equations using the trapezoid rule. Future development will include more sophisticated numerical integration methods. Parameters ---------- *args Every indexing set needed to evaluate the integral expression wrt : :py:class:`ContinuousSet` The continuous domain over which the integral is being taken rule : function Function returning the expression being integrated csR|tkrtt||St|dkr.tdn t|dkrDttSttSdS)Nrz+Integral must be indexed by a ContinuousSet)r super__new__len ValueErrorSimpleIntegralIndexedIntegral)clsargskwds) __class__6/tmp/pip-unpacked-wheel-n62dbgi3/pyomo/dae/integral.pyr /s    zIntegral.__new__csPd|krd|krtd|dd|ddkrTt|dkrLtd|dttk rltd|_dx t|D]\}}|kr|qWdkrtdj|_ |d|dd}|d d}|dk rt d |d d|d dkrtd fdd}||d <| dt t j|f||dS)NwrtZ withrespecttoz5Cannot specify both 'wrt' and 'withrespectto keywordsr zyIntegral indexed by multiple ContinuousSets. The desired ContinuousSet must be specified using the keyword argument 'wrt'rzdCannot take the integral with respect to '%s'. Must take an integral with respect to a ContinuousSetzIThe ContinuousSet '%s' was not found in the indexing sets of the IntegralboundszrSetting bounds on integrals has not yet been implemented. Integrals may only be taken over an entire ContinuousSetexprZrulez#Must specify an integral expressioncs:tjtfddttdDS)Nc 3s|]z}d|d|fd|dfdfd|fdVqdS)g?r rNr).0i)adsintexplocmrr rsz8Integral.__init__.._trap_rule..r )sortedZfind_componentZ local_namesumranger )r r)rrr)rrr r _trap_rulepsz%Integral.__init__.._trap_rulectype) TypeErrorpopr rtyper_wrt enumeratenamerr setdefaultr r__init__)selfrrrsargrr%r)rrrrr.9sL          zIntegral.__init__cCs|jS)zp Return the :py:class:`ContinuousSet` the integral is being taken over )r*)r/rrrget_continuousset{szIntegral.get_continuousset)__name__ __module__ __qualname____doc__r r.r2 __classcell__rr)rrr s Br c@s eZdZdZddZddZdS)rzw An integral that will have no indexing sets after applying a numerical integration transformation cOs&tj|d|dtj|f||dS)N) component)rr.r )r/rrrrrr.szSimpleIntegral.__init__cCsd|jkrdSdS)zj Checks to see if all ContinuousSets indexing this Integral have been discretized schemeFT)r*get_discretization_info)r/rrris_fully_discretizedsz#SimpleIntegral.is_fully_discretizedN)r3r4r5r6r.r;rrrrrsrc@seZdZdZddZdS)rzd An integral that will be indexed after applying a numerical integration transformation cCsh|j}d|krdSg}|dkr2|g}n |j}x&|D]}|jtkrBd|krBdSqBWdS)zk Checks to see if all ContinuousSets indexing this Integral have been discretized. r9Fr T)r*r:ZdimZ index_setZ set_tupler&r)r/rZsetlistrrrrr;s       z$IndexedIntegral.is_fully_discretizedN)r3r4r5r6r;rrrrrsrN)Zpyomo.core.base.pluginrZpyomo.dae.contsetrZpyomo.dae.diffvarrZpyomo.core.base.expressionrrrr__all__registerr rrrrrr s   k