B u `,@snddlZddlZddlmZddlmZddlmZddlm Z e dZ dgZ e dGd ddeZdS) N)ConstructionTimer)ModelComponentFactory)SortedSimpleSet)native_numeric_typesz pyomo.dae ContinuousSetzWA bounded continuous numerical range optionally containing discrete points of interest.csheZdZdZfddZddZddZdd Zd d Zd d Z ddZ dfdd Z dddZ Z S)ra Represents a bounded continuous domain Minimally, this set must contain two numeric values defining the bounds of a continuous range. Discrete points of interest may be added to the continuous set. A continuous set is one dimensional and may only contain numerical values. Parameters ---------- initialize : `list` Default discretization points to be included bounds : `tuple` The bounding points for the continuous domain. The bounds will be included as discrete points in the :py:class:`ContinuousSet` and will be used to bound the points added to the :py:class:`ContinuousSet` through the 'initialize' argument, a data file, or the add() method Attributes ---------- _changed : `boolean` This keeps track of whether or not the ContinuousSet was changed during discretization. If the user specifies all of the needed discretization points before the discretization then there is no need to go back through the model and reconstruct things indexed by the :py:class:`ContinuousSet` _fe : `list` This is a sorted list of the finite element points in the :py:class:`ContinuousSet`. i.e. this list contains all the discrete points in the :py:class:`ContinuousSet` that are not collocation points. Points that are both finite element points and collocation points will be included in this list. _discretization_info : `dict` This is a dictionary which contains information on the discretization transformation which has been applied to the :py:class:`ContinuousSet`. cs|dddk rtd|dd|ddkr8td|dddk rPtd|d ddk rhtd t|d kr|td |d td|_g|_i|_tt|j f|dS)z Constructor filterNz:'filter' is not a valid keyword argument for ContinuousSetZdimenz9'dimen' is not a valid keyword argument for ContinuousSetZvirtualz;'virtual' is not a valid keyword argument for ContinuousSetvalidatez<'validate' is not a valid keyword argument for ContinuousSetrz$A ContinuousSet expects no argumentsctypeF) pop TypeError setdefaultlenr_changed_fe_discretization_infosuper__init__)selfargskwds) __class__5/tmp/pip-unpacked-wheel-n62dbgi3/pyomo/dae/contset.pyrCs     zContinuousSet.__init__cCs|jS)a Returns the finite element points If the :py:class:`ContinuousSet ` has been discretizaed using a collocation scheme, this method will return a list of the finite element discretization points but not the collocation points within each finite element. If the :py:class:`ContinuousSet ` has not been discretized or a finite difference discretization was used, this method returns a list of all the discretization points in the :py:class:`ContinuousSet `. Returns ------- `list` of `floats` )r)rrrrget_finite_elements^sz!ContinuousSet.get_finite_elementscCs|jS)zReturns a `dict` with information on the discretization scheme that has been applied to the :py:class:`ContinuousSet`. Returns ------- `dict` )r)rrrrget_discretization_infopsz%ContinuousSet.get_discretization_infocCs|jS)aI Returns flag indicating if the :py:class:`ContinuousSet` was changed during discretization Returns "True" if additional points were added to the :py:class:`ContinuousSet ` while applying a discretization scheme Returns ------- `boolean` )r)rrrr get_changedzs zContinuousSet.get_changedcCs"|dk r|dk rtd||_dS)zw Sets the ``_changed`` flag to 'newvalue' Parameters ---------- newvalue : `boolean` TFzJThe _changed attribute on a ContinuousSet may only be set to True or FalseN) ValueErrorr)rZnewvaluerrr set_changeds zContinuousSet.set_changedcCs^||jkr|S|t|jkr>tdt||jft|jSx|jD]}||krF|SqFWdS)z Returns the first finite element point that is greater or equal to 'point' Parameters ---------- point : `float` Returns ------- float z[The point '%s' exceeds the upper bound of the ContinuousSet '%s'. Returning the upper boundN)rmaxloggerwarnstrname)rpointirrrget_upper_element_boundarys   z(ContinuousSet.get_upper_element_boundarycCs||jkrHd|jkrD|jddkrD|j|}|dkrD|j|dS|S|t|jkrxtdt||jft|jSt|j}| x|D]}||kr|SqWdS)z Returns the first finite element point that is less than or equal to 'point' Parameters ---------- point : `float` Returns ------- float schemezLAGRANGE-RADAUrrzaThe point '%s' is less than the lower bound of the ContinuousSet '%s'. Returning the lower bound N) rrindexminr r!r"r#listreverse)rr$tmpZrev_fer%rrrget_lower_element_boundarys      z(ContinuousSet.get_lower_element_boundaryNcs|jr dSt|}tt||x2|D]*}t|tkr@td|jt kr(tdq(Wx,|j D]}|dk rb||krb| |qbWd| krtd|j t|dkrtd|j t||_|dS)z; Constructs a :py:class:`ContinuousSet` component Nz#ContinuousSet cannot contain tuplesz-ContinuousSet can only contain numeric valuesz}ContinuousSet '%s' must have at least two values indicating the range over which a differential equation is to be discretized)Z _constructedrrr constructtypetuplerrrdomainZboundsaddr#rr*rreport)rvaluesZtimervalZbnd)rrrr/s(         zContinuousSet.constructcsd}td}tj||d}||kr<|}|}nB||krZ|d}|}n$tfdd|d|gD\}}|dk r||krdS|S)a Returns the index of the nearest point in the :py:class:`ContinuousSet `. If a tolerance is specified, the index will only be returned if the distance between the target and the closest point is less than or equal to that tolerance. If there is a tie for closest point, the index on the left is returned. Parameters ---------- target : `float` tolerance : `float` or `None` Returns ------- `float` or `None` r)lohic3s"|]}t||fVqdS)N)abs).0j)rtargetrr sz3ContinuousSet.find_nearest_index..N)rbisect bisect_rightr))rr<Z tolerancer7r8r%Z nearest_indexdeltar)rr<rfind_nearest_indexs $z ContinuousSet.find_nearest_index)N)N)__name__ __module__ __qualname____doc__rrrrrr&r-r/rA __classcell__rr)rrrs+  "))loggingr>Zpyomo.common.timingrZpyomo.core.base.pluginrZpyomo.core.base.setrZpyomo.core.base.numvaluer getLoggerr __all__registerrrrrr s