Esempio n. 1
0
    def _setup_dynamics(self):
        # Look for parent flowsheet
        fs = self.flowsheet()

        # Check the dynamic flag, and retrieve if necessary
        if self.config.dynamic == useDefault:
            if fs is None:
                # No parent, so default to steady-state and warn user
                _log.warning('{} is a top level flowsheet, but dynamic flag '
                             'set to useDefault. Dynamic '
                             'flag set to False by default'.format(self.name))
                self.config.dynamic = False

            else:
                # Get dynamic flag from parent flowsheet
                self.config.dynamic = fs.config.dynamic

        # Check for case when dynamic=True, but parent dynamic=False
        elif self.config.dynamic is True:
            if fs is not None and fs.config.dynamic is False:
                raise DynamicError(
                    '{} trying to declare a dynamic model within '
                    'a steady-state flowsheet. This is not '
                    'supported by the IDAES framework. Try '
                    'creating a dynamic flowsheet instead, and '
                    'declaring some models as steady-state.'.format(self.name))

        if self.config.time is not None:
            # Validate user provided time domain
            if (self.config.dynamic is True
                    and not isinstance(self.config.time, ContinuousSet)):
                raise DynamicError(
                    '{} was set as a dynamic flowsheet, but time domain '
                    'provided was not a ContinuousSet.'.format(self.name))
        else:
            # If no parent flowsheet, set up time domain
            if fs is None:
                # Create time domain
                if self.config.dynamic:
                    # Check if time_set has at least two points
                    if len(self.config.time_set) < 2:
                        # Check if time_set is at default value
                        if self.config.time_set == [0.0]:
                            # If default, set default end point to be 1.0
                            self.config.time_set = [0.0, 1.0]
                        else:
                            # Invalid user input, raise Excpetion
                            raise DynamicError(
                                "Flowsheet provided with invalid "
                                "time_set attribute - must have at "
                                "least two values (start and end).")
                    # For dynamics, need a ContinuousSet
                    self.time = ContinuousSet(initialize=self.config.time_set)
                else:
                    # For steady-state, use an ordered Set
                    self.time = pe.Set(initialize=self.config.time_set,
                                       ordered=True)

                # Set time config argument as reference to time domain
                self.config.time = self.time
            else:
                # Set time config argument to parent time
                self.config.time = fs.config.time
Esempio n. 2
0
    def _setup_dynamics(self):
        """
        This method automates the setting of the dynamic flag and time domain
        for unit models.

        Performs the following:
         1) Determines if this is a top level flowsheet
         2) Gets dynamic flag from parent if not top level, or checks validity
            of argument provided
         3) Checks has_holdup flag if present and dynamic = True

        Args:
            None

        Returns:
            None
        """
        # Get parent object
        if hasattr(self.parent_block(), "config"):
            # Parent block has a config block, so use this
            parent = self.parent_block()
        else:
            # Use parent flowsheet
            try:
                parent = self.flowsheet()
            except ConfigurationError:
                raise DynamicError('{} has no parent flowsheet from which to '
                                   'get dynamic argument. Please provide a '
                                   'value for this argument when constructing '
                                   'the unit.'.format(self.name))

        # Check the dynamic flag, and retrieve if necessary
        if self.config.dynamic == useDefault:
            # Get flag from parent flowsheet
            try:
                self.config.dynamic = parent.config.dynamic
            except AttributeError:
                # No flowsheet, raise exception
                raise DynamicError('{} parent flowsheet has no dynamic '
                                   'argument. Please provide a '
                                   'value for this argument when constructing '
                                   'the unit.'.format(self.name))

        # Check for case when dynamic=True, but parent dynamic=False
        if (self.config.dynamic and not parent.config.dynamic):
            raise DynamicError('{} trying to declare a dynamic model within '
                               'a steady-state flowsheet. This is not '
                               'supported by the IDAES framework. Try '
                               'creating a dynamic flowsheet instead, and '
                               'declaring some models as steady-state.'.format(
                                   self.name))

        # Set and validate has_holdup argument
        if self.config.has_holdup == useDefault:
            # Default to same value as dynamic flag
            self.config.has_holdup = self.config.dynamic
        elif self.config.has_holdup is False:
            if self.config.dynamic is True:
                # Dynamic model must have has_holdup = True
                raise ConfigurationError(
                    "{} invalid arguments for dynamic and has_holdup. "
                    "If dynamic = True, has_holdup must also be True "
                    "(was False)".format(self.name))