Ejemplo n.º 1
0
    def from_ivc(cls, ivc: om.IndepVarComp) -> "VariableList":
        """
        Creates a VariableList instance from an OpenMDAO IndepVarComp instance

        :param ivc: an IndepVarComp instance
        :return: a VariableList instance
        """
        variables = VariableList()

        ivc = deepcopy(ivc)
        om.Problem(ivc).setup()  # Need setup to have get_io_metadata working

        for name, metadata in ivc.get_io_metadata(
                metadata_keys=["value", "units", "upper", "lower"]).items():
            metadata = metadata.copy()
            value = metadata.pop("value")
            if np.shape(value) == (1, ):
                value = float(value[0])
            elif np.shape(value) == ():
                pass
            else:
                value = np.asarray(value)
            metadata.update({"value": value})
            variables[name] = metadata

        return variables
Ejemplo n.º 2
0
    def from_ivc(cls, ivc: om.IndepVarComp) -> "VariableList":
        """
        Creates a VariableList instance from an OpenMDAO IndepVarComp instance

        :param ivc: an IndepVarComp instance
        :return: a VariableList instance
        """
        variables = cls()

        ivc = deepcopy(ivc)
        om.Problem(ivc).setup()  # Need setup to have get_io_metadata working

        for name, metadata in ivc.get_io_metadata(
                metadata_keys=["val", "units", "upper", "lower"]).items():
            metadata = metadata.copy()
            value = metadata.pop("val")
            value = cls._as_list_or_float(value)
            metadata.update({"val": value})
            variables[name] = metadata

        return variables