def test__pour_by_volume(self): vessel = Vessel("test", materials={"H2O": [material.H2O, 100, 'mol']}) initial_volume = vessel.get_current_volume() event = ['pour by volume', Vessel('test_2'), 0.1] vessel.push_event_to_queue(feedback=[event], dt=0) final_volume = vessel.get_current_volume() self.assertLess(final_volume[1], initial_volume[1])
def test__drain_by_pixel_less(self): vessel = Vessel("test", materials={ 'C6H14': [material.C6H14, 1, 'mol'], 'H2O': [material.H2O, 1, 'mol'] }) initial_volume = vessel.get_current_volume() vessel2 = Vessel('test_2') event = ['drain by pixel', vessel2, 10] vessel.push_event_to_queue(events=[event], dt=1) final_volume = vessel.get_current_volume() self.assertLess(final_volume[1], initial_volume[1])
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