コード例 #1
0
ファイル: base.py プロジェクト: zdy0903/tardis
    def update(self, **kwargs):
        for key in kwargs:
            if key not in self.outputs_dict:
                raise PlasmaMissingModule('Trying to update property {0}'
                                          ' that is unavailable'.format(key))
            self.outputs_dict[key].set_value(kwargs[key])

        for module_name in self._resolve_update_list(kwargs.keys()):
            self.plasma_properties_dict[module_name].update()
コード例 #2
0
ファイル: base.py プロジェクト: yogeshwara-krishna/tardis
    def _build_graph(self):
        """
        Builds the directed Graph using network X

        :param plasma_modules:
        :return:
        """

        self.graph = nx.DiGraph()
        ## Adding all nodes
        self.graph.add_nodes_from(
            [
                (plasma_property.name, {})
                for plasma_property in self.plasma_properties
            ]
        )

        # Flagging all input modules
        self.input_properties = [
            item
            for item in self.plasma_properties
            if not hasattr(item, "inputs")
        ]

        for plasma_property in self.plasma_properties:
            # Skipping any module that is an input module
            if plasma_property in self.input_properties:
                continue

            for input in plasma_property.inputs:
                if input not in self.outputs_dict:
                    raise PlasmaMissingModule(
                        "Module {0} requires input "
                        "{1} which has not been added"
                        " to this plasma".format(plasma_property.name, input)
                    )
                try:
                    position = self.outputs_dict[input].outputs.index(input)
                    label = self.outputs_dict[input].latex_name[position]
                    label = "$" + label + "$"
                    label = label.replace("\\", "\\\\")
                except:
                    label = input.replace("_", "-")
                self.graph.add_edge(
                    self.outputs_dict[input].name,
                    plasma_property.name,
                    label=label,
                )
コード例 #3
0
ファイル: base.py プロジェクト: zeerakt/tardis
    def thaw(self, *args):
        """
        Thaw plama properties.

        This method thaws (unfreezes) plasma properties allowing them to be
        updated again.

        Parameters
        ----------
        args : iterable of str
            Names of plasma properties to unfreeze.

        Examples
        --------
        >>> plasma.thaw('t_electrons')
        """
        for key in args:
            if key not in self.outputs_dict:
                raise PlasmaMissingModule("Trying to thaw property {0}"
                                          " that is unavailable".format(key))
            self.outputs_dict[key].frozen = False
コード例 #4
0
ファイル: base.py プロジェクト: zeerakt/tardis
    def freeze(self, *args):
        """
        Freeze plama properties.

        This method freezes plasma properties to prevent them from being
        updated: the values of a frozen property are fixed in the plasma
        calculation. This is useful for example for setting up test cases.

        Parameters
        ----------
        args : iterable of str
            Names of plasma properties to freeze.

        Examples
        --------
        >>> plasma.freeze('t_electrons')
        """
        for key in args:
            if key not in self.outputs_dict:
                raise PlasmaMissingModule("Trying to freeze property {0}"
                                          " that is unavailable".format(key))
            self.outputs_dict[key].frozen = True