示例#1
0
    def plotting_step(self, t, tmax, vessels: vessel.Vessel):
        '''
        Set up a method to handle the acquisition of the necessary plotting parameters
        from an input vessel.

        Parameters
        ---------------
        `t` : `float`
            Current amount of time
        `tmax` : `float`
            Maximum time allowed
        `vessels` : `vessel.Vessel`
            A vessel containing methods to acquire the necessary parameters

        Returns
        ---------------
        `plot_data_state` : `list`
            A list containing the states to be plotted such as time,
            temperature, volume, pressure, and reactant amounts
        `plot_data_mol` : `list`
            A list containing the molar amounts of reactants and products
        `plot_data_concentration` : `list`
            A list containing the concentration of reactants and products

        Raises
        ---------------
        None
        '''

        # acquire the necessary parameters from the vessel
        T = vessels.get_temperature()
        V = vessels.get_volume()
        # V = 0.0025

        # create containers to hold the plotting parameters
        plot_data_state = [[], [], [], []]
        plot_data_mol = [[] for _ in range(self.n.shape[0])]
        plot_data_concentration = [[] for _ in range(self.n.shape[0])]

        # Record time data
        plot_data_state[0].append(t / tmax)

        # record temperature data
        Tmin = vessels.get_Tmin()
        Tmax = vessels.get_Tmax()
        plot_data_state[1].append((T - Tmin) / (Tmax - Tmin))

        # record volume data
        Vmin = vessels.get_min_volume()
        Vmax = vessels.get_max_volume()
        plot_data_state[2].append((V - Vmin) / (Vmax - Vmin))

        # record pressure data
        P = vessels.get_pressure()
        plot_data_state[3].append(P / vessels.get_pmax())

        # calculate and record the molar concentrations of the reactants and products
        C = vessels.get_concentration(materials=self.materials)
        for j in range(self.n.shape[0]):
            plot_data_mol[j].append(self.n[j])
            plot_data_concentration[j].append(C[j])

        return plot_data_state, plot_data_mol, plot_data_concentration
示例#2
0
    def perform_action(self, action, vessels: vessel.Vessel, t, n_steps,
                       step_num):
        """
        Update the environment with processes defined in `action`.

        Parameters
        ---------------
        `action` : `np.array`
            An array containing elements describing the changes to be made, during the current
            step, to each modifiable thermodynamic variable and reactant used in the reaction.
        `vessels` : `vessel.Vessel`
            A vessel containing initial materials to be used in a series of reactions.
        `n_steps` : `int`
            The number of increments into which the action is split.

        Returns
        ---------------
        `vessels` : `vessel.Vessel`
            A vessel that has been updated to have the proper materials and
            thermodynamic properties.

        Raises
        ---------------
        None
        """

        self.perform_compatibility_check(action=action,
                                         vessels=vessels,
                                         n_steps=n_steps,
                                         step_num=step_num)

        # deconstruct the action
        temperature_change, volume_change, delta_n_array = self.action_deconstruct(
            action=action)

        # deconstruct the vessel: acquire the vessel temperature and volume and create the n array
        temperature, volume = self.vessel_deconstruct(vessels=vessels)
        current_volume = vessels.get_current_volume()[-1]

        # perform the complete action over a series of increments
        if self.solver != 'newton':
            n_steps = 1
        for __ in range(n_steps):
            # split the overall temperature change into increments,
            # ensure it does not exceed the maximal and minimal temperature values
            temperature += temperature_change / n_steps
            temperature = np.min([
                np.max([temperature, vessels.get_Tmin()]),
                vessels.get_Tmax()
            ])

            # split the overall volume change into increments,
            # ensure it does not exceed the maximal and minimal volume values
            volume += volume_change / n_steps
            volume = np.min([
                np.max([volume, vessels.get_min_volume()]),
                vessels.get_max_volume()
            ])

            # split the overall molar changes into increments
            for j, delta_n in enumerate(delta_n_array):
                dn = delta_n / n_steps
                self.n[j] += dn
                self.cur_in_hand[j] -= dn

                # set a penalty for trying to add unavailable material (tentatively set to 0)
                # reward -= 0

                # if the amount that is in hand is below a certain threshold set it to 0
                if self.cur_in_hand[j] < self.threshold:
                    self.cur_in_hand[j] = 0.0

            # perform the reaction and update the molar concentrations of the reactants and products
            self.update(self.n / current_volume, temperature, current_volume,
                        t, vessels.get_defaultdt(), n_steps)

        # create a new reaction vessel containing the final materials
        vessels = self.update_vessel(temperature, volume)

        return vessels